Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
818 changes: 621 additions & 197 deletions Source/Data/Controls.cs

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Source/Data/PersistedData/ControlsConfigBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public sealed class ControlsConfigBinding
public Axes? Axis { get; set; }
public float AxisDeadzone { get; set; }
public bool AxisInverted { get; set; }
public Gamepads? OnlyFor { get; set; }
public Gamepads? NotFor { get; set; }
public Gamepads[]? ForGamepads { get; set; }

public ControlsConfigBinding() { }
public ControlsConfigBinding(Keys input) => Key = input;
Expand All @@ -27,7 +26,7 @@ public ControlsConfigBinding(Axes input, float deadzone, bool inverted)

private bool Condition(VirtualButton vb, VirtualButton.IBinding binding)
{
if (!OnlyFor.HasValue && !NotFor.HasValue)
if (ForGamepads == null || !ForGamepads.Any())
return true;

int index;
Expand All @@ -38,10 +37,8 @@ private bool Condition(VirtualButton vb, VirtualButton.IBinding binding)
else
return true;

if (OnlyFor.HasValue && Input.Controllers[index].Gamepad != OnlyFor.Value)
return false;

if (NotFor.HasValue && Input.Controllers[index].Gamepad == NotFor.Value)
Gamepads gamepad = Input.Controllers.Any() ? Input.Controllers[index].Gamepad : Gamepads.Xbox;
if (!ForGamepads.Contains(gamepad))
return false;

return true;
Expand Down
148 changes: 0 additions & 148 deletions Source/Data/PersistedData/ControlsConfig_V01.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,154 +10,6 @@ public class ControlsConfig_V01 : PersistedData
public Dictionary<string, List<ControlsConfigBinding>> Actions { get; set; } = [];
public Dictionary<string, ControlsConfigStick> Sticks { get; set; } = [];

public static ControlsConfig_V01 Defaults = new()
{
Actions = new()
{
["Jump"] = [
new(Keys.C),
new(Buttons.South),
new(Buttons.North),
],
["Dash"] = [
new(Keys.X),
new(Buttons.West),
new(Buttons.East),
],
["Climb"] = [
new(Keys.Z),
new(Keys.V),
new(Keys.LeftShift),
new(Keys.RightShift),
new(Buttons.LeftShoulder),
new(Buttons.RightShoulder),
new(Axes.LeftTrigger, 0.4f, false),
new(Axes.RightTrigger, 0.4f, false),
],
["Confirm"] = [
new(Keys.C),
new(Buttons.South) { NotFor = Gamepads.Nintendo },
new(Buttons.East) { OnlyFor = Gamepads.Nintendo },
],
["Cancel"] = [
new(Keys.X),
new(Buttons.East) { NotFor = Gamepads.Nintendo },
new(Buttons.South) { OnlyFor = Gamepads.Nintendo },
],
["Pause"] = [
new(Keys.Escape),
new(Keys.Enter),
new(Buttons.Start),
new(Buttons.Select),
new(Buttons.Back)
],
["CopyFile"] = [
new(Keys.V),
new(Buttons.LeftShoulder)
],
["DeleteFile"] = [
new(Keys.N),
new(Buttons.RightShoulder)
],
["CreateFile"] = [
new(Keys.B),
new(Buttons.North)
],
["ResetBindings"] = [
new(Keys.V),
new(Buttons.LeftShoulder)
],
["ClearBindings"] = [
new(Keys.B),
new(Buttons.North)
],
["FullScreen"] = [
new(Keys.F4),
],
["ReloadAssets"] = [
new(Keys.F5),
],
["DebugMenu"] = [
new(Keys.F6),
],
["Restart"] = [
new(Keys.R),
],
},

Sticks = new()
{
["Move"] = new()
{
Deadzone = 0.35f,
Left = [
new(Keys.Left),
new(Buttons.Left),
new(Axes.LeftX, 0.0f, true)
],
Right = [
new(Keys.Right),
new(Buttons.Right),
new(Axes.LeftX, 0.0f, false)
],
Up = [
new(Keys.Up),
new(Buttons.Up),
new(Axes.LeftY, 0.0f, true)
],
Down = [
new(Keys.Down),
new(Buttons.Down),
new(Axes.LeftY, 0.0f, false)
],
},
["Camera"] = new()
{
Deadzone = 0.35f,
Left = [
new(Keys.A),
new(Axes.RightX, 0.0f, true)
],
Right = [
new(Keys.D),
new(Axes.RightX, 0.0f, false)
],
Up = [
new(Keys.W),
new(Axes.RightY, 0.0f, true)
],
Down = [
new(Keys.S),
new(Axes.RightY, 0.0f, false)
],
},
["Menu"] = new()
{
Deadzone = 0.35f,
Left = [
new(Keys.Left),
new(Buttons.Left),
new(Axes.LeftX, 0.50f, true)
],
Right = [
new(Keys.Right),
new(Buttons.Right),
new(Axes.LeftX, 0.50f, false)
],
Up = [
new(Keys.Up),
new(Buttons.Up),
new(Axes.LeftY, 0.50f, true)
],
Down = [
new(Keys.Down),
new(Buttons.Down),
new(Axes.LeftY, 0.50f, false)
],
},
}
};

public override JsonTypeInfo GetTypeInfo()
{
return ControlsConfig_V01Context.Default.ControlsConfig_V01;
Expand Down
2 changes: 2 additions & 0 deletions Source/Data/PersistedData/ModSettingsRecord_V01.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public sealed class ModSettingsRecord_V01 : PersistedData
public Dictionary<string, float> SettingsFloatData { get; set; } = [];
public Dictionary<string, bool> SettingsBoolData { get; set; } = [];

public ControlsConfig_V01 ModControlBindings { get; set; } = new ControlsConfig_V01();

public string GetStringSetting(string name, string defaultValue = "")
=> SettingsStringData.TryGetValue(name, out string? value) ? value : defaultValue;

Expand Down
5 changes: 5 additions & 0 deletions Source/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ public override void Update()
// update top scene
try
{
if (!(scene is GameErrorMessage))
{
ModManager.Instance.PreUpdate(Time.Delta);
}

if (scene != null)
{
var pausing =
Expand Down
13 changes: 8 additions & 5 deletions Source/Helpers/Menu.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Celeste64.Mod;

namespace Celeste64;

public class Menu
Expand Down Expand Up @@ -49,23 +51,24 @@ public Item Describe(Loc.Localized description)
/// <param name="button">Virtual button we are trying to bind to</param>
/// <param name="rootMenu">Root menu for the menu we are currently in</param>
/// <param name="isForController">True if this is a controller binding, false for keyboard</param>
public class InputBind(Loc.Localized locString, VirtualButton button, Menu? rootMenu, bool isForController) : Item
public class InputBind(Loc.Localized locString, VirtualButton button, Menu? rootMenu, bool isForController, GameMod? mod = null) : Item
{
public override Loc.Localized? LocString => locString;

public float DeadZone;
public bool RequiresBinding;
public bool IsForController => isForController;
public GameMod? Mod => mod;
public override bool Pressed()
{
Audio.Play(Sfx.ui_select);
rootMenu?.PushSubMenu(new BindControlMenu(rootMenu, button, locString, isForController, DeadZone));
rootMenu?.PushSubMenu(new BindControlMenu(rootMenu, button, locString, isForController, DeadZone, mod));
return true;
}

public virtual List<Subtexture> GetTextures()
{
return Controls.GetPrompts(button, isForController);
return Controls.GetPrompts(button, isForController, Mod?.ModSettingsData?.ModControlBindings);
}

public VirtualButton GetButton()
Expand Down Expand Up @@ -478,12 +481,12 @@ protected virtual void HandleInput()
if (Controls.ResetBindings.ConsumePress())
{
// Reset current binding to it's default value
Controls.ResetBinding(bind.GetButton(), bind.IsForController);
Controls.ResetBinding(bind.GetButton(), bind.IsForController, bind.Mod);
}
else if (Controls.ClearBindings.ConsumePress())
{
// Clear current binding so there are no bindings (Or 1 binding if RequiredBinding flag is true, where it will keep just the last binding)
Controls.ClearBinding(bind.GetButton(), bind.IsForController, bind.RequiresBinding);
Controls.ClearBinding(bind.GetButton(), bind.IsForController, bind.RequiresBinding, bind.Mod?.ModSettingsData?.ModControlBindings);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Source/Mod/Core/GameMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public bool LoadSettings()

try
{
Controls.LoadModConfig(this);

return LoadSettingsForType("Settings.", SettingsType, Settings);
}
catch (Exception e)
Expand Down Expand Up @@ -587,6 +589,13 @@ public virtual void OnModLoaded() { }
/// </summary>
public virtual void OnModUnloaded() { }


/// <summary>
/// Called once at the beginning of every frame, before game logic
/// </summary>
/// <param name="deltaTime">How much time passed since the previous update</param>
public virtual void PreUpdate(float deltaTime) { }

/// <summary>
/// Called once every frame
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Source/Mod/Core/ModManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ internal void OnModFileChanged(ModFileChangedCtx ctx)
if (Settings.EnableAutoReload) Game.Instance.ReloadAssets(false);
}

internal void PreUpdate(float deltaTime)
{
foreach (var mod in EnabledMods)
{
mod.PreUpdate(deltaTime);
}
}

internal void Update(float deltaTime)
{
foreach (var mod in EnabledMods)
Expand Down
14 changes: 9 additions & 5 deletions Source/Mod/Menu/BindControlMenu.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Celeste64.Mod;

namespace Celeste64;

public class BindControlMenu : Menu
Expand All @@ -7,15 +9,17 @@ public class BindControlMenu : Menu
private const float waitBeforeClosingTime = 5;
private VirtualButton button;
private bool isForController;
private GameMod? mod;
private float deadZone;

public BindControlMenu(Menu? rootMenu, VirtualButton button, string buttonName, bool isForController, float deadZone = 0)
public BindControlMenu(Menu? rootMenu, VirtualButton button, string buttonName, bool isForController, float deadZone = 0, GameMod? mod = null)
{
RootMenu = rootMenu;

this.button = button;
this.deadZone = deadZone;
this.isForController = isForController;
this.mod = mod;
Title = string.Format(Loc.Str("PressToBind"), buttonName);
TitleScale = 1;

Expand All @@ -30,7 +34,7 @@ protected override void HandleInput()
Keys? pressed = Input.Keyboard.FirstPressed();
if (pressed != null && pressed != Keys.Unknown && pressed != Keys.Application && pressed != Keys.ScrollLock) // We don't have icons for these currently, so don't allow them
{
Controls.AddBinding(button, (Keys)pressed);
Controls.AddBinding(button, (Keys)pressed, mod?.ModSettingsData?.ModControlBindings);
RootMenu?.PopSubMenu();
return;
}
Expand All @@ -40,7 +44,7 @@ protected override void HandleInput()
{
if (Input.Mouse.Pressed((MouseButtons)button))
{
Controls.AddBinding(this.button, (MouseButtons)button);
Controls.AddBinding(this.button, (MouseButtons)button, mod?.ModSettingsData?.ModControlBindings);
RootMenu?.PopSubMenu();
return;
}
Expand All @@ -56,7 +60,7 @@ protected override void HandleInput()
{
if (controller.Pressed((Buttons)button))
{
Controls.AddBinding(this.button, (Buttons)button);
Controls.AddBinding(this.button, (Buttons)button, mod?.ModSettingsData?.ModControlBindings);
RootMenu?.PopSubMenu();
return;
}
Expand All @@ -66,7 +70,7 @@ protected override void HandleInput()
{
if (Math.Abs(controller.Axis((Axes)axis)) > 0.5f)
{
Controls.AddBinding(this.button, (Axes)axis, controller.Axis((Axes)axis) < -0.5f, deadZone);
Controls.AddBinding(this.button, (Axes)axis, controller.Axis((Axes)axis) < -0.5f, deadZone, mod?.ModSettingsData?.ModControlBindings);
RootMenu?.PopSubMenu();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Mod/Menu/ControlsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ protected override void RenderItems(Batcher batch)
UI.Prompt(batch, Controls.Confirm, Loc.Str("Bind"), at, out width, 1.0f);
at.X -= width + 8 * Game.RelativeScale;

UI.Prompt(batch, Controls.CreateFile, Loc.Str("Clear"), at, out width, 1.0f);
UI.Prompt(batch, Controls.ClearBindings, Loc.Str("Clear"), at, out width, 1.0f);
at.X -= width + 8 * Game.RelativeScale;

UI.Prompt(batch, Controls.CopyFile, Loc.Str("Reset"), at, out width, 1.0f);
UI.Prompt(batch, Controls.ResetBindings, Loc.Str("Reset"), at, out width, 1.0f);
batch.PopMatrix();
}
}
Loading