using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using TeslaConsole.Properties; namespace TeslaConsole.BattleTech; /// /// The BattleTech operator-defaults editor: one column per game mode (Free For /// All / No Return), mirroring RPDefaultsDialog's Death Race / Football /// layout. OK persists to (BTDefaults.btd). Both /// modes share the single BT catalog; the rows are the BT option set (mech, /// camo, patch, badge, experience, advanced damage) instead of RP's. /// public class BTDefaultsDialog : Form { private IContainer components; private TableLayoutPanel mMainTable; private Label mFfaHeaderLabel; private Label mNoReturnHeaderLabel; private Label mMapLabel; private Label mWeatherLabel; private Label mTimeOfDayLabel; private Label mAdvancedDamageLabel; private Label mMissionLengthLabel; private Label mMechLabel; private Label mCamoLabel; private Label mPatchLabel; private Label mBadgeLabel; private Label mExperienceLabel; private Label mLaunchDelayLabel; private ComboBox mFfaMap; private ComboBox mNoReturnMap; private ComboBox mFfaWeather; private ComboBox mNoReturnWeather; private ComboBox mFfaTimeOfDay; private ComboBox mNoReturnTimeOfDay; private ComboBox mFfaAdvancedDamage; private ComboBox mNoReturnAdvancedDamage; private MaskedTextBox mFfaMissionLength; private MaskedTextBox mNoReturnMissionLength; private ComboBox mFfaVehicle; private ComboBox mNoReturnVehicle; private ComboBox mFfaCamo; private ComboBox mNoReturnCamo; private ComboBox mFfaPatch; private ComboBox mNoReturnPatch; private ComboBox mFfaBadge; private ComboBox mNoReturnBadge; private ComboBox mFfaExperience; private ComboBox mNoReturnExperience; private NumericUpDown mFfaLaunchDelay; private NumericUpDown mNoReturnLaunchDelay; private Label mDosBoxLabel; private CheckBox mDosBoxShift; private TableLayoutPanel mButtonsTable; private Button mCancel; private Button mOK; private static BTDefaultsDialog mSingletonDialog; protected override void Dispose(bool disposing) { if (disposing && components != null) { components.Dispose(); } base.Dispose(disposing); } public static void ShowSingleton() { if (mSingletonDialog == null || mSingletonDialog.IsDisposed) { mSingletonDialog = new BTDefaultsDialog(); } mSingletonDialog.Show(); mSingletonDialog.Focus(); mSingletonDialog.WindowState = FormWindowState.Normal; } private BTDefaultsDialog() { InitializeComponent(); base.Icon = Resources.swirl; BTScenario scenario = BTConfig.FreeForAll; BuildColumn(scenario, BTDefaults.FreeForAll, mFfaMap, mFfaWeather, mFfaTimeOfDay, mFfaAdvancedDamage, mFfaMissionLength, mFfaVehicle, mFfaCamo, mFfaPatch, mFfaBadge, mFfaExperience, mFfaLaunchDelay); BuildColumn(scenario, BTDefaults.NoReturn, mNoReturnMap, mNoReturnWeather, mNoReturnTimeOfDay, mNoReturnAdvancedDamage, mNoReturnMissionLength, mNoReturnVehicle, mNoReturnCamo, mNoReturnPatch, mNoReturnBadge, mNoReturnExperience, mNoReturnLaunchDelay); mDosBoxShift.Checked = BTDefaults.DosBoxAddressShift; } private static void BuildColumn(BTScenario scenario, BTDefaults.BattleDefaults defaults, ComboBox map, ComboBox weather, ComboBox timeOfDay, ComboBox advancedDamage, MaskedTextBox missionLength, ComboBox vehicle, ComboBox camo, ComboBox patch, ComboBox badge, ComboBox experience, NumericUpDown launchDelay) { BuildNamedOption(map, scenario.Maps.Keys, scenario.Maps.Values, defaults.MapKey); BuildNamedOption(weather, scenario.Weather.Keys, scenario.Weather.Values, defaults.WeatherKey); BuildGenericOption(timeOfDay, scenario.TimesOfDay, defaults.TimeOfDayKey); BuildOnOffOptions(advancedDamage, defaults.AdvancedDamage); BuildMissionLengthControl(missionLength, defaults.MissionLength); BuildNamedOption(vehicle, scenario.Vehicles.Keys, scenario.Vehicles.Values, defaults.VehicleKey); BuildGenericOption(camo, scenario.Colors, defaults.CamoKey); BuildGenericOption(patch, scenario.Patches, defaults.PatchKey); BuildGenericOption(badge, scenario.Badges, defaults.EmblemKey); BuildGenericOption(experience, scenario.Experiences, defaults.ExperienceKey); launchDelay.Value = defaults.LaunchDelay; } private static void BuildOnOffOptions(ComboBox comboBox, bool defaultValue) { comboBox.DisplayMember = "Value"; comboBox.ValueMember = "Key"; comboBox.Items.Add(new KeyValuePair(key: false, "Off")); comboBox.Items.Add(new KeyValuePair(key: true, "On")); comboBox.SelectedIndex = (defaultValue ? 1 : 0); } private static void BuildMissionLengthControl(MaskedTextBox maskedTextBox, TimeSpan defaultValue) { maskedTextBox.Mask = "00:00:00"; maskedTextBox.ValidatingType = typeof(TimeSpan); maskedTextBox.Text = defaultValue.ToString(); } /// /// Fills a combo from a keyed catalog of objects whose Name property is the /// display text and whose ToString returns it (BTMap/BTVehicle/BTWeather). /// private static void BuildNamedOption(ComboBox comboBox, IEnumerable keys, IEnumerable values, string defaultKey) { int selectedIndex = 0; int num = 0; comboBox.DisplayMember = "Name"; comboBox.ValueMember = "Key"; IEnumerator keyEnumerator = keys.GetEnumerator(); foreach (T value in values) { keyEnumerator.MoveNext(); comboBox.Items.Add(value); if (keyEnumerator.Current == defaultKey) { selectedIndex = num; } num++; } comboBox.SelectedIndex = selectedIndex; } private static void BuildGenericOption(ComboBox comboBox, IEnumerable> options, string defaultKey) { int selectedIndex = 0; int num = 0; comboBox.DisplayMember = "Value"; comboBox.ValueMember = "Key"; foreach (KeyValuePair option in options) { comboBox.Items.Add(option); if (option.Key == defaultKey) { selectedIndex = num; } num++; } comboBox.SelectedIndex = selectedIndex; } private void mCancel_Click(object sender, EventArgs e) { Close(); } private void mOK_Click(object sender, EventArgs e) { SaveColumn(BTDefaults.FreeForAll, mFfaMap, mFfaWeather, mFfaTimeOfDay, mFfaAdvancedDamage, mFfaMissionLength, mFfaVehicle, mFfaCamo, mFfaPatch, mFfaBadge, mFfaExperience, mFfaLaunchDelay); SaveColumn(BTDefaults.NoReturn, mNoReturnMap, mNoReturnWeather, mNoReturnTimeOfDay, mNoReturnAdvancedDamage, mNoReturnMissionLength, mNoReturnVehicle, mNoReturnCamo, mNoReturnPatch, mNoReturnBadge, mNoReturnExperience, mNoReturnLaunchDelay); BTDefaults.DosBoxAddressShift = mDosBoxShift.Checked; BTDefaults.Save(); Hide(); } private static void SaveColumn(BTDefaults.BattleDefaults defaults, ComboBox map, ComboBox weather, ComboBox timeOfDay, ComboBox advancedDamage, MaskedTextBox missionLength, ComboBox vehicle, ComboBox camo, ComboBox patch, ComboBox badge, ComboBox experience, NumericUpDown launchDelay) { defaults.MapKey = ((BTMap)map.SelectedItem).Key; defaults.WeatherKey = ((BTWeather)weather.SelectedItem).Key; defaults.TimeOfDayKey = ExtractSelectedKey(timeOfDay); defaults.AdvancedDamage = ExtractSelectedKey(advancedDamage); defaults.MissionLength = (TimeSpan)missionLength.ValidateText(); defaults.VehicleKey = ((BTVehicle)vehicle.SelectedItem).Key; defaults.CamoKey = ExtractSelectedKey(camo); defaults.PatchKey = ExtractSelectedKey(patch); defaults.EmblemKey = ExtractSelectedKey(badge); defaults.ExperienceKey = ExtractSelectedKey(experience); defaults.LaunchDelay = (int)launchDelay.Value; } private static T ExtractSelectedKey(ComboBox comboBox) { if (comboBox.SelectedItem is KeyValuePair) { return ((KeyValuePair)comboBox.SelectedItem).Key; } return (T)comboBox.SelectedItem; } private void InitializeComponent() { this.mMainTable = new System.Windows.Forms.TableLayoutPanel(); this.mFfaHeaderLabel = new System.Windows.Forms.Label(); this.mNoReturnHeaderLabel = new System.Windows.Forms.Label(); this.mMapLabel = new System.Windows.Forms.Label(); this.mWeatherLabel = new System.Windows.Forms.Label(); this.mTimeOfDayLabel = new System.Windows.Forms.Label(); this.mAdvancedDamageLabel = new System.Windows.Forms.Label(); this.mMissionLengthLabel = new System.Windows.Forms.Label(); this.mMechLabel = new System.Windows.Forms.Label(); this.mCamoLabel = new System.Windows.Forms.Label(); this.mPatchLabel = new System.Windows.Forms.Label(); this.mBadgeLabel = new System.Windows.Forms.Label(); this.mExperienceLabel = new System.Windows.Forms.Label(); this.mLaunchDelayLabel = new System.Windows.Forms.Label(); this.mFfaMap = new System.Windows.Forms.ComboBox(); this.mNoReturnMap = new System.Windows.Forms.ComboBox(); this.mFfaWeather = new System.Windows.Forms.ComboBox(); this.mNoReturnWeather = new System.Windows.Forms.ComboBox(); this.mFfaTimeOfDay = new System.Windows.Forms.ComboBox(); this.mNoReturnTimeOfDay = new System.Windows.Forms.ComboBox(); this.mFfaAdvancedDamage = new System.Windows.Forms.ComboBox(); this.mNoReturnAdvancedDamage = new System.Windows.Forms.ComboBox(); this.mFfaMissionLength = new System.Windows.Forms.MaskedTextBox(); this.mNoReturnMissionLength = new System.Windows.Forms.MaskedTextBox(); this.mFfaVehicle = new System.Windows.Forms.ComboBox(); this.mNoReturnVehicle = new System.Windows.Forms.ComboBox(); this.mFfaCamo = new System.Windows.Forms.ComboBox(); this.mNoReturnCamo = new System.Windows.Forms.ComboBox(); this.mFfaPatch = new System.Windows.Forms.ComboBox(); this.mNoReturnPatch = new System.Windows.Forms.ComboBox(); this.mFfaBadge = new System.Windows.Forms.ComboBox(); this.mNoReturnBadge = new System.Windows.Forms.ComboBox(); this.mFfaExperience = new System.Windows.Forms.ComboBox(); this.mNoReturnExperience = new System.Windows.Forms.ComboBox(); this.mFfaLaunchDelay = new System.Windows.Forms.NumericUpDown(); this.mNoReturnLaunchDelay = new System.Windows.Forms.NumericUpDown(); this.mDosBoxLabel = new System.Windows.Forms.Label(); this.mDosBoxShift = new System.Windows.Forms.CheckBox(); this.mButtonsTable = new System.Windows.Forms.TableLayoutPanel(); this.mCancel = new System.Windows.Forms.Button(); this.mOK = new System.Windows.Forms.Button(); this.mMainTable.SuspendLayout(); this.mButtonsTable.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)this.mFfaLaunchDelay).BeginInit(); ((System.ComponentModel.ISupportInitialize)this.mNoReturnLaunchDelay).BeginInit(); base.SuspendLayout(); this.mMainTable.ColumnCount = 3; this.mMainTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.mMainTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50f)); this.mMainTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50f)); this.mMainTable.Controls.Add(this.mFfaHeaderLabel, 1, 0); this.mMainTable.Controls.Add(this.mNoReturnHeaderLabel, 2, 0); this.mMainTable.Controls.Add(this.mMapLabel, 0, 1); this.mMainTable.Controls.Add(this.mFfaMap, 1, 1); this.mMainTable.Controls.Add(this.mNoReturnMap, 2, 1); this.mMainTable.Controls.Add(this.mWeatherLabel, 0, 2); this.mMainTable.Controls.Add(this.mFfaWeather, 1, 2); this.mMainTable.Controls.Add(this.mNoReturnWeather, 2, 2); this.mMainTable.Controls.Add(this.mTimeOfDayLabel, 0, 3); this.mMainTable.Controls.Add(this.mFfaTimeOfDay, 1, 3); this.mMainTable.Controls.Add(this.mNoReturnTimeOfDay, 2, 3); this.mMainTable.Controls.Add(this.mAdvancedDamageLabel, 0, 4); this.mMainTable.Controls.Add(this.mFfaAdvancedDamage, 1, 4); this.mMainTable.Controls.Add(this.mNoReturnAdvancedDamage, 2, 4); this.mMainTable.Controls.Add(this.mMissionLengthLabel, 0, 5); this.mMainTable.Controls.Add(this.mFfaMissionLength, 1, 5); this.mMainTable.Controls.Add(this.mNoReturnMissionLength, 2, 5); this.mMainTable.Controls.Add(this.mMechLabel, 0, 6); this.mMainTable.Controls.Add(this.mFfaVehicle, 1, 6); this.mMainTable.Controls.Add(this.mNoReturnVehicle, 2, 6); this.mMainTable.Controls.Add(this.mCamoLabel, 0, 7); this.mMainTable.Controls.Add(this.mFfaCamo, 1, 7); this.mMainTable.Controls.Add(this.mNoReturnCamo, 2, 7); this.mMainTable.Controls.Add(this.mPatchLabel, 0, 8); this.mMainTable.Controls.Add(this.mFfaPatch, 1, 8); this.mMainTable.Controls.Add(this.mNoReturnPatch, 2, 8); this.mMainTable.Controls.Add(this.mBadgeLabel, 0, 9); this.mMainTable.Controls.Add(this.mFfaBadge, 1, 9); this.mMainTable.Controls.Add(this.mNoReturnBadge, 2, 9); this.mMainTable.Controls.Add(this.mExperienceLabel, 0, 10); this.mMainTable.Controls.Add(this.mFfaExperience, 1, 10); this.mMainTable.Controls.Add(this.mNoReturnExperience, 2, 10); this.mMainTable.Controls.Add(this.mLaunchDelayLabel, 0, 11); this.mMainTable.Controls.Add(this.mFfaLaunchDelay, 1, 11); this.mMainTable.Controls.Add(this.mNoReturnLaunchDelay, 2, 11); this.mMainTable.Controls.Add(this.mDosBoxLabel, 0, 12); this.mMainTable.Controls.Add(this.mDosBoxShift, 1, 12); this.mMainTable.Controls.Add(this.mButtonsTable, 0, 13); this.mMainTable.Dock = System.Windows.Forms.DockStyle.Fill; this.mMainTable.Location = new System.Drawing.Point(3, 3); this.mMainTable.Name = "mMainTable"; this.mMainTable.RowCount = 14; for (int i = 0; i < 13; i++) { this.mMainTable.RowStyles.Add(new System.Windows.Forms.RowStyle()); } this.mMainTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f)); this.mMainTable.Size = new System.Drawing.Size(478, 414); this.mMainTable.TabIndex = 0; this.mFfaHeaderLabel.Anchor = System.Windows.Forms.AnchorStyles.None; this.mFfaHeaderLabel.AutoSize = true; this.mFfaHeaderLabel.Name = "mFfaHeaderLabel"; this.mFfaHeaderLabel.Text = "Free For All"; this.mNoReturnHeaderLabel.Anchor = System.Windows.Forms.AnchorStyles.None; this.mNoReturnHeaderLabel.AutoSize = true; this.mNoReturnHeaderLabel.Name = "mNoReturnHeaderLabel"; this.mNoReturnHeaderLabel.Text = "No Return"; ConfigureRowLabel(this.mMapLabel, "mMapLabel", "Map:"); ConfigureRowLabel(this.mWeatherLabel, "mWeatherLabel", "Weather:"); ConfigureRowLabel(this.mTimeOfDayLabel, "mTimeOfDayLabel", "Time Of Day:"); ConfigureRowLabel(this.mAdvancedDamageLabel, "mAdvancedDamageLabel", "Advanced Damage:"); ConfigureRowLabel(this.mMissionLengthLabel, "mMissionLengthLabel", "Mission Length:"); ConfigureRowLabel(this.mMechLabel, "mMechLabel", "Mech:"); ConfigureRowLabel(this.mCamoLabel, "mCamoLabel", "Camo:"); ConfigureRowLabel(this.mPatchLabel, "mPatchLabel", "Patch:"); ConfigureRowLabel(this.mBadgeLabel, "mBadgeLabel", "Badge:"); ConfigureRowLabel(this.mExperienceLabel, "mExperienceLabel", "Experience:"); ConfigureRowLabel(this.mLaunchDelayLabel, "mLaunchDelayLabel", "Autotranslocate Delay:"); ConfigureRowLabel(this.mDosBoxLabel, "mDosBoxLabel", "DOSBox Build:"); ConfigureOptionCombo(this.mFfaMap, "mFfaMap"); ConfigureOptionCombo(this.mNoReturnMap, "mNoReturnMap"); ConfigureOptionCombo(this.mFfaWeather, "mFfaWeather"); ConfigureOptionCombo(this.mNoReturnWeather, "mNoReturnWeather"); ConfigureOptionCombo(this.mFfaTimeOfDay, "mFfaTimeOfDay"); ConfigureOptionCombo(this.mNoReturnTimeOfDay, "mNoReturnTimeOfDay"); ConfigureOptionCombo(this.mFfaAdvancedDamage, "mFfaAdvancedDamage"); ConfigureOptionCombo(this.mNoReturnAdvancedDamage, "mNoReturnAdvancedDamage"); ConfigureOptionCombo(this.mFfaVehicle, "mFfaVehicle"); ConfigureOptionCombo(this.mNoReturnVehicle, "mNoReturnVehicle"); ConfigureOptionCombo(this.mFfaCamo, "mFfaCamo"); ConfigureOptionCombo(this.mNoReturnCamo, "mNoReturnCamo"); ConfigureOptionCombo(this.mFfaPatch, "mFfaPatch"); ConfigureOptionCombo(this.mNoReturnPatch, "mNoReturnPatch"); ConfigureOptionCombo(this.mFfaBadge, "mFfaBadge"); ConfigureOptionCombo(this.mNoReturnBadge, "mNoReturnBadge"); ConfigureOptionCombo(this.mFfaExperience, "mFfaExperience"); ConfigureOptionCombo(this.mNoReturnExperience, "mNoReturnExperience"); this.mFfaMissionLength.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; this.mFfaMissionLength.Name = "mFfaMissionLength"; this.mNoReturnMissionLength.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; this.mNoReturnMissionLength.Name = "mNoReturnMissionLength"; this.mFfaLaunchDelay.Dock = System.Windows.Forms.DockStyle.Fill; this.mFfaLaunchDelay.Name = "mFfaLaunchDelay"; this.mNoReturnLaunchDelay.Dock = System.Windows.Forms.DockStyle.Fill; this.mNoReturnLaunchDelay.Name = "mNoReturnLaunchDelay"; this.mMainTable.SetColumnSpan(this.mDosBoxShift, 2); this.mDosBoxShift.Anchor = System.Windows.Forms.AnchorStyles.Left; this.mDosBoxShift.AutoSize = true; this.mDosBoxShift.Name = "mDosBoxShift"; this.mDosBoxShift.Text = "Shift all pod IPs +100 (DOSBox-X preservation build)"; this.mDosBoxShift.UseVisualStyleBackColor = true; this.mButtonsTable.ColumnCount = 2; this.mMainTable.SetColumnSpan(this.mButtonsTable, 3); this.mButtonsTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100f)); this.mButtonsTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); this.mButtonsTable.Controls.Add(this.mCancel, 1, 0); this.mButtonsTable.Controls.Add(this.mOK, 0, 0); this.mButtonsTable.Dock = System.Windows.Forms.DockStyle.Fill; this.mButtonsTable.Margin = new System.Windows.Forms.Padding(0); this.mButtonsTable.Name = "mButtonsTable"; this.mButtonsTable.RowCount = 1; this.mButtonsTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f)); this.mButtonsTable.Size = new System.Drawing.Size(478, 44); this.mButtonsTable.TabIndex = 27; this.mCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; this.mCancel.Name = "mCancel"; this.mCancel.Size = new System.Drawing.Size(75, 22); this.mCancel.TabIndex = 1; this.mCancel.Text = "&Cancel"; this.mCancel.UseVisualStyleBackColor = true; this.mCancel.Click += new System.EventHandler(mCancel_Click); this.mOK.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right; this.mOK.Name = "mOK"; this.mOK.Size = new System.Drawing.Size(75, 22); this.mOK.TabIndex = 0; this.mOK.Text = "&OK"; this.mOK.UseVisualStyleBackColor = true; this.mOK.Click += new System.EventHandler(mOK_Click); base.AcceptButton = this.mOK; base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f); base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; base.ClientSize = new System.Drawing.Size(484, 420); base.Controls.Add(this.mMainTable); base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; base.MaximizeBox = false; base.Name = "BTDefaultsDialog"; base.Padding = new System.Windows.Forms.Padding(3); this.Text = "BattleTech Defaults"; this.mMainTable.ResumeLayout(false); this.mMainTable.PerformLayout(); this.mButtonsTable.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)this.mFfaLaunchDelay).EndInit(); ((System.ComponentModel.ISupportInitialize)this.mNoReturnLaunchDelay).EndInit(); base.ResumeLayout(false); } private static void ConfigureRowLabel(Label label, string name, string text) { label.Anchor = AnchorStyles.Right; label.AutoSize = true; label.Name = name; label.Text = text; } private static void ConfigureOptionCombo(ComboBox comboBox, string name) { comboBox.Anchor = AnchorStyles.Left | AnchorStyles.Right; comboBox.DropDownStyle = ComboBoxStyle.DropDownList; comboBox.FormattingEnabled = true; comboBox.Name = name; } }