Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
invitemenu.c
Go to the documentation of this file.
1 class InviteMenu extends UIScriptedMenu
2 {
3  private TextWidget m_LogoutTimeText;
4  private TextWidget m_DescriptionText;
5  private ButtonWidget m_bCancel;
6  private ButtonWidget m_bCancelConsole;
7  private int m_iTime;
8 
9  private ref FullTimeData m_FullTime;
10 
11  void InviteMenu()
12  {
13  m_iTime = 15;
14 
15  m_FullTime = new FullTimeData();
16 
17  if (GetGame().GetMission())
18  {
19  GetGame().GetMission().AddActiveInputExcludes({"menu"});
20 
21  GetGame().GetMission().GetHud().ShowHudUI(false);
22  GetGame().GetMission().GetHud().ShowQuickbarUI(false);
23  }
24  }
25 
26  void ~InviteMenu()
27  {
28  if (GetGame() && GetGame().GetMission())
29  {
30  GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
31 
32  GetGame().GetMission().GetHud().ShowHudUI(true);
33  GetGame().GetMission().GetHud().ShowQuickbarUI(true);
34 
35  GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
36  GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
37  }
38  }
39 
40  override Widget Init()
41  {
42  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_invite_dialog.layout");
43 
44  m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
45  m_DescriptionText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
46  m_bCancel = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancel"));
47 
48  // player should sit down if possible
49  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
50  if (player && player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
51  {
52  player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
53  player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
54  }
55 
56  if (GetGame().GetMission())
57  {
58  GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
59  GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
60  }
61 
62  OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
63 
64  SetTime(m_iTime);
65  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateTime, 1000, true);
66 
67  return layoutRoot;
68  }
69 
70  override void Update(float timeslice)
71  {
72  if (GetUApi().GetInputByID(UAUIBack).LocalPress())
73  Cancel();
74 
75  if (m_iTime <= 0)
76  {
77  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
78  string ip;
79  int port;
80  OnlineServices.GetInviteServerInfo(ip, port);
81  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.ConnectFromJoin, ip, port);
82  }
83  }
84 
85  override bool OnClick(Widget w, int x, int y, int button)
86  {
87  super.OnClick(w, x, y, button);
88 
89  if (w.GetUserID() == IDC_CANCEL)
90  {
91  Cancel();
92  return true;
93  }
94 
95  return false;
96  }
97 
98  void SetTime(int time)
99  {
100  m_iTime = time;
101  string text = "#layout_logout_dialog_until_logout_";
102 
103  TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
104 
105  if (m_FullTime.m_Days > 0)
106  text += "dhms";
107  else if (m_FullTime.m_Hours > 0)
108  text += "hms";
109  else if (m_FullTime.m_Minutes > 0)
110  text += "ms";
111  else
112  text += "s";
113 
114  text = Widget.TranslateString(text);
115  text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
116  m_LogoutTimeText.SetText(text);
117  }
118 
119  void UpdateTime()
120  {
121  if (m_iTime > 0)
122  {
123  m_iTime -= 1;
124  SetTime(m_iTime);
125  }
126  }
127 
128  void Cancel()
129  {
130  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
131 
132  g_Game.SetGameState(DayZGameState.IN_GAME);
133  g_Game.SetLoadState(DayZLoadState.CONNECT_CONTROLLER_SELECT);
134  Close();
135  }
136 
137  protected void OnInputPresetChanged()
138  {
139  #ifdef PLATFORM_CONSOLE
141  #endif
142  }
143 
144  protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
145  {
148  }
149 
150  protected void UpdateControlsElements()
151  {
152  RichTextWidget toolbarText = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
153  string context = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#dialog_cancel", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
154 
155  toolbarText.SetText(context);
156  }
157 
158  protected void UpdateControlsElementVisibility()
159  {
160  bool toolbarShow = false;
161  #ifdef PLATFORM_CONSOLE
162  toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
163  #endif
164 
165  layoutRoot.FindAnyWidget("BottomConsoleToolbar").Show(toolbarShow);
166  m_bCancel.Show(!toolbarShow);
167  }
168 }
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
IDC_CANCEL
const int IDC_CANCEL
Definition: constants.c:128
UpdateControlsElements
protected void UpdateControlsElements()
Definition: itemdropwarningmenu.c:92
Close
void Close()
y
Icon y
OnInputDeviceChanged
protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition: inventory.c:167
EInputDeviceType
EInputDeviceType
Definition: input.c:2
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
UpdateControlsElementVisibility
protected void UpdateControlsElementVisibility()
Definition: itemdropwarningmenu.c:100
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
OnInputPresetChanged
protected void OnInputPresetChanged()
Definition: inventory.c:160
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
EmoteLauncher
Definition: emotemanager.c:83
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
SetTime
void SetTime(float time)
DEPRECATED.
OnlineServices
Definition: onlineservices.c:1