From 40908aa78f440b3c96091272862708da82a7503c Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 29 Jun 2024 14:44:50 +0200 Subject: [PATCH 01/10] updated slot xml to allow more XML --- src/core/Global.ttslua | 5 -- src/playermat/Playermat.ttslua | 86 +++++++++++++++---------------- src/playermat/PlayermatApi.ttslua | 8 +-- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 98200319..fe16e87f 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -238,11 +238,6 @@ function onObjectNumberTyped(hoveredObject, playerColor, number) end end --- TTS event, used to redraw the playermat slot symbols after a small delay to account for the custom font loading -function onPlayerConnect() - Wait.time(function() playermatApi.redrawSlotSymbols("All") end, 0.2) -end - --------------------------------------------------------- -- chaos token drawing --------------------------------------------------------- diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index ebb7ecad..1f8ffce8 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -166,7 +166,7 @@ function onLoad(savedData) self.createButton(buttonParameters) showDrawButton(isDrawButtonVisible) - redrawSlotSymbols() + createXML() math.randomseed(os.time()) Wait.time(function() collisionEnabled = true end, 0.1) end @@ -255,13 +255,11 @@ function discardListOfObjects(objList) else deckLib.placeOrMergeIntoDeck(obj, ENCOUNTER_DISCARD_POSITION, { x = 0, y = -90, z = 0 }) end - - -- put chaos tokens back into bag (e.g. Unrelenting) elseif tokenChecker.isChaosToken(obj) then + -- put chaos tokens back into bag (e.g. Unrelenting) chaosBagApi.returnChaosTokenToBag(obj) - - -- don't touch locked objects (like the table etc.) or specific objects (like key tokens) elseif not obj.getLock() and not obj.hasTag("DontDiscard") then + -- don't touch locked objects (like the table etc.) or specific objects (like key tokens) ownedObjects.Trash.putObject(obj) end end @@ -395,19 +393,17 @@ function doUpkeep(_, clickedByColor, isRightClick) end end - local j = 0 - local k = 0 - - for i = #cardsToDiscard, 1, -1 do - j = j + 1 - Wait.time(function() deckLib.placeOrMergeIntoDeck(cardsToDiscard[i], returnGlobalDiscardPosition(), self.getRotation()) end, j * 0.1) + -- perform discarding 1 by 1 + local pos = returnGlobalDiscardPosition() + local count = #cardsToDiscard + for i = count, 1, -1 do + Wait.time(function() deckLib.placeOrMergeIntoDeck(cardsToDiscard[i], pos, rot) end, (count - i + 1) * 0.1) end -- add some time if there are any cards to discard, if not, draw up to 5 immediately - if j > 0 then - k = 0.7 + (j * 0.1) - else - k = 0 + local k = 0 + if count > 0 then + k = 0.7 + (count * 0.1) end Wait.time(function() @@ -600,15 +596,16 @@ function checkForDES() end --------------------------------------------------------- --- slot symbol displaying +-- XML creation and modifying --------------------------------------------------------- --- this will redraw the XML for the slot symbols based on the slotData table -function redrawSlotSymbols() +-- initializes the XML +function createXML() local xml = {} - local snapId = 0 + -- create a panel for each slot symbol -- use the snap point positions in the main play area for positions + local snapId = 0 for _, snap in ipairs(self.getSnapPoints()) do if inArea(snap.position, MAIN_PLAY_AREA) then snapId = snapId + 1 @@ -623,6 +620,8 @@ function redrawSlotSymbols() tag = "Panel", attributes = { id = "slotPanel" .. snapId, + raycastTarget = "false", -- this disables the click function temporarily + onClick = "slotClickFunction", scale = "0.1 0.1 1", width = "175", height = "175", @@ -646,9 +645,27 @@ function redrawSlotSymbols() end end + -- create the personal option panel + self.UI.setXmlTable(xml) end +-- updates the XML for the slot symbols based on the slotData table +function updateSlotSymbols() + for slotId, slotName in ipairs(slotData) do + -- update the symbol + self.UI.setAttributes("slot" .. slotId, { + rotation = getSlotRotation(slotName), + text = slotNameToChar[slotName] + }) + + -- update availability of the click function + self.UI.setAttribute("slotPanel" .. slotId, "raycastTarget", currentlyEditingSlots) + end + + -- TODO: update the "edit slots button"? +end + -- toggle the "slot editing mode" function toggleSlotEditing(_, clickedByColor, isRightClick) if isRightClick then @@ -660,19 +677,15 @@ function toggleSlotEditing(_, clickedByColor, isRightClick) -- toggle internal variable currentlyEditingSlots = not currentlyEditingSlots + updateSlotSymbols() if currentlyEditingSlots then - editButtonLabel("Edit Slots", "Stop editing") broadcastToColor("Click on a slot symbol (or an empty slot) to edit it.", messageColor, "Orange") - addClickFunctionToSlots() - else - editButtonLabel("Stop editing", "Edit Slots") - redrawSlotSymbols() end end -- click function for slot symbols during the "slot editing mode" -function slotClickfunction(player, _, id) +function slotClickFunction(player, _, id) local slotIndex = id:gsub("slotPanel", "") slotIndex = tonumber(slotIndex) @@ -686,12 +699,7 @@ function slotClickfunction(player, _, id) player.showOptionsDialog("Choose Slot Symbol", slotNames, slotData[slotIndex], function(chosenSlotName) slotData[slotIndex] = chosenSlotName - - -- update slot symbol - self.UI.setAttribute("slot" .. slotIndex, "text", slotNameToChar[chosenSlotName]) - - -- update slot rotation - self.UI.setAttribute("slot" .. slotIndex, "rotation", getSlotRotation(chosenSlotName)) + updateSlotSymbols() end ) end @@ -711,20 +719,7 @@ function resetSlotSymbols() for _, slotName in ipairs(defaultSlotData) do table.insert(slotData, slotName) end - - redrawSlotSymbols() - - -- need to re-add the click functions if currently in edit mode - if currentlyEditingSlots then - addClickFunctionToSlots() - end -end - --- enables the click functions for editing -function addClickFunctionToSlots() - for i = 1, #slotData do - self.UI.setAttribute("slotPanel" .. i, "onClick", "slotClickfunction") - end + updateSlotSymbols() end --------------------------------------------------------- @@ -1023,6 +1018,7 @@ function updateTexture(overrideName) self.script_state = onSave() customInfo.image = newUrl + ---@diagnostic disable-next-line: param-type-mismatch self.setCustomObject(customInfo) local reloadedMat = self.reload() diff --git a/src/playermat/PlayermatApi.ttslua b/src/playermat/PlayermatApi.ttslua index 6c77c94f..5e446a45 100644 --- a/src/playermat/PlayermatApi.ttslua +++ b/src/playermat/PlayermatApi.ttslua @@ -79,7 +79,7 @@ do PlayermatApi.loadSlotData = function(matColor, newSlotData) for _, mat in pairs(getMatForColor(matColor)) do mat.setTable("slotData", newSlotData) - mat.call("redrawSlotSymbols") + mat.call("updateSlotSymbols") return end end @@ -316,11 +316,11 @@ do end end - -- Redraws the XML for the slot symbols based on the slotData table + -- Updates the XML for the slot symbols based on the slotData table ---@param matColor string Color of the playermat - White, Orange, Green, Red or All - PlayermatApi.redrawSlotSymbols = function(matColor) + PlayermatApi.updateSlotSymbols = function(matColor) for _, mat in pairs(getMatForColor(matColor)) do - mat.call("redrawSlotSymbols") + mat.call("updateSlotSymbols") end end From f71b1d16a6c143ac84f281020abeb3fd86810b54 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sat, 29 Jun 2024 15:55:27 +0200 Subject: [PATCH 02/10] first shot at xml creation --- src/playermat/Playermat.ttslua | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 1f8ffce8..093677d7 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -7,6 +7,19 @@ local searchLib = require("util/SearchLib") local tokenChecker = require("core/token/TokenChecker") local tokenManager = require("core/token/TokenManager") +-- option panel data +local availableOptions = { + ["Personal Settings"] = { + { + id = "slotEditing", + title = "Enable Slot Edit Mode", + tooltip = "Makes each slot clickable to change the symbol.", + type = "toggle", + data = "false" + } + } +} + -- we use this to turn off collision handling until onLoad() is complete local collisionEnabled = false local currentlyEditingSlots = false @@ -646,6 +659,148 @@ function createXML() end -- create the personal option panel + local defaultsXML = { + tag = "Defaults", + children = { + { + tag = "Text", + attributes = { color = "#FFFFFF", alignment = "MiddleLeft" } + }, + { + tag = "Dropdown", + attributes = { rectAlignment = "MiddleCenter" } + }, + { + tag = "Cell", + attributes = { dontUseTableCellBackground = "true", outlineSize = "0 1", outline = "grey" } + } + } + } + table.insert(xml, defaultsXML) + + -- main window + local optionPanelXML = { + tag = "TableLayout", + attributes = { + width = "100", + height = "100", + rotation = "0 0 180", + position = "300 0 -100", + --active = "false", + color = "#000000", + outlineSize = "2 2", + outline = "grey", + showAnimation = "SlideIn_Right", + hideAnimation = "SlideOut_Right", + animationDuration = "0.2" + }, + children = { + -- header + { + tag = "Row", + attributes = { preferredHeight = "60" }, + children = { + { + tag = "Cell", + children = { + { + tag = "Panel", + attributes = { padding = "10 0 0 0", scale = "0.3 0.3" }, + children = { + { + tag = "Text", + attributes = { font = "font_teutonic-arkham", fontSize = "35", text = "Options" } + } + } + } + } + } + } + } + } + } + + -- add options groups + for groupName, groupData in pairs(availableOptions) do + -- group header + local groupXML = { + tag = "Row", + attributes = { preferredHeight = "44" }, + children = { + { + tag = "Cell", + attributes = { padding = "10 10 0 0", columnSpan = "3", color = "#222222" }, + children = { + { + tag = "Panel", + attributes = { padding = "5 0 0 0" }, + children = { + { + tag = "Text", + attributes = { fontSize = "28", font = "font_teutonic-arkham", text = groupName } + } + } + } + } + } + } + } + + -- options + for i, optionData in ipairs(groupData) do + local optionXML = { + { + tag = "Row", + attributes = { preferredHeight = "50", tooltip = optionData.tooltip, tooltipPosition = "Left", tooltipBackgroundColor = "rgba(0,0,0,1)" }, + children = { + -- option title + { + tag = "Cell", + attributes = { padding = "10 10 5 5", color = "#333333", columnSpan = "2" }, + children = { + { + tag = "Panel", + attributes = { padding = "10 0 0 0" }, + children = { + { + tag = "Text", + attributes = { fontSize = "22", font = "font_teutonic-arkham", text = optionData.title } + } + } + } + } + }, + -- option button + { + tag = "Cell", + attributes = { padding = "10 10 5 5", color = "#333333" }, + children = { + { + tag = "Button", + attributes = { + id = optionData.id, + image = "option-off", + onClick="onClick_toggleOption", + rectAlignment = "MiddleRight", + offsetXY = "-30 0", + colors = "#FFFFFF|#dfdfdf", + height = "36", + width = "65", + ignoreLayout = "True" + } + } + } + } + } + } + } + table.insert(groupXML, optionXML) + end + table.insert(optionPanelXML, groupXML) + end + table.insert(xml, optionPanelXML) + + -- create buttons at the bottom self.UI.setXmlTable(xml) end From 9eb2c0c1caa69aa3cb24a8a1a7ed3614c622ccea Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Sun, 30 Jun 2024 00:20:21 +0200 Subject: [PATCH 03/10] Xml editing --- objects/Playermat1White.8b081b.json | 12 ++++++++++++ objects/Playermat2Orange.bd0ff4.json | 12 ++++++++++++ objects/Playermat3Green.383d8b.json | 12 ++++++++++++ objects/Playermat4Red.0840d5.json | 12 ++++++++++++ src/playermat/Playermat.ttslua | 19 ++++++++++--------- 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/objects/Playermat1White.8b081b.json b/objects/Playermat1White.8b081b.json index 0eaea951..a87403af 100644 --- a/objects/Playermat1White.8b081b.json +++ b/objects/Playermat1White.8b081b.json @@ -342,6 +342,18 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", "WidthScale": 0 }, + "CustomUIAsset": [ + { + "Name": "option-on", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + }, + { + "Name": "option-off", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + } + ], "Description": "", "DragSelectable": true, "GMNotes": "", diff --git a/objects/Playermat2Orange.bd0ff4.json b/objects/Playermat2Orange.bd0ff4.json index d2fb2b64..d688bea9 100644 --- a/objects/Playermat2Orange.bd0ff4.json +++ b/objects/Playermat2Orange.bd0ff4.json @@ -342,6 +342,18 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", "WidthScale": 0 }, + "CustomUIAsset": [ + { + "Name": "option-on", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + }, + { + "Name": "option-off", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + } + ], "Description": "", "DragSelectable": true, "GMNotes": "", diff --git a/objects/Playermat3Green.383d8b.json b/objects/Playermat3Green.383d8b.json index 41f250bc..c8778deb 100644 --- a/objects/Playermat3Green.383d8b.json +++ b/objects/Playermat3Green.383d8b.json @@ -342,6 +342,18 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", "WidthScale": 0 }, + "CustomUIAsset": [ + { + "Name": "option-on", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + }, + { + "Name": "option-off", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + } + ], "Description": "", "DragSelectable": true, "GMNotes": "", diff --git a/objects/Playermat4Red.0840d5.json b/objects/Playermat4Red.0840d5.json index c76a35b0..91ce61ea 100644 --- a/objects/Playermat4Red.0840d5.json +++ b/objects/Playermat4Red.0840d5.json @@ -342,6 +342,18 @@ "ImageURL": "http://cloud-3.steamusercontent.com/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", "WidthScale": 0 }, + "CustomUIAsset": [ + { + "Name": "option-on", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + }, + { + "Name": "option-off", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + } + ], "Description": "", "DragSelectable": true, "GMNotes": "", diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 093677d7..6aeefc4f 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -8,7 +8,7 @@ local tokenChecker = require("core/token/TokenChecker") local tokenManager = require("core/token/TokenManager") -- option panel data -local availableOptions = { +local availableOptions = { ["Personal Settings"] = { { id = "slotEditing", @@ -682,8 +682,9 @@ function createXML() local optionPanelXML = { tag = "TableLayout", attributes = { - width = "100", - height = "100", + scale = "0.2 0.2", + width = "600", + height = "600", rotation = "0 0 180", position = "300 0 -100", --active = "false", @@ -698,7 +699,7 @@ function createXML() -- header { tag = "Row", - attributes = { preferredHeight = "60" }, + --attributes = { preferredHeight = "60" }, children = { { tag = "Cell", @@ -725,7 +726,7 @@ function createXML() -- group header local groupXML = { tag = "Row", - attributes = { preferredHeight = "44" }, + --attributes = { preferredHeight = "44" }, children = { { tag = "Cell", @@ -751,7 +752,7 @@ function createXML() local optionXML = { { tag = "Row", - attributes = { preferredHeight = "50", tooltip = optionData.tooltip, tooltipPosition = "Left", tooltipBackgroundColor = "rgba(0,0,0,1)" }, + --attributes = { preferredHeight = "50", tooltip = optionData.tooltip, tooltipPosition = "Left", tooltipBackgroundColor = "rgba(0,0,0,1)" }, children = { -- option title { @@ -780,7 +781,7 @@ function createXML() attributes = { id = optionData.id, image = "option-off", - onClick="onClick_toggleOption", + onClick = "onClick_toggleOption", rectAlignment = "MiddleRight", offsetXY = "-30 0", colors = "#FFFFFF|#dfdfdf", @@ -794,9 +795,9 @@ function createXML() } } } - table.insert(groupXML, optionXML) + table.insert(groupXML.children, optionXML) end - table.insert(optionPanelXML, groupXML) + table.insert(optionPanelXML.children, groupXML) end table.insert(xml, optionPanelXML) From 004733459201ce44f7c9b6999031eae5a59853a1 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Fri, 2 Aug 2024 11:53:36 +0200 Subject: [PATCH 04/10] updated option panel --- objects/Playermat1White.8b081b.json | 8 +- objects/Playermat2Orange.bd0ff4.json | 8 +- objects/Playermat3Green.383d8b.json | 8 +- objects/Playermat4Red.0840d5.json | 8 +- src/accessories/HandHelper.ttslua | 15 --- src/core/Global.ttslua | 4 +- src/playermat/Playermat.ttslua | 164 +++++++++++++++------------ xml/Global/OptionPanel.xml | 46 +++----- 8 files changed, 127 insertions(+), 134 deletions(-) diff --git a/objects/Playermat1White.8b081b.json b/objects/Playermat1White.8b081b.json index 9ce12145..b7f3b111 100644 --- a/objects/Playermat1White.8b081b.json +++ b/objects/Playermat1White.8b081b.json @@ -344,14 +344,14 @@ }, "CustomUIAsset": [ { - "Name": "option-on", + "Name": "option_on", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" }, { - "Name": "option-off", + "Name": "option_off", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" } ], "Description": "", diff --git a/objects/Playermat2Orange.bd0ff4.json b/objects/Playermat2Orange.bd0ff4.json index 95758e21..c80d0d3d 100644 --- a/objects/Playermat2Orange.bd0ff4.json +++ b/objects/Playermat2Orange.bd0ff4.json @@ -344,14 +344,14 @@ }, "CustomUIAsset": [ { - "Name": "option-on", + "Name": "option_on", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" }, { - "Name": "option-off", + "Name": "option_off", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" } ], "Description": "", diff --git a/objects/Playermat3Green.383d8b.json b/objects/Playermat3Green.383d8b.json index 777740fb..40179bdd 100644 --- a/objects/Playermat3Green.383d8b.json +++ b/objects/Playermat3Green.383d8b.json @@ -344,14 +344,14 @@ }, "CustomUIAsset": [ { - "Name": "option-on", + "Name": "option_on", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" }, { - "Name": "option-off", + "Name": "option_off", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" } ], "Description": "", diff --git a/objects/Playermat4Red.0840d5.json b/objects/Playermat4Red.0840d5.json index ffdfedb1..24942a4c 100644 --- a/objects/Playermat4Red.0840d5.json +++ b/objects/Playermat4Red.0840d5.json @@ -344,14 +344,14 @@ }, "CustomUIAsset": [ { - "Name": "option-on", + "Name": "option_on", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668997008/2178787B67B3C96F3419EDBAB8420E39893756BC/" }, { - "Name": "option-off", + "Name": "option_off", "Type": 0, - "URL": "http://cloud-3.steamusercontent.com/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" + "URL": "https://steamusercontent-a.akamaihd.net/ugc/2462982115668996901/D6438ECBB11DECC6DB9987589FF526FBAD4D2368/" } ], "Description": "", diff --git a/src/accessories/HandHelper.ttslua b/src/accessories/HandHelper.ttslua index d67e73bf..cce2209e 100644 --- a/src/accessories/HandHelper.ttslua +++ b/src/accessories/HandHelper.ttslua @@ -24,16 +24,6 @@ function onLoad() buttonParamaters.font_size = 120 self.createButton(buttonParamaters) - -- index 2: button to discard a card - buttonParamaters.label = "Discard Random Card" - buttonParamaters.click_function = "discardRandom" - buttonParamaters.position.z = 0.7 - buttonParamaters.height = 175 - buttonParamaters.width = 900 - buttonParamaters.font_size = 90 - buttonParamaters.font_color = "Black" - self.createButton(buttonParamaters) - -- make sure this part executes after the playermats are loaded Wait.time(function() updateColors() @@ -117,8 +107,3 @@ function updateValue() -- update button label and color self.editButton({ index = 0, font_color = hasDES and "Green" or "White", label = size }) end - --- discards a random non-hidden card from hand -function discardRandom() - playermatApi.doDiscardOne(matColor) -end diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index d273d4f0..e0d4cb03 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -267,8 +267,8 @@ function onObjectNumberTyped(hoveredObject, playerColor, number) end end --- TTS event, used to redraw the playermat slot symbols after a small delay to account for the custom font loading -function onPlayerConnect() +-- TTS event, used to redraw the playermat slot symbols after a delay to account for the custom font loading +function onPlayerChangeColor() Wait.time(function() playermatApi.redrawSlotSymbols("All") end, 0.2) end diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 5787b577..5f766159 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -10,17 +10,20 @@ local tokenSpawnTrackerApi = require("core/token/TokenSpawnTrackerApi") -- option panel data local availableOptions = { - ["Personal Settings"] = { + ["PERSONAL SETTINGS"] = { { - id = "slotEditing", - title = "Enable Slot Edit Mode", + id = "slotEditing", + title = "Enable Slot Edit Mode", tooltip = "Makes each slot clickable to change the symbol.", - type = "toggle", - data = "false" + type = "toggle" } } } +-- stores the value for each id +local optionPanelData = {} +optionPanelData.slotEditing = false + -- we use this to turn off collision handling until onLoad() is complete local collisionEnabled = false local currentlyEditingSlots = false @@ -77,24 +80,24 @@ local buttonParameters = { -- table of texture URLs local nameToTexture = { Guardian = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241599869/179119CA88170D9F5C87CD00D267E6F9F397D2F7/", - Mystic = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600113/F6473F92B3435C32A685BB4DC2A88C2504DDAC4F/", - Neutral = "https://steamusercontent-a.akamaihd.net/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", - Rogue = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600395/00CFAFC13D7B6EACC147D22A40AF9FBBFFAF3136/", - Seeker = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600579/92DEB412D8D3A9C26D1795CEA0335480409C3E4B/", + Mystic = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600113/F6473F92B3435C32A685BB4DC2A88C2504DDAC4F/", + Neutral = "https://steamusercontent-a.akamaihd.net/ugc/2462982115659543571/5D778EA4BC682DAE97E8F59A991BCF8CB3979B04/", + Rogue = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600395/00CFAFC13D7B6EACC147D22A40AF9FBBFFAF3136/", + Seeker = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600579/92DEB412D8D3A9C26D1795CEA0335480409C3E4B/", Survivor = "https://steamusercontent-a.akamaihd.net/ugc/2501268517241600848/CEB685E9C8A4A3C18A4B677A519B49423B54E886/" } -- translation table for slot names to characters for special font local slotNameToChar = { - ["any"] = "", - ["Accessory"] = "C", - ["Ally"] = "E", - ["Arcane"] = "G", - ["Body"] = "K", + ["any"] = "", + ["Accessory"] = "C", + ["Ally"] = "E", + ["Arcane"] = "G", + ["Body"] = "K", ["Hand (right)"] = "M", - ["Hand (left)"] = "M", - ["Hand x2"] = "N", - ["Tarot"] = "A" + ["Hand (left)"] = "M", + ["Hand x2"] = "N", + ["Tarot"] = "A" } -- slot symbol for the respective slot (from top left to bottom right) - intentionally global! @@ -120,13 +123,18 @@ local ownedObjects = {} local matColor = self.getMemo() function onSave() + log(optionPanelData) + log(type(optionPanelData)) + log(optionPanelData.slotEditing) + return JSON.encode({ activeInvestigatorClass = activeInvestigatorClass, - activeInvestigatorId = activeInvestigatorId, - isClassTextureEnabled = isClassTextureEnabled, - isDrawButtonVisible = isDrawButtonVisible, - playerColor = playerColor, - slotData = slotData + activeInvestigatorId = activeInvestigatorId, + isClassTextureEnabled = isClassTextureEnabled, + isDrawButtonVisible = isDrawButtonVisible, + optionPanelData = optionPanelData, + playerColor = playerColor, + slotData = slotData }) end @@ -137,6 +145,7 @@ function onLoad(savedData) activeInvestigatorId = loadedData.activeInvestigatorId isClassTextureEnabled = loadedData.isClassTextureEnabled isDrawButtonVisible = loadedData.isDrawButtonVisible + --optionPanelData = loadedData.optionPanelData playerColor = loadedData.playerColor slotData = loadedData.slotData end @@ -174,10 +183,10 @@ function onLoad(savedData) -- Upkeep button: can use the default parameters for this self.createButton(buttonParameters) - -- Slot editing button: modified default data - buttonParameters.label = "Edit Slots" - buttonParameters.click_function = "toggleSlotEditing" - buttonParameters.tooltip = "Right-click to reset slot symbols" + -- Discard 1 button: modified default data + buttonParameters.label = "Discard 1" + buttonParameters.click_function = "doDiscardOne" + buttonParameters.tooltip = "Discard one random card from hand (hidden cards are excluded)." buttonParameters.position.z = 0.92 self.createButton(buttonParameters) @@ -239,18 +248,6 @@ function round(num, numDecimalPlaces) return math.floor(num * mult + 0.5) / mult end --- edits the label of a button ----@param oldLabel string Old label of the button ----@param newLabel string New label of the button -function editButtonLabel(oldLabel, newLabel) - local buttons = self.getButtons() - for i = 1, #buttons do - if buttons[i].label == oldLabel then - self.editButton({ index = buttons[i].index, label = newLabel }) - end - end -end - -- updates the internal "messageColor" which is used for print/broadcast statements if no player is seated ---@param clickedByColor string Colorstring of player who clicked a button function updateMessageColor(clickedByColor) @@ -258,7 +255,7 @@ function updateMessageColor(clickedByColor) end --------------------------------------------------------- --- Discard buttons +-- Discard buttons (threat area) --------------------------------------------------------- -- handles discarding for a list of objects @@ -418,7 +415,8 @@ function doUpkeep(_, clickedByColor, isRightClick) -- draw up to 5 cards local cardsToDraw = 5 - #handCards + #cardsToDiscard if cardsToDraw > 0 then - printToColor("Discarding " .. #cardsToDiscard .. " and drawing " .. cardsToDraw .. " card(s). (Patrice)", messageColor) + printToColor("Discarding " .. #cardsToDiscard .. " and drawing " .. cardsToDraw .. " card(s). (Patrice)", + messageColor) -- add some time if there are any cards to discard local k = 0 @@ -608,9 +606,12 @@ function doDiscardOne() -- get a random eligible card (from the "choices" table) local num = math.random(1, #choices) - deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation()) - broadcastToAll(getColoredName(playerColor) .. " randomly discarded card " - .. choices[num] .. "/" .. #hand .. ".", "White") + local card = hand[choices[num]] + local cardName = card.getName() + local cardId = choices[num] .. "/" .. #hand + + deckLib.placeOrMergeIntoDeck(card, returnGlobalDiscardPosition(), self.getRotation()) + broadcastToAll(getColoredName(playerColor) .. " randomly discarded " .. cardName " (" .. cardId .. ").", "White") end end @@ -714,18 +715,23 @@ function createXML() } table.insert(xml, defaultsXML) + -- work out the position + local bounds = self.getBoundsNormalized() + local setAsideDirection = bounds.center.z > 0 and 1 or -1 + -- main window local optionPanelXML = { tag = "TableLayout", attributes = { - scale = "0.2 0.2", - width = "600", - height = "600", + scale = "0.11 0.11", + width = "1000", + height = "1200", rotation = "0 0 180", - position = "300 0 -100", + position = (setAsideDirection * 270) .. " -35 -58", --active = "false", + raycastTarget = "true", color = "#000000", - outlineSize = "2 2", + outlineSize = "5 5", outline = "grey", showAnimation = "SlideIn_Right", hideAnimation = "SlideOut_Right", @@ -735,18 +741,18 @@ function createXML() -- header { tag = "Row", - --attributes = { preferredHeight = "60" }, + attributes = { preferredHeight = "200" }, children = { { tag = "Cell", children = { { tag = "Panel", - attributes = { padding = "10 0 0 0", scale = "0.3 0.3" }, + attributes = { padding = "30 0 0 0" }, children = { { tag = "Text", - attributes = { font = "font_teutonic-arkham", fontSize = "35", text = "Options" } + attributes = { font = "font_teutonic-arkham", fontSize = "110", text = "Options" } } } } @@ -762,19 +768,19 @@ function createXML() -- group header local groupXML = { tag = "Row", - --attributes = { preferredHeight = "44" }, + attributes = { preferredHeight = "150" }, children = { { tag = "Cell", - attributes = { padding = "10 10 0 0", columnSpan = "3", color = "#222222" }, + attributes = { padding = "20 10 0 0", columnSpan = "3", color = "#222222" }, children = { { tag = "Panel", - attributes = { padding = "5 0 0 0" }, + attributes = { padding = "40 0 0 0" }, children = { { tag = "Text", - attributes = { fontSize = "28", font = "font_teutonic-arkham", text = groupName } + attributes = { fontSize = "75", font = "font_teutonic-arkham", text = groupName } } } } @@ -782,26 +788,30 @@ function createXML() } } } + table.insert(optionPanelXML.children, groupXML) -- options - for i, optionData in ipairs(groupData) do - local optionXML = { - { + for _, optionData in ipairs(groupData) do + local optionXML = {} + if optionData.type ~= "toggle" then + log("This isn't implemented yet ;)") + else + optionXML = { tag = "Row", - --attributes = { preferredHeight = "50", tooltip = optionData.tooltip, tooltipPosition = "Left", tooltipBackgroundColor = "rgba(0,0,0,1)" }, + attributes = { preferredHeight = "150", tooltip = optionData.tooltip, tooltipPosition = "Left", tooltipBackgroundColor = "rgba(0,0,0,1)" }, children = { -- option title { tag = "Cell", - attributes = { padding = "10 10 5 5", color = "#333333", columnSpan = "2" }, + attributes = { padding = "20 10 5 5", color = "#333333", columnSpan = "2" }, children = { { tag = "Panel", - attributes = { padding = "10 0 0 0" }, + attributes = { padding = "50 0 0 0" }, children = { { tag = "Text", - attributes = { fontSize = "22", font = "font_teutonic-arkham", text = optionData.title } + attributes = { fontSize = "65", font = "font_teutonic-arkham", text = optionData.title } } } } @@ -816,13 +826,13 @@ function createXML() tag = "Button", attributes = { id = optionData.id, - image = "option-off", + image = optionData.data == true and "option_on" or "option_off", onClick = "onClick_toggleOption", rectAlignment = "MiddleRight", offsetXY = "-30 0", colors = "#FFFFFF|#dfdfdf", - height = "36", - width = "65", + height = "72", + width = "130", ignoreLayout = "True" } } @@ -830,18 +840,30 @@ function createXML() } } } - } - table.insert(groupXML.children, optionXML) + end + table.insert(optionPanelXML.children, optionXML) end - table.insert(optionPanelXML.children, groupXML) end table.insert(xml, optionPanelXML) - - -- create buttons at the bottom - self.UI.setXmlTable(xml) end +-- changes the UI state and the internal variable for the togglebuttons +function onClick_toggleOption(player, _, id) + local state = optionPanelData[id] + local newState = not state + applyOptionPanelChange(id, newState, player.color) + self.UI.setAttribute(id, "image", newState and "option_on" or "option_off") +end + +function applyOptionPanelChange(id, state, clickedByColor) + optionPanelData[id] = state + + if id == "slotEditing" then + toggleSlotEditing(_, clickedByColor) + end +end + -- updates the XML for the slot symbols based on the slotData table function updateSlotSymbols() for slotId, slotName in ipairs(slotData) do diff --git a/xml/Global/OptionPanel.xml b/xml/Global/OptionPanel.xml index 6530366b..49f7fb68 100644 --- a/xml/Global/OptionPanel.xml +++ b/xml/Global/OptionPanel.xml @@ -63,6 +63,7 @@ padding="0 17 3 3"/>