Skip to content

Commit 80efb0b

Browse files
Replace YACL with ContextMenu. Fix major bugs with MinecraftSkin
1 parent af33897 commit 80efb0b

19 files changed

Lines changed: 249 additions & 268 deletions

File tree

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ dependencies {
3434
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
3535
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
3636

37-
implementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"
38-
3937
//fuzzyscore
4038
implementation 'org.apache.commons:commons-text:1.12.0'
4139
}
@@ -44,7 +42,6 @@ processResources {
4442
inputs.property "version", project.version
4543
inputs.property "loader_version", project.loader_version
4644
inputs.property "minecraft_version", project.minecraft_version
47-
inputs.property "yacl_version", project.yacl_version
4845

4946
filesMatching("fabric.mod.json") {
5047
expand([

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ maven_group = com.tanishisherewith
1818
archives_base_name = dynamichud
1919

2020
# Dependencies
21-
fabric_version=0.145.4+26.1.1
22-
yacl_version=3.9.4+26.1-fabric
21+
fabric_version=0.145.4+26.1.1

src/main/java/com/tanishisherewith/dynamichud/DynamicHUD.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public static void printWarn(String msg) {
4949
public void onInitializeClient() {
5050
printInfo("Initialising DynamicHUD");
5151

52-
//YACL load
53-
GlobalConfig.HANDLER.load();
52+
//Config load
53+
GlobalConfig.loadOrCreate();
5454

5555
ClientLifecycleEvents.CLIENT_STARTED.register((minecraft)-> IntegrationManager.integrate());
5656

src/main/java/com/tanishisherewith/dynamichud/config/GlobalConfig.java

Lines changed: 123 additions & 186 deletions
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.tanishisherewith.dynamichud.internal;
2+
3+
import com.google.gson.TypeAdapter;
4+
import com.google.gson.stream.JsonReader;
5+
import com.google.gson.stream.JsonToken;
6+
import com.google.gson.stream.JsonWriter;
7+
8+
import java.awt.Color;
9+
import java.io.IOException;
10+
11+
public class ColorTypeAdapter extends TypeAdapter<Color> {
12+
@Override
13+
public void write(JsonWriter out, Color color) throws IOException {
14+
if (color == null) {
15+
out.nullValue();
16+
return;
17+
}
18+
out.value(color.getRGB());
19+
}
20+
21+
@Override
22+
public Color read(JsonReader in) throws IOException {
23+
if (in.peek() == JsonToken.NULL) {
24+
in.nextNull();
25+
return null;
26+
}
27+
return new Color(in.nextInt(), true);
28+
}
29+
}

src/main/java/com/tanishisherewith/dynamichud/mixins/OptionsScreenMixin.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
import com.llamalad7.mixinextras.sugar.Local;
44
import com.tanishisherewith.dynamichud.config.GlobalConfig;
5+
import com.tanishisherewith.dynamichud.utils.contextmenu.ContextMenuManager;
6+
import net.minecraft.client.gui.GuiGraphicsExtractor;
57
import net.minecraft.client.gui.components.Button;
68
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
79
import net.minecraft.client.gui.layouts.LinearLayout;
810
import net.minecraft.client.gui.screens.Screen;
911
import net.minecraft.client.gui.screens.TitleScreen;
1012
import net.minecraft.client.gui.screens.options.OptionsScreen;
13+
import net.minecraft.client.input.CharacterEvent;
14+
import net.minecraft.client.input.KeyEvent;
15+
import net.minecraft.client.input.MouseButtonEvent;
1116
import net.minecraft.network.chat.Component;
17+
import org.lwjgl.glfw.GLFW;
1218
import org.spongepowered.asm.mixin.Final;
1319
import org.spongepowered.asm.mixin.Mixin;
1420
import org.spongepowered.asm.mixin.Shadow;
1521
import org.spongepowered.asm.mixin.Unique;
1622
import org.spongepowered.asm.mixin.injection.At;
1723
import org.spongepowered.asm.mixin.injection.Inject;
1824
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
25+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1926

2027
import java.util.function.Supplier;
2128

@@ -45,13 +52,12 @@ protected OptionsScreenMixin(Component title) {
4552
)
4653
private void injectDHLayout(CallbackInfo ci, @Local(ordinal = 0) LinearLayout header) {
4754
this.header = header;
48-
dhButton = openScreenButton(Component.literal("DH"), () -> GlobalConfig.get().createYACLGUI());
55+
dhButton = openScreenButton(Component.literal("DH"), () -> GlobalConfig.get().openMenu());
4956
dhButton.setPosition(this.width / 2 - 150 - 24 - 8, header.getY() + header.getHeight() - 20);
5057
dhButton.setSize(20,20);
5158
this.addRenderableWidget(dhButton);
5259
}
5360

54-
5561
@Inject(
5662
method = "repositionElements",
5763
at = @At(value = "TAIL")

src/main/java/com/tanishisherewith/dynamichud/utils/Util.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static List<Option<?>> filterAndSortOptions(List<Option<?>> source, int
9797
boolean groupMatches = groupScore >= threshold;
9898

9999
if (groupMatches || !filteredChildren.isEmpty()) {
100-
OptionGroup newGroup = new OptionGroup(group.name);
100+
OptionGroup newGroup = new OptionGroup(group.getName());
101101
newGroup.setExpanded(true);
102102
for (Option<?> child : filteredChildren) {
103103
newGroup.addOption(child);
@@ -115,6 +115,7 @@ private static List<Option<?>> filterAndSortOptions(List<Option<?>> source, int
115115
int sb = getEffectiveScore(b, scoreMap);
116116
return Integer.compare(sb, sa);
117117
});
118+
System.out.println("RESULT: " + result);
118119
return result;
119120
}
120121

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void render(GuiGraphicsExtractor graphics, int xPos, int yPos, int mouseX
113113

114114
update();
115115

116-
if (animScale <= 0.0f || newScreenFlag) return;
116+
if (animScale <= 0.01f || newScreenFlag) return;
117117

118118
int screenWidth = DynamicHUD.MC.getWindow().getGuiScaledWidth();
119119
int screenHeight = DynamicHUD.MC.getWindow().getGuiScaledHeight();
@@ -195,11 +195,17 @@ public void toggleDisplay() {
195195
}
196196

197197
protected double getTMouseX(double mouseX) {
198-
return mouseX / getMenuScale();
198+
if(getMenuScale() < 1.0f) {
199+
return DynamicHUD.MC.mouseHandler.xpos() / getMenuScale();
200+
}
201+
return mouseX;
199202
}
200203

201204
protected double getTMouseY(double mouseY) {
202-
return mouseY / getMenuScale();
205+
if(getMenuScale() < 1.0f) {
206+
return DynamicHUD.MC.mouseHandler.ypos() / getMenuScale();
207+
}
208+
return mouseY;
203209
}
204210

205211
public boolean toggleDisplay(WidgetBox widgetBox, double mouseX, double mouseY, int button) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public class ContextMenuProperties {
2222
protected boolean enableAnimations = true;
2323
protected Skin skin = new ClassicSkin();
2424

25-
protected ContextMenuProperties() {
26-
}
25+
protected ContextMenuProperties() {}
2726

2827
public static Builder<?> builder() {
2928
return new Builder<>(new ContextMenuProperties());

src/main/java/com/tanishisherewith/dynamichud/utils/contextmenu/layout/LayoutEngine.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* Manages item spacing, padding, min width, and active layout strategies.
1717
*/
1818
public class LayoutEngine {
19-
private int horizontalPadding = 8;
20-
private int verticalPadding = 4;
21-
private int itemSpacing = 2;
22-
private int minWidth = 80;
19+
private int horizontalPadding;
20+
private int verticalPadding;
21+
private int itemSpacing;
22+
private int minWidth;
2323
private LayoutStrategy activeStrategy;
2424

2525
public LayoutEngine() {
@@ -126,7 +126,7 @@ public void layout(ContextMenu<?> menu, LayoutEngine engine) {
126126
int maxInnerWidth = engine.getMinWidth();
127127
for (Option<?> option : visibleOptions) {
128128
if (!option.shouldRender()) continue;
129-
int preferredWidth = option.getWidth() > 0 ? option.getWidth() : font.width(option.name);
129+
int preferredWidth = option.getWidth() > 0 ? option.getWidth() : font.width(option.getName());
130130
maxInnerWidth = Math.max(maxInnerWidth, preferredWidth);
131131
}
132132

0 commit comments

Comments
 (0)