Skip to content

Themes

IMPORTANT

Themes can only be registered for GUIs made with ModularUI.

Reloading themes

You can reload themes by either reloading resources (which is slow) or by running the /reloadThemes command.

For mod developers

Registering themes

First create a ThemeBuilder instance. This will be your theme data. Feel free to extend the class for additional helpers. The class is just a json wrapper. Next you need to register it. Make sure to do that before resource packs are loaded (that's when themes gets loaded and parsed). FMLPreInit works fine.

java
ThemeBuilder<?> myTheme = new ThemeBuilder<>("mymodid:my_theme");
IThemeApi.get().registerTheme(myTheme);

It is not required to have the mod id in the name, but it will help identifying the theme and having a unique name. Multiple themes with the same name can be registered. Themes that are added later will override all properties of all previously registered themes.

You can edit the theme before and after you registered it. Just make sure it's before the themes are loaded. If you are unsure you can use the ReloadThemeEvent.Pre.

Applying a theme to a GUI

There are two ways to set a theme in a GUI.

  1. IThemeApi.get().registerThemeForScreen(String screenOwner, String mainPanelName, String themeName) This method can be used at any point. Registering another theme with the same screen name will overwrite the old one.
  2. Setting it directly in the screen: new ModularScreen(...).useTheme(String themeName) (can also be called in build method of a CustomModularScreen)

If both methods are used, the first will always take priority.

Checkout this page to find out what properties you can add to the builder.

Registering widget themes

Call IThemeAPI.get().registerWidgetTheme(String id, T defaultTheme, T defaultHoverTheme, WidgetThemeParser<T> parser) or use the builder with IThemeAPI.get().widgetThemeKeyBuilder(String id, Class<T> type). These methods return a WidgetThemeKey<T>. You should store it somewhere to be accessible everywhere, anytime.

Warning

You should include your mods id in the id otherwise your mod will be incompatible with mods who register a widget theme with the same id. Also note that you can't use colon (:) in the id since it's reserved for sub widget themes. You can use -, _ or $ to prefix your mod id.

For sub widget themes simply call any overload of widgetThemeKey.createSubKey(String subName, @Nullable T defaultValue, @Nullable T defaultHoverValue). widgetThemeKey will be the parent of the new sub theme.

For resource packs

First create new file in your resource pack at assets/modularui/themes.json. You can replace modularui with any loaded mod id here. In this file you will define themes and where they are located as well as setting themes for GUIs.

Let's look at the themes.json file that is shipped with ModularUI.

json
{
  "vanilla": "modularui:vanilla",
  "vanilla_dark": "modularui:vanilla_dark",
  "screens": {
    "modularui:test": "vanilla_dark"
  }
}

Registering themes

The first line is "vanilla": "modularui:vanilla". vanilla is the name of the theme and modularui:vanilla is the path to the theme file. This means the theme file for vanilla should be at assets/modularui/themes/vanilla.json. The next line defines a new theme with the name vanilla_dark with the theme file located at assets/modularui/themes/vanilla_dark.json.

Applying a theme to a GUI

Let's look at the next line: "screens": {}

Inside the curly brackets we can set themes for screens. The format is "screen_owner:main_panel_name": "theme_name". So in the example above modularui:test the full screen name and vanilla_dark is the theme name (which we defined before).

Checkout this page to find out how to write themes.

Contributors

© 2024 CleanroomMC. All Rights Reserved.