add settings menu

This commit is contained in:
Chr1Z93 2023-05-23 15:44:50 +02:00
parent caa273e7e1
commit fc4f60ca19
3 changed files with 227 additions and 24 deletions

View File

@ -40,6 +40,7 @@ playButtonData = {
{ id = "21", width = "20", height = "20", offset = "-20 80" } { id = "21", width = "20", height = "20", offset = "-20 80" }
} }
-- To-Do: dynamically get positions by linking to objects
cameraData = { cameraData = {
{ position = { -1.6, 1.55, 0 }, distance = 18 }, -- 1. Act/Agenda { position = { -1.6, 1.55, 0 }, distance = 18 }, -- 1. Act/Agenda
{ position = { -28, 1.55, 0 }, distance = -1 }, -- 2. Map { position = { -28, 1.55, 0 }, distance = -1 }, -- 2. Map
@ -61,6 +62,7 @@ cameraData = {
{ position = { -59.08, 1.55, -83 }, distance = 27 } -- 18. Additions { position = { -59.08, 1.55, -83 }, distance = 27 } -- 18. Additions
} }
local settingsOpenForColor
local visibility = {} local visibility = {}
local claims = {} local claims = {}
local pitch = {} local pitch = {}
@ -84,10 +86,13 @@ function onLoad(savedData)
claims = loadedData.claims claims = loadedData.claims
pitch = loadedData.pitch pitch = loadedData.pitch
else else
resetClaimColors() local allColors = Player.getColors()
-- default state for visibility for _, color in ipairs(allColors) do
for _, color in ipairs(Player.getColors()) do -- default state for claims
claims[color] = {}
-- default state for visibility
visibility[color] = { full = false, play = false } visibility[color] = { full = false, play = false }
end end
end end
@ -227,26 +232,20 @@ end
--------------------------------------------------------- ---------------------------------------------------------
-- handles all button clicks -- handles all button clicks
function buttonClicked(player, _, idValue) function buttonClicked(player, _, id)
local index = tonumber(idValue) local index = tonumber(id)
if index == 19 then if index == 19 then
setVisibility("toggle", player.color) setVisibility("toggle", player.color)
elseif index == 20 then elseif index == 20 then
setVisibility("close", player.color) setVisibility("close", player.color)
elseif index == 21 then elseif index == 21 then
player.showInputDialog("Please enter your desired viewing angle in degrees (90 = bird's-eye view):", "75", updatePitch) toggleSettings(player)
else else
loadCamera(player, _, index) loadCamera(player, index)
end end
end end
function updatePitch(input, playerColor)
local number = tonumber(input) or 75
if number > 90 then number = 90 end
pitch[playerColor] = number
end
-- generates a table with rectangular bounds for provided objects -- generates a table with rectangular bounds for provided objects
function getDynamicViewBounds(objList) function getDynamicViewBounds(objList)
local count = 0 local count = 0
@ -293,11 +292,12 @@ function getDynamicViewBounds(objList)
end end
-- loads the specified camera for a player -- loads the specified camera for a player
function loadCamera(player, _, index) function loadCamera(player, index)
local lookHere local lookHere
-- dynamic view of the play area -- dynamic view of the play area
if index == 2 then if index == 2 then
-- search the scripting zone on the play area for objects
local bounds = getDynamicViewBounds(getObjectFromGUID("a2f932").getObjects()) local bounds = getDynamicViewBounds(getObjectFromGUID("a2f932").getObjects())
lookHere = { lookHere = {
@ -310,12 +310,24 @@ function loadCamera(player, _, index)
local matColorList = { "White", "Orange", "Green", "Red" } local matColorList = { "White", "Orange", "Green", "Red" }
local matColor = matColorList[index - 2] -- mat index 1 - 4 local matColor = matColorList[index - 2] -- mat index 1 - 4
if #getSeatedPlayers() == 1 or claims[player.color][matColor] then -- check if anyone (except for yourself) has claimed this color
local isClaimed = false
for playerColor, playerTable in pairs(claims) do
if playerColor ~= player.color and playerTable[matColor] then
isClaimed = true
break
end
end
-- swap to that color if it isn't claimed by someone else
if #getSeatedPlayers() == 1 or not isClaimed then
local newPlayerColor = playmatApi.getPlayerColor(matColor) local newPlayerColor = playmatApi.getPlayerColor(matColor)
copyVisibility({ startColor = player.color, targetColor = newPlayerColor }) copyVisibility({ startColor = player.color, targetColor = newPlayerColor })
player.changeColor(newPlayerColor) player.changeColor(newPlayerColor)
end end
-- search on the playmat for objects
local bounds = getDynamicViewBounds(playmatApi.searchPlaymat(matColor)) local bounds = getDynamicViewBounds(playmatApi.searchPlaymat(matColor))
lookHere = { lookHere = {
@ -339,14 +351,57 @@ function loadCamera(player, _, index)
end end
--------------------------------------------------------- ---------------------------------------------------------
-- functions to reset/initialize tables -- settings related functionality
--------------------------------------------------------- ---------------------------------------------------------
function resetClaimColors() -- claims a color for a player
for _, seatedColor in ipairs(getSeatedPlayers()) do function claimColor(player, color)
claims[seatedColor] = {} local currentState = claims[player.color][color]
for _, color in ipairs(Player.getColors()) do claims[player.color][color] = not currentState
claims[seatedColor][color] = (seatedColor == color) end
end
function loadDefaultSettings(player)
-- reset claims for that player
for _, color in ipairs(Player.getColors()) do
claims[player.color][color] = (player.color == color)
end
-- reset pitch for that player
pitch[player.color] = nil
-- update the UI accordingly
updateSettingsUI(player)
end
-- called by clicking a toggle
function toggleSettings(player)
if settingsOpenForColor == player.color then
settingsOpenForColor = nil
UI.setAttribute("navPanelSettings", "active", false)
elseif settingsOpenForColor then
broadcastToColor("Someone else is currently using the settings. Please wait and try again.", player.color, "Yellow")
else
settingsOpenForColor = player.color
updateSettingsUI(player)
UI.setAttribute("navPanelSettings", "visibility", player.color)
UI.setAttribute("navPanelSettings", "active", true)
end
end
-- called by the slider
function updatePitch(player, number)
pitch[player.color] = number
end
-- updates the settings UI for the provided player
function updateSettingsUI(player)
-- update the slider
UI.setAttribute("sliderPitch", "value", pitch[player.color] or 75)
-- update the claims
local matColorList = { "White", "Orange", "Green", "Red" }
for _, matColor in pairs(matColorList) do
UI.setAttribute("claim" .. matColor, "isOn", claims[player.color][matColor] or false)
end end
end end

View File

@ -112,6 +112,6 @@
</VerticalLayout> </VerticalLayout>
<Include src="TitleSplash.xml"/> <Include src="TitleSplash.xml"/>
<Include src="NavigationOverlay.xml"/>
<Include src="OptionPanel.xml"/> <Include src="OptionPanel.xml"/>
<Include src="UpdateNotification.xml"/> <Include src="UpdateNotification.xml"/>
<Include src="NavigationOverlay.xml"/>

View File

@ -1,5 +1,46 @@
<!-- Defaults --> <!-- Default formatting -->
<Defaults> <Defaults>
<Text color="#FFFFFF"
alignment="MiddleLeft" />
<Toggle isOn="False"
rectAlignment="MiddleRight" />
<Cell dontUseTableCellBackground="true"
outlineSize="0 1"
outline="grey" />
<!-- options -->
<Row class="option-text"
preferredHeight="45"/>
<Cell class="option-text"
color="#333333"/>
<Cell class="option-button"
color="#333333"/>
<Text class="option-header"
fontSize="20"
font="font_teutonic-arkham"/>
<Cell class="claim"
tooltip="Clicking this seat in the navigation overlay will now only swap the playercolor for you."
tooltipPosition="Right" />
<!-- buttons at the bottom -->
<Button class="bottomButtons"
hoverClass="hover"
pressClass="press"
selectClass="select"
color="#888888"
minHeight="35"
fontSize="24"
font="font_teutonic-arkham"/>
<Button class="hover"
color="grey"/>
<Button class="press"
color="white"/>
<Button class="select"
color="white"/>
<!-- Navigation Panels -->
<Panel class="navPanel" <Panel class="navPanel"
active="false" active="false"
allowDragging="true" allowDragging="true"
@ -22,3 +63,110 @@
width="205" width="205"
class="navPanel"> class="navPanel">
</Panel> </Panel>
<!-- Settings -->
<TableLayout id="navPanelSettings"
active="false"
width="300"
height="335"
color="#000000"
outlineSize="2 2"
outline="grey"
rectAlignment="MiddleCenter">
<!-- Header -->
<Row preferredHeight="60">
<Cell>
<Panel padding="10 0 0 0">
<Text font="font_teutonic-arkham"
fontSize="35">Navigation Overlay</Text>
</Panel>
</Cell>
</Row>
<!-- Options -->
<Row>
<Cell>
<TableLayout columnWidths="0 125"
autoCalculateHeight="1"
cellPadding="10 0 5 5">
<!-- Option: Custom pitch -->
<Row class="option-text">
<Cell class="option-text">
<Text class="option-header">Viewing angle in degrees:</Text>
</Cell>
<Cell class="option-button">
<Slider id="sliderPitch"
onValueChanged="797ede/updatePitch"
wholeNumbers="true"
minValue="0"
maxValue="90"
value="75"
tooltip="This controls the camera pitch ('nodding your head')."
tooltipPosition="Right"/>
</Cell>
</Row>
<!-- Option: Claim White -->
<Row class="option-text">
<Cell class="option-text">
<Text class="option-header">Claim "White" seat</Text>
</Cell>
<Cell class="option-button claim">
<Toggle id="claimWhite"
onValueChanged="797ede/claimColor(White)"/>
</Cell>
</Row>
<!-- Option: Claim Orange -->
<Row class="option-text">
<Cell class="option-text">
<Text class="option-header">Claim "Orange" seat</Text>
</Cell>
<Cell class="option-button claim">
<Toggle id="claimOrange"
onValueChanged="797ede/claimColor(Orange)"/>
</Cell>
</Row>
<!-- Option: Claim Green -->
<Row class="option-text">
<Cell class="option-text">
<Text class="option-header">Claim "Green" seat</Text>
</Cell>
<Cell class="option-button claim">
<Toggle id="claimGreen"
onValueChanged="797ede/claimColor(Green)"/>
</Cell>
</Row>
<!-- Option: Claim Red -->
<Row class="option-text">
<Cell class="option-text">
<Text class="option-header">Claim "Red" seat</Text>
</Cell>
<Cell class="option-button claim">
<Toggle id="claimRed"
onValueChanged="797ede/claimColor(Red)"/>
</Cell>
</Row>
</TableLayout>
</Cell>
</Row>
<!-- Buttons: Defaults and Close -->
<Row preferredHeight="50">
<Cell>
<HorizontalLayout minHeight="55"
flexibleHeight="0"
padding="10 10 5 10"
spacing="35">
<Button class="bottomButtons"
onClick="797ede/loadDefaultSettings">Load defaults</Button>
<Button class="bottomButtons"
onClick="797ede/toggleSettings">Close</Button>
</HorizontalLayout>
</Cell>
</Row>
</TableLayout>