Beispiel #1
0
 private void ThreadStartFunction()
 {
     actualForm = FormPool.GetForm(Views.MainMenuForm);
     //reset handler
     actualForm.MenuOptionChange -= menuEventHandler;
     actualForm.MenuOptionChange += menuEventHandler;
     actualForm.MessageBoxShow   -= messageBoxEventHandler;
     actualForm.MessageBoxShow   += messageBoxEventHandler;
     actualForm.Show();
 }
Beispiel #2
0
        private void switchView(Views viewToSwitch, bool hideLast, bool modal)
        {
            if (hideLast)
            {
                actualForm.Hide();
            }

            actualView = viewToSwitch;
            actualForm = FormPool.GetForm(viewToSwitch);

            //reset handler
            actualForm.MenuOptionChange -= menuEventHandler;
            actualForm.MenuOptionChange += menuEventHandler;
            actualForm.MessageBoxShow   -= messageBoxEventHandler;
            actualForm.MessageBoxShow   += messageBoxEventHandler;


            if (actualForm.InvokeRequired)
            {
                actualForm.Invoke(new TopMostEventHandler(SetFormTopMost), new object[] { actualForm, modal });
            }
            else
            {
                SetFormTopMost(actualForm, modal);
            }

            if (actualForm.Visible == false)
            {
                if (actualForm.InvokeRequired)
                {
                    actualForm.Invoke(new FormShowEventHandler(actualForm.Show), new object[] { mainForm });
                }
                else
                {
                    actualForm.Show(mainForm);
                }
            }
        }
Beispiel #3
0
        void Simulation_GameEnd(int winTeamId)
        {
            InfoLog.WriteInfo("Game End Event", EPrefix.ClientInformation);

            //GameGraphics.GameGraphicsChanged -= new EventHandler(gg_GameGraphicsChanged);
            //mapView.Paint -= new PaintEventHandler(openGLView_Paint);

            GameGraphics.DeinitGL();

            _gameLogic.Simulation.AbortSimulation();

            _gameLogic.Simulation.BuildingCompleted -= new ClientSimulation.BuildingCreationHandler(Simulation_OnBuildingCompleted);
            _gameLogic.Simulation.UnitCompleted     -= new ClientSimulation.UnitHandler(Simulation_OnUnitCompleted);
            //_gameLogic.Simulation.onTurnEnd -= new SimulationHandler(Simulation_onTurnEnd);
            _gameLogic.Simulation.OnCreditsUpdate -= new ClientSimulation.OnCreditsHandler(UpdateCredits);
            _gameLogic.Simulation.InvalidBuild    -= new ClientSimulation.InvalidBuildHandler(_buildManager.OnBadLocation);
            //_gameLogic.Simulation.onTurnEnd -= new SimulationHandler(_buildManager.ProcessTurn);
            _gameLogic.Simulation.BuildingDestroyed -= new ClientSimulation.BuildingHandler(Simulation_BuildingDestroyed);
            _gameLogic.Simulation.UpdateStripItem   -= new ClientSimulation.UpdateStripItemHandler(this.UpdateStrip);
            _gameLogic.OnBadLocation -= new GameLogic.BadLocationHandler(_buildManager.OnBadLocation);
            _gameLogic.GameEnd       -= new GameLogic.GameEndHandler(Simulation_GameEnd);
            _gameLogic.PauseResume   -= new GameLogic.PauseResumeHandler(this.onPauseResume);

            GameMessageHandler.Instance.GameInitialization -= new GameInitEventHandler(Instance_GameInitialization);

            bool   isWinner           = false;
            string endGameInformation = string.Empty;

            if (winTeamId == _gameLogic.CurrentPlayer.TeamID)
            {
                isWinner = true;
            }

            /* Playing proper music */
            if (isWinner)
            {
                endGameInformation = "Congratulations, you won!";
                AudioEngine.Instance.Music.Play(MusicType.Win);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Win);
            }
            else
            {
                endGameInformation = "Unfortunately you lost!";
                AudioEngine.Instance.Music.Play(MusicType.Lose);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Lose);
            }

            /*
             * KŒ: tu jest burdel, GameForm nie jest od przepinania handlerów, ani od zarz¹dzania okienkami w aplikacji
             * nie mo¿na wyœwietliæ GameForm jako okna modalnego, albo zrobiæ w nim event?
             */

            /* Sending message to server */
            GameEndMessage gameEndMessage = (GameEndMessage)Utils.CreateMessageWithSenderId(MessageType.EndGame);

            gameEndMessage.HasWon = isWinner;

            /* Managing the UI */
            MainMenuForm mainMenuForm = FormPool.GetForm(Views.ChatForm) as MainMenuForm;

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Suspend();
            }

            Connection.Instance.MessageHandler = mainMenuForm.MenuMessageHandler;
            Connection.Instance.SendMessage(gameEndMessage);
            this.OnMessageBoxShow(endGameInformation, "Game End", MessageBoxButtons.OK, MessageBoxIcon.Information);
            /* Stop playing music */
            AudioEngine.Instance.Music.Stop();

            this.GameFormClose = true;
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(this.Close));
            }
            else
            {
                this.Close();
            }

            // dosyc nieladne, bo to moze byc przejscie i z pause i z gamemenu (bo moga byc nad gameform)
            OnMenuOptionChange(new MenuOptionArg(MenuOption.Exit, this, true));

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Resume();
            }

            //_gameLogic.Simulation.AbortSimulation();
        }