Class Theme

java.lang.Object
dev.myriadclient.api.ui.Theme
All Implemented Interfaces:
Identified

public final class Theme extends Object implements Identified
A theme preset: applying it writes values into the live ThemeSettings (anything it doesn't set keeps Myriad's default). Players can edit a preset; their edits are saved on top of it. Register one with AddonContext.registerTheme; it shows in the Theme window, and Ui.applyTheme(MyriadId) applies it.
ctx.registerTheme(new Theme(ctx.id("sunset"), "Sunset", t -> ThemePalette.of(...).apply(t)));
Optional extras for themes that come from outside the game, like a system theme: live (re-apply when it changes), notice (explain a problem in the Theme panel), aliases (old ids it replaces) and preferOnFirstRun.
  • Constructor Details

    • Theme

      public Theme(MyriadId id, String name, Consumer<ThemeSettings> apply)
      Parameters:
      id - its registry id, also what saved choices refer to
      name - the name players see
      apply - writes the preset's values into the theme; it runs after every theme value was reset to Myriad's default, and before the player's own edits are put back on top
  • Method Details

    • id

      public MyriadId id()
      Description copied from interface: Identified
      The id, <mod id of the addon that registered it>:<path>; it doesn't change once registered.
      Specified by:
      id in interface Identified
    • name

      public String name()
      The name players see.
    • apply

      public Consumer<ThemeSettings> apply()
      What writes the preset's values into the theme.
    • live

      public Theme live(Supplier<String> version)
      Makes the theme follow something that changes outside the game. While it's active, Myriad calls version every couple of seconds and re-applies the theme when the returned string changes (return e.g. a file's modification time). A call that throws counts as an empty string. Returns this theme.
    • notice

      public Theme notice(Supplier<@Nullable String> notice)
      A message the Theme panel shows (highlighted) while notice returns non-null, e.g. why it can't load. Returns this theme.
    • aliases

      public Theme aliases(String... oldIds)
      Ids this theme replaces (from an older version or another addon), as namespace:path strings; saved choices and edits carry over. Returns this theme.
    • preferOnFirstRun

      public Theme preferOnFirstRun()
      Use this theme instead of Myriad's default on a fresh install (e.g. one that matches the player's system). If several themes ask, the first in the theme registry wins. Returns this theme.
    • live

      public @Nullable Supplier<String> live()
      What live(Supplier) set, or null for a theme that doesn't follow anything.
    • notice

      public @Nullable String notice()
      The message notice(Supplier) gives now, or null when there's none (or no notice was set).
    • aliases

      public List<MyriadId> aliases()
      The ids aliases(String...) set; empty by default.
    • prefersFirstRun

      public boolean prefersFirstRun()
      Whether preferOnFirstRun() was called.
    • toString

      public String toString()
      Its name.
      Overrides:
      toString in class Object