mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 16:12:54 +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:
parent
554be1c422
commit
1062e07ec1
@ -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,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Spacing = new Vector2(10, 0),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
Button = new TriangleButton
|
||||||
|
{
|
||||||
Size = new Vector2(100, 30),
|
Size = new Vector2(100, 30),
|
||||||
Action = () => Action?.Invoke()
|
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);
|
||||||
|
|
||||||
|
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
|
// in case number got clamped, reset number in numberBox
|
||||||
{
|
numberBox.Text = number.ToString();
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
Action?.Invoke(number);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
},
|
else
|
||||||
Button = new TriangleButton
|
|
||||||
{
|
{
|
||||||
Anchor = Anchor.CentreRight,
|
// TODO: input box was empty, give user feedback? do nothing?
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
Size = new Vector2(100, 30),
|
|
||||||
Action = () =>
|
|
||||||
{
|
|
||||||
if (numberBox.Text.Length > 0) Action?.Invoke(NumberValue);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user