Skip to content

Commit bbe7c81

Browse files
authored
Update ModularUI Theme wiki (#50)
* theme stuff * update * stuff * jei -> recipe viewer * fix * player inv ui factory * more ui factory info * typo
1 parent 31321c5 commit bbe7c81

File tree

10 files changed

+312
-55
lines changed

10 files changed

+312
-55
lines changed

docs/.vitepress/config/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ function wikiSidebar(): DefaultTheme.SidebarItem[] {
172172
{ text: "Color", link: "color" },
173173
{ text: "Drawable", link: "drawable" },
174174
{ text: "Theme", link: "theme" },
175+
{ text: "Widget Theme Reference", link: "theme_ref" }
175176
],
176177
},
177178
],

docs/wiki/modularui/client-gui-tutorial.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ for client side and a diamond. Then we open the screen with `ClientGUI.open()`.
7777
method we just created. Now let's boot up minecraft and test it.
7878

7979
:::info {id="info"}
80-
There are some overloads of `ClientGUI.open()` which allow you to pass in a `JeiSettings` or `UISettings` instance.
80+
There are some overloads of `ClientGUI.open()` which allow you to pass in a `RecipeViewerSettings` or `UISettings`
81+
instance. (`RecipeViewer` refers to JEI in 1.12 and NEI in 1.7.10).
8182
:::
8283

8384
::: code-group

docs/wiki/modularui/framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Useful methods are:
5050
- `getPartialTicks()` returns the partial ticks for the current frame
5151
- `getTheme()` returns the current active theme
5252
- `getUISettings()` returns the current UI settings
53-
- `getJeiSettings()` returns the current modifiable JEI settings
53+
- `getRecipeViewerSettings()` returns the current modifiable JEI/NEI settings
5454

5555
## ModularPanel
5656

