Skip to content

Commit

Permalink
Merge pull request #1 from Fabiano1337/osu-lazer-speedkeys
Browse files Browse the repository at this point in the history
Osu lazer speedkeys
  • Loading branch information
Fabiano1337 committed May 2, 2024
2 parents 2d02404 + fa0b631 commit e737635
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
8 changes: 8 additions & 0 deletions osu.Game/Input/Bindings/GlobalActionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ public static IEnumerable<GlobalAction> GetGlobalActionsFor(GlobalActionCategory
new KeyBinding(new[] { InputKey.Shift, InputKey.F2 }, GlobalAction.SelectPreviousRandom),
new KeyBinding(InputKey.F3, GlobalAction.ToggleBeatmapOptions),
new KeyBinding(InputKey.BackSpace, GlobalAction.DeselectAllMods),
new KeyBinding(InputKey.PageUp, GlobalAction.IncreaseSpeed),
new KeyBinding(InputKey.PageDown, GlobalAction.DecreaseSpeed),
};

private static IEnumerable<KeyBinding> audioControlKeyBindings => new[]
Expand Down Expand Up @@ -409,6 +411,12 @@ public enum GlobalAction
[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorToggleRotateControl))]
EditorToggleRotateControl,

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.IncreaseSpeed))]
IncreaseSpeed,

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.DecreaseSpeed))]
DecreaseSpeed,

[LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.IncreaseOffset))]
IncreaseOffset,

Expand Down
10 changes: 10 additions & 0 deletions osu.Game/Localisation/GlobalActionKeyBindingStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,16 @@ public static class GlobalActionKeyBindingStrings
/// </summary>
public static LocalisableString EditorToggleRotateControl => new TranslatableString(getKey(@"editor_toggle_rotate_control"), @"Toggle rotate control");

/// <summary>
/// "Increase Speed"
/// </summary>
public static LocalisableString IncreaseSpeed => new TranslatableString(getKey(@"increase_speed"), @"Increase Speed");

/// <summary>
/// "Decrease Speed"
/// </summary>
public static LocalisableString DecreaseSpeed => new TranslatableString(getKey(@"decrease_speed"), @"Decrease Speed");

private static string getKey(string key) => $@"{prefix}:{key}";
}
}
84 changes: 82 additions & 2 deletions osu.Game/Screens/Select/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,82 @@ public override bool OnBackButton()

return false;
}

private void increaseSpeed()
{
var rateAdjustStates = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust);
var stateDoubleTime = ModSelect.AllAvailableMods.First(pair => pair.Mod is ModDoubleTime);
bool rateModActive = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust && pair.Active.Value).Count() > 0;
double stepSize = 0.05d;
double newRate = 1d + stepSize;
// If no mod rateAdjust mod is currently active activate DoubleTime with speed newRate
if (!rateModActive)
{
stateDoubleTime.Active.Value = true;
((ModDoubleTime)stateDoubleTime.Mod).SpeedChange.Value = newRate;
return;
}
// Find current active rateAdjust mod and modify speed, enable DoubleTime if necessary
foreach (var state in rateAdjustStates)
{
ModRateAdjust mod = (ModRateAdjust)state.Mod;
if (!state.Active.Value) continue;
newRate = mod.SpeedChange.Value + stepSize;
if (mod.Acronym == "DT" || mod.Acronym == "NC")
mod.SpeedChange.Value = newRate;
else
{
if (newRate == 1.0d)
state.Active.Value = false;
if (newRate > 1d)
{
state.Active.Value = false;
stateDoubleTime.Active.Value = true;
((ModDoubleTime)stateDoubleTime.Mod).SpeedChange.Value = newRate;
break;
}
if (newRate < 1d)
mod.SpeedChange.Value = newRate;
}
}
}
private void decreaseSpeed()
{
var rateAdjustStates = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust);
var stateHalfTime = ModSelect.AllAvailableMods.First(pair => pair.Mod is ModHalfTime);
bool rateModActive = ModSelect.AllAvailableMods.Where(pair => pair.Mod is ModRateAdjust && pair.Active.Value).Count() > 0;
double stepSize = 0.05d;
double newRate = 1d - stepSize;
// If no mod rateAdjust mod is currently active activate HalfTime with speed newRate
if (!rateModActive)
{
stateHalfTime.Active.Value = true;
((ModHalfTime)stateHalfTime.Mod).SpeedChange.Value = newRate;
return;
}
// Find current active rateAdjust mod and modify speed, enable HalfTime if necessary
foreach (var state in rateAdjustStates)
{
ModRateAdjust mod = (ModRateAdjust)state.Mod;
if (!state.Active.Value) continue;
newRate = mod.SpeedChange.Value - stepSize;
if (mod.Acronym == "HT" || mod.Acronym == "DC")
mod.SpeedChange.Value = newRate;
else
{
if (newRate == 1.0d)
state.Active.Value = false;
if (newRate < 1d)
{
state.Active.Value = false;
stateHalfTime.Active.Value = true;
((ModHalfTime)stateHalfTime.Mod).SpeedChange.Value = newRate;
break;
}
if (newRate > 1d)
mod.SpeedChange.Value = newRate;
}
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Expand Down Expand Up @@ -1011,12 +1086,17 @@ public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
return false;

if (!this.IsCurrentScreen()) return false;

switch (e.Action)
{
case GlobalAction.Select:
FinaliseSelection();
return true;
case GlobalAction.IncreaseSpeed:
increaseSpeed();
return true;
case GlobalAction.DecreaseSpeed:
decreaseSpeed();
return true;
}

return false;
Expand Down

0 comments on commit e737635

Please sign in to comment.