DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
UiHintPanel.c
См. документацию.
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(GetGame());
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 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
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}
override Widget Init()
Определения DayZGame.c:127
Icon x
Icon y
string m_RootPath
Определения UiHintPanel.c:302
void UiHintPanel(Widget parent_widget)
Определения UiHintPanel.c:324
Определения EnDebug.c:233
Определения EnMath.c:7
Определения gameplay.c:317
int m_PreviousRandomIndex
Определения UiHintPanel.c:30
void RestartSlideShow()
Определения UiHintPanel.c:243
void UiHintPanel(Widget parent_widget)
Определения UiHintPanel.c:35
TextWidget m_UiHeadlineLabel
Определения UiHintPanel.c:21
void RandomizePageIndex()
Определения UiHintPanel.c:171
void ShowRandomPage()
Определения UiHintPanel.c:164
void PopulateLayout()
Определения UiHintPanel.c:114
void BuildLayout(Widget parent_widget)
Определения UiHintPanel.c:93
TextWidget m_UiPageingLabel
Определения UiHintPanel.c:23
void SetHintHeadline()
Определения UiHintPanel.c:127
int m_SlideShowDelay
Определения UiHintPanel.c:12
void SetHintPaging()
Определения UiHintPanel.c:158
RichTextWidget m_UiDescLabel
Определения UiHintPanel.c:20
ButtonWidget m_UiRightButton
Определения UiHintPanel.c:19
string m_RootPath
Определения UiHintPanel.c:13
void ShowPreviousPage()
Определения UiHintPanel.c:208
Widget m_ParentWidget
Определения UiHintPanel.c:29
void StopSlideShow()
Определения UiHintPanel.c:238
void SlideshowThread()
Определения UiHintPanel.c:233
Widget m_SpacerFrame
Определения UiHintPanel.c:17
void SetHintDescription()
Определения UiHintPanel.c:131
void ~UiHintPanel()
Определения UiHintPanel.c:42
ImageWidget m_UiHintImage
Определения UiHintPanel.c:22
void StartSlideshow()
Определения UiHintPanel.c:228
Widget m_RootFrame
Определения UiHintPanel.c:16
bool m_Initialized
Определения UiHintPanel.c:28
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения UiHintPanel.c:281
override bool OnClick(Widget w, int x, int y, int button)
Определения UiHintPanel.c:252
void LoadContentList()
Определения UiHintPanel.c:85
void Init(DayZGame game)
Определения UiHintPanel.c:51
void Init()
Определения MainMenuPromo.c:48
DayZGame m_Game
Определения UiHintPanel.c:27
void SetHintImage()
Определения UiHintPanel.c:140
ButtonWidget m_UiLeftButton
Определения UiHintPanel.c:18
void ShowNextPage()
Определения UiHintPanel.c:192
override bool OnMouseEnter(Widget w, int x, int y)
Определения UiHintPanel.c:272
int m_PageIndex
Определения UiHintPanel.c:26
const string m_DataPath
Определения UiHintPanel.c:14
ref array< ref HintPage > m_ContentList
Определения UiHintPanel.c:25
map: item x vector(index, width, height)
Определения EnWidgets.c:651
Определения EnWidgets.c:220
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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].
Определения 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].
Определения EnMath.c:54
MouseState
Определения EnSystem.c:311
const int CALL_CATEGORY_GUI
Определения tools.c:9