Skip to content

Commit 213b95e

Browse files
committed
Fix wiki button.
1 parent 977d000 commit 213b95e

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package me.melontini.andromeda.common.client;
2+
3+
import com.mojang.blaze3d.systems.RenderSystem;
4+
import net.minecraft.client.gui.DrawContext;
5+
import net.minecraft.client.gui.widget.ButtonWidget;
6+
import net.minecraft.screen.ScreenTexts;
7+
import net.minecraft.text.Text;
8+
import net.minecraft.util.Identifier;
9+
10+
public class UvTexturedButtonWidget extends ButtonWidget {
11+
protected final Identifier texture;
12+
protected final int u;
13+
protected final int v;
14+
protected final int hoveredVOffset;
15+
protected final int textureWidth;
16+
protected final int textureHeight;
17+
18+
public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, ButtonWidget.PressAction pressAction) {
19+
this(x, y, width, height, u, v, height, texture, 256, 256, pressAction);
20+
}
21+
22+
public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, ButtonWidget.PressAction pressAction) {
23+
this(x, y, width, height, u, v, hoveredVOffset, texture, 256, 256, pressAction);
24+
}
25+
26+
public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction) {
27+
this(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, ScreenTexts.EMPTY);
28+
}
29+
30+
public UvTexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, Identifier texture, int textureWidth, int textureHeight, ButtonWidget.PressAction pressAction, Text message) {
31+
super(x, y, width, height, message, pressAction, DEFAULT_NARRATION_SUPPLIER);
32+
this.textureWidth = textureWidth;
33+
this.textureHeight = textureHeight;
34+
this.u = u;
35+
this.v = v;
36+
this.hoveredVOffset = hoveredVOffset;
37+
this.texture = texture;
38+
}
39+
40+
public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
41+
int i = v;
42+
if (!this.isNarratable()) {
43+
i = v + hoveredVOffset * 2;
44+
} else if (this.isSelected()) {
45+
i = v + hoveredVOffset;
46+
}
47+
48+
RenderSystem.enableDepthTest();
49+
context.drawTexture(texture, this.getX(), this.getY(), (float)u, (float)i, width, height, textureWidth, textureHeight);
50+
}
51+
}

src/main/java/me/melontini/andromeda/common/client/config/ModMenuIntegration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
44
import com.terraformersmc.modmenu.api.ModMenuApi;
55
import lombok.CustomLog;
6+
import me.melontini.andromeda.common.client.UvTexturedButtonWidget;
7+
import me.melontini.andromeda.util.Debug;
68
import me.melontini.dark_matter.api.base.util.Support;
9+
import me.melontini.dark_matter.api.glitter.ScreenParticleHelper;
710
import net.fabricmc.api.EnvType;
811
import net.fabricmc.api.Environment;
912
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
1013
import net.minecraft.client.gui.Drawable;
1114
import net.minecraft.client.gui.Element;
1215
import net.minecraft.client.gui.Selectable;
1316
import net.minecraft.client.gui.screen.Screen;
17+
import net.minecraft.client.util.InputUtil;
18+
import net.minecraft.particle.ParticleTypes;
1419
import net.minecraft.text.ClickEvent;
1520
import net.minecraft.text.Style;
1621
import net.minecraft.util.Identifier;
@@ -30,7 +35,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
3035
Screen screen = AutoConfigScreen.get(parent);
3136
ScreenEvents.AFTER_INIT.register((client, screen1, scaledWidth, scaledHeight) -> {
3237
if (screen == screen1) {
33-
/*addDrawableChild(screen, new TexturedButtonWidget(screen.width - 40, 13, 20, 20, 0, 0, 20, WIKI_BUTTON_TEXTURE, 32, 64, button -> {
38+
addDrawableChild(screen, new UvTexturedButtonWidget(screen.width - 40, 13, 20, 20, 0, 0, 20, WIKI_BUTTON_TEXTURE, 32, 64, button -> {
3439
if (InputUtil.isKeyPressed(client.getWindow().getHandle(), InputUtil.GLFW_KEY_LEFT_SHIFT)) {
3540
Debug.load();
3641
Support.runWeak(EnvType.CLIENT, () -> () -> ScreenParticleHelper.addScreenParticles(
@@ -40,7 +45,7 @@ public ConfigScreenFactory<?> getModConfigScreenFactory() {
4045
} else {
4146
screen.handleTextClick(WIKI_LINK);
4247
}
43-
}));*/
48+
}));
4449
}
4550
});
4651
return screen;

0 commit comments

Comments
 (0)