diff --git a/src/arkhamdb/DeckImporterMain.ttslua b/src/arkhamdb/DeckImporterMain.ttslua index e0dce129..1a3f2d48 100644 --- a/src/arkhamdb/DeckImporterMain.ttslua +++ b/src/arkhamdb/DeckImporterMain.ttslua @@ -103,9 +103,12 @@ function loadCards(slots, investigatorId, bondedList, customizations, playerColo -- If cards are spread too close together TTS groups them weirdly, selecting multiples -- when hovering over a single card. This distance is the minimum to avoid that local spreadDistance = 1.15 - if (zone == "SetAside4") then + if (zone == "SetAside4" and #zoneCards < 6) then -- SetAside4 is reserved for customization cards, and we want them spread on the table -- so their checkboxes are visible + -- TO-DO: take into account that spreading will make multiple rows + -- (unclear if this is affected by the user's local setting) + -- -> To avoid weird positioning, there will only be a spread if less than 6 upgradesheets are spawned if (playerColor == "White") then deckPos.z = deckPos.z + (#zoneCards - 1) * spreadDistance elseif (playerColor == "Green") then diff --git a/src/playercards/customizable/AlchemicalDistillationUpgradeSheet.ttslua b/src/playercards/customizable/AlchemicalDistillationUpgradeSheet.ttslua index 95ecd11f..d98c8208 100644 --- a/src/playercards/customizable/AlchemicalDistillationUpgradeSheet.ttslua +++ b/src/playercards/customizable/AlchemicalDistillationUpgradeSheet.ttslua @@ -1,10 +1,4 @@ -- Customizable Cards: Alchemical Distillation --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} - -- Color information for buttons boxSize = 40 @@ -12,8 +6,6 @@ boxSize = 40 -- static values x_1 = -0.933 x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,154 +20,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 1, 1, 2, 4, 5 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/CustomModificationsUpgradeSheet.ttslua b/src/playercards/customizable/CustomModificationsUpgradeSheet.ttslua index 1e0e5350..59260d19 100644 --- a/src/playercards/customizable/CustomModificationsUpgradeSheet.ttslua +++ b/src/playercards/customizable/CustomModificationsUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Custom Modifications --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 38 @@ -11,8 +6,6 @@ boxSize = 38 -- static values x_1 = -0.935 x_offset = 0.0735 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -26,154 +19,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 2, 2, 3, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/DamningTestimonyUpgradeSheet.ttslua b/src/playercards/customizable/DamningTestimonyUpgradeSheet.ttslua index 77255bfb..b26add04 100644 --- a/src/playercards/customizable/DamningTestimonyUpgradeSheet.ttslua +++ b/src/playercards/customizable/DamningTestimonyUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Damning Testimony --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 40 @@ -11,8 +6,6 @@ boxSize = 40 -- static values x_1 = -0.935 x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -26,154 +19,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 2, 2, 3, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/EmpiricalHypothesisUpgradeSheet.ttslua b/src/playercards/customizable/EmpiricalHypothesisUpgradeSheet.ttslua index b3123175..aa13ced8 100644 --- a/src/playercards/customizable/EmpiricalHypothesisUpgradeSheet.ttslua +++ b/src/playercards/customizable/EmpiricalHypothesisUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Empirical Hypothesis --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 37 @@ -11,8 +6,6 @@ boxSize = 37 -- static values x_1 = -0.935 x_offset = 0.069 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,154 +21,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 1, 1, 2, 2, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/FriendsinLowPlacesUpgradeSheet.ttslua b/src/playercards/customizable/FriendsinLowPlacesUpgradeSheet.ttslua index 8f1cae92..5ffaa455 100644 --- a/src/playercards/customizable/FriendsinLowPlacesUpgradeSheet.ttslua +++ b/src/playercards/customizable/FriendsinLowPlacesUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Friends in Low Places --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons and input boxes boxSize = 36 @@ -12,8 +7,6 @@ inputFontsize = 50 -- static values x_1 = -0.935 x_offset = 0.0685 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,156 +21,8 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 2, 2, 2, 2, 3, 3 } - inputBoxes = { 1, 1 } inputWidth = { 640, 290 } inputPos = { { 0.275, 0.25, -0.91 }, { 0.6295, 0.25, -0.44 } } --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") \ No newline at end of file diff --git a/src/playercards/customizable/GrizzledUpgradeSheet.ttslua b/src/playercards/customizable/GrizzledUpgradeSheet.ttslua index 39a5a906..de3dff98 100644 --- a/src/playercards/customizable/GrizzledUpgradeSheet.ttslua +++ b/src/playercards/customizable/GrizzledUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Grizzled --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons and input boxes boxSize = 40 @@ -12,8 +7,6 @@ inputFontsize = 50 -- static values x_1 = -0.933 x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -26,156 +19,8 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 2, 3, 4, 5 } - inputBoxes = { 1, 1, 1 } inputWidth = { 600, 875, 875 } inputPos = { { 0.3, 0.25, -0.91 }, { 0.005, 0.25, -0.58 }, { 0.005, 0.25, -0.32 } } --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/HonedInstinctUpgradeSheet.ttslua b/src/playercards/customizable/HonedInstinctUpgradeSheet.ttslua index bde1a713..6a70c151 100644 --- a/src/playercards/customizable/HonedInstinctUpgradeSheet.ttslua +++ b/src/playercards/customizable/HonedInstinctUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Honed Instinct --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 38 @@ -11,8 +6,6 @@ boxSize = 38 -- static values x_1 = -0.935 x_offset = 0.069 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,154 +21,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/HuntersArmorUpgradeSheet.ttslua b/src/playercards/customizable/HuntersArmorUpgradeSheet.ttslua index b2ed3fda..00fa116d 100644 --- a/src/playercards/customizable/HuntersArmorUpgradeSheet.ttslua +++ b/src/playercards/customizable/HuntersArmorUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Hunter's Armor --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 40 @@ -11,8 +6,6 @@ boxSize = 40 -- static values x_1 = -0.933 x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -27,154 +20,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 2, 2, 2, 2, 3, 3 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/HyperphysicalShotcasterUpgradeSheet.ttslua b/src/playercards/customizable/HyperphysicalShotcasterUpgradeSheet.ttslua index fb094979..6a0f4fba 100644 --- a/src/playercards/customizable/HyperphysicalShotcasterUpgradeSheet.ttslua +++ b/src/playercards/customizable/HyperphysicalShotcasterUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Hyperphysical Shotcaster --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 38 @@ -11,8 +6,6 @@ boxSize = 38 -- static values x_1 = -0.935 x_offset = 0.069 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -27,154 +20,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 2, 2, 2, 2, 2, 4, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/LivingInkUpgradeSheet.ttslua b/src/playercards/customizable/LivingInkUpgradeSheet.ttslua index e8d4db17..1aab65da 100644 --- a/src/playercards/customizable/LivingInkUpgradeSheet.ttslua +++ b/src/playercards/customizable/LivingInkUpgradeSheet.ttslua @@ -1,45 +1,40 @@ -- Customizable Cards: Living Ink --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Size information for buttons -boxSize = 40 +boxSize = 40 -- static values -x_1 = -0.935 -x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 +x_1 = -0.935 +x_offset = 0.075 +y_visible = 0.25 +y_invisible = -0.5 -- z-values (lines on the sheet) -posZ = { - -0.69, - -0.355, - 0.0855, - 0.425, - 0.555, - 0.685, - 1.02 +posZ = { + -0.69, + -0.355, + 0.0855, + 0.425, + 0.555, + 0.685, + 1.02 } -- box setup (amount of boxes per line and amount of marked boxes in that line) -existingBoxes = { 1, 1, 2, 2, 3, 3, 3 } +existingBoxes = { 1, 1, 2, 2, 3, 3, 3 } -- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" +markDEBUG = "" -- Locations of the skill selectors local SKILL_ICON_POSITIONS = { - willpower = { x = 0.085, z = -0.88}, - intellect = { x = -0.183, z = -0.88}, - combat = { x = -0.473, z = -0.88}, - agility = { x = -0.74, z = -0.88}, + willpower = { x = 0.085, z = -0.88 }, + intellect = { x = -0.183, z = -0.88 }, + combat = { x = -0.473, z = -0.88 }, + agility = { x = -0.74, z = -0.88 }, } -local selectedSkills = { +local selectedSkills = { willpower = false, intellect = false, combat = false, @@ -50,7 +45,7 @@ local selectedSkills = { function onDestroy() self.script_state = onSave() end function onSave() - local skillArray = { } + local skillArray = {} for skill, isSelected in pairs(selectedSkills) do if (isSelected) then table.insert(skillArray, skill) @@ -61,35 +56,35 @@ end -- Startup procedure function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - log(loaded_data[2]) - for _, skill in ipairs(loaded_data[2]) do - if (skill ~= "") then - log("Skill from load "..skill) - selectedSkills[skill] = true - end - end - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - local selectedSkills = { - willpower = false, - intellect = false, - combat = false, - agility = false - } + if saved_data ~= "" and markDEBUG == "" then + local loaded_data = JSON.decode(saved_data) + markedBoxes = loaded_data[1] + log(loaded_data[2]) + for _, skill in ipairs(loaded_data[2]) do + if (skill ~= "") then + log("Skill from load " .. skill) + selectedSkills[skill] = true + end end + else + markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + inputValues = { "", "", "", "", "" } + local selectedSkills = { + willpower = false, + intellect = false, + combat = false, + agility = false + } + end - makeData() - createButtonsAndBoxes() + makeData() + createButtonsAndBoxes() - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() updateScale(1) end) - self.addContextMenuItem("Scale: double", function() updateScale(2) end) - self.addContextMenuItem("Scale: triple", function() updateScale(3) end) - updateSkillDisplay() + self.addContextMenuItem("Reset Inputs", function() updateState() end) + self.addContextMenuItem("Scale: normal", function() updateScale(1) end) + self.addContextMenuItem("Scale: double", function() updateScale(2) end) + self.addContextMenuItem("Scale: triple", function() updateScale(3) end) + updateSkillDisplay() end function updateScale(scale) @@ -98,61 +93,61 @@ function updateScale(scale) end function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() - updateSkillDisplay() + if markedBoxesNew then markedBoxes = markedBoxesNew end + makeData() + createButtonsAndBoxes() + updateSkillDisplay() end -- create Data function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} + Data = {} + Data.checkbox = {} + Data.textbox = {} - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i + -- repeat this for each entry (= line) in existingBoxes + local totalCount = 0 + for i = 1, #existingBoxes do + -- repeat this for each checkbox per line + for j = 1, existingBoxes[i] do + totalCount = totalCount + 1 + Data.checkbox[totalCount] = {} + Data.checkbox[totalCount].pos = {} + Data.checkbox[totalCount].pos.x = x_1 + j * x_offset + Data.checkbox[totalCount].pos.z = posZ[i] + Data.checkbox[totalCount].row = i - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end + if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then + Data.checkbox[totalCount].pos.y = y_visible + Data.checkbox[totalCount].state = true + else + Data.checkbox[totalCount].pos.y = y_invisible + Data.checkbox[totalCount].state = false + end end + end end -- checks or unchecks the given box function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row + local row = Data.checkbox[tableIndex].row - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false + if Data.checkbox[tableIndex].state == true then + Data.checkbox[tableIndex].pos.y = y_invisible + Data.checkbox[tableIndex].state = false - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true + markedBoxes[row] = markedBoxes[row] - 1 + else + Data.checkbox[tableIndex].pos.y = y_visible + Data.checkbox[tableIndex].state = true - markedBoxes[row] = markedBoxes[row] + 1 - end + markedBoxes[row] = markedBoxes[row] + 1 + end - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) + self.editButton({ + index = tableIndex - 1, + position = Data.checkbox[tableIndex].pos + }) end function click_willpower() @@ -176,40 +171,40 @@ function click_agility() end function createButtonsAndBoxes() - self.clearButtons() + self.clearButtons() - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) + for i, box_data in ipairs(Data.checkbox) do + local funcName = "checkbox" .. i + local func = function() click_checkbox(i) end + self.setVar(funcName, func) - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end + self.createButton({ + click_function = funcName, + function_owner = self, + position = box_data.pos, + height = boxSize, + width = boxSize, + font_size = box_data.size, + scale = { 1, 1, 1 }, + color = { 0, 0, 0 }, + font_color = { 0, 0, 0 } + }) + end - makeSkillSelectionButtons() + makeSkillSelectionButtons() end -- Creates the invisible buttons overlaying the skill icons function makeSkillSelectionButtons() local buttonPositions = { x = -1 * SKILL_ICON_POSITIONS.willpower.x, y = 0.2, z = SKILL_ICON_POSITIONS.willpower.z } local buttonData = { - click_function = "click_willpower", - function_owner = self, - position = buttonPositions, - height = 130, - width = 130, - scale = { 1, 1, 1 }, - color = { 0, 0, 0, 0 }, + click_function = "click_willpower", + function_owner = self, + position = buttonPositions, + height = 130, + width = 130, + scale = { 1, 1, 1 }, + color = { 0, 0, 0, 0 }, } self.createButton(buttonData) buttonData.click_function = "click_intellect" @@ -229,7 +224,7 @@ end -- Refresh the vector circles indicating a skill is selected. Since we can only have one table of -- vectors set, have to refresh all 4 at once function updateSkillDisplay() - local circles = { } + local circles = {} for skill, isSelected in pairs(selectedSkills) do if isSelected then local circle = getCircleVector(SKILL_ICON_POSITIONS[skill]) @@ -258,8 +253,8 @@ function getCircleVector(center) end return { - points = vecList, - color = {0.597, 0.195, 0.796}, - thickness = 0.02, + points = vecList, + color = { 0.597, 0.195, 0.796 }, + thickness = 0.02, } end diff --git a/src/playercards/customizable/MakeshiftTrapUpgradeSheet.ttslua b/src/playercards/customizable/MakeshiftTrapUpgradeSheet.ttslua index f43f200c..06fcd1a2 100644 --- a/src/playercards/customizable/MakeshiftTrapUpgradeSheet.ttslua +++ b/src/playercards/customizable/MakeshiftTrapUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Makeshift Trap --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 39 @@ -11,8 +6,6 @@ boxSize = 39 -- static values x_1 = -0.935 x_offset = 0.0735 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -27,154 +20,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 2, 2, 2, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/PocketMultiToolUpgradeSheet.ttslua b/src/playercards/customizable/PocketMultiToolUpgradeSheet.ttslua index 24c8e8ca..e2eae9bf 100644 --- a/src/playercards/customizable/PocketMultiToolUpgradeSheet.ttslua +++ b/src/playercards/customizable/PocketMultiToolUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Pocket Multi Tool --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 40 @@ -11,8 +6,6 @@ boxSize = 40 -- static values x_1 = -0.933 x_offset = 0.075 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -27,154 +20,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 2, 2, 2, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/PowerWordUpgradeSheet.ttslua b/src/playercards/customizable/PowerWordUpgradeSheet.ttslua index 9d19459b..96464b61 100644 --- a/src/playercards/customizable/PowerWordUpgradeSheet.ttslua +++ b/src/playercards/customizable/PowerWordUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Power Word --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 38 @@ -11,8 +6,6 @@ boxSize = 38 -- static values x_1 = -0.933 x_offset = 0.069 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,154 +21,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 1, 1, 2, 3, 3, 3 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/RunicAxeUpgradeSheet.ttslua b/src/playercards/customizable/RunicAxeUpgradeSheet.ttslua index 3a365ef0..12012103 100644 --- a/src/playercards/customizable/RunicAxeUpgradeSheet.ttslua +++ b/src/playercards/customizable/RunicAxeUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: Runic Axe --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons boxSize = 38 @@ -11,8 +6,6 @@ boxSize = 38 -- static values x_1 = -0.935 x_offset = 0.0705 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,154 +21,6 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 1, 1, 1, 3, 3, 4 } - inputBoxes = {} --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/SummonedServitorUpgradeSheet.ttslua b/src/playercards/customizable/SummonedServitorUpgradeSheet.ttslua index 11bcf950..5763f178 100644 --- a/src/playercards/customizable/SummonedServitorUpgradeSheet.ttslua +++ b/src/playercards/customizable/SummonedServitorUpgradeSheet.ttslua @@ -1,276 +1,270 @@ -- Customizable Cards: Summoned Servitor --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons -boxSize = 35 +boxSize = 35 -- static values -x_1 = -0.935 -x_offset = 0.068 -y_visible = 0.25 -y_invisible = -0.5 +x_1 = -0.935 +x_offset = 0.068 +y_visible = 0.25 +y_invisible = -0.5 -- z-values (lines on the sheet) -posZ = { - -0.92, - -0.625, - -0.33, - 0.055, - 0.26, - 0.56, - 0.765, - 1.06 +posZ = { + -0.92, + -0.625, + -0.33, + 0.055, + 0.26, + 0.56, + 0.765, + 1.06 } -- box setup (amount of boxes per line and amount of marked boxes in that line) -existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 } - -inputBoxes = {} +existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 } +inputBoxes = {} -- Locations of the slot selectors local SLOT_ICON_POSITIONS = { - arcane = { x = 0.160, z = 0.65}, - ally = { x = -0.073, z = 0.65} + arcane = { x = 0.160, z = 0.65 }, + ally = { x = -0.073, z = 0.65 } } -- These match with ArkhamDB's way of storing the data in the dropdown menu -local slotIndices = {arcane = "1", ally = "0", none = ""} +local slotIndices = { arcane = "1", ally = "0", none = "" } -local selectedSlot = slotIndices.none +local selectedSlot = slotIndices.none -- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" +markDEBUG = "" -- save state when going into bags / decks function onDestroy() self.script_state = onSave() end -function onSave() return JSON.encode({ markedBoxes, {selectedSlot} }) end +function onSave() return JSON.encode({ markedBoxes, { selectedSlot } }) end -- Startup procedure function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - selectedSlot = loaded_data[2][1] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - selectedSlot = "" - end + if saved_data ~= "" and markDEBUG == "" then + local loaded_data = JSON.decode(saved_data) + markedBoxes = loaded_data[1] + selectedSlot = loaded_data[2][1] + else + markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + selectedSlot = "" + end - makeData() - createButtonsAndBoxes() - updateSlotDisplay() + makeData() + createButtonsAndBoxes() + updateSlotDisplay() - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) + self.addContextMenuItem("Reset Inputs", function() updateState() end) + self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) + self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) + self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) end function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() - updateSlotDisplay() + if markedBoxesNew then markedBoxes = markedBoxesNew end + makeData() + createButtonsAndBoxes() + updateSlotDisplay() end -- create Data function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} + Data = {} + Data.checkbox = {} + Data.textbox = {} - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i + -- repeat this for each entry (= line) in existingBoxes + local totalCount = 0 + for i = 1, #existingBoxes do + -- repeat this for each checkbox per line + for j = 1, existingBoxes[i] do + totalCount = totalCount + 1 + Data.checkbox[totalCount] = {} + Data.checkbox[totalCount].pos = {} + Data.checkbox[totalCount].pos.x = x_1 + j * x_offset + Data.checkbox[totalCount].pos.z = posZ[i] + Data.checkbox[totalCount].row = i - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end + if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then + Data.checkbox[totalCount].pos.y = y_visible + Data.checkbox[totalCount].state = true + else + Data.checkbox[totalCount].pos.y = y_invisible + Data.checkbox[totalCount].state = false + end end + end - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end + -- repeat this for each entry (= line) in inputBoxes + local totalCount = 0 + for i = 1, #inputBoxes do + -- repeat this for each textbox per line + for j = 1, inputBoxes[i] do + totalCount = totalCount + 1 + Data.textbox[totalCount] = {} + Data.textbox[totalCount].pos = inputPos[totalCount] + Data.textbox[totalCount].width = inputWidth[totalCount] + Data.textbox[totalCount].value = inputValues[totalCount] end + end end -- checks or unchecks the given box function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row + local row = Data.checkbox[tableIndex].row - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false + if Data.checkbox[tableIndex].state == true then + Data.checkbox[tableIndex].pos.y = y_invisible + Data.checkbox[tableIndex].state = false - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true + markedBoxes[row] = markedBoxes[row] - 1 + else + Data.checkbox[tableIndex].pos.y = y_visible + Data.checkbox[tableIndex].state = true - markedBoxes[row] = markedBoxes[row] + 1 - end + markedBoxes[row] = markedBoxes[row] + 1 + end - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) + self.editButton({ + index = tableIndex - 1, + position = Data.checkbox[tableIndex].pos + }) end -- updates saved value for given text box function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end + if selected == false then + inputValues[i] = value + end end function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() + self.clearButtons() + self.clearInputs() - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) + for i, box_data in ipairs(Data.checkbox) do + local funcName = "checkbox" .. i + local func = function() click_checkbox(i) end + self.setVar(funcName, func) - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end + self.createButton({ + click_function = funcName, + function_owner = self, + position = box_data.pos, + height = boxSize, + width = boxSize, + font_size = box_data.size, + scale = { 1, 1, 1 }, + color = { 0, 0, 0 }, + font_color = { 0, 0, 0 } + }) + end - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) + for i, box_data in ipairs(Data.textbox) do + local funcName = "textbox" .. i + local func = function(_, _, val, sel) click_textbox(i, val, sel) end + self.setVar(funcName, func) - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end + self.createInput({ + input_function = funcName, + function_owner = self, + label = "Click to type", + alignment = 2, + position = box_data.pos, + scale = buttonScale, + width = box_data.width, + height = (inputFontsize * 1) + 24, + font_size = inputFontsize, + color = "White", + font_color = buttonFontColor, + value = box_data.value + }) + end - makeSlotSelectionButtons() + makeSlotSelectionButtons() end -- Creates the invisible buttons overlaying the slot words function makeSlotSelectionButtons() - local buttonPositions = { x = -1 * SLOT_ICON_POSITIONS.arcane.x, y = 0.2, z = SLOT_ICON_POSITIONS.arcane.z } - local buttonData = { - click_function = "click_arcane", - function_owner = self, - position = buttonPositions, - height = 130, - width = 130, - scale = { 1, 1, 1 }, - color = { 0, 0, 0, 0 }, - } - self.createButton(buttonData) - buttonData.click_function = "click_ally" - buttonPositions.x = -1 * SLOT_ICON_POSITIONS.ally.x - buttonData.position = buttonPositions - self.createButton(buttonData) + local buttonPositions = { x = -1 * SLOT_ICON_POSITIONS.arcane.x, y = 0.2, z = SLOT_ICON_POSITIONS.arcane.z } + local buttonData = { + click_function = "click_arcane", + function_owner = self, + position = buttonPositions, + height = 130, + width = 130, + scale = { 1, 1, 1 }, + color = { 0, 0, 0, 0 }, + } + self.createButton(buttonData) + buttonData.click_function = "click_ally" + buttonPositions.x = -1 * SLOT_ICON_POSITIONS.ally.x + buttonData.position = buttonPositions + self.createButton(buttonData) end function click_arcane() - if selectedSlot == slotIndices.arcane then - selectedSlot = slotIndices.none - else - selectedSlot = slotIndices.arcane - end - updateSlotDisplay() + if selectedSlot == slotIndices.arcane then + selectedSlot = slotIndices.none + else + selectedSlot = slotIndices.arcane + end + updateSlotDisplay() end - + function click_ally() - if selectedSlot == slotIndices.ally then - selectedSlot = slotIndices.none - else - selectedSlot = slotIndices.ally - end - updateSlotDisplay() + if selectedSlot == slotIndices.ally then + selectedSlot = slotIndices.none + else + selectedSlot = slotIndices.ally + end + updateSlotDisplay() end -- Refresh the vector circles indicating a slot is selected. function updateSlotDisplay() - local box = {} - local center = {} - center = SLOT_ICON_POSITIONS["arcane"] - local arcaneVecList = { - Vector(center.x + 0.12, 0.3, center.z + 0.05), - Vector(center.x - 0.12, 0.3, center.z + 0.05), - Vector(center.x - 0.12, 0.3, center.z - 0.05), - Vector(center.x + 0.12, 0.3, center.z - 0.05), - Vector(center.x + 0.12, 0.3, center.z + 0.05), - } - center = SLOT_ICON_POSITIONS["ally"] - local allyVecList = { - Vector(center.x + 0.07, 0.3, center.z + 0.05), - Vector(center.x - 0.07, 0.3, center.z + 0.05), - Vector(center.x - 0.07, 0.3, center.z - 0.05), - Vector(center.x + 0.07, 0.3, center.z - 0.05), - Vector(center.x + 0.07, 0.3, center.z + 0.05), - } - local arcaneVecColor = {0.5, 0.5, 0.5, 0.75} - local allyVecColor = {0.5, 0.5, 0.5, 0.75} - if selectedSlot == slotIndices.arcane then - arcaneVecColor = {0.597, 0.195, 0.796} - elseif selectedSlot == slotIndices.ally then - allyVecColor = {0.597, 0.195, 0.796} - end + local box = {} + local center = {} + center = SLOT_ICON_POSITIONS["arcane"] + local arcaneVecList = { + Vector(center.x + 0.12, 0.3, center.z + 0.05), + Vector(center.x - 0.12, 0.3, center.z + 0.05), + Vector(center.x - 0.12, 0.3, center.z - 0.05), + Vector(center.x + 0.12, 0.3, center.z - 0.05), + Vector(center.x + 0.12, 0.3, center.z + 0.05), + } + center = SLOT_ICON_POSITIONS["ally"] + local allyVecList = { + Vector(center.x + 0.07, 0.3, center.z + 0.05), + Vector(center.x - 0.07, 0.3, center.z + 0.05), + Vector(center.x - 0.07, 0.3, center.z - 0.05), + Vector(center.x + 0.07, 0.3, center.z - 0.05), + Vector(center.x + 0.07, 0.3, center.z + 0.05), + } + local arcaneVecColor = { 0.5, 0.5, 0.5, 0.75 } + local allyVecColor = { 0.5, 0.5, 0.5, 0.75 } + if selectedSlot == slotIndices.arcane then + arcaneVecColor = { 0.597, 0.195, 0.796 } + elseif selectedSlot == slotIndices.ally then + allyVecColor = { 0.597, 0.195, 0.796 } + end - self.setVectorLines({ - { - points = arcaneVecList, - color = arcaneVecColor, - thickness = 0.02, - }, - { - points = allyVecList, - color = allyVecColor, - thickness = 0.02, - }, - - }) + self.setVectorLines({ + { + points = arcaneVecList, + color = arcaneVecColor, + thickness = 0.02, + }, + { + points = allyVecList, + color = allyVecColor, + thickness = 0.02, + }, + + }) end diff --git a/src/playercards/customizable/TheRavenQuillUpgradeSheet.ttslua b/src/playercards/customizable/TheRavenQuillUpgradeSheet.ttslua index e213bf7c..91df5221 100644 --- a/src/playercards/customizable/TheRavenQuillUpgradeSheet.ttslua +++ b/src/playercards/customizable/TheRavenQuillUpgradeSheet.ttslua @@ -1,9 +1,4 @@ -- Customizable Cards: The Raven Quill --- by Chr1Z -information = { - version = "1.7", - last_updated = "12.10.2022" -} -- Color information for buttons and input boxes boxSize = 37 @@ -12,8 +7,6 @@ inputFontsize = 38 -- static values x_1 = -0.935 x_offset = 0.0705 -y_visible = 0.25 -y_invisible = -0.5 -- z-values (lines on the sheet) posZ = { @@ -28,156 +21,8 @@ posZ = { -- box setup (amount of boxes per line and amount of marked boxes in that line) existingBoxes = { 1, 1, 2, 2, 2, 3, 4 } - inputBoxes = { 1, 1 } inputWidth = { 425, 775 } inputPos = { { 0.5, 0.25, -0.905 }, { 0.125, 0.25, 0 } } --- override 'marked boxes' for debugging ('all' or 'none') -markDEBUG = "" - --- save state when going into bags / decks -function onDestroy() self.script_state = onSave() end - -function onSave() return JSON.encode({ markedBoxes, inputValues }) end - --- Startup procedure -function onLoad(saved_data) - if saved_data ~= "" and markDEBUG == "" then - local loaded_data = JSON.decode(saved_data) - markedBoxes = loaded_data[1] - inputValues = loaded_data[2] - else - markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } - inputValues = { "", "", "", "", "" } - end - - makeData() - createButtonsAndBoxes() - - self.addContextMenuItem("Reset Inputs", function() updateState() end) - self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) - self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) - self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) -end - -function updateState(markedBoxesNew) - if markedBoxesNew then markedBoxes = markedBoxesNew end - makeData() - createButtonsAndBoxes() -end - --- create Data -function makeData() - Data = {} - Data.checkbox = {} - Data.textbox = {} - - -- repeat this for each entry (= line) in existingBoxes - local totalCount = 0 - for i = 1, #existingBoxes do - -- repeat this for each checkbox per line - for j = 1, existingBoxes[i] do - totalCount = totalCount + 1 - Data.checkbox[totalCount] = {} - Data.checkbox[totalCount].pos = {} - Data.checkbox[totalCount].pos.x = x_1 + j * x_offset - Data.checkbox[totalCount].pos.z = posZ[i] - Data.checkbox[totalCount].row = i - - if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then - Data.checkbox[totalCount].pos.y = y_visible - Data.checkbox[totalCount].state = true - else - Data.checkbox[totalCount].pos.y = y_invisible - Data.checkbox[totalCount].state = false - end - end - end - - -- repeat this for each entry (= line) in inputBoxes - local totalCount = 0 - for i = 1, #inputBoxes do - -- repeat this for each textbox per line - for j = 1, inputBoxes[i] do - totalCount = totalCount + 1 - Data.textbox[totalCount] = {} - Data.textbox[totalCount].pos = inputPos[totalCount] - Data.textbox[totalCount].width = inputWidth[totalCount] - Data.textbox[totalCount].value = inputValues[totalCount] - end - end -end - --- checks or unchecks the given box -function click_checkbox(tableIndex) - local row = Data.checkbox[tableIndex].row - - if Data.checkbox[tableIndex].state == true then - Data.checkbox[tableIndex].pos.y = y_invisible - Data.checkbox[tableIndex].state = false - - markedBoxes[row] = markedBoxes[row] - 1 - else - Data.checkbox[tableIndex].pos.y = y_visible - Data.checkbox[tableIndex].state = true - - markedBoxes[row] = markedBoxes[row] + 1 - end - - self.editButton({ - index = tableIndex - 1, - position = Data.checkbox[tableIndex].pos - }) -end - --- updates saved value for given text box -function click_textbox(i, value, selected) - if selected == false then - inputValues[i] = value - end -end - -function createButtonsAndBoxes() - self.clearButtons() - self.clearInputs() - - for i, box_data in ipairs(Data.checkbox) do - local funcName = "checkbox" .. i - local func = function() click_checkbox(i) end - self.setVar(funcName, func) - - self.createButton({ - click_function = funcName, - function_owner = self, - position = box_data.pos, - height = boxSize, - width = boxSize, - font_size = box_data.size, - scale = { 1, 1, 1 }, - color = { 0, 0, 0 }, - font_color = { 0, 0, 0 } - }) - end - - for i, box_data in ipairs(Data.textbox) do - local funcName = "textbox" .. i - local func = function(_, _, val, sel) click_textbox(i, val, sel) end - self.setVar(funcName, func) - - self.createInput({ - input_function = funcName, - function_owner = self, - label = "Click to type", - alignment = 2, - position = box_data.pos, - scale = buttonScale, - width = box_data.width, - height = (inputFontsize * 1) + 24, - font_size = inputFontsize, - color = "White", - font_color = buttonFontColor, - value = box_data.value - }) - end -end +require("playercards/customizable/UpgradeSheetLibrary") diff --git a/src/playercards/customizable/UpgradeSheetLibrary.ttslua b/src/playercards/customizable/UpgradeSheetLibrary.ttslua new file mode 100644 index 00000000..d5754632 --- /dev/null +++ b/src/playercards/customizable/UpgradeSheetLibrary.ttslua @@ -0,0 +1,173 @@ +--[[ EXAMPLE CONFIGURATION +-- Color information for buttons +boxSize = 40 + +-- static values +x_1 = -0.933 +x_offset = 0.075 + +-- z-values (lines on the sheet) +posZ = { + -0.892, + -0.665, + -0.430, + -0.092, + 0.142, + 0.376, + 0.815 +} + +-- box setup (amount of boxes per line and amount of marked boxes in that line) +existingBoxes = { 1, 1, 1, 1, 2, 4, 5 } +inputBoxes = {}]] + +-- static values +y_visible = 0.25 +y_invisible = -0.5 + +-- override 'marked boxes' for debugging ('all' or 'none') +markDEBUG = "" + +-- save state when going into bags / decks +function onDestroy() self.script_state = onSave() end + +function onSave() return JSON.encode({ markedBoxes, inputValues }) end + +-- Startup procedure +function onLoad(saved_data) + if saved_data ~= "" and markDEBUG == "" then + local loaded_data = JSON.decode(saved_data) + markedBoxes = loaded_data[1] + inputValues = loaded_data[2] + else + markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + inputValues = { "", "", "", "", "" } + end + + makeData() + createButtonsAndBoxes() + + self.addContextMenuItem("Reset Inputs", function() updateState({ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) end) + self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end) + self.addContextMenuItem("Scale: double", function() self.setScale({ 2, 1, 2 }) end) + self.addContextMenuItem("Scale: triple", function() self.setScale({ 3, 1, 3 }) end) +end + +function updateState(markedBoxesNew) + if markedBoxesNew then markedBoxes = markedBoxesNew end + makeData() + createButtonsAndBoxes() +end + +-- create Data +function makeData() + Data = {} + Data.checkbox = {} + Data.textbox = {} + + -- repeat this for each entry (= line) in existingBoxes + local totalCount = 0 + for i = 1, #existingBoxes do + -- repeat this for each checkbox per line + for j = 1, existingBoxes[i] do + totalCount = totalCount + 1 + Data.checkbox[totalCount] = {} + Data.checkbox[totalCount].pos = {} + Data.checkbox[totalCount].pos.x = x_1 + j * x_offset + Data.checkbox[totalCount].pos.z = posZ[i] + Data.checkbox[totalCount].row = i + + if (markDEBUG == "all") or (markedBoxes[i] >= j and markDEBUG ~= "none") then + Data.checkbox[totalCount].pos.y = y_visible + Data.checkbox[totalCount].state = true + else + Data.checkbox[totalCount].pos.y = y_invisible + Data.checkbox[totalCount].state = false + end + end + end + + -- repeat this for each entry (= line) in inputBoxes + local totalCount = 0 + for i = 1, #inputBoxes do + -- repeat this for each textbox per line + for j = 1, inputBoxes[i] do + totalCount = totalCount + 1 + Data.textbox[totalCount] = {} + Data.textbox[totalCount].pos = inputPos[totalCount] + Data.textbox[totalCount].width = inputWidth[totalCount] + Data.textbox[totalCount].value = inputValues[totalCount] + end + end +end + +-- checks or unchecks the given box +function click_checkbox(tableIndex) + local row = Data.checkbox[tableIndex].row + + if Data.checkbox[tableIndex].state == true then + Data.checkbox[tableIndex].pos.y = y_invisible + Data.checkbox[tableIndex].state = false + markedBoxes[row] = markedBoxes[row] - 1 + else + Data.checkbox[tableIndex].pos.y = y_visible + Data.checkbox[tableIndex].state = true + markedBoxes[row] = markedBoxes[row] + 1 + end + + self.editButton({ + index = tableIndex - 1, + position = Data.checkbox[tableIndex].pos + }) +end + +-- updates saved value for given text box +function click_textbox(i, value, selected) + if selected == false then + inputValues[i] = value + end +end + +function createButtonsAndBoxes() + self.clearButtons() + self.clearInputs() + + for i, box_data in ipairs(Data.checkbox) do + local funcName = "checkbox" .. i + local func = function() click_checkbox(i) end + self.setVar(funcName, func) + + self.createButton({ + click_function = funcName, + function_owner = self, + position = box_data.pos, + height = boxSize, + width = boxSize, + font_size = box_data.size, + scale = { 1, 1, 1 }, + color = { 0, 0, 0 }, + font_color = { 0, 0, 0 } + }) + end + + for i, box_data in ipairs(Data.textbox) do + local funcName = "textbox" .. i + local func = function(_, _, val, sel) click_textbox(i, val, sel) end + self.setVar(funcName, func) + + self.createInput({ + input_function = funcName, + function_owner = self, + label = "Click to type", + alignment = 2, + position = box_data.pos, + scale = buttonScale, + width = box_data.width, + height = (inputFontsize * 1) + 24, + font_size = inputFontsize, + color = "White", + font_color = buttonFontColor, + value = box_data.value + }) + end +end