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

◆ PopulateLayout()

void Init::PopulateLayout ( )
protected

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

408{
409 #ifdef DIAG_DEVELOPER
410 static int m_ForcedIndex = -1;//only for debug purposes
411 #endif
412
413 // Const
414 protected int m_SlideShowDelay = 25000; // The speed of the slideshow
415 protected string m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints.layout"; // Layout path
416 protected const string m_DataPath = "scripts/data/hints.json"; // Json path
417 // Widgets
418 protected Widget m_RootFrame;
419 protected Widget m_SpacerFrame;
420 protected ButtonWidget m_UiLeftButton;
421 protected ButtonWidget m_UiRightButton;
424 protected ImageWidget m_UiHintImage;
426 // Data
428 protected int m_PageIndex = int.MIN;
429 protected DayZGame m_Game;
430 protected bool m_Initialized;
431 protected Widget m_ParentWidget;
432 protected int m_PreviousRandomIndex = int.MIN;
433
434 // ---------------------------------------------------------
435
436 // Constructor
437 void UiHintPanel(Widget parent_widget)
438 {
439 DayZGame game = DayZGame.Cast(GetGame());
440 m_ParentWidget = parent_widget;
441 Init(game);
442 }
443 // Destructor
444 void ~UiHintPanel()
445 {
447
448 if(m_RootFrame)
449 m_RootFrame.Unlink();
450 }
451
452
453 void Init(DayZGame game)
454 {
455 //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
456 //however for modding legacy support purposes, this was done without modifying the CTOR signature with the addition of the Init method,
457 //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
458
459 if (m_Initialized)
460 return;
461 if (!game)//is null when instantiated from DayZGame during loading before calling Init explicitly
462 return;
463 m_Initialized = true;
464
465 m_Game = game;
466 // Load Json File
468 // If load successful
469 if (m_ContentList)
470 {
471 // Build the layout
473 // Get random page index
475 // Populate the layout with data
477 // Start the slideshow
479 }
480 else
481 ErrorEx("Could not create the hint panel. The data are missing!");
482 }
483
484 // ------------------------------------------------------
485
486 // Load content data from json file
487 protected void LoadContentList()
488 {
489 string errorMessage;
490 if (!JsonFileLoader<array<ref HintPage>>.LoadFile(m_DataPath, m_ContentList, errorMessage))
491 ErrorEx(errorMessage);
492 }
493
494 // Create and Build the layout
495 protected void BuildLayout(Widget parent_widget)
496 {
497 // Create the layout
498 m_RootFrame = m_Game.GetWorkspace().CreateWidgets(m_RootPath, parent_widget);
499
500 if (m_RootFrame)
501 {
502 // Find Widgets
503 m_SpacerFrame = m_RootFrame.FindAnyWidget("GridSpacerWidget1");
504 m_UiLeftButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("LeftButton"));
505 m_UiRightButton = ButtonWidget.Cast(m_RootFrame.FindAnyWidget("RightButton"));
506 m_UiHeadlineLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("HeadlineLabel"));
507 m_UiDescLabel = RichTextWidget.Cast(m_RootFrame.FindAnyWidget("HintDescLabel"));
508 m_UiHintImage = ImageWidget.Cast(m_RootFrame.FindAnyWidget("HintImage"));
509 m_UiPageingLabel = TextWidget.Cast(m_RootFrame.FindAnyWidget("PageInfoLabel"));
510 // Set handler
511 m_RootFrame.SetHandler(this);
512 }
513 }
514
515 // Populate the hint with content
516 protected void PopulateLayout()
517 {
518 if (m_RootFrame)
519 {
522 SetHintImage();
524 }
525 }
526
527 // -------------------------------------------
528 // Setters
529 protected void SetHintHeadline()
530 {
531 m_UiHeadlineLabel.SetText(m_ContentList.Get(m_PageIndex).GetHeadlineText());
532 }
533 protected void SetHintDescription()
534 {
535 #ifdef DEVELOPER
536 //Print("showing contents for page "+m_PageIndex);
537 #endif
538 m_UiDescLabel.SetText(m_ContentList.Get(m_PageIndex).GetDescriptionText());
539 m_UiDescLabel.Update();
540 m_SpacerFrame.Update();
541 }
542 protected void SetHintImage()
543 {
544 string image_path = m_ContentList.Get(m_PageIndex).GetImagePath();
545
546 // If there is an image
547 if (image_path)
548 {
549 // Show the widget
550 m_UiHintImage.Show(true);
551 // Set the image path
552 m_UiHintImage.LoadImageFile(0, image_path);
553 }
554 else
555 {
556 // Hide the widget
557 m_UiHintImage.Show(false);
558 }
559 }
560 protected void SetHintPaging()
561 {
563 m_UiPageingLabel.SetText(string.Format("%1 / %2", m_PageIndex + 1, m_ContentList.Count()));
564 }
565
566 void ShowRandomPage()
567 {
570 }
571
572 // Set a random page index
573 protected void RandomizePageIndex()
574 {
575 #ifdef DIAG_DEVELOPER
577 {
578 if (m_ForcedIndex != -1)
579 {
580 m_PageIndex = Math.Clamp(m_ForcedIndex,0,m_ContentList.Count() - 1);
581 return;
582 }
583 }
584 #endif
585
586 Math.Randomize(m_Game.GetTime());
587 Math.RandomFloat01();//throw-away value, without calling this, the next random number is always the same, calling Math.Randomize(-1) makes no difference
591
592 }
593 // Show next hint page by incrementing the page index.
594 protected void ShowNextPage()
595 {
596 // Update the page index
597 if ( m_PageIndex < m_ContentList.Count() - 1 )
598 {
599 m_PageIndex++;
600 }
601 else
602 {
603 m_PageIndex = 0;
604 }
605
606 //Update the hint page
608 }
609 // Show previous hint page by decreasing the page index.
610 protected void ShowPreviousPage()
611 {
612 // Update the page index
613 if ( m_PageIndex == 0 )
614 {
615 m_PageIndex = m_ContentList.Count() - 1;
616 }
617 else
618 {
619 m_PageIndex--;
620
621 }
622 //Update the hint page
624 }
625
626 // -------------------------------------------
627 // Slideshow
628
629 // Creates new slidshow thread
630 protected void StartSlideshow()
631 {
633 }
634 // Slidshow thread - run code
635 protected void SlideshowThread()
636 {
637 ShowNextPage();
638 }
639 // Stop the slide show
640 protected void StopSlideShow()
641 {
642 m_Game.GetCallQueue(CALL_CATEGORY_GUI).Remove(SlideshowThread);
643 }
644 // Restart the slide show
645 protected void RestartSlideShow()
646 {
649 }
650
651 // ----------------------------------------
652 // Layout manipulation
653
654 override bool OnClick(Widget w, int x, int y, int button)
655 {
656 if (button == MouseState.LEFT)
657 {
658 switch (w)
659 {
660 case m_UiLeftButton:
661 {
663 return true;
664 }
665 case m_UiRightButton:
666 {
667 ShowNextPage();
668 return true;
669 }
670 }
671 }
672 return false;
673 }
674 override bool OnMouseEnter(Widget w, int x, int y)
675 {
676 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
677 {
679 return true;
680 }
681 return false;
682 }
683 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
684 {
685 if (w == m_RootPath || w == m_UiLeftButton || w == m_UiRightButton)
686 {
688 return true;
689 }
690 return false;
691 }
692}
693
694// ---------------------------------------------------------------------------------------------------------
695class UiHintPanelLoading extends UiHintPanel
696{
697 override void Init(DayZGame game)
698 {
699 m_RootPath = "Gui/layouts/new_ui/hints/in_game_hints_load.layout";
700 super.Init(game);
701 }
702}
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