updated visibility

This commit is contained in:
Chr1Z93 2024-02-19 14:51:57 +01:00
parent 5e7ef9947c
commit 34825a42ee
4 changed files with 116 additions and 78 deletions

View File

@ -46,12 +46,6 @@ local library, requestObj, modMeta
local acknowledgedUpgradeVersions = {} local acknowledgedUpgradeVersions = {}
local contentToShow = "campaigns" local contentToShow = "campaigns"
local currentListItem = 1 local currentListItem = 1
local xmlVisibility = {
downloadWindow = false,
optionPanel = false,
playAreaGallery = false,
updateNotification = false
}
local tabIdTable = { local tabIdTable = {
tab1 = "campaigns", tab1 = "campaigns",
tab2 = "scenarios", tab2 = "scenarios",
@ -752,7 +746,7 @@ end
-- click function for the "Custom URL" button in the playarea image gallery -- click function for the "Custom URL" button in the playarea image gallery
function onClick_customUrl(player) function onClick_customUrl(player)
onClick_toggleUi(_, "playareaGallery") changeWindowVisibilityForColor(player.color, "playareaGallery")
Wait.time(function() Wait.time(function()
player.showInputDialog("Enter a custom URL for the playarea image", "", function(newURL) player.showInputDialog("Enter a custom URL for the playarea image", "", function(newURL)
playAreaApi.updateSurface(newURL) playAreaApi.updateSurface(newURL)
@ -770,12 +764,7 @@ end
-- the download button on the placeholder objects calls this to directly initiate a download -- the download button on the placeholder objects calls this to directly initiate a download
---@param params table contains url and guid of replacement object ---@param params table contains url and guid of replacement object
function placeholder_download(params) function placeholder_download(params)
local url = SOURCE_REPO .. '/' .. params.url function downloadCoroutine()
requestObj = WebRequest.get(url, function (request) contentDownloadCallback(request, params) end)
startLuaCoroutine(Global, 'downloadCoroutine')
end
function downloadCoroutine()
-- show progress bar -- show progress bar
UI.setAttribute('download_progress', 'active', true) UI.setAttribute('download_progress', 'active', true)
@ -795,22 +784,21 @@ function downloadCoroutine()
UI.setAttribute('download_progress', 'active', false) UI.setAttribute('download_progress', 'active', false)
-- hide download window -- hide download window
if xmlVisibility.downloadWindow then changeWindowVisibilityForColor(params.player.color, "downloadWindow", false)
xmlVisibility.downloadWindow = false
UI.hide('downloadWindow')
end
return 1 return 1
end
local url = SOURCE_REPO .. '/' .. params.url
requestObj = WebRequest.get(url, function (request) contentDownloadCallback(request, params) end)
startLuaCoroutine(Global, 'downloadCoroutine')
end end
-- spawns a bag that contains every object from the library -- spawns a bag that contains every object from the library
function onClick_downloadAll() function onClick_downloadAll(player)
broadcastToAll("Download initiated - this will take a few minutes!") broadcastToAll("Download initiated - this will take a few minutes!")
-- hide download window -- hide download window
if xmlVisibility.downloadWindow then changeWindowVisibilityForColor(player.color, "downloadWindow", false)
xmlVisibility.downloadWindow = false
UI.hide('downloadWindow')
end
startLuaCoroutine(Global, "coroutineDownloadAll") startLuaCoroutine(Global, "coroutineDownloadAll")
end end
@ -826,9 +814,9 @@ function coroutineDownloadAll()
"rotX": 0, "rotX": 0,
"rotY": 270, "rotY": 270,
"rotZ": 0, "rotZ": 0,
"scaleX": 1.0, "scaleX": 1,
"scaleY": 1.0, "scaleY": 1,
"scaleZ": 1.0 "scaleZ": 1
}, },
"Nickname": "{{NICKNAME}}", "Nickname": "{{NICKNAME}}",
"Bag": { "Bag": {
@ -875,7 +863,7 @@ function coroutineDownloadAll()
end end
-- spawns a placeholder box for the selected object -- spawns a placeholder box for the selected object
function onClick_spawnPlaceholder() function onClick_spawnPlaceholder(player)
-- get object references -- get object references
local item = library[contentToShow][currentListItem] local item = library[contentToShow][currentListItem]
local dummy = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlaceholderBoxDummy") local dummy = guidReferenceApi.getObjectByOwnerAndType("Mythos", "PlaceholderBoxDummy")
@ -926,39 +914,84 @@ function onClick_spawnPlaceholder()
Player.getPlayers()[1].pingTable(spawnPos) Player.getPlayers()[1].pingTable(spawnPos)
-- hide download window -- hide download window
if xmlVisibility.downloadWindow then changeWindowVisibilityForColor(player.color, "downloadWindow", false)
xmlVisibility.downloadWindow = false
UI.hide('downloadWindow')
end
end end
-- toggles the visibility of the respective UI -- toggles the visibility of the respective UI
---@param player tts__Player Player that triggered this ---@param player tts__Player Player that triggered this
---@param title string Name of the UI to toggle ---@param windowId string Name of the UI to toggle
function onClick_toggleUi(player, title) function onClick_toggleUi(player, windowId)
if title == "Navigation Overlay" then if windowId == "Navigation Overlay" then
navigationOverlayApi.cycleVisibility(player.color) navigationOverlayApi.cycleVisibility(player.color)
return return
-- hide the playareaGallery if visible
elseif title == "downloadWindow" and xmlVisibility.playAreaGallery then
onClick_toggleUi(_, "playAreaGallery")
-- hide the downloadWindow if visible
elseif title == "playAreaGallery" and xmlVisibility.downloadWindow then
onClick_toggleUi(_, "downloadWindow")
end end
if xmlVisibility[title] then -- hide the playAreaGallery if visible
-- small delay to allow button click sounds to play if windowId == "downloadWindow" then
Wait.time(function() UI.hide(title) end, 0.1) changeWindowVisibilityForColor(player.color, "playAreaGallery", false)
else -- hide the downloadWindow if visible
UI.show(title) elseif windowId == "playAreaGallery" then
changeWindowVisibilityForColor(player.color, "downloadWindow", false)
end end
xmlVisibility[title] = not xmlVisibility[title]
changeWindowVisibilityForColor(player.color, windowId)
end
-- toggles the visibility of the specific window for the specified color
---@param color string Player color to toggle the visibility for
---@param windowId string ID of the XML element
---@param overrideState? boolean Forcefully sets the new visibility
---@return boolean visible Returns the new state of the visibility
function changeWindowVisibilityForColor(color, windowId, overrideState)
-- current state
local colorString = UI.getAttribute(windowId, "visibility") or ""
-- parse the visibility string
local visible = false
local viewers = {}
for str in string.gmatch(colorString, "%a+") do
table.insert(viewers, str)
if str == color then
visible = true
end
end
-- add / remove the color as viewer
if visible == true then
removeValueFromTable(viewers, color)
elseif visible == false then
table.insert(viewers, color)
end
visible = not visible
-- resolve override
if overrideState == true and visible == false then
table.insert(viewers, color)
visible = true
elseif overrideState == false and visible == true then
removeValueFromTable(viewers, color)
visible = false
end
-- construct new string
local newColorString = ""
for _, viewer in ipairs(viewers) do
newColorString = newColorString .. viewer .. "|"
end
-- remove last delimiter
newColorString = newColorString:sub(1, -2)
-- update the visibility of the XML
UI.setAttribute(windowId, "visibility", newColorString)
UI.setAttribute(windowId, "active", newColorString ~= "")
return visible
end end
-- forwards the call to the onClick function -- forwards the call to the onClick function
function togglePlayAreaGallery() function togglePlayAreaGallery(playerColor)
onClick_toggleUi(_, "playAreaGallery") changeWindowVisibilityForColor(playerColor, "playareaGallery")
end end
-- updates the preview window -- updates the preview window
@ -1614,5 +1647,17 @@ function onClick_notification(_, parameter)
end end
UI.hide("FinnIcon") UI.hide("FinnIcon")
UI.hide("updateNotification") UI.hide("updateNotification")
xmlVisibility["updateNotification"] = false end
---------------------------------------------------------
-- Utility functions
---------------------------------------------------------
function removeValueFromTable(t, val)
for i, v in ipairs(t) do
if v == val then
table.remove(t, i)
break
end
end
end end

View File

@ -24,13 +24,8 @@ function onLoad(savedData)
end end
-- click function for main button -- click function for main button
function onClick_toggleGallery() function onClick_toggleGallery(_, playerColor)
Global.call("togglePlayAreaGallery") Global.call("togglePlayAreaGallery", playerColor)
end
function onClick_defaultImage()
playAreaApi.updateSurface()
Global.call("togglePlayAreaGallery")
end end
function getDataSubTableByIndex(dataTable, index) function getDataSubTableByIndex(dataTable, index)
@ -108,13 +103,13 @@ function onClick_listItem(_, _, listId)
updatePlayAreaGallery() updatePlayAreaGallery()
end end
function onClick_image(_, _, id) function onClick_image(player, _, id)
local imageIndex = tonumber(id:sub(6)) local imageIndex = tonumber(id:sub(6))
local dataForType = getDataSubTableByIndex(PLAYAREA_IMAGE_DATA, typeIndex) local dataForType = getDataSubTableByIndex(PLAYAREA_IMAGE_DATA, typeIndex)
local dataForSelection = getDataSubTableByIndex(dataForType, selectionIndex) local dataForSelection = getDataSubTableByIndex(dataForType, selectionIndex)
local newURL = dataForSelection[imageIndex].URL local newURL = dataForSelection[imageIndex].URL
playAreaApi.updateSurface(newURL) playAreaApi.updateSurface(newURL)
Global.call("togglePlayAreaGallery") Global.call("togglePlayAreaGallery", player.color)
end end
function highlightTabAndItem() function highlightTabAndItem()

View File

@ -22,7 +22,6 @@
<!-- window to select downloadable content --> <!-- window to select downloadable content -->
<VerticalLayout id="downloadWindow" <VerticalLayout id="downloadWindow"
visibility="Admin"
color="black" color="black"
active="false" active="false"
height="800" height="800"

View File

@ -85,7 +85,6 @@
<!-- Option Panel --> <!-- Option Panel -->
<TableLayout id="optionPanel" <TableLayout id="optionPanel"
class="window" class="window"
visibility="Admin"
rectAlignment="LowerRight" rectAlignment="LowerRight"
offsetXY="-50 80" offsetXY="-50 80"
raycastTarget="true"> raycastTarget="true">