Skip to content

Commit 97d3da9

Browse files
committed
actually implement filters
1 parent 3f8a575 commit 97d3da9

2 files changed

Lines changed: 49 additions & 17 deletions

File tree

fluXis/Overlay/Browse/BrowseFilter.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using fluXis.Graphics.UserInterface.Color;
55
using fluXis.Graphics.UserInterface.Interaction;
66
using osu.Framework.Allocation;
7+
using osu.Framework.Bindables;
78
using osu.Framework.Extensions.IEnumerableExtensions;
89
using osu.Framework.Graphics;
910
using osu.Framework.Graphics.Containers;
@@ -16,7 +17,7 @@ namespace fluXis.Overlay.Browse;
1617

1718
public partial class BrowseFilter<T> : FillFlowContainer
1819
{
19-
public BrowseFilter(LocalisableString title, IEnumerable<Option> options)
20+
public BrowseFilter(LocalisableString title, BindableList<T> selected, IEnumerable<Option> options)
2021
{
2122
RelativeSizeAxes = Axes.X;
2223
Height = 20;
@@ -35,7 +36,7 @@ public BrowseFilter(LocalisableString title, IEnumerable<Option> options)
3536
}
3637
};
3738

38-
options.ForEach(x => Add(new Button(x)));
39+
options.ForEach(x => Add(new Button(x, selected)));
3940
}
4041

4142
public class Option
@@ -58,6 +59,7 @@ private partial class Button : CompositeDrawable
5859
private UISamples samples { get; set; }
5960

6061
private readonly Option option;
62+
private readonly BindableList<T> selected;
6163

6264
private Box background;
6365
private HoverLayer hover;
@@ -66,9 +68,10 @@ private partial class Button : CompositeDrawable
6668

6769
private bool enabled;
6870

69-
public Button(Option option)
71+
public Button(Option option, BindableList<T> selected)
7072
{
7173
this.option = option;
74+
this.selected = selected;
7275
}
7376

7477
[BackgroundDependencyLoader]
@@ -103,6 +106,20 @@ private void load()
103106
};
104107
}
105108

109+
protected override void LoadComplete()
110+
{
111+
base.LoadComplete();
112+
113+
selected.BindCollectionChanged((_, _) =>
114+
{
115+
enabled = selected.Contains(option.Value);
116+
117+
background.Alpha = enabled ? 1f : 0f;
118+
text.Alpha = enabled ? 1f : .6f;
119+
text.Colour = enabled ? Theme.TextDark : Theme.Text;
120+
}, true);
121+
}
122+
106123
protected override bool OnHover(HoverEvent e)
107124
{
108125
samples.Hover();
@@ -115,25 +132,15 @@ protected override void OnHoverLost(HoverLostEvent e)
115132
hover.Hide();
116133
}
117134

118-
protected override bool OnMouseDown(MouseDownEvent e)
119-
{
120-
return base.OnMouseDown(e);
121-
}
122-
123-
protected override void OnMouseUp(MouseUpEvent e)
124-
{
125-
base.OnMouseUp(e);
126-
}
127-
128135
protected override bool OnClick(ClickEvent e)
129136
{
130137
enabled = !enabled;
131138
samples.Click();
132139
flash.Show();
133140

134-
background.Alpha = enabled ? 1f : 0f;
135-
text.Alpha = enabled ? 1f : .6f;
136-
text.Colour = enabled ? Theme.TextDark : Theme.Text;
141+
var v = option.Value;
142+
if (!selected.Remove(v))
143+
selected.Add(v);
137144

138145
return true;
139146
}

fluXis/Overlay/Browse/BrowseOverlay.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using fluXis.Overlay.User.Header;
2323
using JetBrains.Annotations;
2424
using osu.Framework.Allocation;
25+
using osu.Framework.Bindables;
26+
using osu.Framework.Extensions.IEnumerableExtensions;
2527
using osu.Framework.Graphics;
2628
using osu.Framework.Graphics.Containers;
2729
using osu.Framework.Graphics.Shapes;
@@ -73,6 +75,9 @@ public partial class BrowseOverlay : OverlayContainer, IKeyBindingHandler<FluXis
7375
private bool firstOpen = true;
7476
private double previousScrollY;
7577

78+
private BindableList<MapStatus> filterStatus;
79+
private BindableList<int> filterKeymode;
80+
7681
[BackgroundDependencyLoader]
7782
private void load()
7883
{
@@ -202,12 +207,14 @@ private void load()
202207
{
203208
new BrowseFilter<MapStatus>(
204209
"Status",
210+
filterStatus = new BindableList<MapStatus>(),
205211
Enum.GetValues<MapStatus>()
206212
.Where(x => x >= MapStatus.Unsubmitted)
207213
.Select(x => new BrowseFilter<MapStatus>.Option(x, x.ToString(), Theme.GetStatusColor((int)x)))
208214
),
209215
new BrowseFilter<int>(
210216
"Keymode",
217+
filterKeymode = new BindableList<int>(),
211218
Enumerable.Range(4, 5)
212219
.Select(x => new BrowseFilter<int>.Option(x, $"{x}K", Theme.GetKeyCountColor(x)))
213220
)
@@ -256,7 +263,25 @@ private void loadMapsets(long offset = 0, bool reload = false)
256263
if (reload)
257264
flow.Clear();
258265

259-
var req = new MapSetsRequest(offset, 48, currentQuery);
266+
var query = currentQuery;
267+
filterKeymode.ForEach(x => query += $" k={x}");
268+
269+
if (filterStatus.Count == 4)
270+
query += " s=a";
271+
else
272+
{
273+
filterStatus.ForEach(x => query += $" s={x switch {
274+
MapStatus.Unsubmitted => "u",
275+
MapStatus.Pending => "pen",
276+
MapStatus.Impure => "i",
277+
MapStatus.Pure => "p",
278+
_ => throw new ArgumentOutOfRangeException(nameof(x), x, null) }
279+
}");
280+
}
281+
282+
Logger.Log(query);
283+
284+
var req = new MapSetsRequest(offset, 48, query);
260285
req.Success += response =>
261286
{
262287
loadedAll = response.Data.Count == 0;

0 commit comments

Comments
 (0)