diff --git a/srcjs/stendhal/Client.ts b/srcjs/stendhal/Client.ts index 22fd022aaef..fdde84bb49e 100644 --- a/srcjs/stendhal/Client.ts +++ b/srcjs/stendhal/Client.ts @@ -394,7 +394,7 @@ export class Client { var menubutton = document.getElementById("menubutton")!; menubutton.addEventListener("click", () => { - const dialogState = stendhal.config.dialogstates["menu"]; + const dialogState = stendhal.config.windowstates["menu"]; const menuContent = new ApplicationMenuDialog(); const menuFrame = ui.createSingletonFloatingWindow( "Menu", menuContent, dialogState.x, dialogState.y); diff --git a/srcjs/stendhal/action/SettingsAction.ts b/srcjs/stendhal/action/SettingsAction.ts index cd7cb4dfd12..6db39b26b99 100644 --- a/srcjs/stendhal/action/SettingsAction.ts +++ b/srcjs/stendhal/action/SettingsAction.ts @@ -23,7 +23,7 @@ export class SettingsAction extends SlashAction { readonly maxParams = 0; execute(_type: string, _params: string[], _remainder: string): boolean { - const wstate = stendhal.config.dialogstates["settings"]; + const wstate = stendhal.config.windowstates["settings"]; const offset = stendhal.ui.getPageOffset(); const content = new SettingsDialog(); diff --git a/srcjs/stendhal/entity/Chest.ts b/srcjs/stendhal/entity/Chest.ts index 5ff3f214651..86ef21d389f 100644 --- a/srcjs/stendhal/entity/Chest.ts +++ b/srcjs/stendhal/entity/Chest.ts @@ -88,7 +88,7 @@ export class Chest extends PopupInventory { openInventoryWindow() { if (!this.inventory || !this.inventory.isOpen()) { - const dstate = stendhal.config.dialogstates["chest"]; + const dstate = stendhal.config.windowstates["chest"]; const invComponent = new ItemInventoryComponent(this, "content", 5, 6, stendhal.config.getBoolean("action.chest.quickpickup"), undefined); invComponent.setConfigId("chest"); diff --git a/srcjs/stendhal/entity/Corpse.ts b/srcjs/stendhal/entity/Corpse.ts index cfe4e140c9d..77946e42c1c 100644 --- a/srcjs/stendhal/entity/Corpse.ts +++ b/srcjs/stendhal/entity/Corpse.ts @@ -79,7 +79,7 @@ export class Corpse extends PopupInventory { } } - const dstate = stendhal.config.dialogstates["corpse"]; + const dstate = stendhal.config.windowstates["corpse"]; const invComponent = new ItemInventoryComponent(this, "content", content_row, content_col, true, undefined); invComponent.setConfigId("corpse"); diff --git a/srcjs/stendhal/entity/User.ts b/srcjs/stendhal/entity/User.ts index 925d14524ed..a75b44b8f8f 100644 --- a/srcjs/stendhal/entity/User.ts +++ b/srcjs/stendhal/entity/User.ts @@ -86,7 +86,7 @@ export class User extends Player { action: function(_entity: any) { let outfitDialog = ui.get(UIComponentEnum.OutfitDialog); if (!outfitDialog) { - const dstate = stendhal.config.dialogstates["outfit"]; + const dstate = stendhal.config.windowstates["outfit"]; outfitDialog = new OutfitDialog(); new FloatingWindow("Choose outfit", outfitDialog, dstate.x, dstate.y); } diff --git a/srcjs/stendhal/event/ProgressStatusEvent.ts b/srcjs/stendhal/event/ProgressStatusEvent.ts index a448ca0322b..57c4a52ac28 100644 --- a/srcjs/stendhal/event/ProgressStatusEvent.ts +++ b/srcjs/stendhal/event/ProgressStatusEvent.ts @@ -34,7 +34,7 @@ export class ProgressStatusEvent extends RPEvent { let travelLogDialog = ui.get(UIComponentEnum.TravelLogDialog) as TravelLogDialog; if (!this["progress_type"]) { if (!travelLogDialog) { - const dstate = stendhal.config.dialogstates["travellog"]; + const dstate = stendhal.config.windowstates["travellog"]; travelLogDialog = new TravelLogDialog(dataItems); new FloatingWindow("Travel Log", travelLogDialog, dstate.x, dstate.y); } diff --git a/srcjs/stendhal/event/TradeEvent.ts b/srcjs/stendhal/event/TradeEvent.ts index 1b0cfd9f865..f53acd1f785 100644 --- a/srcjs/stendhal/event/TradeEvent.ts +++ b/srcjs/stendhal/event/TradeEvent.ts @@ -32,7 +32,7 @@ export class TradeEvent extends RPEvent { let dialog = ui.get(UIComponentEnum.TradeDialog) as TradeDialog; if (this["user_trade_state"] !== "NO_ACTIVE_TRADE" && !dialog) { - const dstate = stendhal.config.dialogstates["trade"]; + const dstate = stendhal.config.windowstates["trade"]; dialog = new TradeDialog(); new FloatingWindow("Trade", dialog, dstate.x, dstate.y); } diff --git a/srcjs/stendhal/ui/toolkit/Component.ts b/srcjs/stendhal/ui/toolkit/Component.ts index b99a8e920f5..c92f6efdb3f 100644 --- a/srcjs/stendhal/ui/toolkit/Component.ts +++ b/srcjs/stendhal/ui/toolkit/Component.ts @@ -53,6 +53,7 @@ export abstract class Component { * * @param cid * The string identifier. + * @deprecated */ public setConfigId(cid: string) { this.cid = cid; diff --git a/srcjs/stendhal/ui/toolkit/DialogContentComponent.ts b/srcjs/stendhal/ui/toolkit/DialogContentComponent.ts index 42b3b834132..e21a414cb8f 100644 --- a/srcjs/stendhal/ui/toolkit/DialogContentComponent.ts +++ b/srcjs/stendhal/ui/toolkit/DialogContentComponent.ts @@ -28,10 +28,13 @@ export abstract class DialogContentComponent extends ThemedComponent { this.componentElement.classList.add("dialogcontents"); } + /** + * @deprecated + */ public updateConfig(newX: number, newY: number) { const cid = this.getConfigId(); - if (stendhal.config.dialogstates[cid]) { - stendhal.config.dialogstates[cid] = {x: newX, y: newY}; + if (stendhal.config.windowstates[cid]) { + stendhal.config.windowstates[cid] = {x: newX, y: newY}; } } diff --git a/srcjs/stendhal/ui/toolkit/FloatingWindow.ts b/srcjs/stendhal/ui/toolkit/FloatingWindow.ts index 06b416ce6cb..d0396246836 100644 --- a/srcjs/stendhal/ui/toolkit/FloatingWindow.ts +++ b/srcjs/stendhal/ui/toolkit/FloatingWindow.ts @@ -30,6 +30,9 @@ export class FloatingWindow extends Component { private content: Component; + private windowId?: string; + + constructor(title: string, protected contentComponent: Component, x: number, y: number) { super("window-template"); @@ -163,7 +166,7 @@ export class FloatingWindow extends Component { window.removeEventListener("touchend", this.onMouseUpDuringDragListener, true); } - private checkPos() { + private checkPos(): any { if (this.content) { this.content.onMoved(); } @@ -201,6 +204,13 @@ export class FloatingWindow extends Component { } public override onMoved() { - this.checkPos(); + const pos = this.checkPos(); + if (typeof(this.windowId) !== "undefined") { + stendhal.config.setWindowState(this.windowId, pos.x, pos.y); + } + } + + public setId(id: string|undefined) { + this.windowId = id; } } diff --git a/srcjs/stendhal/util/ConfigManager.ts b/srcjs/stendhal/util/ConfigManager.ts index 7fc22f8235a..a776f81ffc9 100644 --- a/srcjs/stendhal/util/ConfigManager.ts +++ b/srcjs/stendhal/util/ConfigManager.ts @@ -90,7 +90,7 @@ export class ConfigManager { } as {[name: string]: string}; private storage = window.localStorage; - private dialogstates: any = {}; + private windowstates: any = {}; private initialized = false; /** Singleton instance. */ @@ -122,13 +122,13 @@ export class ConfigManager { // store window information for this session // TODO: move this into "session" file - this.dialogstates["chest"] = {x: 160, y: 370}; - this.dialogstates["corpse"] = {x: 160, y: 370}; - this.dialogstates["menu"] = {x: 150, y: 20}; - this.dialogstates["outfit"] = {x: 300, y: 50}; - this.dialogstates["settings"] = {x: 20, y: 20}; - this.dialogstates["trade"] = {x: 200, y: 100}; - this.dialogstates["travellog"] = {x: 160, y: 50}; + this.windowstates["chest"] = {x: 160, y: 370}; + this.windowstates["corpse"] = {x: 160, y: 370}; + this.windowstates["menu"] = {x: 150, y: 20}; + this.windowstates["outfit"] = {x: 300, y: 50}; + this.windowstates["settings"] = {x: 20, y: 20}; + this.windowstates["trade"] = {x: 200, y: 100}; + this.windowstates["travellog"] = {x: 160, y: 50}; this.initialized = true; } @@ -258,6 +258,45 @@ export class ConfigManager { this.storage.clear(); } + /** + * Sets attributes for a dialog window. + * + * TODO: move into session manager + * + * @param id + * Dialog identifier. + * @param x + * Horizontal position. + * @param y + * Vertical position. + */ + setWindowState(id: string, x: number, y: number) { + this.windowstates[id] = {x: x, y: y}; + this.set("ui.window." + id, x + "," + y); + } + + /** + * Retrieves attributes for a dialog window. + * + * TODO: move into session manager + * + * @param id + * Dialog identifier. + * @return + * Object containing X/Y positioning of dialog. + */ + getWindowState(id: string): {[index: string]: number} { + let state: {[index: string]: number} = {}; + if (this.windowstates.hasOwnProperty(id)) { + state = this.windowstates[id]; + } else { + const tmp: string[] = (this.get("ui.window." + id) || "0,0").split(","); + state.x = parseInt(tmp[0], 10); + state.y = parseInt(tmp[1], 10); + } + return state; + } + /** * Sets the UI theme. *