Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerHubWarningEditorUIComponent.c
Go to the documentation of this file.
2 {
3  protected static SCR_PlayerHubWarningEditorUIComponent m_Self;
4  protected Widget m_WidgetRef;
5 
6  protected bool m_bTimerSet;
7  protected int m_iCurrentWarningTimer;
8  protected SCR_PlayerHubAreaTriggerEntity m_LinkedHub;
9 
10  [Attribute()]
11  protected string m_sTimerText;
12 
13  protected TextWidget m_TimerText;
14 
15  protected IEntity m_PlayerRef;
16 
17  //======================== UPDATE TIMER ========================\\
18 
19  //------------------------------------------------------------------------------------------------
20  //Todo: this is not accurate
21  protected void UpdateTimer()
22  {
23  m_iCurrentWarningTimer--;
24  m_TimerText.SetText(m_iCurrentWarningTimer.ToString());
25 
26  if (m_iCurrentWarningTimer <= 0)
27  {
28  TimerDone();
29  HideTimer();
30  }
31  }
32 
33  //======================== TIMER COMPLETED/CANCELED ========================\\
34 
35  //------------------------------------------------------------------------------------------------
36  //Use: Replication.Time()
37  protected void TimerDone(bool canceled = false)
38  {
39  //Remove Update
40  GetGame().GetCallqueue().Remove(UpdateTimer);
41  m_Self.m_bTimerSet = false;
42 
43  //Timer done
44  m_LinkedHub.TimerDone(m_PlayerRef, canceled);
45 
46  HideTimer();
47  }
48 
49  //======================== SET TIMER ========================\\
50 
51  //------------------------------------------------------------------------------------------------
55  static void SetWarningTimer(int newTimer, SCR_PlayerHubAreaTriggerEntity newHub, IEntity playerInTrigger)
56  {
57  if (!m_Self)
58  return;
59 
60  //Cancel prev timer
61  if (m_Self.m_LinkedHub)
62  m_Self.m_LinkedHub.TimerDone(m_Self.m_PlayerRef, true);
63 
64  //Set Hub and player ref
65  m_Self.m_LinkedHub = newHub;
66  m_Self.m_PlayerRef = playerInTrigger;
67 
68 
69  //Set timer
70  m_Self.m_iCurrentWarningTimer = newTimer;
71  m_Self.m_bTimerSet = true;
72 
73  //Set Update
74  GetGame().GetCallqueue().CallLater(m_Self.UpdateTimer, 1000, true);
75 
76  m_Self.ShowTimer();
77  }
78 
79  //======================== CANCEL TIMER ========================\\
80 
81  //------------------------------------------------------------------------------------------------
85  static void CancelWarningTimer(SCR_PlayerHubAreaTriggerEntity hub, bool hubDestroyed = false)
86  {
87  if (!m_Self)
88  return;
89 
90  if (m_Self.m_bTimerSet && (!hubDestroyed || ( hubDestroyed && m_Self.m_LinkedHub == hub))){
91  m_Self.TimerDone(true);
92  }
93  }
94 
95 
96  //======================== VISIBILITY ========================\\
97 
98  //------------------------------------------------------------------------------------------------
99  protected void ShowTimer()
100  {
101  m_TimerText.SetText(m_iCurrentWarningTimer.ToString());
102  m_WidgetRef.SetVisible(true);
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected void HideTimer()
107  {
108  m_WidgetRef.SetVisible(false);
109  }
110 
111  //======================== INHERITED ========================\\
112 
113  //------------------------------------------------------------------------------------------------
114  override void HandlerAttached(Widget w)
115  {
116  m_WidgetRef = w;
117  m_Self = this;
118  m_TimerText = TextWidget.Cast(w.FindAnyWidget(m_sTimerText));
119 
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override void HandlerDeattached(Widget w)
124  {
125  if (m_bTimerSet && m_Self)
126  GetGame().GetCallqueue().Remove(m_Self.UpdateTimer);
127  }
128 }
SCR_PlayerHubAreaTriggerEntity
Definition: SCR_PlayerHubAreaTriggerEnity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_PlayerHubWarningEditorUIComponent
Definition: SCR_PlayerHubWarningEditorUIComponent.c:1