// command private void comboboxCommand_SelectedIndexChanged(object sender, EventArgs e) { if (this.Tag == null & listviewControls.SelectedIndices.Count == 1) { int i = listviewControls.SelectedIndices[0]; int j = comboboxCommand.SelectedIndex; if (j >= 0) { Interface.CurrentControls[i].Command = Translations.CommandInfos[j].Command; Translations.CommandInfo Info = Translations.CommandInfos.TryGetInfo(Translations.CommandInfos[j].Command); Interface.CurrentControls[i].InheritedType = Info.Type; labelCommandOption.Enabled = Translations.CommandInfos[j].EnableOption; updownCommandOption.Enabled = Translations.CommandInfos[j].EnableOption; UpdateControlListElement(listviewControls.Items[i], i, true); } } }
private void UpdateControlListElement(ListViewItem Item, int Index, bool ResizeColumns) { Translations.CommandInfo Info = Translations.CommandInfos.TryGetInfo(Interface.CurrentControls[Index].Command); Item.SubItems[0].Text = Info.Name; switch (Info.Type) { case Translations.CommandType.Digital: Item.SubItems[1].Text = Translations.GetInterfaceString("controls_list_type_digital"); break; case Translations.CommandType.AnalogHalf: Item.SubItems[1].Text = Translations.GetInterfaceString("controls_list_type_analoghalf"); break; case Translations.CommandType.AnalogFull: Item.SubItems[1].Text = Translations.GetInterfaceString("controls_list_type_analogfull"); break; default: Item.SubItems[1].Text = Info.Type.ToString(); break; } Item.SubItems[2].Text = Info.Description; if (Interface.CurrentControls[Index].Method == Interface.ControlMethod.Keyboard) { Item.ImageKey = @"keyboard"; } else if (Interface.CurrentControls[Index].Method == Interface.ControlMethod.Joystick) { if (Info.Type == Translations.CommandType.AnalogHalf | Info.Type == Translations.CommandType.AnalogFull) { Item.ImageKey = @"joystick"; } else { Item.ImageKey = @"gamepad"; } } else { Item.ImageKey = null; } Item.SubItems[3].Text = GetControlDetails(Index); Item.SubItems[4].Text = Interface.CurrentControls[Index].Option.ToString(System.Globalization.CultureInfo.InvariantCulture); if (ResizeColumns) { listviewControls.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); } }
/// <summary>Saves a control configuration to disk</summary> /// <param name="FileOrNull">An absolute file path if we are exporting the controls, or a null reference to save to the default configuration location</param> /// <param name="controlsToSave">The list of controls to save</param> internal static void SaveControls(string FileOrNull, Control[] controlsToSave) { CultureInfo Culture = CultureInfo.InvariantCulture; System.Text.StringBuilder Builder = new System.Text.StringBuilder(); Builder.AppendLine("; Current control configuration"); Builder.AppendLine("; ============================="); Builder.AppendLine("; This file was automatically generated. Please modify only if you know what you're doing."); Builder.AppendLine("; This file is INCOMPATIBLE with versions older than 1.4.4."); Builder.AppendLine(); for (int i = 0; i < controlsToSave.Length; i++) { Translations.CommandInfo Info = Translations.CommandInfos.TryGetInfo(controlsToSave[i].Command); Builder.Append(Info.Name + ", "); switch (controlsToSave[i].Method) { case ControlMethod.Keyboard: Builder.Append("keyboard, " + controlsToSave[i].Key + ", " + ((int)controlsToSave[i].Modifier).ToString(Culture) + ", " + controlsToSave[i].Option.ToString(Culture)); break; case ControlMethod.Joystick: Builder.Append("joystick, " + controlsToSave[i].Device.ToString(Culture) + ", "); switch (controlsToSave[i].Component) { case JoystickComponent.Axis: Builder.Append("axis, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Ball: Builder.Append("ball, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Hat: Builder.Append("hat, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Button: Builder.Append("button, " + controlsToSave[i].Element.ToString(Culture)); break; default: Builder.Append("invalid"); break; } Builder.Append(", " + controlsToSave[i].Option.ToString(Culture)); break; case ControlMethod.RailDriver: Builder.Append("raildriver, 0, "); switch (controlsToSave[i].Component) { case JoystickComponent.Axis: Builder.Append("axis, " + controlsToSave[i].Element.ToString(Culture) + ", " + controlsToSave[i].Direction.ToString(Culture)); break; case JoystickComponent.Button: Builder.Append("button, " + controlsToSave[i].Element.ToString(Culture)); break; default: Builder.Append("invalid"); break; } Builder.Append(", " + controlsToSave[i].Option.ToString(Culture)); break; } Builder.Append("\n"); } string File; if (FileOrNull == null) { File = OpenBveApi.Path.CombineFile(Program.FileSystem.SettingsFolder, "1.5.0/controls.cfg"); } else { File = FileOrNull; } System.IO.File.WriteAllText(File, Builder.ToString(), new System.Text.UTF8Encoding(true)); }