Пример #1
0
    public MainMenuUi()
    {
        var mmLocalization = Tig.FS.ReadMesFile("mes/mainmenu.mes");

        var widgetDoc = WidgetDoc.Load("ui/main_menu.json", (type, definition) => {
            if (type == "mainMenuButton")
            {
                return(CreateMainMenuButton(definition));
            }
            else
            {
                throw new ArgumentException("Unknown custom widget type: " + type);
            }
        });

        mMainWidget = widgetDoc.GetRootContainer();

        mViewCinematicsDialog = new ViewCinematicsDialog(this, mmLocalization);
        mSetPiecesDialog      = new SetPiecesDialog(this);

        // This eats all mouse messages that reach the full-screen main menu
        mMainWidget.SetMouseMsgHandler(msg => { return(true); });
        mMainWidget.SetWidgetMsgHandler(msg => { return(true); });

        mMainWidget.SetKeyStateChangeHandler(msg =>
        {
            // Close the menu if it's the ingame menu
            if (msg.key == DIK.DIK_ESCAPE && !msg.down)
            {
                if (mCurrentPage == MainMenuPage.InGameNormal || mCurrentPage == MainMenuPage.InGameIronman)
                {
                    Hide();
                }
            }

            return(true);
        });

        mPagesWidget = widgetDoc.GetContainer("pages");

        mPageWidgets[MainMenuPage.MainMenu]      = widgetDoc.GetContainer("page-main-menu");
        mPageWidgets[MainMenuPage.Difficulty]    = widgetDoc.GetContainer("page-difficulty");
        mPageWidgets[MainMenuPage.InGameNormal]  = widgetDoc.GetContainer("page-ingame-normal");
        mPageWidgets[MainMenuPage.InGameIronman] = widgetDoc.GetContainer("page-ingame-ironman");
        mPageWidgets[MainMenuPage.Options]       = widgetDoc.GetContainer("page-options");
        //mPageWidgets[MainMenuPage.SetPieces] = widgetDoc.GetWindow("page-set-pieces");

        MainMenuButton GetButton(string id)
        {
            return((MainMenuButton)widgetDoc.GetWidget(id));
        }

        // Wire up buttons on the main menu
        GetButton("new-game").SetClickHandler(() => { Show(MainMenuPage.Difficulty); });
        GetButton("load-game").SetClickHandler(() =>
        {
            Hide();
            UiSystems.SaveGame.ShowLoad(true);
        });
        GetButton("tutorial").SetClickHandler(() => LaunchTutorial());
        GetButton("options").SetClickHandler(() => { Show(MainMenuPage.Options); });
        GetButton("quit-game").SetClickHandler(() =>
        {
            Tig.MessageQueue.Enqueue(new Message(MessageType.EXIT));
        });

        // Wire up buttons on the difficulty selection page
        GetButton("difficulty-normal").SetClickHandler(() =>
        {
            Globals.GameLib.IsIronmanGame = false;
            Hide();
            UiSystems.PCCreation.Start();
        });
        GetButton("difficulty-ironman").SetClickHandler(() =>
        {
            Globals.GameLib.IsIronmanGame = true;
            Hide();
            UiSystems.PCCreation.Start();
        });
        GetButton("difficulty-exit").SetClickHandler(() => { Show(MainMenuPage.MainMenu); });

        // Wire up buttons on the ingame menu (normal difficulty)
        GetButton("ingame-normal-load").SetClickHandler(() =>
        {
            Hide();
            UiSystems.SaveGame.ShowLoad(false);
        });
        GetButton("ingame-normal-save").SetClickHandler(() =>
        {
            Hide();
            UiSystems.SaveGame.ShowSave(true);
        });
        GetButton("ingame-normal-close").SetClickHandler(Hide);
        GetButton("ingame-normal-quit").SetClickHandler(() =>
        {
            Hide();
            GameSystems.ResetGame();
            UiSystems.Reset();
            Show(MainMenuPage.MainMenu);
        });

        // Wire up buttons on the ingame menu (ironman difficulty)
        GetButton("ingame-ironman-close").SetClickHandler(Hide);
        GetButton("ingame-ironman-save-quit").SetClickHandler(() =>
        {
            Globals.GameLib.IronmanSave();
            Globals.GameLib.Reset();
            UiSystems.Reset();
            Show(MainMenuPage.MainMenu);
        });

        // Wire up buttons on the ingame menu (ironman difficulty)
        GetButton("options-show").SetClickHandler(() =>
        {
            Hide();
            UiSystems.Options.Show(true);
        });
        GetButton("options-view-cinematics").SetClickHandler(() =>
        {
            Hide();
            UiSystems.UtilityBar.Hide();
            // TODO ui_mm_msg_ui4();
            mViewCinematicsDialog.Show();
        });
        GetButton("options-credits").SetClickHandler(() =>
        {
            Hide();

            List <int> creditsMovies = new List <int> {
                100, 110, 111, 112, 113
            };
            foreach (var movieId in creditsMovies)
            {
                GameSystems.Movies.MovieQueueAdd(movieId);
            }

            GameSystems.Movies.MovieQueuePlay();

            Show(MainMenuPage.Options);
        });
        GetButton("options-back").SetClickHandler(() => { Show(MainMenuPage.MainMenu); });

        RepositionWidgets(Globals.UiManager.CanvasSize);
        Globals.UiManager.OnCanvasSizeChanged += RepositionWidgets;

        Hide(); // Hide everything by default
    }