custom color support
This commit is contained in:
parent
d50f34bdc0
commit
df7673cdfb
@ -641,10 +641,10 @@ function onClick_load()
|
|||||||
UI.hide('load_button')
|
UI.hide('load_button')
|
||||||
end
|
end
|
||||||
|
|
||||||
function onClick_toggleUi(color, title)
|
function onClick_toggleUi(player, title)
|
||||||
if title == "Navigation Overlay" then
|
if title == "Navigation Overlay" then
|
||||||
local navigationOverlayHandler = getObjectFromGUID("797ede")
|
local navigationOverlayHandler = getObjectFromGUID("797ede")
|
||||||
navigationOverlayHandler.call("cycleVisibility", color)
|
navigationOverlayHandler.call("cycleVisibility", player.color)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
16
src/core/NavigationOverlayApi.ttslua
Normal file
16
src/core/NavigationOverlayApi.ttslua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
do
|
||||||
|
local NavigationOverlayApi = {}
|
||||||
|
local HANDLER_GUID = "797ede"
|
||||||
|
|
||||||
|
-- Copies the visibility for the Navigation overlay
|
||||||
|
---@param startColor String Color of the player to copy from
|
||||||
|
---@param targetColor String Color of the targeted player
|
||||||
|
NavigationOverlayApi.copyVisibility = function(startColor, targetColor)
|
||||||
|
getObjectFromGUID(HANDLER_GUID).call("copyVisibility", {
|
||||||
|
startColor = startColor,
|
||||||
|
targetColor = targetColor
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
return NavigationOverlayApi
|
||||||
|
end
|
@ -82,13 +82,11 @@ function onLoad(savedData)
|
|||||||
else
|
else
|
||||||
resetCameras()
|
resetCameras()
|
||||||
resetClaimColors()
|
resetClaimColors()
|
||||||
|
resetVisibility()
|
||||||
end
|
end
|
||||||
|
|
||||||
updateOverlay()
|
updateXmlButtons()
|
||||||
end
|
updateVisibility()
|
||||||
|
|
||||||
function closeOverlay(_, color)
|
|
||||||
setVisibility("close", color)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function cycleVisibility(color)
|
function cycleVisibility(color)
|
||||||
@ -96,19 +94,36 @@ function cycleVisibility(color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function setVisibility(type, color)
|
function setVisibility(type, color)
|
||||||
local visibility[color] = { full = false, play = false }
|
|
||||||
|
|
||||||
if type == "next" then
|
if type == "next" then
|
||||||
if visibility[color].full then
|
if visibility[color].full then
|
||||||
visibility[color] = { full = false, play = true }
|
visibility[color] = {
|
||||||
|
full = false,
|
||||||
|
play = true
|
||||||
|
}
|
||||||
elseif visibility[color].play then
|
elseif visibility[color].play then
|
||||||
visibility[color] = { full = false, play = false }
|
visibility[color] = {
|
||||||
|
full = false,
|
||||||
|
play = false
|
||||||
|
}
|
||||||
else
|
else
|
||||||
visibility[color] = { full = true, play = false }
|
visibility[color] = {
|
||||||
|
full = true,
|
||||||
|
play = false
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
elseif type == "toggle" then
|
||||||
|
visibility[color] = {
|
||||||
|
full = not visibility[color].full,
|
||||||
|
play = not visibility[color].play
|
||||||
|
}
|
||||||
|
else
|
||||||
|
visibility[color] = {
|
||||||
|
full = false,
|
||||||
|
play = false
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
updateOverlay()
|
updateVisibility()
|
||||||
end
|
end
|
||||||
|
|
||||||
function getIndices(color)
|
function getIndices(color)
|
||||||
@ -136,88 +151,58 @@ function resetCameras()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function resizeOverlay(object, color)
|
-- update XML visibility
|
||||||
for _, v in ipairs(getIndices(color)) do
|
function updateVisibility()
|
||||||
if v > 0 then
|
local fullColors = "Black"
|
||||||
local full = fullVisibility[v]
|
local playColors = "Black"
|
||||||
fullVisibility[v] = not full
|
|
||||||
playVisibility[v] = full
|
for color, v in pairs(visibility) do
|
||||||
|
if v.full then
|
||||||
|
fullColors = fullColors .. '|' .. color
|
||||||
|
elseif v.play then
|
||||||
|
playColors = playColors .. '|' .. color
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
updateOverlay()
|
log(fullColors)
|
||||||
|
log(playColors)
|
||||||
|
-- update the visibility on the XML
|
||||||
|
UI.setAttribute("navPanelFull", "visibility", fullColors)
|
||||||
|
UI.setAttribute("navPanelPlay", "visibility", playColors)
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateOverlay()
|
function updateXmlButtons()
|
||||||
-- update XML visibility
|
|
||||||
local fullColors, playColors
|
|
||||||
for i, v in pairs(fullVisibility) do
|
|
||||||
if v then
|
|
||||||
local matColor = getPlayerColorForIndex(i)
|
|
||||||
if fullColors and matColor ~= nil then
|
|
||||||
fullColors = fullColors .. '|' .. matColor
|
|
||||||
elseif matColor ~= nil then
|
|
||||||
fullColors = matColor
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, v in pairs(playVisibility) do
|
|
||||||
if v then
|
|
||||||
local matColor = getPlayerColorForIndex(i)
|
|
||||||
if playColors and matColor ~= nil then
|
|
||||||
playColors = playColors .. '|' .. matColor
|
|
||||||
elseif matColor ~= nil then
|
|
||||||
playColors = matColor
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fullColors then
|
|
||||||
updateXMLbuttons("full")
|
|
||||||
UI.setAttribute("navPanelFull", "visibility", fullColors)
|
|
||||||
UI.show("navPanelFull")
|
|
||||||
else
|
|
||||||
UI.hide("navPanelFull")
|
|
||||||
end
|
|
||||||
|
|
||||||
if playColors then
|
|
||||||
updateXMLbuttons("play")
|
|
||||||
UI.setAttribute("navPanelPlay", "visibility", playColors)
|
|
||||||
UI.show("navPanelPlay")
|
|
||||||
else
|
|
||||||
UI.hide("navPanelPlay")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function updateXMLbuttons(type)
|
|
||||||
local data, id, overlay, color
|
|
||||||
if type == "full" then
|
|
||||||
data = fullButtonData
|
|
||||||
id = "navPanelFull"
|
|
||||||
overlay = "OverlayLarge"
|
|
||||||
else
|
|
||||||
data = playButtonData
|
|
||||||
id = "navPanelPlay"
|
|
||||||
overlay = "OverlaySmall"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- XML button creation
|
|
||||||
local guid = self.getGUID()
|
|
||||||
local ui = UI.getXmlTable()
|
local ui = UI.getXmlTable()
|
||||||
local xml = findTagWithId(ui, id)
|
ui = updateXmlButtonHelper(ui, {
|
||||||
|
data = fullButtonData,
|
||||||
|
id = "navPanelFull",
|
||||||
|
overlay = "OverlayLarge"
|
||||||
|
})
|
||||||
|
ui = updateXmlButtonHelper(ui, {
|
||||||
|
data = playButtonData,
|
||||||
|
id = "navPanelPlay",
|
||||||
|
overlay = "OverlaySmall"
|
||||||
|
})
|
||||||
|
UI.setXmlTable(ui)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- XML button creation
|
||||||
|
function updateXmlButtonHelper(ui, params)
|
||||||
|
local color
|
||||||
|
local guid = self.getGUID()
|
||||||
|
local xml = findTagWithId(ui, params.id)
|
||||||
|
|
||||||
-- add basic image
|
-- add basic image
|
||||||
xml.children = { {
|
xml.children = { {
|
||||||
tag = "image",
|
tag = "image",
|
||||||
attributes = {
|
attributes = {
|
||||||
id = "backgroundImage",
|
id = "backgroundImage",
|
||||||
image = overlay
|
image = params.overlay
|
||||||
}
|
}
|
||||||
} }
|
} }
|
||||||
|
|
||||||
-- add all buttons
|
-- add all buttons
|
||||||
for _, d in ipairs(data) do
|
for _, d in ipairs(params.data) do
|
||||||
local buttonID = tonumber(d.id)
|
local buttonID = tonumber(d.id)
|
||||||
|
|
||||||
if editing and buttonID < 19 then
|
if editing and buttonID < 19 then
|
||||||
@ -250,8 +235,7 @@ function updateXMLbuttons(type)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
return ui
|
||||||
UI.setXmlTable(ui)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function findTagWithId(ui, id)
|
function findTagWithId(ui, id)
|
||||||
@ -270,10 +254,10 @@ function buttonClicked(player, _, idValue)
|
|||||||
local buttonID = tonumber(idValue)
|
local buttonID = tonumber(idValue)
|
||||||
|
|
||||||
if buttonID == 19 then
|
if buttonID == 19 then
|
||||||
resizeOverlay(nil, player.color)
|
setVisibility("toggle", player.color)
|
||||||
return
|
return
|
||||||
elseif buttonID == 20 then
|
elseif buttonID == 20 then
|
||||||
closeOverlay(nil, player.color)
|
setVisibility("close", player.color)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -294,44 +278,22 @@ function buttonClicked(player, _, idValue)
|
|||||||
selectedEditButton = -1
|
selectedEditButton = -1
|
||||||
end
|
end
|
||||||
|
|
||||||
updateOverlay()
|
updateXmlButtons()
|
||||||
elseif claiming then
|
elseif claiming then
|
||||||
if buttonID >= 3 and buttonID <= 6 then
|
if buttonID >= 3 and buttonID <= 6 then
|
||||||
local colorID = buttonID - 2
|
local colors = {"White", "Orange", "Green", "Red"}
|
||||||
local playerIndex = getIndexForPlayerColor(player.color)
|
local matColor = colors[buttonID - 2]
|
||||||
|
claims[player.color][matColor] = not claims[player.color][matColor]
|
||||||
-- if we haven't claimed it, break all earlier claims
|
|
||||||
if playermatData[playerIndex].claims[colorID] == false then
|
|
||||||
for i = 1, 4 do
|
|
||||||
if i ~= colorID then
|
|
||||||
playermatData[i].claims[colorID] = false
|
|
||||||
playermatData[colorID].claims[i] = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, 4 do
|
|
||||||
if playermatData[playerIndex].claims[i] then
|
|
||||||
playermatData[i].claims[colorID] = true
|
|
||||||
playermatData[colorID].claims[i] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
fullVisibility[colorID] = fullVisibility[playerIndex]
|
|
||||||
playVisibility[colorID] = playVisibility[playerIndex]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
claiming = false
|
claiming = false
|
||||||
updateOverlay()
|
updateXmlButtons()
|
||||||
else
|
else
|
||||||
loadCamera(player, _, buttonID)
|
loadCamera(player, _, buttonID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function loadCamera(player, _, index)
|
function loadCamera(player, _, index)
|
||||||
local playerColor = player.color
|
|
||||||
local playerIndex = getIndexForPlayerColor(playerColor)
|
|
||||||
|
|
||||||
-- only do map zooming if the camera hasn't been specially set by user
|
-- only do map zooming if the camera hasn't been specially set by user
|
||||||
if index == 2 and cameraParams[playerIndex][index].distance <= 0 then
|
if index == 2 and cameraParams[playerIndex][index].distance <= 0 then
|
||||||
local zone = getObjectFromGUID("a2f932")
|
local zone = getObjectFromGUID("a2f932")
|
||||||
@ -360,10 +322,13 @@ function loadCamera(player, _, index)
|
|||||||
})
|
})
|
||||||
elseif index >= 3 and index <= 6 then
|
elseif index >= 3 and index <= 6 then
|
||||||
local newMatIndex = index - 2 -- mat index 1 - 4
|
local newMatIndex = index - 2 -- mat index 1 - 4
|
||||||
local newMatColor = getPlayerColorForIndex(newMatIndex)
|
local colorList = { "White", "Orange", "Green", "Red" }
|
||||||
|
local newMatColor = colorList[newMatIndex]
|
||||||
|
local newPlayerColor = playmatApi.getPlayerColor(newMatColor)
|
||||||
|
|
||||||
if newMatColor ~= nil and (#getSeatedPlayers() == 1 or playermatData[playerIndex].claims[newMatIndex]) then
|
if newMatColor ~= nil and (#getSeatedPlayers() == 1 or claims[player.color][newMatColor]) then
|
||||||
player.changeColor(newMatColor)
|
copyVisibility({startColor = player.color, targetColor = newPlayerColor})
|
||||||
|
player.changeColor(newPlayerColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cameraParams[newMatIndex][index].distance <= 0 then
|
if cameraParams[newMatIndex][index].distance <= 0 then
|
||||||
@ -384,10 +349,10 @@ function loadCamera(player, _, index)
|
|||||||
|
|
||||||
-- White/Orange
|
-- White/Orange
|
||||||
if index == 3 or index == 4 then
|
if index == 3 or index == 4 then
|
||||||
divisor = {x = 1, z = 1.6 } -- screen ratio * 1.2 (for my macbook pro, no idea how to generalize this)
|
divisor = {x = 1.5, z = 1.5 } -- screen ratio * 1.2 (for my macbook pro, no idea how to generalize this)
|
||||||
-- Green/Red
|
-- Green/Red
|
||||||
else
|
else
|
||||||
divisor = {x = 1.6, z = 1}
|
divisor = {x = 1.5, z = 1.5}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- need to wait if the player color changed
|
-- need to wait if the player color changed
|
||||||
@ -403,13 +368,27 @@ function loadCamera(player, _, index)
|
|||||||
Wait.frames(function() player.lookAt(cameraParams[newMatIndex][index]) end, 2)
|
Wait.frames(function() player.lookAt(cameraParams[newMatIndex][index]) end, 2)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
local playerIndex = getIndexForPlayerColor(player.color)
|
||||||
player.lookAt(cameraParams[playerIndex][index])
|
player.lookAt(cameraParams[playerIndex][index])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function beginSetCamera(object, color)
|
function copyVisibility(params)
|
||||||
|
visibility[params.targetColor] = {
|
||||||
|
full = visibility[params.startColor].full,
|
||||||
|
play = visibility[params.startColor].play
|
||||||
|
}
|
||||||
|
updateVisibility()
|
||||||
|
end
|
||||||
|
|
||||||
|
function beginClaimColor()
|
||||||
|
claiming = true
|
||||||
|
updateXmlButtons()
|
||||||
|
end
|
||||||
|
|
||||||
|
function beginSetCamera()
|
||||||
editing = true
|
editing = true
|
||||||
updateOverlay()
|
updateXmlButtons()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TO-DO: update this
|
-- TO-DO: update this
|
||||||
@ -426,24 +405,19 @@ function updateEditCamera(params)
|
|||||||
editDistance = params[4]
|
editDistance = params[4]
|
||||||
end
|
end
|
||||||
|
|
||||||
function beginClaimColor()
|
|
||||||
claiming = true
|
|
||||||
updateOverlay()
|
|
||||||
end
|
|
||||||
|
|
||||||
function resetClaimColors()
|
function resetClaimColors()
|
||||||
for i = 1, 4 do
|
for _, seatedColor in ipairs(getSeatedPlayers()) do
|
||||||
for j = 1, 4 do
|
claims[seatedColor] = {}
|
||||||
playermatData[i].claims = {}
|
for _, color in ipairs(Player.getColors()) do
|
||||||
playermatData[i].claims[j] = (i == j)
|
claims[seatedColor][color] = (seatedColor == color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- helper functions
|
function resetVisibility()
|
||||||
function getPlayerColorForIndex(index)
|
for _, color in ipairs(Player.getColors()) do
|
||||||
local color = { "White", "Orange", "Green", "Red" }
|
visibility[color] = { full = false, play = false }
|
||||||
return color[index]
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function getIndexForPlayerColor(color)
|
function getIndexForPlayerColor(color)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
local tokenManager = require("core/token/TokenManager")
|
local tokenManager = require("core/token/TokenManager")
|
||||||
local tokenChecker = require("core/token/TokenChecker")
|
local tokenChecker = require("core/token/TokenChecker")
|
||||||
|
local navigationOverlayApi = require("core/NavigationOverlayApi")
|
||||||
|
|
||||||
-- set true to enable debug logging and show Physics.cast()
|
-- set true to enable debug logging and show Physics.cast()
|
||||||
local DEBUG = false
|
local DEBUG = false
|
||||||
@ -504,6 +505,7 @@ function changeColor(clickedByColor)
|
|||||||
|
|
||||||
-- if the seated player clicked this, reseat him to the new color
|
-- if the seated player clicked this, reseat him to the new color
|
||||||
if clickedByColor == playerColor then
|
if clickedByColor == playerColor then
|
||||||
|
navigationOverlayApi.copyVisibility(playerColor, color)
|
||||||
Player[playerColor].changeColor(color)
|
Player[playerColor].changeColor(color)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<!-- Defaults -->
|
<!-- Defaults -->
|
||||||
<Defaults>
|
<Defaults>
|
||||||
<Panel class="navPanel"
|
<Panel class="navPanel"
|
||||||
active="false"
|
visibility="Black"
|
||||||
allowDragging="true"
|
allowDragging="true"
|
||||||
rectAlignment="LowerRight"
|
rectAlignment="LowerRight"
|
||||||
returnToOriginalPositionWhenReleased="false"
|
returnToOriginalPositionWhenReleased="false"
|
||||||
|
Loading…
Reference in New Issue
Block a user