Skip to content

Commit 9fb56fb

Browse files
Fix: SubMenuOption sharing same skin as ParentMenu leading to many problems. Final patches to all skins, widgets saving...
1 parent 3c431b7 commit 9fb56fb

File tree

11 files changed

+186
-117
lines changed

11 files changed

+186
-117
lines changed

src/main/java/com/tanishisherewith/dynamichud/integration/IntegrationManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static void integrate() {
148148
} else {
149149
DynamicHUD.logger.error("Mod {} has improper implementation of DynamicHUD", modId, e);
150150
}
151-
bad_implementations.add(new ModError(modId, e.getLocalizedMessage().trim()));
151+
bad_implementations.add(new ModError(modId, e.getMessage().trim()));
152152
}
153153
}
154154
printInfo("(DynamicHUD) Integration of supported mods was successful");

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/ContextMenuProperties.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public Skin getSkin() {
9191
return skin;
9292
}
9393

94+
/**
95+
* @return Cloned object of every property except skin
96+
*/
9497
public ContextMenuProperties clone() {
9598
return cloneToBuilder().build();
9699
}
@@ -111,12 +114,24 @@ public Builder<?> cloneToBuilder() {
111114
.enableAnimations(enableAnimations);
112115
}
113116

117+
/**
118+
* @return Cloned object with same skin as the current ContextMenuProperties
119+
*/
114120
public ContextMenuProperties cloneWithSkin() {
115121
return this.cloneToBuilder()
116122
.skin(skin)
117123
.build();
118124
}
119125

