diff options
Diffstat (limited to 'resources/js/ui.js')
-rw-r--r-- | resources/js/ui.js | 81 |
1 files changed, 54 insertions, 27 deletions
diff --git a/resources/js/ui.js b/resources/js/ui.js index 6f38867..77b5b54 100644 --- a/resources/js/ui.js +++ b/resources/js/ui.js @@ -725,7 +725,7 @@ const UI = { template.querySelector('[data-template-slot="heal"]').addEventListener('click', () => { const applicableMonsters = Memory.state.player.monsters.filter((monster) => monster.hp < monster.stats.hp || monster.statusEffect); if (applicableMonsters.length === 0) { - alert('No applicable monsters.'); + alert(translate('ui:no_applicable_monsters', true)); return; } @@ -1004,7 +1004,8 @@ const UI = { const connection = currentArea.connections[connectionSlug]; const connectionNode = UI.createTemplate(Template.areaSelectionItem); - connectionNode.querySelector('[data-template-slot="text"]').textContent = connection.name; + connectionNode.querySelector('[data-template-slot="text"]').textContent = + translate(connection['modules/tuxemon.slug']) || slugToName(connection['modules/tuxemon.slug']); let canGo = true; for (const condition of connection.conditions) { @@ -1090,27 +1091,27 @@ const UI = { const tabs = { heal: { - heading: 'Heal', + heading: translate('ui:inventory:tab:heal'), items: [], }, stats: { - heading: 'Stats', + heading: translate('ui:inventory:tab:stats'), items: [], }, balls: { - heading: 'Balls', + heading: translate('ui:inventory:tab:balls'), items: [], }, techniques: { - heading: 'Techniques', + heading: translate('ui:inventory:tab:techniques'), items: [], }, other: { - heading: 'Other', + heading: translate('ui:inventory:tab:other'), items: [], }, keyItems: { - heading: 'Key Items', + heading: translate('ui:inventory:tab:key_items'), items: [], }, }; @@ -1180,13 +1181,13 @@ const UI = { const popup = UI.createPopup(); const journal = UI.createTemplate(Template.menuJournal); - journal.querySelector('[data-template-slot="save"]').addEventListener('click', () => { + journal.querySelector('[data-template-slot="save"]').addEventListener('click', UI.createEventListener(() => { UI.openSaveDialog(); - }); + })); - journal.querySelector('[data-template-slot="load"]').addEventListener('click', () => { + journal.querySelector('[data-template-slot="load"]').addEventListener('click', UI.createEventListener(() => { UI.openLoadDialog(); - }); + })); popup.querySelector('.popup').appendChild(journal); UI.drawPopup(popup); @@ -1237,9 +1238,9 @@ const UI = { Memory.state.Settings.language = selected.value; await fetchTranslation(Memory.state.Settings.language); - UI.drawOpponentMonster(); - UI.drawActiveMonster(); - UI.drawActiveTechniques(); + applyTranslation(); + + UI.drawArea(); }); @@ -1572,7 +1573,7 @@ const UI = { template.classList.add('inventory__monster-selection'); if (template.children.length === 0) { - alert('No applicable monsters.'); + alert(translate('ui:no_applicable_monsters', true)); return; } @@ -1608,14 +1609,14 @@ const UI = { const saveData = Memory.save(); dialog.querySelector('[data-template-slot="saveData"]').value = saveData; - dialog.querySelector('[data-template-slot="saveClipboard"]').addEventListener('click', async () => { + dialog.querySelector('[data-template-slot="saveClipboard"]').addEventListener('click', UI.createEventListenr(async () => { if (navigator.clipboard) { await navigator.clipboard.writeText(saveData); alert('Saved to clipboard!'); } else { alert('ERROR: Browser can\'t copy to clipboard! You have to do it manually.'); } - }); + })); popup.querySelector('.popup').appendChild(dialog); UI.drawPopup(popup); @@ -1625,24 +1626,50 @@ const UI = { const popup = UI.createPopup(); const dialog = UI.createTemplate(Template.dialogLoad); - dialog.querySelector('[data-template-slot="load"]').addEventListener('click', () => { + dialog.querySelector('[data-template-slot="load"]').addEventListener('click', UI.createEventListener(() => { Memory.load( dialog.querySelector('[data-template-slot="saveData"]').value.trim() ); document.querySelectorAll('.popup__overlay').forEach((element) => element.remove()) - }); + })); popup.querySelector('.popup').appendChild(dialog); UI.drawPopup(popup); }, + + + // Error + + /** + * @param {Function} listener + * + * @returns {Function} + */ + createEventListener (listener) { + return (event) => { + try { + listener(event); + } catch (exception) { + console.log(exception); + UI.showErrorMessage(exception); + } + }; + }, + + /** + * @param {string} message + */ + showErrorMessage (message) { + alert(message); + }, }; // UI element click bindings -UI.elements.showMap.addEventListener('click', UI.openMap); -UI.elements.changeArea.addEventListener('click', UI.openAreaSelection); -UI.elements.menuParty.addEventListener('click', UI.openPartyMenu); -UI.elements.menuInventory.addEventListener('click', UI.openInventoryMenu); -UI.elements.menuLog.addEventListener('click', UI.toggleLog); -UI.elements.menuJournal.addEventListener('click', UI.openJournalMenu); -UI.elements.menuSettings.addEventListener('click', UI.openSettingsMenu); +UI.elements.showMap.addEventListener('click', UI.createEventListener(UI.openMap)); +UI.elements.changeArea.addEventListener('click', UI.createEventListener(UI.createEventListener(UI.openAreaSelection))); +UI.elements.menuParty.addEventListener('click', UI.createEventListener(UI.openPartyMenu)); +UI.elements.menuInventory.addEventListener('click', UI.createEventListener(UI.openInventoryMenu)); +UI.elements.menuLog.addEventListener('click', UI.createEventListener(UI.toggleLog)); +UI.elements.menuJournal.addEventListener('click', UI.createEventListener(UI.openJournalMenu)); +UI.elements.menuSettings.addEventListener('click', UI.createEventListener(UI.openSettingsMenu)); |