Beyond_Beyaan.Screens.ShipDesignScreen.RefreshValidButtons C# (CSharp) Метод

RefreshValidButtons() приватный Метод

private RefreshValidButtons ( ) : void
Результат void
        private void RefreshValidButtons()
        {
            //This function greys out all illegal buttons, and activates all legal buttons.  Illegal meaning that there isn't enough space for incrementation, or decrementation if the weapon count is 1
            float remainingSpace = _shipDesign.TotalSpace - _shipDesign.SpaceUsed;

            _computerButton.SetTextColor(AtLeastOneBetterComputer(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
            _shieldButton.SetTextColor(AtLeastOneBetterShield(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
            _ECMButton.SetTextColor(AtLeastOneBetterECM(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
            _engineButton.SetTextColor(AtLeastOneBetterEngine(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
            _maneuverButton.SetTextColor(AtLeastOneBetterManeuver(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
            _armorButton.SetTextColor(AtLeastOneBetterArmor(remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);

            for (int i = 0; i < _shipDesign.Weapons.Length; i++)
            {
                if (_shipDesign.Weapons[i].Key == null)
                {
                    _weaponButtons[i].SetTextColor(AtLeastOneBetterWeapon(new KeyValuePair<Equipment, int>(null, 0), remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
                    _weaponCounts[i].Enabled = false;
                }
                else
                {
                    _weaponButtons[i].SetTextColor(AtLeastOneBetterWeapon(_shipDesign.Weapons[i], remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
                    _weaponCounts[i].Enabled = true;
                    if (_shipDesign.Weapons[i].Key.GetSize(_techLevels, _shipDesign.Size) > remainingSpace)
                    {
                        _weaponCounts[i].UpButtonEnabled = false;
                    }
                    else
                    {
                        _weaponCounts[i].UpButtonEnabled = true;
                    }
                }
            }
            for (int i = 0; i < _shipDesign.Specials.Length; i++)
            {
                if (_shipDesign.Specials[i] != null)
                {
                    _specialButtons[i].SetTextColor(AtLeastOneHigherLevelSpecial(_shipDesign.Specials[i], remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
                }
                else
                {
                    _specialButtons[i].SetTextColor(AtLeastOneHigherLevelSpecial(null, remainingSpace) ? System.Drawing.Color.White : System.Drawing.Color.Tan, System.Drawing.Color.Empty);
                }
            }
            for (int i = _shipDesign.Size; i <= Ship.HUGE; i++)
            {
                //Any sizes bigger than current one is enabled by default
                _shipSizeButtons[i].Enabled = true;
            }
            for (int i = _shipDesign.Size - 1; i >= Ship.SMALL; i--)
            {
                //Check if smaller ship size can contain all current equipments, if not, disable the buttons
                Ship testShip = new Ship(_shipDesign);
                testShip.Size = i;
                testShip.UpdateEngineNumber();
                if (testShip.SpaceUsed > testShip.TotalSpace)
                {
                    //invalid design, can't go smaller
                    for (int j = i; j >= Ship.SMALL; j--)
                    {
                        _shipSizeButtons[j].Enabled = false;
                    }
                    break;
                }
                _shipSizeButtons[i].Enabled = true;
            }
        }