DayZ 1.24
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
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
36 {
37 DayZGame game = DayZGame.Cast(GetGame());
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 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
91
92 // Create and Build the layout
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 {
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 m_PageIndex++;
197 else
198 m_PageIndex = 0;
199
200 //Update the hint page
202 }
203 // Show previous hint page by decreasing the page index.
204 protected void ShowPreviousPage()
205 {
206 // Update the page index
207 if (m_PageIndex == 0)
208 m_PageIndex = m_ContentList.Count() - 1;
209 else
210 m_PageIndex--;
211
212 //Update the hint page
214 }
215
216 // -------------------------------------------
217 // Slideshow
218
219 // Creates new slidshow thread
220 protected void StartSlideshow()
221 {
223 }
224 // Slidshow thread - run code
225 protected void SlideshowThread()
226 {
227 ShowNextPage();
228 }
229 // Stop the slide show
230 protected void StopSlideShow()
231 {
232 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
233 }
234 // Restart the slide show
235 protected void RestartSlideShow()
236 {
239 }
240
241 // ----------------------------------------
242 // Layout manipulation
243
244 override bool OnClick(Widget w, int x, int y, int button)
245 {
246 if (button == MouseState.LEFT)
247 {
248 switch (w)
249 {
250 case m_UiLeftButton:
251 {
253 return true;
254 }
255 case m_UiRightButton:
256 {
257 ShowNextPage();
258 return true;
259 }
260 }
261 }
262 return false;
263 }
264 override bool OnMouseEnter(Widget w, int x, int y)
265 {
266 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
267 {
269 return true;
270 }
271 return false;
272 }
273 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
274 {
275 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
276 {
278 return true;
279 }
280 return false;
281 }
282}
283
284// ---------------------------------------------------------------------------------------------------------
286{
287 override void Init(DayZGame game)
288 {
289 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
290 super.Init(game);
291 }
292}
override Widget Init()
Definition DayZGame.c:120
Icon x
Icon y
Widget m_RootFrame
const string m_DataPath
ImageWidget m_UiHintImage
int m_PageIndex
ButtonWidget m_UiRightButton
string m_RootPath
Widget m_ParentWidget
bool m_Initialized
ref array< ref HintPage > m_ContentList
void SlideshowThread()
Widget m_SpacerFrame
RichTextWidget m_UiDescLabel
int m_SlideShowDelay
TextWidget m_UiHeadlineLabel
DayZGame m_Game
TextWidget m_UiPageingLabel
void UiHintPanel(Widget parent_widget)
ButtonWidget m_UiLeftButton
int m_PreviousRandomIndex
Definition EnMath.c:7
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void UiHintPanel(Widget parent_widget)
Definition UiHintPanel.c:35
void BuildLayout(Widget parent_widget)
Definition UiHintPanel.c:93
RichTextWidget m_UiDescLabel
Definition UiHintPanel.c:20
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
void Init(DayZGame game)
Definition UiHintPanel.c:51
override bool OnMouseEnter(Widget w, int x, int y)
ref array< ref HintPage > m_ContentList
Definition UiHintPanel.c:25
proto native CGame GetGame()
enum ShapeType ErrorEx
static proto bool IsInitialized()
Checks if DiagMenu is initialized.
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:126
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
MouseState
Definition EnSystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9