Skip to content

Commit

Permalink
Merge pull request #2274 from andy840119/refactor-toolbar-button-inherit
Browse files Browse the repository at this point in the history
Refactor toolbar button inherition.
  • Loading branch information
andy840119 authored Aug 18, 2024
2 parents 5a1657c + f117019 commit 050e614
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 99 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose.Toolbar.Carets;

public abstract partial class MoveToCaretPositionButton : KeyActionButton
public abstract partial class MoveToCaretPositionButton : ToolbarEditActionButton
{
protected abstract MovingCaretAction AcceptAction { get; }

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Configuration;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose.Toolbar.Panels;

public partial class ToggleInvalidInfoPanelButton : LyricEditorConfigButton
public partial class ToggleInvalidInfoPanelButton : ToolbarToggleButton
{
protected override KaraokeRulesetLyricEditorSetting Setting => KaraokeRulesetLyricEditorSetting.ShowInvalidInfoInComposer;
public ToggleInvalidInfoPanelButton()
{
SetIcon(FontAwesome.Solid.ExclamationTriangle);
}

protected override IconUsage Icon => FontAwesome.Solid.ExclamationTriangle;
[BackgroundDependencyLoader]
private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManager)
{
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.ShowInvalidInfoInComposer, Active);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Karaoke.Configuration;

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose.Toolbar.Panels;

public partial class TogglePropertyPanelButton : LyricEditorConfigButton
public partial class TogglePropertyPanelButton : ToolbarToggleButton
{
protected override KaraokeRulesetLyricEditorSetting Setting => KaraokeRulesetLyricEditorSetting.ShowPropertyPanelInComposer;
public TogglePropertyPanelButton()
{
SetIcon(FontAwesome.Solid.FileImage);
}

protected override IconUsage Icon => FontAwesome.Solid.FileImage;
[BackgroundDependencyLoader]
private void load(KaraokeRulesetLyricEditorConfigManager lyricEditorConfigManager)
{
lyricEditorConfigManager.BindWith(KaraokeRulesetLyricEditorSetting.ShowPropertyPanelInComposer, Active);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osuTK;

Expand All @@ -15,47 +17,63 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose
/// </summary>
public abstract partial class ToolbarButton : OsuClickableContainer
{
public void SetIcon(Drawable icon)
{
Size = new Vector2(SpecialActionToolbar.HEIGHT);
IconContainer.Icon = icon;
IconContainer.Show();
}

[Resolved]
private TextureStore textures { get; set; } = null!;

public void SetIcon(string texture) =>
SetIcon(new Sprite
[Resolved]
private OsuColour colours { get; set; } = null!;

protected ConstrainedIconContainer IconContainer;

protected ToolbarButton()
{
Children = new Drawable[]
{
Texture = textures.Get(texture),
});
IconContainer = new ConstrainedIconContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(SpecialActionToolbar.ICON_SIZE),
Alpha = 0,
},
};
}

public void SetIcon(IconUsage iconUsage) =>
SetIcon(new SpriteIcon
{
Icon = iconUsage,
});

public void SetIcon(Drawable icon)
{
Size = new Vector2(SpecialActionToolbar.HEIGHT);
IconContainer.Icon = icon;
IconContainer.Show();
}

protected void SetState(bool enabled)
{
IconContainer.Icon.Alpha = enabled ? 1f : 0.5f;
Enabled.Value = enabled;
}

protected ConstrainedIconContainer IconContainer;
protected override bool OnClick(ClickEvent e)
{
ToggleClickEffect();

protected ToolbarButton()
return base.OnClick(e);
}

public void ToggleClickEffect()
{
Children = new Drawable[]
if (Enabled.Value)
{
IconContainer = new ConstrainedIconContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(SpecialActionToolbar.ICON_SIZE),
Alpha = 0,
},
};
IconContainer.FadeOut(100).Then().FadeIn();
}
else
{
IconContainer.FadeColour(colours.Red, 100).Then().FadeColour(Colour4.White);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose
/// <summary>
/// Button that able to receive the <see cref="KaraokeEditAction"/> event.
/// </summary>
public abstract partial class KeyActionButton : ActionButton, IKeyBindingHandler<KaraokeEditAction>, IHasIKeyBindingHandlerOrder
public abstract partial class ToolbarEditActionButton : ToolbarButton, IKeyBindingHandler<KaraokeEditAction>, IHasIKeyBindingHandlerOrder
{
protected abstract KaraokeEditAction EditAction { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Content.Compose
/// <summary>
/// Button for toggle open and close.
/// </summary>
public abstract partial class ToggleButton : ToolbarButton
public abstract partial class ToolbarToggleButton : ToolbarButton
{
protected readonly Bindable<bool> Active = new();

protected ToggleButton()
protected ToolbarToggleButton()
{
Active.BindValueChanged(x =>
{
Expand Down

0 comments on commit 050e614

Please sign in to comment.