mirror of
https://github.com/osukey/osukey.git
synced 2025-05-25 23:47:30 +09:00
Split AddPresetPopover
to separate file
This commit is contained in:
parent
ac9321204c
commit
82d3fbd51b
@ -7,18 +7,12 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Cursor;
|
using osu.Framework.Graphics.Cursor;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Game.Database;
|
|
||||||
using osu.Game.Extensions;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Game.Localisation;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
{
|
{
|
||||||
@ -69,96 +63,5 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Popover GetPopover() => new AddPresetPopover(this);
|
public Popover GetPopover() => new AddPresetPopover(this);
|
||||||
|
|
||||||
private class AddPresetPopover : OsuPopover
|
|
||||||
{
|
|
||||||
private readonly AddPresetButton button;
|
|
||||||
|
|
||||||
private readonly LabelledTextBox nameTextBox;
|
|
||||||
private readonly LabelledTextBox descriptionTextBox;
|
|
||||||
private readonly ShearedButton createButton;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private Bindable<RulesetInfo> ruleset { get; set; } = null!;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
|
||||||
|
|
||||||
[Resolved]
|
|
||||||
private RealmAccess realm { get; set; } = null!;
|
|
||||||
|
|
||||||
public AddPresetPopover(AddPresetButton addPresetButton)
|
|
||||||
{
|
|
||||||
button = addPresetButton;
|
|
||||||
|
|
||||||
Child = new FillFlowContainer
|
|
||||||
{
|
|
||||||
Width = 300,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Spacing = new Vector2(7),
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
nameTextBox = new LabelledTextBox
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Label = CommonStrings.Name,
|
|
||||||
TabbableContentContainer = this
|
|
||||||
},
|
|
||||||
descriptionTextBox = new LabelledTextBox
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Label = CommonStrings.Description,
|
|
||||||
TabbableContentContainer = this
|
|
||||||
},
|
|
||||||
createButton = new ShearedButton
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
Text = ModSelectOverlayStrings.AddPreset,
|
|
||||||
Action = tryCreatePreset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
|
||||||
{
|
|
||||||
Body.BorderThickness = 3;
|
|
||||||
Body.BorderColour = colours.Orange1;
|
|
||||||
|
|
||||||
createButton.DarkerColour = colours.Orange1;
|
|
||||||
createButton.LighterColour = colours.Orange0;
|
|
||||||
createButton.TextColour = colourProvider.Background6;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tryCreatePreset()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value))
|
|
||||||
{
|
|
||||||
Body.Shake();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
realm.Write(r => r.Add(new ModPreset
|
|
||||||
{
|
|
||||||
Name = nameTextBox.Current.Value,
|
|
||||||
Description = descriptionTextBox.Current.Value,
|
|
||||||
Mods = selectedMods.Value.ToArray(),
|
|
||||||
Ruleset = r.Find<RulesetInfo>(ruleset.Value.ShortName)
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.HidePopover();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
|
||||||
{
|
|
||||||
base.UpdateState(state);
|
|
||||||
if (state.NewValue == Visibility.Hidden)
|
|
||||||
button.Active.Value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
113
osu.Game/Overlays/Mods/AddPresetPopover.cs
Normal file
113
osu.Game/Overlays/Mods/AddPresetPopover.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Database;
|
||||||
|
using osu.Game.Extensions;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Localisation;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Mods
|
||||||
|
{
|
||||||
|
internal class AddPresetPopover : OsuPopover
|
||||||
|
{
|
||||||
|
private readonly AddPresetButton button;
|
||||||
|
|
||||||
|
private readonly LabelledTextBox nameTextBox;
|
||||||
|
private readonly LabelledTextBox descriptionTextBox;
|
||||||
|
private readonly ShearedButton createButton;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<RulesetInfo> ruleset { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private Bindable<IReadOnlyList<Mod>> selectedMods { get; set; } = null!;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RealmAccess realm { get; set; } = null!;
|
||||||
|
|
||||||
|
public AddPresetPopover(AddPresetButton addPresetButton)
|
||||||
|
{
|
||||||
|
button = addPresetButton;
|
||||||
|
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
Width = 300,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(7),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
nameTextBox = new LabelledTextBox
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Label = CommonStrings.Name,
|
||||||
|
TabbableContentContainer = this
|
||||||
|
},
|
||||||
|
descriptionTextBox = new LabelledTextBox
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Label = CommonStrings.Description,
|
||||||
|
TabbableContentContainer = this
|
||||||
|
},
|
||||||
|
createButton = new ShearedButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
Text = ModSelectOverlayStrings.AddPreset,
|
||||||
|
Action = tryCreatePreset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
||||||
|
{
|
||||||
|
Body.BorderThickness = 3;
|
||||||
|
Body.BorderColour = colours.Orange1;
|
||||||
|
|
||||||
|
createButton.DarkerColour = colours.Orange1;
|
||||||
|
createButton.LighterColour = colours.Orange0;
|
||||||
|
createButton.TextColour = colourProvider.Background6;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryCreatePreset()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(nameTextBox.Current.Value))
|
||||||
|
{
|
||||||
|
Body.Shake();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
realm.Write(r => r.Add(new ModPreset
|
||||||
|
{
|
||||||
|
Name = nameTextBox.Current.Value,
|
||||||
|
Description = descriptionTextBox.Current.Value,
|
||||||
|
Mods = selectedMods.Value.ToArray(),
|
||||||
|
Ruleset = r.Find<RulesetInfo>(ruleset.Value.ShortName)
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.HidePopover();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
||||||
|
{
|
||||||
|
base.UpdateState(state);
|
||||||
|
if (state.NewValue == Visibility.Hidden)
|
||||||
|
button.Active.Value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user