From 1c9a782f31cb5b58d666c28d1c0f98e1bf482ef4 Mon Sep 17 00:00:00 2001 From: schwiti6190 <58079399+schwiti6190@users.noreply.github.com> Date: Sun, 24 Dec 2023 16:43:08 +0100 Subject: [PATCH] Added fillType Setting --- config/MasterTranslations.xml | 10 +- config/gui/CourseGeneratorSettingsFrame.xml | 11 +- config/gui/FillTypeTargetFrame.xml | 49 +++++ config/gui/GUIProfiles.xml | 73 ++++++++ .../FieldWorkJobParameterSetup.xml | 2 + .../FillTypeSelectionParameterSetup.xml | 12 ++ .../jobParameters/StreetJobParameterSetup.xml | 11 +- modDesc.xml | 1 + scripts/CpSettingsUtil.lua | 12 +- scripts/ai/AIUtil.lua | 20 ++ scripts/ai/jobs/CpJobParameters.lua | 17 ++ scripts/ai/parameters/AIParameterSetting.lua | 25 ++- .../AIParameterSettingInterface.lua | 8 + .../ai/parameters/AIParameterSettingList.lua | 44 +++-- .../CpAIParameterFillTypeSelection.lua | 175 ++++++++++++++++++ scripts/gui/CpAIFrameExtended.lua | 123 +++++++++++- scripts/gui/CpOptionToggleElement.lua | 100 +--------- 17 files changed, 562 insertions(+), 131 deletions(-) create mode 100644 config/gui/FillTypeTargetFrame.xml create mode 100644 config/jobParameters/FillTypeSelectionParameterSetup.xml create mode 100644 scripts/ai/parameters/CpAIParameterFillTypeSelection.lua diff --git a/config/MasterTranslations.xml b/config/MasterTranslations.xml index 30501f574..ea3fe1ce0 100644 --- a/config/MasterTranslations.xml +++ b/config/MasterTranslations.xml @@ -418,13 +418,9 @@ - - - - - - - + + + diff --git a/config/gui/CourseGeneratorSettingsFrame.xml b/config/gui/CourseGeneratorSettingsFrame.xml index 1d99bef95..38b991333 100644 --- a/config/gui/CourseGeneratorSettingsFrame.xml +++ b/config/gui/CourseGeneratorSettingsFrame.xml @@ -1,7 +1,7 @@ - - + + @@ -9,6 +9,13 @@ + + + + + + + diff --git a/config/gui/FillTypeTargetFrame.xml b/config/gui/FillTypeTargetFrame.xml new file mode 100644 index 000000000..ffedf4e0d --- /dev/null +++ b/config/gui/FillTypeTargetFrame.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/gui/GUIProfiles.xml b/config/gui/GUIProfiles.xml index 8886c1bd9..b7b7b69aa 100644 --- a/config/gui/GUIProfiles.xml +++ b/config/gui/GUIProfiles.xml @@ -126,5 +126,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/jobParameters/FieldWorkJobParameterSetup.xml b/config/jobParameters/FieldWorkJobParameterSetup.xml index 039c32fde..f775e0109 100644 --- a/config/jobParameters/FieldWorkJobParameterSetup.xml +++ b/config/jobParameters/FieldWorkJobParameterSetup.xml @@ -15,6 +15,8 @@ + + diff --git a/config/jobParameters/FillTypeSelectionParameterSetup.xml b/config/jobParameters/FillTypeSelectionParameterSetup.xml new file mode 100644 index 000000000..d4ea052e6 --- /dev/null +++ b/config/jobParameters/FillTypeSelectionParameterSetup.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/config/jobParameters/StreetJobParameterSetup.xml b/config/jobParameters/StreetJobParameterSetup.xml index 31a2a2f55..a1917293d 100644 --- a/config/jobParameters/StreetJobParameterSetup.xml +++ b/config/jobParameters/StreetJobParameterSetup.xml @@ -20,8 +20,13 @@ - - - + + + + + + + + \ No newline at end of file diff --git a/modDesc.xml b/modDesc.xml index c1f1fd82f..7d60b8f86 100644 --- a/modDesc.xml +++ b/modDesc.xml @@ -388,6 +388,7 @@ Changelog 7.1.0.0: + diff --git a/scripts/CpSettingsUtil.lua b/scripts/CpSettingsUtil.lua index e707eddb3..1225c4896 100644 --- a/scripts/CpSettingsUtil.lua +++ b/scripts/CpSettingsUtil.lua @@ -427,12 +427,22 @@ function CpSettingsUtil.raiseEventForSettings(settings, eventName, ...) end end -function CpSettingsUtil.registerXmlSchema(schema, key) +function CpSettingsUtil.registerXmlSchemaForSetting(schema, key) schema:register(XMLValueType.INT, key.."#value", "Old setting save format.") schema:register(XMLValueType.STRING, key.."#currentValue", "Setting value") schema:register(XMLValueType.STRING, key.."#name", "Setting name") end +function CpSettingsUtil.registerXmlSchema(schema, key) + CpSettingsUtil.registerXmlSchemaForSetting(schema, key) + + --- Fill type setting + CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).fillType") + CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).maxFillLevel") + CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).minFillLevel") + CpSettingsUtil.registerXmlSchemaForSetting(schema, key .. "(?).counter") +end + --- Loads setting values from an xml file. ---@param dataTable table ---@param xmlFile table diff --git a/scripts/ai/AIUtil.lua b/scripts/ai/AIUtil.lua index 0b8f3942b..1d3ec9448 100644 --- a/scripts/ai/AIUtil.lua +++ b/scripts/ai/AIUtil.lua @@ -727,3 +727,23 @@ function AIUtil.isOtherVehicleAhead(vehicle, otherVehicle) local _, _, dz = localToLocal(otherVehicle.rootNode, vehicle:getAIDirectionNode(), 0, 0, 0) return dz > (frontMarkerOffset + backMarkerOffset) / 2 end + +function AIUtil.getAllValidFillTypes(vehicle, lambda, ...) + local fillTypes, fillTypesByIndex = {}, {} + for _, v in pairs(vehicle:getChildVehicles()) do + if v.getFillUnits then + for ix, _ in pairs(v:getFillUnits()) do + for fillType, state in pairs(v:getFillUnitSupportedFillTypes(ix)) do + if state then + if not fillTypesByIndex[fillType] and + (lambda == nil or lambda(fillType, ...)) then + fillTypesByIndex[fillType] = true + table.insert(fillTypes, fillType) + end + end + end + end + end + end + return fillTypes, fillTypesByIndex +end diff --git a/scripts/ai/jobs/CpJobParameters.lua b/scripts/ai/jobs/CpJobParameters.lua index 145a98f26..ecb977ec6 100644 --- a/scripts/ai/jobs/CpJobParameters.lua +++ b/scripts/ai/jobs/CpJobParameters.lua @@ -538,6 +538,23 @@ function CpStreetJobParameters:isLoadTargetPointDisabled() return self:hasNoValidTrailerAttached() or self.loadUnloadTargetMode:getValue() ~= CpStreetJobParameters.LOAD_AND_UNLOAD end +function CpStreetJobParameters:generateFillTypes() + local fillTypes = {} + local texts = {} + local vehicle = self.job:getVehicle() + if vehicle then + fillTypes = AIUtil.getAllValidFillTypes(vehicle, function() + return true + end) + for _, f in pairs(fillTypes) do + table.insert(texts, g_fillTypeManager:getFillTypeTitleByIndex(f)) + end + end + table.insert(fillTypes, 1, -1) + table.insert(texts, 1, "---") + return fillTypes, texts, fillTypes[1] +end + ---@param setting CpAIParameterTargetPoint function CpStreetJobParameters:onChangeTargetPoints(setting) if setting:getIsDisabled() then diff --git a/scripts/ai/parameters/AIParameterSetting.lua b/scripts/ai/parameters/AIParameterSetting.lua index d7bd08909..8920436b1 100644 --- a/scripts/ai/parameters/AIParameterSetting.lua +++ b/scripts/ai/parameters/AIParameterSetting.lua @@ -2,13 +2,13 @@ ---@class AIParameterSetting : AIParameterSettingInterface AIParameterSetting = CpObject(AIParameterSettingInterface) -function AIParameterSetting:init(name) +function AIParameterSetting:init(data, vehicle, class) AIParameterSettingInterface.init(self) self.data = nil - self.vehicle = nil - self.class = nil + self.vehicle = vehicle + self.class = class - self.name = name + self.name = "" self.title = "" self.tooltip = "" @@ -63,6 +63,9 @@ function AIParameterSetting:getIsDisabled() if self:hasCallback(self.data.isDisabledFunc) then return self:getCallback(self.data.isDisabledFunc) end + if self.parent and self.parent:getIsDisabled() then + return true + end return false end @@ -79,11 +82,17 @@ function AIParameterSetting:getIsVisible() if self:hasCallback(self.data.isVisibleFunc) then return self:getCallback(self.data.isVisibleFunc) end + if self.parent and not self.parent:getIsVisible() then + return false + end return true end --- Is the setting specific for a player and is not synchronized? function AIParameterSetting:getIsUserSetting() + if self.data == nil then + CpUtil.error("data is nil for %s!", self.name) + end return self.data.isUserSetting end @@ -92,6 +101,14 @@ function AIParameterSetting:getIsExpertModeSetting() return self.data.isExpertModeOnly end +function AIParameterSetting:setParent(parent) + self.parent = parent +end + +function AIParameterSetting:setClass(class) + self.class = class +end + --- Raises an event and sends the callback string to the Settings controller class. function AIParameterSetting:raiseCallback(callbackStr, ...) if self.class ~= nil and self.class.raiseCallback and callbackStr then diff --git a/scripts/ai/parameters/AIParameterSettingInterface.lua b/scripts/ai/parameters/AIParameterSettingInterface.lua index ed4ec64f5..ca15e83b1 100644 --- a/scripts/ai/parameters/AIParameterSettingInterface.lua +++ b/scripts/ai/parameters/AIParameterSettingInterface.lua @@ -173,4 +173,12 @@ end function AIParameterSettingInterface:getDebugString() +end + +function AIParameterSettingInterface:setParent(parent) + +end + +function AIParameterSettingInterface:setClass(class) + end \ No newline at end of file diff --git a/scripts/ai/parameters/AIParameterSettingList.lua b/scripts/ai/parameters/AIParameterSettingList.lua index cde7b6fba..d12d8c43c 100644 --- a/scripts/ai/parameters/AIParameterSettingList.lua +++ b/scripts/ai/parameters/AIParameterSettingList.lua @@ -90,12 +90,17 @@ function AIParameterSettingList.getAreaText(value, precision) return g_i18n:formatArea(value, 1, true) end +function AIParameterSettingList.getVolumeText(value, precision) + return g_i18n:formatVolume(value, 1) +end + AIParameterSettingList.UNITS_TEXTS = { - AIParameterSettingList.getSpeedText, --- km/h - AIParameterSettingList.getDistanceText, --- m - AIParameterSettingList.getAreaText, --- ha/arcs + AIParameterSettingList.getSpeedText, --- km/h + AIParameterSettingList.getDistanceText, --- m + AIParameterSettingList.getAreaText, --- ha/arcs function (value, precision) return string.format("%d", value) .. "%" end, --- percent - function (value, precision) return string.format("%d", value) .. "°" end --- degrees + function (value, precision) return string.format("%d", value) .. "°" end, --- degrees + AIParameterSettingList.getVolumeText -- liters } AIParameterSettingList.UNITS_CONVERSION = { @@ -129,7 +134,7 @@ end --- Enriches texts with values of values, if they are not explicit declared. function AIParameterSettingList:enrichTexts(texts, unit) if self.values == nil then - CpUtil.error("Failed to enrich texts!") + CpUtil.error("Failed to enrich texts for %s!", self.name) end for i, value in ipairs(self.values) do local text = tostring(value) @@ -204,16 +209,19 @@ end function AIParameterSettingList:refresh() if self.data.generateValuesFunction then local lastValue = self.values[self.current] - local newValue - self.values, self.texts, newValue = self:getCallback(self.data.generateValuesFunction, lastValue) - if newValue ~= nil then - self:setValue(newValue) - else - self:setValue(lastValue) + local values, texts, newValue = self:getCallback(self.data.generateValuesFunction, lastValue) + if values and texts then + self.values = values + self.texts = texts + if newValue ~= nil then + self:setValue(newValue) + else + self:setValue(lastValue) + end + self:debug("Refreshed from %s to %s", tostring(lastValue), tostring(self.values[self.current])) + self:validateTexts() + return end - self:debug("Refreshed from %s to %s", tostring(lastValue), tostring(self.values[self.current])) - self:validateTexts() - return end self.values = {} self.texts = {} @@ -366,6 +374,10 @@ end ---@param comparisonFunc function ---@return boolean value is not valid and could not be set. local function setValueInternal(self, value, comparisonFunc) + if not self.values then + CpUtil.error("No valid values table for %s", self.name) + return false + end local new -- find the value requested for i = 1, #self.values do @@ -499,6 +511,10 @@ function AIParameterSettingList:getValueByIndex(index) return self.values[index] end +function AIParameterSettingList:getCurrentIndex() + return self.current +end + --- Set the next value function AIParameterSettingList:setNextItem() local new = self:checkAndSetValidValue(self.current + 1) diff --git a/scripts/ai/parameters/CpAIParameterFillTypeSelection.lua b/scripts/ai/parameters/CpAIParameterFillTypeSelection.lua new file mode 100644 index 000000000..4ae68d716 --- /dev/null +++ b/scripts/ai/parameters/CpAIParameterFillTypeSelection.lua @@ -0,0 +1,175 @@ +---@class CpAIParameterFillTypeSetting : AIParameterSetting +CpAIParameterFillTypeSetting = CpObject(AIParameterSetting) + +function CpAIParameterFillTypeSetting:init(data, vehicle, class) + AIParameterSetting.init(self, data, vehicle, class) + self.guiParameterType = AIParameterType.TEXT --- For the giants gui element. + self:initFromData(data, vehicle, class) + --- Use this hack to load the setting without the need for changing every setting behavior. + local filePath = Utils.getFilename("config/jobParameters/FillTypeSelectionParameterSetup.xml", + g_Courseplay.BASE_DIRECTORY) + local childrenData = { + generateFillTypes = function () + return {-1}, {"-1"} + end + } + CpSettingsUtil.loadSettingsFromSetup(childrenData, filePath) + + --- Child parameters + self.fillType = childrenData.fillType:clone(vehicle, class) + self.fillType:setParent(self) + self.maxFillLevel = childrenData.maxFillLevel:clone(vehicle, class) + self.maxFillLevel:setParent(self) + self.minFillLevel = childrenData.minFillLevel:clone(vehicle, class) + self.minFillLevel:setParent(self) + self.counter = childrenData.counter:clone(vehicle, class) + self.counter:setParent(self) +end + +function CpAIParameterFillTypeSetting:saveToXMLFile(xmlFile, key, usedModNames) + self.fillType:saveToXMLFile(xmlFile, key..".fillType", usedModNames) + self.maxFillLevel:saveToXMLFile(xmlFile, key..".maxFillLevel", usedModNames) + self.minFillLevel:saveToXMLFile(xmlFile, key..".minFillLevel", usedModNames) + self.counter:saveToXMLFile(xmlFile, key..".counter", usedModNames) +end + +function CpAIParameterFillTypeSetting:loadFromXMLFile(xmlFile, key) + self.fillType:loadFromXMLFile(xmlFile, key..".fillType") + self.maxFillLevel:loadFromXMLFile(xmlFile, key..".maxFillLevel") + self.minFillLevel:loadFromXMLFile(xmlFile, key..".minFillLevel") + self.counter:loadFromXMLFile(xmlFile, key..".counter") +end + +function CpAIParameterFillTypeSetting:readStream(streamId, connection) + self.fillType:readStream(streamId, connection) + self.maxFillLevel:readStream(streamId, connection) + self.minFillLevel:readStream(streamId, connection) + self.counter:readStream(streamId, connection) + self.isSynchronized = true +end + +function CpAIParameterFillTypeSetting:writeStream(streamId, connection) + self.fillType:writeStream(streamId, connection) + self.maxFillLevel:writeStream(streamId, connection) + self.minFillLevel:writeStream(streamId, connection) + self.counter:writeStream(streamId, connection) +end + +function CpAIParameterFillTypeSetting:refresh() + self.fillType:refresh() + self.maxFillLevel:refresh() + self.minFillLevel:refresh() + self.counter:refresh() +end + +function CpAIParameterFillTypeSetting:clone(...) + return CpAIParameterFillTypeSetting(self.data,...) +end + +function CpAIParameterFillTypeSetting:bindSettingsToGui(lambda, ...) + lambda(self, self.fillType, self.maxFillLevel, self.minFillLevel, self.counter, ...) +end + +function CpAIParameterFillTypeSetting:getNumberOfItemsInSection(list, section) + return self.fillType:getNumberOfElements() +end + +function CpAIParameterFillTypeSetting:getTitleForSectionHeader(list, section) + return nil +end + +function CpAIParameterFillTypeSetting:populateCellForItemInSection(list, section, index, cell) + cell:getAttribute("name"):setText(self.fillType:getTextByIndex(index)) + -- if g_Courseplay.globalSettings:isAutoDriveForStreetActive() then + -- if g_Courseplay.adSortedGroups then + -- cell:getAttribute("name"):setText(g_Courseplay.adSortedGroups[section + g_Courseplay.adOffsetIndex][index].name) + -- cell.target = self.aiFrame + -- cell:setCallback("onClickCallback", "onClickStreetTargetList") + -- else + -- cell:getAttribute("name"):setText("---") + -- cell.target = self.aiFrame + -- cell:setCallback("onClickCallback", "onClickStreetTargetList") + -- end + -- else + -- if self.aiFrame.streetTargetPointParameter then + -- cell:getAttribute("name"):setText(self.aiFrame.streetTargetPointParameter:getTextByIndex(index)) + -- cell.target = self.aiFrame + -- cell:setCallback("onClickCallback", "onClickStreetTargetList") + -- end + -- end +end + +function CpAIParameterFillTypeSetting:onListSelectionChanged(list, section, index) + self.fillType:setValue(self.fillType:getValueByIndex(index)) +end + +function CpAIParameterFillTypeSetting:getString() + return self.fillType:getString() +end + +function CpAIParameterFillTypeSetting:__tostring() + return string.format("CpAIParameterFillTypeSetting(fillType: %s, maxFillLevel: %s, minFillLevel: %s, counter: %s)", + tostring(self.fillType), tostring(self.maxFillLevel), tostring(self.minFillLevel), tostring(self.counter)) +end + +--- Parameter to selected an unloading station. +---@class CpAIParameterFillTypeSelection : AIParameterSettingList +CpAIParameterFillTypeSelection = CpObject(AIParameterSettingList) +function CpAIParameterFillTypeSelection:init(data, vehicle, class) + AIParameterSettingList.init(self, data, vehicle, class) + + --- Child parameters + self.fillTypeSettings = {} + for i = 1, self.data.max do + self.fillTypeSettings[i] = CpAIParameterFillTypeSetting(data, vehicle, class) + end +end + +function CpAIParameterFillTypeSelection:saveToXMLFile(xmlFile, key, usedModNames) + AIParameterSettingList.saveToXMLFile(self, xmlFile, key, usedModNames) + for i = 1, self.data.max do + self.fillTypeSettings[i]:saveToXMLFile(xmlFile, string.format("%s(%d)", key, i), usedModNames) + end +end + +function CpAIParameterFillTypeSelection:loadFromXMLFile(xmlFile, key) + AIParameterSettingList.loadFromXMLFile(self, xmlFile, key) + xmlFile:iterate(key, function(ix, subKey) + self.fillTypeSettings[ix]:loadFromXMLFile(xmlFile, subKey) + end) +end + +function CpAIParameterFillTypeSelection:readStream(streamId, connection) + AIParameterSettingList.readStream(self, streamId, connection) + for i = 1, self.data.max do + self.fillTypeSettings[i]:readStream(streamId, connection) + end +end + +function CpAIParameterFillTypeSelection:writeStream(streamId, connection) + AIParameterSettingList.writeStream(self, streamId, connection) + for i = 1, self.data.max do + self.fillTypeSettings[i]:writeStream(streamId, connection) + end +end + +function CpAIParameterFillTypeSelection:refresh() + AIParameterSettingList.refresh(self) + for i = 1, self.data.max do + self.fillTypeSettings[i]:refresh() + end +end + +function CpAIParameterFillTypeSelection:clone(...) + return CpAIParameterFillTypeSelection(self.data,...) +end + +function CpAIParameterFillTypeSelection:bindChildSettingsToGui(lambda, ...) + for i = 1, self.data.max do + self.fillTypeSettings[i]:bindSettingsToGui(lambda, ...) + end +end + +function CpAIParameterFillTypeSelection:__tostring() + return string.format("CpAIParameterFillTypeSelection(name=%s, value=%s, text=%s)", self.name, tostring(self:getValue()), self:getString()) +end \ No newline at end of file diff --git a/scripts/gui/CpAIFrameExtended.lua b/scripts/gui/CpAIFrameExtended.lua index 25c60f4fc..17b4eccf6 100644 --- a/scripts/gui/CpAIFrameExtended.lua +++ b/scripts/gui/CpAIFrameExtended.lua @@ -2,6 +2,7 @@ CpInGameMenuAIFrameExtended = {} CpInGameMenuAIFrameExtended.MODE_COURSE_GENERATOR = 10 CpInGameMenuAIFrameExtended.MODE_DRAW_FIELD_BORDER = 11 CpInGameMenuAIFrameExtended.MODE_STREET_TARGET_POINT_SELECTION = 12 +CpInGameMenuAIFrameExtended.MODE_Fill_TYPE_SELECTION = 13 --- Adds the course generate button in the ai menu page. CpInGameMenuAIFrameExtended.positionUvs = GuiUtils.getUVs({ @@ -52,7 +53,7 @@ function CpInGameMenuAIFrameExtended:onAIFrameLoadMapFinished() self:registerControls({"createCpMultiOptionTemplate", "multiTextOptionPrefab","subTitlePrefab","courseGeneratorLayoutElements", "courseGeneratorLayout","courseGeneratorHeader","drawingCustomFieldHeader", - "vineCourseGeneratorLayoutElements", "courseGeneratorFrame"}) + "vineCourseGeneratorLayoutElements", "courseGeneratorFrame", "createCpTextTemplate"}) --- TODO: Figure out the correct implementation for Issues #1015 & #1457. local element = self:getDescendantByName("ingameMenuAI") @@ -76,6 +77,9 @@ function CpInGameMenuAIFrameExtended:onAIFrameLoadMapFinished() self.createCpMultiOptionTemplate:unlinkElement() FocusManager:removeElement(self.createCpMultiOptionTemplate) + self.createCpTextTemplate:unlinkElement() + FocusManager:removeElement(self.createCpTextTemplate) + --- Vine course generator layout local settingsBySubTitle = CpCourseGeneratorSettings.getVineSettingSetup() CpSettingsUtil.generateGuiElementsFromSettingsTable(settingsBySubTitle, @@ -153,6 +157,10 @@ function CpInGameMenuAIFrameExtended:onAIFrameLoadMapFinished() pageAI:onClickOpenCloseStreetTargetPointSelection() return end + if pageAI.mode == CpInGameMenuAIFrameExtended.MODE_Fill_TYPE_SELECTION then + pageAI:onClickOpenCloseFillTypeSelection() + return + end CpInGameMenuAIFrameExtended.resetHotspots(self) superFunc(pageAI) if pageAI:getIsPicking() then @@ -184,11 +192,40 @@ function CpInGameMenuAIFrameExtended:onAIFrameLoadMapFinished() self.createMultiOptionTemplate:delete() self.createMultiOptionTemplate = self.createCpMultiOptionTemplate + self.createTextTemplate:delete() + self.createTextTemplate = self.createCpTextTemplate + CpInGameMenuAIFrameExtended.aiFrame = self + + CpInGameMenuAIFrameExtended.registerConsoleCommands() end InGameMenuAIFrame.onLoadMapFinished = Utils.appendedFunction(InGameMenuAIFrame.onLoadMapFinished, CpInGameMenuAIFrameExtended.onAIFrameLoadMapFinished) +function CpInGameMenuAIFrameExtended:loadFillTypeSelectionFrame() + if self.fillTypeSelectionTargetFrame then + self.fillTypeSelectionTargetFrame:delete() + end + + self:registerControls({"fillTypeSelectionTargetFrame", "fillTypeSelectionTargetLayout", + "fillTypeSelectionTargetHeader", "fillTypeSelectionFillTypeTitle"}) + + local element = self:getDescendantByName("ingameMenuAI") + + local xmlFile = loadXMLFile("Temp", Utils.getFilename( + "config/gui/FillTypeTargetFrame.xml",Courseplay.BASE_DIRECTORY)) + g_gui:loadGuiRec(xmlFile, "FillTypeTargetFrame", + element, self) + delete(xmlFile) + self:exposeControlsAsFields() + self.fillTypeSelectionTargetFrame:onGuiSetupFinished() + self.fillTypeSelectionTargetFrame:applyScreenAlignment() + self.fillTypeSelectionTargetFrame:setVisible(false) + self.fillTypeSelectionTargetLayout:invalidateLayout() + element:updateAbsolutePosition() +end + + --- Creates alternative buttons, which are put into the button layout. function CpInGameMenuAIFrameExtended:setupButtons() local function createBtn(prefab, text, callback) @@ -241,11 +278,12 @@ function CpInGameMenuAIFrameExtended:updateContextInputBarVisibility() end self.buttonSelectStreetTargetPoint:setVisible(self.mode == CpInGameMenuAIFrameExtended.MODE_STREET_TARGET_POINT_SELECTION) - + self.buttonBack:setVisible(self:getCanGoBack() or self.mode == CpInGameMenuAIFrameExtended.MODE_COURSE_GENERATOR or self.mode == CpInGameMenuAIFrameExtended.MODE_DRAW_FIELD_BORDER or - self.mode == CpInGameMenuAIFrameExtended.MODE_STREET_TARGET_POINT_SELECTION) + self.mode == CpInGameMenuAIFrameExtended.MODE_STREET_TARGET_POINT_SELECTION or + self.mode == CpInGameMenuAIFrameExtended.MODE_Fill_TYPE_SELECTION) self.buttonDeleteCustomField:setVisible(self.currentHotspot and self.currentHotspot:isa(CustomFieldHotspot)) self.buttonRenameCustomField:setVisible(self.currentHotspot and self.currentHotspot:isa(CustomFieldHotspot)) @@ -433,9 +471,59 @@ function InGameMenuAIFrame:onClickSelectStreetTargetPoint() end end +function InGameMenuAIFrame:onClickOpenCloseFillTypeSelection() + if self.mode == CpInGameMenuAIFrameExtended.MODE_Fill_TYPE_SELECTION then + self.fillTypeSelectionTargetFrame:setVisible(false) + self.contextBox:setVisible(true) + self:toggleMapInput(true) + self.ingameMap:onOpen() + self.ingameMap:registerActionEvents() + self.mode = InGameMenuAIFrame.MODE_CREATE + self:setJobMenuVisible(true) + self:updateParameterValueTexts() + else + self.mode = CpInGameMenuAIFrameExtended.MODE_Fill_TYPE_SELECTION + CpInGameMenuAIFrameExtended:consoleCommandReloadFillTypeSelection() + -- for i = #self.fillTypeSelectionTargetLayout.elements, 1, -1 do + -- self.fillTypeSelectionTargetLayout.elements[i]:delete() + -- end + -- self.fillTypeSelectionTargetLayout:invalidateLayout() + if self.fillTypeSelectionParameter then + self.fillTypeSelectionTargetHeader:setText(string.format("%s(%s)", + self.fillTypeSelectionParameter:getTitle(), + CpUtil.getName(CpInGameMenuAIFrameExtended.getVehicle()))) + self.fillTypeSelectionParameter:bindSettingsToGui(function(fillTypeSetting, fillType, maxFillLevel, minFillLevel, counter) + local element = self.fillTypeSelectionTargetLayout--:clone(self.fillTypeSelectionTargetLayout) + -- FocusManager:loadElementFromCustomValues(element) + local function link(element, setting) + print(tostring(setting)) + setting:refresh() + element:setDataSource(setting) + element.aiParameter = setting + element:setDisabled(not setting:getCanBeChanged()) + end + element:getDescendantByName("fillType"):setDelegate(nil) + link(element:getDescendantByName("fillType"), fillTypeSetting) + element:getDescendantByName("fillType"):reloadData() + element:getDescendantByName("fillType"):setSelectedIndex(fillType:getCurrentIndex()) + self.fillTypeSelectionFillTypeTitle:setText(fillTypeSetting:getTitle()) + link(element:getDescendantByName("maxFillLevel"), maxFillLevel) + link(element:getDescendantByName("minFillLevel"), minFillLevel) + link(element:getDescendantByName("counter"), counter) + element:invalidateLayout() + -- self.fillTypeSelectionTargetLayout:invalidateLayout() + end, self) + end + self.fillTypeSelectionTargetFrame:setVisible(true) + self:toggleMapInput(false) + self:setJobMenuVisible(false) + self.contextBox:setVisible(false) + end +end + function CpInGameMenuAIFrameExtended:getNumberOfItemsInSection(list, section) if g_Courseplay.globalSettings:isAutoDriveForStreetActive() then - return g_Courseplay.adSortedGroups and #g_Courseplay.adSortedGroups[section + g_Courseplay.adOffsetIndex] + return g_Courseplay.adSortedGroups and #g_Courseplay.adSortedGroups[section + g_Courseplay.adOffsetIndex] or 1 else if self.aiFrame.streetTargetPointParameter then return self.aiFrame.streetTargetPointParameter:getNumberOfElements() @@ -722,20 +810,30 @@ function InGameMenuAIFrame:onClickMultiTextOptionCenterParameter(guiElement) if parameter and parameter.is_a and vehicle then if g_Courseplay.globalSettings:isAutoDriveForStreetActive() then if parameter:is_a(CpAIParameterTargetPoint) then - self.streetTargetPointHeader:setText(string.format("%s(%s)", parameter:getTitle(), CpUtil.getName(vehicle))) + self.streetTargetPointHeader:setText(string.format("%s(%s)", + parameter:getTitle(), CpUtil.getName(vehicle))) self.streetTargetPointParameter = parameter self:onClickOpenCloseStreetTargetPointSelection() end else if parameter:is_a(CpAIParameterUnloadingStation) then - self.streetTargetPointHeader:setText(string.format("%s(%s)", parameter:getTitle(), CpUtil.getName(vehicle))) + self.streetTargetPointHeader:setText(string.format("%s(%s)", + parameter:getTitle(), CpUtil.getName(vehicle))) self.streetTargetPointParameter = parameter self:onClickOpenCloseStreetTargetPointSelection() end end + if parameter:is_a(CpAIParameterFillTypeSetting) then + self.fillTypeSelectionParameter = parameter + CpUtil.try(self.onClickOpenCloseFillTypeSelection, self) + end end end +function InGameMenuAIFrame:onClickFillTypeMultiTextOptionParameter(guiElement) + +end + --- Added support for the cp field target position. function CpInGameMenuAIFrameExtended:updateParameterValueTexts(superFunc, ...) if self.currentJobElements == nil then @@ -951,4 +1049,17 @@ function CpInGameMenuAIFrameExtended.getVehicle() if vehicle ~=nil and vehicle:isa(Vehicle) then return vehicle end +end + +function CpInGameMenuAIFrameExtended.registerConsoleCommands() + g_devHelper.consoleCommands:registerConsoleCommand("cpGuiReloadFillTypeSelection", + "cpGuiReloadFillTypeSelection", "consoleCommandReloadFillTypeSelection", CpInGameMenuAIFrameExtended) +end + +function CpInGameMenuAIFrameExtended:consoleCommandReloadFillTypeSelection() + --- Reloading profiles + g_gui.currentlyReloading = true + g_gui:loadProfiles( Utils.getFilename("config/gui/GUIProfiles.xml", Courseplay.BASE_DIRECTORY) ) + CpInGameMenuAIFrameExtended.loadFillTypeSelectionFrame(CpInGameMenuAIFrameExtended.aiFrame) + g_gui.currentlyReloading = false end \ No newline at end of file diff --git a/scripts/gui/CpOptionToggleElement.lua b/scripts/gui/CpOptionToggleElement.lua index f9ae45944..6f3e873d2 100644 --- a/scripts/gui/CpOptionToggleElement.lua +++ b/scripts/gui/CpOptionToggleElement.lua @@ -30,99 +30,11 @@ function CpOptionToggleElement:updateContentElement() end end --- function CpOptionToggleElement:addElement(element) --- CpOptionToggleElement:superClass().addElement(self, element) --- if self.textElement then --- self.textElement.target = self --- self.textElement:setCallback("onClickCallback", "onCenterButtonClicked") --- end --- end - --- function CpOptionToggleElement:mouseEvent(posX, posY, isDown, isUp, button, eventUsed) --- if self:getIsActive() then --- eventUsed = eventUsed or CpOptionToggleElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed) --- local cursorInElement = GuiUtils.checkOverlayOverlap(posX, posY, self.absPosition[1], --- self.absPosition[2], self.size[1], self.size[2], nil) --- if not eventUsed then - --- end - --- if cursorInElement then --- if not self.mouseEntered then --- if not self.forceHighlight then --- FocusManager:setHighlight(self) --- end - --- self.mouseEntered = true --- end --- else --- self:restoreOverlayState() - --- self.mouseDown = false --- self.mouseEntered = false - --- if not self.forceHighlight then --- FocusManager:unsetHighlight(self) --- end --- end - --- if not eventUsed and cursorInElement and not FocusManager:isLocked() then --- if isDown and button == Input.MOUSE_BUTTON_LEFT then --- if self.handleFocus and not self.forceFocus then --- FocusManager:setFocus(self) - --- eventUsed = true --- end - --- self.mouseDown = true --- end - --- if self.mouseDown and self:getOverlayState() ~= GuiOverlay.STATE_PRESSED then --- self:storeOverlayState() --- self:setOverlayState(GuiOverlay.STATE_PRESSED) --- end - --- if isUp and button == Input.MOUSE_BUTTON_LEFT and self.mouseDown then --- self:restoreOverlayState() - --- self.mouseDown = false - --- self:sendAction() - --- eventUsed = true --- end --- end --- end - - --- if self:getIsActive() then --- if CpOptionToggleElement:superClass().mouseEvent(self, posX, posY, isDown, isUp, button, eventUsed) then --- eventUsed = true --- end - --- if not eventUsed and not self.forceHighlight --- and GuiUtils.checkOverlayOverlap(posX, posY, --- self.absPosition[1], self.absPosition[2], --- self.absSize[1], self.absSize[2], nil) then --- if not self.mouseEntered and not self.focusActive then --- FocusManager:setHighlight(self) - --- self.mouseEntered = true --- end --- elseif self.mouseEntered and not self.focusActive then --- FocusManager:unsetHighlight(self) - --- self.mouseEntered = false --- end --- end - --- return eventUsed --- end - --- function CpOptionToggleElement:onFocusActivate() --- if self:getIsActive() then --- print("Hello focus") --- end --- end +function CpOptionToggleElement:updateTitle() + CpOptionToggleElement:superClass().updateTitle(self) + if self.labelElement and self.labelElement.setText then + self.labelElement:setText(self.dataSource:getTitle()) + end +end Gui.CONFIGURATION_CLASS_MAPPING.cpOptionToggle = CpOptionToggleElement \ No newline at end of file