Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
newscarousel.c
Go to the documentation of this file.
7
9{
10 protected const int MAX_ARTICLES = 3;
11 protected const float ARTICLE_SWITCH_TIME = 3.0;
12
13 protected Widget m_Root;
14 protected ButtonWidget m_HotlinkButton;
16 protected ImageWidget m_Image;
18 protected ButtonWidget m_NextPageBtn;
19 protected ButtonWidget m_PrevPageBtn;
20 protected ImageWidget m_NextPageBtnIcon;
21 protected ImageWidget m_PrevPageBtnIcon;
22
23 #ifdef PLATFORM_CONSOLE
24 protected ImageWidget m_NextPageBtnIconConsole;
25 protected ImageWidget m_PrevPageBtnIconConsole;
26 #endif
27
31 protected int m_ArticleIndex;
32
33 protected ref Timer m_NewsSwitchTimer;
34 protected bool m_SwitchToNext = true;
35
36 #ifdef PLATFORM_CONSOLE
37 protected MainMenuConsole m_MainMenu;
38 #else
39 protected MainMenu m_MainMenu;
40 #endif
41
42 protected GridSpacerWidget m_GridSpacer;
44
46
47 void NewsCarousel(Widget parent, UIScriptedMenu mainMenu)
48 {
49 m_Root = g_Game.GetWorkspace().CreateWidgets("gui/layouts/new_ui/news_carousel.layout", parent);
50
51 m_TitleText = TextWidget.Cast(m_Root.FindAnyWidget("nf_title"));
52
53 m_NextPageBtn = ButtonWidget.Cast(m_Root.FindAnyWidget("next_button"));
54 m_PrevPageBtn = ButtonWidget.Cast(m_Root.FindAnyWidget("prev_button"));
55 m_HotlinkButton = ButtonWidget.Cast(m_Root.FindAnyWidget("nf_hotlink_button"));
56 m_HotlinkButtonLabel = RichTextWidget.Cast(m_Root.FindAnyWidget("nf_hotlink_label"));
57
58 m_NextPageBtnIcon = ImageWidget.Cast(m_Root.FindAnyWidget("next_icon_pc"));
59 m_PrevPageBtnIcon = ImageWidget.Cast(m_Root.FindAnyWidget("prev_icon_pc"));
60
61 m_PrevPageBtnIcon.Show(false);
62 #ifdef PLATFORM_CONSOLE
63
64 m_NextPageBtnIconConsole = ImageWidget.Cast(m_Root.FindAnyWidget("next_icon_console"));
65 m_PrevPageBtnIconConsole = ImageWidget.Cast(m_Root.FindAnyWidget("prev_icon_console"));
66
67 #ifdef PLATFORM_XBOX
68 m_NextPageBtnIconConsole.LoadImageFile(0, "set:xbox_buttons image:DPAD_right");
69 m_PrevPageBtnIconConsole.LoadImageFile(0, "set:xbox_buttons image:DPAD_left");
70 #else
71 m_NextPageBtnIconConsole.LoadImageFile(0, "set:playstation_buttons image:DPAD_right");
72 m_PrevPageBtnIconConsole.LoadImageFile(0, "set:playstation_buttons image:DPAD_left");
73 #endif
74 #endif
75
76 #ifdef PLATFORM_CONSOLE
77 m_MainMenu = MainMenuConsole.Cast(mainMenu);
78 #else
79 m_MainMenu = MainMenu.Cast(mainMenu);
80 #endif
81
82 m_GridSpacer = GridSpacerWidget.Cast(m_Root.FindAnyWidget("nf_grid"));
83
84 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
85
86 m_Root.SetHandler(this);
87
89
90 #ifdef PLATFORM_CONSOLE
91 if (g_Game.GetMission())
92 {
93 g_Game.GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
94 }
95 #endif
96
97 OnInputDeviceChanged(g_Game.GetInput().GetCurrentInputDevice());
98 }
99
101 {
103 m_NewsSwitchTimer.Stop();
104
105 if (g_Game.GetMission())
106 {
107 g_Game.GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
108 }
109 }
110
111 void Destroy()
112 {
113 m_Root.Unlink();
114 }
115
116 protected void SwitchNews()
117 {
118 if (m_SwitchToNext && m_ArticleIndex < m_NewsArticles.Count() - 1)
119 {
120 NextArticle();
121 if (m_ArticleIndex == m_NewsArticles.Count() - 1)
122 {
123 m_SwitchToNext = false;
124 }
125 }
126
127 if (!m_SwitchToNext && m_ArticleIndex > 0)
128 {
130 if (m_ArticleIndex == 0)
131 {
132 m_SwitchToNext = true;
133 }
134 }
135 }
136
137 void ShowNewsCarousel(bool show)
138 {
139 if (show)
140 {
142 }
143
144 m_Root.Show(show);
145 }
146
147 protected void UpdateCarouselInfo()
148 {
149 if (!m_NewsArticles)
151 else
152 m_NewsArticles.Clear();
153
155 if (!newsData)
156 return;
157
158 for (int i = 0; i < newsData.News.Count(); i++)
159 {
160 JsonDataNewsArticle article = newsData.News[i];
161 if (article)
162 {
164 if (article.categoryID == NewsCategory.DLCS)
165 {
166 if (modInfo && !modInfo.GetIsOwned())
167 {
168 m_NewsArticles.Insert(article);
169 }
170 }
171
172 if (article.categoryID == NewsCategory.DLC_PROMO)
173 {
174 if (!modInfo || (modInfo && !modInfo.GetIsOwned()))
175 {
176 m_NewsArticles.Insert(article);
177 }
178 }
179
180 if (m_NewsArticles.Count() >= MAX_ARTICLES)
181 break;
182 }
183 }
184
185 int articlesCount = m_NewsArticles.Count();
186 if (articlesCount < MAX_ARTICLES)
187 {
188 if (articlesCount == 0)
189 {
190 m_Root.Show(false);
191 }
192 else
193 {
194 m_Root.Show(true);
195 if (articlesCount == 1)
196 {
197 Widget pageIndicators = m_Root.FindAnyWidget("nf_pages");
198 if (pageIndicators)
199 {
200 pageIndicators.Show(false);
201 }
202
203 #ifndef PLATFORM_CONSOLE
204 m_NextPageBtnIcon.Show(false);
205 #else
206 m_NextPageBtnIconConsole.Show(false);
207 #endif
208 }
209
210 // Color carousel page indicators or hide them if not needed
211 for (int j = 1; j <= MAX_ARTICLES; j++)
212 {
213 Widget w = m_Root.FindAnyWidget("page" + j);
214 if (!w)
215 break;
216
217 if (j > articlesCount)
218 {
219 w.Show(false);
220 }
221 }
222 }
223 }
224
225 if (!m_NewsSwitchTimer && articlesCount > 1)
226 {
228 m_NewsSwitchTimer.Run(ARTICLE_SWITCH_TIME, this, "SwitchNews", null, true);
229 }
230
231 if (!m_AnimatedSpacer)
232 {
233 int maxColums = (articlesCount - 1);
234 m_AnimatedSpacer = new AnimatedGridSpacer(m_GridSpacer, maxColums, 0.4, AnimatedGridSpacerEasingType.EASE_IN_OUT_QUART);
235 m_AnimatedSpacer.m_OnAnimationComplete.Insert(OnAnimationCompleted);
236 }
237
238 ShowPost(0);
239 }
240
241 protected void ShowPost(int index)
242 {
243 m_CurrentArticle = null;
244 m_CurrentModInfo = null;
245
246 if (index == 0 && m_NewsArticles.Count() == 0 || index > m_NewsArticles.Count() - 1)
247 return;
248
249 JsonDataNewsArticle article = m_NewsArticles[index];
250 if (!article)
251 {
252 ErrorEx(string.Format("Failed to get article for index %1", index), ErrorExSeverity.WARNING);
253 return;
254 }
255
256 m_CurrentArticle = article;
257
259 if (modInfo)
260 {
261 m_CurrentModInfo = modInfo;
262 }
263
264 m_ArticleIndex = index;
265 m_TitleText.SetText(article.title);
266
267 ImageWidget imageW = ImageWidget.Cast(m_Root.FindAnyWidget("nf_image" + index));
268 if (imageW)
269 {
270 if (article.coverImage != "")
271 {
272 imageW.LoadImageFile(0, article.coverImage);
273 imageW.SetImage(0);
274 }
275 }
276
277 for (int i = 1; i <= MAX_ARTICLES; i++)
278 {
279 Widget w = m_Root.FindAnyWidget("page" + i);
280 if (!w)
281 break;
282
283 if ((i - 1) == index)
284 {
286 }
287 else
288 {
289 ColorNormal(w);
290 }
291 }
292 }
293
295 {
296 Widget focusW = GetWidgetUnderCursor();
297 if (!focusW || focusW && focusW != m_HotlinkButton)
298 {
299 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
300 }
301 else
302 {
303 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
304 }
305 }
306
307 protected void ColorHighlight(Widget w)
308 {
309 w.SetColor(ARGB(255, 255, 0, 0));
310 }
311
312 protected void ColorNormal(Widget w)
313 {
314 w.SetColor(ARGB(140, 0, 0, 0));
315 }
316
318 {
320 m_NewsSwitchTimer.Stop();
321
322 NextArticle();
323
325 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
326 }
327
328 protected void NextArticle()
329 {
330 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
331 return;
332
333 if (m_ArticleIndex < m_NewsArticles.Count() - 1)
334 {
337 m_AnimatedSpacer.MoveRight();
338 }
339
340 bool showRight = m_ArticleIndex < m_NewsArticles.Count() - 1;
341 ShowArrowRight(showRight);
342 bool showLeft = m_ArticleIndex > 0;
343 ShowArrowLeft(showLeft);
344 }
345
347 {
349 m_NewsSwitchTimer.Stop();
350
352
354 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
355 }
356
357 protected void PreviousArticle()
358 {
359 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
360 return;
361
362 if (m_ArticleIndex > 0)
363 {
366 m_AnimatedSpacer.MoveLeft();
367 }
368
369 bool showRight = m_ArticleIndex < m_NewsArticles.Count() - 1;
370 ShowArrowRight(showRight);
371 bool showLeft = m_ArticleIndex > 0;
372 ShowArrowLeft(showLeft);
373 }
374
375 protected void ShowArrowRight(bool state)
376 {
377 switch (m_CurrentInputDevice)
378 {
379 #ifdef PLATFORM_CONSOLE
380 case EInputDeviceType.CONTROLLER:
381 {
382 m_NextPageBtnIconConsole.Show(state);
383 break;
384 }
385 #endif
386 default:
387 {
388 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
389 {
390 m_NextPageBtnIcon.Show(state);
391 }
392 break;
393 }
394 }
395 }
396
397 protected void ShowArrowLeft(bool state)
398 {
399 switch (m_CurrentInputDevice)
400 {
401 #ifdef PLATFORM_CONSOLE
402 case EInputDeviceType.CONTROLLER:
403 {
404 m_PrevPageBtnIconConsole.Show(state);
405 break;
406 }
407 #endif
408 default:
409 {
410 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
411 {
412 m_PrevPageBtnIcon.Show(state);
413 }
414 break;
415 }
416 }
417 }
418
420 {
422 if (!article)
423 {
424 ErrorEx(string.Format("Failed to get article for index %1", m_ArticleIndex), ErrorExSeverity.WARNING);
425 return;
426 }
427
429 {
430 m_CurrentModInfo.GoToStore();
431 }
432 else
433 {
434 if (article.fullUrl != "")
435 {
436 g_Game.OpenURL(article.fullUrl);
437 }
438 }
439 }
440
441 override bool OnClick(Widget w, int x, int y, int button)
442 {
443 if (w == m_HotlinkButton)
444 {
446 }
447 else if (w == m_NextPageBtn)
448 {
450 }
451 else if (w == m_PrevPageBtn)
452 {
454 }
455
456 return false;
457 }
458
459 override bool OnMouseEnter(Widget w, int x, int y)
460 {
461 if (w == m_HotlinkButton)
462 {
463 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
464 return false;
465
466 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
467 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 0, 0));
468 return true;
469 }
470 else if (w == m_NextPageBtn)
471 {
472 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
473 return true;
474 }
475 else if (w == m_PrevPageBtn)
476 {
477 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
478 return true;
479 }
480 return false;
481 }
482
483 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
484 {
485 if (w == m_HotlinkButton)
486 {
487 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
488 return false;
489
490 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
491 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 255, 255));
492 return true;
493 }
494 else if (w == m_NextPageBtn)
495 {
496 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
497 return true;
498 }
499 else if (w == m_PrevPageBtn)
500 {
501 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
502 return true;
503 }
504 return false;
505 }
506
507 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
508 {
509 bool showNext = m_ArticleIndex < m_NewsArticles.Count() - 1;
510 bool showPrevious = m_ArticleIndex > 0;
511
512 if (pInputDeviceType == EInputDeviceType.UNKNOWN && g_Game.GetInput().IsActiveGamepadSelected())
513 pInputDeviceType = EInputDeviceType.CONTROLLER;
514
515 switch (pInputDeviceType)
516 {
517 case EInputDeviceType.CONTROLLER:
518 {
519 m_CurrentInputDevice = pInputDeviceType;
520 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
521 m_NextPageBtnIcon.Show(false);
522 m_PrevPageBtnIcon.Show(false);
523 #ifdef PLATFORM_CONSOLE
524 m_NextPageBtnIconConsole.Show(showNext);
525 m_PrevPageBtnIconConsole.Show(showPrevious);
526 #endif
527 break;
528 }
529 default:
530 {
531 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
532 {
533 m_CurrentInputDevice = pInputDeviceType;
534 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
535 #ifdef PLATFORM_CONSOLE
536 m_NextPageBtnIconConsole.Show(false);
537 m_PrevPageBtnIconConsole.Show(false);
538 #endif
539 m_NextPageBtnIcon.Show(showNext);
540 m_PrevPageBtnIcon.Show(showPrevious);
541 break;
542 }
543 }
544 }
545 }
546
547 protected string GetButtonLabel(string color)
548 {
549 string shopLabel;
550 #ifdef PLATFORM_WINDOWS
551 shopLabel = "#dlc_open_store";
552 #endif
553
554 #ifdef PLATFORM_CONSOLE
555 #ifdef PLATFORM_MSSTORE
556 shopLabel = "#dlc_open_store_Xbox";
557 #else
558 #ifdef PLATFORM_XBOX
559 shopLabel = "#dlc_open_store_Xbox";
560 #else
561 shopLabel = "#dlc_open_store_PS";
562 #endif
563 #endif
564 #endif
565
567 {
568 switch (m_CurrentArticle.categoryID)
569 {
570 case NewsCategory.DLC_PROMO:
571 {
572 if (m_CurrentArticle.fullUrl != string.Empty)
573 {
574 shopLabel = "#dlc_news_wishlist";
575 }
576 else
577 {
578 shopLabel = "#dlc_news_comingsoon";
579 }
580 break;
581 }
582 case NewsCategory.MISC_PROMO:
583 {
584 shopLabel = "#dlc_news_learn_more";
585 break;
586 }
587 }
588 }
589
590 string label = shopLabel;
591 string linkIcon = string.Format("<image set=\"%1\" name=\"%2\" scale=\"%3\"/>", "dayz_gui", "externallink", 0.9);
592
593 if (m_CurrentInputDevice == EInputDeviceType.CONTROLLER && m_CurrentArticle && m_CurrentArticle.fullUrl != string.Empty)
594 {
595 label = string.Format("#dlc_news_hold %1%2", InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER, 1.2), shopLabel);
596 }
597
598 string fullLabel = string.Format("<color rgba=\"%1\">%2 %3</color>", color, label, linkIcon);
599 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
600 fullLabel = string.Format("<color rgba=\"%1\">%2</color>", color, label);
601
602 return fullLabel;
603 }
604
605 void Update(float timeslice)
606 {
608 m_AnimatedSpacer.Update(timeslice);
609 }
610}
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition inventory.c:261
enum AnimatedGridSpacerEasingType m_GridSpacer
void AnimatedGridSpacer(Widget gridSpacer, int maxColums, float animDuration=0.25, AnimatedGridSpacerEasingType easing=AnimatedGridSpacerEasingType.EASE_IN_OUT_CUBIC)
AnimatedGridSpacerEasingType
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition inpututils.c:167
string coverImage
int categoryID
string title
string fullUrl
string dlcName
ref array< ref JsonDataNewsArticle > News
static JsonDataNewsList GetNewsData()
Definition mainmenudata.c:7
static ModInfo GetDLCModInfoByName(string dlcName)
DLCs only.
proto bool GetIsOwned()
map: item x vector(index, width, height)
Definition enwidgets.c:657
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Xbox menu.
Definition dayzgame.c:64
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
proto native void Destroy()
Cleans up the Effect, including unregistering if needed.
Definition effect.c:216
static proto string Format(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
Gets n-th character from string.
const int CALL_CATEGORY_GUI
Definition tools.c:9
bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
bool OnClick(Widget w, int x, int y, int button)
proto native Widget GetWidgetUnderCursor()
bool OnMouseEnter(Widget w, int x, int y)
Icon x
Icon y
EInputDeviceType
Definition input.c:3
ButtonWidget m_NextPageBtn
bool m_SwitchToNext
ButtonWidget m_PrevPageBtn
void OnClickPreviousArticle()
ref array< JsonDataNewsArticle > m_NewsArticles
ImageWidget m_NextPageBtnIcon
RichTextWidget m_HotlinkButtonLabel
void UpdateCarouselInfo()
void ShowArrowRight(bool state)
void ShowPost(int index)
ImageWidget m_Image
ref AnimatedGridSpacer m_AnimatedSpacer
ButtonWidget m_HotlinkButton
void OnClickNextArticle()
void NextArticle()
JsonDataNewsArticle m_CurrentArticle
const float ARTICLE_SWITCH_TIME
enum NewsCategory MAX_ARTICLES
void ~NewsCarousel()
int m_ArticleIndex
TextWidget m_TitleText
void ShowPromotion()
void ShowArrowLeft(bool state)
ref Timer m_NewsSwitchTimer
EInputDeviceType m_CurrentInputDevice
string GetButtonLabel(string color)
void OnAnimationCompleted()
void PreviousArticle()
MainMenu m_MainMenu
ImageWidget m_PrevPageBtnIcon
ModInfo m_CurrentModInfo
void SwitchNews()
void NewsCarousel(Widget parent, UIScriptedMenu mainMenu)
void ShowNewsCarousel(bool show)
NewsCategory
Definition newscarousel.c:2
@ DLCS
Definition newscarousel.c:3
@ DLC_PROMO
Definition newscarousel.c:4
@ MISC_PROMO
Definition newscarousel.c:5
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
Widget m_Root
Definition sizetochild.c:91