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