Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionmenu.c
Go to the documentation of this file.
1 class ActionMenu
2 {
3  private const float FADE_IN_TIME = 0.3;
4  private const float FADE_OUT_TIME = 0.3;
5  private const float HIDE_MENU_TIME = 5;
6 
7  private ref WidgetFadeTimer m_FadeTimer;
8  private ref array<TextWidget> m_actionItems;
9  private TextWidget m_defaultActionWidget;
10  private Widget m_actionsPanelWidget;
11  private ref Timer m_hide_timer;
12 
13  private bool m_visible;
14 
15  void ActionMenu()
16  {
17  m_actionItems = new array<TextWidget>;
18  m_FadeTimer = new WidgetFadeTimer;
19  m_hide_timer = new Timer(CALL_CATEGORY_GUI);
20  m_visible = false;
21  }
22 
23  void Init(Widget actions_panel_widget, TextWidget default_action_widget)
24  {
25  m_defaultActionWidget = default_action_widget;
26  m_actionsPanelWidget = actions_panel_widget;
27  m_actionItems.Clear();
28  int i = 0;
29  TextWidget w = TextWidget.Cast( m_actionsPanelWidget.FindAnyWidget("ActionListItem" + i.ToString()) );
30 
31  while (w)
32  {
33  m_actionItems.Insert(w);
34  w.Show(false);
35  i++;
36  w = TextWidget.Cast( m_actionsPanelWidget.FindAnyWidget("ActionListItem" + i.ToString()) );
37  }
38 
39  m_defaultActionWidget.Show(false);
40  m_actionsPanelWidget.Show(true);
41  m_actionsPanelWidget.SetAlpha(0);
42  }
43 
44  void UpdateWidgets()
45  {
46 #ifdef DIAG_DEVELOPER
47  // tmp
48  bool newATSelection = DiagMenu.GetBool( DiagMenuIDs.MISC_ACTION_TARGETS_NEW, true );
49 
50  // read the action manager
51  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
52  TSelectableActionInfoArray actions = player.GetActionManager().GetSelectableActions();
53  int selectedActionIndex = player.GetActionManager().GetSelectedActionIndex();
54 
55  // clear state
56  m_defaultActionWidget.Show(false);
57  if ( actions.Count() <= 1 )
58  m_FadeTimer.FadeOut(m_actionsPanelWidget, FADE_OUT_TIME, true);
59  else
60  m_FadeTimer.FadeIn(m_actionsPanelWidget, FADE_IN_TIME, true);
61 
62  // update state
63  for (int i = 0; i < m_actionItems.Count(); i++)
64  {
65  TextWidget w = m_actionItems.Get(i);
66 
67  if (i < actions.Count())
68  {
69  TSelectableActionInfo actionInfo = actions.Get(i);
70  w.SetText(actionInfo.param3);
71 
72  if (i == selectedActionIndex)
73  {
74  w.SetColor(0xFFFFEC44);
75 
76  m_defaultActionWidget.SetText(actionInfo.param3);
77  if ( !newATSelection )
78  {
79  m_defaultActionWidget.Show(true);
80  }
81  }
82  else
83  {
84  w.SetColor(0xFFFFFFFF);
85  }
86 
87  w.Show(true);
88  }
89  else
90  {
91  w.Show(false);
92  }
93  }
94 
95  float sx;
96  float sy;
97  m_actionsPanelWidget.GetSize(sx, sy);
98  m_actionsPanelWidget.SetSize(sx, 8 + (actions.Count() * 32));
99 #endif
100  }
101 
102  void NextAction()
103  {
104  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
105  player.GetActionManager().SelectNextAction();
106 
107  UpdateWidgets();
108 
109  m_hide_timer.Run(HIDE_MENU_TIME, this, "HideWithFadeout");
110  }
111 
112  void PrevAction()
113  {
114  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
115  player.GetActionManager().SelectPrevAction();
116 
117  UpdateWidgets();
118 
119  m_hide_timer.Run(HIDE_MENU_TIME, this, "HideWithFadeout");
120  }
121 
122  void NextActionCategory()
123  {
124  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
125  player.GetActionManager().SelectNextActionCategory();
126 
127  UpdateWidgets();
128 
129  m_hide_timer.Run(HIDE_MENU_TIME, this, "HideWithFadeout");
130  }
131 
132  void PrevActionCategory()
133  {
134  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
135  player.GetActionManager().SelectPrevActionCategory();
136 
137  UpdateWidgets();
138 
139  m_hide_timer.Run(HIDE_MENU_TIME, this, "HideWithFadeout");
140  }
141 
142  void Show()
143  {
144  if( m_visible )
145  return;
146 
147  m_visible = true;
148  m_hide_timer.Run(HIDE_MENU_TIME, this, "HideWithFadeout");
149  }
150 
151  void Refresh()
152  {
153  if( !m_visible )
154  Show();
155 
156  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
157  if( player.GetActionManager().IsSelectableActionsChanged() )
158  UpdateWidgets();
159  }
160 
161  void Hide()
162  {
163  if( !m_visible )
164  return;
165 
166  m_visible = false;
167  m_hide_timer.Stop();
168  m_FadeTimer.Stop();
169  //m_defaultActionWidget.Show(false);
170  m_actionsPanelWidget.Show(false);
171  }
172 
173  void HideWithFadeout()
174  {
175  //m_defaultActionWidget.Show(false);
176  if (m_actionsPanelWidget.IsVisible())
177  m_FadeTimer.FadeOut(m_actionsPanelWidget, FADE_OUT_TIME, true);
178  }
179 }
GetGame
proto native CGame GetGame()
DiagMenu
Definition: endebug.c:232
Param3
Definition: entityai.c:95
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
DiagMenuIDs
DiagMenuIDs
Definition: ediagmenuids.c:1
PlayerBase
Definition: playerbaseclient.c:1
TextWidget
Definition: enwidgets.c:219
ActionMenu
Definition: actionmenu.c:1
array< TextWidget >
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Timer
Definition: dayzplayerimplement.c:62
Widget
Definition: enwidgets.c:189