From 5a71eda9a70da3b67e0f6cb63aa77a1d861e7008 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Fri, 2 Dec 2022 01:17:19 +0100 Subject: [PATCH 01/16] initial commit optionpanel (WORK IN PROGRESS) --- modsettings/CustomUIAssets.json | 7 +- objects/Root.xml | 119 +++++++++++++++++++------------- src/core/Global.ttslua | 54 +++++++++++---- 3 files changed, 119 insertions(+), 61 deletions(-) diff --git a/modsettings/CustomUIAssets.json b/modsettings/CustomUIAssets.json index bf393bb2..71b8b9eb 100644 --- a/modsettings/CustomUIAssets.json +++ b/modsettings/CustomUIAssets.json @@ -43,5 +43,10 @@ "Name": "OverlaySmall", "Type": 0, "URL": "http://cloud-3.steamusercontent.com/ugc/1745699502804112719/CFFC89BF9FB8439204EE19CF94180EC99450CD38/" + }, + { + "Name": "option-gear", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2026086584372569912/5CB461AEAE2E59D3064D90A776EB86C46081EC78/" } -] +] \ No newline at end of file diff --git a/objects/Root.xml b/objects/Root.xml index 9b7059b8..0ea616c5 100644 --- a/objects/Root.xml +++ b/objects/Root.xml @@ -1,65 +1,90 @@ + - + + + - + + + + + + + + + + \ No newline at end of file diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 2e0a201e..74758332 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -558,14 +558,10 @@ local source_repo = 'https://raw.githubusercontent.com/seth-sced/loadable-object local library = nil local request_obj -function onClick_toggleUi(player, window) - toggle_ui(window) -end - function onClick_refreshList() local request = WebRequest.get(source_repo .. '/library.json', completed_list_update) request_obj = request - startLuaCoroutine(Global, 'my_coroutine') + startLuaCoroutine(Global, 'downloadCoroutine') end function onClick_select(player, params) @@ -573,7 +569,7 @@ function onClick_select(player, params) local url = source_repo .. '/' .. params.url local request = WebRequest.get(url, function (request) complete_obj_download(request, params) end ) request_obj = request - startLuaCoroutine(Global, 'my_coroutine') + startLuaCoroutine(Global, 'downloadCoroutine') end function onClick_load() @@ -581,18 +577,50 @@ function onClick_load() UI.hide('load_button') end -function toggle_ui(title) - UI.hide('load_ui') - if UI.getValue('title') == title or title == 'Hidden' then - UI.setValue('title', 'Hidden') +function onClick_defaultSettings() + print("Dummy: Load default settings") +end + +local optionPanel = {} +function onClick_toggleOption(_, id) + local state = self.UI.getAttribute("toggle" .. id, "isOn") + + -- flip state (and handle stupid "False" value) + if state == "False" then + state = true else + state = false + end + + self.UI.setAttribute("toggle" .. id, "isOn", state) + optionPanel[id] = state + print("Option no. " .. id .. ": " .. tostring(optionPanel[id])) +end + +function onClick_applySettings() + print("Dummy: Apply settings") +end + +function onClick_toggleUi(_, title) + UI.hide('optionPanel') + UI.hide('load_ui') + + -- when same button is clicked or close window button is pressed, don't open UI + if UI.getValue('title') ~= title and title ~= 'Hidden' then UI.setValue('title', title) - update_window_content(title) - UI.show('load_ui') + + if title == "Option Panel" then + UI.show('optionPanel') + else + update_window_content(title) + UI.show('load_ui') + end + else + UI.setValue('title', "Hidden") end end -function my_coroutine() +function downloadCoroutine() while request_obj do UI.setAttribute('download_progress', 'percentage', request_obj.download_progress * 100) coroutine.yield(0) From 12a71894d8a55e9d0c868bc038d6bd8dc9d4de54 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 6 Dec 2022 20:10:09 +0100 Subject: [PATCH 02/16] moved xml to dedicated folder, save function added --- config.json | 4 ++-- src/core/Global.ttslua | 23 +++++++++++++++++++++-- objects/Root.xml => xml/Global.xml | 0 3 files changed, 23 insertions(+), 4 deletions(-) rename objects/Root.xml => xml/Global.xml (100%) diff --git a/config.json b/config.json index afbade21..f3b6e45c 100644 --- a/config.json +++ b/config.json @@ -22,7 +22,7 @@ }, "Lighting_path": "Lighting.json", "LuaScript": "require(\"core/Global\")", - "LuaScriptState": "", + "LuaScriptState": "[]", "MusicPlayer_path": "MusicPlayer.json", "Note": "", "ObjectStates_order": [ @@ -266,5 +266,5 @@ "Tags": [], "Turns_path": "Turns.json", "VersionNumber": "v13.2.2", - "XmlUI_path": "Root.xml" + "XmlUI": "" } diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 74758332..be3f299a 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -5,6 +5,9 @@ ENCOUNTER_DECK_POS = {-3.93, 1, 5.76} ENCOUNTER_DECK_DISCARD_POSITION = {-3.85, 1, 10.38} +-- optionPanel data +optionPanel = {} + -- GUID of data helper DATA_HELPER_GUID = "708279" @@ -125,10 +128,27 @@ local overallStats = { -- general code --------------------------------------------------------- -function onLoad() +-- saving state of optionPanel to restore later +function onSave() return JSON.encode(optionPanel) end + +function onLoad(savedData) + if savedData then + optionPanel = JSON.decode(savedData) + for id, enabled in pairs(optionPanel) do + if enabled then + self.UI.setAttribute("toggle" .. id, "isOn", true) + end + end + else + for i = 1, 8 do + optionPanel[i] = false + end + end + for _, guid in ipairs(NOT_INTERACTABLE) do getObjectFromGUID(guid).interactable = false end + math.randomseed(os.time()) end @@ -581,7 +601,6 @@ function onClick_defaultSettings() print("Dummy: Load default settings") end -local optionPanel = {} function onClick_toggleOption(_, id) local state = self.UI.getAttribute("toggle" .. id, "isOn") diff --git a/objects/Root.xml b/xml/Global.xml similarity index 100% rename from objects/Root.xml rename to xml/Global.xml From ce8e6815a5e2f7a15d29aeebd60d2fa524738839 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 6 Dec 2022 20:57:33 +0100 Subject: [PATCH 03/16] xml cleanup --- src/core/Global.ttslua | 10 +-- xml/Global.xml | 136 ++++++++++++++++++++++------------------- 2 files changed, 78 insertions(+), 68 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index be3f299a..e92fe345 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -135,9 +135,7 @@ function onLoad(savedData) if savedData then optionPanel = JSON.decode(savedData) for id, enabled in pairs(optionPanel) do - if enabled then - self.UI.setAttribute("toggle" .. id, "isOn", true) - end + if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end end else for i = 1, 8 do @@ -613,11 +611,13 @@ function onClick_toggleOption(_, id) self.UI.setAttribute("toggle" .. id, "isOn", state) optionPanel[id] = state - print("Option no. " .. id .. ": " .. tostring(optionPanel[id])) end function onClick_applySettings() - print("Dummy: Apply settings") + print("Enabling following settings:") + for id, value in pairs(optionPanel) do + if value then print(id) end + end end function onClick_toggleUi(_, title) diff --git a/xml/Global.xml b/xml/Global.xml index 0ea616c5..a55724e3 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -11,80 +11,90 @@ - + + + - - - - - - + + + + + + + - - - + + + \ No newline at end of file From 43315aefcc8f50560d45aff591b05c702ab324de Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 4 Dec 2022 01:21:53 -0800 Subject: [PATCH 04/16] Add method to enable or disable card type snap point tagging on a playmat This uses the new object API concept to provide a layer of indirection between an object and others which might call() to methods on it. Example usage: local playmatApi = require("playermat/PlaymatApi") playmatApi.setLimitSnapsByType(tag, "All") --- src/playermat/Playmat.ttslua | 73 ++++++++++++++++++++++++++++++++- src/playermat/PlaymatApi.ttslua | 48 ++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/playermat/PlaymatApi.ttslua diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index c7e67f26..eb02f89a 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -1,5 +1,5 @@ -- set true to enable debug logging and show Physics.cast() -local DEBUG = false +local DEBUG = true -- we use this to turn off collision handling until onLoad() is complete local COLLISION_ENABLED = false @@ -16,6 +16,27 @@ local DISCARD_BUTTON_OFFSETS = { {0.91, 0.1, -0.945} } +local MAIN_PLAY_AREA = { + upperLeft = { + x = 1.98, + z = 0.736, + }, + lowerRight = { + x = -0.79, + z = -0.39, + } +} +local INVESTIGATOR_AREA = { + upperLeft = { + x = -1.084, + z = 0.06517 + }, + lowerRight = { + x = -1.258, + z = -0.0805, + } +} + local PLAY_ZONE_ROTATION = self.getRotation() local TRASHCAN @@ -627,6 +648,56 @@ function spawnToken(position, tokenType) Global.call('spawnToken', {position, tokenType, PLAY_ZONE_ROTATION}) end +-- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes +-- is true, the main card slot snap points will only snap assets, while the investigator area point +-- will only snap Investigators. If matchTypes is false, snap points will be reset to snap all +-- cards. +-- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. +function setLimitSnapsByType(params) + local matchTypes = params.matchTypes + if matchTypes then + log("Set true") + else + log("Set false") + end + local snaps = self.getSnapPoints() + for i, snap in ipairs(snaps) do + local snapPos = snap.position + if inArea(snapPos, MAIN_PLAY_AREA) then + local snapTags = snaps[i].tags + if matchTypes then + if snapTags == nil then + snaps[i].tags = { "Asset" } + else + table.insert(snaps[i].tags, "Asset") + end + else + snaps[i].tags = nil + end + end + if inArea(snapPos, INVESTIGATOR_AREA) then + local snapTags = snaps[i].tags + if matchTypes then + if snapTags == nil then + snaps[i].tags = { "Investigator" } + else + table.insert(snaps[i].tags, "Investigator") + end + else + snaps[i].tags = nil + end + end + end + self.setSnapPoints(snaps) +end + +function inArea(point, bounds) + return (point.x < bounds.upperLeft.x + and point.x > bounds.lowerRight.x + and point.z < bounds.upperLeft.z + and point.z > bounds.lowerRight.z) +end + -- called by custom data helpers to add player card data ---@param args table Contains only one entry, the GUID of the custom data helper function updatePlayerCards(args) diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua new file mode 100644 index 00000000..b1197809 --- /dev/null +++ b/src/playermat/PlaymatApi.ttslua @@ -0,0 +1,48 @@ +do + local PlaymatApi = { } + local internal = { } + + local WHITE_MAT_GUID = "8b081b" + local ORANGE_MAT_GUID = "bd0ff4" + local GREEN_MAT_GUID = "383d8b" + local RED_MAT_GUID = "0840d5" + + -- Sets the requested playermat's snap points to limit snapping to matching card types or not. If + -- matchTypes is true, the main card slot snap points will only snap assets, while the + -- investigator area point will only snap Investigators. If matchTypes is false, snap points will + -- be reset to snap all cards. + -- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. + -- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also + -- accepts "All" as a special value which will apply the setting to all four mats. + PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor) + for _, mat in ipairs(internal.getMatForColor(matColor)) do + mat.call("setLimitSnapsByType", { matchTypes = matchCardTypes }) + end + end + + -- Convenience function to look up a mat's object by color, or get all mats. + -- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also + -- accepts "All" as a special value which will return all four mats. + -- @return Array of playermat objects. If a single mat is requested, will return a single-element + -- array to simplify processing by consumers. + internal.getMatForColor = function(matColor) + if matColor == "White" then + return { getObjectFromGUID(WHITE_MAT_GUID) } + elseif matColor == "Orange" then + return { getObjectFromGUID(ORANGE_MAT_GUID) } + elseif matColor == "Green" then + return { getObjectFromGUID(GREEN_MAT_GUID) } + elseif matColor == "Red" then + return { getObjectFromGUID(RED_MAT_GUID) } + elseif matColor == "All" then + return { + getObjectFromGUID(WHITE_MAT_GUID), + getObjectFromGUID(ORANGE_MAT_GUID), + getObjectFromGUID(GREEN_MAT_GUID), + getObjectFromGUID(RED_MAT_GUID), + } + end + end + + return PlaymatApi +end From bd89174377d972aabb92ed06ed6917538f28fd88 Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 4 Dec 2022 01:29:02 -0800 Subject: [PATCH 05/16] Expanded documentation and remove old log messages --- src/playermat/Playmat.ttslua | 14 +++++++------- src/playermat/PlaymatApi.ttslua | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index eb02f89a..27d5f525 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -1,5 +1,5 @@ -- set true to enable debug logging and show Physics.cast() -local DEBUG = true +local DEBUG = false -- we use this to turn off collision handling until onLoad() is complete local COLLISION_ENABLED = false @@ -655,11 +655,6 @@ end -- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. function setLimitSnapsByType(params) local matchTypes = params.matchTypes - if matchTypes then - log("Set true") - else - log("Set false") - end local snaps = self.getSnapPoints() for i, snap in ipairs(snaps) do local snapPos = snap.position @@ -691,7 +686,12 @@ function setLimitSnapsByType(params) self.setSnapPoints(snaps) end -function inArea(point, bounds) +-- Simple method to check if the given point is in a specified area. Local use only, +-- @param point Vector. Point to check, only x and z values are relevant +-- @param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample +-- bounds definition. +-- @return Boolean. True if the point is in the area defined by bounds +local function inArea(point, bounds) return (point.x < bounds.upperLeft.x and point.x > bounds.lowerRight.x and point.z < bounds.upperLeft.z diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index b1197809..d3421ffb 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -11,7 +11,8 @@ do -- matchTypes is true, the main card slot snap points will only snap assets, while the -- investigator area point will only snap Investigators. If matchTypes is false, snap points will -- be reset to snap all cards. - -- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. + -- @param matchCardTypes Boolean. Whether snap points should only snap for the matching card + -- types. -- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will apply the setting to all four mats. PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor) From 5231609f442a51f40ea202e86a434999b233b716 Mon Sep 17 00:00:00 2001 From: Buhallin Date: Sun, 4 Dec 2022 14:49:34 -0800 Subject: [PATCH 06/16] Add some cleanup for playmat snap type setting, as well as a get() method to return the current state --- src/playermat/Playmat.ttslua | 5 ++--- src/playermat/PlaymatApi.ttslua | 34 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 27d5f525..c9731451 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -653,8 +653,7 @@ end -- will only snap Investigators. If matchTypes is false, snap points will be reset to snap all -- cards. -- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. -function setLimitSnapsByType(params) - local matchTypes = params.matchTypes +function setLimitSnapsByType(matchTypes) local snaps = self.getSnapPoints() for i, snap in ipairs(snaps) do local snapPos = snap.position @@ -691,7 +690,7 @@ end -- @param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample -- bounds definition. -- @return Boolean. True if the point is in the area defined by bounds -local function inArea(point, bounds) +function inArea(point, bounds) return (point.x < bounds.upperLeft.x and point.x > bounds.lowerRight.x and point.z < bounds.upperLeft.z diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index d3421ffb..489387e4 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -2,10 +2,12 @@ do local PlaymatApi = { } local internal = { } - local WHITE_MAT_GUID = "8b081b" - local ORANGE_MAT_GUID = "bd0ff4" - local GREEN_MAT_GUID = "383d8b" - local RED_MAT_GUID = "0840d5" + local MAT_IDS = { + White = "8b081b", + Orange = "bd0ff4", + Green = "383d8b", + Red = "0840d5", + } -- Sets the requested playermat's snap points to limit snapping to matching card types or not. If -- matchTypes is true, the main card slot snap points will only snap assets, while the @@ -17,7 +19,7 @@ do -- accepts "All" as a special value which will apply the setting to all four mats. PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor) for _, mat in ipairs(internal.getMatForColor(matColor)) do - mat.call("setLimitSnapsByType", { matchTypes = matchCardTypes }) + mat.call("setLimitSnapsByType", matchCardTypes) end end @@ -27,20 +29,16 @@ do -- @return Array of playermat objects. If a single mat is requested, will return a single-element -- array to simplify processing by consumers. internal.getMatForColor = function(matColor) - if matColor == "White" then - return { getObjectFromGUID(WHITE_MAT_GUID) } - elseif matColor == "Orange" then - return { getObjectFromGUID(ORANGE_MAT_GUID) } - elseif matColor == "Green" then - return { getObjectFromGUID(GREEN_MAT_GUID) } - elseif matColor == "Red" then - return { getObjectFromGUID(RED_MAT_GUID) } - elseif matColor == "All" then + local targetMatGuid = MAT_IDS[matColor] + if targetMatGuid != nil then + return { getObjectFromGUID(targetMatGuid) } + end + if matColor == "All" then return { - getObjectFromGUID(WHITE_MAT_GUID), - getObjectFromGUID(ORANGE_MAT_GUID), - getObjectFromGUID(GREEN_MAT_GUID), - getObjectFromGUID(RED_MAT_GUID), + getObjectFromGUID(MAT_IDS.White), + getObjectFromGUID(MAT_IDS.Orange), + getObjectFromGUID(MAT_IDS.Green), + getObjectFromGUID(MAT_IDS.Red), } end end From d4a41b7b02c08cc6166b3a2e6e6dcef7851a4f56 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Tue, 6 Dec 2022 21:26:08 +0100 Subject: [PATCH 07/16] option for playermat snap tags added --- src/core/Global.ttslua | 15 ++++++++++++--- xml/Global.xml | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index e92fe345..46dc2a71 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -613,10 +613,19 @@ function onClick_toggleOption(_, id) optionPanel[id] = state end +local PlayerMatAPI = require("playermat/PlaymatApi") function onClick_applySettings() - print("Enabling following settings:") - for id, value in pairs(optionPanel) do - if value then print(id) end + printToAll("---------------------", "White") + printToAll("Applying settings...", "White") + for id, state in pairs(optionPanel) do + if state then print(id) end + + -- option 1: Snap tags + if id == "1" then + printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") + PlayerMatAPI.setLimitSnapsByType(state, "All") + end + end end diff --git a/xml/Global.xml b/xml/Global.xml index a55724e3..cd454e67 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -62,7 +62,7 @@ - Toggle Text 1 + Playermats: Snap tags for 'Assets' Toggle Text 2 From 229277d1d722497e792f477ecb73a0ad86baf359 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 7 Dec 2022 13:02:09 +0100 Subject: [PATCH 08/16] custom font added --- modsettings/CustomUIAssets.json | 10 +++++ xml/Global.xml | 54 +-------------------------- xml/OptionPanel.xml | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 xml/OptionPanel.xml diff --git a/modsettings/CustomUIAssets.json b/modsettings/CustomUIAssets.json index 71b8b9eb..e955ba9d 100644 --- a/modsettings/CustomUIAssets.json +++ b/modsettings/CustomUIAssets.json @@ -48,5 +48,15 @@ "Name": "option-gear", "Type": 0, "URL": "http://cloud-3.steamusercontent.com/ugc/2026086584372569912/5CB461AEAE2E59D3064D90A776EB86C46081EC78/" + }, + { + "Name": "font_birmingham", + "Type": 1, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466443497/3CF9BB9AF968D245961494CC9A151774EB9BA638/" + }, + { + "Name": "font_teutonic", + "Type": 1, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466409230/EA26C778B3A2C7D7F3FB2765BD6EB6FDACAB863E/" } ] \ No newline at end of file diff --git a/xml/Global.xml b/xml/Global.xml index cd454e67..fcb08160 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -3,7 +3,6 @@ - - \ No newline at end of file + diff --git a/xml/OptionPanel.xml b/xml/OptionPanel.xml new file mode 100644 index 00000000..829e2160 --- /dev/null +++ b/xml/OptionPanel.xml @@ -0,0 +1,66 @@ + + + + + + + \ No newline at end of file From df9cff8f38392b7f756b0ba3f9d92da8cadca144 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 7 Dec 2022 13:20:29 +0100 Subject: [PATCH 09/16] addition of more fonts --- modsettings/CustomUIAssets.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modsettings/CustomUIAssets.json b/modsettings/CustomUIAssets.json index e955ba9d..7f7f6b6e 100644 --- a/modsettings/CustomUIAssets.json +++ b/modsettings/CustomUIAssets.json @@ -54,9 +54,24 @@ "Type": 1, "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466443497/3CF9BB9AF968D245961494CC9A151774EB9BA638/" }, + { + "Name": "font_columbus", + "Type": 1, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466515872/F473E4ACC75ACB6CE07457C45290B4912E0B3286/" + }, + { + "Name": "font_oldremington", + "Type": 1, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466515932/AFCE53F1E1D9580D166F53AD9EB0D77A331D4A26/" + }, { "Name": "font_teutonic", "Type": 1, "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466409230/EA26C778B3A2C7D7F3FB2765BD6EB6FDACAB863E/" + }, + { + "Name": "font_uglyqua", + "Type": 1, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466516005/113C19D37CFFA9E554394FD5B11B32967F846A62/" } ] \ No newline at end of file From d4beeeb95d67ee077db775b0a400c98dfe7533e1 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 7 Dec 2022 16:40:55 +0100 Subject: [PATCH 10/16] UI done for now --- src/core/Global.ttslua | 16 ++++- xml/Global.xml | 28 ++++---- xml/OptionPanel.xml | 143 +++++++++++++++++++++++++---------------- 3 files changed, 114 insertions(+), 73 deletions(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 46dc2a71..c46e0403 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -615,9 +615,15 @@ end local PlayerMatAPI = require("playermat/PlaymatApi") function onClick_applySettings() - printToAll("---------------------", "White") - printToAll("Applying settings...", "White") + local printed = false + for id, state in pairs(optionPanel) do + if not printed then + printToAll("---------------------", "White") + printToAll("Applying settings...", "White") + printed = true + end + if state then print(id) end -- option 1: Snap tags @@ -627,6 +633,12 @@ function onClick_applySettings() end end + + if not printed then + printToAll("---------------------", "White") + printToAll("Not settings selected!", "White") + end + end function onClick_toggleUi(_, title) diff --git a/xml/Global.xml b/xml/Global.xml index fcb08160..89a4626b 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -1,31 +1,29 @@ - - + + + Option Panel + + + + + PLAYERMATS + + + + + Enable snap tags + Only cards with the tag "Asset" will snap (official cards are supported by default). Disable this if you are having issues with custom content. + + + + + Toggle Text 2 + Description for Option 2 + + + + + Toggle Text 3 + Description for Option 3 + + + + + + + Group 2 + + + + Toggle Text 4 + Description for Option 4 + + + + + Toggle Text 5 + Description for Option 5 + + + + + Toggle Text 6 + Description for Option 6 + + + + + + + Group 3 + + + + Toggle Text 7 + Description for Option 7 + + + + + Toggle Text 8 + Description for Option 8 + + + + + + + + \ No newline at end of file From d53302c9e0685cbb5b7e753c86d52539c3a92807 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 8 Dec 2022 12:01:10 +0100 Subject: [PATCH 11/16] WIP commit to split PR into parts --- modsettings/CustomUIAssets.json | 14 +++- src/core/Global.ttslua | 38 +++++----- src/playermat/Playmat.ttslua | 37 +++++++++- src/playermat/PlaymatApi.ttslua | 29 ++++++-- xml/Global.xml | 9 ++- xml/OptionPanel.xml | 122 +++++++++++++++++++------------- 6 files changed, 166 insertions(+), 83 deletions(-) diff --git a/modsettings/CustomUIAssets.json b/modsettings/CustomUIAssets.json index 7f7f6b6e..7e5a1ef6 100644 --- a/modsettings/CustomUIAssets.json +++ b/modsettings/CustomUIAssets.json @@ -65,13 +65,23 @@ "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466515932/AFCE53F1E1D9580D166F53AD9EB0D77A331D4A26/" }, { - "Name": "font_teutonic", + "Name": "font_teutonic-arkham", "Type": 1, - "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466409230/EA26C778B3A2C7D7F3FB2765BD6EB6FDACAB863E/" + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118467703445/89328E273B4C5180BF491516CE998DE3C604E162/" }, { "Name": "font_uglyqua", "Type": 1, "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118466516005/113C19D37CFFA9E554394FD5B11B32967F846A62/" + }, + { + "Name": "option_image1", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118468280563/911BA319CD7502258D570B23BD51B3D8DA8B2AC3/" + }, + { + "Name": "option_image2", + "Type": 0, + "URL": "http://cloud-3.steamusercontent.com/ugc/2027213118470839572/FB133C41A6D8915A44C138BCF947ECFE3D111813/" } ] \ No newline at end of file diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index c46e0403..a4c26687 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -611,34 +611,28 @@ function onClick_toggleOption(_, id) self.UI.setAttribute("toggle" .. id, "isOn", state) optionPanel[id] = state + + applyChange(id, state) end local PlayerMatAPI = require("playermat/PlaymatApi") -function onClick_applySettings() - local printed = false +function applyChange(id, state) + -- option 1: Snap tags + if id == "1" then + printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") + PlayerMatAPI.setLimitSnapsByType(state, "All") - for id, state in pairs(optionPanel) do - if not printed then - printToAll("---------------------", "White") - printToAll("Applying settings...", "White") - printed = true - end + -- option 2: Draw 1 button + elseif id=="2" then + printToAll("'Draw 1' button " .. (state and "en" or "dis") .."abled.", "White") + PlayerMatAPI.showDrawButton(state, "All") - if state then print(id) end - - -- option 1: Snap tags - if id == "1" then - printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.setLimitSnapsByType(state, "All") - end + -- option 3: Clickable clue counters + elseif id=="3" then + printToAll("Clickable clue counters " .. (state and "en" or "dis") .."abled.", "White") + PlayerMatAPI.clickableClues(state, "All") end - - if not printed then - printToAll("---------------------", "White") - printToAll("Not settings selected!", "White") - end - end function onClick_toggleUi(_, title) @@ -649,7 +643,7 @@ function onClick_toggleUi(_, title) if UI.getValue('title') ~= title and title ~= 'Hidden' then UI.setValue('title', title) - if title == "Option Panel" then + if title == "Options" then UI.show('optionPanel') else update_window_content(title) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index c9731451..69e8912e 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -45,8 +45,9 @@ local RESOURCE_COUNTER -- global variable so it can be reset by the Clean Up Helper activeInvestigatorId = "00000" +local drawButton = false -function onSave() return JSON.encode({zoneID = zoneID, playerColor = PLAYER_COLOR, activeInvestigatorId = activeInvestigatorId}) end +function onSave() return JSON.encode({zoneID = zoneID, playerColor = PLAYER_COLOR, activeInvestigatorId = activeInvestigatorId, drawButton = drawButton}) end function onLoad(save_state) self.interactable = DEBUG @@ -96,8 +97,11 @@ function onLoad(save_state) zoneID = state.zoneID PLAYER_COLOR = state.playerColor activeInvestigatorId = state.activeInvestigatorId + drawButton = state.drawButton end + showDrawButton(drawButton) + if getObjectFromGUID(zoneID) == nil then spawnDeckZone() end COLLISION_ENABLED = true end @@ -648,11 +652,40 @@ function spawnToken(position, tokenType) Global.call('spawnToken', {position, tokenType, PLAY_ZONE_ROTATION}) end +-- Sets this playermat's draw 1 button to visible +---@param visibleButton Boolean. Whether the draw 1 button should be visible +function showDrawButton(visibleButton) + drawButton = visibleButton + if drawButton then + self.createButton({ + label = "Draw 1", + click_function = "doDrawOne", + function_owner = mat, + position = { 1.84, 0.1, -0.36 }, + scale = { 0.12, 0.12, 0.12 }, + width = 800, + height = 280, + font_size = 180 + }) + else + -- remove button with index 9 if 10 buttons are present (because index starts at 0) + if #self.getButtons() == 10 then + self.removeButton(9) + end + end +end + +-- Spawns / destroys a clickable clue counter for this playmat +---@param clickableCounter Boolean. Whether the clickable clue counter should be present +function clickableClues(clickableCounter) + print("dummy function for clue counters") +end + -- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes -- is true, the main card slot snap points will only snap assets, while the investigator area point -- will only snap Investigators. If matchTypes is false, snap points will be reset to snap all -- cards. --- @param matchTypes Boolean. Whether snap points should only snap for the matching card types. +---@param matchTypes Boolean. Whether snap points should only snap for the matching card types. function setLimitSnapsByType(matchTypes) local snaps = self.getSnapPoints() for i, snap in ipairs(snaps) do diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 489387e4..5948a4de 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -13,9 +13,9 @@ do -- matchTypes is true, the main card slot snap points will only snap assets, while the -- investigator area point will only snap Investigators. If matchTypes is false, snap points will -- be reset to snap all cards. - -- @param matchCardTypes Boolean. Whether snap points should only snap for the matching card + ---@param matchCardTypes Boolean. Whether snap points should only snap for the matching card -- types. - -- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also + ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will apply the setting to all four mats. PlaymatApi.setLimitSnapsByType = function(matchCardTypes, matColor) for _, mat in ipairs(internal.getMatForColor(matColor)) do @@ -23,10 +23,31 @@ do end end + + -- Sets the requested playermat's draw 1 button to visible + ---@param visibleButton Boolean. Whether the draw 1 button should be visible or not + ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also + -- accepts "All" as a special value which will apply the setting to all four mats. + PlaymatApi.showDrawButton = function(visibleButton, matColor) + for _, mat in ipairs(internal.getMatForColor(matColor)) do + mat.call("showDrawButton", visibleButton) + end + end + + -- Spawns a clickable clue counter for the requested playermat + ---@param visibleButton Boolean. Whether the clickable counter should be present or not + ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also + -- accepts "All" as a special value which will apply the setting to all four mats. + PlaymatApi.clickableClues = function(clickableCounter, matColor) + for _, mat in ipairs(internal.getMatForColor(matColor)) do + mat.call("clickableClues", clickableCounter) + end + end + -- Convenience function to look up a mat's object by color, or get all mats. - -- @param matColor String for one of the active player colors - White, Orange, Green, Red. Also + ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will return all four mats. - -- @return Array of playermat objects. If a single mat is requested, will return a single-element + ---@return Array of playermat objects. If a single mat is requested, will return a single-element -- array to simplify processing by consumers. internal.getMatForColor = function(matColor) local targetMatGuid = MAT_IDS[matColor] diff --git a/xml/Global.xml b/xml/Global.xml index 89a4626b..69935cd5 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -3,27 +3,26 @@ - - + \ No newline at end of file From ef7502fbe8dd9ca448b6f68f24b26dd09481ae1f Mon Sep 17 00:00:00 2001 From: Chr1Z <97286811+Chr1Z93@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:54:02 +0100 Subject: [PATCH 12/16] resolving merge conflict --- src/playermat/Playmat.ttslua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index f6606c1b..67e3a073 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -681,6 +681,10 @@ function clickableClues(clickableCounter) print("dummy function for clue counters") end +-- Sets this playermat's snap points to limit snapping to matching card types or not. If matchTypes +-- is true, the main card slot snap points will only snap assets, while the investigator area point +-- will only snap Investigators. If matchTypes is false, snap points will be reset to snap all +-- cards. ---@param matchTypes Boolean. Whether snap points should only snap for the matching card types. function setLimitSnapsByType(matchTypes) local snaps = self.getSnapPoints() @@ -715,10 +719,10 @@ function setLimitSnapsByType(matchTypes) end -- Simple method to check if the given point is in a specified area. Local use only, --- @param point Vector. Point to check, only x and z values are relevant --- @param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample +---@param point Vector. Point to check, only x and z values are relevant +---@param bounds Table. Defined area to see if the point is within. See MAIN_PLAY_AREA for sample -- bounds definition. --- @return Boolean. True if the point is in the area defined by bounds +---@return Boolean. True if the point is in the area defined by bounds function inArea(point, bounds) return (point.x < bounds.upperLeft.x and point.x > bounds.lowerRight.x From 2f83df87d8926a3992ae9cfe8050444ab5578631 Mon Sep 17 00:00:00 2001 From: Chr1Z <97286811+Chr1Z93@users.noreply.github.com> Date: Mon, 12 Dec 2022 09:55:20 +0100 Subject: [PATCH 13/16] removed empty line --- src/playermat/PlaymatApi.ttslua | 1 - 1 file changed, 1 deletion(-) diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 89cde2d7..6a4064e6 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -13,7 +13,6 @@ do -- matchTypes is true, the main card slot snap points will only snap assets, while the -- investigator area point will only snap Investigators. If matchTypes is false, snap points will -- be reset to snap all cards. - ---@param matchCardTypes Boolean. Whether snap points should only snap for the matching card -- types. ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also From 24e8f3d8a6e7dc292eafc38fdf55c4ddee3773dc Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 12 Dec 2022 12:18:45 +0100 Subject: [PATCH 14/16] resolving review comments --- config.json | 2 +- src/core/Global.ttslua | 47 +++++++++++++++++---------------- src/playermat/Playmat.ttslua | 33 ++++++++++++++++------- src/playermat/PlaymatApi.ttslua | 6 ++--- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/config.json b/config.json index 46ab6ea5..c2e3a329 100644 --- a/config.json +++ b/config.json @@ -22,7 +22,7 @@ }, "Lighting_path": "Lighting.json", "LuaScript": "require(\"core/Global\")", - "LuaScriptState": "[]", + "LuaScriptState": "{\"optionPanel\":[false,false,false,false,false,false,false,false]}", "MusicPlayer_path": "MusicPlayer.json", "Note": "", "ObjectStates_order": [ diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 283a4660..21363e7d 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -28,8 +28,8 @@ local NOT_INTERACTABLE = { local chaosTokens = {} local chaosTokensLastMat = nil local IS_RESHUFFLING = false - -local bagSearchers = { } +local bagSearchers = {} +local playmatAPI = require("playermat/PlaymatApi") --------------------------------------------------------- -- data for tokens @@ -131,18 +131,15 @@ local overallStats = { --------------------------------------------------------- -- saving state of optionPanel to restore later -function onSave() return JSON.encode(optionPanel) end +function onSave() return JSON.encode({ optionPanel = optionPanel }) end function onLoad(savedData) if savedData then - optionPanel = JSON.decode(savedData) - for id, enabled in pairs(optionPanel) do - if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end - end + loadedData = JSON.decode(savedData) + optionPanel = loadedData.optionPanel + updateOptionPanelState() else - for i = 1, 8 do - optionPanel[i] = false - end + print("Saved state could not be found!") end for _, guid in ipairs(NOT_INTERACTABLE) do @@ -652,27 +649,31 @@ function onClick_toggleOption(_, id) end self.UI.setAttribute("toggle" .. id, "isOn", state) - optionPanel[id] = state - applyChange(id, state) + id = tonumber(id) + optionPanel[id] = state + applyOptionPanelChange(id, state) end -local PlayerMatAPI = require("playermat/PlaymatApi") -function applyChange(id, state) +-- sets the option panel to the correct state (corresponding to 'optionPanel') +function updateOptionPanelState() + for id, enabled in pairs(optionPanel) do + if enabled then self.UI.setAttribute("toggle" .. id, "isOn", true) end + end +end + +function applyOptionPanelChange(id, state) -- option 1: Snap tags - if id == "1" then - printToAll("Playermat snap tags " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.setLimitSnapsByType(state, "All") + if id == 1 then + playmatAPI.setLimitSnapsByType(state, "All") -- option 2: Draw 1 button - elseif id=="2" then - printToAll("'Draw 1' button " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.showDrawButton(state, "All") + elseif id == 2 then + playmatAPI.showDrawButton(state, "All") -- option 3: Clickable clue counters - elseif id=="3" then - printToAll("Clickable clue counters " .. (state and "en" or "dis") .."abled.", "White") - PlayerMatAPI.clickableClues(state, "All") + elseif id == 3 then + playmatAPI.clickableClues(state, "All") end end diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 67e3a073..7294d6b5 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -47,7 +47,14 @@ local RESOURCE_COUNTER activeInvestigatorId = "00000" local drawButton = false -function onSave() return JSON.encode({zoneID = zoneID, playerColor = PLAYER_COLOR, activeInvestigatorId = activeInvestigatorId, drawButton = drawButton}) end +function onSave() + return JSON.encode({ + zoneID = zoneID, + playerColor = PLAYER_COLOR, + activeInvestigatorId = activeInvestigatorId, + drawButton = drawButton + }) +end function onLoad(save_state) self.interactable = DEBUG @@ -653,9 +660,11 @@ function spawnToken(position, tokenType) end -- Sets this playermat's draw 1 button to visible ----@param visibleButton Boolean. Whether the draw 1 button should be visible -function showDrawButton(visibleButton) - drawButton = visibleButton +---@param visible Boolean. Whether the draw 1 button should be visible +function showDrawButton(visible) + drawButton = visible + + -- create the "Draw 1" button if drawButton then self.createButton({ label = "Draw 1", @@ -667,17 +676,21 @@ function showDrawButton(visibleButton) height = 280, font_size = 180 }) + + -- remove the "Draw 1" button else - -- remove button with index 9 if 10 buttons are present (because index starts at 0) - if #self.getButtons() == 10 then - self.removeButton(9) + local buttons = self.getButtons() + for i = 1, #buttons do + if buttons[i].label == "Draw 1" then + self.removeButton(buttons[i].index) + end end end end --- Spawns / destroys a clickable clue counter for this playmat ----@param clickableCounter Boolean. Whether the clickable clue counter should be present -function clickableClues(clickableCounter) +-- Shows or hides the clickable clue counter for this playmat +---@param showCounters Boolean. Whether the clickable clue counter should be present +function clickableClues(showCounters) print("dummy function for clue counters") end diff --git a/src/playermat/PlaymatApi.ttslua b/src/playermat/PlaymatApi.ttslua index 6a4064e6..a8b0e952 100644 --- a/src/playermat/PlaymatApi.ttslua +++ b/src/playermat/PlaymatApi.ttslua @@ -33,13 +33,13 @@ do end end - -- Spawns a clickable clue counter for the requested playermat + -- Shows or hides the clickable clue counter for the requested playermat ---@param visibleButton Boolean. Whether the clickable counter should be present or not ---@param matColor String for one of the active player colors - White, Orange, Green, Red. Also -- accepts "All" as a special value which will apply the setting to all four mats. - PlaymatApi.clickableClues = function(clickableCounter, matColor) + PlaymatApi.clickableClues = function(showCounter, matColor) for _, mat in ipairs(internal.getMatForColor(matColor)) do - mat.call("clickableClues", clickableCounter) + mat.call("clickableClues", showCounter) end end From 74bc2807f6144688b9959953d2ce0037c890c7e9 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 12 Dec 2022 12:20:54 +0100 Subject: [PATCH 15/16] disabled option-panel button for now --- xml/Global.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xml/Global.xml b/xml/Global.xml index 69935cd5..ebb4622f 100644 --- a/xml/Global.xml +++ b/xml/Global.xml @@ -17,7 +17,7 @@