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

◆ ShowRandomPage()

void Init::ShowRandomPage ( )
protected

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

458{
459 #ifdef DIAG_DEVELOPER
460 static int m_ForcedIndex = -1;//only for debug purposes
461 #endif
462
463 // Const
464 protected int m_SlideShowDelay = 25000; // The speed of the slideshow
465 protected string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
466 protected const string m_DataPath = "scripts/data/hints.json"; // Json path
467 // Widgets
468 protected Widget m_RootFrame;
469 protected Widget m_SpacerFrame;
470 protected ButtonWidget m_UiLeftButton;
471 protected ButtonWidget m_UiRightButton;
474 protected ImageWidget m_UiHintImage;
476 // Data
478 protected int m_PageIndex = int.MIN;
479 protected DayZGame m_Game;
480 protected bool m_Initialized;
481 protected Widget m_ParentWidget;
482 protected int m_PreviousRandomIndex = int.MIN;
483
484 // ---------------------------------------------------------
485
486 // Constructor
487 void UiHintPanel(Widget parent_widget)
488 {
489 DayZGame game = DayZGame.Cast(GetGame());
490 m_ParentWidget = parent_widget;
491 Init(game);
492 }
493 // Destructor
494 void ~UiHintPanel()
495 {
497
498 if(m_RootFrame)
499 m_RootFrame.Unlink();
500 }
501
502
503 void Init(DayZGame game)
504 {
505 //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
506 //however for modding legacy support purposes, this was done without modifying the CTOR signature with the addition of the Init method,
507 //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
508
509 if (m_Initialized)
510 return;
511 if (!game)//is null when instantiated from DayZGame during loading before calling Init explicitly
512 return;
513 m_Initialized = true;
514
515 m_Game = game;
516 // Load Json File
518 // If load successful
519 if (m_ContentList)
520 {
521 // Build the layout
523 // Get random page index
525 // Populate the layout with data
527 // Start the slideshow
529 }
530 else
531 ErrorEx("Could not create the hint panel. The data are missing!");
532 }
533
534 // ------------------------------------------------------
535
536 // Load content data from json file
537 protected void LoadContentList()
538 {
539 string errorMessage;
540 if (!JsonFileLoader<array<ref HintPage>>.LoadFile(m_DataPath, m_ContentList, errorMessage))
541 ErrorEx(errorMessage);
542 }
543
544 // Create and Build the layout
545 protected void BuildLayout(Widget parent_widget)
546 {
547 // Create the layout
548 m_RootFrame = m_Game.GetWorkspace().CreateWidgets(m_RootPath, parent_widget);
549
550 if (m_RootFrame)
551 {
552 // Find Widgets
553 m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
554 m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
555 m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
556 m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
557 m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
558 m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
559 m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
560 // Set handler
561 m_RootFrame.SetHandler(this);
562 }
563 }
564
565 // Populate the hint with content
566 protected void PopulateLayout()
567 {
568 if (m_RootFrame)
569 {
572 SetHintImage();
574 }
575 }
576
577 // -------------------------------------------
578 // Setters
579 protected void SetHintHeadline()
580 {
581 m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
582 }
583 protected void SetHintDescription()
584 {
585 #ifdef DEVELOPER
586 //Print("showing contents for page "+m_PageIndex);
587 #endif
588 m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
589 m_UiDescLabel.Update();
590 m_SpacerFrame.Update();
591 }
592 protected void SetHintImage()
593 {
594 string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
595
596 // If there is an image
597 if (image_path)
598 {
599 // Show the widget
600 m_UiHintImage.Show(true);
601 // Set the image path
602 m_UiHintImage.LoadImageFile(0, image_path);
603 }
604 else
605 {
606 // Hide the widget
607 m_UiHintImage.Show(false);
608 }
609 }
610 protected void SetHintPaging()
611 {
613 m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
614 }
615
616 void ShowRandomPage()
617 {
620 }
621
622 // Set a random page index
623 protected void RandomizePageIndex()
624 {
625 #ifdef DIAG_DEVELOPER
627 {
628 if (m_ForcedIndex != -1)
629 {
630 m_PageIndex = Math.Clamp(m_ForcedIndex,0,m_ContentList.Count() - 1);
631 return;
632 }
633 }
634 #endif
635
636 Math.Randomize(m_Game.GetTime());
637 Math.RandomFloat01();//throw-away value, without calling this, the next random number is always the same, calling Math.Randomize(-1) makes no difference
641
642 }
643 // Show next hint page by incrementing the page index.
644 protected void ShowNextPage()
645 {
646 // Update the page index
647 if ( m_PageIndex < m_ContentList.Count() - 1 )
648 {
649 m_PageIndex++;
650 }
651 else
652 {
653 m_PageIndex = 0;
654 }
655
656 //Update the hint page
658 }
659 // Show previous hint page by decreasing the page index.
660 protected void ShowPreviousPage()
661 {
662 // Update the page index
663 if ( m_PageIndex == 0 )
664 {
665 m_PageIndex = m_ContentList.Count() - 1;
666 }
667 else
668 {
669 m_PageIndex--;
670
671 }
672 //Update the hint page
674 }
675
676 // -------------------------------------------
677 // Slideshow
678
679 // Creates new slidshow thread
680 protected void StartSlideshow()
681 {
683 }
684 // Slidshow thread - run code
685 protected void SlideshowThread()
686 {
687 ShowNextPage();
688 }
689 // Stop the slide show
690 protected void StopSlideShow()
691 {
692 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
693 }
694 // Restart the slide show
695 protected void RestartSlideShow()
696 {
699 }
700
701 // ----------------------------------------
702 // Layout manipulation
703
704 override bool OnClick(Widget w, int x, int y, int button)
705 {
706 if (button == MouseState.LEFT)
707 {
708 switch (w)
709 {
710 case m_UiLeftButton:
711 {
713 return true;
714 }
715 case m_UiRightButton:
716 {
717 ShowNextPage();
718 return true;
719 }
720 }
721 }
722 return false;
723 }
724 override bool OnMouseEnter(Widget w, int x, int y)
725 {
726 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
727 {
729 return true;
730 }
731 return false;
732 }
733 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
734 {
735 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
736 {
738 return true;
739 }
740 return false;
741 }
742}
743
744// ---------------------------------------------------------------------------------------------------------
745class UiHintPanelLoading extends UiHintPanel
746{
747 override void Init(DayZGame game)
748 {
749 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
750 super.Init(game);
751 }
752}
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