From 77a9a56fb8929b992e0743ce2a4c9fa1db1dc315 Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Tue, 23 Jun 2020 13:17:28 +0300 Subject: [PATCH] load widgets from cfg --- src/ipc/types.ts | 87 +++++++++++++++++++++++- src/web/overlay/OverlayWindow.vue | 62 +++-------------- src/web/price-check/PriceCheckWindow.vue | 3 + 3 files changed, 100 insertions(+), 52 deletions(-) diff --git a/src/ipc/types.ts b/src/ipc/types.ts index 5f6f9165..07beb3e2 100644 --- a/src/ipc/types.ts +++ b/src/ipc/types.ts @@ -24,8 +24,28 @@ export interface Config { searchStatRange: number stashScroll: boolean subdomain: string + widgets: Widget[] } +interface Widget { + wmId: number + wmType: string + wmTitle: string + wmWants: 'show' | 'hide' + wmZorder: number | 'exclusive' | undefined + wmFlags: (WidgetWellKnownFlag | string)[] + // --------------- + [key: string]: any +} + +type WidgetWellKnownFlag = + 'uninitialized' | + 'skip-menu' | + 'has-browser' | + 'invisible-on-blur' | + 'hide-on-blur' | + 'hide-on-blur(close)' + export const defaultConfig: Config = { priceCheckKey: 'D', priceCheckKeyHold: 'Ctrl', @@ -60,5 +80,70 @@ export const defaultConfig: Config = { accountName: '', searchStatRange: 10, stashScroll: true, - subdomain: 'us' + subdomain: 'us', + widgets: [ + // --- REQUIRED --- + { + wmId: 1, + wmType: 'menu', + wmTitle: '', + wmWants: 'show', + wmZorder: 1, + wmFlags: ['invisible-on-blur', 'skip-menu'], + anchor: { + pos: 'tl', + x: 5, + y: 5 + } + }, + { + wmId: 2, + wmType: 'price-check', + wmTitle: '', + wmWants: 'hide', + wmZorder: 'exclusive', + wmFlags: ['hide-on-blur', 'skip-menu'] + }, + // --- DEFAULT --- + { + wmId: 4, + wmType: 'inventory-search', + wmTitle: 'Map rolling', + wmWants: 'hide', + wmZorder: 4, + wmFlags: ['invisible-on-blur'], + anchor: { + pos: 'tl', + x: 35, + y: 46 + }, + entries: [ + { id: 1, text: '"Pack Size: +3"' }, + { id: 2, text: 'Reflect' }, + { id: 3, text: '"Cannot Leech Life"' }, + { id: 4, text: '"Cannot Leech Mana"' } + ] + }, + { + wmId: 5, + wmType: 'inventory-search', + wmTitle: 'Dump sorting', + wmWants: 'hide', + wmZorder: 5, + wmFlags: ['invisible-on-blur'], + anchor: { + pos: 'tl', + x: 34, + y: 56 + }, + entries: [ + { id: 1, text: 'Currency' }, + { id: 2, text: '"Divination Card"' }, + { id: 3, text: 'Fossil' }, + { id: 4, text: '"Map Tier"' }, + { id: 5, text: '"Map Device" "Rarity: Normal"' }, + { id: 6, text: 'Tane Laboratory' } + ] + } + ] } diff --git a/src/web/overlay/OverlayWindow.vue b/src/web/overlay/OverlayWindow.vue index 5b12792f..12c1b640 100644 --- a/src/web/overlay/OverlayWindow.vue +++ b/src/web/overlay/OverlayWindow.vue @@ -42,56 +42,6 @@ export default { active: false, gameFocused: false, hideUI: false, - widgets: [ - { - wmId: 1, - wmType: 'timer', - wmWants: 'show', - wmTitle: 'Timer', - wmFlags: [], - anchor: { - pos: 'cc', - x: 10, - y: 50 - } - }, - { - wmId: 4, - wmType: 'menu', - wmWants: 'show', - wmFlags: ['invisible-on-blur', 'skip-menu'], - anchor: { - pos: 'tl', - x: 5, - y: 5 - } - }, - { - wmId: 2, - wmType: 'inventory-search', - wmFlags: ['invisible-on-blur'], - wmWants: 'hide', - anchor: { - pos: 'tr', - x: 81, - y: 20 - }, - wmTitle: 'Map rolling', - entries: [ - { id: 2, text: 'Reflect' }, - { id: 1, text: '"Quantity: +3"' }, - { id: 3, text: '"Cannot Leech Life"' }, - { id: 4, text: '"Cannot Leech Mana"' } - ] - }, - { - wmId: 3, - wmType: 'price-check', - wmZorder: 'exclusive', - wmWants: 'hide', - wmFlags: ['hide-on-blur', 'skip-menu'] - } - ], devicePixelRatio: null } }, @@ -136,7 +86,9 @@ export default { } if (this.active === false && this.gameFocused === false) { - Config.saveConfig() + this.$nextTick(() => { + Config.saveConfig() + }) } }) MainProcess.addEventListener(VISIBILITY, ({ detail: e }) => { @@ -153,6 +105,14 @@ export default { }) }, computed: { + widgets: { + get () { + return Config.store.widgets + }, + set (value) { + Config.store.widgets = value + } + }, visibilityState () { let showExclusive = this.widgets.find(w => w.wmZorder === 'exclusive' && w.wmWants === 'show') if (!this.active && showExclusive && showExclusive.wmFlags.includes('invisible-on-blur')) { diff --git a/src/web/price-check/PriceCheckWindow.vue b/src/web/price-check/PriceCheckWindow.vue index 1a093e1e..2504d45c 100644 --- a/src/web/price-check/PriceCheckWindow.vue +++ b/src/web/price-check/PriceCheckWindow.vue @@ -114,6 +114,9 @@ export default { this.updatePoeUiWidth() }, data () { + this.config.wmWants = 'hide' + this.config.wmFlags = ['hide-on-blur', 'skip-menu'] + return { poeUiWidth: '1px', checkPosition: { x: 1, y: 1 },