mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 07:33:55 +09:00
Browser - SearchableList
This commit is contained in:
102
osu.Game/Overlays/SearchableList/DisplayStyleControl.cs
Normal file
102
osu.Game/Overlays/SearchableList/DisplayStyleControl.cs
Normal file
@ -0,0 +1,102 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public class DisplayStyleControl<T> : Container
|
||||
{
|
||||
public readonly SlimEnumDropdown<T> Dropdown;
|
||||
public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>();
|
||||
|
||||
public DisplayStyleControl()
|
||||
{
|
||||
AutoSizeAxes = Axes.Both;
|
||||
|
||||
Children = new[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Spacing = new Vector2(10f, 0f),
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Spacing = new Vector2(5f, 0f),
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new[]
|
||||
{
|
||||
new DisplayStyleToggleButton(FontAwesome.fa_th_large, PanelDisplayStyle.Grid, DisplayStyle),
|
||||
new DisplayStyleToggleButton(FontAwesome.fa_list_ul, PanelDisplayStyle.List, DisplayStyle),
|
||||
},
|
||||
},
|
||||
Dropdown = new SlimEnumDropdown<T>
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Width = 160f,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
DisplayStyle.Value = PanelDisplayStyle.Grid;
|
||||
}
|
||||
|
||||
private class DisplayStyleToggleButton : ClickableContainer
|
||||
{
|
||||
private readonly TextAwesome icon;
|
||||
private readonly PanelDisplayStyle style;
|
||||
private readonly Bindable<PanelDisplayStyle> bindable;
|
||||
|
||||
public DisplayStyleToggleButton(FontAwesome icon, PanelDisplayStyle style, Bindable<PanelDisplayStyle> bindable)
|
||||
{
|
||||
this.bindable = bindable;
|
||||
this.style = style;
|
||||
Size = new Vector2(25f);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
this.icon = new TextAwesome
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = icon,
|
||||
TextSize = 18,
|
||||
UseFullGlyphHeight = false,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
};
|
||||
|
||||
bindable.ValueChanged += Bindable_ValueChanged;
|
||||
Bindable_ValueChanged(bindable.Value);
|
||||
Action = () => bindable.Value = this.style;
|
||||
}
|
||||
|
||||
private void Bindable_ValueChanged(PanelDisplayStyle style)
|
||||
{
|
||||
icon.FadeTo(style == this.style ? 1.0f : 0.5f, 100);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
bindable.ValueChanged -= Bindable_ValueChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum PanelDisplayStyle
|
||||
{
|
||||
Grid,
|
||||
List,
|
||||
}
|
||||
}
|
28
osu.Game/Overlays/SearchableList/HeaderTabControl.cs
Normal file
28
osu.Game/Overlays/SearchableList/HeaderTabControl.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public class HeaderTabControl<T> : OsuTabControl<T>
|
||||
{
|
||||
protected override TabItem<T> CreateTabItem(T value) => new HeaderTabItem(value);
|
||||
|
||||
public HeaderTabControl()
|
||||
{
|
||||
Height = 26;
|
||||
AccentColour = Color4.White;
|
||||
}
|
||||
|
||||
private class HeaderTabItem : OsuTabItem
|
||||
{
|
||||
public HeaderTabItem(T value) : base(value)
|
||||
{
|
||||
Text.TextSize = 16;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
111
osu.Game/Overlays/SearchableList/SearchableListFilterControl.cs
Normal file
111
osu.Game/Overlays/SearchableList/SearchableListFilterControl.cs
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public abstract class SearchableListFilterControl<T> : Container
|
||||
{
|
||||
private const float padding = 10;
|
||||
|
||||
private readonly Box tabStrip;
|
||||
|
||||
public readonly SearchTextBox Search;
|
||||
public readonly PageTabControl<T> Tabs;
|
||||
|
||||
protected abstract Color4 BackgroundColour { get; }
|
||||
protected abstract T DefaultTab { get; }
|
||||
protected virtual Drawable CreateSupplementaryControls() => null;
|
||||
|
||||
public SearchableListFilterControl()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("BrowseFilterControl only supports enums as the generic type argument");
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
var controls = CreateSupplementaryControls();
|
||||
Container controlsContainer;
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = BackgroundColour,
|
||||
Alpha = 0.9f,
|
||||
},
|
||||
tabStrip = new Box
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 1,
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Top = padding, Horizontal = SearchableListOverlay.WIDTH_PADDING },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Search = new FilterSearchTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
controlsContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Margin = new MarginPadding { Top = controls != null ? padding : 0 },
|
||||
},
|
||||
Tabs = new PageTabControl<T>
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
new Box //keep the tab strip part of autosize, but don't put it in the flow container
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 1,
|
||||
Colour = Color4.White.Opacity(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (controls != null) controlsContainer.Children = new[] { controls };
|
||||
|
||||
Tabs.Current.Value = DefaultTab;
|
||||
Tabs.Current.TriggerChange();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
tabStrip.Colour = colours.Yellow;
|
||||
}
|
||||
|
||||
private class FilterSearchTextBox : SearchTextBox
|
||||
{
|
||||
protected override Color4 BackgroundUnfocused => backgroundColour;
|
||||
protected override Color4 BackgroundFocused => backgroundColour;
|
||||
|
||||
private Color4 backgroundColour;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
backgroundColour = colours.Gray2.Opacity(0.9f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
94
osu.Game/Overlays/SearchableList/SearchableListHeader.cs
Normal file
94
osu.Game/Overlays/SearchableList/SearchableListHeader.cs
Normal file
@ -0,0 +1,94 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public abstract class SearchableListHeader<T> : Container
|
||||
{
|
||||
public static readonly float HEIGHT = 90;
|
||||
|
||||
private readonly Box tabStrip;
|
||||
|
||||
public readonly HeaderTabControl<T> Tabs;
|
||||
|
||||
protected abstract Color4 BackgroundColour { get; }
|
||||
protected abstract float TabStripWidth { get; } //can be removed once (if?) TabControl support auto sizing
|
||||
protected abstract T DefaultTab { get; }
|
||||
protected abstract Drawable CreateHeaderText();
|
||||
|
||||
public SearchableListHeader()
|
||||
{
|
||||
if (!typeof(T).IsEnum)
|
||||
throw new InvalidOperationException("BrowseHeader only supports enums as the generic type argument");
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = HEIGHT;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = BackgroundColour,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Left = SearchableListOverlay.WIDTH_PADDING, Right = SearchableListOverlay.WIDTH_PADDING },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Position = new Vector2(-35f, 5f),
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(10f, 0f),
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TextAwesome
|
||||
{
|
||||
TextSize = 25,
|
||||
Icon = FontAwesome.fa_osu_chevron_down_o,
|
||||
},
|
||||
CreateHeaderText(),
|
||||
},
|
||||
},
|
||||
tabStrip = new Box
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Width = TabStripWidth,
|
||||
Height = 1,
|
||||
},
|
||||
Tabs = new HeaderTabControl<T>
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Tabs.Current.Value = DefaultTab;
|
||||
Tabs.Current.TriggerChange();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
tabStrip.Colour = colours.Green;
|
||||
}
|
||||
}
|
||||
}
|
124
osu.Game/Overlays/SearchableList/SearchableListOverlay.cs
Normal file
124
osu.Game/Overlays/SearchableList/SearchableListOverlay.cs
Normal file
@ -0,0 +1,124 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Graphics.Backgrounds;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public abstract class SearchableListOverlay : WaveOverlayContainer
|
||||
{
|
||||
public static readonly float WIDTH_PADDING = 80;
|
||||
}
|
||||
|
||||
//todo: naming
|
||||
public abstract class SearchableListOverlay<T,U> : SearchableListOverlay
|
||||
{
|
||||
private readonly Container scrollContainer;
|
||||
|
||||
protected readonly SearchableListHeader<T> Header;
|
||||
protected readonly SearchableListFilterControl<U> Filter;
|
||||
protected readonly FillFlowContainer ScrollFlow;
|
||||
|
||||
protected abstract Color4 BackgroundColour { get; }
|
||||
protected abstract Color4 TrianglesColourLight { get; }
|
||||
protected abstract Color4 TrianglesColourDark { get; }
|
||||
protected abstract SearchableListHeader<T> CreateHeader();
|
||||
protected abstract SearchableListFilterControl<U> CreateFilterControl();
|
||||
|
||||
public SearchableListOverlay()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = BackgroundColour,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
Children = new[]
|
||||
{
|
||||
new Triangles
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
TriangleScale = 5,
|
||||
ColourLight = TrianglesColourLight,
|
||||
ColourDark = TrianglesColourDark,
|
||||
},
|
||||
},
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
Header = CreateHeader(),
|
||||
Filter = CreateFilterControl(),
|
||||
},
|
||||
},
|
||||
scrollContainer = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
{
|
||||
new ScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
ScrollDraggerVisible = false,
|
||||
Children = new[]
|
||||
{
|
||||
ScrollFlow = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Horizontal = SearchableListOverlay.WIDTH_PADDING },
|
||||
Direction = FillDirection.Vertical,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Filter.Search.Exit = Hide;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
scrollContainer.Padding = new MarginPadding { Top = Header.Height + Filter.Height };
|
||||
}
|
||||
|
||||
protected override bool OnFocus(InputState state)
|
||||
{
|
||||
Filter.Search.TriggerFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
{
|
||||
base.PopIn();
|
||||
|
||||
Filter.Search.HoldFocus = true;
|
||||
}
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
base.PopOut();
|
||||
|
||||
Filter.Search.HoldFocus = false;
|
||||
}
|
||||
}
|
||||
}
|
41
osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs
Normal file
41
osu.Game/Overlays/SearchableList/SlimEnumDropdown.cs
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Game.Overlays.SearchableList
|
||||
{
|
||||
public class SlimEnumDropdown<T> : OsuEnumDropdown<T>
|
||||
{
|
||||
protected override DropdownHeader CreateHeader() => new SlimDropdownHeader { AccentColour = AccentColour };
|
||||
protected override Menu CreateMenu() => new SlimMenu();
|
||||
|
||||
private class SlimDropdownHeader : OsuDropdownHeader
|
||||
{
|
||||
public SlimDropdownHeader()
|
||||
{
|
||||
Height = 25;
|
||||
Icon.TextSize = 16;
|
||||
Foreground.Padding = new MarginPadding { Top = 4, Bottom = 4, Left = 8, Right = 4 };
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
BackgroundColour = Color4.Black.Opacity(0.25f);
|
||||
}
|
||||
}
|
||||
|
||||
private class SlimMenu : OsuMenu
|
||||
{
|
||||
public SlimMenu()
|
||||
{
|
||||
Background.Colour = Color4.Black.Opacity(0.25f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user