diff --git a/ActionEventsLoader.lua b/ActionEventsLoader.lua
new file mode 100644
index 000000000..06d5d1721
--- /dev/null
+++ b/ActionEventsLoader.lua
@@ -0,0 +1,446 @@
+---@class ActionEventsLoader
+ActionEventsLoader = CpObject()
+
+---All the normal action events attributes
+ActionEventsLoader.actionEventAttributes = {
+ {name = 'name', getXmlFunction = getXMLString},
+ {name = 'class', getXmlFunction = getXMLString},
+ {name = 'callbackFunc', getXmlFunction = getXMLString},
+ {name = 'callbackParameter', getXmlFunction = getXMLString},
+ {name = 'callbackState', getXmlFunction = getXMLInt},
+ {name = 'isDisabledCallbackFunc', getXmlFunction = getXMLString},
+ {name = 'text', getXmlFunction = getXMLString},
+}
+
+---All the setting action events attributes
+ActionEventsLoader.settingActionEventAttributes = {
+ {name = 'name', getXmlFunction = getXMLString},
+ {name = 'setting', getXmlFunction = getXMLString},
+ {name = 'callbackFunc', getXmlFunction = getXMLString},
+ {name = 'callbackParameter', getXmlFunction = getXMLString},
+ {name = 'callbackState', getXmlFunction = getXMLInt},
+ {name = 'isDisabledCallbackFunc', getXmlFunction = getXMLString},
+ {name = 'text', getXmlFunction = getXMLString},
+}
+
+---String to class reference, only for global classes.
+ActionEventsLoader.classStringToClass = {
+ ["courseEditor"] = courseEditor
+}
+---Table where the global action events gets saved in.
+ActionEventsLoader.globalActionEventNameToID = {}
+
+---Every action event name translation text needs "input_"
+---at the beginning. With this it's possible
+---to get the action event text: courseplay:loc(textPrefix..actionEventName)
+ActionEventsLoader.textPrefix = "input_"
+
+function ActionEventsLoader:init()
+ self.actionEvents = {}
+ self.settingActionEvents = {}
+ self.globalActionEvents = {}
+ if g_currentMission then
+ self:loadFromXml()
+ end
+end
+
+function ActionEventsLoader:loadFromXml()
+ self.xmlFileName = Utils.getFilename('config/ActionEventsConfig.xml', courseplay.path)
+ self.xmlFile = self:loadXmlFile(self.xmlFileName)
+end
+
+---Loads ActionEventsConfig file
+---@param string file path
+function ActionEventsLoader:loadXmlFile(fileName)
+ courseplay.info('Loading action events configuration from %s ...', fileName)
+ if fileExists(fileName) then
+ local xmlFile = loadXMLFile('actionEventsConfig', fileName)
+ local rootElement = 'ActionEventsConfig'
+ if xmlFile and hasXMLProperty(xmlFile, rootElement) then
+ local baseElement = string.format('%s.%s', rootElement,'ActionEvents')
+ self:loadActionEvents(xmlFile, baseElement,'ActionEvent',self.actionEventAttributes,self.actionEvents)
+ baseElement = string.format('%s.%s', rootElement,'SettingActionEvents')
+ self:loadActionEvents(xmlFile, baseElement,'SettingActionEvent',self.settingActionEventAttributes,self.settingActionEvents)
+ baseElement = string.format('%s.%s', rootElement,'GlobalActionEvents')
+ self:loadActionEvents(xmlFile, baseElement,'GlobalActionEvent',self.actionEventAttributes,self.globalActionEvents)
+ return xmlFile
+ end
+ else
+ courseplay.info('Action events configuration file %s does not exist.', fileName)
+ end
+end
+
+---Loads an action events table from ActionEventsConfig.xml
+---@param int xmlFile id
+---@param string rootElement of the action event table
+---@param string key for each single action event
+---@param table attributes of the action event table
+---@param table actionEventTable to store the data in
+function ActionEventsLoader:loadActionEvents(xmlFile, rootElement,key,attributes,actionEventTable)
+ if hasXMLProperty(xmlFile, rootElement) then
+ local i = 0
+ while true do
+ local baseElement = string.format('%s.%s(%d)', rootElement,key, i)
+ if hasXMLProperty(xmlFile, baseElement) then
+ self:loadAttributes(xmlFile, baseElement,attributes,actionEventTable)
+ else
+ break
+ end
+ i = i + 1
+ end
+ end
+end
+
+---Loads all attribute of an action event
+---@param int xmlFile id
+---@param string rootElement of the attributes
+---@param table attributes of the action event table
+---@param table actionEventTable to store the data in
+function ActionEventsLoader:loadAttributes(xmlFile, rootElement,attributes,actionEventTable)
+ local attributesTable = {}
+ for _,attributeData in ipairs(attributes) do
+ attributesTable[attributeData.name] = attributeData.getXmlFunction(xmlFile, rootElement.."#"..attributeData.name)
+ end
+ table.insert(actionEventTable,attributesTable)
+end
+
+---Gets all simple action events
+function ActionEventsLoader:getActionEvents()
+ return self.actionEvents
+end
+
+---Gets all setting action events
+function ActionEventsLoader:getSettingActionEvents()
+ return self.settingActionEvents
+end
+
+---Gets all setting action events
+function ActionEventsLoader:getGlobalActionEvents()
+ return self.globalActionEvents
+end
+
+---Registers all action events
+---@param object vehicle
+---@param boolean isActiveForInput
+---@param boolean isActiveForInputIgnoreSelection
+function ActionEventsLoader.onRegisterVehicleActionEvents(vehicle,isActiveForInput, isActiveForInputIgnoreSelection)
+ if vehicle.isClient then
+ ---Table where the action events gets saved in the vehicle.
+ if vehicle.cpActionEvents == nil then
+ vehicle.cpActionEvents = {}
+ else
+ vehicle:clearActionEventsTable(vehicle.cpActionEvents)
+ end
+ if vehicle:getIsActiveForInput(true, true) then
+ ---Register all vehicle action events
+ ActionEventsLoader.registerVehicleActionEvents(vehicle,isActiveForInput, isActiveForInputIgnoreSelection)
+ ActionEventsLoader.registerVehicleSettingActionEvents(vehicle,isActiveForInput, isActiveForInputIgnoreSelection)
+ end
+ end
+end
+
+---Registers all none setting vehicle action events
+---@param object vehicle
+---@param boolean isActiveForInput
+---@param boolean isActiveForInputIgnoreSelection
+function ActionEventsLoader.registerVehicleActionEvents(vehicle,isActiveForInput, isActiveForInputIgnoreSelection)
+ local actionEvents = g_ActionEventsLoader:getActionEvents()
+ for _,actionEventData in ipairs(actionEvents) do
+ ActionEventsLoader.registerActionEvent(actionEventData,vehicle,false)
+ end
+end
+
+---Registers all setting vehicle action events
+---@param object vehicle
+---@param boolean isActiveForInput
+---@param boolean isActiveForInputIgnoreSelection
+function ActionEventsLoader.registerVehicleSettingActionEvents(vehicle,isActiveForInput, isActiveForInputIgnoreSelection)
+ local actionEvents = g_ActionEventsLoader:getSettingActionEvents()
+ for _,actionEventData in ipairs(actionEvents) do
+ ActionEventsLoader.registerActionEvent(actionEventData,vehicle,true)
+ end
+end
+
+---Registers all global none setting action events
+function ActionEventsLoader.registerGlobalActionEvents()
+ if g_client then
+ local actionEvents = g_ActionEventsLoader:getGlobalActionEvents()
+ for _,actionEventData in ipairs(actionEvents) do
+ local actionEventName = ActionEventsLoaderUtil.getActionEventName(actionEventData)
+ local class = ActionEventsLoaderUtil.getActionEventClass(actionEventData,ActionEventCallbacks)
+ local classParameter = ActionEventsLoaderUtil.getActionEventCallbackParameter(actionEventData)
+
+ local actionEventCallback = ActionEventsLoaderUtil.getActionEventCallback(actionEventData,class)
+ local actionEventText = ActionEventsLoaderUtil.getActionEventText(actionEventData)
+
+ local isDisabled = ActionEventsLoaderUtil.getActionEventIsDisabled(actionEventData,class,classParameter)
+
+ courseplay.debugFormat(courseplay.DBG_HUD,"Register action event: name= %s, text= %s, isDisabled= %s",
+ actionEventName, courseplay:loc(actionEventText), tostring(isDisabled))
+
+ ---Registers an action event.
+ local _, eventId = g_inputBinding:registerActionEvent(actionEventName, class, actionEventCallback, false, true, false, true,actionEventData.callbackState)
+ g_inputBinding:setActionEventTextPriority(eventId, GS_PRIO_HIGH)
+ g_inputBinding:setActionEventText(eventId, courseplay:loc(actionEventText))
+ g_inputBinding:setActionEventActive(eventId, not isDisabled)
+
+
+ ActionEventsLoader.globalActionEventNameToID[actionEventName] = eventId
+ end
+ end
+end
+FSBaseMission.registerActionEvents = Utils.appendedFunction(FSBaseMission.registerActionEvents, ActionEventsLoader.registerGlobalActionEvents)
+
+---Registers an action event
+---@param table actionEventData from the config xml
+---@param object vehicle
+---@param boolean isSetting, is the action event linked to a setting class?
+function ActionEventsLoader.registerActionEvent(actionEventData,vehicle,isSetting)
+ local actionEventName = ActionEventsLoaderUtil.getActionEventName(actionEventData)
+ local class,classParameter
+ ---If the action event is a setting we get the setting by the settings name
+ if isSetting then
+ class = ActionEventsLoaderUtil.getActionEventSetting(actionEventData,vehicle)
+ classParameter = class
+ else
+ class = ActionEventsLoaderUtil.getActionEventClass(actionEventData,ActionEventCallbacks)
+ classParameter = ActionEventsLoaderUtil.getActionEventCallbackParameter(actionEventData,vehicle)
+ end
+ local actionEventCallback = ActionEventsLoaderUtil.getActionEventCallback(actionEventData,class)
+ local actionEventText = ActionEventsLoaderUtil.getActionEventText(actionEventData)
+
+ local isDisabled = ActionEventsLoaderUtil.getActionEventIsDisabled(actionEventData,class,classParameter)
+
+ courseplay.debugVehicle(courseplay.DBG_HUD,vehicle,"Register action event: name= %s, text= %s, isDisabled= %s",
+ actionEventName, courseplay:loc(actionEventText), tostring(isDisabled))
+
+ ---Registers an action event into the vehicle.
+ local _, eventId = vehicle:addActionEvent(vehicle.cpActionEvents,actionEventName, classParameter, actionEventCallback, true, false, false, true,actionEventData.callbackState)
+ g_inputBinding:setActionEventTextPriority(eventId, GS_PRIO_HIGH)
+ ---Display text in the F1 window in the top left.
+ g_inputBinding:setActionEventText(eventId, courseplay:loc(actionEventText))
+ g_inputBinding:setActionEventActive(eventId, not isDisabled)
+ ---addActionEvent( action event table, action event name, action event class,
+ --- callback function, trigger key up, trigger key down, trigger always,
+ --- is active, callback state, action event icon)
+end
+
+---Updates action events and disables them if not needed
+---@param object vehicle
+---@param table actionEvents table of action events
+---@param boolean isSetting, is the action event linked to a setting class?
+function ActionEventsLoader.updateActionEvents(actionEvents,actionEventsNameToID,isSetting,vehicle)
+ if actionEventsNameToID == nil then
+ return
+ end
+ for _,actionEventData in ipairs(actionEvents) do
+ local actionEventName = ActionEventsLoaderUtil.getActionEventName(actionEventData)
+ local actionEventText = ActionEventsLoaderUtil.getActionEventText(actionEventData)
+ local actionEvent = InputAction[actionEventName] and actionEventsNameToID[InputAction[actionEventName]]
+ if actionEvent then
+ local class,classParameter
+ ---If the action event is a setting we get the setting by the settings name
+ if isSetting then
+ class = ActionEventsLoaderUtil.getActionEventSetting(actionEventData,vehicle)
+ classParameter = class
+ else
+ class = ActionEventsLoaderUtil.getActionEventClass(actionEventData,ActionEventCallbacks)
+ classParameter = ActionEventsLoaderUtil.getActionEventCallbackParameter(actionEventData,vehicle)
+ end
+ local isDisabled = ActionEventsLoaderUtil.getActionEventIsDisabled(actionEventData,class,classParameter)
+
+ if vehicle then
+ courseplay.debugVehicle(courseplay.DBG_HUD,vehicle,"Update action event: name= %s, text= %s, isDisabled= %s",
+ actionEventName, courseplay:loc(actionEventText), tostring(isDisabled))
+ else
+ courseplay.debugFormat(courseplay.DBG_HUD,"Update action event: name= %s, text= %s, isDisabled= %s",
+ actionEventName, courseplay:loc(actionEventText), tostring(isDisabled))
+ end
+ ---Enable/disable the action event
+ g_inputBinding:setActionEventActive(actionEvent.actionEventId, not isDisabled)
+ end
+ end
+end
+
+
+---Updates all vehicle action events and disables them if not needed
+---@param object vehicle
+function ActionEventsLoader.updateAllActionEvents(vehicle)
+ local actionEvents = g_ActionEventsLoader:getActionEvents()
+ ActionEventsLoader.updateActionEvents(actionEvents,vehicle.cpActionEvents,false,vehicle)
+ actionEvents = g_ActionEventsLoader:getSettingActionEvents()
+ ActionEventsLoader.updateActionEvents(actionEvents,vehicle.cpActionEvents,true,vehicle)
+ ---TODO: This one needs some fine tuning
+-- actionEvents = g_ActionEventsLoader:getGlobalActionEvents()
+-- ActionEventsLoader.updateActionEvents(actionEvents,ActionEventsLoader.actionEventsNameToID)
+end
+
+
+g_ActionEventsLoader = ActionEventsLoader()
+
+ActionEventsLoaderUtil = {}
+
+---Gets the action event name of the xml data
+function ActionEventsLoaderUtil.getActionEventName(actionEventData)
+ return InputAction[actionEventData.name]
+end
+
+---Gets the action event class of the xml data or returns the default class
+---@param table actionEventData from the config xml
+---@param object default class for the callbacks
+function ActionEventsLoaderUtil.getActionEventClass(actionEventData,defaultClass)
+ return actionEventData.class and ActionEventsLoader.classStringToClass[actionEventData.class] or defaultClass
+end
+
+---Gets the action event callback function parameter of the xml data, default is default class
+---@param table actionEventData from the config xml
+---@param object default class for the callbacks
+function ActionEventsLoaderUtil.getActionEventCallbackParameter(actionEventData,defaultClass)
+ return actionEventData.callbackParameter and ActionEventsLoader.classStringToClass[actionEventData.callbackParameter] or defaultClass
+end
+
+---Gets the action event setting of the xml data
+---@param table actionEventData from the config xml
+---@param object vehicle
+function ActionEventsLoaderUtil.getActionEventSetting(actionEventData,vehicle)
+ return vehicle.cp.settings[actionEventData.setting]
+end
+
+---Gets the action event callback function of the xml data
+---@param table actionEventData from the config xml
+---@param object callback class
+function ActionEventsLoaderUtil.getActionEventCallback(actionEventData,class)
+ return class[actionEventData.callbackFunc]
+end
+
+---Gets the action event text of the xml data, default is the action event name
+---@param table actionEventData from the config xml
+function ActionEventsLoaderUtil.getActionEventText(actionEventData)
+ ---If no explicit action event text was set,
+ ---the action events name is used with the prefix:"input_",
+ ---as all action event translation need this to be correctly displayed
+ ---in the Input bindings menu by giants.
+ return actionEventData.text or ActionEventsLoader.textPrefix..actionEventData.name
+end
+
+---Is the action event disabled ?
+---Defaults to class.isDisabled , if the is disabled callback function is not defined or it is always enabled
+---@param table actionEventData from the config xml
+---@param object callback class
+---@param int callback parameter
+function ActionEventsLoaderUtil.getActionEventIsDisabled(actionEventData,class,classParameter)
+ local isDisabledCallback = actionEventData.isDisabledCallbackFunc and class[actionEventData.isDisabledCallbackFunc] or class.isDisabled
+ local callbackState = actionEventData.callbackState
+ if isDisabledCallback then
+ return isDisabledCallback(classParameter,callbackState)
+ end
+ return false
+end
+
+
+ActionEventCallbacks = {}
+
+--[[
+ Every action event callback has the following parameters:
+ - class of the callback, here vehicle
+ - action event name
+ - input value: not sure
+ - a possible additional variable, for example an integer
+ - isAnalog: not sure
+]]--
+function ActionEventCallbacks.actionEventOpenCloseHud(vehicle, actionName, inputValue, callbackState, isAnalog)
+ vehicle:setCourseplayFunc('openCloseHud', not vehicle.cp.hud.show);
+end
+
+function ActionEventCallbacks.actionEventNextDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog)
+ local newMode = SettingsUtil.getNextCpMode(vehicle)
+ if newMode ~= vehicle.cp.mode then
+ vehicle:setCourseplayFunc('setCpMode', newMode);
+ end
+end
+
+function ActionEventCallbacks.actionEventPreviousDriverMode(vehicle, actionName, inputValue, callbackState, isAnalog)
+ local newMode = SettingsUtil.getPrevCpMode(vehicle)
+ if newMode ~= vehicle.cp.mode then
+ vehicle:setCourseplayFunc('setCpMode', newMode);
+ end
+end
+
+function ActionEventCallbacks.actionEventNextHudPage(vehicle, actionName, inputValue, callbackState, isAnalog)
+ local newPage = courseplay.hud.getNextPage(vehicle)
+ if newPage ~= courseplay.hud.getCurrentPage(vehicle) then
+ vehicle:setCourseplayFunc('setHudPage', newPage)
+ end
+end
+
+function ActionEventCallbacks.actionEventPreviousHudPage(vehicle, actionName, inputValue, callbackState, isAnalog)
+ local newPage = courseplay.hud.getPrevPage(vehicle)
+ if newPage ~= courseplay.hud.getCurrentPage(vehicle) then
+ vehicle:setCourseplayFunc('setHudPage', newPage)
+ end
+end
+
+
+function ActionEventCallbacks.actionEventStartStopRecording(vehicle, actionName, inputValue, callbackState, isAnalog)
+ if not vehicle.cp.canDrive then
+ if not vehicle.cp.recordingIsPaused then
+ if not vehicle.cp.isRecording and vehicle.cp.numWaypoints == 0 then
+ vehicle:setCourseplayFunc('start_record', nil);
+ elseif not vehicle.cp.isRecordingTurnManeuver then
+ vehicle:setCourseplayFunc('stop_record', nil);
+ end
+ end
+ end
+end
+
+function ActionEventCallbacks.actionEventPauseRecording(vehicle, actionName, inputValue, callbackState, isAnalog)
+ vehicle:setCourseplayFunc('setRecordingPause', nil, false, 1);
+end
+
+function ActionEventCallbacks.actionEventToggleReverseRecording(vehicle, actionName, inputValue, callbackState, isAnalog)
+ vehicle:setCourseplayFunc('change_DriveDirection', nil, false, 1);
+end
+
+function ActionEventCallbacks.actionEventStartStopDriving(vehicle, actionName, inputValue, callbackState, isAnalog)
+ courseplay:startStop(vehicle)
+end
+
+function ActionEventCallbacks.actionEventDriveNow(vehicle, actionName, inputValue, callbackState, isAnalog)
+
+end
+
+---Is disabled callbacks to disable action events.
+---@param vehicle
+
+function ActionEventCallbacks.isActionEventOpenCloseHudDisabled(vehicle)
+
+end
+
+function ActionEventCallbacks.isActionEventChangeDriverModeDisabled(vehicle)
+ return not vehicle.cp.hud.show or vehicle:getIsCourseplayDriving() or vehicle.cp.isRecording
+end
+
+function ActionEventCallbacks.isActionEventChangeHudPageDisabled(vehicle)
+ return not vehicle.cp.hud.show or vehicle.cp.isRecording
+end
+
+
+function ActionEventCallbacks.isActionEventStartStopRecordingDisabled(vehicle)
+ return vehicle.cp.canDrive
+end
+
+function ActionEventCallbacks.isActionEventPauseRecordingDisabled(vehicle)
+ return vehicle.cp.canDrive or vehicle.cp.numWaypoints < 3
+end
+
+function ActionEventCallbacks.isActionEventToggleReverseRecortdingDisabled(vehicle)
+ return vehicle.cp.canDrive or not vehicle.cp.isRecording
+end
+
+function ActionEventCallbacks.isActionEventStartStopDrivingDisabled(vehicle)
+ return not vehicle.cp.canDrive
+end
+
+function ActionEventCallbacks.isActionEventDriveNowDisabled(vehicle)
+ return true
+end
diff --git a/CpManager.lua b/CpManager.lua
index 3f3e7dd05..21685f7f3 100644
--- a/CpManager.lua
+++ b/CpManager.lua
@@ -46,6 +46,7 @@ function CpManager:loadMap(name)
if g_server ~= nil then
self:loadXmlSettings();
g_vehicleConfigurations:loadFromXml()
+ g_ActionEventsLoader:loadFromXml()
end
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- SETUP (continued)
@@ -285,19 +286,6 @@ function CpManager:update(dt)
self.realTime5SecsTimerThrough = true;
end;
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- -- HELP MENU
- if g_gui.currentGui == nil and g_currentMission.controlledVehicle == nil and not g_currentMission.player.currentTool then
- if self.playerOnFootMouseEnabled then
- -- TODO: Fix this when rewriting to the new Input Info box
- -- Throws an error -> CpManager.lua:296: attempt to call method 'addHelpTextFunction' (a nil value)
- -- wasn't able to find smth similiar in the FS19 doc, hence disable it for now
- --g_currentMission:addHelpTextFunction(self.drawMouseButtonHelp, self, self.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_HIDE'));
- --Tommi elseif self.globalInfoText.hasContent then
- --Tommi g_currentMission:addHelpTextFunction(self.drawMouseButtonHelp, self, self.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_SHOW'));
- end;
- end;
-
if not courseplay.fields.modifier then
courseplay.fields.modifier = DensityMapModifier:new(g_currentMission.terrainDetailId, g_currentMission.terrainDetailTypeFirstChannel, g_currentMission.terrainDetailTypeNumChannels) -- terrain type modifier
courseplay.fields.filter = DensityMapFilter:new(courseplay.fields.modifier) -- filter on terrain type
@@ -363,43 +351,14 @@ function CpManager:mouseEvent(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- LEFT CLICK to click the button shown in globalInfoText
if (isDown or isUp) and mouseKey == courseplay.inputBindings.mouse.primaryButtonId and courseplay:mouseIsInArea(posX, posY, area.x1, area.x2, area.y1, area.y2) then
- if self.globalInfoText.hasContent then
- for i,button in pairs(self.globalInfoText.buttons) do
- if button.show and button:getHasMouse(posX, posY) then
- button:setClicked(isDown);
- if isUp then
- local sourceVehicle = g_currentMission.controlledVehicle or button.parameter;
- button:handleMouseClick(sourceVehicle);
- end;
- break;
- end;
- end;
- end;
-
+ self:onPrimaryMouseClick(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- RIGHT CLICK to activate the mouse cursor when I'm not in a vehicle and a globalInfoText is shown
elseif isUp and mouseKey == courseplay.inputBindings.mouse.secondaryButtonId and g_currentMission.controlledVehicle == nil then
- if self.globalInfoText.hasContent and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool then
- self.playerOnFootMouseEnabled = true;
- self.wasPlayerFrozen = g_currentMission.isPlayerFrozen;
- g_currentMission.isPlayerFrozen = true;
- elseif self.playerOnFootMouseEnabled then
- self.playerOnFootMouseEnabled = false;
- if self.globalInfoText.hasContent then --if a button was hovered when deactivating the cursor, deactivate hover state
- for _,button in pairs(self.globalInfoText.buttons) do
- button:setClicked(false);
- button:setHovered(false);
- end;
- end;
- if not self.wasPlayerFrozen then
- g_currentMission.isPlayerFrozen = false;
- end;
- end;
- g_inputBinding:setShowMouseCursor(self.playerOnFootMouseEnabled);
-
+ self:onSecondaryMouseClick(posX, posY, isDown, isUp, mouseKey)
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- HOVER
- elseif not isDown and not isUp and self.globalInfoText.hasContent then
+ elseif not isDown and not isUp and self:getHasGlobalInfoText() then
for _,button in pairs(self.globalInfoText.buttons) do
button:setClicked(false);
if button.show and not button.isHidden then
@@ -410,12 +369,88 @@ function CpManager:mouseEvent(posX, posY, isDown, isUp, mouseKey)
g_devHelper:mouseEvent(posX, posY, isDown, isUp, mouseKey)
end;
+---Secondary mouse button pressed
+---@param float posX, mouse x position
+---@param float posY, mouse y position
+---@param boolean isDown, is the mouse button down ?
+---@param boolean isUp, is the mouse button up ?
+---@param int mouseKey, which mouse button was pressed ?
+function CpManager:onSecondaryMouseClick(posX, posY, isDown, isUp, mouseKey)
+ if self:getHasGlobalInfoText() and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool then
+ self.playerOnFootMouseEnabled = true
+ self.wasPlayerFrozen = g_currentMission.isPlayerFrozen
+ g_currentMission.isPlayerFrozen = true
+ elseif self.playerOnFootMouseEnabled then
+ self.playerOnFootMouseEnabled = false
+ if self:getHasGlobalInfoText() then --if a button was hovered when deactivating the cursor, deactivate hover state
+ self:resetGlobalInfoTextButtons()
+ end;
+ if not self.wasPlayerFrozen then
+ g_currentMission.isPlayerFrozen = false
+ end;
+ end;
+ g_inputBinding:setShowMouseCursor(self.playerOnFootMouseEnabled)
+ CpManager:updateMouseInputText()
+end
+
+---Primary mouse button pressed
+---@param float posX, mouse x position
+---@param float posY, mouse y position
+---@param boolean isDown, is the mouse button down ?
+---@param boolean isUp, is the mouse button up ?
+---@param int mouseKey, which mouse button was pressed ?
+function CpManager:onPrimaryMouseClick(posX, posY, isDown, isUp, mouseKey)
+ if self:getHasGlobalInfoText() then
+ for i,button in pairs(self.globalInfoText.buttons) do
+ if button.show and button:getHasMouse(posX, posY) then
+ button:setClicked(isDown)
+ if isUp then
+ local sourceVehicle = g_currentMission.controlledVehicle or button.parameter
+ button:handleMouseClick(sourceVehicle)
+ end
+ break
+ end
+ end
+ CpManager:updateMouseInputText()
+ end
+end
+
+---Is the second mouse button allowed, when the player isn't in a vehicle ?
+---@return boolean allowed?
+function CpManager:isSecondaryMouseClickAllowed()
+ return self.playerOnFootMouseEnabled or self:getHasGlobalInfoText() and not self.playerOnFootMouseEnabled and not g_currentMission.player.currentTool
+end
+
+---Is the first mouse button allowed, when the player isn't in a vehicle ?
+---@return boolean allowed?
+function CpManager:isPrimaryMouseClickAllowed()
+ return self:getHasGlobalInfoText() and self.playerOnFootMouseEnabled
+end
+
+---Updates mouse input texts
+---@param boolean forceText should the texts forced to display?
+function CpManager:updateMouseInputText()
+ -- HELP MENU
+ ---TODO: For now always display the mouse action text,
+ --- as this one would probably be broken in MP,
+ --- should probably rework global info texts.
+
+-- if g_gui.currentGui == nil and not g_currentMission.player.currentTool then
+-- g_currentMission.hud.inputHelp:clearCustomEntries()
+-- if self:isPrimaryMouseClickAllowed() or g_currentMission.controlledVehicle ~= nil then
+-- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_MOUSEACTION_PRIMARY', '', courseplay:loc("input_COURSEPLAY_MOUSEACTION_PRIMARY"), false)
+-- end
+-- if self:isSecondaryMouseClickAllowed() or g_currentMission.controlledVehicle ~= nil then
+-- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_MOUSEACTION_SECONDARY', '', courseplay:loc("input_COURSEPLAY_MOUSEACTION_SECONDARY"), false)
+-- end
+-- end
+end
+
function CpManager:keyEvent(unicode, sym, modifier, isDown)
courseplay:onKeyEvent(unicode, sym, modifier, isDown)
g_devHelper:keyEvent(unicode, sym, modifier, isDown)
end;
-
-- ####################################################################################################
function CpManager.saveXmlSettings(self)
if g_server == nil and g_dedicatedServerInfo == nil then return end;
@@ -1113,6 +1148,17 @@ function CpManager:renderGlobalInfoTexts(basePosY)
return line;
end;
+function CpManager:resetGlobalInfoTextButtons()
+ for _,button in pairs(self.globalInfoText.buttons) do
+ button:setClicked(false);
+ button:setHovered(false);
+ end;
+end
+
+function CpManager:getHasGlobalInfoText()
+ return self.globalInfoText.hasContent
+end
+
-- ####################################################################################################
-- 2D COURSE DRAW SETUP
function CpManager:setup2dCourseData(createOverlays)
diff --git a/base.lua b/base.lua
index 11205dbdc..62ae3999f 100644
--- a/base.lua
+++ b/base.lua
@@ -408,7 +408,8 @@ function courseplay:onLeaveVehicle()
courseplay:setMouseCursor(self, false);
courseEditor:reset()
end
-
+ ---Update mouse action event texts
+ CpManager:updateMouseInputText()
--hide visual i3D waypoint signs when not in vehicle
courseplay.signs:setSignsVisibility(self, true);
end
@@ -423,7 +424,8 @@ function courseplay:onEnterVehicle()
if self.cp.mouseCursorActive then
courseplay:setMouseCursor(self, true);
end;
-
+ ---Update mouse action event texts
+ CpManager:updateMouseInputText()
--show visual i3D waypoint signs only when in vehicle
courseplay.signs:setSignsVisibility(self);
end
@@ -464,88 +466,8 @@ function courseplay:onDraw()
end
local nx,ny,nz = getWorldTranslation(self.cp.directionNode);
cpDebug:drawPoint(nx, ny+4, nz, 0.6196, 0.3490 , 0);
- end;
-
-
- -- HELP BUTTON TEXTS
- --renderText(0.2, 0.5, 0.02, string.format("InputBinding.wrapMousePositionEnabled(%s),g_currentMission.isPlayerFrozen(%s) self:getIsActive(%s) and Enterable.getIsEntered(self)(%s) then"
- --,tostring(InputBinding.wrapMousePositionEnabled),tostring(g_currentMission.isPlayerFrozen),tostring(self:getIsActive()),tostring(Enterable.getIsEntered(self))));
- --print(string.format("if self:getIsActive(%s) and self.isEntered(%s) then",tostring(self:getIsActive()),tostring(Enterable.getIsEntered(self))))
+ end;
-
- if self:getIsActive() and self:getIsEntered() then
- local modifierPressed = courseplay.inputModifierIsPressed;
- --missing hud.openWithMouse ?
- if self.cp.canDrive and not modifierPressed then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_FUNCTIONS'), InputBinding.COURSEPLAY_MODIFIER, nil, GS_PRIO_HIGH);
- end;
-
- --[[if self.cp.hud.show then
- if self.cp.mouseCursorActive then
- g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_HIDE'));
- else
- g_currentMission:addHelpTextFunction(CpManager.drawMouseButtonHelp, self, CpManager.hudHelpMouseLineHeight, courseplay:loc('COURSEPLAY_MOUSEARROW_SHOW'));
- end;
- end;]]
- if modifierPressed then
- if not self.cp.hud.show then
- --g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_HUD'], true)
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_OPEN'), InputBinding.COURSEPLAY_HUD, nil, GS_PRIO_HIGH);
- else
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_HUD_CLOSE'), InputBinding.COURSEPLAY_HUD, nil, GS_PRIO_HIGH);
- end;
- end;
-
- if modifierPressed then
- if self.cp.canDrive then
- if isDriving then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_STOP_COURSE'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
- --g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_START_STOP'], true)
- if self.cp.HUD1wait or (self.cp.driver and self.cp.driver:isWaiting()) then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_CONTINUE'), InputBinding.COURSEPLAY_CANCELWAIT, nil, GS_PRIO_HIGH);
- end;
- if self.cp.HUD1noWaitforFill then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_DRIVE_NOW'), InputBinding.COURSEPLAY_DRIVENOW, nil, GS_PRIO_HIGH);
- end;
- else
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_START_COURSE'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
- --g_gui.inputManager:setActionEventTextVisibility(courseplay.inputActionEventIds['COURSEPLAY_START_STOP'], true)
-
- --new ShovelPositions still need info text!
-
- -- if self.cp.hasShovelStatePositions[2] and InputBinding.COURSEPLAY_SHOVELPOSITION_LOAD ~= nil then
- -- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_LOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_LOAD, nil, GS_PRIO_HIGH);
- -- end;
- -- if self.cp.hasShovelStatePositions[3] and InputBinding.COURSEPLAY_SHOVELPOSITION_TRANSPORT ~= nil then
- -- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_TRANSPORT'). InputBinding.COURSEPLAY_SHOVELPOSITION_TRANSPORT, nil, GS_PRIO_HIGH);
- -- end;
- -- if self.cp.hasShovelStatePositions[4] and InputBinding.COURSEPLAY_SHOVELPOSITION_PREUNLOAD ~= nil then
- -- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_PREUNLOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_PREUNLOAD, nil, GS_PRIO_HIGH);
- -- end;
- -- if self.cp.hasShovelStatePositions[5] and InputBinding.COURSEPLAY_SHOVELPOSITION_UNLOAD ~= nil then
- -- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_SHOVELPOSITION_UNLOAD'). InputBinding.COURSEPLAY_SHOVELPOSITION_UNLOAD, nil, GS_PRIO_HIGH);
- -- end;
- --end;
- end;
- else
- if not self.cp.isRecording and not self.cp.recordingIsPaused and self.cp.numWaypoints == 0 then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_START'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
- elseif self.cp.isRecording and not self.cp.recordingIsPaused and not self.cp.isRecordingTurnManeuver then
- g_currentMission:addHelpButtonText(courseplay:loc('COURSEPLAY_RECORDING_STOP'), InputBinding.COURSEPLAY_START_STOP, nil, GS_PRIO_HIGH);
- end;
- end;
-
- if self.cp.canSwitchMode then
- if self.cp.nextMode then
- g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_NEXTMODE'), InputBinding.COURSEPLAY_NEXTMODE, nil, GS_PRIO_HIGH);
- end;
- if self.cp.prevMode then
- g_currentMission:addHelpButtonText(courseplay:loc('input_COURSEPLAY_PREVMODE'), InputBinding.COURSEPLAY_PREVMODE, nil, GS_PRIO_HIGH);
- end;
- end;
- end;
- end;
-
if self:getIsActive() then
if self.cp.hud.show then
courseplay.hud:setContent(self);
@@ -1387,8 +1309,12 @@ function courseplay.onStartCpAIDriver(vehicle,helperIndex,noEventSend, startedFa
spec.currentHelper = g_helperManager:getRandomHelper()
end
g_helperManager:useHelper(spec.currentHelper)
- spec.startedFarmId = startedFarmId
- if g_server ~= nil then
+ ---Make sure the farmId is never: 0 == spectator farm id,
+ ---which could be the case when autodrive starts a CP driver.
+ if startedFarmId ~= 0 then
+ spec.startedFarmId = startedFarmId
+ end
+ if g_server ~= nil then
g_farmManager:updateFarmStats(startedFarmId, "workersHired", 1)
end
if noEventSend == nil or noEventSend == false then
diff --git a/button.lua b/button.lua
index 4be9370d0..3f9662e3c 100644
--- a/button.lua
+++ b/button.lua
@@ -352,6 +352,9 @@ function courseplay.button:getHasMouse(mouseX, mouseY)
return courseplay:mouseIsInArea(mouseX, mouseY, self.x, self.x2, self.y, self.y2);
end;
+function courseplay.button:getIsDisabled()
+ return self.isDisabled
+end
-- #################################################################
diff --git a/clicktoswitch.lua b/clicktoswitch.lua
index 509da9325..491fcf6ad 100644
--- a/clicktoswitch.lua
+++ b/clicktoswitch.lua
@@ -68,83 +68,3 @@ function clickToSwitch:vehicleClickToSwitchRaycastCallback(hitObjectId, x, y, z,
end
return true
end
-
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
--- CODE MERGING NOTES
------------------------------------------------------------------------------------------
---[[
-
--- make the following change to input.lua (to
-
-function courseplay:onMouseEvent(posX, posY, isDown, isUp, mouseButton)
- --RIGHT CLICK
- -- Input binding debug
- local vehicle = g_currentMission.controlledVehicle
- if not vehicle or not vehicle.hasCourseplaySpec then return end
- courseEditor:updateMouseState(vehicle, posX, posY, isDown, isUp, mouseButton)
-
- --print(string.format('courseplay:mouseEvent(posX(%s), posY(%s), isDown(%s), isUp(%s), mouseButton(%s))', tostring(posX), tostring(posY), tostring(isDown), tostring(isUp), tostring(mouseButton) ))
- --print(string.format("if isUp(%s) and mouseButton(%s) == courseplay.inputBindings.mouse.secondaryButtonId(%s) and Enterable.getIsEntered(self)(%s) then"
- --,tostring(isUp),tostring(mouseButton),tostring(courseplay.inputBindings.mouse.secondaryButtonId),tostring(Enterable.getIsEntered(self))))
- if isUp and mouseButton == courseplay.inputBindings.mouse.secondaryButtonId and vehicle:getIsEntered() then
- if vehicle.cp.hud.show then
- courseplay:setMouseCursor(vehicle, not vehicle.cp.mouseCursorActive);
- elseif not vehicle.cp.hud.show and vehicle.cp.hud.openWithMouse then
- courseplay:openCloseHud(vehicle, true)
- end;
- end;
-
- local hudGfx = courseplay.hud.visibleArea;
- local mouseIsInHudArea = vehicle.cp.mouseCursorActive and courseplay:mouseIsInArea(posX, posY, hudGfx.x1, hudGfx.x2, hudGfx.y1, vehicle.cp.suc.active and courseplay.hud.suc.visibleArea.y2 or hudGfx.y2);
- -- if not mouseIsInHudArea then return; end;
-
- -- should we switch vehicles? -- added for clickToSwitch
- if courseplay.globalSettings.clickToSwitch:is(true) and vehicle.cp.mouseCursorActive and vehicle.cp.hud.show and vehicle:getIsEntered() and not mouseIsInHudArea and -- added for clickToSwitch
- mouseButton == courseplay.inputBindings.mouse.primaryButtonId then -- added for clickToSwitch
- clickToSwitch:updateMouseState(vehicle, posX, posY, isDown, isUp, mouseButton) -- added for clickToSwitch
- end -- added for clickToSwitch
-
-.
-.
-
-----------------------------
-
-In settings.lua add the following just after the 'AutoFieldScanSetting' block (to define the global setting to turn this on or off)
-
----@class ClickToSwitchSetting : BooleanSetting
-ClickToSwitchSetting = CpObject(BooleanSetting)
-function ClickToSwitchSetting:init()
- BooleanSetting.init(self, 'clickToSwitch', 'COURSEPLAY_CLICK_TO_SWITCH',
- 'COURSEPLAY_YES_NO_CLICK_TO_SWITCH', nil)
- -- set default while we are transitioning from the the old setting to this new one
- self:set(false)
-end
-
-----------------------------
-
-In GlobalSettingsPage.xml add the following just after the 'workerWages' block (to define the on/off gui switch for this feature)
-.
-.
-
-
-
-
-
-
-
-.
-.
-----------------------------
-
-In translation_en.xml add
-.
-.
- -- add for clicktoswitch
- -- add for clicktoswitch
-.
-.
-
-do this for the other translation languages too.
-
-]]--
\ No newline at end of file
diff --git a/config/ActionEventsConfig.xml b/config/ActionEventsConfig.xml
new file mode 100644
index 000000000..a455385f1
--- /dev/null
+++ b/config/ActionEventsConfig.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/courseeditor.lua b/courseeditor.lua
index 02d9fa061..82b8b9e9c 100644
--- a/courseeditor.lua
+++ b/courseeditor.lua
@@ -159,35 +159,26 @@ function courseEditor:setEnabled(value, vehicle)
if not vehicle.cp.isRecording and not self:isAutoDriveCourse(vehicle) and #vehicle.Waypoints > 0 then
self.enabled = value
vehicle.cp.settings.showVisualWaypoints:set(ShowVisualWaypointsSetting.ALL)
- self:addInputHelp()
+ ActionEventsLoader.updateAllActionEvents(vehicle)
end
else
self.enabled = value
vehicle.cp.visualWaypointsAl = false
- self:clearInputHelp()
self:reset()
+ ActionEventsLoader.updateAllActionEvents(vehicle)
end
end
--- add entries to the input help panel (via F1 keypress, usually)
-function courseEditor:addInputHelp()
- g_currentMission.hud.inputHelp:clearCustomEntries()
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_TOGGLE', '', "Toggle course editor", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_UNDO', '', "Undo last course change", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_SAVE', '', "Save course changes", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_SPEED_DECREASE', '', "Decrease waypoint speed", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_SPEED_INCREASE', '', "Increase waypoint speed", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_DELETE_WAYPOINT', '', "Delete waypoint", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_DELETE_NEXT_WAYPOINT', '', "Delete next waypoint", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_DELETE_TO_START', '',"Delete wayoints to start", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_DELETE_TO_END', '', "Delete waypoints to end", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_INSERT_WAYPOINT', '', "Insert waypoint", false)
- g_currentMission.hud.inputHelp:addCustomEntry('COURSEPLAY_EDITOR_CYCLE_WAYPOINT_TYPE', '', "Change waypoint type", false)
+function courseEditor.setEnabledActionEvent(vehicle)
+ courseEditor:setEnabled(not courseEditor.enabled, vehicle)
end
--- remove our custom input help panel entries
-function courseEditor:clearInputHelp()
- g_currentMission.hud.inputHelp:clearCustomEntries()
+function courseEditor.getIsNotAllowedToUse(vehicle)
+ return vehicle.cp.isRecording or courseEditor:isAutoDriveCourse(vehicle) or #vehicle.Waypoints == 0
+end
+
+function courseEditor:getIsDisabled()
+ return not self.enabled
end
-- call reset when entering a vehicle or after saving a course via hotkey
@@ -211,7 +202,6 @@ function courseEditor:reset()
self.historyAdded = false
self.waypointTypeIndex = 0
self:clearHistory()
- self:clearInputHelp()
end
-- clears the undo history
diff --git a/courseplay.lua b/courseplay.lua
index 063ff1d7c..5f03b3bb5 100644
--- a/courseplay.lua
+++ b/courseplay.lua
@@ -107,6 +107,7 @@ local function initialize()
'Conflict',
'AITurn',
'VehicleConfigurations',
+ 'ActionEventsLoader',
'course-generator/geo',
'course-generator/Island',
'course-generator/courseGenerator',
diff --git a/hud.lua b/hud.lua
index 4760c750a..7cce57008 100644
--- a/hud.lua
+++ b/hud.lua
@@ -657,12 +657,13 @@ function courseplay.hud:updatePageContent(vehicle, page)
end
elseif entry.functionToCall == 'startingPoint:next' then
--StartingPointSetting
- if not vehicle:getIsCourseplayDriving() and vehicle.cp.canDrive then
- self:enableButtonWithFunction(vehicle,page, 'next',vehicle.cp.settings.startingPoint)
- vehicle.cp.hud.content.pages[page][line][1].text = vehicle.cp.settings.startingPoint:getLabel()
- vehicle.cp.hud.content.pages[page][line][2].text = vehicle.cp.settings.startingPoint:getText()
+ local setting = vehicle.cp.settings.startingPoint
+ if not setting:isDisabled() then
+ self:enableButtonWithFunction(vehicle,page, 'next',setting)
+ vehicle.cp.hud.content.pages[page][line][1].text = setting:getLabel()
+ vehicle.cp.hud.content.pages[page][line][2].text = setting:getText()
else
- self:disableButtonWithFunction(vehicle,page, 'next',vehicle.cp.settings.startingPoint)
+ self:disableButtonWithFunction(vehicle,page, 'next',setting)
end
elseif entry.functionToCall == 'autoDriveMode:changeByX' then
--autoDriveModeSetting
@@ -1266,6 +1267,7 @@ function courseplay.hud:setReloadPageOrder(vehicle, page, bool)
vehicle.cp.hud.reloadPage[page] = bool;
courseplay:debug(string.format('%s: set reloadPage[%d]', nameNum(vehicle), page), courseplay.DBG_HUD);
end;
+ ActionEventsLoader.updateAllActionEvents(vehicle)
end;
function courseplay:setFontSettings(color, fontBold, align)
@@ -1992,6 +1994,8 @@ function courseplay.hud:disableButtonsOnThisPage(vehicle,page)
end
end
+
+
function courseplay.hud:enableButtonWithFunction(vehicle,page, func,class)
if class then
self:debug(vehicle,string.format("enableButton Setting: %s function: %s",class.name, func))
@@ -2034,6 +2038,48 @@ function courseplay.hud:disableButtonWithFunction(vehicle,page, func,class)
end
end
+---Gets the next allowed hud page.
+---@param vehicle
+function courseplay.hud.getNextPage(vehicle)
+ ---self.numPages: is off by one page, as the first page is 0
+ local numPages = courseplay.hud.numPages + 1
+ for i=1,numPages do
+ local targetPage = vehicle.cp.hud.currentPage +i
+ ---If the last page is reached continue from the beginning.
+ if targetPage > courseplay.hud.numPages then
+ targetPage = targetPage - numPages
+ end
+ local button = vehicle.cp.hud.hudPageButtons[targetPage]
+ if button and not button:getIsDisabled() then
+ return targetPage
+ end
+ end
+end
+
+---Gets the previous allowed hud page.
+---@param vehicle
+function courseplay.hud.getPrevPage(vehicle)
+ ---self.numPages: is off by one page, as the first page is 0
+ local numPages = courseplay.hud.numPages + 1
+ for i=1,numPages do
+ local targetPage = vehicle.cp.hud.currentPage -i
+ ---If the first page is reached continue from the last one.
+ if targetPage < 0 then
+ targetPage = numPages + targetPage
+ end
+ local button = vehicle.cp.hud.hudPageButtons[targetPage]
+ if button and not button:getIsDisabled() then
+ return targetPage
+ end
+ end
+end
+
+---Gets the current hud page.
+---@param vehicle
+function courseplay.hud.getCurrentPage(vehicle)
+ return vehicle.cp.hud.currentPage
+end
+
---Should consider making all simple row buttons callback functions
---into Action events callbacks, this one would make it easier
---for multiplayer and also for easier implementations of
diff --git a/input.lua b/input.lua
index 42d1d1d5b..5d19e2a80 100644
--- a/input.lua
+++ b/input.lua
@@ -227,11 +227,6 @@ function courseplay:onActionBindingsChanged(...)
courseplay.inputBindings.updateInputButtonData();
- for _, vehicle in pairs(g_currentMission.enterables) do
- if vehicle.cp and vehicle.cp.hud then
- courseplay.hud:setReloadPageOrder(vehicle, courseplay.hud.PAGE_GENERAL_SETTINGS, true);
- end
- end
end
end
InputDisplayManager.onActionBindingsChanged = Utils.appendedFunction(InputDisplayManager.onActionBindingsChanged, courseplay.onActionBindingsChanged);
@@ -267,139 +262,5 @@ function courseplay.inputBindings.updateInputButtonData()
courseplay.inputBindings.mouse[inputNameType .. 'ButtonId'] = Input[mouseButtonName];
-- print(('\t\t%sTextI18n=%q, mouseButtonId=%d'):format(inputNameType, txt, mouseButtonId));
- --[[ TODO: Rewrite input key bindings to use Giants default registerActionEvent
- More info can be found here:
- https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=70&class=7302#onRegisterActionEvents120704
- https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=1&class=7052#registerActionEvent118548
-
- Code below is from Jos.
- local _, eventId = self.inputManager:registerActionEvent(InputAction.SEASONS_SHOW_MENU, self, self.onToggleMenu, false, true, false, true)
- self.inputManager:setActionEventTextVisibility(eventId, true)
- setActionEventTextPriority(eventId, priority)
- setActionEventActive(eventId, isActive)
- ]]
-
- --- Do not activate below code: It will activate variables that dont exist anymore. Read the todo above
- --if inputNameType == 'secondary' then
- -- local fileName = courseplay.inputBindings.mouse.mouseButtonOverlays[mouseButtonName] or 'mouseRMB.png';
- -- --print(('\t\tmouseButtonIdName=%q, fileName=%q'):format(tostring(mouseButtonIdName), tostring(fileName)));
- -- if courseplay.inputBindings.mouse.overlaySecondary then
- -- courseplay.inputBindings.mouse.overlaySecondary:delete();
- -- end;
- -- courseplay.inputBindings.mouse.overlaySecondary = Overlay:new(courseplay.path .. 'img/mouseIcons/' .. fileName, 0, 0, 0.0, 0.0);
- --end;
end;
-
-
- --[[
- --print("set up courseplay.inputActions:")
- for index, action in pairs (g_gui.inputManager.nameActions) do
- if string.match(index,'COURSEPLAY_') then
- --print(string.format("%s: (%s) %s",tostring(index),type(action),tostring(action)))
- local actionTable = {
- binding = '',
- bindingSym = '',
- hasBinding = false,
- isPressed = false,
- hasEvent = false
- }
- if action.primaryKeyboardInput then
- --print(" primaryKeyboardInput:"..tostring(action.primaryKeyboardInput))
- actionTable.hasBinding = true
- actionTable.binding = action.primaryKeyboardInput
- actionTable.bindingSym = Input[actionTable.binding]
-
- end
- courseplay.inputActions[index]= actionTable
- end
- end]]
-
- -- KEYBOARD
- --local modifierTextI18n = g_inputDisplayManager:getKeyboardInputActionKey("COURSEPLAY_MODIFIER");
- local openCloseHudTextI18n = g_inputDisplayManager:getKeyboardInputActionKey("COURSEPLAY_HUD");
-
- courseplay.inputBindings.keyboard.openCloseHudTextI18n = ('%s + %s'):format(modifierTextI18n, openCloseHudTextI18n);
- -- print(('\topenCloseHudTextI18n=%q'):format(courseplay.inputBindings.keyboard.openCloseHudTextI18n));
-end;
-
-
-function courseplay.inputActionCallback(vehicle, actionName, keyStatus)
- --This Line is to show Keybinds in Help Menu, not sure how to do it...
- --courseplay.inputModifierIsPressed = g_gui.inputManager.nameActions.COURSEPLAY_MODIFIER.activeBindings[1].isPressed
- --print(string.format("inputActionCallback:(vehicle(%s), actionName(%s), keyStatus(%s))",tostring(vehicle:getName()),tostring(actionName),tostring(keyStatus)))
-
- if keyStatus == 1 and vehicle:getIsActive() and vehicle:getIsEntered() then
-
- --Shovel:
- if actionName == 'COURSEPLAY_SHOVEL_MOVE_TO_LOADING_POSITION' then
- vehicle.cp.settings.frontloaderToolPositions:playPosition(1)
- elseif actionName == 'COURSEPLAY_SHOVEL_MOVE_TO_TRANSPORT_POSITION' then
- vehicle.cp.settings.frontloaderToolPositions:playPosition(2)
- elseif actionName == 'COURSEPLAY_SHOVEL_MOVE_TO_PRE_UNLOADING_POSITION' then
- vehicle.cp.settings.frontloaderToolPositions:playPosition(3)
- elseif actionName == 'COURSEPLAY_SHOVEL_MOVE_TO_UNLOADING_POSITION' then
- vehicle.cp.settings.frontloaderToolPositions:playPosition(4)
- --Editor:
- elseif actionName == 'COURSEPLAY_EDITOR_TOGGLE' then
- courseEditor:setEnabled(not courseEditor.enabled, vehicle)
- elseif actionName == 'COURSEPLAY_EDITOR_UNDO' then
- courseEditor:undo()
- elseif actionName == 'COURSEPLAY_EDITOR_SAVE' then
- courseEditor:save()
- elseif actionName == 'COURSEPLAY_EDITOR_SPEED_INCREASE' then
- courseEditor:increaseSpeed()
- elseif actionName == 'COURSEPLAY_EDITOR_SPEED_DECREASE' then
- courseEditor:decreaseSpeed()
- elseif actionName == 'COURSEPLAY_EDITOR_DELETE_WAYPOINT' then
- courseEditor:delete()
- elseif actionName == 'COURSEPLAY_EDITOR_DELETE_NEXT_WAYPOINT' then
- courseEditor:deleteNext()
- elseif actionName == 'COURSEPLAY_EDITOR_DELETE_TO_START' then
- courseEditor:deleteToStart()
- elseif actionName == 'COURSEPLAY_EDITOR_DELETE_TO_END' then
- courseEditor:deleteToEnd()
- elseif actionName == 'COURSEPLAY_EDITOR_INSERT_WAYPOINT' then
- courseEditor:insert()
- elseif actionName == 'COURSEPLAY_EDITOR_CYCLE_WAYPOINT_TYPE' then
- courseEditor:cycleType()
-
- --HUD open/close:
- elseif actionName == 'COURSEPLAY_HUD' then
- vehicle:setCourseplayFunc('openCloseHud', not vehicle.cp.hud.show, true);
-
- --Driver Actions:
- elseif actionName == 'COURSEPLAY_CANCELWAIT' and
- ((vehicle.cp.HUD1wait and vehicle.cp.canDrive and vehicle.cp.isDriving) or (vehicle.cp.driver and vehicle.cp.driver:isWaiting())) then
- vehicle:setCourseplayFunc('cancelWait', true, false, 1);
- elseif actionName == 'COURSEPLAY_DRIVENOW' and vehicle.cp.HUD1noWaitforFill and vehicle.cp.canDrive and vehicle.cp.isDriving then
- vehicle:setCourseplayFunc('setDriveUnloadNow', true, false, 1);
- elseif actionName == 'COURSEPLAY_STOP_AT_END' and vehicle.cp.canDrive then
- vehicle:setCourseplayFunc('Setting:stopAtEnd:toggle',nil,false,1)
- --Switch Mode, but doesn't work right now, not sure why
- elseif vehicle.cp.canSwitchMode and vehicle.cp.nextMode and actionName == 'COURSEPLAY_NEXTMODE' then
- vehicle:setCourseplayFunc('setCpMode', vehicle.cp.nextMode, false, 1);
- elseif vehicle.cp.canSwitchMode and vehicle.cp.prevMode and actionName == 'COURSEPLAY_PREVMODE' then
- vehicle:setCourseplayFunc('setCpMode', vehicle.cp.prevMode, false, 1);
-
- --Seeder fertilizer toggle:
- elseif actionName == 'COURSEPLAY_TOGGLE_FERTILIZER' then
- vehicle.cp.settings.sowingMachineFertilizerEnabled:toggle()
-
- --StartStop:
- elseif actionName == 'COURSEPLAY_START_STOP' then
- if vehicle.cp.canDrive then
- if vehicle.cp.isDriving then
- vehicle:setCourseplayFunc('stop', nil, false, 1);
- else
- vehicle:setCourseplayFunc('start', nil, false, 1);
- end;
- else
- if not vehicle.cp.isRecording and not vehicle.cp.recordingIsPaused and vehicle.cp.numWaypoints == 0 then
- vehicle:setCourseplayFunc('start_record', nil, false, 1);
- elseif vehicle.cp.isRecording and not vehicle.cp.recordingIsPaused and not vehicle.cp.isRecordingTurnManeuver then
- vehicle:setCourseplayFunc('stop_record', nil, false, 1);
- end;
- end;
- end;
- end; -- END Keystatus == 1 and vehicle:getIsActive() and Enterable.getIsEntered(vehicle)
end;
diff --git a/modDesc.xml b/modDesc.xml
index 9141f057a..07a6a5a3f 100644
--- a/modDesc.xml
+++ b/modDesc.xml
@@ -1,6 +1,6 @@
- 6.03.00052
+ 6.03.00053
CoursePlay SIX
@@ -84,122 +84,161 @@ Courseplay non sostituisce il sistema di gioco in gioco, ma crea un nuovo lavora
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
+
+
courseplay.NUM_MODES then
+ targetMode = targetMode - courseplay.NUM_MODES
+ end
+ if courseplay:getIsToolCombiValidForCpMode(vehicle,targetMode) then
+ return targetMode
+ end
+ end
+ end
+end
+
+function SettingsUtil.getPrevCpMode(vehicle)
+ if vehicle.cp.canSwitchMode and not vehicle:getIsCourseplayDriving() then
+ for i=1,courseplay.NUM_MODES do
+ local targetMode = vehicle.cp.mode - i
+ if targetMode < 1 then
+ targetMode = courseplay.NUM_MODES + targetMode
+ end
+ if courseplay:getIsToolCombiValidForCpMode(vehicle,targetMode) then
+ return targetMode
+ end
+ end
+ end
+end
+
+
-- do not remove this comment
-- vim: set noexpandtab:
diff --git a/translations/translation_br.xml b/translations/translation_br.xml
index 155acb935..b412128da 100644
--- a/translations/translation_br.xml
+++ b/translations/translation_br.xml
@@ -348,35 +348,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -503,6 +474,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_cs.xml b/translations/translation_cs.xml
index ad8b66337..54e3cc2de 100644
--- a/translations/translation_cs.xml
+++ b/translations/translation_cs.xml
@@ -348,35 +348,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -504,6 +475,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_cz.xml b/translations/translation_cz.xml
index a91f73558..6d5accdf5 100644
--- a/translations/translation_cz.xml
+++ b/translations/translation_cz.xml
@@ -349,35 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -507,6 +478,46 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_de.xml b/translations/translation_de.xml
index bd4ffc1cb..99b52966f 100644
--- a/translations/translation_de.xml
+++ b/translations/translation_de.xml
@@ -348,35 +348,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -504,6 +475,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_en.xml b/translations/translation_en.xml
index 3a0f2939f..44cd06439 100644
--- a/translations/translation_en.xml
+++ b/translations/translation_en.xml
@@ -349,35 +349,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -502,6 +474,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_es.xml b/translations/translation_es.xml
index dc86f9798..b2cabc4f3 100644
--- a/translations/translation_es.xml
+++ b/translations/translation_es.xml
@@ -349,35 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -502,6 +473,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_fr.xml b/translations/translation_fr.xml
index 9d60570a2..091acc055 100644
--- a/translations/translation_fr.xml
+++ b/translations/translation_fr.xml
@@ -348,35 +348,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -506,6 +477,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_hu.xml b/translations/translation_hu.xml
index a62d3c04f..446fd6cd6 100644
--- a/translations/translation_hu.xml
+++ b/translations/translation_hu.xml
@@ -340,35 +340,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -502,6 +473,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_it.xml b/translations/translation_it.xml
index 6ad76c05f..0347f584e 100644
--- a/translations/translation_it.xml
+++ b/translations/translation_it.xml
@@ -349,35 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -504,6 +475,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_jp.xml b/translations/translation_jp.xml
index 9386d6fb6..d07f675ee 100644
--- a/translations/translation_jp.xml
+++ b/translations/translation_jp.xml
@@ -349,35 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -504,6 +475,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_nl.xml b/translations/translation_nl.xml
index 23959d78d..04ed53a74 100644
--- a/translations/translation_nl.xml
+++ b/translations/translation_nl.xml
@@ -340,35 +340,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -502,6 +473,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_pl.xml b/translations/translation_pl.xml
index c6adb4fc4..a09c8dfef 100644
--- a/translations/translation_pl.xml
+++ b/translations/translation_pl.xml
@@ -348,35 +348,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -505,6 +476,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_pt.xml b/translations/translation_pt.xml
index 38521da51..46a9e08bd 100644
--- a/translations/translation_pt.xml
+++ b/translations/translation_pt.xml
@@ -343,35 +343,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -502,6 +473,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_ru.xml b/translations/translation_ru.xml
index ae501b096..fb87b5954 100644
--- a/translations/translation_ru.xml
+++ b/translations/translation_ru.xml
@@ -349,36 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -506,6 +476,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/translations/translation_sl.xml b/translations/translation_sl.xml
index 31553e04d..324cdc481 100644
--- a/translations/translation_sl.xml
+++ b/translations/translation_sl.xml
@@ -349,35 +349,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -505,6 +476,46 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+