Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
uihintpanel.c
Go to the documentation of this file.
1/*
2 Ui class for hints in in-game-menu
3*/
4class UiHintPanel extends ScriptedWidgetEventHandler
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;
16 private TextWidget m_UiHeadlineLabel;
17 private ImageWidget m_UiHintImage;
18 private TextWidget m_UiPageingLabel;
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
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 {
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 {
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
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
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 {
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 {
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}
Widget m_RootFrame
const string m_DataPath
void RandomizePageIndex()
ImageWidget m_UiHintImage
void SetHintHeadline()
void SetHintImage()
void SetHintPaging()
int m_PageIndex
ButtonWidget m_UiRightButton
void ~UiHintPanel()
string m_RootPath
void SetHintDescription()
void StartSlideshow()
ref array< ref HintPage > m_ContentList
void StopSlideShow()
void RestartSlideShow()
override bool OnMouseEnter(Widget w, int x, int y)
void SlideshowThread()
Widget m_SpacerFrame
RichTextWidget m_UiDescLabel
void BuildLayout(Widget parent_widget)
int m_SlideShowDelay
TextWidget m_UiHeadlineLabel
void ShowPreviousPage()
TextWidget m_UiPageingLabel
void PopulateLayout()
void UiHintPanel(Widget parent_widget)
ButtonWidget m_UiLeftButton
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void LoadContentList()
void ShowNextPage()
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:151
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
MouseState
Definition ensystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9
Icon x
Icon y