Skip to content

Commit

Permalink
0.8.1926.35354
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Feb 1, 2019
1 parent cb4d0da commit accc9e8
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 59 deletions.
139 changes: 82 additions & 57 deletions AcManager.Tools/Helpers/AcSettings/ControlsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,54 @@ internal ControlsSettings() : base("controls", false) {
new KeyboardSpecificButtonEntry("LEFT", ToolsStrings.Controls_SteerLeft)
}.Union(WheelGearsButtonEntries.Select(x => x.KeyboardButton)).ToArray();

#region Joystick entires
ControllerCarExtraButtonEntries = new[] {
new ControllerButtonCombined("KERS", KeyboardButtonProvider, ToolsStrings.Controls_Kers),
new ControllerButtonCombined("DRS", KeyboardButtonProvider, ToolsStrings.Controls_Drs),
new ControllerButtonCombined("ACTION_HEADLIGHTS_FLASH", KeyboardButtonProvider, ToolsStrings.Controls_FlashHeadlights),
new ControllerButtonCombined("ACTION_HORN", KeyboardButtonProvider, ToolsStrings.Controls_Horn),
};
ControllerCarBrakeButtonEntries = new[] {
new ControllerButtonCombined("BALANCEUP", KeyboardButtonProvider, ToolsStrings.Controls_MoveToFront),
new ControllerButtonCombined("BALANCEDN", KeyboardButtonProvider, ToolsStrings.Controls_MoveToRear),
};
ControllerCarTurboButtonEntries = new[] {
new ControllerButtonCombined("TURBOUP", KeyboardButtonProvider, ToolsStrings.Controls_Increase),
new ControllerButtonCombined("TURBODN", KeyboardButtonProvider, ToolsStrings.Controls_Decrease),
};
ControllerCarTractionControlButtonEntries = new[] {
new ControllerButtonCombined("TCUP", KeyboardButtonProvider, ToolsStrings.Controls_Increase),
new ControllerButtonCombined("TCDN", KeyboardButtonProvider, ToolsStrings.Controls_Decrease),
};
ControllerCarAbsButtonEntries = new[] {
new ControllerButtonCombined("ABSUP", KeyboardButtonProvider, ToolsStrings.Controls_Increase),
new ControllerButtonCombined("ABSDN", KeyboardButtonProvider, ToolsStrings.Controls_Decrease),
};
ControllerCarEngineBrakeButtonEntries = new[] {
new ControllerButtonCombined("ENGINE_BRAKE_UP", KeyboardButtonProvider, ToolsStrings.Controls_Increase),
new ControllerButtonCombined("ENGINE_BRAKE_DN", KeyboardButtonProvider, ToolsStrings.Controls_Decrease),
};
ControllerCarMgukButtonEntries = new[] {
new ControllerButtonCombined("MGUK_DELIVERY_UP", KeyboardButtonProvider, ToolsStrings.Controls_Mguk_IncreaseDelivery),
new ControllerButtonCombined("MGUK_DELIVERY_DN", KeyboardButtonProvider, ToolsStrings.Controls_Mguk_DecreaseDelivery),
new ControllerButtonCombined("MGUK_RECOVERY_UP", KeyboardButtonProvider, ToolsStrings.Controls_Mguk_IncreaseRecovery),
new ControllerButtonCombined("MGUK_RECOVERY_DN", KeyboardButtonProvider, ToolsStrings.Controls_Mguk_DecreaseRecovery),
new ControllerButtonCombined("MGUH_MODE", KeyboardButtonProvider, ToolsStrings.Controls_Mguh_Mode)
};
ControllerViewButtonEntries = new[] {
new ControllerButtonCombined("GLANCELEFT", KeyboardButtonProvider, ToolsStrings.Controls_GlanceLeft),
new ControllerButtonCombined("GLANCERIGHT", KeyboardButtonProvider, ToolsStrings.Controls_GlanceRight),
new ControllerButtonCombined("GLANCEBACK", KeyboardButtonProvider, ToolsStrings.Controls_GlanceBack),
new ControllerButtonCombined("ACTION_CHANGE_CAMERA", KeyboardButtonProvider, ToolsStrings.Controls_ChangeCamera)
};
ControllerCarButtonEntries = new[] {
new ControllerButtonCombined("GEARUP", KeyboardButtonProvider, ToolsStrings.Controls_NextGear),
new ControllerButtonCombined("GEARDN", KeyboardButtonProvider, ToolsStrings.Controls_PreviousGear),
new ControllerButtonCombined(HandbrakeId, KeyboardButtonProvider, ToolsStrings.Controls_Handbrake),
new ControllerButtonCombined("ACTION_HEADLIGHTS", KeyboardButtonProvider, ToolsStrings.Controls_Headlights),
};
#endregion

