SCED/objects/OptionPanelSource.830bd0/jaqenZannsNavigationOverlay.a8affa/CameraPlacementHelper.cecc3e.ttslua

175 lines
4.9 KiB
Plaintext
Raw Normal View History

2023-04-12 05:24:59 -04:00
--Data tables used in button creation
ref_modifyPitchButtons = {
{ offset = -0.37, func = function() click_modify(-1, 0) end },
{ offset = -1.11, func = function() click_modify(-5, 0) end },
{ offset = 0.37, func = function() click_modify(1, 0) end },
{ offset = 1.11, func = function() click_modify(5, 0) end },
}
ref_modifyDistanceButtons = {
{ offset = -0.37, func = function() click_modify(-1, 1) end },
{ offset = -1.11, func = function() click_modify(-5, 1) end },
{ offset = 0.37, func = function() click_modify(1, 1) end },
{ offset = 1.11, func = function() click_modify(5, 1) end },
}
2022-11-11 02:59:55 -05:00
--On-demand save function, remembers pitch and distance values
function updateSave()
2023-04-12 05:24:59 -04:00
self.script_state = JSON.encode({ pitch = pitch, distance = distance })
2022-11-11 02:59:55 -05:00
end
--Startup, loading memory
function onload(saved_data)
2023-04-12 05:24:59 -04:00
--Loads the tracking for if the game has started yet
if saved_data ~= "" then
local loaded_data = JSON.decode(saved_data)
pitch = loaded_data.pitch
distance = loaded_data.distance
else
pitch = 45
distance = 30
end
createInputs()
createButtons()
2022-11-11 02:59:55 -05:00
end
--Activated by finishing writing in the input box, updates save info
2023-04-12 05:24:59 -04:00
function input_entered(inputString, stillEditing, typeIndex)
if stillEditing == false then
--Check to avoid empty input strings
if tonumber(inputString) == nil then inputString = 0 end
--Update save data
if typeIndex == 0 then
pitch = inputString
else
distance = inputString
2022-11-11 02:59:55 -05:00
end
2023-04-12 05:24:59 -04:00
updateSave()
end
2022-11-11 02:59:55 -05:00
end
--Activated by button, the -5 -1 +1 +5 buttons
function click_modify(amount, typeIndex)
2023-04-12 05:24:59 -04:00
if typeIndex == 0 then
pitch = pitch + amount
self.editInput({ index = typeIndex, value = pitch })
else
distance = distance + amount
self.editInput({ index = typeIndex, value = distance })
end
updateSave()
2022-11-11 02:59:55 -05:00
end
--Activated by button, uses the data to move the camera
function click_setCamera(_, color)
2023-04-12 05:24:59 -04:00
--Check if there is another object to use instead of self
local targetObj = self
local nameGUID = string.sub(self.getName(), 1, 6)
if getObjectFromGUID(nameGUID) ~= nil then
targetObj = getObjectFromGUID(nameGUID)
end
--Check if there is an offset to use instead of 180
local offsetY = 180
local offsetString = string.sub(self.getName(), 7)
if tonumber(string.match(offsetString, "%d+")) ~= nil then
offsetY = tonumber(string.match(offsetString, "%d+"))
end
--Move camera into position around object
local pos = targetObj.getPosition()
local rot = targetObj.getRotation()
rot.y = rot.y + offsetY
Player[color].lookAt({ position = pos, pitch = pitch, yaw = rot.y, distance = distance })
--Send values to main tile
for _, v in ipairs(getObjects()) do
if v.getName() == "jaqenZann's Navigation Overlay Tile" then
v.call('updateEditCamera', { { pos.x, pos.y, pos.z }, tonumber(pitch), rot.y, tonumber(distance) })
break
2022-11-11 02:59:55 -05:00
end
2023-04-12 05:24:59 -04:00
end
2022-11-11 02:59:55 -05:00
end
--Button/Input creation
--Text boxes for number input
function createInputs()
2023-04-12 05:24:59 -04:00
local funcName = "inputFuncNamePitch"
local func = function(_, _, x, z) input_entered(x, z, 0) end
self.setVar(funcName, func)
self.createInput({
input_function = funcName,
function_owner = self,
label = "input",
alignment = 2,
position = { -3.4, 0.35, -0.21 },
rotation = { 0, 0, 0 },
height = 420,
width = 1400,
font_size = 400,
color = { 57 / 255, 46 / 255, 40 / 255 },
font_color = { 1, 1, 1 },
value = pitch,
validation = 3
})
local funcName = "inputFuncNameDistance"
local func = function(_, _, x, z) input_entered(x, z, 1) end
self.setVar(funcName, func)
self.createInput({
input_function = funcName,
function_owner = self,
label = "input",
alignment = 4,
position = { 3.4, 0.35, -0.21 },
rotation = { 0, 0, 0 },
height = 420,
width = 1400,
font_size = 400,
color = { 57 / 255, 46 / 255, 40 / 255 },
font_color = { 1, 1, 1 },
value = distance,
validation = 3
})
2022-11-11 02:59:55 -05:00
end
--Center button and -5 - +5 buttons
function createButtons()
2023-04-12 05:24:59 -04:00
self.createButton({
click_function = "click_setCamera",
function_owner = self,
position = { 0, 0.4, 0 },
height = 900,
width = 900,
color = { 1, 1, 1, 0 },
tooltip = "Set camera to this angle"
})
for i, ref in ipairs(ref_modifyPitchButtons) do
local funcName = "pitchModifyFunction_" .. i
self.setVar(funcName, ref.func)
local pos = { -3.4 + ref.offset, 0.3, 0.6 }
2022-11-11 02:59:55 -05:00
self.createButton({
2023-04-12 05:24:59 -04:00
click_function = funcName,
function_owner = self,
position = pos,
height = 240,
width = 320,
color = { 1, 1, 1, 0 }
2022-11-11 02:59:55 -05:00
})
2023-04-12 05:24:59 -04:00
end
2022-11-11 02:59:55 -05:00
2023-04-12 05:24:59 -04:00
for i, ref in ipairs(ref_modifyDistanceButtons) do
local funcName = "distanceModifyFunction_" .. i
self.setVar(funcName, ref.func)
local pos = { 3.4 + ref.offset, 0.3, 0.6 }
self.createButton({
click_function = funcName,
function_owner = self,
position = pos,
height = 240,
width = 320,
color = { 1, 1, 1, 0 }
})
end
2022-11-11 02:59:55 -05:00
end