59 lines
1.9 KiB
Plaintext
59 lines
1.9 KiB
Plaintext
local buttonParameters = {}
|
|
buttonParameters.function_owner = self
|
|
buttonParameters.height = 650
|
|
buttonParameters.width = 700
|
|
buttonParameters.position = { x = -4.775, y = 0.1, z = -0.03 }
|
|
buttonParameters.color = { 0, 0, 0, 0 }
|
|
buttonParameters.font_color = { 0, 0, 0, 100 }
|
|
buttonParameters.font_size = 450
|
|
|
|
function onSave() return JSON.encode(stats) end
|
|
|
|
-- load stats and make buttons (left to right)
|
|
function onLoad(savedData)
|
|
if savedData and savedData ~= "" then
|
|
stats = JSON.decode(savedData) or { 1, 1, 1, 1 }
|
|
end
|
|
|
|
for index = 1, 4 do
|
|
local fnName = "buttonClick" .. index
|
|
_G[fnName] = function(_, _, isRightClick) buttonClick(isRightClick, index) end
|
|
buttonParameters.click_function = fnName
|
|
buttonParameters.position.x = buttonParameters.position.x + 1.91
|
|
self.createButton(buttonParameters)
|
|
updateButtonLabel(index)
|
|
end
|
|
|
|
self.addContextMenuItem("Reset to 1s", function() updateStats({ 1, 1, 1, 1 }) end)
|
|
end
|
|
|
|
function buttonClick(isRightClick, index)
|
|
stats[index] = math.min(math.max(stats[index] + (isRightClick and -1 or 1), 0), 99)
|
|
updateButtonLabel(index)
|
|
end
|
|
|
|
-- sync the button label to the internal value
|
|
function updateButtonLabel(index)
|
|
local fontSize = buttonParameters.font_size
|
|
local whitespace = " "
|
|
|
|
if stats[index] > 9 then
|
|
fontSize = buttonParameters.font_size * 0.65
|
|
whitespace = " "
|
|
end
|
|
|
|
self.editButton({ index = index - 1, label = stats[index] .. whitespace, font_size = fontSize })
|
|
end
|
|
|
|
-- update the stats to the provided values
|
|
---@param newStats table Contains the new values for the stats: {Willpower, Intellect, Fight, Agility}
|
|
function updateStats(newStats)
|
|
if newStats and #newStats == 4 then
|
|
stats = newStats
|
|
|
|
for i = 1, 4 do updateButtonLabel(i) end
|
|
elseif newStats then
|
|
printToAll("Provided new stats are incomplete or incorrectly formatted.", "Red")
|
|
end
|
|
end
|