Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Diff fixes
Browse files Browse the repository at this point in the history
- Partly fixes #7312
- Setting for course draw mode
- Diff MP fixes
  • Loading branch information
schwiti6190 committed Jun 28, 2021
1 parent b2e13b5 commit 1119f45
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 97 deletions.
2 changes: 1 addition & 1 deletion AIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ end
--- without restarting the game.
function AIDriver:onDraw()
if CpManager.isDeveloper and self.course and
(self.vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_DBGONLY or self.vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH) then
self.settings.courseDrawMode:isCourseVisible() then
self.course:draw()
end
if CpManager.isDeveloper and self.pathfinder then
Expand Down
87 changes: 87 additions & 0 deletions Events/FloatSettingEvent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
FloatSettingEvent = {};
FloatSettingEvent.TYPE_SETTING = 0
FloatSettingEvent.TYPE_GLOBAL = 1
FloatSettingEvent.TYPE_COURSEGENERATOR = 2
local FloatSettingEvent_mt = Class(FloatSettingEvent, Event);

InitEventClass(FloatSettingEvent, "FloatSettingEvent");

function FloatSettingEvent:emptyNew()
local self = Event:new(FloatSettingEvent_mt);
self.className = "FloatSettingEvent";
return self;
end

function FloatSettingEvent:new(vehicle,parentName, name, value)
courseplay:debug(string.format("FloatSettingEvent:new(%s, %s, %s, %s)",nameNum(vehicle), tostring(name),tostring(parentName), tostring(value)), courseplay.DBG_MULTIPLAYER)
self.vehicle = nil
self.vehicle = vehicle;
self.parentName = parentName
self.name = name
self.value = value;
return self;
end

function FloatSettingEvent:readStream(streamId, connection) -- wird aufgerufen wenn mich ein Event erreicht
if streamReadBool(streamId) then
courseplay:debug("vehicle specific Setting",courseplay.DBG_MULTIPLAYER)
self.vehicle = NetworkUtil.getObject(streamReadInt32(streamId))
else
courseplay:debug("global Setting",courseplay.DBG_MULTIPLAYER)
self.vehicle = nil
end
self.parentName = streamReadString(streamId)
self.name = streamReadString(streamId)
self.value = streamReadFloat32(streamId)

courseplay:debug("FloatSettingEvent:readStream()",courseplay.DBG_MULTIPLAYER)
courseplay:debug(('vehicle:%s, parentName:%s, name:%s, value:%s'):format(nameNum(self.vehicle),tostring(self.parentName), tostring(self.name), tostring(self.value)), courseplay.DBG_MULTIPLAYER);

self:run(connection);
end

