Repository navigation
Display Feature
Here you will learn how the display feature is organized
The DisplayRenderer serves as the primary component in the drawing hierarchy. It is responsible for managing the rendering process of a DisplayCanvas, which is attached to the renderer. The DisplayRenderer not only handles the canvas but also manages the associated DisplayData and a list of DisplayTrigger objects.
Moreover, the DisplayRenderer implements the InjectablePlaceholderList, enabling the injection of placeholders for use within the canvas.
The DisplayRenderer offers versatility in its rendering contexts. It can be rendered in various environments, including the BaseScreen, in the HUD, or through manual invocation. Further details on these rendering contexts will be provided subsequently.
The DisplayCanvas class, a subclass of DisplayElement, maintains a list of DisplayElements. It controls how the elements are displayed.
The DisplayElement is the foundation of all elements that are displayed on screen.
It contains the base variables and methods
The DisplayManager registers all display element templates, trigger templates, and actions (details on actions to be discussed later). This class is also the central hub for managing the HUD canvas and all active canvases linked to renderers. Future updates may transition from managing active canvases to focusing on renderers.
Templates for elements and triggers are essentially pre-defined implementations without any data or the canvases, which are loaded from config objects with default data. To utilize these templates, you need first obtain a clone from the DisplayManager, then apply data from a configuration file using the updateVariables(Config conf) method. This process readies the element for use.
An important aspect of the display feature is its independence from Minecraft's scaleFactor and texture size limitations. This feature is designed to circumvent these restrictions. However, to manage resolution changes, the number of available resolutions (or window sizes) is restricted. These resolutions can be set in the game settings. Additionally, the system allows for the optimization of display element variables for specific resolutions, ensuring adaptability across different screen sizes.
More in-depth information on resolution handling will be provided in later sections.
Now, after understanding the structure, you can practice a little bit and make the simpliest gui screen.
- First, create the test.json in your resources(on the top, so, not in assets or any other folder)
And copy the json from here
Then, in your main class create the config object attached to the created file. If you dont know how, read the WIKI section about configs.
Once you've got a config object, you can compile and register canvas template:
//It basically clones and updates variables of the template elements that are specified in config
//This object can be used as a template with a default data.
DisplayElement element = getDisplayManager().getElementRegistry().compileCanvasTemplate(id,config); // for an id u can use test, or whatever you like
//Register to later access the template
getDisplayManager().getElementRegistry().registerTemplate(id, element);
Nice! Last step left. You need to draw it somewhere. The most simple way is to draw it on GuiScreen.
Lets override the MainMenu screen of the Minecraft:
@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event){
if(event.getGui() instanceof GuiMainMenu){
event.setGui(
new BaseScreen(this,
getDisplayManager().getElementRegistry().getDrawableCanvas("yourCanvasId") //returns the cloned canvas template, ready to use
);
);
}
}
Don't forget to register the class where u put it in Forge EVENT_BUS:
MinecraftForge.EVENT_BUS.register(this)
Its ready to be tested! You should see the cute cat and text in main menu
Now, I highly suggest you to play around the settings.
Tip: Once you made changes to config you can press Shift+S to reload the currently active DisplayRenderer.
If it doesnt work, change the debug state of the AtumMod to true
Here, you can find the list of the settings you can use. But before we move to that, one thing requires clarification.
There are the Base settings and Element settings. The difference between them is in what config section they can be setted up.
The Base settings are setuped in root section of an element. The Element settings are setuped in a "settings" subsection
Besides looking for settings options here, alternatively you can find them by looking at updateElementVariable() and updateBaseVariables() methods
- "template": "template-id-to-use"
- "layer": "the-layer-to-use" //More info here
- "posX": 1
- "posY": 1
- "width": 100
- "height": 100
- "fixRatio": true/false //Affects on different screen sizes //optional, default: false
- "outline": {"color": "RGB", "size": 3 } //draws an outline around the element //optional
- FOR CANVAS: "elements": { }
- "image": "write-path-to-resource" OR "playerSkin" OR "heldItem" //required
- "color": "RGB" //optional
- "textureX": 0 OR the position in texture u want to draw //optional
- "textureY": 0 OR the position in texture u want to draw //optional
- "textureWidth": 0 OR the width of the part of texture u want to draw //optional
- "textureHeight": 0 OR the height of the part of texture u want to draw //optional
- "font": "font path" //currently supported fonts here, I'll later update this to allow more options to choose from
- "fontSize": integer value, default is 25
- "text": "your_text_here" //if you want to add colors, use minecraft color codes. Unfortunately, rgb colors not yet implemented here
- "image": "write-path-to-resource"
- "brightness": 1.0;1.0;1.0 - more number, brighter it will be //kinda weird i know, it literally the color, from openGL, should be renamed
- "brightness-onHover": 0.8.0.8,0.8
- "brightness-onClick": 0.8.0.8,0.8
- "textureX": 0 OR the position in texture u want to draw //optional
- "textureY": 0 OR the position in texture u want to draw //optional
- "textureWidth": 0 OR the width of the part of texture u want to draw //optional
- "textureHeight": 0 OR the height of the part of texture u want to draw //optional
- "actions-onPress"{ListOfActions}
- "actions-onRelease"{ListOfActions}
Example for actions: "actions-onRelease": { "1": "open_link@https://google.com" }
- "color-filled": "RGB"
- "color-empty": "RGB"
- "progress-expression": "your expression" //Supports placeholders