Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
ingamemenu.c
Go to the documentation of this file.
1 class InGameMenu extends UIScriptedMenu
2 {
3  string m_ServerInfoText;
4 
5  protected Widget m_ContinueButton;
6  protected Widget m_SeparatorPanel;
7  protected Widget m_ExitButton;
8  protected Widget m_RestartButton;
9  protected Widget m_RespawnButton;
10  protected Widget m_RestartDeadRandomButton;
11  protected Widget m_RestartDeadCustomButton;
12  protected Widget m_OptionsButton;
13  protected Widget m_ServerInfoPanel;
14  protected Widget m_FavoriteButton;
15  protected Widget m_FavoriteImage;
16  protected Widget m_UnfavoriteImage;
17  protected Widget m_CopyInfoButton;
18 
19  protected ref TextWidget m_ModdedWarning;
20  protected ref TextWidget m_ServerIP;
21  protected ref TextWidget m_ServerPort;
22  protected ref TextWidget m_ServerName;
23 
24  protected ref UiHintPanel m_HintPanel;
25 
26  void ~InGameMenu()
27  {
28  HudShow(true);
29 
30  Mission mission = g_Game.GetMission();
31  if (mission)
32  mission.Continue();
33  }
34 
35  override Widget Init()
36  {
37  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_ingamemenu.layout");
38 
39  m_ContinueButton = layoutRoot.FindAnyWidget("continuebtn");
40  m_SeparatorPanel = layoutRoot.FindAnyWidget("separator_red");
41  m_ExitButton = layoutRoot.FindAnyWidget("exitbtn");
42  m_RestartButton = layoutRoot.FindAnyWidget("restartbtn");
43  m_RespawnButton = layoutRoot.FindAnyWidget("respawn_button");
44  m_RestartDeadRandomButton = layoutRoot.FindAnyWidget("respawn_button_random");
45  m_RestartDeadCustomButton = layoutRoot.FindAnyWidget("respawn_button_custom");
46  m_OptionsButton = layoutRoot.FindAnyWidget("optionsbtn");
47  m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
48  m_HintPanel = new UiHintPanel(layoutRoot.FindAnyWidget("hint_frame"));
49  m_ServerInfoPanel = layoutRoot.FindAnyWidget("server_info");
50  m_ServerIP = TextWidget.Cast(layoutRoot.FindAnyWidget("server_ip"));
51  m_ServerPort = TextWidget.Cast(layoutRoot.FindAnyWidget("server_port"));
52  m_ServerName = TextWidget.Cast(layoutRoot.FindAnyWidget("server_name"));
53  m_FavoriteImage = layoutRoot.FindAnyWidget("favorite_image");
54  m_UnfavoriteImage = layoutRoot.FindAnyWidget("unfavorite_image");
55  m_CopyInfoButton = layoutRoot.FindAnyWidget("copy_button");
56 
57  if (GetGame().IsMultiplayer())
58  {
59  ButtonSetText(m_RestartButton, "#main_menu_respawn");
60  }
61  else
62  {
63  ButtonSetText(m_RestartButton, "#main_menu_restart");
64  }
65 
66  HudShow(false);
67  SetGameVersion();
68  SetServerInfoVisibility(SetServerInfo() && g_Game.GetProfileOption(EDayZProfilesOptions.SERVERINFO_DISPLAY));
69  m_ModdedWarning.Show(g_Game.ReportModded());
70 
71  Mission mission = g_Game.GetMission();
72  if (mission)
73  mission.Pause();
74 
75  return layoutRoot;
76  }
77 
78  protected void SetGameVersion()
79  {
80  TextWidget version_widget = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
81  string version;
82  GetGame().GetVersion(version);
83  version_widget.SetText("#main_menu_version" + " " + version);
84 
85  #ifdef PREVIEW_BUILD
86  version_widget.SetText("THIS IS PREVIEW");
87  #endif
88  }
89 
90  protected bool SetServerInfo()
91  {
92  if (GetGame().IsMultiplayer())
93  {
94  MenuData menu_data = g_Game.GetMenuData();
95  GetServersResultRow info = OnlineServices.GetCurrentServerInfo();
96 
97  if (info)
98  {
99  m_ServerPort.SetText(info.m_HostPort.ToString());
100  m_ServerIP.SetText(info.m_HostIp);
101  m_ServerName.SetText(info.m_Name);
102  m_UnfavoriteImage.Show(info.m_Favorite);
103  m_FavoriteImage.Show(!info.m_Favorite);
104  m_ServerInfoText = "" + info.GetIpPort();
105 
106  return true;
107  }
108  //temporary, incomplete solution, OnlineServices.GetCurrentServerInfo() should be working!
109  else if (menu_data && menu_data.GetLastPlayedCharacter() != GameConstants.DEFAULT_CHARACTER_MENU_ID)
110  {
111  int char_id = menu_data.GetLastPlayedCharacter();
112  int port;
113  string address,name;
114 
115  menu_data.GetLastServerAddress(char_id,address);
116  port = menu_data.GetLastServerPort(char_id);
117  menu_data.GetLastServerName(char_id,name);
118  m_ServerPort.SetText(port.ToString());
119  m_ServerIP.SetText(address);
120  m_ServerName.SetText(name);
121  m_ServerInfoText = "" + address + ":" + port;
122 
123  return true;
124  }
125  else
126  {
127  g_Game.RefreshCurrentServerInfo();
128  }
129  }
130  return false;
131  }
132 
133  protected void HudShow(bool show)
134  {
135  Mission mission = GetGame().GetMission();
136  if (mission)
137  {
138  IngameHud hud = IngameHud.Cast(mission.GetHud());
139  if (hud)
140  {
141  hud.ShowHudUI(g_Game.GetProfileOption(EDayZProfilesOptions.HUD) && show);
142  hud.ShowQuickbarUI(g_Game.GetProfileOption(EDayZProfilesOptions.QUICKBAR) && show);
143  }
144  }
145  }
146 
147  override bool OnMouseEnter(Widget w, int x, int y)
148  {
149  ColorHighlight(w);
150  return true;
151  }
152 
153  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
154  {
155  ColorNormal(w);
156  return true;
157  }
158 
159  override bool OnClick(Widget w, int x, int y, int button)
160  {
161  super.OnClick(w, x, y, button);
162 
163  if (w == m_ContinueButton)
164  {
165  OnClick_Continue();
166  return true;
167  }
168  else if (w == m_RestartButton)
169  {
170  #ifdef DEVELOPER
171  if (GetGame().IsMultiplayer() || (GetGame().GetPlayer() && GetGame().GetPlayer().IsUnconscious()))
172  OnClick_Restart();
173  else
174  {
175  PluginDeveloper plugin = PluginDeveloper.GetInstance();
176  if (plugin)
177  plugin.ToggleMissionLoader();
178  }
179  #else
180  OnClick_Restart();
181  #endif
182  return true;
183  }
184  else if (w == m_RespawnButton)
185  {
186  OnClick_Respawn();
187  return true;
188  }
189  else if (w == m_OptionsButton)
190  {
191  OnClick_Options();
192  return true;
193  }
194  else if (w == m_ExitButton)
195  {
196  OnClick_Exit();
197  return true;
198  }
199  else if (w == m_CopyInfoButton)
200  {
201  GetGame().CopyToClipboard(m_ServerInfoText);
202  }
203 
204  return false;
205  }
206 
207  protected void OnClick_Continue()
208  {
209  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().Continue);
210  }
211 
212  protected void OnClick_Restart()
213  {
214  if (!GetGame().IsMultiplayer())
215  {
216  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().RestartMission);
217  }
218  else
219  {
220  OnClick_Respawn();
221  }
222  }
223 
224  protected void OnClick_Respawn()
225  {
226  Man player = GetGame().GetPlayer();
227 
228  if (player && player.IsUnconscious() && !player.IsDamageDestroyed())
229  {
230  GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
231  }
232  else
233  {
234  if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
235  {
236  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
237  }
238  else
239  {
240  GameRespawn(true);
241  }
242  }
243  }
244 
245  protected void OnClick_Options()
246  {
247  EnterScriptedMenu(MENU_OPTIONS);
248  }
249 
250  protected void OnClick_Exit()
251  {
252  GetGame().LogoutRequestTime();
253  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
254  }
255 
256  override bool OnModalResult(Widget w, int x, int y, int code, int result)
257  {
258  super.OnModalResult(w, x, y, code, result);
259  if (code == IDC_INT_EXIT && result == DBB_YES)
260  {
261  if (GetGame().IsMultiplayer())
262  {
263  GetGame().LogoutRequestTime();
264  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
265  }
266  else
267  {
268  // skip logout screen in singleplayer
269  GetGame().GetMission().AbortMission();
270  }
271  g_Game.CancelLoginTimeCountdown();
272  return true;
273  }
274  else if (code == IDC_INT_EXIT && result == DBB_NO)
275  {
276  g_Game.CancelLoginTimeCountdown();
277  }
278  else if (code == IDC_INT_RETRY && result == DBB_YES && GetGame().IsMultiplayer())
279  {
280  if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
281  {
282  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
283  }
284  else
285  {
286  GameRespawn(true);
287  }
288  return true;
289  }
290 
291  return false;
292  }
293 
294  override void Update(float timeslice)
295  {
296  super.Update(timeslice);
297 
298  UpdateGUI();
299  }
300 
301  protected void UpdateGUI()
302  {
303  #ifdef BULDOZER
304  m_RestartButton.Show(false);
305  m_RespawnButton.Show(false);
306  #else
307  Man player = GetGame().GetPlayer();
308  bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
309 
310  if (GetGame().IsMultiplayer())
311  {
312  m_RestartButton.Show(playerAlive && player.IsUnconscious() && !CfgGameplayHandler.GetDisableRespawnInUnconsciousness());
313  m_RespawnButton.Show(!playerAlive);
314  }
315  else
316  {
317  m_RestartButton.Show(true);
318  m_RespawnButton.Show(false);
319  m_SeparatorPanel.Show(playerAlive);
320  }
321 
322  m_ContinueButton.Show(playerAlive);
323  #endif
324  }
325 
326  void MenuRequestRespawn(UIScriptedMenu menu, bool random)
327  {
328  if (RespawnDialogue.Cast(menu))
329  GameRespawn(random);
330  }
331 
332  protected void GameRespawn(bool random)
333  {
334  GetGame().GetMenuDefaultCharacterData(false).SetRandomCharacterForced(random);
335  GetGame().RespawnPlayer();
336 
337  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
338  if (player)
339  {
340  player.SimulateDeath(true);
341  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
342  }
343 
344  MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
345  missionGP.DestroyAllMenus();
346  missionGP.SetPlayerRespawning(true);
347  missionGP.Continue();
348 
349  Close();
350  }
351 
352  protected void ColorHighlight(Widget w)
353  {
354  if (!w)
355  return;
356 
357  ButtonSetColor(w, ARGB(255, 0, 0, 0));
358  ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
359  }
360 
361  protected void ColorNormal(Widget w)
362  {
363  if (!w)
364  return;
365 
366  ButtonSetColor(w, ARGB(0, 0, 0, 0));
367  ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
368  }
369 
370  protected void ColorDisable(Widget w)
371  {
372  if (!w)
373  return;
374 
375  ButtonSetColor(w, ARGB(0, 0, 0, 0));
376  ButtonSetTextColor(w, ColorManager.COLOR_DISABLED_TEXT);
377  }
378 
379  protected void ButtonSetText(Widget w, string text)
380  {
381  if (!w)
382  return;
383 
384  TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
385  if (label)
386  label.SetText(text);
387 
388  }
389 
390  protected void ButtonSetColor(Widget w, int color)
391  {
392  Widget panel = w.FindWidget(w.GetName() + "_panel");
393  if (panel)
394  panel.SetColor(color);
395  }
396 
397  protected void ButtonSetTextColor(Widget w, int color)
398  {
399  TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
400  if (label)
401  label.SetColor(color);
402  }
403 
404  void SetServerInfoVisibility(bool show)
405  {
406  m_ServerInfoPanel.Show(show);
407  }
408 
410  void ToggleFavoriteServer();
411 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
Continue
void Continue()
Timer continue when it was paused.
Definition: tools.c:247
mission
Mission mission
Definition: displaystatus.c:28
EDayZProfilesOptions
EDayZProfilesOptions
Definition: edayzprofilesoptions.c:1
Mission
Mission class.
Definition: gameplay.c:670
Close
void Close()
y
Icon y
IDC_INT_RETRY
const int IDC_INT_RETRY
ingame menu
Definition: constants.c:148
UiHintPanel
void UiHintPanel(Widget parent_widget)
Definition: uihintpanel.c:30
ColorDisable
void ColorDisable(Widget w)
Definition: serverbrowsertab.c:720
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
m_HintPanel
ref UiHintPanelLoading m_HintPanel
Definition: dayzgame.c:691
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
PlayerBase
Definition: playerbaseclient.c:1
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
ColorNormal
void ColorNormal(Widget w)
Definition: serverbrowsertab.c:668
ColorManager
Definition: colormanager.c:1
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
ColorHighlight
void ColorHighlight(Widget w)
Definition: serverbrowsertab.c:619
EPlayerStates
EPlayerStates
Definition: eplayerstates.c:1
MENU_OPTIONS
const int MENU_OPTIONS
Definition: constants.c:173
CfgGameplayHandler
Definition: cfggameplayhandler.c:1
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
MENU_RESPAWN_DIALOGUE
const int MENU_RESPAWN_DIALOGUE
Definition: constants.c:199
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
MenuData
Definition: gameplay.c:895
GameConstants
Definition: constants.c:612
m_ModdedWarning
TextWidget m_ModdedWarning
Definition: dayzgame.c:676
Widget
Definition: enwidgets.c:189
IDC_INT_EXIT
const int IDC_INT_EXIT
Definition: constants.c:150
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
OnlineServices
Definition: onlineservices.c:1
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322