3737import java .util .function .Function ;
3838
3939/**
40- * This is the base class for all modular ui's . It only exists on client side.
40+ * This is the base class for all modular UIs . It only exists on client side.
4141 * It handles drawing the screen, all panels and widget interactions.
4242 */
4343@ SideOnly (Side .CLIENT )
@@ -128,6 +128,11 @@ ModularPanel buildUI(ModularGuiContext context) {
128128 throw new UnsupportedOperationException ();
129129 }
130130
131+ /**
132+ * Should be called in custom {@link GuiScreen GuiScreen} constructors which implement {@link IMuiScreen}.
133+ *
134+ * @param wrapper the gui screen wrapping this screen
135+ */
131136 @ MustBeInvokedByOverriders
132137 public void construct (IMuiScreen wrapper ) {
133138 if (this .screenWrapper != null ) throw new IllegalStateException ("ModularScreen is already constructed!" );
@@ -149,6 +154,15 @@ public void constructOverlay(GuiScreen screen) {
149154 this .overlay = true ;
150155 }
151156
157+ /**
158+ * Called everytime the Game window changes its size. Overriding for additional logic is allowed, but super must be called.
159+ * This method resizes the entire widget tree of every panel currently open and then updates the size of the {@link IMuiScreen} wrapper.
160+ * <p>
161+ * Do not call this method except in an override!
162+ *
163+ * @param width with of the resized game window
164+ * @param height height of the resized game window
165+ */
152166 @ MustBeInvokedByOverriders
153167 public void onResize (int width , int height ) {
154168 this .context .updateScreenArea (width , height );
@@ -234,13 +248,22 @@ public boolean isPanelOpen(ModularPanel panel) {
234248 return this .panelManager .hasOpenPanel (panel );
235249 }
236250
251+ /**
252+ * Called at the start of every client tick (20 times per second).
253+ */
237254 @ MustBeInvokedByOverriders
238255 public void onUpdate () {
239256 for (ModularPanel panel : this .panelManager .getOpenPanels ()) {
240257 WidgetTree .onUpdate (panel );
241258 }
242259 }
243260
261+ /**
262+ * Called 60 times per second in custom ticks. This logic is separate from rendering.
263+ *
264+ * @deprecated logic may be moved to rendering
265+ */
266+ @ Deprecated
244267 @ MustBeInvokedByOverriders
245268 public void onFrameUpdate () {
246269 this .panelManager .checkDirty ();
@@ -255,7 +278,12 @@ public void onFrameUpdate() {
255278 this .context .onFrameUpdate ();
256279 }
257280
258- public void drawScreen (int mouseX , int mouseY , float partialTicks ) {
281+ /**
282+ * Draws this screen and all open panels with their whole widget tree.
283+ * <p>
284+ * Do not call, only override!
285+ */
286+ public void drawScreen () {
259287 GlStateManager .disableRescaleNormal ();
260288 RenderHelper .disableStandardItemLighting ();
261289 GlStateManager .disableLighting ();
@@ -281,7 +309,12 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
281309 GlStateManager .enableAlpha ();
282310 }
283311
284- public void drawForeground (float partialTicks ) {
312+ /**
313+ * Called after all panels with their whole widget trees and potential additional elements are drawn.
314+ * <p>
315+ * Do not call, only override!
316+ */
317+ public void drawForeground () {
285318 GlStateManager .disableRescaleNormal ();
286319 RenderHelper .disableStandardItemLighting ();
287320 GlStateManager .disableLighting ();
@@ -304,7 +337,11 @@ public void drawForeground(float partialTicks) {
304337 GlStateManager .enableAlpha ();
305338 }
306339
307- public boolean handleDraggableInput (int button , boolean pressed ) {
340+ /**
341+ * Called when a mouse button is pressed or released. Used to handle dropping of currently dragged elements.
342+ */
343+ @ ApiStatus .Internal
344+ public final boolean onMouseInputPre (int button , boolean pressed ) {
308345 if (this .context .hasDraggable ()) {
309346 if (pressed ) {
310347 this .context .onMousePressed (button );
@@ -316,6 +353,15 @@ public boolean handleDraggableInput(int button, boolean pressed) {
316353 return false ;
317354 }
318355
356+ /**
357+ * Called when a mouse button is pressed. Tries to invoke
358+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onMousePressed(int) Interactable#onMousePressed(int)} on every widget under
359+ * the mouse after gui action listeners have been called. Will try to focus widgets that have been interacted with.
360+ * Focused widgets will be interacted with first in other interaction methods (mouse scroll, release and drag, key press and release).
361+ *
362+ * @param mouseButton mouse button (0 = left button, 1 = right button, 2 = scroll button, 4 and 5 = side buttons)
363+ * @return true if the action was consumed and further processing should be canceled
364+ */
319365 public boolean onMousePressed (int mouseButton ) {
320366 for (IGuiAction .MousePressed action : getGuiActionListeners (IGuiAction .MousePressed .class )) {
321367 action .press (mouseButton );
@@ -334,6 +380,14 @@ public boolean onMousePressed(int mouseButton) {
334380 return false ;
335381 }
336382
383+ /**
384+ * Called when a mouse button is released. Tries to invoke
385+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onMouseRelease(int) Interactable#onMouseRelease(int)} on every widget under
386+ * the mouse after gui action listeners have been called.
387+ *
388+ * @param mouseButton mouse button (0 = left button, 1 = right button, 2 = scroll button, 4 and 5 = side buttons)
389+ * @return true if the action was consumed and further processing should be canceled
390+ */
337391 public boolean onMouseRelease (int mouseButton ) {
338392 for (IGuiAction .MouseReleased action : getGuiActionListeners (IGuiAction .MouseReleased .class )) {
339393 action .release (mouseButton );
@@ -352,6 +406,15 @@ public boolean onMouseRelease(int mouseButton) {
352406 return false ;
353407 }
354408
409+ /**
410+ * Called when a keyboard key is pressed. Tries to invoke
411+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onKeyPressed(char, int) Interactable#onKeyPressed(char, int)} on every
412+ * widget under the mouse after gui action listeners have been called.
413+ *
414+ * @param typedChar the character of the pressed key or {@link Character#MIN_VALUE} for keys without a character
415+ * @param keyCode the key code of the pressed key (see constants at {@link org.lwjgl.input.Keyboard})
416+ * @return true if the action was consumed and further processing should be canceled
417+ */
355418 public boolean onKeyPressed (char typedChar , int keyCode ) {
356419 for (IGuiAction .KeyPressed action : getGuiActionListeners (IGuiAction .KeyPressed .class )) {
357420 action .press (typedChar , keyCode );
@@ -367,6 +430,15 @@ public boolean onKeyPressed(char typedChar, int keyCode) {
367430 return false ;
368431 }
369432
433+ /**
434+ * Called when a keyboard key is released. Tries to invoke
435+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onKeyRelease(char, int) Interactable#onKeyRelease(char, int)} on every
436+ * widget under the mouse after gui action listeners have been called.
437+ *
438+ * @param typedChar the character of the released key or {@link Character#MIN_VALUE} for keys without a character
439+ * @param keyCode the key code of the released key (see constants at {@link org.lwjgl.input.Keyboard})
440+ * @return true if the action was consumed and further processing should be canceled
441+ */
370442 public boolean onKeyRelease (char typedChar , int keyCode ) {
371443 for (IGuiAction .KeyReleased action : getGuiActionListeners (IGuiAction .KeyReleased .class )) {
372444 action .release (typedChar , keyCode );
@@ -382,6 +454,16 @@ public boolean onKeyRelease(char typedChar, int keyCode) {
382454 return false ;
383455 }
384456
457+ /**
458+ * Called when a mouse button is released. Tries to invoke
459+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onMouseScroll(UpOrDown, int) Interactable#onMouseScroll(UpOrDown,int)} on every widget under
460+ * the mouse after gui action listeners have been called.
461+ *
462+ * @param scrollDirection the direction of the scroll
463+ * @param amount the amount that has been scrolled. This value will always be > 0. It is not recommended to use this value to determine
464+ * scroll speed
465+ * @return true if the action was consumed and further processing should be canceled
466+ */
385467 public boolean onMouseScroll (UpOrDown scrollDirection , int amount ) {
386468 for (IGuiAction .MouseScroll action : getGuiActionListeners (IGuiAction .MouseScroll .class )) {
387469 action .scroll (scrollDirection , amount );
@@ -397,6 +479,15 @@ public boolean onMouseScroll(UpOrDown scrollDirection, int amount) {
397479 return false ;
398480 }
399481
482+ /**
483+ * Called every time the mouse pos changes and a mouse button is held down. Invokes
484+ * {@link com.cleanroommc.modularui.api.widget.Interactable#onMouseDrag(int, long) Interactable#onMouseDrag(int,long)} on every widget
485+ * under the mouse after gui action listeners have been called.
486+ *
487+ * @param mouseButton mouse button that is held down (0 = left button, 1 = right button, 2 = scroll button, 4 and 5 = side buttons)
488+ * @param timeSinceClick how long the button has been held down until now in milliseconds
489+ * @return true if the action was consumed and further processing should be canceled
490+ */
400491 public boolean onMouseDrag (int mouseButton , long timeSinceClick ) {
401492 for (IGuiAction .MouseDrag action : getGuiActionListeners (IGuiAction .MouseDrag .class )) {
402493 action .drag (mouseButton , timeSinceClick );
@@ -412,29 +503,59 @@ public boolean onMouseDrag(int mouseButton, long timeSinceClick) {
412503 return false ;
413504 }
414505
506+ /**
507+ * Called with {@code true} after a widget which implements {@link com.cleanroommc.modularui.api.widget.IFocusedWidget IFocusedWidget}
508+ * has consumed a mouse press and called with {@code false} if a widget is currently focused and anything else has consumed a mouse
509+ * press. This is required for other mods like JEI/NEI to not interfere with inputs.
510+ *
511+ * @param focus true if the gui screen will be focused
512+ */
415513 @ ApiStatus .Internal
416514 public void setFocused (boolean focus ) {
417515 this .screenWrapper .setFocused (focus );
418516 }
419517
518+ /**
519+ * @return true if this screen is currently open and displayed on the screen
520+ */
420521 public boolean isActive () {
421522 return getCurrent () == this ;
422523 }
423524
525+ /**
526+ * The owner of this screen. Usually a modid. This is mainly used to find theme overrides.
527+ *
528+ * @return owner of this screen
529+ */
424530 @ NotNull
425531 public String getOwner () {
426532 return this .owner ;
427533 }
428534
535+ /**
536+ * The name of this screen, which is also the name of the panel. Every UI under one owner should have a different name.
537+ * Unfortunately there is no good way to verify this, so it's the UI implementors responsibility to set a proper name for the main panel.
538+ * This is mainly used to find theme overrides.
539+ *
540+ * @return name of this screen
541+ */
429542 @ NotNull
430543 public String getName () {
431544 return this .name ;
432545 }
433546
547+ /**
548+ * @return the owner and name as a {@link ResourceLocation}
549+ * @see #getOwner()
550+ * @see #getName()
551+ */
434552 public ResourceLocation getResourceLocation () {
435553 return new ResourceLocation (this .owner , this .name );
436554 }
437555
556+ /**
557+ * @return true if this is an overlay for another screen
558+ */
438559 public boolean isOverlay () {
439560 return overlay ;
440561 }
@@ -565,16 +686,31 @@ public ITheme getCurrentTheme() {
565686 return this .currentTheme ;
566687 }
567688
689+ /**
690+ * Tries to use a specific theme for this screen. If the theme for this screen has been overriden via resource packs, this method does
691+ * nothing.
692+ *
693+ * @param theme id of theme to use
694+ * @return this for builder like usage
695+ */
568696 public ModularScreen useTheme (String theme ) {
569697 this .currentTheme = IThemeApi .get ().getThemeForScreen (this , theme );
570698 return this ;
571699 }
572700
701+ /**
702+ * Sets if the gui should pause the game in the background. Pausing means every ticking will halt. If the client is connected to a
703+ * dedicated server the UI will NEVER pause the game.
704+ *
705+ * @param pausesGame true if the ui should pause the game in the background.
706+ * @return this for builder like usage
707+ */
573708 public ModularScreen pausesGame (boolean pausesGame ) {
574709 this .pausesGame = pausesGame ;
575710 return this ;
576711 }
577712
713+ // TODO move this to a more appropriate place
578714 public enum UpOrDown {
579715 UP (1 ), DOWN (-1 );
580716
0 commit comments