1414import com .cleanroommc .modularui .drawable .ItemDrawable ;
1515import com .cleanroommc .modularui .drawable .Rectangle ;
1616import com .cleanroommc .modularui .drawable .SpriteDrawable ;
17+ import com .cleanroommc .modularui .factory .ClientGUI ;
1718import com .cleanroommc .modularui .screen .CustomModularScreen ;
1819import com .cleanroommc .modularui .screen .ModularPanel ;
20+ import com .cleanroommc .modularui .screen .ModularScreen ;
1921import com .cleanroommc .modularui .screen .RichTooltip ;
2022import com .cleanroommc .modularui .screen .viewport .GuiContext ;
2123import com .cleanroommc .modularui .screen .viewport .ModularGuiContext ;
3739import com .cleanroommc .modularui .widget .Widget ;
3840import com .cleanroommc .modularui .widgets .ButtonWidget ;
3941import com .cleanroommc .modularui .widgets .ColorPickerDialog ;
40- import com .cleanroommc .modularui .widgets .CycleButtonWidget ;
4142import com .cleanroommc .modularui .widgets .ListWidget ;
4243import com .cleanroommc .modularui .widgets .RichTextWidget ;
4344import com .cleanroommc .modularui .widgets .SchemaWidget ;
6566import org .apache .commons .lang3 .tuple .Pair ;
6667import org .jetbrains .annotations .NotNull ;
6768
69+ import java .lang .reflect .InvocationTargetException ;
70+ import java .lang .reflect .Method ;
71+ import java .lang .reflect .Modifier ;
6872import java .util .ArrayList ;
6973import java .util .Arrays ;
74+ import java .util .Comparator ;
7075import java .util .List ;
7176import java .util .Random ;
7277import java .util .stream .IntStream ;
@@ -75,7 +80,46 @@ public class TestGuis extends CustomModularScreen {
7580
7681 @ Override
7782 public @ NotNull ModularPanel buildUI (ModularGuiContext context ) {
78- return buildColorUI (context );
83+
84+ // collect all test from all build methods in this class via reflection
85+ List <Method > uiMethods = new ArrayList <>();
86+ for (Method method : TestGuis .class .getDeclaredMethods ()) {
87+ if (!"buildUI" .equals (method .getName ()) && // exclude this method
88+ !Modifier .isStatic (method .getModifiers ()) &&
89+ Modifier .isPublic (method .getModifiers ()) &&
90+ ModularPanel .class .isAssignableFrom (method .getReturnType ()) &&
91+ method .getParameterCount () == 1 &&
92+ method .getParameterTypes ()[0 ] == ModularGuiContext .class ) {
93+ uiMethods .add (method );
94+ }
95+ }
96+ uiMethods .sort (Comparator .comparing (Method ::getName ));
97+
98+ return new ModularPanel ("client_tests" ).height (200 ).width (170 )
99+ .padding (7 )
100+ .child (Flow .column ()
101+ .child (IKey .str ("Client Test UIs" ).asWidget ().margin (1 ))
102+ .child (new ListWidget <>().widthRel (1f ).expanded ()
103+ .children (uiMethods .size (), i -> {
104+ Method m = uiMethods .get (i );
105+ String name = m .getName ();
106+ if (name .startsWith ("build" )) name = name .substring (5 );
107+ if (name .endsWith ("UI" )) name = name .substring (0 , name .length () - 2 );
108+ name = name .replaceAll ("([a-z])([A-Z])" , "$1 $2" );
109+ return new ButtonWidget <>()
110+ .height (16 )
111+ .widthRel (1f )
112+ .margin (0 , 1 )
113+ .overlay (IKey .str (name ))
114+ .onMousePressed (button -> {
115+ try {
116+ ClientGUI .open (new ModularScreen ((ModularPanel ) m .invoke (TestGuis .this , context )).openParentOnClose (true ));
117+ } catch (IllegalAccessException | InvocationTargetException e ) {
118+ ModularUI .LOGGER .throwing (e );
119+ }
120+ return true ;
121+ });
122+ })));
79123 }
80124
81125 public @ NotNull ModularPanel buildToggleGridListUI (ModularGuiContext context ) {
@@ -323,7 +367,7 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
323367 return panel ;
324368 }
325369
326- public ModularPanel buildListUi (ModularGuiContext context ) {
370+ public ModularPanel buildListUI (ModularGuiContext context ) {
327371 Random rnd = new Random ();
328372 return ModularPanel .defaultPanel ("list" , 100 , 150 )
329373 .padding (7 )
@@ -435,7 +479,6 @@ public ModularPanel buildListUi(ModularGuiContext context) {
435479 colorPicker1 .openPanel ();
436480 return true ;
437481 }))
438- .child (new CycleButtonWidget ())
439482 .child (new ButtonWidget <>()
440483 .debugName ("color picker button 2" )
441484 .background (color2 )
0 commit comments