addition of edit button to set pitch

This commit is contained in:
Chr1Z93 2023-05-23 12:42:24 +02:00
parent 2297ea294d
commit caa273e7e1
2 changed files with 85 additions and 130 deletions

View File

@ -37,12 +37,12 @@
{ {
"Name": "OverlayLarge", "Name": "OverlayLarge",
"Type": 0, "Type": 0,
"URL": "http://cloud-3.steamusercontent.com/ugc/2021591230441678995/7B413A821136969D8723687A2AD66773B3F8FEED/" "URL": "http://cloud-3.steamusercontent.com/ugc/2038486957000838167/1EF958D11A228817099C310F97817F61F84DDD91/"
}, },
{ {
"Name": "OverlaySmall", "Name": "OverlaySmall",
"Type": 0, "Type": 0,
"URL": "http://cloud-3.steamusercontent.com/ugc/2021591230447630077/18C86248B9BDAF1DE01B67791439A39EE4F97B60/" "URL": "http://cloud-3.steamusercontent.com/ugc/2038486957000850722/37F0D4848BA08788F79DB2D3FB6D11429CB1F861/"
}, },
{ {
"Name": "NavigationOverlayIcon", "Name": "NavigationOverlayIcon",

View File

@ -1,29 +1,30 @@
local playmatApi = require("playermat/PlaymatApi") local playmatApi = require("playermat/PlaymatApi")
fullButtonData = { fullButtonData = {
{ id = "1", width = "84", height = "33", offset = "1 2" }, -- Act/Agenda { id = "1", width = "84", height = "33", offset = "1 2" }, -- 1. Act/Agenda
{ id = "2", width = "78", height = "69", offset = "1 -62" }, -- Map { id = "2", width = "78", height = "69", offset = "1 -62" }, -- 2. Map
{ id = "3", width = "70", height = "36", offset = "-38 -126" }, -- White { id = "3", width = "70", height = "36", offset = "-38 -126" }, -- 3. White
{ id = "4", width = "70", height = "36", offset = "38 -126" }, -- Orange { id = "4", width = "70", height = "36", offset = "38 -126" }, -- 4. Orange
{ id = "5", width = "36", height = "70", offset = "-63 -66" }, -- Green { id = "5", width = "36", height = "70", offset = "-63 -66" }, -- 5. Green
{ id = "6", width = "36", height = "70", offset = "63 -66" }, -- Red { id = "6", width = "36", height = "70", offset = "63 -66" }, -- 6. Red
{ id = "7", width = "38", height = "38", offset = "-65 -3" }, -- Victory { id = "7", width = "38", height = "38", offset = "-65 -3" }, -- 7. Victory
{ id = "8", width = "40", height = "40", offset = "65 -3" }, -- Guide { id = "8", width = "40", height = "40", offset = "65 -3" }, -- 8. Guide
{ id = "9", width = "56", height = "16", offset = "1 -20" }, -- Player count { id = "9", width = "56", height = "16", offset = "1 -20" }, -- 9. Player count
{ id = "10", width = "36", height = "16", offset = "1 -102" }, -- Bless/Curse { id = "10", width = "36", height = "16", offset = "1 -102" }, -- 10. Bless/Curse
{ id = "11", width = "168", height = "56", offset = "1 47" }, -- Scenarios { id = "11", width = "168", height = "56", offset = "1 47" }, -- 11. Scenarios
{ id = "12", width = "52", height = "53", offset = "-154 134" }, -- Player card panel { id = "12", width = "52", height = "53", offset = "-154 134" }, -- 12. Player card panel
{ id = "13", width = "22", height = "22", offset = "-116 132" }, -- Search card panel { id = "13", width = "22", height = "22", offset = "-116 132" }, -- 13. Search card panel
{ id = "14", width = "120", height = "75", offset = "-152 70" }, -- Player card display { id = "14", width = "120", height = "75", offset = "-152 70" }, -- 14. Player card display
{ id = "15", width = "40", height = "54", offset = "-150 -38" }, -- Deck builder { id = "15", width = "40", height = "54", offset = "-150 -38" }, -- 15. Deck builder
{ id = "16", width = "104", height = "84", offset = "-154 -114" }, -- Rules area { id = "16", width = "104", height = "84", offset = "-154 -114" }, -- 16. Rules area
{ id = "17", width = "100", height = "170", offset = "152 72" }, -- Cycle area { id = "17", width = "100", height = "170", offset = "152 72" }, -- 17. Cycle area
{ id = "18", width = "56", height = "60", offset = "182 -124" }, -- Additions { id = "18", width = "56", height = "60", offset = "182 -124" }, -- 18. Additions
{ id = "19", width = "20", height = "20", offset = "-8 150" }, -- Shrink { id = "19", width = "20", height = "20", offset = "0 150" }, -- 19. Shrink
{ id = "20", width = "20", height = "20", offset = "12 150" } -- Close { id = "20", width = "20", height = "20", offset = "20 150" }, -- 20. Close
{ id = "21", width = "20", height = "20", offset = "-20 150" } -- 21. Settings
} }
playButtonData = { playButtonData = {
{ id = "1", width = "80", height = "33", offset = "0 55" }, { id = "1", width = "80", height = "33", offset = "0 55" },
{ id = "2", width = "78", height = "70", offset = "0 -8" }, { id = "2", width = "78", height = "70", offset = "0 -8" },
{ id = "3", width = "68", height = "32", offset = "-36 -71" }, { id = "3", width = "68", height = "32", offset = "-36 -71" },
@ -34,12 +35,13 @@ playButtonData = {
{ id = "8", width = "38", height = "38", offset = "66 52" }, { id = "8", width = "38", height = "38", offset = "66 52" },
{ id = "9", width = "50", height = "12", offset = "0 33" }, { id = "9", width = "50", height = "12", offset = "0 33" },
{ id = "10", width = "32", height = "12", offset = "0 -48" }, { id = "10", width = "32", height = "12", offset = "0 -48" },
{ id = "19", width = "20", height = "20", offset = "-10 80" }, { id = "19", width = "20", height = "20", offset = "0 80" },
{ id = "20", width = "20", height = "20", offset = "10 80" } { id = "20", width = "20", height = "20", offset = "20 80" },
{ id = "21", width = "20", height = "20", offset = "-20 80" }
} }
defaultCameraData = { cameraData = {
{ position = { -1.6, 1.55, 0 }, distance = 18 }, -- 1. ActAgenda { 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
{ position = { -31.6, 1.55, 26.4 }, distance = -1 }, -- 3. Green playmat { position = { -31.6, 1.55, 26.4 }, distance = -1 }, -- 3. Green playmat
{ position = { -55, 1.55, 12.05 }, distance = -1 }, -- 4. White playmat { position = { -55, 1.55, 12.05 }, distance = -1 }, -- 4. White playmat
@ -59,11 +61,9 @@ defaultCameraData = {
{ position = { -59.08, 1.55, -83 }, distance = 27 } -- 18. Additions { position = { -59.08, 1.55, -83 }, distance = 27 } -- 18. Additions
} }
local editing = false local visibility = {}
local claiming = false local claims = {}
local cameraData = {} local pitch = {}
local visibility = {}
local claims = {}
--------------------------------------------------------- ---------------------------------------------------------
-- save/load functionality -- save/load functionality
@ -71,25 +71,28 @@ local claims = {}
function onSave() function onSave()
return JSON.encode({ return JSON.encode({
cameras = cameraData,
visibility = visibility, visibility = visibility,
claims = claims claims = claims,
pitch = pitch
}) })
end end
function onLoad(savedData) function onLoad(savedData)
if savedData ~= "" then if savedData ~= "" then
local loadedData = JSON.decode(savedData) local loadedData = JSON.decode(savedData)
cameraData = loadedData.cameras
visibility = loadedData.visibility visibility = loadedData.visibility
claims = loadedData.claims claims = loadedData.claims
pitch = loadedData.pitch
else else
resetCameras()
resetClaimColors() resetClaimColors()
resetVisibility()
-- default state for visibility
for _, color in ipairs(Player.getColors()) do
visibility[color] = { full = false, play = false }
end
end end
updateXmlButtons() createXmlButtons()
updateVisibility() updateVisibility()
end end
@ -132,7 +135,7 @@ end
-- update XML visibility -- update XML visibility
function updateVisibility() function updateVisibility()
local colorString = {full = "", play = ""} local colorString = { full = "", play = "" }
for color, v in pairs(visibility) do for color, v in pairs(visibility) do
if v.full then if v.full then
@ -158,17 +161,17 @@ function updateVisibility()
end end
--------------------------------------------------------- ---------------------------------------------------------
-- XML creating/editing -- XML button creation
--------------------------------------------------------- ---------------------------------------------------------
function updateXmlButtons() function createXmlButtons()
local ui = UI.getXmlTable() local ui = UI.getXmlTable()
ui = updateXmlButtonHelper(ui, { ui = createXmlButtonHelper(ui, {
data = fullButtonData, data = fullButtonData,
id = "navPanelFull", id = "navPanelFull",
overlay = "OverlayLarge" overlay = "OverlayLarge"
}) })
ui = updateXmlButtonHelper(ui, { ui = createXmlButtonHelper(ui, {
data = playButtonData, data = playButtonData,
id = "navPanelPlay", id = "navPanelPlay",
overlay = "OverlaySmall" overlay = "OverlaySmall"
@ -177,7 +180,7 @@ function updateXmlButtons()
end end
-- XML button creation -- XML button creation
function updateXmlButtonHelper(ui, params) function createXmlButtonHelper(ui, params)
local color local color
local guid = self.getGUID() local guid = self.getGUID()
local xml = findTagWithId(ui, params.id) local xml = findTagWithId(ui, params.id)
@ -193,26 +196,6 @@ function updateXmlButtonHelper(ui, params)
-- add all buttons -- add all buttons
for _, d in ipairs(params.data) do for _, d in ipairs(params.data) do
local buttonID = tonumber(d.id)
if editing and buttonID < 19 then
if selectedEditButton < 0 then
color = "rgba(1,1,1,1)"
elseif buttonID == selectedEditButton then
color = "rgba(0,1,0,1)"
else
color = "rgba(1,0,0,1)"
end
elseif claiming and buttonID < 19 then
if buttonID >= 3 and buttonID <= 6 then
color = "rgba(1,1,1,1)"
else
color = "rgba(1,0,0,1)"
end
else
color = "rgba(0,1,0,0)"
end
table.insert(xml.children, { table.insert(xml.children, {
tag = "button", tag = "button",
attributes = { attributes = {
@ -221,7 +204,7 @@ function updateXmlButtonHelper(ui, params)
height = d.height, height = d.height,
width = d.width, width = d.width,
offsetXY = d.offset, offsetXY = d.offset,
color = color color = "rgba(0,1,0,0)"
} }
}) })
end end
@ -249,15 +232,22 @@ function buttonClicked(player, _, idValue)
if index == 19 then if index == 19 then
setVisibility("toggle", player.color) setVisibility("toggle", player.color)
return
elseif index == 20 then elseif index == 20 then
setVisibility("close", player.color) setVisibility("close", player.color)
return elseif index == 21 then
player.showInputDialog("Please enter your desired viewing angle in degrees (90 = bird's-eye view):", "75", updatePitch)
else
loadCamera(player, _, index)
end end
loadCamera(player, _, index)
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
function getDynamicViewBounds(objList) function getDynamicViewBounds(objList)
local count = 0 local count = 0
local totalBounds = { local totalBounds = {
@ -267,7 +257,7 @@ function getDynamicViewBounds(objList)
maxZ = -60 maxZ = -60
} }
for i, obj in pairs(objList) do for _, obj in pairs(objList) do
-- handling for Physics.cast() results -- handling for Physics.cast() results
if not obj.type then obj = obj.hit_object end if not obj.type then obj = obj.hit_object end
@ -302,85 +292,56 @@ function getDynamicViewBounds(objList)
return totalBounds return totalBounds
end end
-- loads the specified camera for a player
function loadCamera(player, _, index) function loadCamera(player, _, index)
local lookHere local lookHere
-- only do map zooming if the camera hasn't been specially set by user -- dynamic view of the play area
if index == 2 and cameraData[player.color][index].distance <= 0 then if index == 2 then
local bounds = getDynamicViewBounds(getObjectFromGUID("a2f932").getObjects()) local bounds = getDynamicViewBounds(getObjectFromGUID("a2f932").getObjects())
lookHere = { lookHere = {
position = { bounds.middleX, 1.55, bounds.middleZ }, position = { bounds.middleX, 1.55, bounds.middleZ },
pitch = 75,
yaw = 90, yaw = 90,
distance = 0.8 * math.max(bounds.diffX, bounds.diffZ) + 7 distance = 0.8 * math.max(bounds.diffX, bounds.diffZ) + 7
} }
-- dynamic view of the clicked play mat
elseif index >= 3 and index <= 6 then elseif index >= 3 and index <= 6 then
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 if #getSeatedPlayers() == 1 or claims[player.color][matColor] 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
if cameraData[player.color][index].distance <= 0 then local bounds = getDynamicViewBounds(playmatApi.searchPlaymat(matColor))
local bounds = getDynamicViewBounds(playmatApi.searchPlaymat(matColor))
lookHere = { lookHere = {
position = { bounds.middleX, 0, bounds.middleZ }, position = { bounds.middleX, 0, bounds.middleZ },
pitch = 75, yaw = playmatApi.returnRotation(matColor).y + 180,
yaw = playmatApi.returnRotation(matColor).y + 180, distance = 0.42 * math.max(bounds.diffX, bounds.diffZ) + 7
distance = 0.42 * math.max(bounds.diffX, bounds.diffZ) + 7 }
}
end
end end
-- get default data if no dynamic view (play area or play mat) was loaded
if not lookHere then
lookHere = cameraData[index]
lookHere.yaw = 90
end
-- set pitch to default if not edited
lookHere.pitch = pitch[player.color] or 75
-- delay is to account for colorswap -- delay is to account for colorswap
Wait.frames(function() player.lookAt(lookHere or cameraData[player.color][index]) end, 2) Wait.frames(function() player.lookAt(lookHere) end, 2)
end
function beginClaimColor()
claiming = true
updateXmlButtons()
end
function beginSetCamera()
editing = true
updateXmlButtons()
end
-- TO-DO: update this
editPos = { 0, 0, 0 }
editPitch = 0
editYaw = 0
editDistance = 0
selectedEditButton = -1
function updateEditCamera(params)
editPos = params[1]
editPitch = params[2]
editYaw = params[3]
editDistance = params[4]
end end
--------------------------------------------------------- ---------------------------------------------------------
-- functions to reset/initialize tables -- functions to reset/initialize tables
--------------------------------------------------------- ---------------------------------------------------------
function resetCameras()
for _, color in ipairs(Player.getColors()) do
cameraData[color] = {}
for i = 1, #defaultCameraData do
cameraData[color][i] = {}
cameraData[color][i].yaw = 90
cameraData[color][i].pitch = 75
cameraData[color][i].position = defaultCameraData[i].position
cameraData[color][i].distance = defaultCameraData[i].distance
end
end
end
function resetClaimColors() function resetClaimColors()
for _, seatedColor in ipairs(getSeatedPlayers()) do for _, seatedColor in ipairs(getSeatedPlayers()) do
claims[seatedColor] = {} claims[seatedColor] = {}
@ -389,9 +350,3 @@ function resetClaimColors()
end end
end end
end end
function resetVisibility()
for _, color in ipairs(Player.getColors()) do
visibility[color] = { full = false, play = false }
end
end