Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes nil error #3493 #3495

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Courseplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions config/MasterTranslations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,10 @@ The course is saved automatically on closing of the editor and overrides the sel
<Text language="de"><![CDATA[Kurseditor]]></Text>
<Text language="en"><![CDATA[Course editor]]></Text>
</Translation>
<Translation name="CP_editor_change_lane_offset">
<Text language="de"><![CDATA[Ausgewählten Bahnenversatz(%s) ändern]]></Text>
<Text language="en"><![CDATA[Change selected lane offset(%s)]]></Text>
</Translation>
<Translation name="CP_editor_delete_title">
<Text language="de"><![CDATA[Wegpunkte löschen]]></Text>
<Text language="en"><![CDATA[Delete waypoints]]></Text>
Expand Down
21 changes: 18 additions & 3 deletions scripts/Course.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1813,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
12 changes: 12 additions & 0 deletions scripts/ai/parameters/AIParameterSettingList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 58 additions & 1 deletion scripts/editor/CourseEditor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ 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)
end
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.
Expand All @@ -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)
Expand Down Expand Up @@ -99,6 +137,7 @@ function CourseEditor:deactivate()
self.file = nil
self.field = nil
self.courseWrapper = nil
self.needsMultiToolDialog = false
end


Expand Down Expand Up @@ -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()
1 change: 1 addition & 0 deletions translations/translation_br.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ A rota é salva automaticamente ao fechar o editor e substituir a rota seleciona
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editor de rota"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Excluir waypoints"/>
<text name="CP_editor_delete_primary_text" text="primário"/>
<text name="CP_editor_delete_secondary_text" text="secundário"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_cs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="任务线路编辑"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="删除路线"/>
<text name="CP_editor_delete_primary_text" text="主要路线"/>
<text name="CP_editor_delete_secondary_text" text="次要路线"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_ct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="任務編輯器"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="刪除航點"/>
<text name="CP_editor_delete_primary_text" text="主要"/>
<text name="CP_editor_delete_secondary_text" text="次要"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_cz.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Trasa se automaticky uloží při zavření editoru a přepíše vybranou trasu.
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editor tras"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Vymazat body"/>
<text name="CP_editor_delete_primary_text" text="Primární"/>
<text name="CP_editor_delete_secondary_text" text="Sekundární"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_da.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Ruten gemmes automatisk ved lukning af editoren og tilsidesætter den valgte rut
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Rute editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Slet vejpunkter"/>
<text name="CP_editor_delete_primary_text" text="primær"/>
<text name="CP_editor_delete_secondary_text" text="sekundær"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Der Kurs wird beim Schließen automatisch gespeichert und überschrieben.
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Kurseditor"/>
<text name="CP_editor_change_lane_offset" text="Ausgewählten Bahnenversatz(%s) ändern"/>
<text name="CP_editor_delete_title" text="Wegpunkte löschen"/>
<text name="CP_editor_delete_primary_text" text="Löscht den ausgewählten Wegpunkt."/>
<text name="CP_editor_delete_secondary_text" text="Löscht Wegpunkte, über die die Maus gezogen wird."/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_ea.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="Deletes the selected waypoint."/>
<text name="CP_editor_delete_secondary_text" text="Continues deletion of hovered waypoints."/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ El curso se guarda automáticamente al cerrar el editor y anula el curso selecci
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editor de Cursos"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Borrar puntos de ruta"/>
<text name="CP_editor_delete_primary_text" text="primario"/>
<text name="CP_editor_delete_secondary_text" text="secundario"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_fc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_fi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ La course est automatiquement sauvegardée à la fermeture de l'éditeur et remp
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editeur de course"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Supprimer les points"/>
<text name="CP_editor_delete_primary_text" text="principal"/>
<text name="CP_editor_delete_secondary_text" text="secondaire"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_hu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Az útvonal automatikusan mentésre kerül a szerkesztő bezárásakor és felü
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Útvonal szerkesztő"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Csomópontok törlése"/>
<text name="CP_editor_delete_primary_text" text="Kijelölt pont törlése"/>
<text name="CP_editor_delete_secondary_text" text="Kijelölt pont törlése"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Il percorso viene salvato automaticamente alla chiusura dell'editor e sovrascriv
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editor percorsi"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Cancella punto di passaggio"/>
<text name="CP_editor_delete_primary_text" text="primario"/>
<text name="CP_editor_delete_secondary_text" text="secondario"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_jp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_kr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_nl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_no.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Kurs jest automatycznie zapisywany po zamknięciu edytora i nadpisuje wybrany ku
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Edytor kursu"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Usuń punkt trasy"/>
<text name="CP_editor_delete_primary_text" text="główny"/>
<text name="CP_editor_delete_secondary_text" text="dodatkowy"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_pt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ A rota é guardada automaticamente ao fechar o editor e sobrepõe-se a qualquer
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Editor de Rota"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Apagar pontos"/>
<text name="CP_editor_delete_primary_text" text="primário"/>
<text name="CP_editor_delete_secondary_text" text="secundário"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_ro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ The course is saved automatically on closing of the editor and overrides the sel
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Course editor"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Delete waypoints"/>
<text name="CP_editor_delete_primary_text" text="primary"/>
<text name="CP_editor_delete_secondary_text" text="secondary"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Редактор курсов"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Удалить путевую точку"/>
<text name="CP_editor_delete_primary_text" text="Удаляет выбранную путевую точку"/>
<text name="CP_editor_delete_secondary_text" text="Продолжает удаление близлежащих ПТ"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_sv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Banan sparas automatiskt vid stängning av editorn och åsidosätter den valda b
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Kursredaktör"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Ta bort vägpunkt"/>
<text name="CP_editor_delete_primary_text" text="primär"/>
<text name="CP_editor_delete_secondary_text" text="sekundär"/>
Expand Down
1 change: 1 addition & 0 deletions translations/translation_tr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Editör kapatıldığında kurs otomatik olarak kaydedilir ve seçilen kursu ge
<!--Course editor-->
<!---->
<text name="CP_editor_course_title" text="Kurs editörü"/>
<text name="CP_editor_change_lane_offset" text="Change selected lane offset(%s)"/>
<text name="CP_editor_delete_title" text="Yol noktalarını sil"/>
<text name="CP_editor_delete_primary_text" text="birincil"/>
<text name="CP_editor_delete_secondary_text" text="ikincil"/>
Expand Down