optimized code

This commit is contained in:
Zerino 2024-11-10 20:36:27 -03:00
parent 8f7cac79aa
commit 4733a9ef4a
2 changed files with 35 additions and 58 deletions

BIN
TTSModManager.exe Normal file

Binary file not shown.

View File

@ -27,7 +27,7 @@ local Y_VISIBLE = 0.25
local Y_INVISIBLE = -0.5 local Y_INVISIBLE = -0.5
-- Variable to check whether UI finished loading -- Variable to check whether UI finished loading
local isLoading = true; local isLoading = true
-- Used for Summoned Servitor and Living Ink -- Used for Summoned Servitor and Living Ink
local VECTOR_COLOR = { local VECTOR_COLOR = {
@ -154,7 +154,7 @@ function createRowCheckboxes(rowIndex)
end end
function getCheckboxPosition(row, col) function getCheckboxPosition(row, col)
return tostring((xInitial + col * xOffset) * -100) .. " " .. tostring(customizations[row].checkboxes.posZ * 100) .. " " .. tostring(-22) return translatePosition(xInitial + col * xOffset, customizations[row].checkboxes.posZ)
end end
function createRowTextField(rowIndex) function createRowTextField(rowIndex)
@ -169,8 +169,7 @@ function createRowTextField(rowIndex)
local func = function(player, value) clickTextbox(rowIndex, value) end local func = function(player, value) clickTextbox(rowIndex, value) end
self.setVar(funcName, func) self.setVar(funcName, func)
local posVector = Vector(textField.position) local actualPosition = translatePosition(textField.position[1], textField.position[3])
local actualPosition = tostring(posVector.x * -100) .. " " .. tostring(posVector.z * 100) .. " " .. tostring(-22)
local newTextbox = { local newTextbox = {
tag = "InputField", tag = "InputField",
attributes = { attributes = {
@ -192,6 +191,14 @@ function createRowTextField(rowIndex)
table.insert(xmlTable, newTextbox) table.insert(xmlTable, newTextbox)
end end
function translatePosition(posX, posZ)
-- position values are made strings to be usabled by the XML, height (z) is always -22
local translatedPosX = tostring(posX * -100)
local translatedPosY = tostring(posZ * 100)
local combinedPos = translatedPosX .. " " .. translatedPosY .. " " .. -22
return combinedPos
end
function updateDisplay() function updateDisplay()
for i = 1, #customizations do for i = 1, #customizations do
updateRowDisplay(i) updateRowDisplay(i)
@ -219,44 +226,10 @@ function updateCheckboxes(rowIndex)
for col = 1, checkboxCount do for col = 1, checkboxCount do
if col <= selected then if col <= selected then
local identifier = tostring(rowIndex) .. " " .. tostring(col) local identifier = tostring(rowIndex) .. " " .. tostring(col)
if isLoading then waitForUILoad(identifier, "color", "#000000")
Wait.condition(
function()
Wait.frames(
function()
isLoading = false;
self.UI.setAttribute(identifier, "color", "#000000")
end,
1
)
end,
function()
return not self.UI.loading
end
)
else
self.UI.setAttribute(identifier, "color", "#000000")
end
else else
local identifier = tostring(rowIndex) .. " " .. tostring(col) local identifier = tostring(rowIndex) .. " " .. tostring(col)
if isLoading then waitForUILoad(identifier, "color", "#48b02800")
Wait.condition(
function()
Wait.frames(
function()
isLoading = false;
self.UI.setAttribute(identifier, "color", "#48b02800")
end,
1
)
end,
function()
return not self.UI.loading
end
)
else
self.UI.setAttribute(identifier, "color", "#48b02800")
end
end end
checkboxIndex = checkboxIndex + 1 checkboxIndex = checkboxIndex + 1
end end
@ -265,24 +238,28 @@ end
function updateTextField(rowIndex) function updateTextField(rowIndex)
local inputIndex = rowInputIndex[rowIndex] local inputIndex = rowInputIndex[rowIndex]
if selectedUpgrades[rowIndex] ~= nil and selectedUpgrades[rowIndex].text ~= nil then if selectedUpgrades[rowIndex] ~= nil and selectedUpgrades[rowIndex].text ~= nil then
if isLoading then waitForUILoad(rowIndex, "text", selectedUpgrades[rowIndex].text)
Wait.condition( end
function() end
Wait.frames(
function() function waitForUILoad(id, attribute, value)
isLoading = false; if isLoading then
self.UI.setAttribute(rowIndex, "text", " " .. selectedUpgrades[rowIndex].text) Wait.condition(
end, function()
1 Wait.frames(
) function()
end, isLoading = false;
function() self.UI.setAttribute(id, attribute, value)
return not self.UI.loading end,
end 1
) )
else end,
self.UI.setAttribute(rowIndex, "text", " " .. selectedUpgrades[rowIndex].text) function()
end return not self.UI.loading
end
)
else
self.UI.setAttribute(id, attribute, value)
end end
end end