Пример #1
0
        private void LoadLastSettings()
        {
            var path = Path.Combine(_gameMain.GameDataSet.FullName, "GameSettings.config");

            if (File.Exists(path))
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    _playerEmperorName.SetText(reader.ReadLine());
                    _playerHomeworldName.SetText(reader.ReadLine());
                    var raceName = reader.ReadLine();
                    if (raceName == "Random")
                    {
                        _playerRaces[0] = null;
                        _raceSprites[0] = _randomRaceSprite;
                    }
                    else
                    {
                        foreach (var race in _gameMain.RaceManager.Races)
                        {
                            if (race.RaceName == raceName)
                            {
                                _playerRaces[0] = race;
                                _raceSprites[0] = race.MiniAvatar;
                                break;
                            }
                        }
                    }
                    _galaxyComboBox.SelectedIndex     = int.Parse(reader.ReadLine());
                    _difficultyComboBox.SelectedIndex = int.Parse(reader.ReadLine());
                    _numericUpDownAI.SetValue(int.Parse(reader.ReadLine()));
                    for (int i = 0; i < _numericUpDownAI.Value; i++)
                    {
                        raceName = reader.ReadLine();
                        if (raceName == "Random")
                        {
                            _playerRaces[i + 1] = null;
                            _raceSprites[i + 1] = _randomRaceSprite;
                        }
                        else
                        {
                            foreach (var race in _gameMain.RaceManager.Races)
                            {
                                if (race.RaceName == raceName)
                                {
                                    _playerRaces[i + 1] = race;
                                    _raceSprites[i + 1] = race.MiniAvatar;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                _playerRaces = new Race[6];
                _numericUpDownAI.SetValue(1);
                _playerEmperorName.SetText(string.Empty);
                _playerHomeworldName.SetText(string.Empty);
                for (int i = 0; i < _raceSprites.Length; i++)
                {
                    _raceSprites[i] = _randomRaceSprite;
                }
            }
        }
Пример #2
0
        public void LoadSystem(StarSystem system, Empire currentEmpire)
        {
            _currentSystem = system;
            _currentEmpire = currentEmpire;
            if (_currentSystem.IsThisSystemExploredByEmpire(_currentEmpire))
            {
                _isExplored = true;
                var planet = _currentSystem.Planets[0];
                _name.SetText(_currentSystem.Name);
                _isOwnedSystem = _currentSystem.Planets[0].Owner == _currentEmpire;
                _name.SetTextAttributes(_currentSystem.Planets[0].Owner != null ? _currentSystem.Planets[0].Owner.EmpireColor : System.Drawing.Color.White, System.Drawing.Color.Empty);
                _popLabel.SetText(planet.Owner != null ? string.Format("{0:0.0}/{1:0} B", planet.TotalPopulation, planet.TotalMaxPopulation - planet.Waste) : string.Format("{0:0} B", planet.TotalMaxPopulation - planet.Waste));
                _terrainLabel.SetText(Utility.PlanetTypeToString(_currentSystem.Planets[0].PlanetType));
                if (_isOwnedSystem)
                {
                    _name.SetReadOnly(false);
                    _productionLabel.SetText(string.Format("{0:0.0} ({1:0.0}) Industry", _currentSystem.Planets[0].ActualProduction, _currentSystem.Planets[0].TotalProduction));
                    _infrastructureLabel.SetText(_currentSystem.Planets[0].InfrastructureStringOutput);
                    _researchLabel.SetText(_currentSystem.Planets[0].ResearchStringOutput);
                    _environmentLabel.SetText(_currentSystem.Planets[0].EnvironmentStringOutput);
                    _defenseLabel.SetText(_currentSystem.Planets[0].DefenseStringOutput);
                    _constructionLabel.SetText(_currentSystem.Planets[0].ConstructionStringOutput);
                    _infrastructureSlider.TopIndex = planet.InfrastructureAmount;
                    _researchSlider.TopIndex       = planet.ResearchAmount;
                    _environmentSlider.TopIndex    = planet.EnvironmentAmount;
                    _defenseSlider.TopIndex        = planet.DefenseAmount;
                    _constructionSlider.TopIndex   = planet.ConstructionAmount;

                    _infrastructureLockButton.Selected = planet.InfrastructureLocked;
                    _infrastructureSlider.SetEnabledState(!planet.InfrastructureLocked);
                    _researchLockButton.Selected = planet.ResearchLocked;
                    _researchSlider.SetEnabledState(!planet.ResearchLocked);
                    _environmentLockButton.Selected = planet.EnvironmentLocked;
                    _environmentSlider.SetEnabledState(!planet.EnvironmentLocked);
                    _defenseLockButton.Selected = planet.DefenseLocked;
                    _defenseSlider.SetEnabledState(!planet.DefenseLocked);
                    _constructionLockButton.Selected = planet.ConstructionLocked;
                    _constructionSlider.SetEnabledState(!planet.ConstructionLocked);

                    if (_currentSystem.Planets[0].TransferSystem.Key.StarSystem != null)
                    {
                        _transferLabel.SetText("Moving " + _currentSystem.Planets[0].TransferSystem.Value + " Pop");
                        _transferLabel.MoveTo(_xPos + 10, _yPos + 440);
                    }
                    else
                    {
                        _transferLabel.SetText(string.Empty);
                    }
                }
                else if (_currentSystem.Planets[0].Owner != null)
                {
                    _generalPurposeText.SetText("Colonized by " + _currentSystem.Planets[0].Owner.EmpireRace.RaceName + " Empire");
                    _name.SetReadOnly(true);
                }
                else
                {
                    _generalPurposeText.SetText("No colony");
                    _name.SetReadOnly(true);
                }
            }
            else
            {
                _isExplored = false;
                _name.SetText("Unexplored");
                _name.SetTextAttributes(System.Drawing.Color.White, System.Drawing.Color.Empty);
                _generalPurposeText.SetText(_currentSystem.Description);
                _popLabel.SetText(string.Empty);
                _terrainLabel.SetText(string.Empty);
                _productionLabel.SetText(string.Empty);
                _infrastructureLabel.SetText(string.Empty);
                _researchLabel.SetText(string.Empty);
                _environmentLabel.SetText(string.Empty);
                _defenseLabel.SetText(string.Empty);
                _constructionLabel.SetText(string.Empty);
                _name.SetReadOnly(true);
            }
        }
Пример #3
0
        public override bool MouseUp(int x, int y)
        {
            if (_promptShowing)
            {
                if (!_saveGameNameField.MouseUp(x, y) && !string.IsNullOrEmpty(_saveGameNameField.Text))
                {
                    _promptShowing = false;
                    _gameMain.SaveGame(_saveGameNameField.Text);
                    GetSaveList();                     //Refresh the list after saving
                }
            }
            if (_scrollBar.MouseUp(x, y))
            {
                RefreshSaveButtons();
                return(true);
            }
            if (_buttons[0].MouseUp(x, y))
            {
                var func = CloseWindow;
                if (func != null)
                {
                    func();
                }
                _gameMain.ClearAll();
                _gameMain.ChangeToScreen(Screen.NewGame);
                return(true);
            }
            if (_buttons[1].MouseUp(x, y))
            {
                _promptShowing = true;
                if (_selectedGame >= 0)
                {
                    _saveGameNameField.SetText(_files[_selectedGame].Name.Substring(0, _files[_selectedGame].Name.Length - _files[_selectedGame].Extension.Length));
                }
                else
                {
                    _saveGameNameField.SetText(string.Empty);
                }
                _saveGameNameField.Select();
                return(true);
            }
            if (_buttons[2].MouseUp(x, y))
            {
                var func = CloseWindow;
                if (func != null)
                {
                    func();
                }
                _gameMain.LoadGame(_files[_selectedGame].Name);
                return(true);
            }
            if (_buttons[3].MouseUp(x, y))
            {
                //TODO: Add prompt to ensure user really want to exit
                _gameMain.ExitGame();
                return(true);
            }

            for (int i = 0; i < _maxVisible; i++)
            {
                if (_saveGameButtons[i].MouseUp(x, y))
                {
                    foreach (var button in _saveGameButtons)
                    {
                        button.Selected = false;
                    }
                    _saveGameButtons[i].Selected = true;
                    _selectedGame       = i + _scrollBar.TopIndex;
                    _buttons[2].Enabled = true;
                    return(true);
                }
            }

            if (!base.MouseUp(x, y))
            {
                //Clicked outside the window, close this window
                if (CloseWindow != null)
                {
                    CloseWindow();
                }
            }
            else
            {
                //Clicked inside window, clear save game selection, if any
                _selectedGame = -1;
                foreach (var button in _saveGameButtons)
                {
                    button.Selected = false;
                }
                _buttons[2].Enabled = false;
            }
            return(false);
        }
Пример #4
0
 public override bool MouseUp(int x, int y)
 {
     if (!_colonizing)
     {
         for (int i = 0; i < _maxShips; i++)
         {
             if (_shipButtons[i].MouseUp(x, y))
             {
                 foreach (var button in _shipButtons)
                 {
                     button.Selected = false;
                 }
                 _shipButtons[i].Selected = true;
             }
         }
         if (_cancelButton.MouseUp(x, y))
         {
             if (Completed != null)
             {
                 Completed();
             }
         }
         if (_colonizeButton.MouseDown(x, y))
         {
             int whichShip = 0;
             for (int i = 0; i < _maxShips; i++)
             {
                 if (_shipButtons[i].Selected)
                 {
                     whichShip = i;
                     break;
                 }
             }
             var ship = _colonyShips[whichShip];
             _colonizingFleet.ColonizePlanet(ship);
             _nameTextBox.SetText(_starSystem.Name);
             //Select the textbox so it'd capture the keypresses
             _nameTextBox.MouseDown(_gameMain.ScreenWidth / 2, _gameMain.ScreenHeight / 2);
             _nameTextBox.MouseUp(_gameMain.ScreenWidth / 2, _gameMain.ScreenHeight / 2);
             _landingShipPos = _gameMain.ScreenHeight / 2 - 300;
             _groundView     = _starSystem.Planets[0].GroundSprite;
             _landingShip    = _colonizingFleet.Empire.EmpireRace.LandingShip;
             _showingText    = false;
             _colonizing     = true;
         }
     }
     else
     {
         if (!_showingText)
         {
             _showingText    = true;
             _landingShipPos = _gameMain.ScreenHeight / 2 + 50;
         }
         else
         {
             if (!_nameTextBox.MouseUp(x, y) && !string.IsNullOrEmpty(_nameTextBox.Text))
             {
                 _starSystem.Name = _nameTextBox.Text;
                 _colonizing      = false;
                 _showingText     = false;
                 //Done
                 if (Completed != null)
                 {
                     Completed();
                 }
             }
         }
     }
     return(false);
 }