1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 12:45:09 +08:00

refactor and implemented feedback:

- button text change
- renamed ActionableInfoWithNumberBox to ResolutionSelector and moved the clamping logic inside it
- also removed the ugly right margin and added the FillFlowContainer
This commit is contained in:
Olle Kelderman 2020-05-24 22:24:46 +02:00
parent 554be1c422
commit 1062e07ec1

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tournament.Screens
private FillFlowContainer fillFlow; private FillFlowContainer fillFlow;
private LoginOverlay loginOverlay; private LoginOverlay loginOverlay;
private ActionableInfoWithNumberBox resolution; private ResolutionSelector resolution;
[Resolved] [Resolved]
private MatchIPCInfo ipc { get; set; } private MatchIPCInfo ipc { get; set; }
@ -108,15 +108,13 @@ namespace osu.Game.Tournament.Screens
Items = rulesets.AvailableRulesets, Items = rulesets.AvailableRulesets,
Current = LadderInfo.Ruleset, Current = LadderInfo.Ruleset,
}, },
resolution = new ActionableInfoWithNumberBox resolution = new ResolutionSelector
{ {
Label = "Stream area resolution", Label = "Stream area resolution",
ButtonText = "Set size", ButtonText = "Set height",
Action = i => Action = i =>
{ {
i = Math.Clamp(i, 480, 2160);
windowSize.Value = new Size((int)(i * aspect_ratio / TournamentSceneManager.STREAM_AREA_WIDTH * TournamentSceneManager.REQUIRED_WIDTH), i); windowSize.Value = new Size((int)(i * aspect_ratio / TournamentSceneManager.STREAM_AREA_WIDTH * TournamentSceneManager.REQUIRED_WIDTH), i);
resolution.NumberValue = i;
} }
}, },
}; };
@ -167,17 +165,18 @@ namespace osu.Game.Tournament.Screens
public string Value public string Value
{ {
set => ValueText.Text = value; set => valueText.Text = value;
} }
public bool Failing public bool Failing
{ {
set => ValueText.Colour = value ? Color4.Red : Color4.White; set => valueText.Colour = value ? Color4.Red : Color4.White;
} }
public Action Action; public Action Action;
protected TournamentSpriteText ValueText; private TournamentSpriteText valueText;
protected FillFlowContainer FlowContainer;
protected override Drawable CreateComponent() => new Container protected override Drawable CreateComponent() => new Container
{ {
@ -185,71 +184,75 @@ namespace osu.Game.Tournament.Screens
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Children = new Drawable[] Children = new Drawable[]
{ {
ValueText = new TournamentSpriteText valueText = new TournamentSpriteText
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
Button = new TriangleButton FlowContainer = new FillFlowContainer
{ {
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
Size = new Vector2(100, 30), AutoSizeAxes = Axes.Both,
Action = () => Action?.Invoke() Spacing = new Vector2(10, 0),
}, Children = new Drawable[]
{
Button = new TriangleButton
{
Size = new Vector2(100, 30),
Action = () => Action?.Invoke()
}
}
}
} }
}; };
} }
private class ActionableInfoWithNumberBox : ActionableInfo private class ResolutionSelector : ActionableInfo
{ {
private const int height_min_allowed_value = 480;
private const int height_max_allowed_value = 2160; // 4k
public new Action<int> Action; public new Action<int> Action;
private OsuNumberBox numberBox; private OsuNumberBox numberBox;
public int NumberValue protected override Drawable CreateComponent()
{ {
get var drawable = base.CreateComponent();
FlowContainer.Insert(0, numberBox = new OsuNumberBox
{ {
int.TryParse(numberBox.Text, out var val); Width = 100
return val; });
} FlowContainer.SetLayoutPosition(Button, 1);
set => numberBox.Text = value.ToString();
}
protected override Drawable CreateComponent() => new Container base.Action = () =>
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{ {
ValueText = new TournamentSpriteText if (numberBox.Text.Length > 0)
{ {
Anchor = Anchor.CentreLeft, // box contains text
Origin = Anchor.CentreLeft, if (!int.TryParse(numberBox.Text, out var number))
},
numberBox = new OsuNumberBox
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Width = 100,
Margin = new MarginPadding
{ {
Right = 110 // at this point, the only reason we can arrive here is if the input number was too big to parse into an int
// so clamp to max allowed value
number = height_max_allowed_value;
} }
}, else
Button = new TriangleButton
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(100, 30),
Action = () =>
{ {
if (numberBox.Text.Length > 0) Action?.Invoke(NumberValue); number = Math.Clamp(number, height_min_allowed_value, height_max_allowed_value);
} }
},
} // in case number got clamped, reset number in numberBox
}; numberBox.Text = number.ToString();
Action?.Invoke(number);
}
else
{
// TODO: input box was empty, give user feedback? do nothing?
}
};
return drawable;
}
} }
} }
} }