|
| 1 | +using IPT.Common.User.Inputs; |
| 2 | +using Rage; |
| 3 | + |
| 4 | +namespace IPT.Common.User.Settings |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// An INI setting for holdable controller buttons. |
| 8 | + /// </summary> |
| 9 | + public class SettingHoldableButtonCombo : Setting |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Initializes a new instance of the <see cref="SettingHoldableButtonCombo"/> class. |
| 13 | + /// </summary> |
| 14 | + /// <param name="section">The section of the INI file containing the setting.</param> |
| 15 | + /// <param name="name">The name of the setting.</param> |
| 16 | + /// <param name="description">A brief description of the setting.</param> |
| 17 | + public SettingHoldableButtonCombo(string section, string name, string description) |
| 18 | + : base(section, name, description) |
| 19 | + { |
| 20 | + this.Value = new HoldableButtonCombo(ControllerButtons.None, ControllerButtons.None); |
| 21 | + } |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Gets the value. |
| 25 | + /// </summary> |
| 26 | + public HoldableButtonCombo Value { get; private set; } |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Gets the value. |
| 30 | + /// </summary> |
| 31 | + /// <returns>The value.</returns> |
| 32 | + public override object GetValue() |
| 33 | + { |
| 34 | + return this.Value; |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Sets the value. |
| 39 | + /// </summary> |
| 40 | + /// <param name="value">The value.</param> |
| 41 | + public override void SetValue(object value) |
| 42 | + { |
| 43 | + this.Value = (HoldableButtonCombo)value; |
| 44 | + } |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Loads the value. |
| 48 | + /// </summary> |
| 49 | + /// <param name="ini">The INI object used to load the value.</param> |
| 50 | + public override void Load(InitializationFile ini) |
| 51 | + { |
| 52 | + ControllerButtons primary = ini.ReadEnum(this.Section, this.Name, this.Value.PrimaryButton); |
| 53 | + ControllerButtons secondary = ini.ReadEnum(this.Section, $"{this.Name}Modifier", this.Value.SecondaryButton); |
| 54 | + this.Value = new HoldableButtonCombo(primary, secondary); |
| 55 | + } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Saves the value. |
| 59 | + /// </summary> |
| 60 | + /// <param name="ini">The INI object used to save the value.</param> |
| 61 | + public override void Save(InitializationFile ini) |
| 62 | + { |
| 63 | + ini.Write(this.Section, this.Name, this.Value.PrimaryButton.ToString()); |
| 64 | + if (this.Value.HasSecondary) |
| 65 | + { |
| 66 | + ini.Write(this.Section, $"{this.Name}Modifier", this.Value.SecondaryButton.ToString()); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments