Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
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
class
UiHintPanel
extends
ScriptedWidgetEventHandler
5
{
6
// Const
7
private
const
int
m_SlideShowDelay
= 25000;
// The speed of the slideshow
8
private
const
string
m_RootPath
=
"Gui/layouts/new_ui/hints/in_game_hints.layout"
;
// Layout path
9
private
const
string
m_DataPath
=
"Scripts/data/hints.json"
;
// Json path
10
// Widgets
11
private
Widget
m_RootFrame
;
12
private
Widget
m_SpacerFrame
;
13
private
ButtonWidget
m_UiLeftButton
;
14
private
ButtonWidget
m_UiRightButton
;
15
private
RichTextWidget
m_UiDescLabel
;
16
private
TextWidget
m_UiHeadlineLabel
;
17
private
ImageWidget
m_UiHintImage
;
18
private
TextWidget
m_UiPageingLabel
;
19
// Data
20
private
ref
array<ref HintPage>
m_ContentList
;
21
private
int
m_PageIndex
;
22
23
// ---------------------------------------------------------
24
25
// Constructor
26
void
UiHintPanel
(
Widget
parent_widget)
27
{
28
// Load Json File
29
LoadContentList
();
30
// If load successful
31
if
(
m_ContentList
)
32
{
33
// Build the layout
34
BuildLayout
(parent_widget);
35
// Get random page index
36
RandomizePageIndex
();
37
// Populate the layout with data
38
PopulateLayout
();
39
// Start the slideshow
40
StartSlideshow
();
41
}
42
else
43
{
44
Print
(
"ERROR: UiHintPanel - Could not create the hint panel. The data are missing!"
);
45
}
46
}
47
// Destructor
48
void
~UiHintPanel
()
49
{
50
StopSlideShow
();
51
}
52
53
// ------------------------------------------------------
54
55
// Load content data from json file
56
private
void
LoadContentList
()
57
{
58
JsonFileLoader<array<ref HintPage>>.JsonLoadFile(
m_DataPath
,
m_ContentList
);
59
}
60
61
// Create and Build the layout
62
private
void
BuildLayout
(
Widget
parent_widget)
63
{
64
// Create the layout
65
m_RootFrame
=
GetGame
().GetWorkspace().CreateWidgets(
m_RootPath
, parent_widget );
66
67
if
(
m_RootFrame
)
68
{
69
// Find Widgets
70
m_SpacerFrame
=
m_RootFrame
.FindAnyWidget(
"GridSpacerWidget1"
);
71
m_UiLeftButton
= ButtonWidget.Cast(
m_RootFrame
.FindAnyWidget(
"LeftButton"
));
72
m_UiRightButton
= ButtonWidget.Cast(
m_RootFrame
.FindAnyWidget(
"RightButton"
));
73
m_UiHeadlineLabel
=
TextWidget
.Cast(
m_RootFrame
.FindAnyWidget(
"HeadlineLabel"
));
74
m_UiDescLabel
=
RichTextWidget
.Cast(
m_RootFrame
.FindAnyWidget(
"HintDescLabel"
));
75
m_UiHintImage
= ImageWidget.Cast(
m_RootFrame
.FindAnyWidget(
"HintImage"
));
76
m_UiPageingLabel
=
TextWidget
.Cast(
m_RootFrame
.FindAnyWidget(
"PageInfoLabel"
));
77
// Set handler
78
m_RootFrame
.SetHandler(
this
);
79
}
80
}
81
82
// Populate the hint with content
83
private
void
PopulateLayout
()
84
{
85
if
(
m_RootFrame
)
86
{
87
SetHintHeadline
();
88
SetHintDescription
();
89
SetHintImage
();
90
SetHintPaging
();
91
}
92
}
93
94
// -------------------------------------------
95
// Setters
96
private
void
SetHintHeadline
()
97
{
98
m_UiHeadlineLabel
.SetText(
m_ContentList
.Get(
m_PageIndex
).GetHeadlineText());
99
}
100
private
void
SetHintDescription
()
101
{
102
m_UiDescLabel
.SetText(
m_ContentList
.Get(
m_PageIndex
).GetDescriptionText());
103
m_UiDescLabel
.Update();
104
m_SpacerFrame
.Update();
105
}
106
private
void
SetHintImage
()
107
{
108
string
image_path =
m_ContentList
.Get(
m_PageIndex
).GetImagePath();
109
110
// If there is an image
111
if
(image_path)
112
{
113
// Show the widget
114
m_UiHintImage
.Show(
true
);
115
// Set the image path
116
m_UiHintImage
.LoadImageFile(0, image_path);
117
}
118
else
119
{
120
// Hide the widget
121
m_UiHintImage
.Show(
false
);
122
}
123
}
124
private
void
SetHintPaging
()
125
{
126
m_UiPageingLabel
.SetText(
string
.Format(
"%1 / %2"
,
m_PageIndex
+ 1,
m_ContentList
.Count()));
127
}
128
// Set a random page index
129
private
void
RandomizePageIndex
()
130
{
131
m_PageIndex
=
Math
.
RandomInt
(0,
m_ContentList
.Count() - 1);
132
}
133
// Show next hint page by incrementing the page index.
134
private
void
ShowNextPage
()
135
{
136
// Update the page index
137
if
(
m_PageIndex
<
m_ContentList
.Count() - 1 )
138
{
139
m_PageIndex
++;
140
}
141
else
142
{
143
m_PageIndex
= 0;
144
}
145
146
//Update the hint page
147
PopulateLayout
();
148
}
149
// Show previous hint page by decreasing the page index.
150
private
void
ShowPreviousPage
()
151
{
152
// Update the page index
153
if
(
m_PageIndex
== 0 )
154
{
155
m_PageIndex
=
m_ContentList
.Count() - 1;
156
}
157
else
158
{
159
m_PageIndex
--;
160
161
}
162
//Update the hint page
163
PopulateLayout
();
164
}
165
166
// -------------------------------------------
167
// Slideshow
168
169
// Creates new slidshow thread
170
private
void
StartSlideshow
()
171
{
172
GetGame
().GetCallQueue(
CALL_CATEGORY_GUI
).CallLater(
SlideshowThread
,
m_SlideShowDelay
);
173
}
174
// Slidshow thread - run code
175
private
void
SlideshowThread
()
176
{
177
ShowNextPage
();
178
}
179
// Stop the slide show
180
private
void
StopSlideShow
()
181
{
182
GetGame
().GetCallQueue(
CALL_CATEGORY_GUI
).Remove(
SlideshowThread
);
183
}
184
// Restart the slide show
185
private
void
RestartSlideShow
()
186
{
187
StopSlideShow
();
188
StartSlideshow
();
189
}
190
191
// ----------------------------------------
192
// Layout manipulation
193
194
override
bool
OnClick
(
Widget
w,
int
x
,
int
y
,
int
button)
195
{
196
if
(button ==
MouseState
.LEFT)
197
{
198
switch
(w)
199
{
200
case
m_UiLeftButton
:
201
{
202
ShowPreviousPage
();
203
return
true
;
204
}
205
case
m_UiRightButton
:
206
{
207
ShowNextPage
();
208
return
true
;
209
}
210
}
211
}
212
return
false
;
213
}
214
override
bool
OnMouseEnter
(
Widget
w,
int
x
,
int
y
)
215
{
216
if
(w ==
m_RootPath
|| w ==
m_UiLeftButton
|| w ==
m_UiRightButton
)
217
{
218
StopSlideShow
();
219
return
true
;
220
}
221
return
false
;
222
}
223
override
bool
OnMouseLeave
(
Widget
w,
Widget
enterW,
int
x
,
int
y
)
224
{
225
if
(w ==
m_RootPath
|| w ==
m_UiLeftButton
|| w ==
m_UiRightButton
)
226
{
227
RestartSlideShow
();
228
return
true
;
229
}
230
return
false
;
231
}
232
}
UiHintPanel
void UiHintPanel(Widget parent_widget)
Definition
uihintpanel.c:324
Math
Definition
enmath.c:7
RichTextWidget
Definition
gameplay.c:317
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition
enwidgets.c:657
ScriptedWidgetEventHandler::RestartSlideShow
void RestartSlideShow()
Definition
uihintpanel.c:185
ScriptedWidgetEventHandler::m_RootFrame
Widget m_RootFrame
Definition
uihintpanel.c:16
ScriptedWidgetEventHandler::m_DataPath
const string m_DataPath
Definition
uihintpanel.c:14
ScriptedWidgetEventHandler::BuildLayout
void BuildLayout(Widget parent_widget)
Definition
uihintpanel.c:93
ScriptedWidgetEventHandler::ShowNextPage
void ShowNextPage()
Definition
uihintpanel.c:134
ScriptedWidgetEventHandler::m_UiHintImage
ImageWidget m_UiHintImage
Definition
uihintpanel.c:22
ScriptedWidgetEventHandler::PopulateLayout
void PopulateLayout()
Definition
uihintpanel.c:114
ScriptedWidgetEventHandler::m_PageIndex
int m_PageIndex
Definition
uihintpanel.c:26
ScriptedWidgetEventHandler::OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition
uihintpanel.c:223
ScriptedWidgetEventHandler::m_UiRightButton
ButtonWidget m_UiRightButton
Definition
uihintpanel.c:19
ScriptedWidgetEventHandler::m_RootPath
string m_RootPath
Definition
uihintpanel.c:13
ScriptedWidgetEventHandler::SetHintHeadline
void SetHintHeadline()
Definition
uihintpanel.c:127
ScriptedWidgetEventHandler::LoadContentList
void LoadContentList()
Definition
uihintpanel.c:85
ScriptedWidgetEventHandler::RandomizePageIndex
void RandomizePageIndex()
Definition
uihintpanel.c:171
ScriptedWidgetEventHandler::m_ContentList
ref array< ref HintPage > m_ContentList
Definition
uihintpanel.c:25
ScriptedWidgetEventHandler::~UiHintPanel
void ~UiHintPanel()
Definition
uihintpanel.c:48
ScriptedWidgetEventHandler::m_SpacerFrame
Widget m_SpacerFrame
Definition
uihintpanel.c:17
ScriptedWidgetEventHandler::m_UiDescLabel
RichTextWidget m_UiDescLabel
Definition
uihintpanel.c:20
ScriptedWidgetEventHandler::ShowPreviousPage
void ShowPreviousPage()
Definition
uihintpanel.c:150
ScriptedWidgetEventHandler::SetHintDescription
void SetHintDescription()
Definition
uihintpanel.c:131
ScriptedWidgetEventHandler::m_SlideShowDelay
int m_SlideShowDelay
Definition
uihintpanel.c:12
ScriptedWidgetEventHandler::m_UiHeadlineLabel
TextWidget m_UiHeadlineLabel
Definition
uihintpanel.c:21
ScriptedWidgetEventHandler::UiHintPanel
void UiHintPanel(Widget parent_widget)
Definition
uihintpanel.c:26
ScriptedWidgetEventHandler::m_UiPageingLabel
TextWidget m_UiPageingLabel
Definition
uihintpanel.c:23
ScriptedWidgetEventHandler::OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition
uihintpanel.c:214
ScriptedWidgetEventHandler::m_UiLeftButton
ButtonWidget m_UiLeftButton
Definition
uihintpanel.c:18
ScriptedWidgetEventHandler::SetHintPaging
void SetHintPaging()
Definition
uihintpanel.c:158
ScriptedWidgetEventHandler::StopSlideShow
void StopSlideShow()
Definition
uihintpanel.c:238
ScriptedWidgetEventHandler::SetHintImage
void SetHintImage()
Definition
uihintpanel.c:140
ScriptedWidgetEventHandler::OnClick
override bool OnClick(Widget w, int x, int y, int button)
Definition
uihintpanel.c:194
ScriptedWidgetEventHandler::StartSlideshow
void StartSlideshow()
Definition
uihintpanel.c:228
ScriptedWidgetEventHandler::SlideshowThread
void SlideshowThread()
Definition
uihintpanel.c:233
TextWidget
Definition
enwidgets.c:220
Widget
Definition
enwidgets.c:190
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition
isboxcollidinggeometryproxyclasses.c:28
GetGame
DayZGame GetGame()
Definition
gameplay.c:636
Print
proto void Print(void var)
Prints content of variable to console/log.
Math::RandomInt
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
MouseState
MouseState
Definition
ensystem.c:311
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition
tools.c:9
x
Icon x
y
Icon y
Games
Dayz
scripts
5_mission
gui
newui
hints
uihintpanel.c
Generated by
1.17.0