DynamicHUD Dev Guide
DownloadNeed Support?
  • Dynamic HUD
  • Import using Gradle
  • Integrating DynamicHUD
    • Integrating DynamicHUD
    • Adding Widgets
    • Adding your own WidgetRenderer
    • Passing AbstractMoveableScreen instance
    • Changing default key bind
    • Changing save and load file
    • Registering Custom Widgets
  • Widget
    • Widget class
    • How to create a custom widget
    • Widget Renderer
    • WidgetData
    • DynamicValueRegistry
    • Scaling
  • Screens
    • AbstractMoveableScreen
  • ContextMenu
    • ContextMenu class
    • Using context menu
    • Option<T> class
      • Color Option
      • Boolean Option
      • Double Option
      • Runnable Option
      • Enum Option
      • List Option
      • SubMenu Option
Powered by GitBook
On this page

Was this helpful?

  1. Integrating DynamicHUD

Adding your own WidgetRenderer

PreviousAdding WidgetsNextPassing AbstractMoveableScreen instance

Last updated 7 months ago

Was this helpful?

Now, we need to define a custom widget renderer object which will be passed to dynamicHUD. This object is an instance of which contains a list of all widgets to render on screens and manage per mod.

public class MyIntegration implements DynamicHudIntegration{
    TextWidget exampleWidget;
    WidgetRenderer renderer;
    
    @Override
    public void init() {
       //Previously added and initialised text widget
    }

    @Override
    public void addWidgets() {
       //Previously added and initialised text widget
    }
    
    //This method is called after the `addWidgets()` method.
    public void initAfter() {
        //Returns a list of widgets which have the mod id as MyMod.MOD_ID
        List<Widget> widgets = WidgetManager.getWidgetsForMod(MyMod.MOD_ID);
        
        //Create a widgetRenderer with the recieved widgets.
        renderer = new WidgetRenderer(widgets);
        
        /*
          Alternatively you could also use this:
           renderer = new WidgetRenderer(new ArrayList<>());
           renderer.addWidget(exampleWidget);
            
          Though this method is suggested to only be used when you want 
          specific widgets to be rendered instead of all. 
        */
        
        //Render widgets in the game hud (i.e. when a player is in a world)
        renderer.shouldRenderInGameHud(true);
        
        //Add screens to render your widgets in.
        //The default is the GameMenuScreen.class (or the pause menu).
        
        //Add screens to also render the widgets in.
        //Eg:
        renderer.addScreen(TitleScreen.class);
    }

    @Override
    public WidgetRenderer getWidgetRenderer() {
        return renderer;
    }
    
    @Override
    public AbstractMoveableScreen getMovableScreen() {
        return null /*Check the next page for this implementation*/;
    }
}
WidgetRenderer