Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
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
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
18 protected ButtonWidget m_UiLeftButton;
19 protected ButtonWidget m_UiRightButton;
22 protected ImageWidget m_UiHintImage;
24 // Data
26 protected int m_PageIndex = int.MIN;
27 protected DayZGame m_Game;
28 protected bool m_Initialized;
30 protected int m_PreviousRandomIndex = int.MIN;
31
32 // ---------------------------------------------------------
33
34 // Constructor
35 void UiHintPanel(Widget parent_widget)
36 {
37 DayZGame game = DayZGame.Cast(g_Game);
38 m_ParentWidget = parent_widget;
39 Init(game);
40 }
41 // Destructor
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 g_Game 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
165 {
168 }
169
170 // Set a random page index
171 protected void RandomizePageIndex()
172 {
173 #ifdef DIAG_DEVELOPER
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
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}
string m_RootPath
void UiHintPanel(Widget parent_widget)
Definition enmath.c:7
map: item x vector(index, width, height)
Definition enwidgets.c:657
void BuildLayout(Widget parent_widget)
Definition uihintpanel.c:93
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void Init(DayZGame game)
Definition uihintpanel.c:51
ref array< ref HintPage > m_ContentList
Definition uihintpanel.c:25
RichTextWidget m_UiDescLabel
Definition uihintpanel.c:20
void UiHintPanel(Widget parent_widget)
Definition uihintpanel.c:35
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
override Widget Init()
Definition dayzgame.c:127
enum ShapeType ErrorEx
static proto bool IsInitialized()
Checks if DiagMenu is initialized.
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition enmath.c:54
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition enmath.c:126
MouseState
Definition ensystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9
Icon x
Icon y