From 14c075abfccafcd99641cbef876e137b6a9b71a1 Mon Sep 17 00:00:00 2001 From: FlightControl_Master Date: Thu, 30 Nov 2017 12:01:44 +0100 Subject: [PATCH] * Fixed issue with Scoring menu not shown in single player. * Fixed issue with Scoring players table not being populated correctly, resulting in the scoring report for all players not being shown. Fixed. --- Moose Development/Moose/Core/Base.lua | 8 ++-- Moose Development/Moose/Core/Database.lua | 42 ++++++++++++++++++- .../Moose/Functional/Scoring.lua | 40 ++++++++++++++---- 3 files changed, 77 insertions(+), 13 deletions(-) diff --git a/Moose Development/Moose/Core/Base.lua b/Moose Development/Moose/Core/Base.lua index 0f09aa8e6..6bd74942a 100644 --- a/Moose Development/Moose/Core/Base.lua +++ b/Moose Development/Moose/Core/Base.lua @@ -718,9 +718,9 @@ do -- Scheduling nil ) - self._.Schedules[#self.Schedules+1] = ScheduleID + self._.Schedules[#self._.Schedules+1] = ScheduleID - return self._.Schedules + return self._.Schedules[#self._.Schedules] end --- Schedule a new time event. Note that the schedule will only take place if the scheduler is *started*. Even for a single schedule event, the scheduler needs to be started also. @@ -752,9 +752,9 @@ do -- Scheduling Stop ) - self._.Schedules[SchedulerFunction] = ScheduleID + self._.Schedules[#self._.Schedules+1] = ScheduleID - return self._.Schedules + return self._.Schedules[#self._.Schedules] end --- Stops the Schedule. diff --git a/Moose Development/Moose/Core/Database.lua b/Moose Development/Moose/Core/Database.lua index 3993898f3..a07e8fd73 100644 --- a/Moose Development/Moose/Core/Database.lua +++ b/Moose Development/Moose/Core/Database.lua @@ -325,7 +325,7 @@ function DATABASE:AddPlayer( UnitName, PlayerName ) if PlayerName then self:E( { "Add player for unit:", UnitName, PlayerName } ) self.PLAYERS[PlayerName] = UnitName - self.PLAYERUNITS[UnitName] = PlayerName + self.PLAYERUNITS[PlayerName] = self:FindUnit( UnitName ) self.PLAYERSJOINED[PlayerName] = PlayerName end end @@ -337,10 +337,48 @@ function DATABASE:DeletePlayer( UnitName, PlayerName ) if PlayerName then self:E( { "Clean player:", PlayerName } ) self.PLAYERS[PlayerName] = nil - self.PLAYERUNITS[UnitName] = PlayerName + self.PLAYERUNITS[PlayerName] = nil end end +--- Get the player table from the DATABASE. +-- The player table contains all unit names with the key the name of the player (PlayerName). +-- @param #DATABASE self +-- @usage +-- local Players = _DATABASE:GetPlayers() +-- for PlayerName, UnitName in pairs( Players ) do +-- .. +-- end +function DATABASE:GetPlayers() + return self.PLAYERS +end + + +--- Get the player table from the DATABASE, which contains all UNIT objects. +-- The player table contains all UNIT objects of the player with the key the name of the player (PlayerName). +-- @param #DATABASE self +-- @usage +-- local PlayerUnits = _DATABASE:GetPlayerUnits() +-- for PlayerName, PlayerUnit in pairs( PlayerUnits ) do +-- .. +-- end +function DATABASE:GetPlayerUnits() + return self.PLAYERUNITS +end + + +--- Get the player table from the DATABASE which have joined in the mission historically. +-- The player table contains all UNIT objects with the key the name of the player (PlayerName). +-- @param #DATABASE self +-- @usage +-- local PlayersJoined = _DATABASE:GetPlayersJoined() +-- for PlayerName, PlayerUnit in pairs( PlayersJoined ) do +-- .. +-- end +function DATABASE:GetPlayersJoined() + return self.PLAYERSJOINED +end + --- Instantiate new Groups within the DCSRTE. -- This method expects EXACTLY the same structure as a structure within the ME, and needs 2 additional fields defined: diff --git a/Moose Development/Moose/Functional/Scoring.lua b/Moose Development/Moose/Functional/Scoring.lua index 3831475fb..d87546143 100644 --- a/Moose Development/Moose/Functional/Scoring.lua +++ b/Moose Development/Moose/Functional/Scoring.lua @@ -281,8 +281,22 @@ function SCORING:New( GameName ) self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Hit, self._EventOnHit ) + self:HandleEvent( EVENTS.Birth ) self:HandleEvent( EVENTS.PlayerEnterUnit ) self:HandleEvent( EVENTS.PlayerLeaveUnit ) + + -- During mission startup, especially for single player, + -- iterate the database for the player that has joined, and add him to the scoring, and set the menu. + -- But this can only be started one second after the mission has started, so i need to schedule this ... + self.ScoringPlayerScan = BASE:ScheduleOnce( 1, + function() + for PlayerName, PlayerUnit in pairs( _DATABASE:GetPlayerUnits() ) do + self:_AddPlayerFromUnit( PlayerUnit ) + self:SetScoringMenu( PlayerUnit:GetGroup() ) + end + end + ) + -- Create the CSV file. self:OpenCSV( GameName ) @@ -569,6 +583,19 @@ function SCORING:SetCoalitionChangePenalty( CoalitionChangePenalty ) end +--- Sets the scoring menu. +-- @param #SCORING self +-- @return #SCORING +function SCORING:SetScoringMenu( ScoringGroup ) + local Menu = MENU_GROUP:New( ScoringGroup, 'Scoring' ) + local ReportGroupSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary report players in group', Menu, SCORING.ReportScoreGroupSummary, self, ScoringGroup ) + local ReportGroupDetailed = MENU_GROUP_COMMAND:New( ScoringGroup, 'Detailed report players in group', Menu, SCORING.ReportScoreGroupDetailed, self, ScoringGroup ) + local ReportToAllSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary report all players', Menu, SCORING.ReportScoreAllSummary, self, ScoringGroup ) + self:SetState( ScoringGroup, "ScoringMenu", Menu ) + return self +end + + --- Add a new player entering a Unit. -- @param #SCORING self -- @param Wrapper.Unit#UNIT UnitData @@ -811,17 +838,14 @@ function SCORING:_AddMissionScore( Mission, Text, Score ) end + --- Handles the OnPlayerEnterUnit event for the scoring. -- @param #SCORING self -- @param Core.Event#EVENTDATA Event function SCORING:OnEventPlayerEnterUnit( Event ) if Event.IniUnit then self:_AddPlayerFromUnit( Event.IniUnit ) - local Menu = MENU_GROUP:New( Event.IniGroup, 'Scoring' ) - local ReportGroupSummary = MENU_GROUP_COMMAND:New( Event.IniGroup, 'Summary report players in group', Menu, SCORING.ReportScoreGroupSummary, self, Event.IniGroup ) - local ReportGroupDetailed = MENU_GROUP_COMMAND:New( Event.IniGroup, 'Detailed report players in group', Menu, SCORING.ReportScoreGroupDetailed, self, Event.IniGroup ) - local ReportToAllSummary = MENU_GROUP_COMMAND:New( Event.IniGroup, 'Summary report all players', Menu, SCORING.ReportScoreAllSummary, self, Event.IniGroup ) - self:SetState( Event.IniUnit, "ScoringMenu", Menu ) + self:SetScoringMenu( Event.IniGroup ) end end @@ -830,7 +854,7 @@ end -- @param Core.Event#EVENTDATA Event function SCORING:OnEventPlayerLeaveUnit( Event ) if Event.IniUnit then - local Menu = self:GetState( Event.IniUnit, "ScoringMenu" ) -- Core.Menu#MENU_GROUP + local Menu = self:GetState( Event.IniUnit:GetGroup(), "ScoringMenu" ) -- Core.Menu#MENU_GROUP if Menu then -- TODO: Check if this fixes #281. --Menu:Remove() @@ -1661,9 +1685,11 @@ function SCORING:ReportScoreAllSummary( PlayerGroup ) local PlayerMessage = "" - self:T( "Report Score All Players" ) + self:T( { "Summary Score Report of All Players", Players = self.Players } ) for PlayerName, PlayerData in pairs( self.Players ) do + + self:T( { PlayerName = PlayerName, PlayerGroup = PlayerGroup } ) if PlayerName then