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*/
4
5class UiHintPanel extends ScriptedWidgetEventHandler
6{
7 #ifdef DIAG_DEVELOPER
8 static int m_ForcedIndex = -1;//only for debug purposes
9 #endif
10
11 // Const
12 protected int m_SlideShowDelay = 25000; // The speed of the slideshow
13 protected string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
14 protected const string m_DataPath = "scripts/data/hints.json"; // Json path
15 // Widgets
16 protected Widget m_RootFrame;
17 protected Widget m_SpacerFrame;
18 protected ButtonWidget m_UiLeftButton;
19 protected ButtonWidget m_UiRightButton;
21 protected TextWidget m_UiHeadlineLabel;
22 protected ImageWidget m_UiHintImage;
23 protected TextWidget m_UiPageingLabel;
24 // Data
26 protected int m_PageIndex = int.MIN;
27 protected DayZGame m_Game;
28 protected bool m_Initialized;
29 protected Widget m_ParentWidget;
30 protected int m_PreviousRandomIndex = int.MIN;
31
32 // ---------------------------------------------------------
33
34 // Constructor
35 void UiHintPanel(Widget parent_widget)
36 {
37 DayZGame game = DayZGame.Cast(GetGame());
38 m_ParentWidget = parent_widget;
39 Init(game);
40 }
41 // Destructor
42 void ~UiHintPanel()
43 {
45
46 if(m_RootFrame)
47 m_RootFrame.Unlink();
48 }
49
50
51 void Init(DayZGame game)
52 {
53 //as this class is now also being instantiated from within the DayZGame CTOR, where GetGame() does not work yet, we need a way to pass the game instance from DayZGame CTOR
54 //however for modding legacy support purposes, this was done without modifying the CTOR signature with the addition of the Init method,
55 //in order to keep compatibility with existing MODs, there is still a way to instantiate this class properly even without calling Init from the outside
56
57 if (m_Initialized)
58 return;
59 if (!game)//is null when instantiated from DayZGame during loading before calling Init explicitly
60 return;
61 m_Initialized = true;
62
63 m_Game = game;
64 // Load Json File
66 // If load successful
67 if (m_ContentList)
68 {
69 // Build the layout
71 // Get random page index
73 // Populate the layout with data
75 // Start the slideshow
77 }
78 else
79 ErrorEx("Could not create the hint panel. The data are missing!");
80 }
81
82 // ------------------------------------------------------
83
84 // Load content data from json file
85 protected void LoadContentList()
86 {
87 string errorMessage;
88 if (!JsonFileLoader<array<ref HintPage>>.LoadFile(m_DataPath, m_ContentList, errorMessage))
89 ErrorEx(errorMessage);
90 }
91
92 // Create and Build the layout
93 protected void BuildLayout(Widget parent_widget)
94 {
95 // Create the layout
96 m_RootFrame = m_Game.GetWorkspace().CreateWidgets(m_RootPath, parent_widget);
97
98 if (m_RootFrame)
99 {
100 // Find Widgets
101 m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
102 m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
103 m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
104 m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
105 m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
106 m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
107 m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
108 // Set handler
109 m_RootFrame.SetHandler(this);
110 }
111 }
112
113 // Populate the hint with content
114 protected void PopulateLayout()
115 {
116 if (m_RootFrame)
117 {
120 SetHintImage();
122 }
123 }
124
125 // -------------------------------------------
126 // Setters
127 protected void SetHintHeadline()
128 {
129 m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
130 }
131 protected void SetHintDescription()
132 {
133 #ifdef DEVELOPER
134 //Print("showing contents for page "+m_PageIndex);
135 #endif
136 m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
137 m_UiDescLabel.Update();
138 m_SpacerFrame.Update();
139 }
140 protected void SetHintImage()
141 {
142 string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
143
144 // If there is an image
145 if (image_path)
146 {
147 // Show the widget
148 m_UiHintImage.Show(true);
149 // Set the image path
150 m_UiHintImage.LoadImageFile(0, image_path);
151 }
152 else
153 {
154 // Hide the widget
155 m_UiHintImage.Show(false);
156 }
157 }
158 protected void SetHintPaging()
159 {
161 m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
162 }
163
164 void ShowRandomPage()
165 {
168 }
169
170 // Set a random page index
171 protected void RandomizePageIndex()
172 {
173 #ifdef DIAG_DEVELOPER
174 if (DiagMenu.IsInitialized())
175 {
176 if (m_ForcedIndex != -1)
177 {
178 m_PageIndex = Math.Clamp(m_ForcedIndex,0,m_ContentList.Count() - 1);
179 return;
180 }
181 }
182 #endif
183
184 Math.Randomize(m_Game.GetTime());
185 Math.RandomFloat01();//throw-away value, without calling this, the next random number is always the same, calling Math.Randomize(-1) makes no difference
187 m_PageIndex = Math.RandomIntInclusive(0, m_ContentList.Count() - 1);
189
190 }
191 // Show next hint page by incrementing the page index.
192 protected void ShowNextPage()
193 {
194 // Update the page index
195 if ( m_PageIndex < m_ContentList.Count() - 1 )
196 {
197 m_PageIndex++;
198 }
199 else
200 {
201 m_PageIndex = 0;
202 }
203
204 //Update the hint page
206 }
207 // Show previous hint page by decreasing the page index.
208 protected void ShowPreviousPage()
209 {
210 // Update the page index
211 if ( m_PageIndex == 0 )
212 {
213 m_PageIndex = m_ContentList.Count() - 1;
214 }
215 else
216 {
217 m_PageIndex--;
218
219 }
220 //Update the hint page
222 }
223
224 // -------------------------------------------
225 // Slideshow
226
227 // Creates new slidshow thread
228 protected void StartSlideshow()
229 {
231 }
232 // Slidshow thread - run code
233 protected void SlideshowThread()
234 {
235 ShowNextPage();
236 }
237 // Stop the slide show
238 protected void StopSlideShow()
239 {
240 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
241 }
242 // Restart the slide show
243 protected void RestartSlideShow()
244 {
247 }
248
249 // ----------------------------------------
250 // Layout manipulation
251
252 override bool OnClick(Widget w, int x, int y, int button)
253 {
254 if (button == MouseState.LEFT)
255 {
256 switch (w)
257 {
258 case m_UiLeftButton:
259 {
261 return true;
262 }
263 case m_UiRightButton:
264 {
265 ShowNextPage();
266 return true;
267 }
268 }
269 }
270 return false;
271 }
272 override bool OnMouseEnter(Widget w, int x, int y)
273 {
274 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
275 {
277 return true;
278 }
279 return false;
280 }
281 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
282 {
283 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
284 {
286 return true;
287 }
288 return false;
289 }
290}
291
292// ---------------------------------------------------------------------------------------------------------
293class UiHintPanelLoading extends UiHintPanel
294{
295 override void Init(DayZGame game)
296 {
297 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
298 super.Init(game);
299 }
300}
Widget m_RootFrame
const string m_DataPath
void RandomizePageIndex()
void ShowRandomPage()
ImageWidget m_UiHintImage
void SetHintHeadline()
void SetHintImage()
void SetHintPaging()
int m_PageIndex
ButtonWidget m_UiRightButton
void ~UiHintPanel()
string m_RootPath
void SetHintDescription()
Widget m_ParentWidget
bool m_Initialized
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
DayZGame m_Game
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)
int m_PreviousRandomIndex
void LoadContentList()
void ShowNextPage()
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override Widget Init()
Definition dayzgame.c:127
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:151
proto native CGame GetGame()
enum ShapeType ErrorEx
MouseState
Definition ensystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9
Icon x
Icon y