1111import com .cope .meteoraddons .util .VersionUtil ;
1212import meteordevelopment .meteorclient .gui .GuiTheme ;
1313import meteordevelopment .meteorclient .gui .WindowScreen ;
14+ import meteordevelopment .meteorclient .gui .widgets .containers .WContainer ;
1415import meteordevelopment .meteorclient .gui .widgets .containers .WHorizontalList ;
1516import meteordevelopment .meteorclient .gui .widgets .containers .WTable ;
1617import meteordevelopment .meteorclient .gui .widgets .containers .WVerticalList ;
18+ import meteordevelopment .meteorclient .gui .widgets .input .WTextBox ;
1719import meteordevelopment .meteorclient .gui .widgets .pressable .WButton ;
1820import meteordevelopment .meteorclient .renderer .Texture ;
1921import net .minecraft .util .Util ;
2022
2123import java .util .List ;
24+ import java .util .Locale ;
25+ import java .util .stream .Collectors ;
2226
2327import static meteordevelopment .meteorclient .MeteorClient .mc ;
2428import static meteordevelopment .meteorclient .utils .Utils .getWindowWidth ;
2529
2630public class BrowseAddonsScreen extends WindowScreen {
2731 private static final int CARDS_PER_ROW = 4 ;
2832 private boolean isGridView = false ;
33+ private WContainer contentContainer ;
34+ private WTextBox searchField ;
35+ private String currentSearch = "" ;
2936
3037 public BrowseAddonsScreen (GuiTheme theme ) {
3138 super (theme , "Browse Addons" );
@@ -62,27 +69,111 @@ public void initWidgets() {
6269 return ;
6370 }
6471
72+ // Toolbar: Search + View Toggle
6573 WHorizontalList toolbar = add (theme .horizontalList ()).expandX ().widget ();
66- toolbar .add (theme .label (addons .size () + " addons" ));
67- toolbar .add (theme .horizontalList ()).expandX ();
68-
74+
75+ // Search Bar
76+ searchField = toolbar .add (theme .textBox (currentSearch )).minWidth (200 ).expandX ().widget ();
77+ searchField .setFocused (true );
78+ searchField .action = () -> {
79+ currentSearch = searchField .get ();
80+ updateContent (manager .getOnlineAddons ());
81+ };
82+
83+ // View Toggles
84+ toolbar .add (theme .horizontalList ()).expandX (); // Spacer
85+
6986 WButton listBtn = toolbar .add (theme .button (isGridView ? "List" : "[List]" )).widget ();
70- listBtn .action = () -> { isGridView = false ; reload (); };
87+ listBtn .action = () -> {
88+ isGridView = false ;
89+ reload ();
90+ };
7191
7292 WButton gridBtn = toolbar .add (theme .button (isGridView ? "[Grid]" : "Grid" )).widget ();
73- gridBtn .action = () -> { isGridView = true ; reload (); };
93+ gridBtn .action = () -> {
94+ isGridView = true ;
95+ reload ();
96+ };
7497
7598 add (theme .horizontalSeparator ()).expandX ();
7699
100+ // Content Container
101+ contentContainer = add (theme .verticalList ()).expandX ().widget ();
102+ updateContent (addons );
103+ }
104+
105+ private void updateContent (List <Addon > allAddons ) {
106+ contentContainer .clear ();
107+
108+ List <Addon > filtered = allAddons .stream ()
109+ .filter (addon -> matchesSearch (addon , currentSearch ))
110+ .collect (Collectors .toList ());
111+
112+ if (filtered .isEmpty ()) {
113+ contentContainer .add (theme .label ("No addons match your search." )).centerX ();
114+ return ;
115+ }
116+
77117 if (isGridView ) {
78- initGridView (addons );
118+ initGridView (contentContainer , filtered );
79119 } else {
80- initListView (addons );
120+ initListView (contentContainer , filtered );
81121 }
82122 }
83123
84- private void initGridView (List <Addon > addons ) {
85- WTable table = add (theme .table ()).expandX ().widget ();
124+ private boolean matchesSearch (Addon addon , String query ) {
125+ if (query == null || query .isEmpty ()) return true ;
126+ String q = query .toLowerCase (Locale .ROOT );
127+
128+ // Name
129+ if (addon .getName ().toLowerCase (Locale .ROOT ).contains (q )) return true ;
130+
131+ // Description
132+ if (addon .getDescription ().isPresent () && addon .getDescription ().get ().toLowerCase (Locale .ROOT ).contains (q )) return true ;
133+
134+ // Author
135+ if (addon .getAuthors () != null ) {
136+ for (String author : addon .getAuthors ()) {
137+ if (author .toLowerCase (Locale .ROOT ).contains (q )) return true ;
138+ }
139+ }
140+
141+ // Metadata Deep Search
142+ if (addon instanceof OnlineAddon ) {
143+ AddonMetadata meta = ((OnlineAddon ) addon ).getMetadata ();
144+ if (meta != null ) {
145+ // Modules
146+ if (meta .features != null && meta .features .modules != null ) {
147+ for (String module : meta .features .modules ) {
148+ if (module .toLowerCase (Locale .ROOT ).contains (q )) return true ;
149+ }
150+ }
151+ // Commands
152+ if (meta .features != null && meta .features .commands != null ) {
153+ for (String cmd : meta .features .commands ) {
154+ if (cmd .toLowerCase (Locale .ROOT ).contains (q )) return true ;
155+ }
156+ }
157+ // Custom Screens
158+ if (meta .features != null && meta .features .custom_screens != null ) {
159+ for (String screen : meta .features .custom_screens ) {
160+ if (screen .toLowerCase (Locale .ROOT ).contains (q )) return true ;
161+ }
162+ }
163+ // Custom Tags (e.g. "qol", "pvp")
164+ if (meta .custom != null && meta .custom .tags != null ) {
165+ for (String tag : meta .custom .tags ) {
166+ if (tag .toLowerCase (Locale .ROOT ).contains (q )) return true ;
167+ }
168+ }
169+ }
170+ }
171+
172+ return false ;
173+ }
174+
175+ private void initGridView (WContainer parent , List <Addon > addons ) {
176+ WTable table = parent .add (theme .table ()).expandX ().widget ();
86177 int col = 0 ;
87178 for (Addon addon : addons ) {
88179 table .add (new WAddonCard (addon , () -> mc .setScreen (new AddonDetailScreen (theme , addon , this ))));
@@ -94,8 +185,8 @@ private void initGridView(List<Addon> addons) {
94185 }
95186 }
96187
97- private void initListView (List <Addon > addons ) {
98- WVerticalList list = add (theme .verticalList ()).expandX ().widget ();
188+ private void initListView (WContainer parent , List <Addon > addons ) {
189+ WVerticalList list = parent . add (theme .verticalList ()).expandX ().widget ();
99190
100191 for (int i = 0 ; i < addons .size (); i ++) {
101192 Addon addon = addons .get (i );
0 commit comments