Added colors to percentages, fixed some minor issues in logic, and updated tooltips for buttons
This commit is contained in:
parent
5688f26edd
commit
5b17cca20f
@ -39,7 +39,8 @@ local TOKEN_NAMES = {
|
|||||||
function onSave()
|
function onSave()
|
||||||
return JSON.encode({
|
return JSON.encode({
|
||||||
tokenPrecedence = tokenPrecedence,
|
tokenPrecedence = tokenPrecedence,
|
||||||
latestLoad = latestLoad
|
latestLoad = latestLoad,
|
||||||
|
percentage = percentage
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -48,11 +49,12 @@ function onLoad(saveState)
|
|||||||
local loadedData = JSON.decode(saveState)
|
local loadedData = JSON.decode(saveState)
|
||||||
tokenPrecedence = loadedData.tokenPrecedence
|
tokenPrecedence = loadedData.tokenPrecedence
|
||||||
latestLoad = loadedData.latestLoad or "XXX"
|
latestLoad = loadedData.latestLoad or "XXX"
|
||||||
|
percentage = loadedData.percentage
|
||||||
else
|
else
|
||||||
loadDefaultValues()
|
loadDefaultValues()
|
||||||
end
|
end
|
||||||
|
|
||||||
createDefaultButtons(true)
|
createDefaultButtonsAndInputs(true)
|
||||||
|
|
||||||
-- reset context menu
|
-- reset context menu
|
||||||
self.addContextMenuItem("Load default values", function()
|
self.addContextMenuItem("Load default values", function()
|
||||||
@ -68,7 +70,7 @@ function onLoad(saveState)
|
|||||||
end
|
end
|
||||||
layout()
|
layout()
|
||||||
end)
|
end)
|
||||||
self.addContextMenuItem("Toggle Cumulative\n______Percentages", function()
|
self.addContextMenuItem("Toggle Cumulative", function()
|
||||||
if percentage == "basic" or not percentage then
|
if percentage == "basic" or not percentage then
|
||||||
percentage = "cumulative"
|
percentage = "cumulative"
|
||||||
broadcastToAll("Cumulative percentages are unreliable when using tokens that draw other tokens (bless or curse for example)", Color.Yellow)
|
broadcastToAll("Cumulative percentages are unreliable when using tokens that draw other tokens (bless or curse for example)", Color.Yellow)
|
||||||
@ -146,12 +148,12 @@ function loadDefaultValues()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- creates all starting buttons and inputs
|
-- creates all starting buttons and inputs
|
||||||
function createDefaultButtons(loadInputs)
|
function createDefaultButtonsAndInputs(loadInputs)
|
||||||
loadInputs = loadInputs or false
|
loadInputs = loadInputs or false
|
||||||
|
|
||||||
buttonParameters.function_owner = self
|
buttonParameters.function_owner = self
|
||||||
buttonParameters.label = ""
|
buttonParameters.label = ""
|
||||||
buttonParameters.tooltip = "Add / Remove"
|
buttonParameters.tooltip = "Increase / Decrease"
|
||||||
buttonParameters.color = { 0, 0, 0, 0 }
|
buttonParameters.color = { 0, 0, 0, 0 }
|
||||||
buttonParameters.width = 325
|
buttonParameters.width = 325
|
||||||
buttonParameters.height = 325
|
buttonParameters.height = 325
|
||||||
@ -229,24 +231,37 @@ end
|
|||||||
-- deletes previously placed tokens AND percentage buttons
|
-- deletes previously placed tokens AND percentage buttons
|
||||||
function deleteCopiedTokens()
|
function deleteCopiedTokens()
|
||||||
self.clearButtons()
|
self.clearButtons()
|
||||||
createDefaultButtons()
|
createDefaultButtonsAndInputs()
|
||||||
for _, token in ipairs(getObjectsWithTag("tempToken")) do token.destruct() end
|
for _, token in ipairs(getObjectsWithTag("tempToken")) do token.destruct() end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- creates percentage representation buttons
|
-- creates percentage representation buttons
|
||||||
function createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
function createPercentageButton(token_count, value_count, data, token_name, cumulative_percentage)
|
||||||
local offset = -2.675
|
local offset = -2.675
|
||||||
local label_string = string.format("%s", string.format("%05.2f", math.floor((token_count / #data) * 10000) / 100) .. "%")
|
local label_string = string.format("%s", string.format("%05.2f", math.floor((token_count / #data) * 10000) / 100) .. "%")
|
||||||
local buttonScale = {2, 2, 2}
|
local buttonScale = {2, 2, 2}
|
||||||
|
local textColor = {1, 1, 1}
|
||||||
if percentage == "cumulative" then
|
if percentage == "cumulative" then
|
||||||
|
|
||||||
buttonScale = {1.5, 1.5, 1.5}
|
buttonScale = {1.5, 1.5, 1.5}
|
||||||
offset = -2.9
|
offset = -2.85
|
||||||
end
|
end
|
||||||
if cumulative_percentage then
|
if cumulative_percentage then
|
||||||
offset = -2.5
|
offset = -2.45
|
||||||
label_string = string.format("%s", "(" .. string.format("%05.2f", cumulative_percentage) .. "%)")
|
textColor = {1, 1, 1}
|
||||||
|
label_string = string.format("%s", string.format("%05.2f", cumulative_percentage) .. "%")
|
||||||
if cumulative_percentage == 100 then
|
if cumulative_percentage == 100 then
|
||||||
label_string = string.format("%s", "(" .. string.format("%05.1f", cumulative_percentage) .. "%)")
|
label_string = string.format("%s", string.format("%05.1f", cumulative_percentage) .. "%")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if token_name == "Elder Sign" then
|
||||||
|
textColor = {0.35, 0.71, 0.85}
|
||||||
|
elseif token_name == "Auto-fail" then
|
||||||
|
textColor = {0.86, 0.1, 0.1}
|
||||||
|
elseif token_name then
|
||||||
|
textColor = {0.68, 0.53, 0.86}
|
||||||
|
else
|
||||||
|
textColor = {0.85, 0.67, 0.33}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -256,7 +271,7 @@ function createPercentageButton(token_count, value_count, data, cumulative_perce
|
|||||||
width = 0,
|
width = 0,
|
||||||
height = 0,
|
height = 0,
|
||||||
scale = buttonScale,
|
scale = buttonScale,
|
||||||
font_color = {r=1,g=1,b=1},
|
font_color = textColor,
|
||||||
position = (Vector(2.2, -0.05, offset) + Vector(0.1, 0, 0.875 * value_count))
|
position = (Vector(2.2, -0.05, offset) + Vector(0.1, 0, 0.875 * value_count))
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -318,14 +333,15 @@ function layout(_, _, isRightClick)
|
|||||||
local token_count = 0
|
local token_count = 0
|
||||||
local value_count = 1
|
local value_count = 1
|
||||||
local cumulative_percentage = 0
|
local cumulative_percentage = 0
|
||||||
|
local current_token = false
|
||||||
|
|
||||||
for _, item in ipairs(data) do
|
for _, item in ipairs(data) do
|
||||||
if item.value ~= current_value then
|
if item.value ~= current_value then
|
||||||
if percentage then
|
if percentage then
|
||||||
cumulative_percentage = cumulative_percentage + math.floor((token_count / #data) * 10000) / 100
|
cumulative_percentage = cumulative_percentage + math.floor((token_count / #data) * 10000) / 100
|
||||||
createPercentageButton(token_count, value_count, data)
|
createPercentageButton(token_count, value_count, data, current_token)
|
||||||
if percentage == "cumulative" then
|
if percentage == "cumulative" then
|
||||||
createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
createPercentageButton(token_count, value_count, data, current_token, cumulative_percentage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
location.x = location.x - 1.75
|
location.x = location.x - 1.75
|
||||||
@ -333,6 +349,10 @@ function layout(_, _, isRightClick)
|
|||||||
current_value = item.value
|
current_value = item.value
|
||||||
value_count = value_count + 1
|
value_count = value_count + 1
|
||||||
token_count = 0
|
token_count = 0
|
||||||
|
current_token = false
|
||||||
|
end
|
||||||
|
if string.match(item.token.getName(), "%a") ~= nil then
|
||||||
|
current_token = item.token.getName()
|
||||||
end
|
end
|
||||||
item.token.setPosition(location)
|
item.token.setPosition(location)
|
||||||
item.token.setRotation(self.getRotation())
|
item.token.setRotation(self.getRotation())
|
||||||
@ -341,9 +361,9 @@ function layout(_, _, isRightClick)
|
|||||||
end
|
end
|
||||||
if percentage then
|
if percentage then
|
||||||
cumulative_percentage = cumulative_percentage + math.floor((token_count / #data) * 10000) / 100
|
cumulative_percentage = cumulative_percentage + math.floor((token_count / #data) * 10000) / 100
|
||||||
createPercentageButton(token_count, value_count, data)
|
createPercentageButton(token_count, value_count, data, current_token)
|
||||||
if percentage == "cumulative" then
|
if percentage == "cumulative" then
|
||||||
createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
createPercentageButton(token_count, value_count, data, current_token, cumulative_percentage)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user