44using fluXis . Graphics . UserInterface . Color ;
55using fluXis . Graphics . UserInterface . Interaction ;
66using osu . Framework . Allocation ;
7+ using osu . Framework . Bindables ;
78using osu . Framework . Extensions . IEnumerableExtensions ;
89using osu . Framework . Graphics ;
910using osu . Framework . Graphics . Containers ;
@@ -16,7 +17,7 @@ namespace fluXis.Overlay.Browse;
1617
1718public 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 }
0 commit comments