Skip to content

Commit

Permalink
Merge pull request #177 from stijnwop/feature/aplusheading
Browse files Browse the repository at this point in the history
Feature/aplusheading
  • Loading branch information
stijnwop authored Aug 22, 2019
2 parents bf08bf2 + ceb0afa commit ce70784
Show file tree
Hide file tree
Showing 34 changed files with 463 additions and 316 deletions.
12 changes: 1 addition & 11 deletions resources/gui/GuidanceSteeringStrategyFrame.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</GuiElement>

<GuiElement position="30px 0px" type="multiTextOption" profile="guidanceSettingsMultiTextOptionSettings" id="guidanceSteeringStrategyMethodElement"
toolTipElementId="settingsHelpBoxText" toolTipText="$l10n_guidanceSteering_tooltip_strategyMethod">
toolTipElementId="settingsHelpBoxText" onClick="onStrategyChanged" toolTipText="$l10n_guidanceSteering_tooltip_strategyMethod">
<GuiElement type="button" profile="multiTextOptionLeft" />
<GuiElement type="button" profile="multiTextOptionRight" />
<GuiElement type="text" profile="multiTextOptionText" />
Expand All @@ -23,16 +23,6 @@

<GuiElement position="30px 0px" type="button" profile="guidanceSettingsButton" text="$l10n_guidanceSteering_setting_pointA" onClick="onClickSetPointA" id="guidanceSteeringPointAButton" />
<GuiElement position="30px 0px" type="button" profile="guidanceSettingsButton" text="$l10n_guidanceSteering_setting_pointB" onClick="onClickSetPointB" id="guidanceSteeringPointBButton" />

<GuiElement position="30px 0px" type="multiTextOption" profile="guidanceSettingsMultiTextOptionSettings" id="guidanceSteeringCardinalsElement"
toolTipElementId="settingsHelpBoxText" toolTipText="$l10n_guidanceSteering_tooltip_cardinals">
<GuiElement type="button" profile="multiTextOptionLeft" />
<GuiElement type="button" profile="multiTextOptionRight" />
<GuiElement type="text" profile="multiTextOptionText" />
<GuiElement type="text" profile="multiTextOptionTitle" text="$l10n_guidanceSteering_setting_cardinals" />
<GuiElement type="bitmap" profile="multiTextOptionBg" />
</GuiElement>

</GuiElement>

<GuiElement type="boxLayout" profile="guidanceSettingsLayoutLeft" size="413px 500px" position="413px 0px" id="boxLayout">
Expand Down
6 changes: 3 additions & 3 deletions resources/gui/guiProfiles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@
<Value name="lateralFlowSize" value="150px" />
</Profile>

<Profile name="guidanceSteeringHeaderSelector" extends="multiTextOptionSettings">
<Profile name="guidanceSteeringHeaderSelector" extends="uiInGameMenuHeaderSelector">
<Value name="size" value="1280px 112px" />
</Profile>

<Profile name="guidanceSteeringHeaderSelectorWide" extends="multiTextOptionSettings">
<Value name="size" value="1280px 150px" />
<Profile name="guidanceSteeringHeaderSelectorWide" extends="uiInGameMenuHeaderSelector">
<Value name="size" value="960px 112px" />
</Profile>

