Skip to content

Commit

Permalink
update: add first version for additional mode values
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGaertner committed Apr 1, 2019
1 parent 2559384 commit 5907b13
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 25 deletions.
5 changes: 5 additions & 0 deletions GrainTransportAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function GrainTransportAIDriver:init(vehicle)
self.vehicle.cp.runCounter = self.runCounter
end

function GrainTransportAIDriver:setHudContent()
AIDriver.setHudContent(self)
courseplay.hud:setGrainTransportAIDriverContent(self.vehicle)
end

function GrainTransportAIDriver:start(ix)
self.vehicle:setCruiseControlMaxSpeed(self.vehicle:getSpeedLimit() or math.huge)
self:beforeStart()
Expand Down
87 changes: 66 additions & 21 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,18 @@ function courseplay.hud:setContent(vehicle)
self:showCpModeButtons(vehicle, false)
vehicle.cp.hud.saveCourseButton:setShow(false)
vehicle.cp.hud.clearCurrentCourseButton:setShow(false)
self:deleteAllTexts(vehicle,vehicle.cp.hud.currentPage)
self:updatePageContent(vehicle, vehicle.cp.hud.currentPage);
end;
end; --END setHudContent()

function courseplay.hud:deleteAllTexts(vehicle,page)
for line=1,self.numLines do
for column=1,3 do
vehicle.cp.hud.content.pages[page][line][column].text = nil;
end;
end;
end

function courseplay.hud:renderHud(vehicle)
-- self = courseplay.hud
Expand Down Expand Up @@ -716,8 +724,22 @@ function courseplay.hud:updatePageContent(vehicle, page)
self:disableButtonWithFunction(vehicle,page, 'changeStartAtPoint')
end
elseif entry.functionToCall == 'setStopAtEnd' then
vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_STOP_AT_LAST_POINT');
vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.stopAtEnd and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED');
if vehicle.cp.canDrive then
vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_STOP_AT_LAST_POINT');
vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.stopAtEnd and courseplay:loc('COURSEPLAY_ACTIVATED') or courseplay:loc('COURSEPLAY_DEACTIVATED');
end
elseif entry.functionToCall == 'toggleAutomaticCoverHandling' then
vehicle.cp.hud.content.pages[page][line][1].text = courseplay:loc('COURSEPLAY_COVER_HANDLING');
vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.automaticCoverHandling and courseplay:loc('COURSEPLAY_AUTOMATIC') or courseplay:loc('COURSEPLAY_DEACTIVATED');











elseif entry.functionToCall == 'changeTurnSpeed' then
Expand Down Expand Up @@ -759,9 +781,9 @@ function courseplay.hud:updatePageContent(vehicle, page)
self:updateCourseList(vehicle, 2)
vehicle.cp.hud.filterButton:setShow(not vehicle.cp.hud.choose_parent);
vehicle.cp.hud.reloadCourses:setShow(g_server ~= nil and not vehicle.cp.canDrive and not g_currentMission.missionDynamicInfo.isMultiplayer);
vehicle.cp.hud.newFolderButton:setShow(true)
vehicle.cp.hud.newFolderButton:setShow(not vehicle.cp.isDriving)
self:showShiftHudButtons(vehicle, true)
self:setCourseButtonsVisibilty(vehicle)
self:updateCourseButtonsVisibilty(vehicle)

else
self:showShiftHudButtons(vehicle, false)
Expand Down Expand Up @@ -1619,7 +1641,7 @@ function courseplay.hud:setupVehicleHud(vehicle)
vehicle.cp.hud.clearCurrentCourseButton = courseplay.button:new(vehicle, 'global', { 'iconSprite.png', 'courseClear' }, 'clearCurrentLoadedCourse', nil, topIconsX[0], self.topIconsY, wMiddle, hMiddle, nil, nil, false, false, false, courseplay:loc('COURSEPLAY_CLEAR_COURSE'));
vehicle.cp.hud.changeDrawCourseModeButton = courseplay.button:new(vehicle, 'global', { 'iconSprite.png', 'eye' }, 'changeDrawCourseMode', 1, self.col1posX, self.topIconsY, wMiddle, hMiddle, nil, -1, false, false, true);
self:setupCpModeButtons(vehicle)
self:setRecordingButtons(vehicle)
self:setupRecordingButtons(vehicle)
self:setupCoursePageButtons(vehicle,2)

-- ##################################################
Expand Down Expand Up @@ -2063,7 +2085,7 @@ function courseplay.hud:setupCpModeButtons(vehicle)
end;
end

