CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

PlayerSettings.cs (3790B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // The Command & Conquer Map Editor and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // The Command & Conquer Map Editor and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 using MobiusEditor.Interface;
     16 using MobiusEditor.Model;
     17 using MobiusEditor.Utility;
     18 using System;
     19 using System.Collections.Generic;
     20 using System.Data;
     21 using System.Linq;
     22 using System.Windows.Forms;
     23 
     24 namespace MobiusEditor.Controls
     25 {
     26     public partial class PlayerSettings : UserControl
     27     {
     28         private readonly PropertyTracker<House> houseSettingsTracker;
     29         private readonly dynamic house;
     30 
     31         public PlayerSettings(IGamePlugin plugin, PropertyTracker<House> houseSettingsTracker)
     32         {
     33             this.houseSettingsTracker = houseSettingsTracker;
     34             house = houseSettingsTracker;
     35 
     36             InitializeComponent();
     37 
     38             edgeComboBox.Items.Clear();
     39             edgeComboBox.Items.AddRange(new string[] { "North", "South", "West", "East" });
     40 
     41             creditsNud.DataBindings.Add("Value", houseSettingsTracker, "Credits");
     42             maxBuildingsNud.DataBindings.Add("Value", houseSettingsTracker, "MaxBuilding");
     43             maxUnitsNud.DataBindings.Add("Value", houseSettingsTracker, "MaxUnit");
     44             edgeComboBox.DataBindings.Add("SelectedItem", houseSettingsTracker, "Edge");
     45 
     46             switch (plugin.GameType)
     47             {
     48                 case GameType.TiberianDawn:
     49                     maxInfantryNud.Visible = maxInfantryLbl.Visible = false;
     50                     maxVesselsNud.Visible = maxVesselsLbl.Visible = false;
     51                     techLevelNud.Visible = techLevelLbl.Visible = false;
     52                     iqNud.Visible = iqLbl.Visible = false;
     53                     playerControlCheckBox.Visible = playerControlLbl.Visible = false;
     54                     break;
     55                 case GameType.RedAlert:
     56                     maxInfantryNud.DataBindings.Add("Value", houseSettingsTracker, "MaxInfantry");
     57                     maxVesselsNud.DataBindings.Add("Value", houseSettingsTracker, "MaxVessel");
     58                     techLevelNud.DataBindings.Add("Value", houseSettingsTracker, "TechLevel");
     59                     iqNud.DataBindings.Add("Value", houseSettingsTracker, "IQ");
     60                     playerControlCheckBox.DataBindings.Add("Checked", houseSettingsTracker, "PlayerControl");
     61                     break;
     62             }
     63 
     64             playersListBox.Items.Clear();
     65             playersListBox.Items.AddRange(plugin.Map.Houses.Select(h => h.Type.Name).ToArray());
     66 
     67             var selectedIndices = new List<int>();
     68             foreach (var id in house.Allies)
     69             {
     70                 playersListBox.SetSelected(id, true);
     71             }
     72 
     73             playersListBox.SelectedIndexChanged += playersListBox_SelectedIndexChanged;
     74         }
     75 
     76         private void playersListBox_SelectedIndexChanged(object sender, EventArgs e)
     77         {
     78             var allies = 0;
     79             foreach (int selectedIndex in playersListBox.SelectedIndices)
     80             {
     81                 allies |= 1 << selectedIndex;
     82             }
     83             house.Allies = new AlliesMask(allies);
     84         }
     85     }
     86 }