<Profile name="guidanceSteeringPagingButtonLeft" extends="uiInGameMenuPagingButtonLeft">
Expand Down
Binary file modified resources/guidanceSteering_1080p.dds
Binary file not shown.
16 changes: 8 additions & 8 deletions src/GuidanceSteering.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function GuidanceSteering:new(mission, modDirectory, modName, i18n, gui, inputMa

self.ui = GuidanceSteeringUI:new(mission, i18n, modDirectory, gui, inputManager, messageCenter)

self.showGuidanceLines = true
self.showGuidanceLines = false
self.guidanceTerrainAngleIsActive = true

BaseMission.onEnterVehicle = Utils.appendedFunction(BaseMission.onEnterVehicle, GuidanceSteering.onEnterVehicle)
Expand All @@ -45,7 +45,7 @@ function GuidanceSteering:delete()
end

function GuidanceSteering:onMissionLoadFromSavegame(xmlFile)
self.showGuidanceLines = Utils.getNoNil(getXMLBool(xmlFile, "guidanceSteering.settings.showGuidanceLines"), true)
self.showGuidanceLines = Utils.getNoNil(getXMLBool(xmlFile, "guidanceSteering.settings.showGuidanceLines"), false)
self.guidanceTerrainAngleIsActive = Utils.getNoNil(getXMLBool(xmlFile, "guidanceSteering.settings.guidanceTerrainAngleIsActive"), true)

local i = 0
Expand Down Expand Up @@ -101,7 +101,7 @@ end

function GuidanceSteering:onReadStream(streamId, connection)
if connection:getIsServer() then
local numTracks = streamReadUIntN(streamId, GuidanceSteering.SEND_NUM_BITS) + 1
local numTracks = streamReadUIntN(streamId, GuidanceSteering.SEND_NUM_BITS)

for i = 1, numTracks do
local track = {}
Expand All @@ -119,7 +119,7 @@ end

function GuidanceSteering:onWriteStream(streamId, connection)
if not connection:getIsServer() then
streamWriteUIntN(streamId, #self.savedTracks - 1, GuidanceSteering.SEND_NUM_BITS)
streamWriteUIntN(streamId, #self.savedTracks, GuidanceSteering.SEND_NUM_BITS)

for _, track in ipairs(self.savedTracks) do
streamWriteString(streamId, track.name)
Expand Down Expand Up @@ -323,7 +323,7 @@ end
function GuidanceSteering:onEnterVehicle()
if self:getIsClient() then
local vehicle = self.controlledVehicle
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
local hasGuidanceSystem = spec ~= nil and spec.hasGuidanceSystem
local gui = g_guidanceSteering.ui

Expand Down Expand Up @@ -355,7 +355,7 @@ function GuidanceSteering.installSpecializations(vehicleTypeManager, specializat
end

function GuidanceSteering.actionEventAccelerate(vehicle, superFunc, actionName, inputValue, ...)
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
if spec ~= nil and vehicle:getHasGuidanceSystem() and spec.guidanceSteeringIsActive and vehicle.getShuttleDriveDirection == nil then
spec.axisAccelerate = MathUtil.clamp(inputValue, 0, 1)
end
Expand All @@ -364,7 +364,7 @@ function GuidanceSteering.actionEventAccelerate(vehicle, superFunc, actionName,
end

function GuidanceSteering.actionEventBrake(vehicle, superFunc, actionName, inputValue, ...)
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
if spec ~= nil and vehicle:getHasGuidanceSystem() and spec.guidanceSteeringIsActive and vehicle.getShuttleDriveDirection == nil then
spec.axisBrake = MathUtil.clamp(inputValue, 0, 1)
end
Expand All @@ -376,7 +376,7 @@ function GuidanceSteering.actionEventSteer(vehicle, superFunc, actionName, input
superFunc(vehicle, actionName, inputValue, callbackState, isAnalog, ...)

if inputValue ~= 0 then
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
if spec ~= nil and vehicle:getHasGuidanceSystem() and spec.lastInputValues.guidanceSteeringIsActive then
if not isAnalog then
spec.lastInputValues.guidanceSteeringIsActive = false
Expand Down
52 changes: 0 additions & 52 deletions src/events/ABPointPushedEvent.lua

This file was deleted.

57 changes: 57 additions & 0 deletions src/events/GuidanceStrategyChangedEvent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--
-- GuidanceStrategyChangedEvent
--
-- Guidance strategy event to sync guidance data with server.
--
-- Copyright (c) Wopster, 2019

GuidanceStrategyChangedEvent = {}
local GuidanceStrategyChangedEvent_mt = Class(GuidanceStrategyChangedEvent, Event)

InitEventClass(GuidanceStrategyChangedEvent, "GuidanceStrategyChangedEvent")

function GuidanceStrategyChangedEvent:emptyNew()
local self = Event:new(GuidanceStrategyChangedEvent_mt)

return self
end

function GuidanceStrategyChangedEvent:new(vehicle, method)
local self = GuidanceStrategyChangedEvent:emptyNew()

self.vehicle = vehicle
self.method = method

return self
end

function GuidanceStrategyChangedEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.vehicle)
streamWriteInt8(streamId, self.method + 1)
end

function GuidanceStrategyChangedEvent:readStream(streamId, connection)
self.vehicle = NetworkUtil.readNodeObject(streamId)
self.method = streamReadInt8(streamId) - 1

self:run(connection)
end

function GuidanceStrategyChangedEvent:run(connection)
self.vehicle:setGuidanceStrategy(self.method, true)

-- Send from server to all clients
if not connection:getIsServer() then
g_server:broadcastEvent(self, false, connection, self.vehicle)
end
end

function GuidanceStrategyChangedEvent.sendEvent(object, method, noEventSend)
if noEventSend == nil or not noEventSend then
if g_server ~= nil then
g_server:broadcastEvent(GuidanceStrategyChangedEvent:new(object, method), nil, nil, object)
else
g_client:getServerConnection():sendEvent(GuidanceStrategyChangedEvent:new(object, method))
end
end
end
52 changes: 0 additions & 52 deletions src/events/SettingsChangedEvent.lua

This file was deleted.

58 changes: 58 additions & 0 deletions src/events/StrategyInteractEvent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--
-- StrategyInteractEvent
--
-- Strategy push event to handle strategy interaction on other clients.
--
-- Copyright (c) Wopster, 2019

StrategyInteractEvent = {}
local StrategyInteractEvent_mt = Class(StrategyInteractEvent, Event)

InitEventClass(StrategyInteractEvent, "StrategyInteractEvent")

function StrategyInteractEvent:emptyNew()
local self = Event:new(StrategyInteractEvent_mt)

return self
end

function StrategyInteractEvent:new(object)
local self = StrategyInteractEvent:emptyNew()

self.object = object

return self
end

function StrategyInteractEvent:writeStream(streamId, connection)
NetworkUtil.writeNodeObject(streamId, self.object)

local spec = self.object.spec_globalPositioningSystem
spec.lineStrategy:writeStream(streamId, connection)
end

function StrategyInteractEvent:readStream(streamId, connection)
self.object = NetworkUtil.readNodeObject(streamId)
local spec = self.object.spec_globalPositioningSystem
spec.lineStrategy:readStream(streamId, connection)

self:run(connection)
end

function StrategyInteractEvent:run(connection)
if not connection:getIsServer() then
g_server:broadcastEvent(self, false, connection, self.object)
end

self.object:interactWithGuidanceStrategy(true)
end

function StrategyInteractEvent.sendEvent(object, noEventSend)
if noEventSend == nil or not noEventSend then
if g_server ~= nil then
g_server:broadcastEvent(StrategyInteractEvent:new(object), nil, nil, object)
else
g_client:getServerConnection():sendEvent(StrategyInteractEvent:new(object))
end
end
end
23 changes: 11 additions & 12 deletions src/gui/frames/GuidanceSteeringSettingsFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ function GuidanceSteeringSettingsFrame:onFrameOpen()
self.guidanceSteeringWidthIncrementElement:setTexts(increments)
self.guidanceSteeringOffsetIncrementElement:setTexts(increments)

self.guidanceSteeringShowLinesElement:setIsChecked(g_guidanceSteering:isShowGuidanceLinesEnabled())
self.guidanceSteeringSnapAngleElement:setIsChecked(g_guidanceSteering:isTerrainAngleSnapEnabled())

local vehicle = self.ui:getVehicle()
if vehicle ~= nil then
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
local data = spec.guidanceData

self.guidanceSteeringShowLinesElement:setIsChecked(g_guidanceSteering:isShowGuidanceLinesEnabled())
self.guidanceSteeringSnapAngleElement:setIsChecked(g_guidanceSteering:isTerrainAngleSnapEnabled())
self.guidanceSteeringEnableSteeringElement:setIsChecked(spec.guidanceSteeringIsActive)
self.guidanceSteeringAutoInvertOffsetElement:setIsChecked(spec.autoInvertOffset)

Expand All @@ -123,16 +122,16 @@ end
function GuidanceSteeringSettingsFrame:onFrameClose()
GuidanceSteeringSettingsFrame:superClass().onFrameClose(self)

-- Client only
g_guidanceSteering:setIsShowGuidanceLinesEnabled(self.guidanceSteeringShowLinesElement:getIsChecked())
g_guidanceSteering:setIsTerrainAngleSnapEnabled(self.guidanceSteeringSnapAngleElement:getIsChecked())
g_guidanceSteering:setIsGuidanceEnabled(self.guidanceSteeringEnableSteeringElement:getIsChecked())
g_guidanceSteering:setIsAutoInvertOffsetEnabled(self.guidanceSteeringAutoInvertOffsetElement:getIsChecked())

if self.allowSave then
-- Client only
g_guidanceSteering:setIsShowGuidanceLinesEnabled(self.guidanceSteeringShowLinesElement:getIsChecked())
g_guidanceSteering:setIsTerrainAngleSnapEnabled(self.guidanceSteeringSnapAngleElement:getIsChecked())
g_guidanceSteering:setIsGuidanceEnabled(self.guidanceSteeringEnableSteeringElement:getIsChecked())
g_guidanceSteering:setIsAutoInvertOffsetEnabled(self.guidanceSteeringAutoInvertOffsetElement:getIsChecked())

local vehicle = self.ui:getVehicle()
if vehicle ~= nil then
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
local data = spec.guidanceData

local state = self.guidanceSteeringWidthIncrementElement:getState()
Expand Down Expand Up @@ -217,7 +216,7 @@ function GuidanceSteeringSettingsFrame:onClickAutoWidth()
local vehicle = self.ui:getVehicle()

if vehicle ~= nil then
local spec = vehicle:guidanceSteering_getSpecTable("globalPositioningSystem")
local spec = vehicle.spec_globalPositioningSystem
local width, offset = GlobalPositioningSystem.getActualWorkWidth(spec.guidanceNode, vehicle)
self.currentGuidanceWidth = width
self.currentGuidanceOffset = offset
Expand Down
Loading

0 comments on commit ce70784

Please sign in to comment.