diff options
Diffstat (limited to 'resources/js/ui.js')
-rw-r--r-- | resources/js/ui.js | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/resources/js/ui.js b/resources/js/ui.js index 006e6fc..dd287df 100644 --- a/resources/js/ui.js +++ b/resources/js/ui.js @@ -691,6 +691,8 @@ const UI = { /* Map */ + shopSelectionMode: 'buy', + /** * @returns {HTMLElement} */ @@ -785,26 +787,49 @@ const UI = { itemNode.querySelector('[data-template-slot="price"]').innerHTML = formatPrice(price); itemNode.addEventListener('click', () => { - if (Memory.state.money < price) { - alert(`Not enough ${DB.currencies.map[Memory.state.Settings.currency].symbol}.`); - return; - } + if (UI.shopSelectionMode === 'buy') { - Memory.state.money -= price; + if (Memory.state.money < price) { + alert(`Not enough ${DB.currencies.map[Memory.state.Settings.currency].symbol}.`); + return; + } - const itemInInventory = Memory.state.player.inventory.find((inventoryItem) => inventoryItem.slug === item.slug); - if (itemInInventory) { - itemInInventory.quantity++; - } else { - Memory.state.player.inventory.push(new InventoryItem(item, 1)); + Memory.state.money -= price; + + const itemInInventory = Memory.state.player.inventory.find((inventoryItem) => inventoryItem.slug === item.slug); + if (itemInInventory) { + itemInInventory.quantity++; + } else { + Memory.state.player.inventory.push(new InventoryItem(item, 1)); + } + + UI.drawStatus(); } - UI.drawStatus(); + else if (UI.shopSelectionMode === 'info') { + UI.openItemInfo(item); + } }); - template.appendChild(itemNode); + template.querySelector('[data-template-slot="items"]').appendChild(itemNode); } + const selectionModesNode = template.querySelector('[data-template-slot="modes"]'); + const selectionModeNodes = selectionModesNode.querySelectorAll('[data-selection-mode]'); + selectionModeNodes.forEach((node) => { + if (node.dataset.selectionMode === UI.shopSelectionMode) { + node.setAttribute('selected', true); + } + + node.addEventListener('click', () => { + selectionModesNode.querySelector(`[data-selection-mode="${UI.shopSelectionMode}"]`).removeAttribute('selected'); + + UI.shopSelectionMode = node.dataset.selectionMode; + + node.setAttribute('selected', true); + }); + }); + popup.querySelector('.popup').appendChild(template); UI.drawPopup(popup); }, @@ -1089,7 +1114,7 @@ const UI = { } if (Memory.state.activeBall) { - UI.elements.menuCatch.querySelector('img').src = `/modules/tuxemon/mods/tuxemon/gfx/items/${Memory.state.activeBall.slug}.png`; + UI.elements.menuCatch.querySelector('img').src = `/modules/tuxemon/mods/tuxemon/gfx/items/${Memory.state.activeBall}.png`; } else { UI.elements.menuCatch.querySelector('img').src = `/modules/tuxemon/mods/tuxemon/gfx/items/tuxeball.png`; } @@ -1546,7 +1571,12 @@ const UI = { else if (item.category === 'capture') { Game.useItem(item); } + + else if (item.category === 'booster') { + UI.openItemMonsterSelection(item); + } } + else if (UI.inventorySelectionMode === 'info') { UI.openItemInfo(item); } @@ -1586,7 +1616,6 @@ const UI = { await Game.useItem(item, monster); if (item.quantity === 0) { - Game.removeItemFromInventory(Memory.state.player.inventory, item); template.dispatchEvent(new Event('item:isExhausted')); } @@ -1639,7 +1668,7 @@ const UI = { const popup = UI.createPopup(); const template = document.createElement('div'); - template.textContent = item.conditions + ' -- ' + item.effects + ' -- ' + item.description; + template.textContent = item.description; popup.querySelector('.popup').appendChild(template); @@ -1653,6 +1682,7 @@ const UI = { const popup = UI.createPopup(); const dialog = UI.createTemplate(Template.dialogSave); + Memory.saveToLocalStorage(); const saveData = Memory.saveToString(); dialog.querySelector('[data-template-slot="saveData"]').value = saveData; |