function courseplay.hud:setDebugButtons(vehicle,debugButtonOnPage)
function courseplay.hud:setupDebugButtons(vehicle,debugButtonOnPage)
-- debug channels
if courseplay.isDevVersion then
vehicle.cp.hud.debugChannelButtons = {};
Expand All @@ -2085,7 +2107,7 @@ function courseplay.hud:setDebugButtons(vehicle,debugButtonOnPage)
end
end

function courseplay.hud:setRecordingButtons(vehicle)
function courseplay.hud:setupRecordingButtons(vehicle)
local recordingData = {
[1] = { 'recordingStop', 'stop_record', nil, 'COURSEPLAY_RECORDING_STOP' },
[2] = { 'recordingPause', 'setRecordingPause', true, 'COURSEPLAY_RECORDING_PAUSE' },
Expand Down Expand Up @@ -2173,9 +2195,9 @@ function courseplay.hud:setupCoursePageButtons(vehicle,page)
h = self.lineHeight
}
local courseListMouseWheelArea = {
x = self.contentMinX,
x = self.contentMinX+wSmall,
y = self.linesPosY[self.numLines],
width = self.buttonCoursesPosX[4] - self.contentMinX,
width = self.buttonCoursesPosX[4] - self.contentMinX-wSmall,
height = self.linesPosY[1] + self.lineHeight - self.linesPosY[self.numLines]
};
vehicle.cp.hud.courseListMouseArea= courseplay.button:new(vehicle, 'global', nil, 'shiftHudCourses', -1, courseListMouseWheelArea.x, courseListMouseWheelArea.y, courseListMouseWheelArea.width, courseListMouseWheelArea.height, nil, -self.numLines, true, true);
Expand All @@ -2202,7 +2224,7 @@ function courseplay.hud:setupCoursePageButtons(vehicle,page)
vehicle.cp.hud.courseListNextButton = courseplay.button:new(vehicle, 'global', { 'iconSprite.png', 'navDown' }, 'shiftHudCourses', self.numLines, listArrowX, self.linesButtonPosY[self.numLines], wMiddle, hMiddle, nil, self.numLines*2);
end

function courseplay.hud:setCourseButtonsVisibilty(vehicle)
function courseplay.hud:updateCourseButtonsVisibilty(vehicle)
local enable, show = true, true;
local numVisibleCourses = #(vehicle.cp.hud.courses);
local nofolders = nil == next(g_currentMission.cp_folders);
Expand Down Expand Up @@ -2267,19 +2289,22 @@ function courseplay.hud:setCourseButtonsVisibilty(vehicle)
end; -- for buttons

end

function courseplay.hud:showShiftHudButtons(vehicle, show)
local previousLine, nextLine = courseplay.settings.validateCourseListArrows(vehicle);
vehicle.cp.hud.courseListPrevButton:setShow(previousLine and show)
vehicle.cp.hud.courseListNextButton:setShow(nextLine and show)
vehicle.cp.hud.courseListMouseArea:setShow(show)
end

-- Hud content functions
function courseplay.hud:showCpModeButtons(vehicle, show)
for _,button in pairs(vehicle.cp.buttons.global) do
local fn, prm = button.functionToCall, button.parameter;
local fn, cpModeToCheck = button.functionToCall, button.parameter;
if fn == 'setCpMode'then
button:setShow(show);
button:setActive(prm == vehicle.cp.mode)
button:setActive(cpModeToCheck == vehicle.cp.mode)
button:setDisabled(not courseplay:getIsToolValidForCpMode(vehicle,cpModeToCheck))
end
end
end
Expand All @@ -2292,7 +2317,7 @@ function courseplay.hud:showRecordingButtons(vehicle, show)
end
end

function courseplay.hud:enablePageButton(vehicle,pageNumber)
function courseplay.hud:enablePageButtons(vehicle,pageNumber)
local button = vehicle.cp.hud.hudPageButtons[pageNumber];
button:setDisabled(false);
button:setCanBeClicked(not button.isDisabled);
Expand All @@ -2305,12 +2330,23 @@ function courseplay.hud:disablePageButtons(vehicle)
end;
end

function courseplay.hud:clearContent(vehicle)
function courseplay.hud:clearHudPageContent(vehicle)
for hudPage=0,self.numPages do
vehicle.cp.buttons[hudPage]= {}
self:deleteAllAssignedFunctions(vehicle,hudPage)
end
end

function courseplay.hud:deleteAllAssignedFunctions(vehicle,page)
for line=1,self.numLines do
for column=1,3 do
vehicle.cp.hud.content.pages[page][line][column].functionToCall = nil;
end;
end;
end



function courseplay.hud:enableButtonsOnThisPage(vehicle,page)
for _, button in pairs(vehicle.cp.buttons[page])do
button:setDisabled(false)
Expand Down Expand Up @@ -2344,39 +2380,48 @@ end
--call the setup for the different modes
function courseplay.hud:setAIDriverContent(vehicle)
print("setAIDriverContent")
self:clearContent(vehicle)
print("vehicle:"..tostring(vehicle))
self:clearHudPageContent(vehicle)
self:disablePageButtons(vehicle)

