Dayz Explorer 1.29.162510
Loading...
Searching...
No Matches
newscarousel.c
Go to the documentation of this file.
7
8class NewsCarousel extends ScriptedWidgetEventHandler
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;
17 protected TextWidget m_TitleText;
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 {
163 if (article.categoryID == NewsCategory.DLCS)
164 {
165 ModInfo modInfo = MainMenuData.GetDLCModInfoByName(article.dlcName);
166 if (modInfo && !modInfo.GetIsOwned())
167 {
168 m_NewsArticles.Insert(article);
169 }
170 }
171
172 if (article.categoryID == NewsCategory.DLC_PROMO)
173 {
174 m_NewsArticles.Insert(article);
175 }
176
177 if (m_NewsArticles.Count() >= MAX_ARTICLES)
178 break;
179 }
180 }
181
182 int articlesCount = m_NewsArticles.Count();
183 if (articlesCount < MAX_ARTICLES)
184 {
185 if (articlesCount == 0)
186 {
187 m_Root.Show(false);
188 }
189 else
190 {
191 m_Root.Show(true);
192 if (articlesCount == 1)
193 {
194 Widget pageIndicators = m_Root.FindAnyWidget("nf_pages");
195 if (pageIndicators)
196 {
197 pageIndicators.Show(false);
198 }
199
200 #ifndef PLATFORM_CONSOLE
201 m_NextPageBtnIcon.Show(false);
202 #else
203 m_NextPageBtnIconConsole.Show(false);
204 #endif
205 }
206
207 // Color carousel page indicators or hide them if not needed
208 for (int j = 1; j <= MAX_ARTICLES; j++)
209 {
210 Widget w = m_Root.FindAnyWidget("page" + j);
211 if (!w)
212 break;
213
214 if (j > articlesCount)
215 {
216 w.Show(false);
217 }
218 }
219 }
220 }
221
222 if (!m_NewsSwitchTimer && articlesCount > 1)
223 {
225 m_NewsSwitchTimer.Run(ARTICLE_SWITCH_TIME, this, "SwitchNews", null, true);
226 }
227
228 if (!m_AnimatedSpacer)
229 {
230 int maxColums = (articlesCount - 1);
231 m_AnimatedSpacer = new AnimatedGridSpacer(m_GridSpacer, maxColums, 0.4, AnimatedGridSpacerEasingType.EASE_IN_OUT_QUART);
232 m_AnimatedSpacer.m_OnAnimationComplete.Insert(OnAnimationCompleted);
233 }
234
235 ShowPost(0);
236 }
237
238 protected void ShowPost(int index)
239 {
240 m_CurrentArticle = null;
241 m_CurrentModInfo = null;
242
243 if (index == 0 && m_NewsArticles.Count() == 0 || index > m_NewsArticles.Count() - 1)
244 return;
245
246 JsonDataNewsArticle article = m_NewsArticles[index];
247 if (!article)
248 {
249 ErrorEx(string.Format("Failed to get article for index %1", index), ErrorExSeverity.WARNING);
250 return;
251 }
252
253 m_CurrentArticle = article;
254
255 ModInfo modInfo = MainMenuData.GetDLCModInfoByName(article.dlcName);
256 if (modInfo)
257 {
258 m_CurrentModInfo = modInfo;
259 }
260
261 m_ArticleIndex = index;
262 m_TitleText.SetText(article.title);
263
264 ImageWidget imageW = ImageWidget.Cast(m_Root.FindAnyWidget("nf_image" + index));
265 if (imageW)
266 {
267 if (article.coverImage != "")
268 {
269 imageW.LoadImageFile(0, article.coverImage);
270 imageW.SetImage(0);
271 }
272 }
273
274 for (int i = 1; i <= MAX_ARTICLES; i++)
275 {
276 Widget w = m_Root.FindAnyWidget("page" + i);
277 if (!w)
278 break;
279
280 if ((i - 1) == index)
281 {
283 }
284 else
285 {
286 ColorNormal(w);
287 }
288 }
289 }
290
292 {
293 Widget focusW = GetWidgetUnderCursor();
294 if (!focusW || focusW && focusW != m_HotlinkButton)
295 {
296 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
297 }
298 else
299 {
300 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
301 }
302 }
303
304 protected void ColorHighlight(Widget w)
305 {
306 w.SetColor(ARGB(255, 255, 0, 0));
307 }
308
309 protected void ColorNormal(Widget w)
310 {
311 w.SetColor(ARGB(140, 0, 0, 0));
312 }
313
315 {
317 m_NewsSwitchTimer.Stop();
318
319 NextArticle();
320
322 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
323 }
324
325 protected void NextArticle()
326 {
327 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
328 return;
329
330 if (m_ArticleIndex < m_NewsArticles.Count() - 1)
331 {
334 m_AnimatedSpacer.MoveRight();
335 }
336
337 bool showRight = m_ArticleIndex < m_NewsArticles.Count() - 1;
338 ShowArrowRight(showRight);
339 bool showLeft = m_ArticleIndex > 0;
340 ShowArrowLeft(showLeft);
341 }
342
344 {
346 m_NewsSwitchTimer.Stop();
347
349
351 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
352 }
353
354 protected void PreviousArticle()
355 {
356 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
357 return;
358
359 if (m_ArticleIndex > 0)
360 {
363 m_AnimatedSpacer.MoveLeft();
364 }
365
366 bool showRight = m_ArticleIndex < m_NewsArticles.Count() - 1;
367 ShowArrowRight(showRight);
368 bool showLeft = m_ArticleIndex > 0;
369 ShowArrowLeft(showLeft);
370 }
371
372 protected void ShowArrowRight(bool state)
373 {
374 switch (m_CurrentInputDevice)
375 {
376 #ifdef PLATFORM_CONSOLE
377 case EInputDeviceType.CONTROLLER:
378 {
379 m_NextPageBtnIconConsole.Show(state);
380 break;
381 }
382 #endif
383 default:
384 {
385 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
386 {
387 m_NextPageBtnIcon.Show(state);
388 }
389 break;
390 }
391 }
392 }
393
394 protected void ShowArrowLeft(bool state)
395 {
396 switch (m_CurrentInputDevice)
397 {
398 #ifdef PLATFORM_CONSOLE
399 case EInputDeviceType.CONTROLLER:
400 {
401 m_PrevPageBtnIconConsole.Show(state);
402 break;
403 }
404 #endif
405 default:
406 {
407 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
408 {
409 m_PrevPageBtnIcon.Show(state);
410 }
411 break;
412 }
413 }
414 }
415
417 {
419 if (!article)
420 {
421 ErrorEx(string.Format("Failed to get article for index %1", m_ArticleIndex), ErrorExSeverity.WARNING);
422 return;
423 }
424
426 {
427 m_CurrentModInfo.GoToStore();
428 }
429 else
430 {
431 if (article.fullUrl != "")
432 {
433 g_Game.OpenURL(article.fullUrl);
434 }
435 }
436 }
437
438 override bool OnClick(Widget w, int x, int y, int button)
439 {
440 if (w == m_HotlinkButton)
441 {
443 }
444 else if (w == m_NextPageBtn)
445 {
447 }
448 else if (w == m_PrevPageBtn)
449 {
451 }
452
453 return false;
454 }
455
456 override bool OnMouseEnter(Widget w, int x, int y)
457 {
458 if (w == m_HotlinkButton)
459 {
460 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
461 return false;
462
463 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
464 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 0, 0));
465 return true;
466 }
467 else if (w == m_NextPageBtn)
468 {
469 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
470 return true;
471 }
472 else if (w == m_PrevPageBtn)
473 {
474 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
475 return true;
476 }
477 return false;
478 }
479
480 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
481 {
482 if (w == m_HotlinkButton)
483 {
484 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
485 return false;
486
487 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
488 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 255, 255));
489 return true;
490 }
491 else if (w == m_NextPageBtn)
492 {
493 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
494 return true;
495 }
496 else if (w == m_PrevPageBtn)
497 {
498 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
499 return true;
500 }
501 return false;
502 }
503
504 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
505 {
506 bool showNext = m_ArticleIndex < m_NewsArticles.Count() - 1;
507 bool showPrevious = m_ArticleIndex > 0;
508
509 if (pInputDeviceType == EInputDeviceType.UNKNOWN && g_Game.GetInput().IsActiveGamepadSelected())
510 pInputDeviceType = EInputDeviceType.CONTROLLER;
511
512 switch (pInputDeviceType)
513 {
514 case EInputDeviceType.CONTROLLER:
515 {
516 m_CurrentInputDevice = pInputDeviceType;
517 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
518 m_NextPageBtnIcon.Show(false);
519 m_PrevPageBtnIcon.Show(false);
520 #ifdef PLATFORM_CONSOLE
521 m_NextPageBtnIconConsole.Show(showNext);
522 m_PrevPageBtnIconConsole.Show(showPrevious);
523 #endif
524 break;
525 }
526 default:
527 {
528 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
529 {
530 m_CurrentInputDevice = pInputDeviceType;
531 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
532 #ifdef PLATFORM_CONSOLE
533 m_NextPageBtnIconConsole.Show(false);
534 m_PrevPageBtnIconConsole.Show(false);
535 #endif
536 m_NextPageBtnIcon.Show(showNext);
537 m_PrevPageBtnIcon.Show(showPrevious);
538 break;
539 }
540 }
541 }
542 }
543
544 protected string GetButtonLabel(string color)
545 {
546 string shopLabel;
547 #ifdef PLATFORM_WINDOWS
548 shopLabel = "#dlc_open_store";
549 #endif
550
551 #ifdef PLATFORM_CONSOLE
552 #ifdef PLATFORM_MSSTORE
553 shopLabel = "#dlc_open_store_Xbox";
554 #else
555 #ifdef PLATFORM_XBOX
556 shopLabel = "#dlc_open_store_Xbox";
557 #else
558 shopLabel = "#dlc_open_store_PS";
559 #endif
560 #endif
561 #endif
562
564 {
565 switch (m_CurrentArticle.categoryID)
566 {
567 case NewsCategory.DLC_PROMO:
568 {
569 if (m_CurrentArticle.fullUrl != string.Empty)
570 {
571 shopLabel = "#dlc_news_wishlist";
572 }
573 else
574 {
575 shopLabel = "#dlc_news_comingsoon";
576 }
577 break;
578 }
579 case NewsCategory.MISC_PROMO:
580 {
581 shopLabel = "#dlc_news_learn_more";
582 break;
583 }
584 }
585 }
586
587 string label = shopLabel;
588 string linkIcon = string.Format("<image set=\"%1\" name=\"%2\" scale=\"%3\"/>", "dayz_gui", "externallink", 0.9);
589
590 if (m_CurrentInputDevice == EInputDeviceType.CONTROLLER && m_CurrentArticle && m_CurrentArticle.fullUrl != string.Empty)
591 {
592 label = string.Format("#dlc_news_hold %1%2", InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER, 1.2), shopLabel);
593 }
594
595 string fullLabel = string.Format("<color rgba=\"%1\">%2 %3</color>", color, label, linkIcon);
596 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
597 fullLabel = string.Format("<color rgba=\"%1\">%2</color>", color, label);
598
599 return fullLabel;
600 }
601
602 void Update(float timeslice)
603 {
605 m_AnimatedSpacer.Update(timeslice);
606 }
607}
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
static JsonDataNewsList GetNewsData()
Definition mainmenudata.c:7
static ModInfo GetDLCModInfoByName(string dlcName)
DLCs only.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition dayzgame.c:152
ErrorExSeverity
Definition endebug.c:62
enum ShapeType ErrorEx
proto native void Destroy()
Cleans up the Effect, including unregistering if needed.
Definition effect.c:216
const int CALL_CATEGORY_GUI
Definition tools.c:9
void Update()
Definition radialmenu.c:518
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
void ColorNormal(Widget w)
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 ColorHighlight(Widget w)
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
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)