Merge pull request #974 from YumiWhellie/main

Created XML for customizable' upgrade sheets
This commit is contained in:
Chr1Z 2024-11-11 00:43:04 +01:00 committed by GitHub
commit 3cd93501ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 93 additions and 51 deletions

BIN
TTSModManager.exe Normal file

Binary file not shown.

View File

@ -29,7 +29,7 @@ customizations = {
[4] = {
checkboxes = {
posZ = -0.092,
count = 2,
count = 1,
}
},
[5] = {

View File

@ -26,6 +26,9 @@ local playermatApi = require("playermat/PlayermatApi")
local Y_VISIBLE = 0.25
local Y_INVISIBLE = -0.5
-- Variable to check whether UI finished loading
local isLoading = true
-- Used for Summoned Servitor and Living Ink
local VECTOR_COLOR = {
unselected = { 0.5, 0.5, 0.5, 0.75 },
@ -60,6 +63,22 @@ function onLoad(savedData)
selfId = getSelfId()
maybeLoadLivingInkSkills()
xmlTable = {
{
tag = "Defaults",
children = {
{
tag = "Button",
attributes = {
color = "#48b028",
height = 70,
width = 70,
scale = "0.1 0.1 0.1",
}
}
}
}
}
createUi()
maybeUpdateLivingInkSkillDisplay()
maybeUpdateServitorSlotDisplay()
@ -103,6 +122,7 @@ function createUi()
createRowTextField(i)
end
end
self.UI.setXmlTable(xmlTable)
maybeMakeLivingInkSkillSelectionButtons()
maybeMakeServitorSlotSelectionButtons()
updateDisplay()
@ -120,27 +140,21 @@ function createRowCheckboxes(rowIndex)
local func = function() clickCheckbox(rowIndex, col) end
self.setVar(funcName, func)
local checkboxPos = getCheckboxPosition(rowIndex, col)
self.createButton({
click_function = funcName,
function_owner = self,
position = checkboxPos,
height = boxSize * 10,
width = boxSize * 10,
font_size = 1000,
scale = { 0.1, 0.1, 0.1 },
color = { 0, 0, 0 },
font_color = { 0, 0, 0 }
})
local identifier = tostring(rowIndex) .. " " .. tostring(col)
local newCheckbox = {
tag = "Button",
attributes = {
onClick = funcName,
position = checkboxPos,
id = identifier,
}
}
table.insert(xmlTable, newCheckbox)
end
end
function getCheckboxPosition(row, col)
return {
x = xInitial + col * xOffset,
y = Y_VISIBLE,
z = customizations[row].checkboxes.posZ
}
return translatePosition(xInitial + col * xOffset, customizations[row].checkboxes.posZ)
end
function createRowTextField(rowIndex)
@ -152,22 +166,37 @@ function createRowTextField(rowIndex)
rowInputIndex[rowIndex] = #previousInputs
end
local funcName = "textbox" .. rowIndex
local func = function(_, _, val, sel) clickTextbox(rowIndex, val, sel) end
local func = function(player, value) clickTextbox(rowIndex, value) end
self.setVar(funcName, func)
self.createInput({
input_function = funcName,
function_owner = self,
label = "Click to type",
alignment = 2,
position = textField.position,
scale = { 0.1, 0.1, 0.1 },
width = textField.width * 10,
height = inputFontsize * 10 + 75,
font_size = inputFontsize * 10.5,
color = "White",
value = ""
})
local actualPosition = translatePosition(textField.position[1], textField.position[3])
local newTextbox = {
tag = "InputField",
attributes = {
onEndEdit = funcName,
id = rowIndex,
placeholder = "Click to type",
position = actualPosition,
alignment = "UpperLeft",
width = textField.width,
height = (inputFontsize + 15),
fontSize = inputFontsize,
resizeTextForBestFit = true,
fontStyle = "Bold",
rotation = "0 0 180",
scale = "0.2 0.2 0.2",
color = "#FFFFFF",
}
}
table.insert(xmlTable, newTextbox)
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()
@ -195,16 +224,13 @@ function updateCheckboxes(rowIndex)
end
local checkboxIndex = rowCheckboxFirstIndex[rowIndex]
for col = 1, checkboxCount do
local pos = getCheckboxPosition(rowIndex, col)
if col <= selected then
pos.y = Y_VISIBLE
local identifier = tostring(rowIndex) .. " " .. tostring(col)
waitForUILoad(identifier, "color", "#000000")
else
pos.y = Y_INVISIBLE
local identifier = tostring(rowIndex) .. " " .. tostring(col)
waitForUILoad(identifier, "color", "#48b02800")
end
self.editButton({
index = checkboxIndex,
position = pos
})
checkboxIndex = checkboxIndex + 1
end
end
@ -212,10 +238,28 @@ end
function updateTextField(rowIndex)
local inputIndex = rowInputIndex[rowIndex]
if selectedUpgrades[rowIndex] ~= nil and selectedUpgrades[rowIndex].text ~= nil then
self.editInput({
index = inputIndex,
value = " " .. selectedUpgrades[rowIndex].text
})
waitForUILoad(rowIndex, "text", selectedUpgrades[rowIndex].text)
end
end
function waitForUILoad(id, attribute, value)
if isLoading then
Wait.condition(
function()
Wait.frames(
function()
isLoading = false;
self.UI.setAttribute(id, attribute, value)
end,
1
)
end,
function()
return not self.UI.loading
end
)
else
self.UI.setAttribute(id, attribute, value)
end
end
@ -234,15 +278,13 @@ function clickCheckbox(row, col)
end
-- Updates saved value for given text box when it loses focus
function clickTextbox(rowIndex, value, selected)
if selected == false then
if selectedUpgrades[rowIndex] == nil then
selectedUpgrades[rowIndex] = { }
end
selectedUpgrades[rowIndex].text = value:gsub("^%s*(.-)%s*$", "%1")
-- Editing isn't actually done yet, and will block the update. Wait a frame so it's finished
Wait.frames(function() updateRowDisplay(rowIndex) end, 1)
function clickTextbox(rowIndex, value)
if selectedUpgrades[rowIndex] == nil then
selectedUpgrades[rowIndex] = { }
end
selectedUpgrades[rowIndex].text = value:gsub("^%s*(.-)%s*$", "%1")
-- Editing isn't actually done yet, and will block the update. Wait a frame so it's finished
Wait.frames(function() updateRowDisplay(rowIndex) end, 1)
end
---------------------------------------------------------