Skip to content

Commit

Permalink
Merge pull request #1580 from andy840119/fix-issue-in-the-note-popover
Browse files Browse the repository at this point in the history
Fix issue in the note popover
  • Loading branch information
andy840119 authored Sep 11, 2022
2 parents c91b337 + 731639e commit 7593f53
Showing 1 changed file with 82 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,119 @@

#nullable disable

using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Components.Containers;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Edit.Components.UserInterfaceV2
{
public class NoteEditPopover : OsuPopover
{
[Resolved(canBeNull: true)]
private INotePropertyChangeHandler notePropertyChangeHandler { get; set; }

public NoteEditPopover(Note note)
{
LabelledTextBox text;
LabelledTextBox rubyText;
LabelledSwitchButton display;
if (note == null)
throw new ArgumentNullException(nameof(note));

Children = new Drawable[]
Child = new OsuScrollContainer
{
new FillFlowContainer
Height = 320,
Width = 300,
Child = new FillFlowContainer<Section>
{
Width = 200,
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
Children = new Section[]
{
text = new LabelledTextBox
{
Label = "Text",
Description = "The text display on the note.",
Current = note.TextBindable
},
rubyText = new LabelledTextBox
{
Label = "Ruby text",
Description = "Should place something like ruby, 拼音 or ふりがな.",
Current = note.RubyTextBindable
},
display = new LabelledSwitchButton
{
Label = "Display",
Description = "This note will be hidden and not scorable if not display.",
Current = note.DisplayBindable
}
new NoteSection(note),
}
}
};
}

text.OnCommit += (sender, newText) =>
{
if (!newText)
return;
private class NoteSection : Section
{
private INotePropertyChangeHandler notePropertyChangeHandler { get; set; }

string text = sender.Text.Trim();
notePropertyChangeHandler?.ChangeText(text);
};
protected override LocalisableString Title => "Note property";

rubyText.OnCommit += (sender, newText) =>
public NoteSection(Note note)
{
if (!newText)
return;
LabelledTextBox text;
LabelledTextBox rubyText;
LabelledSwitchButton display;

string text = sender.Text.Trim();
notePropertyChangeHandler?.ChangeRubyText(text);
};
Children = new Drawable[]
{
text = new LabelledTextBox
{
Label = "Text",
Description = "The text display on the note.",
Current = note.TextBindable,
TabbableContentContainer = this
},
rubyText = new LabelledTextBox
{
Label = "Ruby text",
Description = "Should place something like ruby, 拼音 or ふりがな.",
Current = note.RubyTextBindable,
TabbableContentContainer = this
},
display = new LabelledSwitchButton
{
Label = "Display",
Description = "This note will be hidden and not scorable if not display.",
Current = note.DisplayBindable,
}
};

display.Current.BindValueChanged(v =>
{
notePropertyChangeHandler?.ChangeDisplayState(v.NewValue);
});
}
ScheduleAfterChildren(() =>
{
GetContainingInputManager().ChangeFocus(text);
});

[BackgroundDependencyLoader(true)]
private void load(HitObjectComposer composer)
{
if (notePropertyChangeHandler != null || composer == null)
return;
text.OnCommit += (sender, newText) =>
{
if (!newText)
return;

string text = sender.Text.Trim();
notePropertyChangeHandler?.ChangeText(text);
};

rubyText.OnCommit += (sender, newText) =>
{
if (!newText)
return;

string text = sender.Text.Trim();
notePropertyChangeHandler?.ChangeRubyText(text);
};

display.Current.BindValueChanged(v =>
{
notePropertyChangeHandler?.ChangeDisplayState(v.NewValue);
});
}

[BackgroundDependencyLoader(true)]
private void load(HitObjectComposer composer)
{
if (notePropertyChangeHandler != null || composer == null)
return;

// todo: not a good way to get change handler, might remove or found another way eventually.
// cannot get change handler directly in editor screen, so should trying to get from karaoke hit object composer.
notePropertyChangeHandler = composer.Dependencies.Get<INotePropertyChangeHandler>();
// todo: not a good way to get change handler, might remove or found another way eventually.
// cannot get change handler directly in editor screen, so should trying to get from karaoke hit object composer.
notePropertyChangeHandler = composer.Dependencies.Get<INotePropertyChangeHandler>();
}
}
}
}

0 comments on commit 7593f53

Please sign in to comment.