Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
logoutmenu.c
Go to the documentation of this file.
1 
2 class LogoutMenu extends UIScriptedMenu
3 {
4  private TextWidget m_LogoutTimeText;
5  private TextWidget m_DescriptionText;
6  private ButtonWidget m_bLogoutNow;
7  private ButtonWidget m_bCancel;
8  private ButtonWidget m_bCancelConsole;
9  private int m_iTime;
10 
11  private ref FullTimeData m_FullTime;
12 
13  void LogoutMenu()
14  {
15  m_iTime = 0;
16  g_Game.SetKeyboardHandle(this);
17 
18  m_FullTime = new FullTimeData();
19  }
20 
21  void ~LogoutMenu()
22  {
23  g_Game.SetKeyboardHandle(null);
24  if (GetGame().GetMission())
25  Cancel(); //cancels request on irregular close (player death, suicide, some mass-menu closure...)
26 
27  m_FullTime = null;
28  }
29 
30  override Widget Init()
31  {
32  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_logout_dialog.layout");
33 
34  m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
35  m_DescriptionText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
36  m_bLogoutNow = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bLogoutNow"));
37  m_bCancel = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancel"));
38 
39  #ifdef PLATFORM_CONSOLE
40  m_bCancel.Show(false);
41  m_bLogoutNow.Show(false);
42 
43  layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
44  RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
45  toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
46  #else
47  m_bCancel.Show(true);
48  m_bLogoutNow.Show(true);
49  layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
50  #endif
51 
52  UpdateInfo();
53 
54  // player should sit down if possible
55  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
56  if (player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
57  {
58  player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
59  player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
60  }
61 
62  return layoutRoot;
63  }
64 
65  void Show()
66  {
67  if (layoutRoot)
68  layoutRoot.Show(true);
69  }
70 
71  void Hide()
72  {
73  if (layoutRoot)
74  layoutRoot.Show(false);
75  }
76 
77  override bool OnClick(Widget w, int x, int y, int button)
78  {
79  super.OnClick(w, x, y, button);
80 
81  if (w == m_bLogoutNow)
82  {
83  GetGame().GetMission().AbortMission();
84 
85  return true;
86  }
87  else if (w == m_bCancel)
88  {
89  Hide();
90  Cancel();
91  return true;
92  }
93 
94  return false;
95  }
96 
97  override void Update(float timeslice)
98  {
99  if (GetUApi().GetInputByID(UAUIBack).LocalPress())
100  {
101  Hide();
102  Cancel();
103  }
104  }
105 
106  void SetLogoutTime()
107  {
108  m_LogoutTimeText.SetText(" ");
109  }
110 
111  void SetTime(int time)
112  {
113  m_iTime = time;
114  string text = "#layout_logout_dialog_until_logout_";
115 
116  TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
117 
118  if (m_FullTime.m_Days > 0)
119  text += "dhms";
120  else if (m_FullTime.m_Hours > 0)
121  text += "hms";
122  else if (m_FullTime.m_Minutes > 0)
123  text += "ms";
124  else
125  text += "s";
126 
127  text = Widget.TranslateString(text);
128  text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
129  m_LogoutTimeText.SetText(text);
130  }
131 
132  void UpdateTime()
133  {
134 
135  if (m_iTime > 0)
136  {
137  SetTime(--m_iTime);
138  }
139  else
140  {
141  Exit();
142  }
143  }
144 
145  void UpdateInfo()
146  {
147  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
148  if (player.IsRestrained() || player.IsUnconscious())
149  {
150  // display killInfo
151  m_DescriptionText.SetText("#layout_logout_dialog_note_killed");
152  }
153  else
154  {
155  // hide killInfo
156  m_DescriptionText.SetText("#layout_logout_dialog_note");
157  }
158  }
159 
160  void Exit()
161  {
162  // exit menu and logout screen
163  GetGame().GetMission().Continue();
164 
165  // stop updating of logout screen
166  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
167 
168  // go back to main menu
169  GetGame().GetMission().AbortMission();
170  }
171 
172  void Cancel()
173  {
174  GetGame().GetMission().Continue();
175  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
176 
177  // request logout cancel from server
178  GetGame().LogoutRequestCancel();
179  }
180 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
InputUtils
Definition: inpututils.c:1
Show
proto native void Show(bool show, bool immedUpdate=true)
Exit
proto native void Exit()
y
Icon y
RichTextWidget
Definition: gameplay.c:315
PlayerBase
Definition: playerbaseclient.c:1
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
Cancel
proto native void Cancel()
cancels action
TextWidget
Definition: enwidgets.c:219
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
EmoteConstants
Definition: constants.c:348
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
x
Icon x
FullTimeData
struct that keeps Time relevant information for future formatting
Definition: timeconversions.c:4
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
EmoteLauncher
Definition: emotemanager.c:83
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
SetTime
void SetTime(float time)
DEPRECATED.
Hide
void Hide()
Definition: dayzgame.c:165