Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
logoutmenu.c
Go to the documentation of this file.
1
2class 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 #ifdef PLATFORM_CONSOLE
9 private ButtonWidget m_bCancelConsole;
10 #endif
11 private int m_iTime;
12
13 private ref FullTimeData m_FullTime;
14
15 void LogoutMenu()
16 {
17 m_iTime = 0;
18 g_Game.SetKeyboardHandle(this);
19
20 m_FullTime = new FullTimeData();
21 }
22
23 void ~LogoutMenu()
24 {
25 g_Game.SetKeyboardHandle(null);
26 if (GetGame().GetMission())
27 Cancel(); //cancels request on irregular close (player death, suicide, some mass-menu closure...)
28
29 m_FullTime = null;
30
31 #ifdef PLATFORM_CONSOLE
32 if (GetGame().GetMission())
33 {
34 GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
35 }
36 #endif
37 }
38
39 override Widget Init()
40 {
41 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_logout_dialog.layout");
42
43 m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
44 m_DescriptionText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
45 m_bLogoutNow = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bLogoutNow"));
46 m_bCancel = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancel"));
47
48 #ifdef PLATFORM_CONSOLE
49 m_bCancelConsole = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancelConsole"));
50 m_bCancel.Show(false);
51 m_bLogoutNow.Show(false);
52 #else
53 m_bCancel.Show(true);
54 m_bLogoutNow.Show(true);
55 layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
56 #endif
57
58 UpdateInfo();
59
60 // player should sit down if possible
61 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
62 if (player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
63 {
64 player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
65 player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
66 }
67
68 #ifdef PLATFORM_CONSOLE
69 if (GetGame().GetMission())
70 {
71 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
72 }
73
74 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
75 #endif
76
77 return layoutRoot;
78 }
79
80 void Show()
81 {
82 if (layoutRoot)
83 layoutRoot.Show(true);
84 }
85
86 void Hide()
87 {
88 if (layoutRoot)
89 layoutRoot.Show(false);
90 }
91
92 override bool OnClick(Widget w, int x, int y, int button)
93 {
94 super.OnClick(w, x, y, button);
95
96 if (w == m_bLogoutNow)
97 {
98 GetGame().GetMission().AbortMission();
99
100 return true;
101 }
102 #ifdef PLATFORM_CONSOLE
103 else if (w == m_bCancelConsole)
104 #else
105 else if (w == m_bCancel)
106 #endif
107 {
108 Hide();
109 Cancel();
110 return true;
111 }
112
113 return false;
114 }
115
116 override void Update(float timeslice)
117 {
118 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
119 {
120 Hide();
121 Cancel();
122 }
123 }
124
125 void SetLogoutTime()
126 {
127 m_LogoutTimeText.SetText(" ");
128 }
129
130 void SetTime(int time)
131 {
132 m_iTime = time;
133 string text = "#layout_logout_dialog_until_logout_";
134
135 TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
136
137 if (m_FullTime.m_Days > 0)
138 text += "dhms";
139 else if (m_FullTime.m_Hours > 0)
140 text += "hms";
141 else if (m_FullTime.m_Minutes > 0)
142 text += "ms";
143 else
144 text += "s";
145
146 text = Widget.TranslateString(text);
147 text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
148 m_LogoutTimeText.SetText(text);
149 }
150
151 void UpdateTime()
152 {
153
154 if (m_iTime > 0)
155 {
156 SetTime(--m_iTime);
157 }
158 else
159 {
160 Exit();
161 }
162 }
163
164 void UpdateInfo()
165 {
166 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
167 if (player.IsRestrained() || player.IsUnconscious())
168 {
169 // display killInfo
170 m_DescriptionText.SetText("#layout_logout_dialog_note_killed");
171 }
172 else
173 {
174 // hide killInfo
175 m_DescriptionText.SetText("#layout_logout_dialog_note");
176 }
177 }
178
179 void Exit()
180 {
181 // exit menu and logout screen
182 GetGame().GetMission().Continue();
183
184 // stop updating of logout screen
185 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
186
187 // go back to main menu
188 GetGame().GetMission().AbortMission();
189 }
190
191 void Cancel()
192 {
193 GetGame().GetMission().Continue();
194 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
195
196 // request logout cancel from server
198 }
199
200 #ifdef PLATFORM_CONSOLE
201 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
202 {
204 }
205
206 protected void UpdateControlsElementVisibility()
207 {
208 bool toolbarShow = false;
209 toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
210 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
211 m_bCancelConsole.Show(!toolbarShow);
212
213 if (toolbarShow)
214 {
215 RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
216 toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
217 }
218 }
219 #endif
220}
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition inventory.c:175
proto native void LogoutRequestCancel()
struct that keeps Time relevant information for future formatting
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition inpututils.c:167
static const float ICON_SCALE_TOOLBAR
Definition inpututils.c:15
void UpdateControlsElementVisibility()
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
override Widget Init()
Definition bookmenu.c:11
override bool OnClick(Widget w, int x, int y, int button)
Definition bookmenu.c:34
void Hide()
Definition dayzgame.c:170
DayZGame g_Game
Definition dayzgame.c:3868
void Show()
Definition dayzgame.c:162
proto native CGame GetGame()
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
Icon x
Icon y
EInputDeviceType
Definition input.c:3
PlayerBase GetPlayer()
void SetTime(float time)
DEPRECATED.
proto native UAInputAPI GetUApi()