private void BtnExStatistics_LeftClick(object sender, EventArgs e)
        {
            MainMenuDarkeningPanel parent = (MainMenuDarkeningPanel)Parent;

            parent.Show(parent.StatisticsWindow);
        }
        /// <summary>
        /// Initializes the main menu's controls.
        /// </summary>
        public override void Initialize()
        {
            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;

            Name = nameof(MainMenu);
            BackgroundTexture = AssetLoader.LoadTexture("MainMenu/mainmenubg.png");
            ClientRectangle   = new Rectangle(0, 0, BackgroundTexture.Width, BackgroundTexture.Height);

            WindowManager.CenterControlOnScreen(this);

            btnNewCampaign                  = new XNAClientButton(WindowManager);
            btnNewCampaign.Name             = nameof(btnNewCampaign);
            btnNewCampaign.IdleTexture      = AssetLoader.LoadTexture("MainMenu/campaign.png");
            btnNewCampaign.HoverTexture     = AssetLoader.LoadTexture("MainMenu/campaign_c.png");
            btnNewCampaign.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnNewCampaign.LeftClick       += BtnNewCampaign_LeftClick;

            btnLoadGame                  = new XNAClientButton(WindowManager);
            btnLoadGame.Name             = nameof(btnLoadGame);
            btnLoadGame.IdleTexture      = AssetLoader.LoadTexture("MainMenu/loadmission.png");
            btnLoadGame.HoverTexture     = AssetLoader.LoadTexture("MainMenu/loadmission_c.png");
            btnLoadGame.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnLoadGame.LeftClick       += BtnLoadGame_LeftClick;

            btnSkirmish                  = new XNAClientButton(WindowManager);
            btnSkirmish.Name             = nameof(btnSkirmish);
            btnSkirmish.IdleTexture      = AssetLoader.LoadTexture("MainMenu/skirmish.png");
            btnSkirmish.HoverTexture     = AssetLoader.LoadTexture("MainMenu/skirmish_c.png");
            btnSkirmish.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnSkirmish.LeftClick       += BtnSkirmish_LeftClick;

            btnCnCNet                  = new XNAClientButton(WindowManager);
            btnCnCNet.Name             = nameof(btnCnCNet);
            btnCnCNet.IdleTexture      = AssetLoader.LoadTexture("MainMenu/cncnet.png");
            btnCnCNet.HoverTexture     = AssetLoader.LoadTexture("MainMenu/cncnet_c.png");
            btnCnCNet.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnCnCNet.LeftClick       += BtnCnCNet_LeftClick;

            btnLan                  = new XNAClientButton(WindowManager);
            btnLan.Name             = nameof(btnLan);
            btnLan.IdleTexture      = AssetLoader.LoadTexture("MainMenu/lan.png");
            btnLan.HoverTexture     = AssetLoader.LoadTexture("MainMenu/lan_c.png");
            btnLan.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnLan.LeftClick       += BtnLan_LeftClick;

            btnOptions                  = new XNAClientButton(WindowManager);
            btnOptions.Name             = nameof(btnOptions);
            btnOptions.IdleTexture      = AssetLoader.LoadTexture("MainMenu/options.png");
            btnOptions.HoverTexture     = AssetLoader.LoadTexture("MainMenu/options_c.png");
            btnOptions.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnOptions.LeftClick       += BtnOptions_LeftClick;

            btnMapEditor                  = new XNAClientButton(WindowManager);
            btnMapEditor.Name             = nameof(btnMapEditor);
            btnMapEditor.IdleTexture      = AssetLoader.LoadTexture("MainMenu/mapeditor.png");
            btnMapEditor.HoverTexture     = AssetLoader.LoadTexture("MainMenu/mapeditor_c.png");
            btnMapEditor.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnMapEditor.LeftClick       += BtnMapEditor_LeftClick;

            btnStatistics                  = new XNAClientButton(WindowManager);
            btnStatistics.Name             = nameof(btnStatistics);
            btnStatistics.IdleTexture      = AssetLoader.LoadTexture("MainMenu/statistics.png");
            btnStatistics.HoverTexture     = AssetLoader.LoadTexture("MainMenu/statistics_c.png");
            btnStatistics.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnStatistics.LeftClick       += BtnStatistics_LeftClick;

            btnCredits                  = new XNAClientButton(WindowManager);
            btnCredits.Name             = nameof(btnCredits);
            btnCredits.IdleTexture      = AssetLoader.LoadTexture("MainMenu/credits.png");
            btnCredits.HoverTexture     = AssetLoader.LoadTexture("MainMenu/credits_c.png");
            btnCredits.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnCredits.LeftClick       += BtnCredits_LeftClick;

            btnExtras                  = new XNAClientButton(WindowManager);
            btnExtras.Name             = nameof(btnExtras);
            btnExtras.IdleTexture      = AssetLoader.LoadTexture("MainMenu/extras.png");
            btnExtras.HoverTexture     = AssetLoader.LoadTexture("MainMenu/extras_c.png");
            btnExtras.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnExtras.LeftClick       += BtnExtras_LeftClick;

            var btnExit = new XNAClientButton(WindowManager);

            btnExit.Name             = nameof(btnExit);
            btnExit.IdleTexture      = AssetLoader.LoadTexture("MainMenu/exitgame.png");
            btnExit.HoverTexture     = AssetLoader.LoadTexture("MainMenu/exitgame_c.png");
            btnExit.HoverSoundEffect = new EnhancedSoundEffect("MainMenu/button.wav");
            btnExit.LeftClick       += BtnExit_LeftClick;

            XNALabel lblCnCNetStatus = new XNALabel(WindowManager);

            lblCnCNetStatus.Name            = nameof(lblCnCNetStatus);
            lblCnCNetStatus.Text            = "DTA players on CnCNet:";
            lblCnCNetStatus.ClientRectangle = new Rectangle(12, 9, 0, 0);

            lblCnCNetPlayerCount      = new XNALabel(WindowManager);
            lblCnCNetPlayerCount.Name = nameof(lblCnCNetPlayerCount);
            lblCnCNetPlayerCount.Text = "-";

            lblVersion            = new XNALinkLabel(WindowManager);
            lblVersion.Name       = nameof(lblVersion);
            lblVersion.LeftClick += LblVersion_LeftClick;

            lblUpdateStatus                 = new XNALinkLabel(WindowManager);
            lblUpdateStatus.Name            = nameof(lblUpdateStatus);
            lblUpdateStatus.LeftClick      += LblUpdateStatus_LeftClick;
            lblUpdateStatus.ClientRectangle = new Rectangle(0, 0, 160, 20);

            AddChild(btnNewCampaign);
            AddChild(btnLoadGame);
            AddChild(btnSkirmish);
            AddChild(btnCnCNet);
            AddChild(btnLan);
            AddChild(btnOptions);
            AddChild(btnMapEditor);
            AddChild(btnStatistics);
            AddChild(btnCredits);
            AddChild(btnExtras);
            AddChild(btnExit);
            AddChild(lblCnCNetStatus);
            AddChild(lblCnCNetPlayerCount);

            if (!ClientConfiguration.Instance.ModMode)
            {
                // ModMode disables version tracking and the updater if it's enabled

                AddChild(lblVersion);
                AddChild(lblUpdateStatus);

                CUpdater.FileIdentifiersUpdated     += CUpdater_FileIdentifiersUpdated;
                CUpdater.OnCustomComponentsOutdated += CUpdater_OnCustomComponentsOutdated;
            }

            base.Initialize(); // Read control attributes from INI

            innerPanel = new MainMenuDarkeningPanel(WindowManager, discordHandler);
            innerPanel.ClientRectangle = new Rectangle(0, 0,
                                                       Width,
                                                       Height);
            innerPanel.DrawOrder   = int.MaxValue;
            innerPanel.UpdateOrder = int.MaxValue;
            AddChild(innerPanel);
            innerPanel.Hide();

            lblVersion.Text = CUpdater.GameVersion;

            innerPanel.UpdateQueryWindow.UpdateDeclined += UpdateQueryWindow_UpdateDeclined;
            innerPanel.UpdateQueryWindow.UpdateAccepted += UpdateQueryWindow_UpdateAccepted;

            innerPanel.UpdateWindow.UpdateCompleted += UpdateWindow_UpdateCompleted;
            innerPanel.UpdateWindow.UpdateCancelled += UpdateWindow_UpdateCancelled;
            innerPanel.UpdateWindow.UpdateFailed    += UpdateWindow_UpdateFailed;

            this.ClientRectangle = new Rectangle((WindowManager.RenderResolutionX - Width) / 2,
                                                 (WindowManager.RenderResolutionY - Height) / 2,
                                                 Width, Height);
            innerPanel.ClientRectangle = new Rectangle(0, 0,
                                                       Math.Max(WindowManager.RenderResolutionX, Width),
                                                       Math.Max(WindowManager.RenderResolutionY, Height));

            CnCNetPlayerCountTask.CnCNetGameCountUpdated += CnCNetInfoController_CnCNetGameCountUpdated;
            cncnetPlayerCountCancellationSource           = new CancellationTokenSource();
            CnCNetPlayerCountTask.InitializeService(cncnetPlayerCountCancellationSource);

            WindowManager.GameClosing += WindowManager_GameClosing;

            skirmishLobby.Exited         += SkirmishLobby_Exited;
            lanLobby.Exited              += LanLobby_Exited;
            optionsWindow.EnabledChanged += OptionsWindow_EnabledChanged;

            optionsWindow.OnForceUpdate += (s, e) => ForceUpdate();

            GameProcessLogic.GameProcessStarted  += SharedUILogic_GameProcessStarted;
            GameProcessLogic.GameProcessStarting += SharedUILogic_GameProcessStarting;

            UserINISettings.Instance.SettingsSaved += SettingsSaved;

            CUpdater.Restart += CUpdater_Restart;

            SetButtonHotkeys(true);
        }
