From 0b7841b0bffa6b59e48d63e5b1cf762262149474 Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Fri, 4 Oct 2024 11:58:17 +0200 Subject: [PATCH 1/3] Fixes nil error #3493 --- scripts/Course.lua | 8 +++++--- scripts/editor/CourseEditor.lua | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/Course.lua b/scripts/Course.lua index 1f35f0ad0..53aa9698b 100644 --- a/scripts/Course.lua +++ b/scripts/Course.lua @@ -1572,8 +1572,8 @@ function Course:saveToXml(courseXml, courseKey) end end ----@param vehicle table ----@param courseXml XmlFile +---@param vehicle table|nil +---@param courseXml table ---@param courseKey string key to the course in the XML function Course.createFromXml(vehicle, courseXml, courseKey) local course = Course(vehicle, {}) @@ -1602,7 +1602,9 @@ function Course.createFromXml(vehicle, courseXml, courseKey) if course.nVehicles and course.nVehicles > 1 then course.multiVehicleData = Course.MultiVehicleData.createFromXmlFile(courseXml, courseKey) course:setPosition(course.multiVehicleData:getPosition()) - vehicle:getCpLaneOffsetSetting():setValue(course.multiVehicleData:getPosition()) + if vehicle then + vehicle:getCpLaneOffsetSetting():setValue(course.multiVehicleData:getPosition()) + end else course:enrichWaypointData() end diff --git a/scripts/editor/CourseEditor.lua b/scripts/editor/CourseEditor.lua index a2e34485e..b0d09f2eb 100644 --- a/scripts/editor/CourseEditor.lua +++ b/scripts/editor/CourseEditor.lua @@ -30,7 +30,7 @@ function CourseEditor:loadCourse() local function load(self, xmlFile, baseKey, noEventSend, name) xmlFile:iterate(baseKey, function (i, key) CpUtil.debugVehicle(CpDebug.DBG_COURSES, self, "Loading assigned course: %s", key) - local course = Course.createFromXml(self, xmlFile, key) + local course = Course.createFromXml(nil, xmlFile, key) course:setName(name) self.courseWrapper = EditorCourseWrapper(course) end) From 7f4988dd4ce1f529af486d68ac9572e1dcedcaff Mon Sep 17 00:00:00 2001 From: David Schwietering Date: Fri, 4 Oct 2024 15:26:08 +0200 Subject: [PATCH 2/3] Added course editor lane offset selection --- Courseplay.lua | 1 + config/MasterTranslations.xml | 4 ++ scripts/Course.lua | 13 +++++ .../ai/parameters/AIParameterSettingList.lua | 12 ++++ scripts/editor/CourseEditor.lua | 57 +++++++++++++++++++ 5 files changed, 87 insertions(+) diff --git a/Courseplay.lua b/Courseplay.lua index 1504fe686..d2a267377 100644 --- a/Courseplay.lua +++ b/Courseplay.lua @@ -196,6 +196,7 @@ function Courseplay:update(dt) g_bunkerSiloManager:update(dt) g_triggerManager:update(dt) g_baleToCollectManager:update(dt) + g_courseEditor:update(dt) if not self.postInit then -- Doubles the map zoom for 4x Maps. Mainly to make it easier to set targets for unload triggers. self.postInit = true diff --git a/config/MasterTranslations.xml b/config/MasterTranslations.xml index 47d6972d5..cb640baa6 100644 --- a/config/MasterTranslations.xml +++ b/config/MasterTranslations.xml @@ -1483,6 +1483,10 @@ The course is saved automatically on closing of the editor and overrides the sel + + + + diff --git a/scripts/Course.lua b/scripts/Course.lua index 53aa9698b..b16b2a726 100644 --- a/scripts/Course.lua +++ b/scripts/Course.lua @@ -1815,4 +1815,17 @@ function Course.MultiVehicleData.createFromStream(stream, nVehicles) end end return mvd +end + +function Course.MultiVehicleData.getAllowedPositions(nMultiToolVehicles) + if nMultiToolVehicles == 2 then + return {-1,1} + elseif nMultiToolVehicles == 3 then + return {-1,0,1} + elseif nMultiToolVehicles == 4 then + return {-2,-1,1,2} + elseif nMultiToolVehicles == 5 then + return {-2,-1,0,1,2} + end + return {0} end \ No newline at end of file diff --git a/scripts/ai/parameters/AIParameterSettingList.lua b/scripts/ai/parameters/AIParameterSettingList.lua index e9846cc7b..1e183a833 100644 --- a/scripts/ai/parameters/AIParameterSettingList.lua +++ b/scripts/ai/parameters/AIParameterSettingList.lua @@ -220,6 +220,18 @@ function AIParameterSettingList:refresh() self:validateTexts() end +--- Gets the texts for the given values. +---@param values table +---@return table +function AIParameterSettingList:getTextsForValues(values) + local texts = {} + for _, v in ipairs(values) do + local ix = self:getClosestIx(v) + table.insert(texts, self.data.texts[ix]) + end + return texts +end + function AIParameterSettingList:validateCurrentValue() local new = self:checkAndSetValidValue(self.current) if new ~= self.current then diff --git a/scripts/editor/CourseEditor.lua b/scripts/editor/CourseEditor.lua index b0d09f2eb..cb89cd69a 100644 --- a/scripts/editor/CourseEditor.lua +++ b/scripts/editor/CourseEditor.lua @@ -38,6 +38,10 @@ function CourseEditor:loadCourse() self.file:load(CpCourseManager.xmlSchema, CpCourseManager.xmlKeyFileManager, load, self, false) self.courseDisplay:setCourse(self.courseWrapper) + local course = self.courseWrapper:getCourse() + if course and course:getMultiTools() > 1 then + self.needsMultiToolDialog = true + end end --- Saves the course, might be a good idea to consolidate this with the saving of CpCourseManager. @@ -53,6 +57,40 @@ function CourseEditor:saveCourse() CpCourseManager.xmlKeyFileManager, save, self) end +function CourseEditor:update(dt) + -- if not g_gui:getIsDialogVisible() and self.needsMultiToolDialog then + -- self.needsMultiToolDialog = false + -- end +end + +function CourseEditor:onClickLaneOffsetSetting(closure, ignoreDialog) + local course = self.courseWrapper:getCourse() + local allowedValues = Course.MultiVehicleData.getAllowedPositions(course:getMultiTools()) + local texts = CpFieldWorkJobParameters.laneOffset:getTextsForValues(allowedValues) + if not ignoreDialog and not g_gui:getIsDialogVisible() then + g_gui:showOptionDialog({ + title = "", + text = CpFieldWorkJobParameters.laneOffset:getTitle(), + options = texts, + callback = function (item) + if item > 0 then + local value = allowedValues[item] + self.courseWrapper:getCourse():setPosition(value) + self.courseDisplay:setCourse(self.courseWrapper) + closure(texts[item]) + end + end + }) + else + local position = course.multiVehicleData.position + for ix, v in ipairs(allowedValues) do + if v == position then + closure(texts[ix]) + end + end + end +end + --- Activates the editor with a given course file. --- Also open the custom build menu only for CP. function CourseEditor:activate(file) @@ -99,6 +137,7 @@ function CourseEditor:deactivate() self.file = nil self.field = nil self.courseWrapper = nil + self.needsMultiToolDialog = false end @@ -401,5 +440,23 @@ local function resetMenuState(screen) end ConstructionScreen.resetMenuState = Utils.appendedFunction(ConstructionScreen.resetMenuState, resetMenuState) +local function registerMenuActionEvents(screen) + if g_courseEditor.isActive and g_courseEditor.needsMultiToolDialog then + local _, eventId = screen.inputManager:registerActionEvent(InputAction.CONSTRUCTION_ACTION_SNAPPING, screen, + function(screen, actionName) + local event = screen.inputManager:getFirstActiveEventForActionName(actionName) + g_courseEditor:onClickLaneOffsetSetting(function(text) + screen.inputManager:setActionEventText(event.id, string.format(g_i18n:getText("CP_editor_change_lane_offset"), text)) + end) + end, false, true, false, true) + g_courseEditor:onClickLaneOffsetSetting(function(text) + screen.inputManager:setActionEventText(eventId, string.format(g_i18n:getText("CP_editor_change_lane_offset"), text)) + end, true) + screen.inputManager:setActionEventActive(eventId, true) + screen.inputManager:setActionEventTextVisibility(eventId, true) + end +end +ConstructionScreen.registerMenuActionEvents = Utils.appendedFunction(ConstructionScreen.registerMenuActionEvents, registerMenuActionEvents) + g_courseEditor = CourseEditor.new() From 764f94c2f03ab242b4f9900ea50801adf8e8eb33 Mon Sep 17 00:00:00 2001 From: schwiti6190 Date: Fri, 4 Oct 2024 13:26:30 +0000 Subject: [PATCH 3/3] Updated translations --- translations/translation_br.xml | 1 + translations/translation_cs.xml | 1 + translations/translation_ct.xml | 1 + translations/translation_cz.xml | 1 + translations/translation_da.xml | 1 + translations/translation_de.xml | 1 + translations/translation_ea.xml | 1 + translations/translation_en.xml | 1 + translations/translation_es.xml | 1 + translations/translation_fc.xml | 1 + translations/translation_fi.xml | 1 + translations/translation_fr.xml | 1 + translations/translation_hu.xml | 1 + translations/translation_it.xml | 1 + translations/translation_jp.xml | 1 + translations/translation_kr.xml | 1 + translations/translation_nl.xml | 1 + translations/translation_no.xml | 1 + translations/translation_pl.xml | 1 + translations/translation_pt.xml | 1 + translations/translation_ro.xml | 1 + translations/translation_ru.xml | 1 + translations/translation_sv.xml | 1 + translations/translation_tr.xml | 1 + 24 files changed, 24 insertions(+) diff --git a/translations/translation_br.xml b/translations/translation_br.xml index 2bd69a0e3..18af4e132 100644 --- a/translations/translation_br.xml +++ b/translations/translation_br.xml @@ -440,6 +440,7 @@ A rota é salva automaticamente ao fechar o editor e substituir a rota seleciona + diff --git a/translations/translation_cs.xml b/translations/translation_cs.xml index 56627649b..a8e9266c1 100644 --- a/translations/translation_cs.xml +++ b/translations/translation_cs.xml @@ -440,6 +440,7 @@ + diff --git a/translations/translation_ct.xml b/translations/translation_ct.xml index 29fc5ee1a..21004b853 100644 --- a/translations/translation_ct.xml +++ b/translations/translation_ct.xml @@ -440,6 +440,7 @@ + diff --git a/translations/translation_cz.xml b/translations/translation_cz.xml index 843625b66..18c7dbec0 100644 --- a/translations/translation_cz.xml +++ b/translations/translation_cz.xml @@ -440,6 +440,7 @@ Trasa se automaticky uloží při zavření editoru a přepíše vybranou trasu. + diff --git a/translations/translation_da.xml b/translations/translation_da.xml index 51908af39..d7dd6de3f 100644 --- a/translations/translation_da.xml +++ b/translations/translation_da.xml @@ -440,6 +440,7 @@ Ruten gemmes automatisk ved lukning af editoren og tilsidesætter den valgte rut + diff --git a/translations/translation_de.xml b/translations/translation_de.xml index 523bc33b9..66997c202 100644 --- a/translations/translation_de.xml +++ b/translations/translation_de.xml @@ -440,6 +440,7 @@ Der Kurs wird beim Schließen automatisch gespeichert und überschrieben. + diff --git a/translations/translation_ea.xml b/translations/translation_ea.xml index 7f957cc2c..c39e7877a 100644 --- a/translations/translation_ea.xml +++ b/translations/translation_ea.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_en.xml b/translations/translation_en.xml index b597bf61a..0204c5a05 100644 --- a/translations/translation_en.xml +++ b/translations/translation_en.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_es.xml b/translations/translation_es.xml index d7114cce4..418f810a5 100644 --- a/translations/translation_es.xml +++ b/translations/translation_es.xml @@ -440,6 +440,7 @@ El curso se guarda automáticamente al cerrar el editor y anula el curso selecci + diff --git a/translations/translation_fc.xml b/translations/translation_fc.xml index e4dd6a2b7..227d7c32d 100644 --- a/translations/translation_fc.xml +++ b/translations/translation_fc.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_fi.xml b/translations/translation_fi.xml index fbd050a53..fa104315b 100644 --- a/translations/translation_fi.xml +++ b/translations/translation_fi.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_fr.xml b/translations/translation_fr.xml index 3ebff9db8..4200999d3 100644 --- a/translations/translation_fr.xml +++ b/translations/translation_fr.xml @@ -440,6 +440,7 @@ La course est automatiquement sauvegardée à la fermeture de l'éditeur et remp + diff --git a/translations/translation_hu.xml b/translations/translation_hu.xml index 9babbb361..2fc16d3b9 100644 --- a/translations/translation_hu.xml +++ b/translations/translation_hu.xml @@ -440,6 +440,7 @@ Az útvonal automatikusan mentésre kerül a szerkesztő bezárásakor és felü + diff --git a/translations/translation_it.xml b/translations/translation_it.xml index 64ff08578..ee28bc30a 100644 --- a/translations/translation_it.xml +++ b/translations/translation_it.xml @@ -440,6 +440,7 @@ Il percorso viene salvato automaticamente alla chiusura dell'editor e sovrascriv + diff --git a/translations/translation_jp.xml b/translations/translation_jp.xml index 64f3e303a..6d0ed01fe 100644 --- a/translations/translation_jp.xml +++ b/translations/translation_jp.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_kr.xml b/translations/translation_kr.xml index 32428610b..06ae47f85 100644 --- a/translations/translation_kr.xml +++ b/translations/translation_kr.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_nl.xml b/translations/translation_nl.xml index 7c1a49f4a..16b34b875 100644 --- a/translations/translation_nl.xml +++ b/translations/translation_nl.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_no.xml b/translations/translation_no.xml index 395de0e6b..d80944650 100644 --- a/translations/translation_no.xml +++ b/translations/translation_no.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_pl.xml b/translations/translation_pl.xml index 1ffb085a1..d61eff10a 100644 --- a/translations/translation_pl.xml +++ b/translations/translation_pl.xml @@ -440,6 +440,7 @@ Kurs jest automatycznie zapisywany po zamknięciu edytora i nadpisuje wybrany ku + diff --git a/translations/translation_pt.xml b/translations/translation_pt.xml index 29cced271..13b259007 100644 --- a/translations/translation_pt.xml +++ b/translations/translation_pt.xml @@ -440,6 +440,7 @@ A rota é guardada automaticamente ao fechar o editor e sobrepõe-se a qualquer + diff --git a/translations/translation_ro.xml b/translations/translation_ro.xml index 01bfeecdf..aa2e9b642 100644 --- a/translations/translation_ro.xml +++ b/translations/translation_ro.xml @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel + diff --git a/translations/translation_ru.xml b/translations/translation_ru.xml index 6d08c4737..25664df97 100644 --- a/translations/translation_ru.xml +++ b/translations/translation_ru.xml @@ -440,6 +440,7 @@ + diff --git a/translations/translation_sv.xml b/translations/translation_sv.xml index d513009fb..f3deda841 100644 --- a/translations/translation_sv.xml +++ b/translations/translation_sv.xml @@ -440,6 +440,7 @@ Banan sparas automatiskt vid stängning av editorn och åsidosätter den valda b + diff --git a/translations/translation_tr.xml b/translations/translation_tr.xml index d3356cbbb..cb7f031d9 100644 --- a/translations/translation_tr.xml +++ b/translations/translation_tr.xml @@ -440,6 +440,7 @@ Editör kapatıldığında kurs otomatik olarak kaydedilir ve seçilen kursu ge +