Create Layouts
Overview
Layouts allow you to control the position of elements. A layout can have multiple elements, and each element can be configured with images, text, text backgrounds, or progress bars.
Configuration Path
All layout files are located in the Xerr/core/layout
directory. You can create subdirectories under this directory to categorize them.
Configuration Rules
A configuration can have multiple layouts, and each layout can have multiple elements.
For example:
Element Positioning
Keep it simple!
You can control the position of elements, whether vertical or horizontal, including images, text, backgrounds, or progress bars. All these can be adjusted within the layout.
Basic Positioning
By default, elements are displayed at the center. You can select positions like top-left, top-right, bottom-left, bottom-right, etc., by setting the position
attribute.
Enum | Position |
---|---|
LEFT_TOP left_top | Top-left |
LEFT_BOTTOM left_bottom | Bottom-left |
RIGHT_TOP right_top | Top-right |
RIGHT_BOTTOM right_bottom | Bottom-right |
CENTER center | Center |
CENTER_LEFT center_left | Center-left |
CENTER_RIGHT center_right | Center-right |
CENTER_TOP center_top | Center-top |
CENTER_BOTTOM center_bottom | Center-bottom |
Coordinate Positioning
The X
coordinate controls the horizontal position, and the Y
coordinate controls the vertical position.
For the X
axis, you can use negative values to move left and positive values to move right.
For the Y
axis, you can use negative values to move down and positive values to move up.
The value of the Y
axis cannot exceed the image's height, or it will display incorrectly.
Adding Elements
You can add text, text backgrounds, graphics, and image progress bars as elements.
Adding Text
The corresponding font file would be:
Adding Graphics
Header Settings
You may be thinking, "Do I need to write the same font
, namespace
, and basename
for each element?"
Of course, it's tedious and redundant in most cases. That's why we provide header settings through the option
.
Default Font Namespace
Once you set the default font, the text in the elements will use this font by default. Likewise, the images and image progress bars will use the default graphic namespace and basename.
The layout id cannot use option
as its name.
Overriding the Default Font
You can override the default font in an element.
Step-by-Step Tutorial
Adding a Graphic
A 256x128 image, named ui.png
, is added to plugins/Xerr/core/assets/image/dialog_ui/dialog/textures/
.
Configure the Graphic
Create and Edit the Layout
Create a layout file plugins/Xerr/core/layout/test.yaml
.
According to the configuration in plugins/Xerr/core/assets/image/dialog_ui/dialog/config.yml
:
dialog_ui
is the graphic namespacedialog
is the graphic configuration file namefram_ui
is the graphic id
Preview the Effect
You can add the following content to the BossBar layout display configuration:
Run the following command to reload the configuration and generate the resource pack. After loading, you can preview the effect:
Moving the Position
You can move the graphic position by adjusting the x
and y
properties.
To center it, calculate width / 2
, which means 256 / 2 = 128
.
Create Custom Progress Bar Layouts
Highly customizable progress bars for any shape.
Add Graphics
- Multiple progress bar graphics
- Example namespace:
hud
- Example basename:
exp
Place all graphics in plugins/Xerrcore/assets/image/hud/exp/textures/
Configure Graphics
Create and Edit Layout
Display in Bossbar
Create Standard Progress Bar Layout
Add Graphics
- 16x16 full icon named
full_icon.png
- 16x16 empty icon named
empty_icon.png
- Example namespace:
hud
- Example basename:
health
Place all graphics in plugins/Xerrcore/assets/image/hud/health/textures/