126+
/**
127+
* @return Cloned object with a clone of the skin as the current ContextMenuProperties
128+
*/
129+
public ContextMenuProperties cloneSkin() {
130+
return this.cloneToBuilder()
131+
.skin(skin.clone())
132+
.build();
133+
}
134+
120135
public static class Builder<T extends ContextMenuProperties> {
121136
protected final T properties;
122137

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/Option.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ public Text getDescription() {
185185
return description;
186186
}
187187

188+
@Override
189+
public String toString() {
190+
return this.getClass().getName() + "{" +
191+
", name=" + name +
192+
", x=" + x +
193+
", y=" + y +
194+
'}';
195+
}
196+
188197
/**
189198
* How complex do you think this option is for a daily normal user.
190199
* For example, some options may be advanced and not needed for casual players but are helpful in customisation

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/OptionGroup.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public List<Option<?>> getGroupOptions() {
2929

3030
@Override
3131
public void updateProperties(ContextMenuProperties properties) {
32-
this.renderer = new OptionGroupRenderer(); // Set renderer as OptionGroupRenderer
33-
32+
super.updateProperties(properties);
3433
if (groupOptions == null) return;
3534

3635
for (Option<?> option : groupOptions) {
@@ -40,6 +39,7 @@ public void updateProperties(ContextMenuProperties properties) {
4039

4140
@Override
4241
public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY) {
42+
super.render(drawContext,x,y,mouseX,mouseY);
4343
}
4444

4545
public boolean isExpanded() {
@@ -63,11 +63,9 @@ public int getHeight() {
6363
return super.getHeight();
6464
}
6565

66-
public class OptionGroupRenderer implements SkinRenderer<Option<OptionGroup>> {
67-
66+
public static class OptionGroupRenderer implements SkinRenderer<Option<OptionGroup>> {
6867
@Override
69-
public void render(DrawContext drawContext, Option<OptionGroup> option, int x, int y, int mouseX, int mouseY) {
70-
}
68+
public void render(DrawContext drawContext, Option<OptionGroup> option, int x, int y, int mouseX, int mouseY) {}
7169

7270
@Override
7371
public boolean mouseClicked(Option<OptionGroup> option2, double mouseX, double mouseY, int button) {

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/SubMenuOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SubMenuOption extends Option<Boolean> {
2222
public <T extends ContextMenuProperties> SubMenuOption(Text name, ContextMenu<?> parentMenu, Supplier<Boolean> getter, Consumer<Boolean> setter, T properties) {
2323
super(name, getter, setter);
2424
Objects.requireNonNull(parentMenu, "Parent Context Menu cannot be null in [" + name + "] SubMenu option");
25-
this.subMenu = parentMenu.createSubMenu(parentMenu.x + parentMenu.getWidth(), this.y, properties);
25+
this.subMenu = parentMenu.createSubMenu(parentMenu.x + parentMenu.getWidth(), this.y, properties.cloneSkin());
2626
this.subMenu.getProperties().setHeightOffset(0);
2727
this.subMenu.setVisible(get());
2828
this.renderer.init(this);

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/options/coloroption/HueSlider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void render(DrawContext drawContext, int x, int y) {
4444
color = (color & 0x00FFFFFF) | (255 << 24);
4545
drawContext.fill(x + i, y, x + i + 1, y + height, color);
4646
}
47+
drawContext.draw();
4748

4849

4950
// Draw the handle

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/ClassicSkin.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ private void drawBorder(MatrixStack matrices, ContextMenu<?> contextMenu, Contex
141141
}
142142
}
143143

144+
@Override
145+
public Skin clone() {
146+
return new ClassicSkin();
147+
}
148+
144149
public static class ClassicBooleanRenderer implements SkinRenderer<BooleanOption> {
145150
@Override
146151
public void render(DrawContext drawContext, BooleanOption option, int x, int y, int mouseX, int mouseY) {
@@ -191,10 +196,12 @@ public static class ClassicSubMenuRenderer implements SkinRenderer<SubMenuOption
191196
public void render(DrawContext drawContext, SubMenuOption option, int x, int y, int mouseX, int mouseY) {
192197
int color = option.value ? Color.GREEN.getRGB() : Color.RED.getRGB();
193198
drawContext.drawText(mc.textRenderer, option.name, x, y, color, false);
199+
drawContext.drawText(mc.textRenderer, option.getSubMenu().isVisible() ? "-" : "+", x + Math.max(option.getParentMenu().getWidth() - 12, mc.textRenderer.getWidth(option.name) + 2), y, color, false);
200+
194201
option.setHeight(mc.textRenderer.fontHeight);
195-
option.setWidth(mc.textRenderer.getWidth(option.name) + 1);
202+
option.setWidth(mc.textRenderer.getWidth(option.name) + 4);
196203

197-
option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y, mouseX, mouseY);
204+
option.getSubMenu().render(drawContext, x + option.getParentMenu().getWidth(), y - 1, mouseX, mouseY);
198205
}
199206
}
200207

@@ -237,7 +244,6 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i
237244
option.drawSlider(drawContext, x, y + textRenderer.fontHeight + 1, option.getWidth(), handleX);
238245

239246
// Draw the handle
240-
241247
DrawHelper.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(),
242248
(float) handleX,
243249
(float) handleY,
@@ -248,6 +254,7 @@ public void render(DrawContext drawContext, DoubleOption option, int x, int y, i
248254
90,
249255
0.6f,
250256
0.6f);
257+
251258
}
252259
}
253260

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/skinsystem/MinecraftSkin.java

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.blaze3d.systems.RenderSystem;
44
import com.tanishisherewith.dynamichud.DynamicHUD;
5+
import com.tanishisherewith.dynamichud.helpers.ColorHelper;
56
import com.tanishisherewith.dynamichud.helpers.DrawHelper;
67
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenu;
78
import com.tanishisherewith.dynamichud.utils.contextmenu.layout.LayoutContext;
@@ -35,18 +36,18 @@ public class MinecraftSkin extends Skin implements GroupableSkin {
3536
Identifier.ofVanilla("widget/button_disabled"),
3637
Identifier.ofVanilla("widget/button_highlighted")
3738
);
38-
private static final int DEFAULT_SCROLLBAR_WIDTH = 8;
39-
private static final int DEFAULT_PANEL_WIDTH = 248;
40-
private static final int DEFAULT_PANEL_HEIGHT = 165;
41-
private static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.ofVanilla("textures/gui/demo_background.png");
42-
private static final Identifier SCROLLER_TEXTURE = Identifier.ofVanilla("widget/scroller");
43-
private static final Identifier SCROLL_BAR_BACKGROUND = Identifier.ofVanilla("widget/scroller_background");
44-
private static final Identifier GROUP_BACKGROUND = Identifier.of(DynamicHUD.MOD_ID, "textures/minecraftskin/group_panel.png");
39+
public static final int DEFAULT_SCROLLBAR_WIDTH = 8;
40+
public static final int DEFAULT_PANEL_WIDTH = 248;
41+
public static final int DEFAULT_PANEL_HEIGHT = 165;
42+
public static final Identifier DEFAULT_BACKGROUND_PANEL = Identifier.ofVanilla("textures/gui/demo_background.png");
43+
public static final Identifier SCROLLER_TEXTURE = Identifier.ofVanilla("widget/scroller");
44+
public static final Identifier SCROLL_BAR_BACKGROUND = Identifier.ofVanilla("widget/scroller_background");
45+
public static final Identifier GROUP_BACKGROUND = Identifier.of(DynamicHUD.MOD_ID, "textures/minecraftskin/group_panel.png");
4546

4647
private final Identifier BACKGROUND_PANEL;
4748
private final int panelWidth;
4849
private final int panelHeight;
49-
private final PanelColor panelColor;
50+
private PanelColor panelColor;
5051

5152
private int imageX, imageY;
5253
private final ScrollHandler scrollHandler;
@@ -124,16 +125,12 @@ public void renderContextMenu(DrawContext drawContext, ContextMenu<?> contextMen
124125

125126
RenderSystem.enableBlend();
126127
RenderSystem.enableDepthTest();
127-
panelColor.applyColor();
128128

129-
drawContext.drawTexture(RenderLayer::getGuiTextured, BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight, 256, 254);
130-
131-
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
129+
drawContext.drawTexture(RenderLayer::getGuiTextured, BACKGROUND_PANEL, imageX, imageY, 0, 0, panelWidth, panelHeight, 256, 254,panelColor.getColor());
132130

133131
drawSingularButton(drawContext, "X", mouseX, mouseY, imageX + 3, imageY + 3, 14, 14);
134132

135133
//Up and down arrows near the group panel
136-
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
137134
RenderSystem.disableBlend();
138135
RenderSystem.disableDepthTest();
139136

@@ -324,6 +321,30 @@ public LayoutContext.Offset getGroupIndent() {
324321
return LayoutContext.Offset.zero();
325322
}
326323

324+
public void setPanelColor(PanelColor panelColor) {
325+
this.panelColor = panelColor;
326+
}
327+
328+
public PanelColor getPanelColor() {
329+
return panelColor;
330+
}
331+
332+
public int getPanelHeight() {
333+
return panelHeight;
334+
}
335+
336+
public int getPanelWidth() {
337+
return panelWidth;
338+
}
339+
340+
public int getImageX() {
341+
return imageX;
342+
}
343+
344+
public int getImageY() {
345+
return imageY;
346+
}
347+
327348
/**
328349
* Group rendering handled already
329350
*/
@@ -332,22 +353,22 @@ public void renderGroup(DrawContext drawContext, OptionGroup group, int groupX,
332353
}
333354

334355
public enum PanelColor {
335-
COFFEE_BROWN(0.6f, 0.3f, 0.1f, 0.9f),
336-
CREAMY(1.0f, 0.9f, 0.8f, 0.9f),
337-
DARK_PANEL(0.2f, 0.2f, 0.2f, 0.9f),
338-
FOREST_GREEN(0.0f, 0.6f, 0.2f, 0.9f),
339-
GOLDEN_YELLOW(1.0f, 0.8f, 0.0f, 0.9f),
340-
LAVENDER(0.8f, 0.6f, 1.0f, 0.9f),
341-
LIGHT_BLUE(0.6f, 0.8f, 1.0f, 0.9f),
342-
LIME_GREEN(0.7f, 1.0f, 0.3f, 0.9f),
343-
MIDNIGHT_PURPLE(0.3f, 0.0f, 0.5f, 0.9f),
344-
OCEAN_BLUE(0.0f, 0.5f, 1.0f, 0.9f),
345-
ROSE_PINK(1.0f, 0.4f, 0.6f, 0.9f),
346-
SKY_BLUE(0.5f, 0.8f, 1.0f, 0.9f),
347-
SOFT_GREEN(0.6f, 1.0f, 0.6f, 0.9f),
348-
SUNSET_ORANGE(1.0f, 0.5f, 0.0f, 0.9f),
349-
WARM_YELLOW(1.0f, 1.0f, 0.6f, 0.9f),
350-
CUSTOM(0.0f, 0.0f, 0.0f, 0.0f); // PlaceHolder for custom colors
356+
COFFEE_BROWN(0.6f, 0.3f, 0.1f, 1.0f),
357+
CREAMY(1.0f, 0.9f, 0.8f, 1.0f),
358+
DARK_PANEL(0.2f, 0.2f, 0.2f, 1.0f),
359+
FOREST_GREEN(0.0f, 0.6f, 0.2f, 1.0f),
360+
GOLDEN_YELLOW(1.0f, 0.8f, 0.0f, 1.0f),
361+
LAVENDER(0.8f, 0.6f, 1.0f, 1.0f),
362+
LIGHT_BLUE(0.6f, 0.8f, 1.0f, 1.0f),
363+
LIME_GREEN(0.7f, 1.0f, 0.3f, 1.0f),
364+
MIDNIGHT_PURPLE(0.3f, 0.0f, 0.5f, 1.0f),
365+
OCEAN_BLUE(0.0f, 0.5f, 1.0f, 1.0f),
366+
ROSE_PINK(1.0f, 0.4f, 0.6f, 1.0f),
367+
SKY_BLUE(0.5f, 0.8f, 1.0f, 1.0f),
368+
SOFT_GREEN(0.6f, 1.0f, 0.6f, 1.0f),
369+
SUNSET_ORANGE(1.0f, 0.5f, 0.0f, 1.0f),
370+
WARM_YELLOW(1.0f, 1.0f, 0.6f, 1.0f),
371+
CUSTOM(0.0f, 0.0f, 0.0f, 0.0f); /// PlaceHolder for custom colors
351372

352373
private float red;
353374
private float green;
@@ -373,6 +394,9 @@ public static PanelColor custom(float red, float green, float blue, float alpha)
373394
public void applyColor() {
374395
RenderSystem.setShaderColor(red, green, blue, alpha);
375396
}
397+
public int getColor() {
398+
return new Color(red,green,blue,alpha).getRGB();
399+
}
376400
}
377401

378402
public class MinecraftBooleanRenderer implements SkinRenderer<BooleanOption> {
@@ -520,7 +544,7 @@ public void render(DrawContext drawContext, EnumOption<E> option, int x, int y,
520544
option.setHeight(25);
521545
option.setWidth(maxWidth);
522546

523-
drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true);
547+
drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true);
524548

525549
option.setPosition(x + panelWidth - maxWidth - 25, y);
526550

@@ -554,7 +578,7 @@ public void render(DrawContext drawContext, ListOption<E> option, int x, int y,
554578
option.setHeight(25);
555579
option.setWidth(maxWidth);
556580

557-
drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true);
581+
drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true);
558582

559583
option.setPosition(x + panelWidth - maxWidth - 25, y);
560584

@@ -601,7 +625,7 @@ public void render(DrawContext drawContext, RunnableOption option, int x, int y,
601625
option.setHeight(25);
602626
option.setWidth(26);
603627

604-
drawContext.drawText(mc.textRenderer, option.name + ": ", x + 15, y + 25 / 2 - 5, -1, true);
628+
drawContext.drawText(mc.textRenderer, option.name.copy().append(": "), x + 15, y + 25 / 2 - 5, -1, true);
605629

606630
option.setPosition(x + panelWidth - 51, y);
607631

@@ -615,4 +639,9 @@ public void render(DrawContext drawContext, RunnableOption option, int x, int y,
615639
RenderSystem.disableDepthTest();
616640
}
617641
}
642+
643+
@Override
644+
public Skin clone() {
645+
return new MinecraftSkin(panelColor);
646+
}
618647
}

0 commit comments

Comments
 (0)