From 616d58218dfe9f4177e8cb04ff45d35c253e8547 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 21 Sep 2023 12:42:21 +0200 Subject: [PATCH] initial commit --- src/core/Global.ttslua | 31 ++++++++++++++++++++++++++---- src/core/token/TokenManager.ttslua | 4 +++- xml/OptionPanel.xml | 14 ++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 987c6f07..4b18ec07 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -900,12 +900,39 @@ function returnLanguageId(code) end end +-- called by the resource counter selection dropdown +function resourceCounterSelected(_, selectedIndex, id) + local optionList = { + "enabled", + "custom", + "disabled" + } + optionPanel[id] = optionList[tonumber(selectedIndex) + 1] + print(optionPanel[id]) +end + +function returnResourceCounterId(name) + local optionList = { + "enabled", + "custom", + "disabled" + } + for index, optionName in ipairs(optionList) do + if optionName == name then + return index + end + end +end + -- sets the option panel to the correct state (corresponding to 'optionPanel') function updateOptionPanelState() for id, optionValue in pairs(optionPanel) do if id == "cardLanguage" and type(optionValue) == "string" then local dropdownId = returnLanguageId(optionValue) - 1 UI.setAttribute(id, "value", dropdownId) + elseif id == "useResourceCounters" and type(optionValue) == "string" then + local dropdownId = returnResourceCounterId(optionValue) - 1 + UI.setAttribute(id, "value", dropdownId) elseif (type(optionValue) == "boolean" and optionValue) or (type(optionValue) == "string" and optionValue) or (type(optionValue) == "table" and #optionValue ~= 0) then @@ -938,10 +965,6 @@ function applyOptionPanelChange(id, state) -- update master clue counter getObjectFromGUID("4a3aa4").setVar("useClickableCounters", state) - -- option: Clickable resource counters - elseif id == "useResourceCounters" then - optionPanel[id] = state - -- option: Play area snap tags elseif id == "playAreaSnapTags" then playAreaAPI.setLimitSnapsByType(state) diff --git a/src/core/token/TokenManager.ttslua b/src/core/token/TokenManager.ttslua index 7a8a2442..9e27b1bb 100644 --- a/src/core/token/TokenManager.ttslua +++ b/src/core/token/TokenManager.ttslua @@ -166,7 +166,9 @@ do if tokenType == "damage" or tokenType == "horror" then TokenManager.spawnCounterToken(card, tokenType, tokenCount, shiftDown) - elseif tokenType == "resource" and optionPanel["useResourceCounters"] then + elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "enabled" then + TokenManager.spawnResourceCounterToken(card, tokenCount) + elseif tokenType == "resource" and optionPanel["useResourceCounters"] == "custom" and tokenCount == 0 then TokenManager.spawnResourceCounterToken(card, tokenCount) else TokenManager.spawnMultipleTokens(card, tokenType, tokenCount, shiftDown, subType) diff --git a/xml/OptionPanel.xml b/xml/OptionPanel.xml index 8626d6a8..6f78b4f2 100644 --- a/xml/OptionPanel.xml +++ b/xml/OptionPanel.xml @@ -216,15 +216,21 @@ - + Use clickable resource tokens This enables spawning of clickable resource tokens for player cards. - - + + + + + + + +