mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Fix ruleset selector line not moving on first display
This commit is contained in:
@ -7,7 +7,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
@ -19,17 +22,24 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
typeof(ToolbarRulesetTabButton),
|
typeof(ToolbarRulesetTabButton),
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestSceneToolbarRulesetSelector()
|
[Resolved]
|
||||||
{
|
private RulesetStore rulesets { get; set; }
|
||||||
ToolbarRulesetSelector selector;
|
|
||||||
|
|
||||||
Add(new Container
|
[Test]
|
||||||
|
public void TestDisplay()
|
||||||
|
{
|
||||||
|
ToolbarRulesetSelector selector = null;
|
||||||
|
|
||||||
|
AddStep("create selector", () =>
|
||||||
|
{
|
||||||
|
Child = new Container
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
Height = Toolbar.HEIGHT,
|
Height = Toolbar.HEIGHT,
|
||||||
Child = selector = new ToolbarRulesetSelector()
|
Child = selector = new ToolbarRulesetSelector()
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("Select random", () =>
|
AddStep("Select random", () =>
|
||||||
@ -38,5 +48,32 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
});
|
});
|
||||||
AddStep("Toggle disabled state", () => selector.Current.Disabled = !selector.Current.Disabled);
|
AddStep("Toggle disabled state", () => selector.Current.Disabled = !selector.Current.Disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNonFirstRulesetInitialState()
|
||||||
|
{
|
||||||
|
TestSelector selector = null;
|
||||||
|
|
||||||
|
AddStep("create selector", () =>
|
||||||
|
{
|
||||||
|
Child = new Container
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
AutoSizeAxes = Axes.X,
|
||||||
|
Height = Toolbar.HEIGHT,
|
||||||
|
Child = selector = new TestSelector()
|
||||||
|
};
|
||||||
|
|
||||||
|
selector.Current.Value = rulesets.GetRuleset(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("mode line has moved", () => selector.ModeButtonLine.DrawPosition.X > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestSelector : ToolbarRulesetSelector
|
||||||
|
{
|
||||||
|
public new Drawable ModeButtonLine => base.ModeButtonLine;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
private const float padding = 10;
|
private const float padding = 10;
|
||||||
|
|
||||||
private Drawable modeButtonLine;
|
protected Drawable ModeButtonLine { get; private set; }
|
||||||
|
|
||||||
public ToolbarRulesetSelector()
|
public ToolbarRulesetSelector()
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
Depth = 1,
|
Depth = 1,
|
||||||
},
|
},
|
||||||
modeButtonLine = new Container
|
ModeButtonLine = new Container
|
||||||
{
|
{
|
||||||
Size = new Vector2(padding * 2 + ToolbarButton.WIDTH, 3),
|
Size = new Vector2(padding * 2 + ToolbarButton.WIDTH, 3),
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
@ -66,17 +66,22 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
Current.BindValueChanged(_ => moveLineToCurrent(), true);
|
Current.BindValueChanged(_ => moveLineToCurrent(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveLineToCurrent()
|
private bool hasInitialPosition;
|
||||||
|
|
||||||
|
// Scheduled to allow the flow layout to be computed before the line position is updated
|
||||||
|
private void moveLineToCurrent() => ScheduleAfterChildren(() =>
|
||||||
{
|
{
|
||||||
foreach (TabItem<RulesetInfo> tabItem in TabContainer)
|
foreach (var tabItem in TabContainer)
|
||||||
{
|
{
|
||||||
if (tabItem.Value == Current.Value)
|
if (tabItem.Value == Current.Value)
|
||||||
{
|
{
|
||||||
modeButtonLine.MoveToX(tabItem.DrawPosition.X, 200, Easing.OutQuint);
|
ModeButtonLine.MoveToX(tabItem.DrawPosition.X, !hasInitialPosition ? 0 : 200, Easing.OutQuint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
hasInitialPosition = true;
|
||||||
|
});
|
||||||
|
|
||||||
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
|
public override bool HandleNonPositionalInput => !Current.Disabled && base.HandleNonPositionalInput;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user