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

◆ RandomizePageIndex()

void Init::RandomizePageIndex ( )
protected

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

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