PlayerSettings.cs 3.7 KB

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