diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-21 22:44:21 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-21 22:44:21 +0200 |
commit | 54e5ffaeb79f989463c144e58dfcd677b752c5a9 (patch) | |
tree | 08e199c521d4ca6ba17f3499204d80f4be774917 /resources/js/ui.js | |
parent | eef0dd25f921a8b900e902631b79fc90d70c0309 (diff) |
log actions
Diffstat (limited to 'resources/js/ui.js')
-rw-r--r-- | resources/js/ui.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/resources/js/ui.js b/resources/js/ui.js index 06e55ed..bfd9204 100644 --- a/resources/js/ui.js +++ b/resources/js/ui.js @@ -42,6 +42,8 @@ const UI = { techniques: document.querySelector('#techniques'), + log: document.querySelector('#log'), + status: document.querySelector('#status'), nextTrainer: document.querySelector('#status [data-template-slot="nextTrainer"]'), nextArea: document.querySelector('#status [data-template-slot="nextArea"]'), @@ -49,6 +51,7 @@ const UI = { menuParty: document.querySelector('#menu__party'), menuInventory: document.querySelector('#menu__inventory'), menuCatch: document.querySelector('#menu__catch'), + menuLog: document.querySelector('#menu__log'), menuJournal: document.querySelector('#menu__journal'), menuSettings: document.querySelector('#menu__settings'), }, @@ -299,10 +302,12 @@ const UI = { if (Game.isBattleType('trainer')) { battleMonsterNode.classList.add('battle__monster--is-trainer'); + battleMonsterNode.querySelector('[data-template-slot="trainerName"]').textContent = Memory.state.opponent.name; if (Memory.state.opponent.sprite) { battleMonsterNode.classList.add('battle__monster--has-trainer-sprite'); battleMonsterNode.querySelector('[data-template-slot="trainerSprite"]').src = `/modules/tuxemon/mods/tuxemon/gfx/sprites/player/${Memory.state.opponent.sprite}`; + battleMonsterNode.querySelector('[data-template-slot="trainerSprite"]').title = Memory.state.opponent.name; } } @@ -456,6 +461,34 @@ const UI = { requestAnimationFrame(techniqueAnimationLoop); }, + drawLog () { + if (UI.elements.log.children.length > Memory.state.Settings.logMaxLength) { + UI.elements.log.innerHTML = ''; + } + + for (const message of Game.logMessages) { + const textNode = document.createElement('div'); + + textNode.innerHTML = '> '.repeat(message.indentation) + message.message; + + if (message.style) { + for (const property of Object.keys(message.style)) { + const value = message.style[property]; + textNode.style[property] = value; + } + } + + UI.elements.log.appendChild(textNode); + UI.elements.log.scrollTop = UI.elements.log.scrollHeight; + } + + Game.logMessages = []; + }, + + toggleLog () { + UI.elements.log.classList.toggle('log--is-hidden'); + }, + /** * @param {Area} area */ @@ -892,7 +925,7 @@ const UI = { languageOptionNode.value = languageCode; languageOptionNode.textContent = languageName; - if (languageCode === Memory.state.language) { + if (languageCode === Memory.state.Settings.language) { languageOptionNode.selected = true; } @@ -901,9 +934,9 @@ const UI = { languageSelectNode.addEventListener('change', async () => { const selected = [...languageSelectNode.children].find((node) => node.selected === true); - Memory.state.language = selected.value; + Memory.state.Settings.language = selected.value; - await fetchTranslation(Memory.state.language); + await fetchTranslation(Memory.state.Settings.language); UI.drawOpponentMonster(); UI.drawActiveMonster(); UI.drawActiveTechniques(); @@ -1227,5 +1260,6 @@ const UI = { // UI element click bindings 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); |