#region Constructing custom patch entries
CustomCarButtonEntries = new[] {
new CustomButtonEntryCombined("__EXT_TURNSIGNAL_LEFT", "Left turn signal", "For cars with turn signals defined", Keys.Left, Keys.Alt),
Expand Down Expand Up @@ -131,14 +179,27 @@ internal ControlsSettings() : base("controls", false) {

var systemAbs = new SystemButtonEntryCombined("ABS", "ABS", true, defaultKey: Keys.A);
var systemTractionControl = new SystemButtonEntryCombined("TRACTION_CONTROL", "Traction control", true, defaultKey: Keys.T);
var mguk1 = new SystemButtonEntryCombined("__CM_MGU_1", "MGU-K recovery", true, defaultKey: Keys.D1);
var mguk2 = new SystemButtonEntryCombined("__CM_MGU_2", "MGU-K delivery", true, defaultKey: Keys.D2);
var engineBrake = new SystemButtonEntryCombined("__CM_ENGINE_BRAKE", "Engine brake", true, defaultKey: Keys.D4);

SystemCarButtonEntries = new[] {
new SystemButtonEntryCombined("MOUSE_STEERING", "Mouse steering", defaultKey: Keys.M),
new SystemButtonEntryCombined("ACTIVATE_AI", "Toggle AI", defaultKey: Keys.C),
new SystemButtonEntryCombined("AUTO_SHIFTER", "Auto shifter", defaultKey: Keys.G),
new SystemButtonEntryCombined("__CM_MGU_1", "MGU 1", false, defaultKey: Keys.D1),
new SystemButtonEntryCombined("__CM_MGU_2", "MGU 2", false, defaultKey: Keys.D2),
new SystemButtonEntryCombined("__CM_MGU_3", "MGU 3", false, defaultKey: Keys.D3),
mguk1,
new SystemButtonEntryCombined("__CM_MGU_1_DECREASE", "MGU-K recovery (decrease)", fixedValueCallback: key => key.HasValue ? new[] {
Keys.Control, Keys.Shift, key.Value
} : null, buttonReference: mguk1.SystemButton),
mguk2,
new SystemButtonEntryCombined("__CM_MGU_2_DECREASE", "MGU-K delivery (decrease)", fixedValueCallback: key => key.HasValue ? new[] {
Keys.Control, Keys.Shift, key.Value
} : null, buttonReference: mguk2.SystemButton),
new SystemButtonEntryCombined("__CM_MGU_3", "MGU-H mode", false, defaultKey: Keys.D3),
engineBrake,
new SystemButtonEntryCombined("__CM_ENGINE_BRAKE_DECREASE", "Engine brake (decrease)", fixedValueCallback: key => key.HasValue ? new[] {
Keys.Control, Keys.Shift, key.Value
} : null, buttonReference: engineBrake.SystemButton),
systemAbs,
new SystemButtonEntryCombined("__CM_ABS_DECREASE", "ABS (decrease)", fixedValueCallback: key => key.HasValue ? new[] {
Keys.Control, Keys.Shift, key.Value
Expand All @@ -156,6 +217,15 @@ internal ControlsSettings() : base("controls", false) {
RefreshOverlayAvailable();
}

private KeyboardButtonEntry KeyboardButtonProvider(string arg) {
return WheelButtonEntries.Select(x => x.KeyboardButton)
.Select(x => (IEntry)x)
.Union(WheelButtonEntries.OfType<WheelButtonCombinedAlt>().Select(x => x.WheelButtonAlt))
.Union(WheelHShifterButtonEntries)
.Union(KeyboardSpecificButtonEntries)
.OfType<KeyboardButtonEntry>().First(x => x.Id == arg);
}

private void OnVideoPropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == nameof(AcSettingsHolder.Video.Fullscreen)) {
RefreshOverlayAvailable();
Expand Down Expand Up @@ -874,59 +944,15 @@ public int WheelFfbSkipSteps {
#endregion

#region Controller
public ControllerButtonCombined[] ControllerCarButtonEntries { get; } = {
new ControllerButtonCombined("GEARUP", ToolsStrings.Controls_NextGear),
new ControllerButtonCombined("GEARDN", ToolsStrings.Controls_PreviousGear),
new ControllerButtonCombined(HandbrakeId, ToolsStrings.Controls_Handbrake),
new ControllerButtonCombined("ACTION_HEADLIGHTS", ToolsStrings.Controls_Headlights),
};

public ControllerButtonCombined[] ControllerCarExtraButtonEntries { get; } = {
new ControllerButtonCombined("KERS", ToolsStrings.Controls_Kers),
new ControllerButtonCombined("DRS", ToolsStrings.Controls_Drs),
new ControllerButtonCombined("ACTION_HEADLIGHTS_FLASH", ToolsStrings.Controls_FlashHeadlights),
new ControllerButtonCombined("ACTION_HORN", ToolsStrings.Controls_Horn),
};

public ControllerButtonCombined[] ControllerCarBrakeButtonEntries { get; } = {
new ControllerButtonCombined("BALANCEUP", ToolsStrings.Controls_MoveToFront),
new ControllerButtonCombined("BALANCEDN", ToolsStrings.Controls_MoveToRear),
};

public ControllerButtonCombined[] ControllerCarTurboButtonEntries { get; } = {
new ControllerButtonCombined("TURBOUP", ToolsStrings.Controls_Increase),
new ControllerButtonCombined("TURBODN", ToolsStrings.Controls_Decrease),
};

public ControllerButtonCombined[] ControllerCarTractionControlButtonEntries { get; } = {
new ControllerButtonCombined("TCUP", ToolsStrings.Controls_Increase),
new ControllerButtonCombined("TCDN", ToolsStrings.Controls_Decrease),
};

public ControllerButtonCombined[] ControllerCarAbsButtonEntries { get; } = {
new ControllerButtonCombined("ABSUP", ToolsStrings.Controls_Increase),
new ControllerButtonCombined("ABSDN", ToolsStrings.Controls_Decrease),
};

public ControllerButtonCombined[] ControllerCarEngineBrakeButtonEntries { get; } = {
new ControllerButtonCombined("ENGINE_BRAKE_UP", ToolsStrings.Controls_Increase),
new ControllerButtonCombined("ENGINE_BRAKE_DN", ToolsStrings.Controls_Decrease),
};

public ControllerButtonCombined[] ControllerCarMgukButtonEntries { get; } = {
new ControllerButtonCombined("MGUK_DELIVERY_UP", ToolsStrings.Controls_Mguk_IncreaseDelivery),
new ControllerButtonCombined("MGUK_DELIVERY_DN", ToolsStrings.Controls_Mguk_DecreaseDelivery),
new ControllerButtonCombined("MGUK_RECOVERY_UP", ToolsStrings.Controls_Mguk_IncreaseRecovery),
new ControllerButtonCombined("MGUK_RECOVERY_DN", ToolsStrings.Controls_Mguk_DecreaseRecovery),
new ControllerButtonCombined("MGUH_MODE", ToolsStrings.Controls_Mguh_Mode)
};

public ControllerButtonCombined[] ControllerViewButtonEntries { get; } = {
new ControllerButtonCombined("GLANCELEFT", ToolsStrings.Controls_GlanceLeft),
new ControllerButtonCombined("GLANCERIGHT", ToolsStrings.Controls_GlanceRight),
new ControllerButtonCombined("GLANCEBACK", ToolsStrings.Controls_GlanceBack),
new ControllerButtonCombined("ACTION_CHANGE_CAMERA", ToolsStrings.Controls_ChangeCamera)
};
public ControllerButtonCombined[] ControllerCarButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarExtraButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarBrakeButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarTurboButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarTractionControlButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarAbsButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarEngineBrakeButtonEntries { get; }
public ControllerButtonCombined[] ControllerCarMgukButtonEntries { get; }
public ControllerButtonCombined[] ControllerViewButtonEntries { get; }

private ControllerButtonCombined[] _controllerButtonEntries;

Expand Down Expand Up @@ -1252,7 +1278,6 @@ public bool AssignKey(Key key) {

if (GetWaiting() is KeyboardButtonEntry) {
AssignInput(GetKeyboardInputButton(KeyInterop.VirtualKeyFromKey(key))).Forget();
Save();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using FirstFloor.ModernUI.Presentation;
using JetBrains.Annotations;

namespace AcManager.Tools.Helpers.AcSettingsControls {
public class ControllerButtonCombined : NotifyPropertyChanged {
public ControllerButtonCombined([LocalizationRequired(false)] string id, string displayName, bool isNew = false) {
public ControllerButtonCombined([LocalizationRequired(false)] string id, Func<string, KeyboardButtonEntry> provider,
string displayName, bool isNew = false) {
IsNew = isNew;
ControllerButton = new ControllerButtonEntry(id, displayName);
KeyboardButton = new KeyboardButtonEntry(id, displayName);
KeyboardButton = provider(id);
}

public ControllerButtonEntry ControllerButton { get; }
Expand Down

0 comments on commit accc9e8

Please sign in to comment.