updated xml

This commit is contained in:
Chr1Z93 2024-09-02 00:46:09 +02:00
parent 34538cfca1
commit 33c48c6076

View File

@ -1,7 +1,7 @@
local MIN_VALUE, MAX_VALUE = 0, 99 local MIN_VALUE, MAX_VALUE = 0, 99
val = 0 val = 0
function onSave() return JSON.encode(val) end function updateSave() self.script_state = val end
function onLoad(savedData) function onLoad(savedData)
if savedData and savedData ~= "" then if savedData and savedData ~= "" then
@ -46,29 +46,29 @@ function createXml()
local uiColor, uiVal = getUiColorAndVal() local uiColor, uiVal = getUiColorAndVal()
local xml = { local xml = {
{ {
tag = "Panel", tag = "Button",
attributes = { attributes = {
id = "valuePanel", id = "xmlBtn",
onClick = "addOrSubtract",
image = "circle", image = "circle",
raycastTarget = self.locked, onClick = "addOrSubtract",
scale = "0.4 0.4 1", scale = "0.35 0.35 1",
color = uiColor, colors = uiColor,
height = params.size,
width = params.size,
position = "0 0 -6", position = "0 0 -6",
rotation = "0 0 180", rotation = "0 0 180",
height = params.size,
width = params.size,
offsetXY = params.offsetXY offsetXY = params.offsetXY
}, },
children = { children = {
{ {
tag = "Text", tag = "Text",
attributes = { attributes = {
id = "valueText", id = "xmlTxt",
text = uiVal, fontStyle = "Bold",
color = "#FFFFFF",
fontSize = params.fontSize, fontSize = params.fontSize,
font = "font_teutonic-arkham" font = "font_teutonic-arkham",
text = uiVal,
color = "#FFFFFF"
} }
} }
} }
@ -77,11 +77,6 @@ function createXml()
self.UI.setXmlTable(xml) self.UI.setXmlTable(xml)
end end
-- update clickability based on lock status
function onHover()
self.UI.setAttribute("valuePanel", "raycastTarget", self.locked)
end
-- rotate to face-up when dropped -- rotate to face-up when dropped
function onDrop() function onDrop()
self.setRotation(self.getRotation():setAt("z", 0)) self.setRotation(self.getRotation():setAt("z", 0))
@ -89,17 +84,21 @@ end
-- value == 1 and unlocked -> no label/background -- value == 1 and unlocked -> no label/background
function getUiColorAndVal() function getUiColorAndVal()
if not self.locked and val == 1 then if val == 1 then
return "#00000000", "" return getColorBlock("#00000000"), ""
else else
return params.color, val return getColorBlock(params.color), val
end end
end end
function getColorBlock(hexColor)
return table.concat({hexColor, hexColor, hexColor}, "|")
end
function updateLabel() function updateLabel()
local uiColor, uiVal = getUiColorAndVal() local uiColor, uiVal = getUiColorAndVal()
self.UI.setAttribute("valuePanel", "color", uiColor) self.UI.setAttribute("xmlBtn", "colors", uiColor)
self.UI.setAttribute("valueText", "text", uiVal) self.UI.setAttribute("xmlTxt", "text", uiVal)
end end
-- sets the value to 'newVal' -- sets the value to 'newVal'
@ -107,6 +106,7 @@ function updateVal(newVal)
if tonumber(newVal) then if tonumber(newVal) then
val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE) val = math.min(math.max(newVal, MIN_VALUE), MAX_VALUE)
updateLabel() updateLabel()
updateSave()
end end
end end