1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +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 LoginOverlay loginOverlay;
private ActionableInfoWithNumberBox resolution;
private ResolutionSelector resolution;
[Resolved]
private MatchIPCInfo ipc { get; set; }
@ -108,15 +108,13 @@ namespace osu.Game.Tournament.Screens
Items = rulesets.AvailableRulesets,
Current = LadderInfo.Ruleset,
},
resolution = new ActionableInfoWithNumberBox
resolution = new ResolutionSelector
{
Label = "Stream area resolution",
ButtonText = "Set size",
ButtonText = "Set height",
Action = i =>
{
i = Math.Clamp(i, 480, 2160);
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
{
set => ValueText.Text = value;
set => valueText.Text = value;
}
public bool Failing
{
set => ValueText.Colour = value ? Color4.Red : Color4.White;
set => valueText.Colour = value ? Color4.Red : Color4.White;
}
public Action Action;
protected TournamentSpriteText ValueText;
private TournamentSpriteText valueText;
protected FillFlowContainer FlowContainer;
protected override Drawable CreateComponent() => new Container
{
@ -185,71 +184,75 @@ namespace osu.Game.Tournament.Screens
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
ValueText = new TournamentSpriteText
valueText = new TournamentSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
Button = new TriangleButton
FlowContainer = new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
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;
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);
return val;
Width = 100
});
FlowContainer.SetLayoutPosition(Button, 1);
base.Action = () =>
{
if (numberBox.Text.Length > 0)
{
// box contains text
if (!int.TryParse(numberBox.Text, out var number))
{
// 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;
}
set => numberBox.Text = value.ToString();
else
{
number = Math.Clamp(number, height_min_allowed_value, height_max_allowed_value);
}
protected override Drawable CreateComponent() => new Container
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{
ValueText = new TournamentSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
numberBox = new OsuNumberBox
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Width = 100,
Margin = new MarginPadding
{
Right = 110
// in case number got clamped, reset number in numberBox
numberBox.Text = number.ToString();
Action?.Invoke(number);
}
},
Button = new TriangleButton
else
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Size = new Vector2(100, 30),
Action = () =>
{
if (numberBox.Text.Length > 0) Action?.Invoke(NumberValue);
}
},
// TODO: input box was empty, give user feedback? do nothing?
}
};
return drawable;
}
}
}
}