Improved percentage variable usage, and made percentage button creation its own function
This commit is contained in:
parent
92e8659ca9
commit
52e91a72c6
@ -21,7 +21,6 @@ inputParameters.tab = 2
|
|||||||
local latestLoad = "XXX"
|
local latestLoad = "XXX"
|
||||||
local updating = false
|
local updating = false
|
||||||
local percentage = false
|
local percentage = false
|
||||||
local cumulative = false
|
|
||||||
local tokenPrecedence = {}
|
local tokenPrecedence = {}
|
||||||
local TOKEN_NAMES = {
|
local TOKEN_NAMES = {
|
||||||
"Elder Sign",
|
"Elder Sign",
|
||||||
@ -62,19 +61,20 @@ function onLoad(saveState)
|
|||||||
layout()
|
layout()
|
||||||
end)
|
end)
|
||||||
self.addContextMenuItem("Toggle Percentages", function()
|
self.addContextMenuItem("Toggle Percentages", function()
|
||||||
percentage = not percentage
|
if percentage then
|
||||||
|
percentage = false
|
||||||
|
else
|
||||||
|
percentage = "basic"
|
||||||
|
end
|
||||||
layout()
|
layout()
|
||||||
end)
|
end)
|
||||||
self.addContextMenuItem("Toggle Cumulative\n______Percentages", function()
|
self.addContextMenuItem("Toggle Cumulative\n______Percentages", function()
|
||||||
if percentage then
|
if percentage == "basic" or not percentage then
|
||||||
cumulative = not cumulative
|
percentage = "cumulative"
|
||||||
else
|
|
||||||
percentage = true
|
|
||||||
cumulative = true
|
|
||||||
end
|
|
||||||
if cumulative then
|
|
||||||
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)
|
||||||
end
|
else
|
||||||
|
percentage = "basic"
|
||||||
|
end
|
||||||
layout()
|
layout()
|
||||||
end)
|
end)
|
||||||
layout()
|
layout()
|
||||||
@ -233,6 +233,28 @@ function deleteCopiedTokens()
|
|||||||
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
|
||||||
|
function createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
||||||
|
local cumulative_percentage = cumulative_percentage or false
|
||||||
|
local offset = 2.2
|
||||||
|
local label_string = string.format("%s", string.format("%05.2f", math.floor((token_count / #data) * 10000) / 100) .. "%")
|
||||||
|
|
||||||
|
if cumulative_percentage then
|
||||||
|
offset = 3.8
|
||||||
|
label_string = string.format("%s", "(" .. string.format("%05.2f", cumulative_percentage) .. "%)")
|
||||||
|
end
|
||||||
|
|
||||||
|
self.createButton({
|
||||||
|
label = label_string,
|
||||||
|
click_function = "print",
|
||||||
|
width = 0,
|
||||||
|
height = 0,
|
||||||
|
scale = {2, 2, 2},
|
||||||
|
font_color = {r=1,g=1,b=1},
|
||||||
|
position = (Vector(offset, -0.05, -2.675) + Vector((0.875 * token_count) + 0.1, 0, 0.875 * value_count))
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
-- main function (delete old tokens, clone chaos bag content, sort it and position it)
|
-- main function (delete old tokens, clone chaos bag content, sort it and position it)
|
||||||
function layout(_, _, isRightClick)
|
function layout(_, _, isRightClick)
|
||||||
if updating then return end
|
if updating then return end
|
||||||
@ -292,25 +314,9 @@ function layout(_, _, isRightClick)
|
|||||||
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
|
||||||
self.createButton({
|
createPercentageButton(token_count, value_count, data)
|
||||||
label = string.format("%s", string.format("%05.2f", math.floor((token_count / #data) * 10000) / 100) .. "%"),
|
if percentage == "cumulative" then
|
||||||
click_function = "print",
|
createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
||||||
width = 0,
|
|
||||||
height = 0,
|
|
||||||
scale = {2, 2, 2},
|
|
||||||
font_color = {r=1,g=1,b=1},
|
|
||||||
position = (Vector(2.2, -0.05, -2.675) + Vector((0.875 * token_count) + 0.1, 0, 0.875 * value_count))
|
|
||||||
})
|
|
||||||
if cumulative then
|
|
||||||
self.createButton({
|
|
||||||
label = string.format("%s", "(" .. string.format("%05.2f", cumulative_percentage) .. "%)"),
|
|
||||||
click_function = "print",
|
|
||||||
width = 0,
|
|
||||||
height = 0,
|
|
||||||
scale = {2, 2, 2},
|
|
||||||
font_color = {r=1,g=1,b=1},
|
|
||||||
position = (Vector(3.8, -0.05, -2.675) + Vector((0.875 * token_count) + 0.1, 0, 0.875 * value_count))
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
location.x = location.x - 1.75
|
location.x = location.x - 1.75
|
||||||
@ -326,25 +332,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
|
||||||
self.createButton({
|
createPercentageButton(token_count, value_count, data)
|
||||||
label = string.format("%s", string.format("%05.2f", math.floor((token_count / #data) * 10000) / 100) .. "%"),
|
if percentage == "cumulative" then
|
||||||
click_function = "print",
|
createPercentageButton(token_count, value_count, data, cumulative_percentage)
|
||||||
width = 0,
|
|
||||||
height = 0,
|
|
||||||
scale = {2, 2, 2},
|
|
||||||
font_color = {r=1,g=1,b=1},
|
|
||||||
position = (Vector(2.2, -0.05, -2.675) + Vector((0.875 * token_count) + 0.1, 0, 0.875 * value_count))
|
|
||||||
})
|
|
||||||
if cumulative then
|
|
||||||
self.createButton({
|
|
||||||
label = string.format("%s", "(" .. string.format("%05.1f", cumulative_percentage) .. "%)"),
|
|
||||||
click_function = "print",
|
|
||||||
width = 0,
|
|
||||||
height = 0,
|
|
||||||
scale = {2, 2, 2},
|
|
||||||
font_color = {r=1,g=1,b=1},
|
|
||||||
position = (Vector(3.8, -0.05, -2.675) + Vector((0.875 * token_count) + 0.1, 0, 0.875 * value_count))
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user