88import com .cleanroommc .modularui .api .IThemeApi ;
99import com .cleanroommc .modularui .api .drawable .IDrawable ;
1010import com .cleanroommc .modularui .api .drawable .IKey ;
11+ import com .cleanroommc .modularui .api .layout .IViewportStack ;
1112import com .cleanroommc .modularui .api .widget .IWidget ;
1213import com .cleanroommc .modularui .drawable .GuiDraw ;
1314import com .cleanroommc .modularui .drawable .GuiTextures ;
4243import com .cleanroommc .modularui .widgets .ListWidget ;
4344import com .cleanroommc .modularui .widgets .RichTextWidget ;
4445import com .cleanroommc .modularui .widgets .SchemaWidget ;
45- import com .cleanroommc .modularui .widgets .SortableListWidget ;
4646import com .cleanroommc .modularui .widgets .TextWidget ;
4747import com .cleanroommc .modularui .widgets .ToggleButton ;
4848import com .cleanroommc .modularui .widgets .TransformWidget ;
@@ -80,16 +80,13 @@ public class TestGuis extends CustomModularScreen {
8080
8181 @ Override
8282 public @ NotNull ModularPanel buildUI (ModularGuiContext context ) {
83-
8483 // collect all test from all build methods in this class via reflection
8584 List <Method > uiMethods = new ArrayList <>();
8685 for (Method method : TestGuis .class .getDeclaredMethods ()) {
87- if (!"buildUI" .equals (method .getName ()) && // exclude this method
88- !Modifier .isStatic (method .getModifiers ()) &&
86+ if (Modifier .isStatic (method .getModifiers ()) &&
8987 Modifier .isPublic (method .getModifiers ()) &&
9088 ModularPanel .class .isAssignableFrom (method .getReturnType ()) &&
91- method .getParameterCount () == 1 &&
92- method .getParameterTypes ()[0 ] == ModularGuiContext .class ) {
89+ method .getParameterCount () == 0 ) {
9390 uiMethods .add (method );
9491 }
9592 }
@@ -106,27 +103,50 @@ public class TestGuis extends CustomModularScreen {
106103 if (name .startsWith ("build" )) name = name .substring (5 );
107104 if (name .endsWith ("UI" )) name = name .substring (0 , name .length () - 2 );
108105 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 ))
106+ return button (name )
114107 .onMousePressed (button -> {
115108 try {
116- ClientGUI .open (new ModularScreen ((ModularPanel ) m .invoke (TestGuis . this , context )).openParentOnClose (true ));
109+ ClientGUI .open (new ModularScreen ((ModularPanel ) m .invoke (null )).openParentOnClose (true ));
117110 } catch (IllegalAccessException | InvocationTargetException e ) {
118111 ModularUI .LOGGER .throwing (e );
119112 }
120113 return true ;
121114 });
122- })));
115+ })
116+ .child (button ("OpenGL test" )
117+ .onMousePressed (button -> {
118+ ClientGUI .open (new GLTestGui ().openParentOnClose (true ));
119+ return true ;
120+ }))
121+ .child (button ("Sortable List" )
122+ .onMousePressed (button -> {
123+ ClientGUI .open (new TestGui ().openParentOnClose (true ));
124+ return true ;
125+ }))
126+ .child (button ("Test self" )
127+ .onMousePressed (button -> {
128+ ClientGUI .open (this );
129+ return true ;
130+ }))));
131+ }
132+
133+ private static ButtonWidget <?> button (String text ) {
134+ return new ButtonWidget <>()
135+ .height (16 ).widthRel (1f ).margin (0 , 1 )
136+ .overlay (IKey .str (text ));
123137 }
124138
125- public @ NotNull ModularPanel buildToggleGridListUI (ModularGuiContext context ) {
126- useTheme (EventHandler .TEST_THEME );
139+ public static @ NotNull ModularPanel buildToggleGridListUI () {
127140 boolean [][] states = new boolean [4 ][16 ];
128- return new ModularPanel ("grid_list" )
129- .height (100 )
141+ // we need to do this to attach the theme since we have no screen yet
142+ // normally you have either UISettings or a ModularScreen at build to set it directly
143+ return new ModularPanel ("grid_list" ) {
144+ @ Override
145+ public void onInit () {
146+ super .onInit ();
147+ getScreen ().useTheme (EventHandler .TEST_THEME );
148+ }
149+ }.height (100 )
130150 .coverChildrenWidth ()
131151 .padding (7 )
132152 .child (new ListWidget <>()
@@ -146,7 +166,7 @@ public class TestGuis extends CustomModularScreen {
146166
147167 }
148168
149- public @ NotNull ModularPanel buildAnimationUI ( ModularGuiContext context ) {
169+ public static @ NotNull ModularPanel buildPendulumAnimationUI ( ) {
150170 IWidget widget = GuiTextures .MUI_LOGO .asWidget ().size (20 ).pos (65 , 65 );
151171 Animator animator = new Animator ()
152172 .bounds (0 , 1 )
@@ -161,13 +181,14 @@ public class TestGuis extends CustomModularScreen {
161181 .child (new TransformWidget ()
162182 .child (widget )
163183 .transform (stack -> {
164- float x = (float ) (55 * Math .cos (animator .getValue () * 2 * Math .PI - Math .PI / 2 ));
165- float y = (float ) (55 * Math .sin (animator .getValue () * 2 * Math .PI - Math .PI / 2 ));
184+ double angle = Math .PI ;
185+ float x = (float ) (55 * Math .cos (animator .getValue () * angle ));
186+ float y = (float ) (55 * Math .sin (animator .getValue () * angle ));
166187 stack .translate (x , y );
167188 }));
168189 }
169190
170- public @ NotNull ModularPanel buildPostTheLogAnimationUI (ModularGuiContext context ) {
191+ public static @ NotNull ModularPanel buildPostTheLogAnimationUI () {
171192 Animator post = new Animator ().curve (Interpolation .SINE_IN ).duration (300 ).bounds (-35 , 0 );
172193 Animator the = new Animator ().curve (Interpolation .SINE_IN ).duration (300 ).bounds (-20 , 0 );
173194 Animator fucking = new Animator ().curve (Interpolation .SINE_IN ).duration (300 ).bounds (53 , 0 );
@@ -216,7 +237,7 @@ public class TestGuis extends CustomModularScreen {
216237 })));
217238 }
218239
219- public @ NotNull ModularPanel buildSpriteAndEntityUI (ModularGuiContext context ) {
240+ public static @ NotNull ModularPanel buildSpriteAndEntityUI () {
220241 TextureAtlasSprite sprite = SpriteHelper .getSpriteOfBlockState (GameObjectHelper .getBlockState ("minecraft" , "command_block" ), EnumFacing .UP );
221242 // SpriteHelper.getSpriteOfItem(new ItemStack(Items.DIAMOND));
222243 Entity entity = FakeEntity .create (EntityDragon .class );
@@ -255,20 +276,7 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
255276 }.asWidget ().alignX (0.5f ).bottom (10 ).size (100 , 75 ));
256277 }
257278
258-
259- public @ NotNull ModularPanel buildSortableListUI (ModularGuiContext context ) {
260- List <String > things = new ArrayList <>();
261- for (int i = 0 ; i < 15 ; i ++) {
262- things .add ("Thing " + i );
263- }
264- return ModularPanel .defaultPanel ("main" )
265- .padding (7 )
266- .child (new SortableListWidget <String >()
267- .children (things , thing -> new SortableListWidget .Item <>(thing )
268- .overlay (IKey .str (thing ))));
269- }
270-
271- public @ NotNull ModularPanel buildRichTextUI (ModularGuiContext context ) {
279+ public static @ NotNull ModularPanel buildRichTextUI () {
272280 return new ModularPanel ("main" )
273281 .size (176 , 166 )
274282 .child (new RichTextWidget ()
@@ -320,7 +328,7 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
320328 ));
321329 }
322330
323- public @ NotNull ModularPanel buildWorldSchemeUI ( ModularGuiContext context ) {
331+ public static @ NotNull ModularPanel buildWorldSchemaUI ( ) {
324332 /*TrackedDummyWorld world = new TrackedDummyWorld();
325333 world.addBlock(new BlockPos(0, 0, 0), new BlockInfo(Blocks.DIAMOND_BLOCK.getDefaultState()));
326334 world.addBlock(new BlockPos(0, 1, 0), new BlockInfo(Blocks.BEDROCK.getDefaultState()));
@@ -367,7 +375,7 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
367375 return panel ;
368376 }
369377
370- public ModularPanel buildListUI ( ModularGuiContext context ) {
378+ public static ModularPanel buildCollapseDisabledChildrenUI ( ) {
371379 Random rnd = new Random ();
372380 return ModularPanel .defaultPanel ("list" , 100 , 150 )
373381 .padding (7 )
@@ -386,7 +394,7 @@ public ModularPanel buildListUI(ModularGuiContext context) {
386394 })));
387395 }
388396
389- public @ NotNull ModularPanel buildSearchTest (ModularGuiContext context ) {
397+ public static @ NotNull ModularPanel buildSearchTest () {
390398 List <String > items = Arrays .asList ("Chicken" , "Jockey" , "Flint" , "Steel" , "Steve" , "Diamond" , "Ingot" , "Iron" , "Armor" , "Greg" );
391399 StringValue searchValue = new StringValue ("" );
392400 return ModularPanel .defaultPanel ("search" , 100 , 150 )
@@ -409,7 +417,7 @@ public ModularPanel buildListUI(ModularGuiContext context) {
409417 .setEnabledIf (w -> items .get (i ).toLowerCase ().contains (searchValue .getStringValue ())))));
410418 }
411419
412- public @ NotNull ModularPanel buildColorUI ( ModularGuiContext context ) {
420+ public static @ NotNull ModularPanel buildColorTheoryUI ( ) {
413421 List <Pair <Integer , Float >> colors = new ArrayList <>();
414422 for (ColorShade shade : ColorShade .getAll ()) {
415423 for (int c : shade ) {
@@ -479,6 +487,7 @@ public ModularPanel buildListUI(ModularGuiContext context) {
479487 colorPicker1 .openPanel ();
480488 return true ;
481489 }))
490+ .child (IKey .str ("<-- Select colors -->" ).asWidget ())
482491 .child (new ButtonWidget <>()
483492 .debugName ("color picker button 2" )
484493 .background (color2 )
@@ -492,4 +501,41 @@ public ModularPanel buildListUI(ModularGuiContext context) {
492501 .child (IKey .str ("Gamma corrected gradient" ).asWidget ().margin (1 ))
493502 .child (correctedGradient .asWidget ().widthRel (1f ).height (10 )));
494503 }
504+
505+ public static @ NotNull ModularPanel buildViewportTransformUI (ModularGuiContext context ) {
506+ return new TestPanel ("test" )
507+ .child (new Widget <>()
508+ .align (Alignment .Center )
509+ .size (50 , 50 )
510+ .background (GuiTextures .BUTTON_CLEAN ));
511+ }
512+
513+ private static class TestPanel extends ModularPanel {
514+
515+ public TestPanel (String name ) {
516+ super (name );
517+ //background(GuiTextures.BACKGROUND);
518+ align (Alignment .Center ).size (100 , 100 );
519+ }
520+
521+ @ Override
522+ public void transform (IViewportStack stack ) {
523+ super .transform (stack );
524+ stack .translate (50 , 50 );
525+ // rotate with constant speed CW
526+ float angle = (float ) ((Minecraft .getSystemTime () % 4000 ) / 4000f * 2 * Math .PI );
527+ stack .rotateZ (angle );
528+
529+ // scale from 0.5 to 1 and back with curve
530+ float scale ;
531+ long t = Minecraft .getSystemTime () % 4000 ;
532+ if (t <= 2000 ) {
533+ scale = Interpolation .BACK_INOUT .interpolate (0.5f , 1f , t / 2000f );
534+ } else {
535+ scale = Interpolation .BACK_INOUT .interpolate (0.5f , 1f , (2000 - t + 2000 ) / 2000f );
536+ }
537+ stack .scale (scale , scale );
538+ stack .translate (-50 , -50 );
539+ }
540+ }
495541}
0 commit comments