Added in rectangles to select ally/arcane slots for Summoned Servitor #84

This commit is contained in:
Jorge Parra 2023-03-06 18:36:42 -05:00
parent c8ac5290d1
commit 4fa1eb6040

View File

@ -31,13 +31,32 @@ existingBoxes = { 1, 1, 1, 1, 1, 2, 3, 5 }
inputBoxes = {}
-- Locations of the skill selectors
local SLOT_ICON_POSITIONS = {
arcane = { x = 0.160, z = 0.65},
ally = { x = -0.073, z = 0.65}
}
local selectedSlots = {
arcane = false,
ally = false
}
-- 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
function onSave()
local slotArray = { }
for slot, isSelected in pairs(selectedSlots) do
if (isSelected) then
table.insert(slotArray, slot)
end
end
return JSON.encode({ markedBoxes, inputValues, slotArray })
end
-- Startup procedure
function onLoad(saved_data)
@ -45,6 +64,13 @@ function onLoad(saved_data)
local loaded_data = JSON.decode(saved_data)
markedBoxes = loaded_data[1]
inputValues = loaded_data[2]
log(loaded_data[3])
for _, slot in ipairs(loaded_data[3]) do
if (slot ~= "") then
log("Slot from load "..slot)
selectedSlots[slot] = true
end
end
else
markedBoxes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
inputValues = { "", "", "", "", "" }
@ -52,6 +78,7 @@ function onLoad(saved_data)
makeData()
createButtonsAndBoxes()
updateSlotDisplay()
self.addContextMenuItem("Reset Inputs", function() updateState() end)
self.addContextMenuItem("Scale: normal", function() self.setScale({ 1, 1, 1 }) end)
@ -63,6 +90,7 @@ function updateState(markedBoxesNew)
if markedBoxesNew then markedBoxes = markedBoxesNew end
makeData()
createButtonsAndBoxes()
updateSlotDisplay()
end
-- create Data
@ -178,4 +206,91 @@ function createButtonsAndBoxes()
value = box_data.value
})
end
makeSlotSelectionButtons()
end
-- Creates the invisible buttons overlaying the skill icons
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)
end
function click_arcane()
selectedSlots.arcane = not selectedSlots.arcane
updateSlotDisplay()
end
function click_ally()
selectedSlots.ally = not selectedSlots.ally
updateSlotDisplay()
end
-- Refresh the vector circles indicating a slot is selected. Since we can only have one table of
-- vectors set, have to refresh all 2 at once
function updateSlotDisplay()
local circles = { }
for slot, isSelected in pairs(selectedSlots) do
if isSelected then
local circle = getCircleVector(SLOT_ICON_POSITIONS[slot], slot)
if circle ~= nil then
table.insert(circles, circle)
end
end
end
self.setVectorLines(circles)
end
function getCircleVector(center, slot)
-- local diameter = Vector(0, 0, 0.1)
-- local pointOfOrigin = Vector(center.x, 0.3, center.z)
-- -- Declare Results vectors
-- local vec = Vector(0, 0, 0)
-- local vecList = {}
-- local arcStep = 5
-- for i = 0, 360, arcStep do
-- diameter:rotateOver('y', arcStep)
-- vec = pointOfOrigin + diameter
-- vec.y = pointOfOrigin.y
-- table.insert(vecList, vec)
-- end
local vecList = {}
if slot == "arcane" then
vecList = {
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),
}
elseif slot == "ally" then
vecList = {
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),
}
end
return {
points = vecList,
color = {0.597, 0.195, 0.796},
thickness = 0.02,
}
end