DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ LoadContentList()

void Init::LoadContentList ( )
protected

См. определение в файле UiHintPanel.c строка 374

379{
380 #ifdef DIAG_DEVELOPER
381 static int m_ForcedIndex = -1;//only for debug purposes
382 #endif
383
384 // Const
385 protected int m_SlideShowDelay = 25000; // The speed of the slideshow
386 protected string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
387 protected const string m_DataPath = "scripts/data/hints.json"; // Json path
388 // Widgets
389 protected Widget m_RootFrame;
390 protected Widget m_SpacerFrame;
391 protected ButtonWidget m_UiLeftButton;
392 protected ButtonWidget m_UiRightButton;
395 protected ImageWidget m_UiHintImage;
397 // Data
399 protected int m_PageIndex = int.MIN;
400 protected DayZGame m_Game;
401 protected bool m_Initialized;
402 protected Widget m_ParentWidget;
403 protected int m_PreviousRandomIndex = int.MIN;
404
405 // ---------------------------------------------------------
406
407 // Constructor
408 void UiHintPanel(Widget parent_widget)
409 {
410 DayZGame game = DayZGame.Cast(GetGame());
411 m_ParentWidget = parent_widget;
412 Init(game);
413 }
414 // Destructor
415 void ~UiHintPanel()
416 {
418
419 if(m_RootFrame)
420 m_RootFrame.Unlink();
421 }
422
423
424 void Init(DayZGame game)
425 {
426 //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
427 //however for modding legacy support purposes, this was done without modifying the CTOR signature with the addition of the Init method,
428 //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
429
430 if (m_Initialized)
431 return;
432 if (!game)//is null when instantiated from DayZGame during loading before calling Init explicitly
433 return;
434 m_Initialized = true;
435
436 m_Game = game;
437 // Load Json File
439 // If load successful
440 if (m_ContentList)
441 {
442 // Build the layout
444 // Get random page index
446 // Populate the layout with data
448 // Start the slideshow
450 }
451 else
452 ErrorEx("Could not create the hint panel. The data are missing!");
453 }
454
455 // ------------------------------------------------------
456
457 // Load content data from json file
458 protected void LoadContentList()
459 {
460 string errorMessage;
461 if (!JsonFileLoader<array<ref HintPage>>.LoadFile(m_DataPath, m_ContentList, errorMessage))
462 ErrorEx(errorMessage);
463 }
464
465 // Create and Build the layout
466 protected void BuildLayout(Widget parent_widget)
467 {
468 // Create the layout
469 m_RootFrame = m_Game.GetWorkspace().CreateWidgets(m_RootPath, parent_widget);
470
471 if (m_RootFrame)
472 {
473 // Find Widgets
474 m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
475 m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
476 m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
477 m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
478 m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
479 m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
480 m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
481 // Set handler
482 m_RootFrame.SetHandler(this);
483 }
484 }
485
486 // Populate the hint with content
487 protected void PopulateLayout()
488 {
489 if (m_RootFrame)
490 {
493 SetHintImage();
495 }
496 }
497
498 // -------------------------------------------
499 // Setters
500 protected void SetHintHeadline()
501 {
502 m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
503 }
504 protected void SetHintDescription()
505 {
506 #ifdef DEVELOPER
507 //Print("showing contents for page "+m_PageIndex);
508 #endif
509 m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
510 m_UiDescLabel.Update();
511 m_SpacerFrame.Update();
512 }
513 protected void SetHintImage()
514 {
515 string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
516
517 // If there is an image
518 if (image_path)
519 {
520 // Show the widget
521 m_UiHintImage.Show(true);
522 // Set the image path
523 m_UiHintImage.LoadImageFile(0, image_path);
524 }
525 else
526 {
527 // Hide the widget
528 m_UiHintImage.Show(false);
529 }
530 }
531 protected void SetHintPaging()
532 {
534 m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
535 }
536
537 void ShowRandomPage()
538 {
541 }
542
543 // Set a random page index
544 protected void RandomizePageIndex()
545 {
546 #ifdef DIAG_DEVELOPER
548 {
549 if (m_ForcedIndex != -1)
550 {
551 m_PageIndex = Math.Clamp(m_ForcedIndex,0,m_ContentList.Count() - 1);
552 return;
553 }
554 }
555 #endif
556
557 Math.Randomize(m_Game.GetTime());
558 Math.RandomFloat01();//throw-away value, without calling this, the next random number is always the same, calling Math.Randomize(-1) makes no difference
562
563 }
564 // Show next hint page by incrementing the page index.
565 protected void ShowNextPage()
566 {
567 // Update the page index
568 if ( m_PageIndex < m_ContentList.Count() - 1 )
569 {
570 m_PageIndex++;
571 }
572 else
573 {
574 m_PageIndex = 0;
575 }
576
577 //Update the hint page
579 }
580 // Show previous hint page by decreasing the page index.
581 protected void ShowPreviousPage()
582 {
583 // Update the page index
584 if ( m_PageIndex == 0 )
585 {
586 m_PageIndex = m_ContentList.Count() - 1;
587 }
588 else
589 {
590 m_PageIndex--;
591
592 }
593 //Update the hint page
595 }
596
597 // -------------------------------------------
598 // Slideshow
599
600 // Creates new slidshow thread
601 protected void StartSlideshow()
602 {
604 }
605 // Slidshow thread - run code
606 protected void SlideshowThread()
607 {
608 ShowNextPage();
609 }
610 // Stop the slide show
611 protected void StopSlideShow()
612 {
613 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
614 }
615 // Restart the slide show
616 protected void RestartSlideShow()
617 {
620 }
621
622 // ----------------------------------------
623 // Layout manipulation
624
625 override bool OnClick(Widget w, int x, int y, int button)
626 {
627 if (button == MouseState.LEFT)
628 {
629 switch (w)
630 {
631 case m_UiLeftButton:
632 {
634 return true;
635 }
636 case m_UiRightButton:
637 {
638 ShowNextPage();
639 return true;
640 }
641 }
642 }
643 return false;
644 }
645 override bool OnMouseEnter(Widget w, int x, int y)
646 {
647 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
648 {
650 return true;
651 }
652 return false;
653 }
654 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
655 {
656 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
657 {
659 return true;
660 }
661 return false;
662 }
663}
664
665// ---------------------------------------------------------------------------------------------------------
666class UiHintPanelLoading extends UiHintPanel
667{
668 override void Init(DayZGame game)
669 {
670 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
671 super.Init(game);
672 }
673}
override Widget Init()
Определения DayZGame.c:127
Icon x
Icon y
Widget m_RootFrame
Определения UiHintPanel.c:305
const string m_DataPath
Определения UiHintPanel.c:303
void RandomizePageIndex()
Определения UiHintPanel.c:460
void ShowRandomPage()
Определения UiHintPanel.c:453
override bool OnClick(Widget w, int x, int y, int button)
Определения UiHintPanel.c:541
ImageWidget m_UiHintImage
Определения UiHintPanel.c:311
void SetHintHeadline()
Определения UiHintPanel.c:416
void SetHintImage()
Определения UiHintPanel.c:429
void SetHintPaging()
Определения UiHintPanel.c:447
int m_PageIndex
Определения UiHintPanel.c:315
ButtonWidget m_UiRightButton
Определения UiHintPanel.c:308
void ~UiHintPanel()
Определения UiHintPanel.c:331
string m_RootPath
Определения UiHintPanel.c:302
void SetHintDescription()
Определения UiHintPanel.c:420
Widget m_ParentWidget
Определения UiHintPanel.c:318
bool m_Initialized
Определения UiHintPanel.c:317
void StartSlideshow()
Определения UiHintPanel.c:517
ref array< ref HintPage > m_ContentList
Определения UiHintPanel.c:314
void StopSlideShow()
Определения UiHintPanel.c:527
void RestartSlideShow()
Определения UiHintPanel.c:532
override bool OnMouseEnter(Widget w, int x, int y)
Определения UiHintPanel.c:561
void SlideshowThread()
Определения UiHintPanel.c:522
Widget m_SpacerFrame
Определения UiHintPanel.c:306
RichTextWidget m_UiDescLabel
Определения UiHintPanel.c:309
void BuildLayout(Widget parent_widget)
Определения UiHintPanel.c:382
int m_SlideShowDelay
Определения UiHintPanel.c:301
TextWidget m_UiHeadlineLabel
Определения UiHintPanel.c:310
DayZGame m_Game
Определения UiHintPanel.c:316
void ShowPreviousPage()
Определения UiHintPanel.c:497
TextWidget m_UiPageingLabel
Определения UiHintPanel.c:312
void PopulateLayout()
Определения UiHintPanel.c:403
void UiHintPanel(Widget parent_widget)
Определения UiHintPanel.c:324
ButtonWidget m_UiLeftButton
Определения UiHintPanel.c:307
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения UiHintPanel.c:570
int m_PreviousRandomIndex
Определения UiHintPanel.c:319
void LoadContentList()
Определения UiHintPanel.c:374
void ShowNextPage()
Определения UiHintPanel.c:481
Определения EnDebug.c:233
Определения EnMath.c:7
Определения gameplay.c:317
Определения 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