DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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 // Const
8 protected int m_SlideShowDelay = 25000; // The speed of the slideshow
9 protected string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
10 protected const string m_DataPath = "Scripts/data/hints.json"; // Json path
11 // Widgets
14 protected ButtonWidget m_UiLeftButton;
15 protected ButtonWidget m_UiRightButton;
18 protected ImageWidget m_UiHintImage;
20 // Data
22 protected int m_PageIndex = int.MIN;
23 protected DayZGame m_Game;
24 protected bool m_Initialized;
26 protected int m_PreviousRandomIndex = int.MIN;
27
28 // ---------------------------------------------------------
29
30 // Constructor
31 void UiHintPanel(Widget parent_widget)
32 {
33 DayZGame game = DayZGame.Cast(GetGame());
34 m_ParentWidget = parent_widget;
35 Init(game);
36 }
37 // Destructor
39 {
41
42 if(m_RootFrame)
43 m_RootFrame.Unlink();
44 }
45
46
47 void Init(DayZGame game)
48 {
49 //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
50 //however for modding legacy support purposes, this was done without modifying the CTOR signature with the addition of the Init method,
51 //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
52
53 if (m_Initialized)
54 return;
55 if (!game)//is null when instantiated from DayZGame during loading before calling Init explicitly
56 return;
57 m_Initialized = true;
58
59 m_Game = game;
60 // Load Json File
62 // If load successful
63 if (m_ContentList)
64 {
65 // Build the layout
67 // Get random page index
69 // Populate the layout with data
71 // Start the slideshow
73 }
74 else
75 {
76 Print("ERROR: UiHintPanel - Could not create the hint panel. The data are missing!");
77 }
78 }
79
80 // ------------------------------------------------------
81
82 // Load content data from json file
83 protected void LoadContentList()
84 {
85 JsonFileLoader<array<ref HintPage>>.JsonLoadFile( m_DataPath, m_ContentList );
86 }
87
88 // Create and Build the layout
89 protected void BuildLayout(Widget parent_widget)
90 {
91 // Create the layout
92 m_RootFrame = m_Game.GetWorkspace().CreateWidgets( m_RootPath, parent_widget );
93
94 if (m_RootFrame)
95 {
96 // Find Widgets
97 m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
98 m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
99 m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
100 m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
101 m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
102 m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
103 m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
104 // Set handler
105 m_RootFrame.SetHandler(this);
106 }
107 }
108
109 // Populate the hint with content
110 protected void PopulateLayout()
111 {
112 if (m_RootFrame)
113 {
116 SetHintImage();
118 }
119 }
120
121 // -------------------------------------------
122 // Setters
123 protected void SetHintHeadline()
124 {
125 m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
126 }
127 protected void SetHintDescription()
128 {
129 #ifdef DEVELOPER
130 //Print("showing contents for page "+m_PageIndex);
131 #endif
132 m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
133 m_UiDescLabel.Update();
134 m_SpacerFrame.Update();
135 }
136 protected void SetHintImage()
137 {
138 string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
139
140 // If there is an image
141 if (image_path)
142 {
143 // Show the widget
144 m_UiHintImage.Show(true);
145 // Set the image path
146 m_UiHintImage.LoadImageFile(0, image_path);
147 }
148 else
149 {
150 // Hide the widget
151 m_UiHintImage.Show(false);
152 }
153 }
154 protected void SetHintPaging()
155 {
157 m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
158 }
159
161 {
164 }
165
166 // Set a random page index
167 protected void RandomizePageIndex()
168 {
169 Math.Randomize(m_Game.GetTime());
170 Math.RandomFloat01();//throw-away value, without calling this, the next random number is always the same, calling Math.Randomize(-1) makes no difference
174
175 }
176 // Show next hint page by incrementing the page index.
177 protected void ShowNextPage()
178 {
179 // Update the page index
180 if ( m_PageIndex < m_ContentList.Count() - 1 )
181 {
182 m_PageIndex++;
183 }
184 else
185 {
186 m_PageIndex = 0;
187 }
188
189 //Update the hint page
191 }
192 // Show previous hint page by decreasing the page index.
193 protected void ShowPreviousPage()
194 {
195 // Update the page index
196 if ( m_PageIndex == 0 )
197 {
198 m_PageIndex = m_ContentList.Count() - 1;
199 }
200 else
201 {
202 m_PageIndex--;
203
204 }
205 //Update the hint page
207 }
208
209 // -------------------------------------------
210 // Slideshow
211
212 // Creates new slidshow thread
213 protected void StartSlideshow()
214 {
216 }
217 // Slidshow thread - run code
218 protected void SlideshowThread()
219 {
220 ShowNextPage();
221 }
222 // Stop the slide show
223 protected void StopSlideShow()
224 {
225 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
226 }
227 // Restart the slide show
228 protected void RestartSlideShow()
229 {
232 }
233
234 // ----------------------------------------
235 // Layout manipulation
236
237 override bool OnClick(Widget w, int x, int y, int button)
238 {
239 if (button == MouseState.LEFT)
240 {
241 switch (w)
242 {
243 case m_UiLeftButton:
244 {
246 return true;
247 }
248 case m_UiRightButton:
249 {
250 ShowNextPage();
251 return true;
252 }
253 }
254 }
255 return false;
256 }
257 override bool OnMouseEnter(Widget w, int x, int y)
258 {
259 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
260 {
262 return true;
263 }
264 return false;
265 }
266 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
267 {
268 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
269 {
271 return true;
272 }
273 return false;
274 }
275}
276
277// ---------------------------------------------------------------------------------------------------------
278class UiHintPanelLoading extends UiHintPanel
279{
280 override void Init(DayZGame game)
281 {
282 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
283 super.Init(game);
285}
override Widget Init()
Definition DayZGame.c:122
Icon x
Icon y
protected DayZGame m_Game
protected TextWidget m_UiPageingLabel
protected int m_PreviousRandomIndex
protected RichTextWidget m_UiDescLabel
protected TextWidget m_UiHeadlineLabel
protected int m_PageIndex
protected Widget m_SpacerFrame
protected bool m_Initialized
protected int m_SlideShowDelay
protected void SlideshowThread()
protected Widget m_RootFrame
protected const string m_DataPath
protected ButtonWidget m_UiLeftButton
protected ImageWidget m_UiHintImage
protected string m_RootPath
protected Widget m_ParentWidget
void UiHintPanel(Widget parent_widget)
protected ref array< ref HintPage > m_ContentList
protected ButtonWidget m_UiRightButton
Definition EnMath.c:7
map: item x vector(index, width, height)
Definition EnWidgets.c:538
protected DayZGame m_Game
Definition UiHintPanel.c:23
protected TextWidget m_UiPageingLabel
Definition UiHintPanel.c:19
protected void StopSlideShow()
protected RichTextWidget m_UiDescLabel
Definition UiHintPanel.c:16
protected TextWidget m_UiHeadlineLabel
Definition UiHintPanel.c:17
protected void SetHintPaging()
protected Widget m_SpacerFrame
Definition UiHintPanel.c:13
protected bool m_Initialized
Definition UiHintPanel.c:24
protected void SlideshowThread()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
protected Widget m_RootFrame
Definition UiHintPanel.c:12
protected void ShowNextPage()
protected void ShowPreviousPage()
void Init(DayZGame game)
Definition UiHintPanel.c:47
protected ButtonWidget m_UiLeftButton
Definition UiHintPanel.c:14
protected ImageWidget m_UiHintImage
Definition UiHintPanel.c:18
protected void LoadContentList()
Definition UiHintPanel.c:83
protected void RestartSlideShow()
protected void BuildLayout(Widget parent_widget)
Definition UiHintPanel.c:89
protected Widget m_ParentWidget
Definition UiHintPanel.c:25
protected void StartSlideshow()
protected void SetHintImage()
protected void PopulateLayout()
void UiHintPanel(Widget parent_widget)
Definition UiHintPanel.c:31
protected void SetHintHeadline()
protected void RandomizePageIndex()
override bool OnMouseEnter(Widget w, int x, int y)
protected ref array< ref HintPage > m_ContentList
Definition UiHintPanel.c:21
protected ButtonWidget m_UiRightButton
Definition UiHintPanel.c:15
protected void SetHintDescription()
override bool OnClick(Widget w, int x, int y, int button)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Definition EnMath.c:53
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:106
MouseState
Definition EnSystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9