Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
theripper93 committed Nov 29, 2023
1 parent 750e72b commit 6200c73
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
35 changes: 32 additions & 3 deletions scripts/core/components/main/buttonPanel/accordionPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { ArgonComponent } from "../../component.js";
import {ButtonPanel} from "./buttonPanel.js";

export class AccordionPanel extends ArgonComponent{
constructor ({accordionPanelCategories}) {
constructor ({accordionPanelCategories, id}) {
super();
this._subPanels = accordionPanelCategories;
this._id = id ?? null;
this.saveState = debounce(this.saveState, 100);
}

get classes() {
Expand All @@ -15,12 +17,38 @@ export class AccordionPanel extends ArgonComponent{
return this.element.classList.contains("show");
}

get id() {
return this._id;
}

setVisibility(){}

toggle(toggle) {
toggle(toggle, noTransition = false) {
if (toggle === undefined) toggle = !this.visible;
if(toggle) ui.ARGON.collapseAllPanels();
if (toggle) ui.ARGON.collapseAllPanels();
if(noTransition) this.element.style.transition = "none";
this.element.classList.toggle("show", toggle);
if (noTransition) setTimeout(() => this.element.style.transition = null, 1);
this.saveState();
}

saveState() {
if (!this.id) return;
const state = {
visible: this.visible,
subPanels: this._subPanels.map(panel => panel.visible)
}
ui.ARGON.setPanelState(state, this)
}

restoreState() {
if (!this.id) return;
const state = ui.ARGON.getPanelState(this);
if (!state) return;
this.toggle(state.visible, true);
for (let i = 0; i < state.subPanels.length; i++) {
this._subPanels[i]?.toggle(state.subPanels[i], true);
}
}

updateItem(item) {
Expand All @@ -44,5 +72,6 @@ export class AccordionPanel extends ArgonComponent{
if (totalActionBarWidth < 0) break;
panel.toggle(true);
}
this.restoreState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ export class AccordionPanelCategory extends ArgonComponent{
});
}

toggle(toggle) {
toggle(toggle, noTransition = false) {
if (toggle === undefined) toggle = !this.visible;
if (noTransition) {
this.element.style.transition = "none";
this.buttonContainer.style.transition = "none";
}
this.element.classList.toggle("show", toggle);
this.element.style.width = toggle ? `${this._realWidth}px` : "0px";
if (noTransition) setTimeout(() => {
this.element.style.transition = null;
this.buttonContainer.style.transition = null;
}, 1);
this.parent.saveState();
}

async _renderInner() {
Expand Down
31 changes: 28 additions & 3 deletions scripts/core/components/main/buttonPanel/buttonPanel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ArgonComponent } from "../../component.js";

export class ButtonPanel extends ArgonComponent{
constructor ({buttons}) {
constructor ({buttons, id}) {
super();
this.element.dataset.iscontainer = true;
this._id = id ?? null;
this._buttons = buttons;
this.saveState = debounce(this.saveState, 100);
}

get classes() {
Expand All @@ -15,12 +17,34 @@ export class ButtonPanel extends ArgonComponent{
return this.element.classList.contains("show");
}

get id() {
return this._id;
}

setVisibility(){}

toggle(toggle) {
toggle(toggle, noTransition = false) {
if (toggle === undefined) toggle = !this.visible;
if(toggle) ui.ARGON.collapseAllPanels();
if (toggle) ui.ARGON.collapseAllPanels();
if(noTransition) this.element.style.transition = "none";
this.element.classList.toggle("show", toggle);
if (noTransition) setTimeout(() => this.element.style.transition = null, 1);
this.saveState();
}

saveState() {
if (!this.id) return;
const state = {
visible: this.visible,
}
ui.ARGON.setPanelState(state, this)
}

restoreState() {
if (!this.id) return;
const state = ui.ARGON.getPanelState(this);
if (!state) return;
this.toggle(state.visible, true);
}

updateItem(item) {
Expand All @@ -38,5 +62,6 @@ export class ButtonPanel extends ArgonComponent{
});
const promises = this._buttons.map(button => button.render());
await Promise.all(promises);
this.restoreState();
}
}
24 changes: 24 additions & 0 deletions scripts/core/hud.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class CoreHUD extends Application{
this.performModuleCheck();
this._itemButtons = [];
this._batchItemsUpdates = new Set();
this._hudState = new Map();
this._tooltip = null;
this._target = null;
this._enabled = false;
Expand Down Expand Up @@ -190,7 +191,30 @@ export class CoreHUD extends Application{
}
}

getState() {
return this._hudState.get(this._target);
}

setState(state) {
this._hudState.set(this._target, state);
}

getPanelState(panel) {
const state = this.getState();
if (!state) return;
return state[panel.id];
}

setPanelState(state, panel) {
const currState = this.getState();
if (!currState) return;
currState[panel.id] = state;
this.setState(currState);
}

async _renderInner(data) {
const _prevState = this._hudState.get(this._target);
if(!_prevState) this._hudState.set(this._target, {});
const element = await super._renderInner(data);
const html = element[0];
this.components = {
Expand Down

0 comments on commit 6200c73

Please sign in to comment.