Exemple #3
0
        public override void Initialize()
        {
            GameProcessLogic.GameProcessExited += SharedUILogic_GameProcessExited;

            Name = "MainMenu";
            BackgroundTexture = AssetLoader.LoadTexture("MainMenu\\mainmenubg.png");
            ClientRectangle   = new Rectangle(0, 0, BackgroundTexture.Width, BackgroundTexture.Height);

            WindowManager.CenterControlOnScreen(this);

            var btnNewCampaign = new XNAClientButton(WindowManager);

            btnNewCampaign.Name             = "btnNewCampaign";
            btnNewCampaign.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\campaign.png");
            btnNewCampaign.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\campaign_c.png");
            btnNewCampaign.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnNewCampaign.LeftClick       += BtnNewCampaign_LeftClick;
            btnNewCampaign.HotKey           = Keys.C;

            var btnLoadGame = new XNAClientButton(WindowManager);

            btnLoadGame.Name             = "btnLoadGame";
            btnLoadGame.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\loadmission.png");
            btnLoadGame.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\loadmission_c.png");
            btnLoadGame.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnLoadGame.LeftClick       += BtnLoadGame_LeftClick;
            btnLoadGame.HotKey           = Keys.L;

            var btnSkirmish = new XNAClientButton(WindowManager);

            btnSkirmish.Name             = "btnSkirmish";
            btnSkirmish.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\skirmish.png");
            btnSkirmish.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\skirmish_c.png");
            btnSkirmish.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnSkirmish.LeftClick       += BtnSkirmish_LeftClick;
            btnSkirmish.HotKey           = Keys.S;

            var btnCnCNet = new XNAClientButton(WindowManager);

            btnCnCNet.Name             = "btnCnCNet";
            btnCnCNet.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\cncnet.png");
            btnCnCNet.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\cncnet_c.png");
            btnCnCNet.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnCnCNet.LeftClick       += BtnCnCNet_LeftClick;
            btnCnCNet.HotKey           = Keys.M;

            var btnLan = new XNAClientButton(WindowManager);

            btnLan.Name             = "btnLan";
            btnLan.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\lan.png");
            btnLan.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\lan_c.png");
            btnLan.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnLan.LeftClick       += BtnLan_LeftClick;
            btnLan.HotKey           = Keys.N;

            var btnOptions = new XNAClientButton(WindowManager);

            btnOptions.Name             = "btnOptions";
            btnOptions.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\options.png");
            btnOptions.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\options_c.png");
            btnOptions.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnOptions.LeftClick       += BtnOptions_LeftClick;
            btnOptions.HotKey           = Keys.O;

            var btnMapEditor = new XNAClientButton(WindowManager);

            btnMapEditor.Name             = "btnMapEditor";
            btnMapEditor.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\mapeditor.png");
            btnMapEditor.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\mapeditor_c.png");
            btnMapEditor.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnMapEditor.LeftClick       += BtnMapEditor_LeftClick;
            btnMapEditor.HotKey           = Keys.E;

            var btnStatistics = new XNAClientButton(WindowManager);

            btnStatistics.Name             = "btnStatistics";
            btnStatistics.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\statistics.png");
            btnStatistics.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\statistics_c.png");
            btnStatistics.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnStatistics.LeftClick       += BtnStatistics_LeftClick;
            btnStatistics.HotKey           = Keys.T;

            var btnCredits = new XNAClientButton(WindowManager);

            btnCredits.Name             = "btnCredits";
            btnCredits.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\credits.png");
            btnCredits.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\credits_c.png");
            btnCredits.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnCredits.LeftClick       += BtnCredits_LeftClick;
            btnCredits.HotKey           = Keys.R;

            var btnExtras = new XNAClientButton(WindowManager);

            btnExtras.Name             = "btnExtras";
            btnExtras.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\extras.png");
            btnExtras.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\extras_c.png");
            btnExtras.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnExtras.LeftClick       += BtnExtras_LeftClick;
            btnExtras.HotKey           = Keys.E;

            var btnExit = new XNAClientButton(WindowManager);

            btnExit.Name             = "btnExit";
            btnExit.IdleTexture      = AssetLoader.LoadTexture("MainMenu\\exitgame.png");
            btnExit.HoverTexture     = AssetLoader.LoadTexture("MainMenu\\exitgame_c.png");
            btnExit.HoverSoundEffect = AssetLoader.LoadSound("MainMenu\\button.wav");
            btnExit.LeftClick       += BtnExit_LeftClick;

            XNALabel lblCnCNetStatus = new XNALabel(WindowManager);

            lblCnCNetStatus.Name            = "lblCnCNetStatus";
            lblCnCNetStatus.Text            = "DTA players on CnCNet:";
            lblCnCNetStatus.ClientRectangle = new Rectangle(12, 9, 0, 0);

            lblCnCNetPlayerCount      = new XNALabel(WindowManager);
            lblCnCNetPlayerCount.Name = "lblCnCNetPlayerCount";
            lblCnCNetPlayerCount.Text = "-";

            lblVersion      = new XNALabel(WindowManager);
            lblVersion.Name = "lblVersion";
            lblVersion.Text = CUpdater.GameVersion;

            lblUpdateStatus                 = new XNALinkLabel(WindowManager);
            lblUpdateStatus.Name            = "lblUpdateStatus";
            lblUpdateStatus.LeftClick      += LblUpdateStatus_LeftClick;
            lblUpdateStatus.ClientRectangle = new Rectangle(0, 0, 160, 20);

            AddChild(btnNewCampaign);
            AddChild(btnLoadGame);
            AddChild(btnSkirmish);
            AddChild(btnCnCNet);
            AddChild(btnLan);
            AddChild(btnOptions);
            AddChild(btnMapEditor);
            AddChild(btnStatistics);
            AddChild(btnCredits);
            AddChild(btnExtras);
            AddChild(btnExit);
            AddChild(lblCnCNetStatus);
            AddChild(lblCnCNetPlayerCount);

            if (!ClientConfiguration.Instance.ModMode)
            {
                AddChild(lblVersion);
                AddChild(lblUpdateStatus);

                CUpdater.FileIdentifiersUpdated += CUpdater_FileIdentifiersUpdated;
            }

            innerPanel = new MainMenuDarkeningPanel(WindowManager);
            innerPanel.ClientRectangle = new Rectangle(0, 0,
                                                       ClientRectangle.Width,
                                                       ClientRectangle.Height);
            AddChild(innerPanel);
            innerPanel.Hide();

            base.Initialize(); // Read control attributes from INI

            innerPanel.UpdateQueryWindow.UpdateDeclined += UpdateQueryWindow_UpdateDeclined;
            innerPanel.UpdateQueryWindow.UpdateAccepted += UpdateQueryWindow_UpdateAccepted;

            innerPanel.UpdateWindow.UpdateCompleted += UpdateWindow_UpdateCompleted;
            innerPanel.UpdateWindow.UpdateCancelled += UpdateWindow_UpdateCancelled;
            innerPanel.UpdateWindow.UpdateFailed    += UpdateWindow_UpdateFailed;

            this.ClientRectangle = new Rectangle((WindowManager.RenderResolutionX - ClientRectangle.Width) / 2,
                                                 (WindowManager.RenderResolutionY - ClientRectangle.Height) / 2,
                                                 ClientRectangle.Width, ClientRectangle.Height);
            innerPanel.ClientRectangle = new Rectangle(0, 0, WindowManager.RenderResolutionX, WindowManager.RenderResolutionY);

            CnCNetPlayerCountTask.CnCNetGameCountUpdated += CnCNetInfoController_CnCNetGameCountUpdated;
            cncnetPlayerCountCancellationSource           = new CancellationTokenSource();
            CnCNetPlayerCountTask.InitializeService(cncnetPlayerCountCancellationSource);

            WindowManager.GameClosing += WindowManager_GameClosing;

            skirmishLobby.Exited += SkirmishLobby_Exited;
            lanLobby.Exited      += LanLobby_Exited;

            GameProcessLogic.GameProcessStarted  += SharedUILogic_GameProcessStarted;
            GameProcessLogic.GameProcessStarting += SharedUILogic_GameProcessStarting;

            UserINISettings.Instance.SettingsSaved += SettingsSaved;

            CUpdater.Restart += CUpdater_Restart;
        }