Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
uihintpanel.c
Go to the documentation of this file.
1 /*
2  Ui class for hints in in-game-menu
3 */
5 {
6  // Const
7  private const int m_SlideShowDelay = 25000; // The speed of the slideshow
8  private const string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
9  private const string m_DataPath = "Scripts/data/hints.json"; // Json path
10  // Widgets
11  private Widget m_RootFrame;
12  private Widget m_SpacerFrame;
13  private ButtonWidget m_UiLeftButton;
14  private ButtonWidget m_UiRightButton;
17  private ImageWidget m_UiHintImage;
19  // Data
21  private int m_PageIndex;
22 
23  // ---------------------------------------------------------
24 
25  // Constructor
26  void UiHintPanel(Widget parent_widget)
27  {
28  // Load Json File
30  // If load successful
31  if (m_ContentList)
32  {
33  // Build the layout
34  BuildLayout(parent_widget);
35  // Get random page index
37  // Populate the layout with data
39  // Start the slideshow
40  StartSlideshow();
41  }
42  else
43  {
44  Print("ERROR: UiHintPanel - Could not create the hint panel. The data are missing!");
45  }
46  }
47  // Destructor
48  void ~UiHintPanel()
49  {
50  StopSlideShow();
51  }
52 
53  // ------------------------------------------------------
54 
55  // Load content data from json file
56  private void LoadContentList()
57  {
58  JsonFileLoader<array<ref HintPage>>.JsonLoadFile( m_DataPath, m_ContentList );
59  }
60 
61  // Create and Build the layout
62  private void BuildLayout(Widget parent_widget)
63  {
64  // Create the layout
65  m_RootFrame = GetGame().GetWorkspace().CreateWidgets( m_RootPath, parent_widget );
66 
67  if (m_RootFrame)
68  {
69  // Find Widgets
70  m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
71  m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
72  m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
73  m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
74  m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
75  m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
76  m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
77  // Set handler
78  m_RootFrame.SetHandler(this);
79  }
80  }
81 
82  // Populate the hint with content
83  private void PopulateLayout()
84  {
85  if (m_RootFrame)
86  {
89  SetHintImage();
90  SetHintPaging();
91  }
92  }
93 
94  // -------------------------------------------
95  // Setters
96  private void SetHintHeadline()
97  {
98  m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
99  }
100  private void SetHintDescription()
101  {
102  m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
103  m_UiDescLabel.Update();
104  m_SpacerFrame.Update();
105  }
106  private void SetHintImage()
107  {
108  string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
109 
110  // If there is an image
111  if (image_path)
112  {
113  // Show the widget
114  m_UiHintImage.Show(true);
115  // Set the image path
116  m_UiHintImage.LoadImageFile(0, image_path);
117  }
118  else
119  {
120  // Hide the widget
121  m_UiHintImage.Show(false);
122  }
123  }
124  private void SetHintPaging()
125  {
126  m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
127  }
128  // Set a random page index
129  private void RandomizePageIndex()
130  {
131  m_PageIndex = Math.RandomInt(0, m_ContentList.Count() - 1);
132  }
133  // Show next hint page by incrementing the page index.
134  private void ShowNextPage()
135  {
136  // Update the page index
137  if ( m_PageIndex < m_ContentList.Count() - 1 )
138  {
139  m_PageIndex++;
140  }
141  else
142  {
143  m_PageIndex = 0;
144  }
145 
146  //Update the hint page
147  PopulateLayout();
148  }
149  // Show previous hint page by decreasing the page index.
150  private void ShowPreviousPage()
151  {
152  // Update the page index
153  if ( m_PageIndex == 0 )
154  {
155  m_PageIndex = m_ContentList.Count() - 1;
156  }
157  else
158  {
159  m_PageIndex--;
160 
161  }
162  //Update the hint page
163  PopulateLayout();
164  }
165 
166  // -------------------------------------------
167  // Slideshow
168 
169  // Creates new slidshow thread
170  private void StartSlideshow()
171  {
172  GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(SlideshowThread, m_SlideShowDelay);
173  }
174  // Slidshow thread - run code
175  private void SlideshowThread()
176  {
177  ShowNextPage();
178  }
179  // Stop the slide show
180  private void StopSlideShow()
181  {
182  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
183  }
184  // Restart the slide show
185  private void RestartSlideShow()
186  {
187  StopSlideShow();
188  StartSlideshow();
189  }
190 
191  // ----------------------------------------
192  // Layout manipulation
193 
194  override bool OnClick(Widget w, int x, int y, int button)
195  {
196  if (button == MouseState.LEFT)
197  {
198  switch (w)
199  {
200  case m_UiLeftButton:
201  {
203  return true;
204  }
205  case m_UiRightButton:
206  {
207  ShowNextPage();
208  return true;
209  }
210  }
211  }
212  return false;
213  }
214  override bool OnMouseEnter(Widget w, int x, int y)
215  {
216  if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
217  {
218  StopSlideShow();
219  return true;
220  }
221  return false;
222  }
223  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
224  {
225  if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
226  {
228  return true;
229  }
230  return false;
231  }
232 }
GetGame
proto native CGame GetGame()
StartSlideshow
protected void StartSlideshow()
Definition: uihintpanel.c:223
m_RootPath
protected string m_RootPath
Definition: uihintpanel.c:8
SetHintDescription
protected void SetHintDescription()
Definition: uihintpanel.c:126
y
Icon y
Print
proto void Print(void var)
Prints content of variable to console/log.
m_UiHeadlineLabel
protected TextWidget m_UiHeadlineLabel
Definition: uihintpanel.c:16
UiHintPanel
void UiHintPanel(Widget parent_widget)
Definition: uihintpanel.c:30
m_UiHintImage
protected ImageWidget m_UiHintImage
Definition: uihintpanel.c:17
m_SpacerFrame
protected Widget m_SpacerFrame
Definition: uihintpanel.c:12
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
m_UiPageingLabel
protected TextWidget m_UiPageingLabel
Definition: uihintpanel.c:18
ShowNextPage
protected void ShowNextPage()
Definition: uihintpanel.c:187
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
LoadContentList
protected void LoadContentList()
Definition: uihintpanel.c:80
RichTextWidget
Definition: gameplay.c:315
RestartSlideShow
protected void RestartSlideShow()
Definition: uihintpanel.c:238
TextWidget
Definition: enwidgets.c:219
m_ContentList
protected ref array< ref HintPage > m_ContentList
Definition: uihintpanel.c:20
m_SlideShowDelay
protected int m_SlideShowDelay
Definition: uihintpanel.c:7
m_UiRightButton
protected ButtonWidget m_UiRightButton
Definition: uihintpanel.c:14
SlideshowThread
protected void SlideshowThread()
Definition: uihintpanel.c:228
PopulateLayout
protected void PopulateLayout()
Definition: uihintpanel.c:109
StopSlideShow
protected void StopSlideShow()
Definition: uihintpanel.c:233
m_DataPath
const protected string m_DataPath
Definition: uihintpanel.c:9
MouseState
MouseState
Definition: ensystem.c:310
~UiHintPanel
void ~UiHintPanel()
Definition: uihintpanel.c:37
SetHintPaging
protected void SetHintPaging()
Definition: uihintpanel.c:153
array< ref HintPage >
SetHintHeadline
protected void SetHintHeadline()
Definition: uihintpanel.c:122
x
Icon x
RandomizePageIndex
protected void RandomizePageIndex()
Definition: uihintpanel.c:166
SetHintImage
protected void SetHintImage()
Definition: uihintpanel.c:135
m_UiDescLabel
protected RichTextWidget m_UiDescLabel
Definition: uihintpanel.c:15
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
Definition: uihintpanel.c:247
Math
Definition: enmath.c:6
m_RootFrame
protected Widget m_RootFrame
Definition: uihintpanel.c:11
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
ShowPreviousPage
protected void ShowPreviousPage()
Definition: uihintpanel.c:203
m_UiLeftButton
protected ButtonWidget m_UiLeftButton
Definition: uihintpanel.c:13
BuildLayout
protected void BuildLayout(Widget parent_widget)
Definition: uihintpanel.c:88
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
m_PageIndex
protected int m_PageIndex
Definition: uihintpanel.c:21