|
1 | 1 | package com.cleanroommc.modularui.api; |
2 | 2 |
|
| 3 | +import com.cleanroommc.modularui.drawable.GuiTextures; |
3 | 4 | import com.cleanroommc.modularui.screen.ModularScreen; |
| 5 | +import com.cleanroommc.modularui.theme.SelectableTheme; |
| 6 | +import com.cleanroommc.modularui.theme.SlotTheme; |
| 7 | +import com.cleanroommc.modularui.theme.TextFieldTheme; |
4 | 8 | import com.cleanroommc.modularui.theme.ThemeAPI; |
| 9 | +import com.cleanroommc.modularui.theme.ThemeBuilder; |
5 | 10 | import com.cleanroommc.modularui.theme.WidgetTheme; |
| 11 | +import com.cleanroommc.modularui.theme.WidgetThemeKey; |
| 12 | +import com.cleanroommc.modularui.theme.WidgetThemeKeyBuilder; |
6 | 13 | import com.cleanroommc.modularui.theme.WidgetThemeParser; |
7 | 14 | import com.cleanroommc.modularui.utils.JsonBuilder; |
8 | 15 |
|
| 16 | +import org.jetbrains.annotations.ApiStatus; |
9 | 17 | import org.jetbrains.annotations.Contract; |
10 | 18 | import org.jetbrains.annotations.NotNull; |
11 | 19 | import org.jetbrains.annotations.Nullable; |
| 20 | +import org.jetbrains.annotations.UnmodifiableView; |
12 | 21 |
|
13 | 22 | import java.util.List; |
14 | 23 |
|
15 | 24 | /** |
16 | 25 | * An API interface for Themes. |
17 | 26 | */ |
| 27 | +@ApiStatus.NonExtendable |
18 | 28 | public interface IThemeApi { |
19 | 29 |
|
20 | 30 | // widget themes |
21 | | - String FALLBACK = "default"; |
22 | | - String PANEL = "panel"; |
23 | | - String BUTTON = "button"; |
24 | | - String ITEM_SLOT = "itemSlot"; |
25 | | - String FLUID_SLOT = "fluidSlot"; |
26 | | - String TEXT_FIELD = "textField"; |
27 | | - String TOGGLE_BUTTON = "toggleButton"; |
| 31 | + WidgetThemeKey<WidgetTheme> FALLBACK = get().widgetThemeKeyBuilder("default", WidgetTheme.class) |
| 32 | + .defaultTheme(WidgetTheme.darkTextNoShadow(18, 18, null)) |
| 33 | + .register(); |
| 34 | + |
| 35 | + WidgetThemeKey<WidgetTheme> PANEL = get().widgetThemeKeyBuilder("panel", WidgetTheme.class) |
| 36 | + .defaultTheme(WidgetTheme.darkTextNoShadow(176, 166, GuiTextures.MC_BACKGROUND)) |
| 37 | + .register(); |
| 38 | + |
| 39 | + WidgetThemeKey<WidgetTheme> BUTTON = get().widgetThemeKeyBuilder("button", WidgetTheme.class) |
| 40 | + .defaultTheme(WidgetTheme.whiteTextShadow(18, 18, GuiTextures.MC_BUTTON)) |
| 41 | + .defaultHoverTheme(WidgetTheme.whiteTextShadow(18, 18, GuiTextures.MC_BUTTON_HOVERED)) |
| 42 | + .register(); |
| 43 | + |
| 44 | + WidgetThemeKey<SlotTheme> ITEM_SLOT = get().widgetThemeKeyBuilder("itemSlot", SlotTheme.class) |
| 45 | + .defaultTheme(new SlotTheme(GuiTextures.SLOT_ITEM)) |
| 46 | + .register(); |
| 47 | + |
| 48 | + WidgetThemeKey<SlotTheme> FLUID_SLOT = get().widgetThemeKeyBuilder("fluidSlot", SlotTheme.class) |
| 49 | + .defaultTheme(new SlotTheme(GuiTextures.SLOT_FLUID)) |
| 50 | + .register(); |
| 51 | + |
| 52 | + WidgetThemeKey<TextFieldTheme> TEXT_FIELD = get().widgetThemeKeyBuilder("textField", TextFieldTheme.class) |
| 53 | + .defaultTheme(new TextFieldTheme(0xFF2F72A8, 0xFF5F5F5F)) |
| 54 | + .register(); |
| 55 | + |
| 56 | + WidgetThemeKey<SelectableTheme> TOGGLE_BUTTON = get().widgetThemeKeyBuilder("toggleButton", SelectableTheme.class) |
| 57 | + .defaultTheme(SelectableTheme.whiteTextShadow(18, 18, GuiTextures.MC_BUTTON, GuiTextures.MC_BUTTON_DISABLED)) |
| 58 | + .defaultHoverTheme(SelectableTheme.whiteTextShadow(18, 18, GuiTextures.MC_BUTTON_HOVERED, GuiTextures.MC_BUTTON_DISABLED)) |
| 59 | + .register(); |
| 60 | + |
| 61 | + // sub widget themes |
| 62 | + WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER = ITEM_SLOT.createSubKey("player"); |
| 63 | + WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_HOTBAR = ITEM_SLOT_PLAYER.createSubKey("playerHotbar"); |
| 64 | + WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_MAIN_INV = ITEM_SLOT_PLAYER.createSubKey("playerMainInventory"); |
| 65 | + WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_OFFHAND = ITEM_SLOT_PLAYER.createSubKey("playerOffhand"); |
| 66 | + WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_ARMOR = ITEM_SLOT_PLAYER.createSubKey("playerArmor"); |
| 67 | + |
| 68 | + String HOVER_SUFFIX = ":hover"; |
28 | 69 |
|
29 | 70 | // properties |
30 | 71 | String PARENT = "parent"; |
| 72 | + String DEFAULT_WIDTH = "defaultWidth"; |
| 73 | + String DEFAULT_HEIGHT = "defaultHeight"; |
31 | 74 | String BACKGROUND = "background"; |
32 | | - String HOVER_BACKGROUND = "hoverBackground"; |
33 | 75 | String COLOR = "color"; |
34 | 76 | String TEXT_COLOR = "textColor"; |
35 | 77 | String TEXT_SHADOW = "textShadow"; |
| 78 | + String ICON_COLOR = "iconColor"; |
36 | 79 | String SLOT_HOVER_COLOR = "slotHoverColor"; |
37 | 80 | String MARKED_COLOR = "markedColor"; |
38 | 81 | String HINT_COLOR = "hintColor"; |
39 | 82 | String SELECTED_BACKGROUND = "selectedBackground"; |
40 | | - String SELECTED_HOVER_BACKGROUND = "selectedHoverBackground"; |
41 | 83 | String SELECTED_COLOR = "selectedColor"; |
42 | 84 | String SELECTED_TEXT_COLOR = "selectedTextColor"; |
43 | 85 | String SELECTED_TEXT_SHADOW = "selectedTextShadow"; |
| 86 | + String SELECTED_ICON_COLOR = "selectedIconColor"; |
44 | 87 |
|
45 | 88 | /** |
46 | 89 | * @return the default api implementation |
@@ -70,20 +113,24 @@ static IThemeApi get() { |
70 | 113 | */ |
71 | 114 | boolean hasTheme(String id); |
72 | 115 |
|
73 | | - /** |
74 | | - * @param id id of the widget theme |
75 | | - * @return if a widget theme with the id is registered |
76 | | - */ |
77 | | - boolean hasWidgetTheme(String id); |
78 | | - |
79 | 116 | /** |
80 | 117 | * Registers a theme json object. Themes from resource packs always have greater priority. |
| 118 | + * Json builders are used here as they are much easier to merge as opposed to normal java objects. |
81 | 119 | * |
82 | 120 | * @param id id of the theme |
83 | 121 | * @param json theme data |
84 | 122 | */ |
85 | 123 | void registerTheme(String id, JsonBuilder json); |
86 | 124 |
|
| 125 | + /** |
| 126 | + * Registers a theme json object. Themes from resource packs always have greater priority. |
| 127 | + * |
| 128 | + * @param themeBuilder theme data |
| 129 | + */ |
| 130 | + default void registerTheme(ThemeBuilder<?> themeBuilder) { |
| 131 | + registerTheme(themeBuilder.getId(), themeBuilder); |
| 132 | + } |
| 133 | + |
87 | 134 | /** |
88 | 135 | * Gets all currently from java side registered theme json's for a theme. |
89 | 136 | * |
@@ -133,11 +180,20 @@ default void registerThemeForScreen(String owner, String name, String theme) { |
133 | 180 | void registerThemeForScreen(String screen, String theme); |
134 | 181 |
|
135 | 182 | /** |
136 | | - * Register a widget theme. |
| 183 | + * Registers a widget theme. It is recommended to store the resulting key in a static variable and make it accessible by public methods. |
137 | 184 | * |
138 | | - * @param id id of the widget theme |
139 | | - * @param defaultTheme the fallback widget theme |
140 | | - * @param parser the widget theme json parser function |
| 185 | + * @param id id of the widget theme |
| 186 | + * @param defaultTheme the fallback widget theme |
| 187 | + * @param defaultHoverTheme the fallback hover widget theme |
| 188 | + * @param parser the widget theme json parser function. This is usually another constructor. |
| 189 | + * @return key to access the widget theme |
141 | 190 | */ |
142 | | - void registerWidgetTheme(String id, WidgetTheme defaultTheme, WidgetThemeParser parser); |
| 191 | + <T extends WidgetTheme> WidgetThemeKey<T> registerWidgetTheme(String id, T defaultTheme, T defaultHoverTheme, WidgetThemeParser<T> parser); |
| 192 | + |
| 193 | + default <T extends WidgetTheme> WidgetThemeKeyBuilder<T> widgetThemeKeyBuilder(String id, Class<T> type) { |
| 194 | + return new WidgetThemeKeyBuilder<>(id); |
| 195 | + } |
| 196 | + |
| 197 | + @UnmodifiableView |
| 198 | + List<WidgetThemeKey<?>> getWidgetThemeKeys(); |
143 | 199 | } |
0 commit comments