Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignInfoDisplay.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_CampaignInfoDisplay : SCR_InfoDisplayExtended
3 {
4  protected static const int HUD_DURATION = 15000;
5  protected static const int SIZE_NORMAL = 20;
6  protected static const int SIZE_WINNER = 24;
7 
8  protected bool m_bInitDone;
9  protected bool m_bPeriodicRefresh;
10 
11  protected SCR_GameModeCampaign m_Campaign;
12 
13  protected Widget m_wCountdownOverlay;
14 
15  protected ImageWidget m_wLeftFlag;
16  protected ImageWidget m_wRightFlag;
17  protected ImageWidget m_wWinScoreSideLeft;
18  protected ImageWidget m_wWinScoreSideRight;
19 
20  protected RichTextWidget m_wLeftScore;
21  protected RichTextWidget m_wRightScore;
22  protected RichTextWidget m_wWinScore;
23  protected RichTextWidget m_wCountdown;
24  protected RichTextWidget m_wFlavour;
25 
26  //------------------------------------------------------------------------------------------------
27  override bool DisplayStartDrawInit(IEntity owner)
28  {
29  m_Campaign = SCR_GameModeCampaign.Cast(GetGame().GetGameMode());
30 
31  if (m_Campaign)
32  m_Campaign.GetOnMatchSituationChanged().Insert(UpdateHUD);
33 
34  return (m_Campaign != null);
35  }
36 
37  //------------------------------------------------------------------------------------------------
38  override void DisplayStartDraw(IEntity owner)
39  {
40  if (m_bInitDone)
41  return;
42 
43  m_bInitDone = true;
44 
45  if (m_Campaign.IsTutorial())
46  Show(false);
47 
48  m_wCountdownOverlay = m_wRoot.FindAnyWidget("Countdown");
49  m_wLeftFlag = ImageWidget.Cast(m_wRoot.FindAnyWidget("FlagSideBlue"));
50  m_wRightFlag = ImageWidget.Cast(m_wRoot.FindAnyWidget("FlagSideRed"));
51  m_wLeftScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ScoreBlue"));
52  m_wRightScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ScoreRed"));
53  m_wWinScore = RichTextWidget.Cast(m_wRoot.FindAnyWidget("TargetScore"));
54  m_wCountdown = RichTextWidget.Cast(m_wRoot.FindAnyWidget("CountdownWin"));
55  m_wFlavour = RichTextWidget.Cast(m_wRoot.FindAnyWidget("FlavourText"));
56  m_wWinScoreSideLeft = ImageWidget.Cast(m_wRoot.FindAnyWidget("ObjectiveLeft"));
57  m_wWinScoreSideRight = ImageWidget.Cast(m_wRoot.FindAnyWidget("ObjectiveRight"));
58 
59  SCR_Faction factionBLUFOR = m_Campaign.GetFactionByEnum(SCR_ECampaignFaction.BLUFOR);
60  SCR_Faction factionOPFOR = m_Campaign.GetFactionByEnum(SCR_ECampaignFaction.OPFOR);
61 
62  m_wLeftFlag.LoadImageTexture(0, factionBLUFOR.GetFactionFlag());
63  m_wRightFlag.LoadImageTexture(0, factionOPFOR.GetFactionFlag());
64 
65  UpdateHUD();
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override void DisplayUpdate(IEntity owner, float timeSlice)
70  {
71  if (!m_bPeriodicRefresh)
72  return;
73 
74  UpdateHUD();
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  protected void HideHUD()
79  {
80  Show(false, UIConstants.FADE_RATE_SLOW)
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  protected void UpdateHUDValues()
85  {
86  int winningFactionId = m_Campaign.GetWinningFactionId();
87  int controlPointsBLUFOR = m_Campaign.GetFactionByEnum(SCR_ECampaignFaction.BLUFOR).GetControlPointsHeld();
88  int controlPointsOPFOR = m_Campaign.GetFactionByEnum(SCR_ECampaignFaction.OPFOR).GetControlPointsHeld();
89  int controlPointsThreshold = m_Campaign.GetControlPointTreshold();
90 
91  m_wLeftScore.SetText(controlPointsBLUFOR.ToString());
92  m_wRightScore.SetText(controlPointsOPFOR.ToString());
93  m_wWinScore.SetText(controlPointsThreshold.ToString());
94 
95  if (winningFactionId == -1)
96  {
97  m_wFlavour.SetVisible(false);
98  m_wCountdownOverlay.SetVisible(false);
99  m_wLeftScore.SetDesiredFontSize(SIZE_NORMAL);
100  m_wRightScore.SetDesiredFontSize(SIZE_NORMAL);
101  m_wWinScoreSideRight.SetColor(Color.FromInt(Color.WHITE));
102  m_wWinScoreSideLeft.SetColor(Color.FromInt(Color.WHITE));
103  m_wRightScore.SetColor(Color.FromInt(Color.WHITE));
104  m_wLeftScore.SetColor(Color.FromInt(Color.WHITE));
105  m_wWinScore.SetColor(Color.FromInt(Color.WHITE));
106  SCR_PopUpNotification.GetInstance().Offset(false);
107  }
108  else
109  {
110  WorldTimestamp victoryTimestamp = m_Campaign.GetVictoryTimestamp();
111  WorldTimestamp pauseTimestamp = m_Campaign.GetVictoryPauseTimestamp();
112  bool isPaused = (pauseTimestamp != 0);
113  float winCountdown;
114 
115  SCR_Faction factionOPFOR = m_Campaign.GetFactionByEnum(SCR_ECampaignFaction.OPFOR);
116 
117  if (isPaused)
118  {
119  winCountdown = victoryTimestamp.DiffMilliseconds(pauseTimestamp);
120  m_wCountdown.SetColor(Color.FromInt(Color.GRAY));
121  }
122  else
123  {
124  ChimeraWorld world = GetGame().GetWorld();
125  winCountdown = victoryTimestamp.DiffMilliseconds(world.GetServerTimestamp());
126  m_wCountdown.SetColor(Color.FromInt(Color.WHITE));
127  m_bPeriodicRefresh = true;
128  }
129 
130  winCountdown = Math.Max(0, Math.Ceil(winCountdown / 1000));
131  Faction winner = GetGame().GetFactionManager().GetFactionByIndex(winningFactionId);
132  string shownTime = SCR_FormatHelper.GetTimeFormatting(winCountdown, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS, ETimeFormatParam.DAYS | ETimeFormatParam.HOURS | ETimeFormatParam.MINUTES);
133  m_wCountdown.SetText(shownTime);
134  SCR_PopUpNotification.GetInstance().Offset(true);
135 
136  m_wFlavour.SetTextFormat("#AR-ConflictHUD_FlavourText_IsWinning", winner.GetFactionName());
137  m_wWinScore.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
138  m_wWinScoreSideRight.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
139  m_wWinScoreSideLeft.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
140 
141  if (winner == factionOPFOR)
142  {
143  m_wRightScore.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
144  m_wLeftScore.SetColor(Color.FromInt(Color.WHITE));
145  m_wRightScore.SetDesiredFontSize(SIZE_WINNER);
146  m_wLeftScore.SetDesiredFontSize(SIZE_NORMAL);
147  }
148  else
149  {
150  m_wLeftScore.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
151  m_wRightScore.SetColor(Color.FromInt(Color.WHITE));
152  m_wLeftScore.SetDesiredFontSize(SIZE_WINNER);
153  m_wRightScore.SetDesiredFontSize(SIZE_NORMAL);
154  }
155 
156  m_wCountdownOverlay.SetVisible(true);
157  m_wFlavour.SetVisible(true);
158  }
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  protected void UpdateHUD()
163  {
164  m_bPeriodicRefresh = false;
165 
166  if (!m_wRoot || !m_bInitDone)
167  return;
168 
169  GetGame().GetCallqueue().Remove(HideHUD);
170 
171  if (m_Campaign.IsTutorial())
172  return;
173  else
174  Show(true, UIConstants.FADE_RATE_FAST);
175 
176  if (m_Campaign.GetIsMatchOver())
177  {
178  Show(false);
179  return;
180  }
181 
182  UpdateHUDValues();
183 
184  if (!m_bPeriodicRefresh && !m_Campaign.GetVictoryTimestamp())
185  GetGame().GetCallqueue().CallLater(HideHUD, HUD_DURATION);
186  }
187 };
m_wFlavour
protected RichTextWidget m_wFlavour
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:63
ChimeraWorld
Definition: ChimeraWorld.c:12
m_wCountdown
protected RichTextWidget m_wCountdown
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:62
SCR_ECampaignFaction
SCR_ECampaignFaction
Definition: SCR_CampaignFactionManager.c:130
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
ETimeFormatParam
ETimeFormatParam
Definition: ETimeFormatParam.c:4
UIColors
Definition: Constants.c:16
SCR_CampaignInfoDisplay
Definition: SCR_CampaignInfoDisplay.c:2
Faction
Definition: Faction.c:12
m_wCountdownOverlay
protected Widget m_wCountdownOverlay
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:61
SCR_Faction
Definition: SCR_Faction.c:6