DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
NewsCarousel.c
См. документацию.
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 else
144 {
145 m_Root.Show(false);
146 }
147 }
148
150 {
151 return m_Root && m_Root.IsVisible();
152 }
153
155 {
156 if (!m_NewsArticles)
157 return 0;
158 return m_NewsArticles.Count();
159 }
160
161 protected void UpdateCarouselInfo()
162 {
163 if (!m_NewsArticles)
165 else
166 m_NewsArticles.Clear();
167
169 if (!newsData)
170 return;
171
172 foreach(JsonDataNewsArticle article: newsData.News)
173 {
174 if (article)
175 {
177 if (article.categoryID == NewsCategory.DLCS)
178 {
179 if (modInfo && !modInfo.GetIsOwned())
180 {
181 m_NewsArticles.Insert(article);
182 }
183 }
184
185 if (article.categoryID == NewsCategory.DLC_PROMO)
186 {
187 if (!modInfo || (modInfo && !modInfo.GetIsOwned()))
188 {
189 m_NewsArticles.Insert(article);
190 }
191 }
192
193 if (m_NewsArticles.Count() >= MAX_ARTICLES)
194 break;
195 }
196 }
197
198 int articlesCount = m_NewsArticles.Count();
199
200 m_ArticleIndex = 0;
201 m_SwitchToNext = true;
202
203 if (articlesCount < MAX_ARTICLES)
204 {
205 if (articlesCount == 0)
206 {
207 m_Root.Show(false);
208 }
209 else
210 {
211 m_Root.Show(true);
212 if (articlesCount == 1)
213 {
214 Widget pageIndicators = m_Root.FindAnyWidget("nf_pages");
215 if (pageIndicators)
216 {
217 pageIndicators.Show(false);
218 }
219
220 #ifndef PLATFORM_CONSOLE
221 m_NextPageBtnIcon.Show(false);
222 #else
223 m_NextPageBtnIconConsole.Show(false);
224 #endif
225 }
226
227 // Color carousel page indicators or hide them if not needed
228 for (int j = 1; j <= MAX_ARTICLES; j++)
229 {
230 Widget w = m_Root.FindAnyWidget("page" + j);
231 if (!w)
232 break;
233
234 if (j > articlesCount)
235 {
236 w.Show(false);
237 }
238 }
239 }
240 }
241
243 {
244 m_NewsSwitchTimer.Stop();
245 m_NewsSwitchTimer = null;
246 }
247
248 m_AnimatedSpacer = null; // force rebuild with the new column count
249
250 if (articlesCount > 1)
251 {
253 m_NewsSwitchTimer.Run(ARTICLE_SWITCH_TIME, this, "SwitchNews", null, true);
254 }
255
256 m_AnimatedSpacer = new AnimatedGridSpacer(m_GridSpacer, articlesCount - 1, 0.4, AnimatedGridSpacerEasingType.EASE_IN_OUT_QUART);
257 m_AnimatedSpacer.m_OnAnimationComplete.Insert(OnAnimationCompleted);
258
259 ShowPost(0);
260 ShowArrowRight(articlesCount > 1);
261 ShowArrowLeft(false);
262 }
263
264 protected void ShowPost(int index)
265 {
266 m_CurrentArticle = null;
267 m_CurrentModInfo = null;
268
269 if (index == 0 && m_NewsArticles.Count() == 0 || index >= m_NewsArticles.Count())
270 return;
271
272 JsonDataNewsArticle article = m_NewsArticles[index];
273 if (!article)
274 {
275 ErrorEx(string.Format("Failed to get article for index %1", index), ErrorExSeverity.WARNING);
276 return;
277 }
278
279 m_CurrentArticle = article;
280
282 if (modInfo)
283 {
284 m_CurrentModInfo = modInfo;
285 }
286
287 m_ArticleIndex = index;
288 m_TitleText.SetText(article.title);
289
290 ImageWidget imageW = ImageWidget.Cast(m_Root.FindAnyWidget("nf_image" + index));
291 if (imageW)
292 {
293 if (article.coverImage != "")
294 {
295 imageW.LoadImageFile(0, article.coverImage);
296 imageW.SetImage(0);
297 }
298 }
299
300 for (int i = 1; i <= MAX_ARTICLES; i++)
301 {
302 Widget w = m_Root.FindAnyWidget("page" + i);
303 if (!w)
304 break;
305
306 if ((i - 1) == index)
307 {
309 }
310 else
311 {
312 ColorNormal(w);
313 }
314 }
315 }
316
318 {
319 Widget focusW = GetWidgetUnderCursor();
320 if (!focusW || focusW && focusW != m_HotlinkButton)
321 {
322 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
323 }
324 else
325 {
326 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
327 }
328 }
329
330 protected void ColorHighlight(Widget w)
331 {
332 w.SetColor(ARGB(255, 255, 0, 0));
333 }
334
335 protected void ColorNormal(Widget w)
336 {
337 w.SetColor(ARGB(140, 0, 0, 0));
338 }
339
341 {
343 m_NewsSwitchTimer.Stop();
344
345 NextArticle();
346
348 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
349 }
350
351 protected void NextArticle()
352 {
353 if (!m_NewsArticles || m_NewsArticles.Count() == 0)
354 return;
355
356 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
357 return;
358
359 if (m_ArticleIndex < m_NewsArticles.Count() - 1)
360 {
363 m_AnimatedSpacer.MoveRight();
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
373 {
375 m_NewsSwitchTimer.Stop();
376
378
380 m_NewsSwitchTimer.Run(3.0, this, "SwitchNews", null, true);
381 }
382
383 protected void PreviousArticle()
384 {
385 if (!m_AnimatedSpacer || m_AnimatedSpacer.IsAnimating())
386 return;
387
388 if (m_ArticleIndex > 0)
389 {
392 m_AnimatedSpacer.MoveLeft();
393 }
394
395 bool showRight = m_ArticleIndex < m_NewsArticles.Count() - 1;
396 ShowArrowRight(showRight);
397 bool showLeft = m_ArticleIndex > 0;
398 ShowArrowLeft(showLeft);
399 }
400
401 protected void ShowArrowRight(bool state)
402 {
403 switch (m_CurrentInputDevice)
404 {
405 #ifdef PLATFORM_CONSOLE
406 case EInputDeviceType.CONTROLLER:
407 {
408 m_NextPageBtnIconConsole.Show(state);
409 break;
410 }
411 #endif
412 default:
413 {
414 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
415 {
416 m_NextPageBtnIcon.Show(state);
417 }
418 break;
419 }
420 }
421 }
422
423 protected void ShowArrowLeft(bool state)
424 {
425 switch (m_CurrentInputDevice)
426 {
427 #ifdef PLATFORM_CONSOLE
428 case EInputDeviceType.CONTROLLER:
429 {
430 m_PrevPageBtnIconConsole.Show(state);
431 break;
432 }
433 #endif
434 default:
435 {
436 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
437 {
438 m_PrevPageBtnIcon.Show(state);
439 }
440 break;
441 }
442 }
443 }
444
446 {
448 return;
449
451 if (!article)
452 {
453 ErrorEx(string.Format("Failed to get article for index %1", m_ArticleIndex), ErrorExSeverity.WARNING);
454 return;
455 }
456
458 {
459 m_CurrentModInfo.GoToStore();
460 }
461 else
462 {
463 if (article.fullUrl != "")
464 {
465 g_Game.OpenURL(article.fullUrl);
466 }
467 }
468 }
469
470 override bool OnClick(Widget w, int x, int y, int button)
471 {
472 if (w == m_HotlinkButton)
473 {
475 }
476 else if (w == m_NextPageBtn)
477 {
479 }
480 else if (w == m_PrevPageBtn)
481 {
483 }
484
485 return false;
486 }
487
488 override bool OnMouseEnter(Widget w, int x, int y)
489 {
490 if (w == m_HotlinkButton)
491 {
492 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
493 return false;
494
495 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 0, 0, 255"));
496 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 0, 0));
497 return true;
498 }
499 else if (w == m_NextPageBtn)
500 {
501 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
502 return true;
503 }
504 else if (w == m_PrevPageBtn)
505 {
506 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 0, 0));
507 return true;
508 }
509 return false;
510 }
511
512 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
513 {
514 if (w == m_HotlinkButton)
515 {
516 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
517 return false;
518
519 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
520 m_HotlinkButtonLabel.SetColor(ARGB(255, 255, 255, 255));
521 return true;
522 }
523 else if (w == m_NextPageBtn)
524 {
525 m_NextPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
526 return true;
527 }
528 else if (w == m_PrevPageBtn)
529 {
530 m_PrevPageBtnIcon.SetColor(ARGB(255, 255, 255, 255));
531 return true;
532 }
533 return false;
534 }
535
536 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
537 {
538 int count = GetArticleCount();
539 bool showNext = m_ArticleIndex < count - 1;
540 bool showPrevious = m_ArticleIndex > 0;
541
542 if (pInputDeviceType == EInputDeviceType.UNKNOWN && g_Game.GetInput().IsActiveGamepadSelected())
543 pInputDeviceType = EInputDeviceType.CONTROLLER;
544
545 switch (pInputDeviceType)
546 {
547 case EInputDeviceType.CONTROLLER:
548 {
549 m_CurrentInputDevice = pInputDeviceType;
550 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
551 m_NextPageBtnIcon.Show(false);
552 m_PrevPageBtnIcon.Show(false);
553 #ifdef PLATFORM_CONSOLE
554 m_NextPageBtnIconConsole.Show(showNext);
555 m_PrevPageBtnIconConsole.Show(showPrevious);
556 #endif
557 break;
558 }
559 default:
560 {
561 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
562 {
563 m_CurrentInputDevice = pInputDeviceType;
564 m_HotlinkButtonLabel.SetText(GetButtonLabel("255, 255, 255, 255"));
565 #ifdef PLATFORM_CONSOLE
566 m_NextPageBtnIconConsole.Show(false);
567 m_PrevPageBtnIconConsole.Show(false);
568 #endif
569 m_NextPageBtnIcon.Show(showNext);
570 m_PrevPageBtnIcon.Show(showPrevious);
571 break;
572 }
573 }
574 }
575 }
576
577 protected string GetButtonLabel(string color)
578 {
579 string shopLabel;
580 #ifdef PLATFORM_WINDOWS
581 shopLabel = "#dlc_open_store";
582 #endif
583
584 #ifdef PLATFORM_CONSOLE
585 #ifdef PLATFORM_MSSTORE
586 shopLabel = "#dlc_open_store_Xbox";
587 #else
588 #ifdef PLATFORM_XBOX
589 shopLabel = "#dlc_open_store_Xbox";
590 #else
591 shopLabel = "#dlc_open_store_PS";
592 #endif
593 #endif
594 #endif
595
597 {
598 switch (m_CurrentArticle.categoryID)
599 {
600 case NewsCategory.DLC_PROMO:
601 {
602 if (m_CurrentArticle.fullUrl != string.Empty)
603 {
604 shopLabel = "#dlc_news_wishlist";
605 }
606 else
607 {
608 shopLabel = "#dlc_news_comingsoon";
609 }
610 break;
611 }
612 case NewsCategory.MISC_PROMO:
613 {
614 shopLabel = "#dlc_news_learn_more";
615 break;
616 }
617 }
618 }
619
620 string label = shopLabel;
621 string linkIcon = string.Format("<image set=\"%1\" name=\"%2\" scale=\"%3\"/>", "dayz_gui", "externallink", 0.9);
622
623 if (m_CurrentInputDevice == EInputDeviceType.CONTROLLER && m_CurrentArticle && m_CurrentArticle.fullUrl != string.Empty)
624 {
625 label = string.Format("#dlc_news_hold %1%2", InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER, 1.2), shopLabel);
626 }
627
628 string fullLabel = string.Format("<color rgba=\"%1\">%2 %3</color>", color, label, linkIcon);
629 if (m_CurrentArticle && m_CurrentArticle.fullUrl == string.Empty)
630 fullLabel = string.Format("<color rgba=\"%1\">%2</color>", color, label);
631
632 return fullLabel;
633 }
634
635 void Update(float timeslice)
636 {
638 m_AnimatedSpacer.Update(timeslice);
639 }
640}
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
enum AnimatedGridSpacerEasingType m_GridSpacer
void AnimatedGridSpacer(Widget gridSpacer, int maxColums, float animDuration=0.25, AnimatedGridSpacerEasingType easing=AnimatedGridSpacerEasingType.EASE_IN_OUT_CUBIC)
Определения AnimatedGridSpacer.c:31
AnimatedGridSpacerEasingType
Определения AnimatedGridSpacer.c:3
DayZGame g_Game
Определения DayZGame.c:4074
Icon x
Icon y
Widget m_Root
Определения SizeToChild.c:91
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Определения InputUtils.c:167
Определения InputUtils.c:2
int categoryID
Определения BiosLobbyService.c:8
string dlcName
Определения BiosLobbyService.c:11
string title
Определения BiosLobbyService.c:19
string coverImage
Определения BiosLobbyService.c:21
string fullUrl
Определения BiosLobbyService.c:22
Определения BiosLobbyService.c:6
ref array< ref JsonDataNewsArticle > News
Определения BiosLobbyService.c:27
static JsonDataNewsList GetNewsData()
Определения MainMenuData.c:26
static ModInfo GetDLCModInfoByName(string dlcName)
DLCs only.
Определения MainMenuData.c:142
Определения MainMenuData.c:2
proto bool GetIsOwned()
Определения ModInfo.c:2
Определения gameplay.c:317
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Определения ItemActionsWidget.c:104
void ColorHighlight(Widget w)
Определения OptionSelectorBase.c:164
void ColorNormal(Widget w)
Определения OptionSelectorBase.c:172
bool IsVisible()
Определения ContextMenu.c:134
Deprecated.
Определения EnWidgets.c:657
Определения EnWidgets.c:220
Определения DayZPlayerImplement.c:39
Определения DayZGame.c:64
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
proto native void Destroy()
Cleans up the Effect, including unregistering if needed.
Определения 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
Определения 3_Game/DayZ/tools/tools.c:9
bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
bool OnMouseEnter(Widget w, int x, int y)
bool OnClick(Widget w, int x, int y, int button)
proto native Widget GetWidgetUnderCursor()
EInputDeviceType
Определения input.c:3
int ARGB(int a, int r, int g, int b)
Определения proto.c:322