--page 1 driving
self:enablePageButton(vehicle,1)
self:enablePageButtons(vehicle,1)
self:addRowButton(vehicle,'startStop', 1, 1, 1 )
self:addRowButton(vehicle,'start_record', 1, 1, 2 )
self:addRowButton(vehicle,'cancelWait', 1, 2, 1 )
self:addRowButton(vehicle,'changeStartAtPoint', 1, 2, 2 )
self:addRowButton(vehicle,'setStopAtEnd', 1, 3, 1 )

--page2 courses
self:enablePageButton(vehicle,2)
self:enablePageButtons(vehicle,2)
self:updateCourseList(vehicle, 2)

--page 5 speeds
self:enablePageButton(vehicle,5)
self:enablePageButtons(vehicle,5)
self:addSettingsRow(vehicle,'changeTurnSpeed', 5, 1, 1 )
self:addSettingsRow(vehicle,'changeFieldSpeed', 5, 2, 1 )
self:addSettingsRow(vehicle,'changeMaxSpeed', 5, 3, 1 )
self:addRowButton(vehicle,'toggleUseRecordingSpeed', 5, 4, 1 )


--page 6 settings
self:enablePageButton(vehicle,6)
self:setDebugButtons(vehicle,6)
self:enablePageButtons(vehicle,6)
self:setupDebugButtons(vehicle,6)

self:setReloadPageOrder(vehicle, -1, true)
end

function courseplay.hud:setGrainTransportAIDriverContent(vehicle)
print("setGrainTransportAIDriverContent")
print("vehicle:"..tostring(vehicle))
--page 1 driving
self:addRowButton(vehicle,'toggleAutomaticCoverHandling', 1, 4, 1 )

--different buttons to set

end


--different buttons to set
function courseplay.hud:addRowButton(vehicle,funct, hudPage, line, column )
print(" addRowButton: "..tostring(funct))
local width = {
Expand Down
4 changes: 0 additions & 4 deletions input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
if buttonToHandle == nil then
for _,button in pairs(vehicle.cp.buttons.global) do
if button.show and button:getHasMouse(posX, posY) then
print(" global ")
buttonToHandle = button;
break;
end;
Expand All @@ -45,7 +44,6 @@ function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
if buttonToHandle == nil then
for _,button in pairs(vehicle.cp.buttons[vehicle.cp.hud.currentPage]) do
if button.canBeClicked and button.show and not button.isDisabled and button:getHasMouse(posX, posY) then
print(" vehicle.cp.buttons[vehicle.cp.hud.currentPage] ")
buttonToHandle = button;
break;
end;
Expand All @@ -56,7 +54,6 @@ function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
if vehicle.cp.hud.currentPage == 2 then
for _,button in pairs(vehicle.cp.buttons[-2]) do
if button.show and button:getHasMouse(posX, posY) then
print(" vehicle.cp.buttons[-2] ")
buttonToHandle = button;
break;
end;
Expand All @@ -65,7 +62,6 @@ function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
end;

if buttonToHandle then
print("on MouseEvent buttonToHandle: "..tostring(buttonToHandle.functionToCall))
buttonToHandle:setClicked(isDown);
--[[if not buttonToHandle.isDisabled and buttonToHandle.hoverText and buttonToHandle.functionToCall ~= nil then
vehicle.cp.hud.content.pages[buttonToHandle.page][buttonToHandle.row][1].isClicked = isDown;
Expand Down
5 changes: 5 additions & 0 deletions settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ end
function courseplay:toggleAutoRefuel(self)
self.cp.allwaysSearchFuel = not self.cp.allwaysSearchFuel
end

function courseplay:toggleAutomaticCoverHandling (self)
self.cp.automaticCoverHandling = not self.cp.automaticCoverHandling
end

function courseplay:toggleMode10automaticSpeed(self)
if self.cp.mode10.leveling then
self.cp.mode10.automaticSpeed = not self.cp.mode10.automaticSpeed
Expand Down
14 changes: 14 additions & 0 deletions toolManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1892,3 +1892,17 @@ function courseplay:getAIMarkerWidth(object, logPrefix)
end
end
end

function courseplay:getIsToolValidForCpMode(vehicle,cpModeToCheck)
if cpModeToCheck == 5 then
return true;
elseif vehicle.cp.workToolAttached then
if cpModeToCheck == 1
or cpModeToCheck == 4
or cpModeToCheck == 6
or cpModeToCheck == 9
or cpModeToCheck == 10 then
return true;
end
end
end

0 comments on commit 5907b13

Please sign in to comment.