function FloatSettingEvent:writeStream(streamId, connection) -- Wird aufgrufen wenn ich ein event verschicke (merke: reihenfolge der Daten muss mit der bei readStream uebereinstimmen
courseplay:debug("FloatSettingEvent:writeStream()",courseplay.DBG_MULTIPLAYER)
courseplay:debug(('vehicle:%s, parentName:%s, name:%s, value:%s'):format(nameNum(self.vehicle),tostring(self.parentName), tostring(self.name), tostring(self.value)), courseplay.DBG_MULTIPLAYER);
if self.vehicle ~= nil then
courseplay:debug("vehicle specific Setting",courseplay.DBG_MULTIPLAYER)
streamWriteBool(streamId, true)
streamWriteInt32(streamId, NetworkUtil.getObjectId(self.vehicle))
else
courseplay:debug("global Setting",courseplay.DBG_MULTIPLAYER)
streamWriteBool(streamId, false)
end
streamWriteString(streamId, self.parentName)
streamWriteString(streamId, self.name)
streamWriteFloat32(streamId, self.value)
end

function FloatSettingEvent:run(connection) -- wir fuehren das empfangene event aus
courseplay:debug("FloatSettingEvent:run()",courseplay.DBG_MULTIPLAYER)
courseplay:debug(('vehicle:%s, parentName:%s, name:%s, value:%s'):format(nameNum(self.vehicle),tostring(self.parentName), tostring(self.name), tostring(self.value)), courseplay.DBG_MULTIPLAYER);

if self.vehicle then
courseplay:debug("vehicle specific Setting",courseplay.DBG_MULTIPLAYER)
self.vehicle.cp[self.parentName][self.name]:setFromNetwork(self.value)
else
courseplay:debug("global Setting",courseplay.DBG_MULTIPLAYER)
courseplay[self.parentName][self.name]:setFromNetwork(self.value)
end
if not connection:getIsServer() then
courseplay:debug("broadcast FloatSettingEvent",courseplay.DBG_MULTIPLAYER)
g_server:broadcastEvent(FloatSettingEvent:new(self.vehicle,self.parentName, self.name, self.value), nil, connection, self.vehicle);
end;
end

function FloatSettingEvent.sendEvent(vehicle,parentName, name, value)
if g_server ~= nil then
courseplay:debug("broadcast FloatSettingEvent", courseplay.DBG_MULTIPLAYER)
courseplay:debug(('vehicle:%s, parentName:%s, name:%s, value:%s'):format(nameNum(vehicle), tostring(parentName), tostring(name), tostring(value)), courseplay.DBG_MULTIPLAYER);
g_server:broadcastEvent(FloatSettingEvent:new(vehicle,parentName, name, value), nil, nil, vehicle);
else
courseplay:debug("send FloatSettingEvent", courseplay.DBG_MULTIPLAYER)
courseplay:debug(('vehicle:%s, parentName:%s, name:%s, value:%s'):format(nameNum(vehicle), tostring(parentName),tostring(name), tostring(value)), courseplay.DBG_MULTIPLAYER);
g_client:getServerConnection():sendEvent(FloatSettingEvent:new(vehicle,parentName, name, value));
end;
end

5 changes: 5 additions & 0 deletions FieldworkAIDriver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ function FieldworkAIDriver:stop(msgReference)
AIDriver.stop(self, msgReference)
end

function FieldworkAIDriver:setWorkFinished(msgReference)
self:stopWork()
AIDriver.setWorkFinished(self, msgReference)
end

function FieldworkAIDriver:writeUpdateStream(streamId, connection, dirtyMask)
if self.vehicle.cp.settings.convoyActive:is(true) then
streamWriteInt32(streamId,self.convoyCurrentDistance)
Expand Down
31 changes: 13 additions & 18 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,25 +268,24 @@ function courseplay:onLoad(savegame)

self.cp.mouseCursorActive = false;

-- 2D course
self.cp.drawCourseMode = courseplay.COURSE_2D_DISPLAY_OFF;

-- 2D pda map background -- TODO: MP?
if g_currentMission.hud.ingameMap and g_currentMission.hud.ingameMap.mapOverlay and g_currentMission.hud.ingameMap.mapOverlay.filename then
self.cp.course2dPdaMapOverlay = Overlay:new(g_currentMission.hud.ingameMap.mapOverlay.filename, 0, 0, 1, 1);
self.cp.course2dPdaMapOverlay:setColor(1, 1, 1, CpManager.course2dPdaMapOpacity);
end;

-- HUD
courseplay.hud:setupVehicleHud(self);

courseplay:validateCanSwitchMode(self);

---@type SettingsContainer
self.cp.settings = SettingsContainer.createVehicleSpecificSettings(self)

---@type SettingsContainer
self.cp.courseGeneratorSettings = SettingsContainer.createCourseGeneratorSettings(self)

-- HUD
courseplay.hud:setupVehicleHud(self);

courseplay:validateCanSwitchMode(self);

courseplay.signs:updateWaypointSigns(self);

courseplay:setAIDriver(self, self.cp.mode)
Expand Down Expand Up @@ -371,8 +370,7 @@ function courseplay:onDraw()
if not status then
self.cp.hudBroken = true
end

if self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_2DONLY or self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH then
if self.cp.settings.courseDrawMode:isCourseMapVisible() then
courseplay:drawCourse2D(self, false);
end;
end; --END draw()
Expand Down Expand Up @@ -507,7 +505,7 @@ function courseplay:onUpdate(dt)
end


if self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_DBGONLY or self.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH then
if self.cp.settings.courseDrawMode:isCourseVisible() then
courseplay:drawWaypointsLines(self);
end;

Expand Down Expand Up @@ -793,8 +791,7 @@ function courseplay:onReadStream(streamId, connection)
end

--Make sure every vehicle has same AIDriver as the Server
courseplay:setAIDriver(self, self.cp.mode)

courseplay:setCpMode(self, self.cp.mode)

self.cp.driver:onReadStream(streamId)

Expand Down Expand Up @@ -864,11 +861,10 @@ end

function courseplay:onReadUpdateStream(streamId, timestamp, connection)
if connection:getIsServer() then
if self.cp.driver ~= nil then
self.cp.driver:readUpdateStream(streamId, timestamp, connection)
end
--only sync while cp is drivin!
if streamReadBool(streamId) then
self.cp.driver:readUpdateStream(streamId, timestamp, connection)

if streamReadBool(streamId) then
self.cp.waypointIndex = streamReadInt32(streamId)
else
Expand Down Expand Up @@ -902,10 +898,9 @@ end

function courseplay:onWriteUpdateStream(streamId, connection, dirtyMask)
if not connection:getIsServer() then
if self.cp.driver ~= nil then
self.cp.driver:writeUpdateStream(streamId, connection, dirtyMask)
end
if streamWriteBool(streamId, self:getIsCourseplayDriving() or false) then
self.cp.driver:writeUpdateStream(streamId, connection, dirtyMask)

if self.cp.waypointIndex then
streamWriteBool(streamId,true)
streamWriteInt32(streamId,self.cp.waypointIndex)
Expand Down
2 changes: 1 addition & 1 deletion course-generator/CourseGeneratorSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function WorkWidthSetting:setToDefault(noEventSend)
end

function WorkWidthSetting:set(value, noEventSend)
self.value:set(value, noEventSend)
self.value:set(value, true)
if not noEventSend then
self:sendEvent()
end
Expand Down
41 changes: 19 additions & 22 deletions courseplay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ local function initialize()
'Events/SiloSelectedFillTypeEvent',
'Events/StartStopWorkEvent',
'Events/SettingsListEvent',
'Events/FloatSettingEvent',
'Events/GlobalSettingsEvent',
'Events/AssignedCombinesEvents',
'Events/CourseEvent',
Expand Down Expand Up @@ -222,11 +223,7 @@ local function setGlobalData()
courseplay.lights.HEADLIGHT_STREET = 1;
courseplay.lights.HEADLIGHT_FULL = 7;

-- 2D/debug lines display options
courseplay.COURSE_2D_DISPLAY_OFF = 0;
courseplay.COURSE_2D_DISPLAY_2DONLY = 1;
courseplay.COURSE_2D_DISPLAY_DBGONLY = 2;
courseplay.COURSE_2D_DISPLAY_BOTH = 3;


-- number separators
local langNumData = {
Expand Down Expand Up @@ -259,23 +256,23 @@ local function setGlobalData()
[1]={name='self.cp.mode',dataFormat='Int'},
[2]={name='self.cp.turnDiameterAuto',dataFormat='Float'},
[3]={name='self.cp.canDrive',dataFormat='Bool'},
[6]={name='self.cp.drivingDirReverse',dataFormat='Bool'},
[7]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'},
[8]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'},
[9]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'},
[10]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'},
[11]={name='self.cp.globalInfoTextLevel',dataFormat='Int'},
[15]={name='self.cp.isDriving',dataFormat='Bool'},
[26]={name='self.cp.hud.openWithMouse',dataFormat='Bool'},
[29]={name='self.cp.workWidth',dataFormat='Float'},
[20]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'},
[21]={name='self.cp.turnDiameter',dataFormat='Float'},
[22]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --??
[23]={name='self.cp.laneOffset',dataFormat='Float'},
[36]={name='self.cp.hud.currentPage',dataFormat='Int'},
[37]={name='self.cp.waypointIndex',dataFormat='Int'},
[38]={name='self.cp.isRecording',dataFormat='Bool'},
[39]={name='self.cp.recordingIsPaused',dataFormat='Bool'},
[4]={name='self.cp.drivingDirReverse',dataFormat='Bool'},
[5]={name='self.cp.fieldEdge.customField.isCreated',dataFormat='Bool'},
[6]={name='self.cp.fieldEdge.customField.fieldNum',dataFormat='Int'},
[7]={name='self.cp.fieldEdge.customField.selectedFieldNumExists',dataFormat='Bool'},
[8]={name='self.cp.fieldEdge.selectedField.fieldNum',dataFormat='Int'},
[9]={name='self.cp.globalInfoTextLevel',dataFormat='Int'},
[10]={name='self.cp.isDriving',dataFormat='Bool'},
[11]={name='self.cp.hud.openWithMouse',dataFormat='Bool'},
[12]={name='self.cp.workWidth',dataFormat='Float'},
[13]={name='self.cp.turnDiameterAutoMode',dataFormat='Bool'},
[14]={name='self.cp.turnDiameter',dataFormat='Float'},
[15]={name='self.cp.coursePlayerNum',dataFormat='Int'}, --??
[16]={name='self.cp.laneOffset',dataFormat='Float'},
[17]={name='self.cp.hud.currentPage',dataFormat='Int'},
[18]={name='self.cp.waypointIndex',dataFormat='Int'},
[19]={name='self.cp.isRecording',dataFormat='Bool'},
[20]={name='self.cp.recordingIsPaused',dataFormat='Bool'},
}

courseplay.globalSettings = SettingsContainer.createGlobalSettings()
Expand Down
24 changes: 24 additions & 0 deletions debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,3 +908,27 @@ function cpDebug:deleteDrawItem(itemNode)
unlink(itemNode);
delete(itemNode);
end


function executeExternFunction(self,superFunc,...)

local errorHandler = function(err)
printCallstack()
return err
end

local status, result = xpcall(superFunc,errorHandler,self,...)

if not status then
print('NetworkUtil : '.. tostring(result))
else
return result
end
end

for i,func in pairs(NetworkUtil) do
if type(func) == "function" then
print(string.format("Add listener to: NetworkUtil = i: %s, func: %s",tostring(i),tostring(func)))
NetworkUtil[i] = Utils.overwrittenFunction(NetworkUtil[i],executeExternFunction)
end
end
25 changes: 9 additions & 16 deletions hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,10 @@ function courseplay.hud:renderHud(vehicle)
vehicle.cp.hud.crossingPointsIcon:render();
end;


local courseDrawModeSetting = vehicle.cp.settings.courseDrawMode
-- 2D/DEBUG LINE BUTTON MODE
if vehicle.cp.drawCourseMode ~= courseplay.COURSE_2D_DISPLAY_OFF then
local txt;
if vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_2DONLY then
txt = '2D';
elseif vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_DBGONLY then
txt = '\nDBG';
else
txt = '2D\nDBG';
end;
if not courseDrawModeSetting:isDeactivated() then
local txt = courseDrawModeSetting:getText()
courseplay:setFontSettings('white', true);
renderText(vehicle.cp.hud.changeDrawCourseModeButton.x + vehicle.cp.hud.changeDrawCourseModeButton.width * 0.5, self.topIconsY + self.fontSizes.version * 1.25, self.fontSizes.version, txt);
courseplay:setFontSettings('white', false);
Expand Down Expand Up @@ -894,11 +887,11 @@ function courseplay.hud:updatePageContent(vehicle, page)
else
vehicle.cp.hud.content.pages[page][line][2].text = '---';
end;
elseif entry.functionToCall == 'changeToolOffsetX' then
elseif entry.functionToCall == 'toolOffsetX:setFromHud' then
--Tool horizontal offset
vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.toolOffsetX:getLabel()
vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.settings.toolOffsetX:getText()
elseif entry.functionToCall == 'changeToolOffsetZ' then
elseif entry.functionToCall == 'toolOffsetZ:setFromHud' then
--Tool vertical offset
vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.toolOffsetZ:getLabel()
vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.settings.toolOffsetZ:getText()
Expand Down Expand Up @@ -1215,7 +1208,7 @@ function courseplay.hud:updatePageContent(vehicle, page)
else
self:showShowWaypointsButtons(vehicle, false)
end

vehicle.cp.hud.changeDrawCourseModeButton:setActive(not vehicle.cp.settings.courseDrawMode:isDeactivated())
-- make sure AutoDrive mode has all options currently available for the vehicle
vehicle.cp.settings.autoDriveMode:update()
self:setReloadPageOrder(vehicle, page, forceUpdate);
Expand Down Expand Up @@ -1376,7 +1369,7 @@ function courseplay.hud:setupVehicleHud(vehicle)

vehicle.cp.hud.saveCourseButton = courseplay.button:new(vehicle, 'global', { 'iconSprite.png', 'save' }, 'showSaveCourseForm', 'course', topIconsX[3], self.topIconsY, wMiddle, hMiddle, nil, nil, false, false, false, courseplay:loc('COURSEPLAY_SAVE_CURRENT_COURSE'));
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);
vehicle.cp.hud.changeDrawCourseModeButton = courseplay.button:new(vehicle, 'global', { 'iconSprite.png', 'eye' }, 'setFromHud', 1, self.col1posX, self.topIconsY, wMiddle, hMiddle, nil, -1, false, false, true):setSetting(vehicle.cp.settings.courseDrawMode)
self:setupCpModeButtons(vehicle)
self:setupRecordingButtons(vehicle)
self:setupCoursePageButtons(vehicle,2)
Expand Down Expand Up @@ -2132,9 +2125,9 @@ function courseplay.hud:setFieldWorkAIDriverContent(vehicle)
self:addRowButton(vehicle,vehicle.cp.settings.symmetricLaneChange,'toggle', 8, 2, 1 )
self:addRowButton(vehicle,vehicle.cp.settings.turnOnField,'toggle', 8, 3, 1 )
self:addRowButton(vehicle,vehicle.cp.settings.useRealisticDriving,'toggle', 8, 4, 1 )
self:addSettingsRowWithArrows(vehicle,nil,'changeToolOffsetX', 8, 5, 1 )
self:addSettingsRowWithArrows(vehicle,vehicle.cp.settings.toolOffsetX,'setFromHud', 8, 5, 1 )
self:setupSetAutoToolOffsetXButton(vehicle,8,5)
self:addSettingsRowWithArrows(vehicle,nil,'changeToolOffsetZ', 8, 6, 1 )
self:addSettingsRowWithArrows(vehicle,vehicle.cp.settings.toolOffsetZ,'setFromHud', 8, 6, 1 )
self:addRowButton(vehicle,vehicle.cp.settings.oppositeTurnMode,'toggle', 8, 7, 1 )

self:setReloadPageOrder(vehicle, -1, true)
Expand Down
2 changes: 1 addition & 1 deletion input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)

-- ##################################################
-- 2D COURSE WINDOW: DRAG + DROP MOVE
if vehicle.cp.course2dDrawData and (vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_2DONLY or vehicle.cp.drawCourseMode == courseplay.COURSE_2D_DISPLAY_BOTH) then
if vehicle.cp.course2dDrawData and vehicle.cp.settings.courseDrawMode:isCourseVisible() then
local plot = CpManager.course2dPlotField;
if isDown and mouseButton == courseplay.inputBindings.mouse.primaryButtonId and vehicle.cp.mouseCursorActive and vehicle:getIsEntered() and courseplay:mouseIsInArea(posX, posY, plot.x, plot.x + plot.width, plot.y, plot.y + plot.height) then
CpManager.course2dDragDropMouseDown = { posX, posY };
Expand Down
Loading

0 comments on commit 1119f45

Please sign in to comment.