Merge branch 'optionpanel' into optionpanel-2

This commit is contained in:
Chr1Z93 2022-12-12 13:25:34 +01:00
commit 5ab71c56c0
6 changed files with 70 additions and 51 deletions

View File

@ -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": [

View File

@ -4,10 +4,6 @@
-- - sets counters to default values (resources and doom) or trauma values (health and sanity, if not disabled) from campaign log
-- - puts everything on playmats and hands into respective trashcans
-- - use the IGNORE_TAG to exclude objects from tidying (default: "CleanUpHelper_Ignore")
information = {
version = "2.4",
last_updated = "24.11.2022"
}
-- enable this for debugging
local SHOW_RAYS = false
@ -96,14 +92,13 @@ function onLoad(saved_data)
-- context menu and buttons
self.addContextMenuItem("More Information", function()
printToAll("------------------------------", "White")
printToAll("Clean Up Helper v" .. information["version"] .. " by Chr1Z", "Orange")
printToAll("last updated: " .. information["last_updated"], "White")
printToAll("Clean Up Helper by Chr1Z", "Orange")
printToAll("ignore tag: " .. IGNORE_TAG, "White")
printToAll("Player order in the campaign log for trauma import:\nWhite, Orange, Green, Red", "White")
end)
-- index 0: button as label
buttonParameters.label = "Clean Up Helper v" .. information["version"]
buttonParameters.label = "Clean Up Helper"
buttonParameters.click_function = "none"
buttonParameters.position = { x = 0, y = 0.1, z = -1.525 }
buttonParameters.height = 0
@ -179,8 +174,13 @@ function cleanUp()
getTrauma()
resetCounters()
-- bless / curse manager prints removed amounts
removeBlessCurse()
printToAll("Removing vector lines...", "White")
removeLines()
printToAll("Discarding player hands...", "White")
discardHands()
@ -266,6 +266,11 @@ function removeBlessCurse()
end
end
-- remove drawn lines
function removeLines()
Global.setVectorLines({})
end
-- discard all hand objects
function discardHands()
for i = 1, 4 do

View File

@ -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")
-- update master clue counter
getObjectFromGUID("4a3aa4").setVar("clickableCounters", state)

View File

@ -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,23 +676,27 @@ 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 with the correct amount of clues
---@param clickableCounter Boolean. Whether the clickable clue counter should be present
function clickableClues(clickableCounter)
---@param showCounter Boolean. Whether the clickable clue counter should be present
function clickableClues(showCounter)
local CLUE_COUNTER = getObjectFromGUID(CLUE_COUNTER_GUID)
local CLUE_CLICKER = getObjectFromGUID(CLUE_CLICKER_GUID)
local clickerPos = CLUE_CLICKER.getPosition()
local clueCount = 0
if clickableCounter then
if showCounter then
-- current clue count
clueCount = CLUE_COUNTER.getVar("exposedValue")
@ -751,10 +764,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

View File

@ -25,22 +25,22 @@ do
-- Sets the requested playermat's draw 1 button to visible
---@param visibleButton Boolean. Whether the draw 1 button should be visible or not
---@param visible 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)
PlaymatApi.showDrawButton = function(visible, matColor)
for _, mat in ipairs(internal.getMatForColor(matColor)) do
mat.call("showDrawButton", visibleButton)
mat.call("showDrawButton", visible)
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

View File

@ -17,7 +17,7 @@
<Button icon="yog-sothoth" tooltip="Extras" onClick="onClick_toggleUi(Extras)"/>
<Button icon="elder-sign" tooltip="Investigators" onClick="onClick_toggleUi(Investigators)"/>
<Button icon="devourer" tooltip="Community Content" onClick="onClick_toggleUi(Community Content)"/>
<Button icon="option-gear" tooltip="Options" onClick="onClick_toggleUi(Options)"/>
<Button icon="option-gear" tooltip="Options" onClick="onClick_toggleUi(Options)" active="false"/>
<!--<Button icon="download" tooltip="ArkhamDB Deck Importer" onClick="onClick_toggleUi(Deck Importer)"/> -->
</VerticalLayout>