variableEditor
Definition
-- @/lua/common/extensions/ui/flowgraph/editor.lua:286
local function variableEditor(source, name, displayOptions)
local variable = source:getFull(name)
if not variable then
im.Text("Variable " .. tostring(name) .. " not found!")
return
end
-- setup display options.
if not displayOptions then
displayOptions = {}
end
displayOptions.global = displayOptions.global or false
if displayOptions.allowEditing == nil then
displayOptions.allowEditing = source.mgr.allowEditing
end
im.PushID1("VariablesColumns")
local totalWidth = im.GetContentRegionAvailWidth()
local textSize = im.GetCursorPosX()
if displayOptions.onlyValue then
im.Text(name)
else
im.Text("Value")
end
im.SameLine()
local textSize = im.GetCursorPosX() - textSize
--local global = self.global
--local target = self.global and self.mgr.variables or self.graph.variables
im.PushItemWidth(totalWidth - 80 - textSize)
if variable.type == 'string' then
local imVal = im.ArrayChar(2048, displayOptions.allowEditing and variable.baseValue or variable.value)
if im.InputText("##input" .. name, imVal, nil, im.InputTextFlags_EnterReturnsTrue) then
if displayOptions.allowEditing then
source:changeBase(name, ffi.string(imVal))
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, ffi.string(imVal))
end
end
elseif variable.type == 'number' then
local imVal = im.FloatPtr(displayOptions.allowEditing and variable.baseValue or variable.value)
if im.InputFloat("##input" .. name, imVal, nil, nil, nil, im.InputTextFlags_EnterReturnsTrue) then
if displayOptions.allowEditing then
source:changeBase(name, imVal[0])
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, imVal[0])
end
end
elseif variable.type == 'bool' then
local imVal = im.BoolPtr(false)
if displayOptions.allowEditing then
imVal[0] = variable.baseValue
else
imVal[0] = variable.value
end
if im.Checkbox("##input" .. name, imVal) then
if displayOptions.allowEditing then
source:changeBase(name, imVal[0])
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, imVal[0])
end
end
elseif variable.type == 'vec3' then
local imVal = im.ArrayFloat(3)
local val = displayOptions.allowEditing and variable.baseValue or variable.value
imVal[0] = im.Float(val[1])
imVal[1] = im.Float(val[2])
imVal[2] = im.Float(val[3])
if im.InputFloat3("##input" .. name, imVal, nil, im.InputTextFlags_EnterReturnsTrue) then
local tbl = { imVal[0], imVal[1], imVal[2] }
if displayOptions.allowEditing then
source:changeBase(name, tbl)
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, tbl)
end
end
elseif variable.type == 'quat' then
local imVal = im.ArrayFloat(4)
local val = displayOptions.allowEditing and variable.baseValue or variable.value
imVal[0] = im.Float(val[1])
imVal[1] = im.Float(val[2])
imVal[2] = im.Float(val[3])
imVal[3] = im.Float(val[4])
if im.InputFloat4("##input" .. name, imVal, nil, im.InputTextFlags_EnterReturnsTrue) then
local tbl = { imVal[0], imVal[1], imVal[2], imVal[3] }
if displayOptions.allowEditing then
source:changeBase(name, tbl)
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, tbl)
end
end
elseif variable.type == 'color' then
local imVal = im.ArrayFloat(4)
local val = displayOptions.allowEditing and variable.baseValue or variable.value
imVal[0] = im.Float(val[1])
imVal[1] = im.Float(val[2])
imVal[2] = im.Float(val[3])
imVal[3] = im.Float(val[4])
if im.ColorEdit4("##input" .. name, imVal, nil, im.InputTextFlags_EnterReturnsTrue) then
local tbl = { imVal[0], imVal[1], imVal[2], imVal[3] }
if displayOptions.allowEditing then
source:changeBase(name, tbl)
source.mgr.fgEditor.addHistory("Changed Variable " .. name)
else
source:changeInstant(name, tbl)
end
end
end
im.SameLine()
im.SetCursorPosX(totalWidth - 22 * im.uiscale[0])
if editor.uiIconImageButton(editor.icons.settings, im.ImVec2(22, 22)) then
im.OpenPopup(source.id .. "-" .. name)
end
im.PopItemWidth()
if im.BeginPopup(source.id .. "-" .. name) then
im.PushItemWidth(100)
if not displayOptions.onlyValue then
if displayOptions.allowEditing then
-- type
if not variable.fixedType then
im.Text("Type")
im.SameLine()
if im.BeginCombo("##type" .. variable.index .. name, variable.type) then
for _, type in ipairs(source:getTypes()) do
source.mgr:DrawTypeIcon(type.name, true, 1)
im.SameLine()
if im.Selectable1(type.name, type.name == variable.type) then
source:updateType(name, type.name)
source.mgr.fgEditor.addHistory("Changed Variable " .. name .. " type to " .. type.name)
end
end
im.EndCombo()
end
else
im.Text("Locked Type")
ui_flowgraph_editor.tooltip("Type Locked (viewmode to debug to change)")
im.SameLine()
im.Text(tostring(variable.type))
end
if editor.getPreference("flowgraph.debug.editorDebug") then
local fixedTypeBool = im.BoolPtr(variable.fixedType or false)
if im.Checkbox("##fix" .. name, fixedTypeBool) then
source:setFixedType(name, fixedTypeBool[0])
source.mgr.fgEditor.addHistory("Fixed Variable type " .. name)
end
end
if editor.getPreference("flowgraph.debug.editorDebug") then
im.Text("Merging")
ui_flowgraph_editor.tooltip("Dictates what happens when multiple values will be set in the same frame.")
im.SameLine()
-- merge strategies
if im.BeginCombo("##mergeStrat" .. variable.index .. name, variable.mergeStrat) then
for _, strat in ipairs(source:getMergeStrats(variable.type)) do
if im.Selectable1(strat.name, variable.mergeStrat == strat.name) then
source:setMergeStrat(name, strat.name)
source.mgr.fgEditor.addHistory("Changed Variable " .. name .. " mergestrat to " .. strat.name)
end
end
im.EndCombo()
end
end
end
if editor.getPreference("flowgraph.debug.editorDebug") then
im.Text("Monitor")
im.SameLine()
local monitor = im.BoolPtr(variable.monitored or false)
if im.Checkbox("##monitor" .. name, monitor) then
source:setMonitor(name, monitor[0])
source.mgr.fgEditor.addHistory("Changed Monitoring of " .. name)
end
ui_flowgraph_editor.tooltip("Checking this will show this variable in the Tool Window.")
im.Text("KeepAfterStop")
im.SameLine()
local stop = im.BoolPtr(variable.keepAfterStop or false)
if im.Checkbox("##keepAfterStop" .. name, stop) then
source:setKeepAfterStop(name, stop[0])
source.mgr.fgEditor.addHistory("Changed KeepAfterStop " .. name)
end
ui_flowgraph_editor.tooltip("Checking this will keep the variables value after stopping the execution, instead of resetting to its base value.")
end
if displayOptions.allowDelete then
if source.mgr.allowEditing then
-- delete
if not variable.undeletable and im.Button("Delete Variable") then
source:removeVariable(name)
source.mgr.fgEditor.addHistory("Deleted Variable " .. name)
end
-- rename
if im.Button("Rename Variable") then
im.OpenPopup(source.id .. "-rename-" .. name)
end
end
end
-- rename variable popup
if im.BeginPopup(source.id .. "-rename-" .. name) then
im.PushItemWidth(150)
im.Text("Rename Variable")
local newNameArray = im.ArrayChar(32)
if im.InputText("##RenameVariable", newNameArray, nil, im.flags(im.InputTextFlags_EnterReturnsTrue)) then
local newName = ffi.string(newNameArray)
if string.len(newName) > 0 then
if source:renameVariable(name, newName) then
print("Variable " .. name .. " renamed to " .. newName)
else
log("E","", "Cannot rename a variable: the new name already exists")
end
else
log("E","", "Cannot rename a variable: the new variable name cannot be empty")
end
end
im.PopItemWidth()
im.EndPopup()
end
end
im.EndPopup()
end
--im.NextColumn()
--im.Columns(1)
im.PopID()
end
Callers
@/lua/ge/extensions/flowgraph/nodes/types/setVariable.lua
end
ui_flowgraph_editor.variableEditor(self.target, self.varName)
end
@/lua/ge/extensions/editor/flowgraph/variables.lua
im.Dummy(im.ImVec2(1,1))
ui_flowgraph_editor.variableEditor(target, varName, {global = global, showNodes = true, allowDelete = true})
end
--if im.TreeNode2(nm..variable.index..'-'..id, nm .. ' = ' .. vName) then
--ui_flowgraph_editor.variableEditor(target, nm, {global = global, showNodes = true, allowDelete = true})
self:drawVariableCard(target, nm, global)
@/lua/ge/extensions/flowgraph/nodes/types/getVariable.lua
end
ui_flowgraph_editor.variableEditor(self.target, self.varName)
end