docs/wiki/modularui/getting-started.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Check the latest version on [Github releases](https://github.com/CleanroomMC/Mod
2525

2626
## Development Tools
2727

28-
I highly recommend using IntelliJ in combination with the Single Hotswap plugin.
28+
I highly recommend using IntelliJ in combination with the Single Hotswap plugin (doesn't work for me in newer IntelliJ
29+
versions, maybe it does for you).
2930

3031
## Other documentation
3132

@@ -39,7 +40,7 @@ First you need to decide if you want a client only screen or a client-server syn
3940

4041
Client only GUIs are easier to work with, but they can't communicate with the server.
4142
You can open one by calling `ClientGUI.open(ModularScreen)`. You can additionally pass in a `UISettings` or
42-
`JeiSettings` instance. Client only GUIs don't display JEI on the side by default. This can be changed in the
43+
`RecipeViewerSettings` instance. Client only GUIs don't display JEI on the side by default. This can be changed in the
4344
JeiSettings. The options in `UISettings` are mostly for synced GUIs. The `ModularScreen` should be a new instance.
4445

4546
Go [here](./client-gui-tutorial.md) to get started on creating a client GUI. Even if you are looking into making a
@@ -60,12 +61,18 @@ here. A `UIFactory` is what finds the exact same `IGuiHolder` on client and serv
6061
`IGuiHolder` is then responsible for creating the UI. ModularUI has build-in factories for:
6162

6263
- Standard tile entities (`GuiFactories.tileEntity()`, `PosGuiData`)
63-
- Items in a players hand (`GuiFactories.item()`, `HandGuiData`)
64-
- Sided tile entities (useful for GregTech covers) (`GuiFactories.sidedTileEntity()`, `SidedPosGuiData`)
64+
- Items in a players inventory (f.e. player hand or even Bauble slots, other mods can be integrated as well)
65+
(`GuiFactories.playerInventory()`, `PlayerInventoryGuiData`)
66+
- Sided tile entities (useful for things like GregTech covers) (`GuiFactories.sidedTileEntity()`, `SidedPosGuiData`)
67+
- Entities (for example villager trading UI) (`GuiFactories.entity()`, `EntityGuiData`)
6568
- Simple factories (these always point to the same `IGuiHolder`) (`GuiFactories.createSimple()`, gui data irrelevant)
6669

6770
Each factory may have its own custom method for opening a GUI. The factories then call `GuiManager.open(...)`.
6871

72+
Should these not suit your needs you may implement your own factory. Just implement `UIFactory` (or `AbstractUIFactory`
73+
for some helpers) and register it with `GuiManager.registerFactory()`. UI factories also control the default container
74+
class and when the ui should be force closed (player out of range usually).
75+
6976
Go [here](./synced-gui-tutorial.md) to get started on creating a synced GUI.
7077

7178
#### Examples

docs/wiki/modularui/json/color.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ If `value` is not defined, [HSL](#hsl) will be used.
8282
```
8383
:::
8484

85-
::: note {id="note"}
85+
:::info Note {id="note"}
8686
The saturation is not the same from [HSV](#hsv) as from [HSL](#hsl) (they are calculated slightly different), but the hue is.
8787
:::
8888

@@ -109,3 +109,27 @@ The saturation is not the same from [HSV](#hsv) as from [HSL](#hsl) (they are ca
109109
::: warning {id="warning"}
110110
You can NOT mix any of those formats! (except of course alpha)
111111
:::
112+
113+
## Predefined colors
114+
There is a shortcut for an invisible color:
115+
```json
116+
{
117+
"color": "invisible"
118+
}
119+
```
120+
Which is equal to
121+
```json
122+
{
123+
"color": "#00FFFFFF"
124+
}
125+
```
126+
Other predefined colors include for example `red`, `blue` and `green`. All predefined color ModularUI defines can be
127+
found [here](https://github.com/CleanroomMC/ModularUI/blob/e52f70accd97d2c9b02635f6c70627d2112d9f6f/src/main/java/com/cleanroommc/modularui/utils/Color.java#L879).
128+
You can also vary the shade of the predefined color by appending a ':' and a positive or negative integer. For example
129+
```json
130+
{
131+
"color": "red:2"
132+
}
133+
```
134+
This would choose red, but two steps brighter. Negative number means darker. Zero is the main color. How many shades
135+
there are for a color is not constant. You will have to look it up at the page above.

docs/wiki/modularui/json/theme.md

Lines changed: 133 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ title: Theme
77
Make sure to check out [how to register themes](../themes.md).
88

99
Here we will take a look what the theme file can look like. If you are a mod developer you can directly translate it to
10-
your `JsonBuilder`.
10+
your `ThemeBuilder`.
1111

12-
Let's look at an example. This is what the default vanilla theme as a json file would look like.
12+
Let's look at an example. This is what the default vanilla theme as a json file would mostly look like.
1313

1414
```json
1515
{
1616
"parent": "DEFAULT",
17+
"defaultWidth": 18,
18+
"defaultHeight": 18,
1719
"background": null,
1820
"hoverBackground": "none",
1921
"color": "#FFFFFFFF",
2022
"textColor": "#FF404040",
2123
"textShadow": false,
24+
"iconColor": "#FF404040",
2225
"panel": {
2326
"background": {
2427
"type": "texture",
@@ -30,13 +33,15 @@ Let's look at an example. This is what the default vanilla theme as a json file
3033
"type": "texture",
3134
"id": "mc_button"
3235
},
33-
"hoverBackground": {
34-
"type": "texture",
35-
"id": "mc_button_hovered"
36-
},
3736
"textColor": "#FFFFFFFF",
3837
"textShadow": true
3938
},
39+
"button:hover": {
40+
"background": {
41+
"type": "texture",
42+
"id": "mc_button_hovered"
43+
}
44+
},
4045
"itemSlot": {
4146
"background": {
4247
"type": "texture",
@@ -65,20 +70,22 @@ Let's look at an example. This is what the default vanilla theme as a json file
6570
"type": "texture",
6671
"id": "mc_button"
6772
},
68-
"hoverBackground": {
69-
"type": "texture",
70-
"id": "mc_button_hovered"
71-
},
7273
"textColor": "#FFFFFFFF",
7374
"textShadow": true,
7475
"selectedBackground": {
7576
"type": "texture",
7677
"id": "mc_button_disabled"
7778
},
78-
"selectedHoverBackground": "none",
7979
"selectedColor": "#FFFFFFFF",
8080
"selectedTextColor": "#FFFFFFFF",
8181
"selectedTextShadow": true
82+
},
83+
"toggleButton:hover": {
84+
"background": {
85+
"type": "texture",
86+
"id": "mc_button_hovered"
87+
},
88+
"selectedBackground": "none"
8289
}
8390
}
8491
```
@@ -87,38 +94,129 @@ First we have the `parent` property. This defines the parent theme. If a theme d
8794
be taken from its parent. If the `parent` property is not set, it defaults to `DEFAULT`, which is just the vanilla
8895
theme.
8996

90-
After that we have the `color`, `background`, `hoverBackground`, `textColor` and `textShadow` properties. These are
91-
fallback properties of [widget themes](#widget-themes). You can put any properties that any widget theme can have here.
92-
If a widget theme does not have said property it will fall back to the top level property if defined.
93-
Note that `"none"` is used for `hoverBackground` so it will be ignored and the widget doesn't suddenly turn invisible.
94-
Read more about the difference between `"none"` and `null` [here](./drawable.md#empty-drawable)
97+
After that we have the `defaultWidth`, `defaultHeight`, `color`, `background`, `textColor`,
98+
`textShadow` and `iconColor` properties. These are fallback properties of [widget themes](#widget-themes). You can put
99+
any properties that any widget theme can have here. If a widget theme does not have said property it will fall back to
100+
the top level property if defined. The `defaultWidth` and `defaultHeight` properties determine the default widget size
101+
if it isn't specified. Note this won't work on every widget. `TextWidget` for example have a default size that is
102+
exactly the size of the text they are displaying.
103+
104+
See [widget themes](theme_ref.md) to find out what widget themes ModularUI provides and what properties they have.
105+
Addons may add more.
106+
107+
Additionally, you can add a
108+
```json
109+
{
110+
"override": true
111+
}
112+
```
113+
property to the top level. This will discard any previous defined themes with the same name of other resourcepacks.
114+
Otherwise, they will be merged, where the theme will only override properties it has defined.
115+
116+
:::info Note {id="note"}
117+
All widget themes are optional. You can define as many as you like. Not defined widget themes will be taken from the
118+
parent theme.
119+
All properties of widget themes (and the fallback properties) are optional.
120+
:::
121+
122+
## Hover widget themes
123+
You may have noticed the widget themes in the example `"button:hover": {...}` and `"toggleButton:hover": {...}`. This is
124+
because when a widget is hovered with the mouse a separate widget theme will be applied. This hover widget theme has all
125+
the properties of the non hover variant. In terms of property inheritance they behave like
126+
[sub widget themes](#sub-widget-themes). If the non hover variant is specified in the current theme, then the properties
127+
will be inherited from there. Otherwise, it will be inherited from the hover widget theme in the parent theme. This also
128+
means that if the none hover variant is specified with any amount of properties, all hover effects from a parent theme
129+
are lost. You will have to re-add them to you current theme.
130+
Unlike sub widget themes, hover widget themes don't need to be registered. Just add the suffix `:hover` to any
131+
registered widget theme (yes, even sub widget themes) and it will work.
132+
133+
Note that `"none"` is used for `background` inside the hover widget theme so it will be ignored
134+
and the widget doesn't suddenly turn invisible when you don't want a separate hover texture. Read more about the
135+
difference between `"none"` and `null` [here](./drawable.md#empty-drawable).
95136

96-
For `color` and `textColor` see [color](./color.md). For `background` and `hoverBackground`
97-
see [drawables](./drawable.md).
137+
You might think that `slotHoverColor` from item slot and fluid slot would belong in the hover widget theme, however
138+
these are special. Specifying them in the hover widget theme variant has no effect.
98139

99-
Next we have objects defined with the property name `panel`, `button`, `itemSlot`, `fluidSlot`, `textField` and
100-
`toggleButton`.
101-
These are widget themes. These are all widget themes ModularUI provides. Addons may add more.
140+
The `defaultWidth` and the `defaultHeight` property obviously have no effect in the hover variant.
102141

103-
## Widget themes
142+
## Inheritance of properties
104143

105-
Widgets which don't use one of the existing widget themes use the fallback properties.
144+
All properties will default to the parent themes widget theme properties, except `color`, `textColor`, `textShadow` and
145+
`iconColor`. These default first to the fallback properties. You can override this behavior, by adding a `inherit`
146+
property to a widget theme. The value of the property should either be a string or a list of strings where each string
147+
is the name of the before mentioned properties. Let's look at an example
106148

107-
All widget themes have the properties `color`, `background`, `hoverBackground`, `textColor` and `textShadow`. Which are
108-
all mostly self-explanatory. `color` is applied additionally to the background (if possible).
149+
Let's say we have a theme A
150+
```json
151+
{
152+
"button": {
153+
"defaultWidth": 24,
154+
"color": "#FF0000"
155+
}
156+
}
157+
```
158+
and a theme B which is a child of A
159+
```json
160+
{
161+
"parent": "A",
162+
"defaultWidth": 20,
163+
"color": "#00FF00",
164+
"button": {
165+
}
166+
}
167+
```
168+
Since `defaultWidth` will be inherited from the parents widget theme, the default width of the button is 24 and not 20.
169+
Contrary to `color` which uses the fallback value first. This means the button will have a color `#00FF00` and not
170+
`#FF0000`. Sometimes this behavior is not desirable. We could copy the value from the parent, but that's extra work and
171+
doesn't get updated when the parent value changes. Instead, we use the `inherit` property:
172+
```json
173+
{
174+
"parent": "A",
175+
"defaultWidth": 20,
176+
"color": "#00FF00",
177+
"button": {
178+
"inherit": [
179+
"color"
180+
]
181+
}
182+
}
183+
```
184+
Now the button color of B will be whatever the parent widget themes values is. In this case it is `#FF0000`. Since we
185+
only have one value in the inherit list, it can be shortened to `"inherit": "color"`.
109186

110-
The `itemSlot` and `fluidSlot` also have the `slotHoverColor`, which is just the rendered color when the slot is
111-
hovered.
112-
Don't use full opacity here. Otherwise, you won't be able to see the item.
187+
:::info Note {id="note"}
188+
Note that other mods may add properties which behave similar to `color`.
189+
:::
113190

114-
The `textField` theme has the `markedColor` property which is the marked text background and the `hintColor` property which is
115-
the color of the text that is shown when the field is empty.
191+
## Sub Widget Themes
192+
Sometimes you want to have different widget themes for the same type of widget. Let's say for example you want to color
193+
the player slots differently than normal slots. In java, we first need to register the sub widget theme with
194+
```java
195+
WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER = ITEM_SLOT.createSubKey("player");
196+
```
116197

117-
The `toggleButton` has `selectedBackground`, `selectedHoverBackground`, `selectedColor`, `selectedTextColor` and
118-
`selectedTextShadow` which are all self-explanatory. Note that
198+
Then inside a theme json we can do this.
199+
```json
200+
{
201+
"itemSlot:player": {
202+
"color": "#FF0000"
203+
}
204+
}
205+
```
206+
This will color only player slots red. The syntax is `parentWidgetThemeName:subName`. Every sub widget theme has to be
207+
defined via a mod. ModularUI currently only has the `itemSlot:player` sub widget theme defined. Every sub theme can have
208+
any properties it's parent can have. Sub widget themes can have sub widget themes.
209+
210+
Let's say that we now want to color hotbar slots a different color. We could create a new sub widget theme from
211+
`ITEM_SLOT`, but if the hotbar theme is not specified it should inherit the player slot theme. We therefore create a sub
212+
widget theme for the just created sub widget theme.
213+
```java
214+
WidgetThemeKey<SlotTheme> ITEM_SLOT_PLAYER_HOTBAR = ITEM_SLOT_PLAYER.createSubKey("playerHotbar");
215+
```
216+
This new widget theme can be accessed with `"itemSlot:playerHotbar"` and **not** `"itemSlot:player:playerHotbar"`.
217+
The syntax is `rootParentWidgetThemeName:subName`. You can find the sub widget themes ModularUI provides [here](theme_ref.md#sub-widget-themes).
119218

120219
:::info Note {id="note"}
121-
All widget themes are optional. You can define as many as you like. Not defined widget themes will be taken from the
122-
parent theme.
123-
All properties of widget themes (and the fallback properties) are optional.
220+
This feature is intended for widgets with the same type and not for different widget types which use the same widget
221+
theme class.
124222
:::

0 commit comments

Comments
 (0)