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

◆ BuildLayout()

void Init::BuildLayout ( Widget parent_widget)
protected

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

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