Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonCloseEditorUIComponent.c
Go to the documentation of this file.
1 class SCR_ButtonCloseEditorUIComponent: ScriptedWidgetComponent
2 {
3  [Attribute()]
4  protected string m_sButtonCloseName;
5 
6  [Attribute()]
7  protected string m_sButtonPlayerName;
8 
9  [Attribute()]
10  protected string m_sButtonRespawnMenuName;
11 
12  [Attribute()]
13  protected string m_sButtonRespawnMenuDisabledName;
14 
15  protected Widget m_ButtonClose;
16  protected Widget m_ButtonPlayer;
17  protected Widget m_ButtonRespawnMenu;
18  protected Widget m_ButtonRespawnMenuDisabled;
19 
20  protected const int BUTTON_CLOSE = 0;
21  protected const int BUTTON_PLAYER = 1;
22  protected const int BUTTON_RESPAWN_MENU = 2;
23  protected const int BUTTON_RESPAWN_MENU_DISABLED = 3;
24 
25  //------------------------------------------------------------------------------------------------
26  protected int GetButtonIndex()
27  {
28  //--- Player avatar exists - 'Play' button
29  IEntity localPlayer = SCR_PlayerController.GetLocalMainEntity();
30  if (localPlayer && !localPlayer.IsDeleted())
31  {
32  DamageManagerComponent damageManager = DamageManagerComponent.Cast(localPlayer.FindComponent(DamageManagerComponent));
33  if (!damageManager)
34  return BUTTON_PLAYER;
35 
36  if (damageManager.GetState() != EDamageState.DESTROYED)
37  return BUTTON_PLAYER;
38  }
39 
40  //--- 'Return to respawn menu' button based on available spawn points
41  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
42  if (factionManager)
43  {
44  int spawnPointCount;
45  Faction playerFaction = factionManager.GetPlayerFaction(SCR_PlayerController.GetLocalPlayerId());
46  if (playerFaction)
47  {
48  //--- Player has faction - return its spawn points
49  string playerFactionKey;
50  playerFactionKey = playerFaction.GetFactionKey();
51  spawnPointCount = SCR_SpawnPoint.GetSpawnPointCountForFaction(playerFactionKey)
52  }
53  else
54  {
55  //--- Player has no faction - return all spawn points
56  spawnPointCount = SCR_SpawnPoint.CountSpawnPoints();
57  }
58 
59  if (spawnPointCount == 0)
60  return BUTTON_RESPAWN_MENU_DISABLED;
61  else
62  return BUTTON_RESPAWN_MENU;
63  }
64 
65  //--- Default - plain 'Close' button
66  return BUTTON_CLOSE;
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  protected void Refresh()
71  {
72  int showButton = GetButtonIndex();
73 
74  m_ButtonClose.SetVisible(showButton == BUTTON_CLOSE);
75  m_ButtonPlayer.SetVisible(showButton == BUTTON_PLAYER);
76  m_ButtonRespawnMenu.SetVisible(showButton == BUTTON_RESPAWN_MENU);
77  m_ButtonRespawnMenuDisabled.SetVisible(showButton == BUTTON_RESPAWN_MENU_DISABLED);
78  }
79 
80  //------------------------------------------------------------------------------------------------
81  protected void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
82  {
83  Refresh();
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  protected void OnPlayerSpawnedOrDeleted(int playerId, IEntity player)
88  {
89  Refresh();
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  override bool OnClick(Widget w, int x, int y, int button)
94  {
95  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
96  if (editorManager)
97  GetGame().GetCallqueue().CallLater(editorManager.Close, 1, false, false); //--- Cannot trigger operation which closes UI from that UI's handler
98 
99  return false;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override void HandlerAttached(Widget w)
104  {
105  if (SCR_Global.IsEditMode())
106  return;
107 
108  m_ButtonPlayer = w.FindAnyWidget(m_sButtonPlayerName);
109  m_ButtonRespawnMenu = w.FindAnyWidget(m_sButtonRespawnMenuName);
110  m_ButtonRespawnMenuDisabled = w.FindAnyWidget(m_sButtonRespawnMenuDisabledName);
111  m_ButtonClose = w.FindAnyWidget(m_sButtonCloseName);
112 
114  if (gameMode)
115  {
116  gameMode.GetOnPlayerSpawned().Insert(OnPlayerSpawnedOrDeleted);
117  gameMode.GetOnPlayerKilled().Insert(OnPlayerKilled);
118  gameMode.GetOnPlayerDeleted().Insert(OnPlayerSpawnedOrDeleted);
119  }
120 
121  SCR_SpawnPoint.Event_OnSpawnPointCountChanged.Insert(Refresh);
122 
123  Refresh();
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  override void HandlerDeattached(Widget w)
128  {
130  if (gameMode)
131  {
132  gameMode.GetOnPlayerSpawned().Remove(OnPlayerSpawnedOrDeleted);
133  gameMode.GetOnPlayerKilled().Remove(OnPlayerKilled);
134  gameMode.GetOnPlayerDeleted().Remove(OnPlayerSpawnedOrDeleted);
135  }
136 
137  SCR_SpawnPoint.Event_OnSpawnPointCountChanged.Remove(Refresh);
138  }
139 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_SpawnPoint
Spawn point entity defines positions on which players can possibly spawn.
Definition: SCR_SpawnPoint.c:27
Instigator
Definition: Instigator.c:6
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonCloseEditorUIComponent
Definition: SCR_ButtonCloseEditorUIComponent.c:1
Faction
Definition: Faction.c:12
SCR_Global
Definition: Functions.c:6
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
DamageManagerComponent
Definition: DamageManagerComponent.c:12
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26