Skip to content

Commit

Permalink
Merge pull request #2482 from smoogipoo/use-bindable-transforms
Browse files Browse the repository at this point in the history
Use bindable transforms
  • Loading branch information
peppy committed May 10, 2018
2 parents aa69e0e + 2e9c91c commit 3504f73
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 50 deletions.
25 changes: 1 addition & 24 deletions osu.Game/Overlays/ChatOverlay.cs
Expand Up @@ -12,10 +12,8 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.MathUtils;
using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Graphics;
Expand Down Expand Up @@ -181,7 +179,7 @@ public ChatOverlay()
{
textbox.HoldFocus = false;
if (1f - ChatHeight.Value < channel_selection_min_height)
transformChatHeightTo(1f - channel_selection_min_height, 800, Easing.OutQuint);
this.TransformBindableTo(ChatHeight, 1f - channel_selection_min_height, 800, Easing.OutQuint);
}
else
textbox.HoldFocus = true;
Expand Down Expand Up @@ -533,26 +531,5 @@ private void postMessage(TextBox textbox, bool newText)

api.Queue(req);
}

private void transformChatHeightTo(double newChatHeight, double duration = 0, Easing easing = Easing.None)
{
this.TransformTo(this.PopulateTransform(new TransformChatHeight(), newChatHeight, duration, easing));
}

private class TransformChatHeight : Transform<double, ChatOverlay>
{
private double valueAt(double time)
{
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;

return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}

public override string TargetMember => "ChatHeight.Value";

protected override void Apply(ChatOverlay d, double time) => d.ChatHeight.Value = valueAt(time);
protected override void ReadIntoStartValue(ChatOverlay d) => StartValue = d.ChatHeight.Value;
}
}
}
27 changes: 2 additions & 25 deletions osu.Game/Rulesets/UI/Scrolling/ScrollingPlayfield.cs
Expand Up @@ -4,9 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transforms;
using osu.Framework.Input;
using osu.Framework.MathUtils;
using osu.Game.Rulesets.Objects.Drawables;
using OpenTK.Input;

Expand Down Expand Up @@ -90,38 +88,17 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
switch (args.Key)
{
case Key.Minus:
transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint);
this.TransformBindableTo(VisibleTimeRange, VisibleTimeRange + time_span_step, 200, Easing.OutQuint);
break;
case Key.Plus:
transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint);
this.TransformBindableTo(VisibleTimeRange, VisibleTimeRange - time_span_step, 200, Easing.OutQuint);
break;
}
}

return false;
}

private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None)
{
this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing));
}

protected sealed override HitObjectContainer CreateHitObjectContainer() => new ScrollingHitObjectContainer(direction);

private class TransformVisibleTimeRange : Transform<double, ScrollingPlayfield>
{
private double valueAt(double time)
{
if (time < StartTime) return StartValue;
if (time >= EndTime) return EndValue;

return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
}

public override string TargetMember => "VisibleTimeRange.Value";

protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time);
protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value;
}
}
}

0 comments on commit 3504f73

Please sign in to comment.