vehicleSelector
Definition
-- @/lua/common/extensions/ui/flowgraph/editor.lua:567
local function vehicleSelector(self, onlyModel)
local reason = nil
self.openPopup = false
if not self._imguiId then
self._imguiId = uniqueIdCounter .. "_childVehicleSelector"
uniqueIdCounter = uniqueIdCounter + 1
end
self.model = self.model or ""
self.config = self.config or ""
self.vehType = self.vehType or 'Car'
self.modelName = self.modelName or ""
self.configName = self.configName or ""
local availWidth = im.GetContentRegionAvailWidth()
local scale = editor.getPreference("ui.general.scale")
local spacing, elemHeight = 0, im.GetFrameHeightWithSpacing()
local elemCount = 3
local height = elemCount * elemHeight + (elemCount - 2) * spacing
im.BeginChild1(self._imguiId, im.ImVec2(-1, height), false, im.WindowFlags_NoScrollWithMouse)
if self.models == nil or next(self.models) == nil then
if im.Button("Load Models and Configs") then
self.models = core_vehicles.getModelList(true).models
table.sort(self.models, function(m1, m2)
return (m1.Name or "") < (m2.Name or "")
end)
if not onlyModel then
if self.model and self.model ~= "" then
local modelData = core_vehicles.getModel(self.model)
if modelData and modelData.model then
self.modelName = dumps(modelData.model.Name)
self.configs = modelData.configs
self.vehType = modelData.model.Type
if self.configs[self.config] then
self.configName = self.configs[self.config].Name or ""
self.configPath = "vehicles/" .. self.model .. "/" .. self.configs[self.config].key .. ".pc"
end
local sortedConfigs = { }
for k, v in pairs(self.configs) do
table.insert(sortedConfigs, { key = k, value = v })
end
table.sort(sortedConfigs, function(c1, c2)
return (c1.value.Name or "") < (c2.value.Name or "")
end)
self.configs = sortedConfigs
end
end
end
end
end
im.Columns(2)
im.SetColumnWidth(0, 60)
if self.models == nil or next(self.models) == nil then
im.Text("Model")
im.NextColumn()
if self.modelName and self.modelName ~= "" then
im.Text(tostring(self.modelName))
elseif self.model and self.model ~= "" then
im.Text(tostring(self.model))
else
im.Text(tostring("No Model Selected"))
end
im.NextColumn()
if not onlyModel then
im.Text("Config")
im.NextColumn()
if self.configName and self.configName ~= "" then
im.Text(tostring(self.configName))
elseif self.config and self.config ~= "" then
im.Text(tostring(self.config))
else
im.Text(tostring("No Config Selected"))
end
end
im.Columns(1)
else
im.Text("Type")
im.NextColumn()
im.PushItemWidth(im.GetContentRegionAvailWidth() - 28)
if im.BeginCombo("##vehType" .. dumps(self.id), self.vehType) then
for _, t in ipairs({ 'Car', 'Truck', 'Prop', 'Trailer', 'Utility', 'Unknown', 'Any'}) do
if im.Selectable1(t, t == self.vehType) then
if t ~= self.vehType then
self.vehType = t
self.model = ""
self.modelName = ""
self.config = ""
self.configName = ""
self.configs = ""
if not onlyModel then
self.config = ""
self.configName = ""
end
reason = "Changed Type to " .. t
end
end
end
im.EndCombo()
end
im.SameLine()
if editor.uiIconImageButton(editor.icons.search, im.ImVec2(22, 22)) then
self.openPopup = true
end
im.NextColumn()
im.Text("Model")
im.NextColumn()
im.PushItemWidth(im.GetContentRegionAvailWidth())
if im.BeginCombo("##models" .. dumps(self.id), self.modelName .. " [" .. self.model .. "]") then
for _, m in ipairs(self.models) do
if m.Type == self.vehType or self.vehType == 'Any' then
if im.Selectable1(m.Name and (m.Name .. " [" .. m.key .. "]") or m.key, m.key == self.model) then
if self.model ~= m.key then
self.model = m.key
self.modelName = dumps(m.Name)
if not onlyModel then
self.configs = core_vehicles.getModel(m.key).configs
-- non-indexed table has to be wrapped, to be able to iterate in sorted order later
local sortedConfigs = { }
for k, v in pairs(self.configs) do
table.insert(sortedConfigs, { key = k, value = v })
end
table.sort(sortedConfigs, function(c1, c2)
return (c1.value.Name or "") < (c2.value.Name or "")
end)
self.configs = sortedConfigs
self.config = ""
self.configName = ""
end
reason = "Changed Model to " .. dumps(m.Name)
end
end
end
end
im.EndCombo()
end
im.NextColumn()
if not onlyModel then
im.Text("Config")
im.NextColumn()
if self.configs and self.configs ~= {} then
im.PushItemWidth(im.GetContentRegionAvailWidth())
if im.BeginCombo("##configs" .. dumps(self.id), self.configName .. " [" .. self.config .. "]") then
for _, m in ipairs(self.configs) do
if im.Selectable1((dumps(m.value.Name) .. " [" .. m.key .. "]"), m.key == self.config) then
self.config = m.key
self.configName = dumps(m.value.Name)
self.configPath = "vehicles/" .. self.model .. "/" .. m.key .. ".pc"
reason = "Changed Vehicle to " .. dumps(m.value.Name)
end
end
im.EndCombo()
end
end
end
end
im.NextColumn()
im.Columns(1)
im.EndChild()
if self.openPopup then im.OpenPopup("vehicleSearchUtil"..self._imguiId) end
if im.BeginPopup("vehicleSearchUtil"..self._imguiId) then
im.BeginChild1("vehicleSearchUtilChild"..self._imguiId, im.ImVec2(350,250))
local searchChanged = false
--if not vehSearchFocus then
--im.SetKeyboardFocusHere()
--im.SetKeyboardFocusHere()
--im.SetKeyboardFocusHere()
--im.SetKeyboardFocusHere()
--vehSearchFocus = true
--end
im.SetNextItemWidth(im.GetContentRegionAvailWidth())
if im.InputText("##searchVehicles", vehSearchTxt, nil, im.InputTextFlags_AutoSelectAll) then
searchChanged = true
end
if searchChanged then
vehSearch:startSearch(ffi.string(vehSearchTxt))
for mIdx, m in ipairs(self.models) do
for cIdx, c in pairs(core_vehicles.getModel(m.key).configs) do
vehSearch:queryElement({
id = m.key.." / " ..c.key,
name = c.Name,
info = {mIdx = mIdx, cIdx = cIdx, modelKey = m.key, configKey = c.key, modelName = m.Name, configName = c.Name}
}, vehicleScoringFunction)
end
end
vehSearchResults = vehSearch:finishSearch()
end
if vehSearchResults then
im.BeginChild1("Scroller", im.GetContentRegionAvail())
for _, result in ipairs(vehSearchResults) do
im.BeginChild1(result.id, im.ImVec2(im.GetContentRegionAvailWidth(), 20 * editor.getPreference("ui.general.scale")))
local cPos = im.GetCursorScreenPos()
im.HighlightText(result.name, vehSearch.matchString)
im.SameLine()
im.BeginDisabled()
im.HighlightText(result.info.modelKey .. "/"..result.info.configKey, vehSearch.matchString)
im.EndDisabled()
im.SameLine()
im.EndChild()
local size = im.GetItemRectSize()
if im.IsItemHovered() then
im.ImDrawList_AddRect(im.GetWindowDrawList(), cPos, im.ImVec2(cPos.x + size.x, cPos.y + size.y), im.GetColorU322(im.ImVec4(1,0.6,0,0.5)), nil, nil, 1)
end
if im.IsItemClicked() then
im.CloseCurrentPopup()
self.model = result.info.modelKey
self.config = result.info.configKey
if self.model and self.model ~= "" then
local modelData = core_vehicles.getModel(self.model)
if modelData and modelData.model then
self.modelName = dumps(modelData.model.Name)
self.configs = modelData.configs
self.vehType = modelData.model.Type
if self.configs[self.config] then
self.configName = self.configs[self.config].Name or ""
self.configPath = "vehicles/" .. self.model .. "/" .. self.configs[self.config].key .. ".pc"
end
local sortedConfigs = { }
for k, v in pairs(self.configs) do
table.insert(sortedConfigs, { key = k, value = v })
end
table.sort(sortedConfigs, function(c1, c2)
return (c1.value.Name or "") < (c2.value.Name or "")
end)
self.configs = sortedConfigs
reason = "changed vehicle through search"
end
end
end
end
im.EndChild()
else
if ffi.string(vehSearchTxt) == "" then
im.Text("Type vehicle model or config here to get results.")
end
end
im.EndChild()
im.EndPopup()
else
vehSearchTxt = im.ArrayChar(256)
vehSearchResults = nil
end
return reason
end
Callers
@/lua/ge/extensions/gameplay/missions/missionTypes/editorHelper.lua
if ui_flowgraph_editor.vehicleSelector(e.mc) then
mtd[e.fieldNameModel] = e.mc.model
@/lua/ge/extensions/flowgraph/nodes/vehicle/vehicleConfigProvider.lua
local reason = nil
reason = ui_flowgraph_editor.vehicleSelector(self)
return reason
@/lua/ge/extensions/editor/util/editorElementHelper.lua
local ret = false
if ui_flowgraph_editor.vehicleSelector(e.mc) then
ctd[e.fieldNameModel] = e.mc.model
@/lua/ge/extensions/flowgraph/nodes/vehicle/special/vehicleAction.lua
local reason = nil
reason = ui_flowgraph_editor.vehicleSelector(self, true)
if self.model and self.model ~= "" then
@/lua/ge/extensions/flowgraph/nodes/vehicle/customPartsConfigProvider.lua
if im.TreeNode2("Load from File","Load from File") then
reason = ui_flowgraph_editor.vehicleSelector(self)
if self.configPath then