Skip to content

Commit

Permalink
Copy course is now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Apr 3, 2022
1 parent 6bc8ee0 commit 156a15c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scripts/gui/hud/CpBaseHud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ function CpBaseHud:addCopyCourseBtn(line)
--- Copy course btn.
self.copyCourseElements = {}
self.copyCourseIx = 1
self.courseVehicles = {}
local leftX, leftY = unpack(self.lines[line].left)
local rightX, rightY = unpack(self.lines[line].right)
local btnYOffset = self.hMargin*0.2
Expand Down Expand Up @@ -382,7 +383,10 @@ function CpBaseHud:addCopyCourseBtn(line)
self.copyCourseElements.copyBtn = CpHudButtonElement.new(copyOverlay, self.baseHud)
self.copyCourseElements.copyBtn:setPosition(rightX, rightY-btnYOffset)
self.copyCourseElements.copyBtn:setCallback("onClickPrimary", self.vehicle, function (vehicle)
--- TODO: add course copy logic here!
local v = self.courseVehicles[self.copyCourseIx]
if v then
self.vehicle:cpCopyCourse(v)
end
end)
self.copyCourseElements.copyBtn:setCallback("onHoveredChanged", self.vehicle, function (vehicle)
--- TODO: Maybe change the vehicle name to the course name, while hovered.
Expand Down
9 changes: 9 additions & 0 deletions scripts/specializations/CpCourseManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function CpCourseManager.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, 'addCpCourse', CpCourseManager.addCourse)
SpecializationUtil.registerFunction(vehicleType, 'getCpCourses', CpCourseManager.getCourses)
SpecializationUtil.registerFunction(vehicleType, 'hasCpCourse', CpCourseManager.hasCourse)
SpecializationUtil.registerFunction(vehicleType, 'cpCopyCourse', CpCourseManager.cpCopyCourse)

SpecializationUtil.registerFunction(vehicleType, 'appendLoadedCpCourse', CpCourseManager.appendLoadedCourse)
SpecializationUtil.registerFunction(vehicleType, 'saveCpCourses', CpCourseManager.saveCourses)
Expand Down Expand Up @@ -190,6 +191,14 @@ function CpCourseManager:setFieldWorkCourse(course)
course:setVehicle(self)
end

--- Copy the fieldwork course from another vehicle.
function CpCourseManager:cpCopyCourse(vehicle)
if vehicle:hasCpCourse() then
local course = vehicle:getFieldWorkCourse()
self:setFieldWorkCourse(course)
end
end

function CpCourseManager:setCoursesFromNetworkEvent(courses)
CpCourseManager.resetCourses(self)
CpCourseManager.addCourse(self,courses[1],true)
Expand Down

0 comments on commit 156a15c

Please sign in to comment.