1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 01:32:55 +08:00

Move drawable construction to load for simplicity

This commit is contained in:
Dean Herbert 2023-05-04 11:14:51 +09:00
parent be995f1359
commit 99d2616c34

View File

@ -20,13 +20,13 @@ namespace osu.Game.Overlays.Mods
{ {
internal partial class EditPresetPopover : OsuPopover internal partial class EditPresetPopover : OsuPopover
{ {
private readonly ModPresetPanel button; private readonly ModPresetPanel presetPanel;
private readonly LabelledTextBox nameTextBox; private LabelledTextBox nameTextBox = null!;
private readonly LabelledTextBox descriptionTextBox; private LabelledTextBox descriptionTextBox = null!;
private readonly ShearedButton useCurrentModsButton; private ShearedButton useCurrentModsButton = null!;
private readonly ShearedButton saveButton; private ShearedButton saveButton = null!;
private readonly FillFlowContainer scrollContent; private FillFlowContainer scrollContent = null!;
private readonly ModPreset preset; private readonly ModPreset preset;
@ -41,11 +41,15 @@ namespace osu.Game.Overlays.Mods
[Resolved] [Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!; private OverlayColourProvider colourProvider { get; set; } = null!;
public EditPresetPopover(ModPresetPanel modPresetPanel) public EditPresetPopover(ModPresetPanel presetPanel)
{ {
button = modPresetPanel; this.presetPanel = presetPanel;
preset = button.Preset.Value; preset = presetPanel.Preset.Value;
}
[BackgroundDependencyLoader]
private void load()
{
Child = new FillFlowContainer Child = new FillFlowContainer
{ {
Width = 300, Width = 300,
@ -59,14 +63,16 @@ namespace osu.Game.Overlays.Mods
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Label = CommonStrings.Name, Label = CommonStrings.Name,
TabbableContentContainer = this TabbableContentContainer = this,
Current = { Value = preset.Name },
}, },
descriptionTextBox = new LabelledTextBox descriptionTextBox = new LabelledTextBox
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Label = CommonStrings.Description, Label = CommonStrings.Description,
TabbableContentContainer = this TabbableContentContainer = this,
Current = { Value = preset.Description },
}, },
new OsuScrollContainer new OsuScrollContainer
{ {
@ -95,40 +101,30 @@ namespace osu.Game.Overlays.Mods
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Text = ModSelectOverlayStrings.UseCurrentMods, Text = ModSelectOverlayStrings.UseCurrentMods,
Action = useCurrentMods DarkerColour = colours.Blue1,
LighterColour = colours.Blue0,
TextColour = colourProvider.Background6,
Action = useCurrentMods,
}, },
saveButton = new ShearedButton saveButton = new ShearedButton
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Text = Resources.Localisation.Web.CommonStrings.ButtonsSave, Text = Resources.Localisation.Web.CommonStrings.ButtonsSave,
Action = save DarkerColour = colours.Orange1,
LighterColour = colours.Orange0,
TextColour = colourProvider.Background6,
Action = save,
}, },
} }
} }
} }
}; };
}
[BackgroundDependencyLoader]
private void load()
{
Body.BorderThickness = 3; Body.BorderThickness = 3;
Body.BorderColour = colours.Orange1; Body.BorderColour = colours.Orange1;
nameTextBox.Current.Value = preset.Name;
descriptionTextBox.Current.Value = preset.Description;
saveButton.DarkerColour = colours.Orange1;
saveButton.LighterColour = colours.Orange0;
saveButton.TextColour = colourProvider.Background6;
useCurrentModsButton.DarkerColour = colours.Blue1;
useCurrentModsButton.LighterColour = colours.Blue0;
useCurrentModsButton.TextColour = colourProvider.Background6;
selectedMods.BindValueChanged(_ => updateActiveState(), true); selectedMods.BindValueChanged(_ => updateActiveState(), true);
nameTextBox.Current.BindValueChanged(s => nameTextBox.Current.BindValueChanged(s =>
{ {
saveButton.Enabled.Value = !string.IsNullOrWhiteSpace(s.NewValue); saveButton.Enabled.Value = !string.IsNullOrWhiteSpace(s.NewValue);
@ -156,7 +152,7 @@ namespace osu.Game.Overlays.Mods
if (newMods?.SetEquals(selectedMods.Value) == false) if (newMods?.SetEquals(selectedMods.Value) == false)
return true; return true;
return button.CheckCurrentModCanBeSave(); return presetPanel.CheckCurrentModCanBeSave();
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -168,7 +164,7 @@ namespace osu.Game.Overlays.Mods
private void save() private void save()
{ {
button.Preset.PerformWrite(s => presetPanel.Preset.PerformWrite(s =>
{ {
s.Name = nameTextBox.Current.Value; s.Name = nameTextBox.Current.Value;
s.Description = descriptionTextBox.Current.Value; s.Description = descriptionTextBox.Current.Value;