-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathTheme.java
More file actions
148 lines (123 loc) · 4.84 KB
/
Theme.java
File metadata and controls
148 lines (123 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.cleanroommc.modularui.theme;
import com.cleanroommc.modularui.ModularUIConfig;
import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.IThemeApi;
import com.cleanroommc.modularui.screen.Tooltip;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Map;
public class Theme implements ITheme {
public static final String FALLBACK = "default";
public static final String PANEL = "panel";
public static final String BUTTON = "button";
public static final String ITEM_SLOT = "itemSlot";
public static final String FLUID_SLOT = "fluidSlot";
public static final String TEXT_FIELD = "textField";
public static final String TOGGLE_BUTTON = "toggleButton";
private final Map<String, WidgetTheme> widgetThemes = new Object2ObjectOpenHashMap<>();
private final String id;
private final ITheme parentTheme;
private final WidgetTheme fallback;
private final WidgetTheme panelTheme;
private final WidgetTheme buttonTheme;
private final WidgetSlotTheme itemSlotTheme;
private final WidgetSlotTheme fluidSlotTheme;
private final WidgetTextFieldTheme textFieldTheme;
private final WidgetThemeSelectable toggleButtonTheme;
private int openCloseAnimationOverride = -1;
private Boolean smoothProgressBarOverride = null;
private Tooltip.Pos tooltipPosOverride = null;
Theme(String id, ITheme parent, Map<String, WidgetTheme> widgetThemes) {
this.id = id;
this.parentTheme = parent;
this.widgetThemes.putAll(widgetThemes);
if (parent instanceof Theme theme) {
for (Map.Entry<String, WidgetTheme> entry : theme.widgetThemes.entrySet()) {
if (!this.widgetThemes.containsKey(entry.getKey())) {
this.widgetThemes.put(entry.getKey(), entry.getValue());
}
}
} else if (parent == IThemeApi.get().getDefaultTheme()) {
if (!this.widgetThemes.containsKey(FALLBACK)) {
this.widgetThemes.put(FALLBACK, ThemeManager.defaultdefaultWidgetTheme);
}
for (Map.Entry<String, WidgetTheme> entry : ThemeAPI.INSTANCE.defaultWidgetThemes.entrySet()) {
if (!this.widgetThemes.containsKey(entry.getKey())) {
this.widgetThemes.put(entry.getKey(), entry.getValue());
}
}
}
this.panelTheme = this.widgetThemes.get(PANEL);
this.fallback = this.widgetThemes.get(FALLBACK);
this.buttonTheme = this.widgetThemes.get(BUTTON);
this.itemSlotTheme = (WidgetSlotTheme) this.widgetThemes.get(ITEM_SLOT);
this.fluidSlotTheme = (WidgetSlotTheme) this.widgetThemes.get(FLUID_SLOT);
this.textFieldTheme = (WidgetTextFieldTheme) this.widgetThemes.get(TEXT_FIELD);
this.toggleButtonTheme = (WidgetThemeSelectable) this.widgetThemes.get(TOGGLE_BUTTON);
}
void setOpenCloseAnimationOverride(int override) {
this.openCloseAnimationOverride = override;
}
void setSmoothProgressBarOverride(boolean smooth) {
this.smoothProgressBarOverride = smooth;
}
void setTooltipPosOverride(Tooltip.Pos pos) {
this.tooltipPosOverride = pos;
}
public String getId() {
return this.id;
}
public ITheme getParentTheme() {
return this.parentTheme;
}
public WidgetTheme getFallback() {
return this.fallback;
}
public WidgetTheme getPanelTheme() {
return this.panelTheme;
}
public WidgetTheme getButtonTheme() {
return this.buttonTheme;
}
@Override
public WidgetSlotTheme getItemSlotTheme() {
return this.itemSlotTheme;
}
@Override
public WidgetSlotTheme getFluidSlotTheme() {
return this.fluidSlotTheme;
}
public WidgetTextFieldTheme getTextFieldTheme() {
return this.textFieldTheme;
}
@Override
public WidgetThemeSelectable getToggleButtonTheme() {
return this.toggleButtonTheme;
}
public WidgetTheme getWidgetTheme(String id) {
if (this.widgetThemes.containsKey(id)) {
return this.widgetThemes.get(id);
}
return getFallback();
}
@Override
public int getOpenCloseAnimationOverride() {
if (this.openCloseAnimationOverride != -1) {
return this.openCloseAnimationOverride;
}
return ModularUIConfig.panelOpenCloseAnimationTime;
}
@Override
public boolean getSmoothProgressBarOverride() {
if (this.smoothProgressBarOverride != null) {
return this.smoothProgressBarOverride;
}
return ModularUIConfig.smoothProgressBar;
}
@Override
public Tooltip.Pos getTooltipPosOverride() {
if (this.tooltipPosOverride != null) {
return this.tooltipPosOverride;
}
return ModularUIConfig.tooltipPos;
}
}