scalable mods
This commit is contained in:
@@ -4,26 +4,25 @@ import net.minecraft.client.gui.DrawContext;
|
|||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
import org.saturnclient.saturnmods.HudMod;
|
import org.saturnclient.saturnmods.HudMod;
|
||||||
import org.saturnclient.saturnmods.ModDimensions;
|
import org.saturnclient.saturnmods.ModDimensions;
|
||||||
import org.saturnclient.saturnmods.ModManager;
|
import org.saturnclient.saturnmods.ModManager;
|
||||||
import org.saturnclient.saturnmods.SaturnMod;
|
import org.saturnclient.saturnmods.SaturnMod;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HudEditor extends Screen {
|
public class HudEditor extends Screen {
|
||||||
private List<HudMod> hudMods = new ArrayList<>();
|
private final List<HudMod> hudMods = new ArrayList<>();
|
||||||
private HudMod draggingMod = null;
|
private HudMod draggingMod = null;
|
||||||
|
private boolean resizing = false;
|
||||||
private int offsetX, offsetY;
|
private int offsetX, offsetY;
|
||||||
|
private static final int RESIZE_MARGIN = 6;
|
||||||
|
|
||||||
public HudEditor() {
|
public HudEditor() {
|
||||||
super(Text.literal("HUD Editor"));
|
super(Text.literal("HUD Editor"));
|
||||||
for (SaturnMod m : ModManager.MODS) {
|
for (SaturnMod m : ModManager.MODS) {
|
||||||
if (m.isEnabled() && m instanceof HudMod) {
|
if (m.isEnabled() && m instanceof HudMod) {
|
||||||
HudMod mod = (HudMod) m;
|
hudMods.add((HudMod) m);
|
||||||
hudMods.add(mod);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,8 +33,20 @@ public class HudEditor extends Screen {
|
|||||||
for (int m = hudMods.size() - 1; m >= 0; m--) {
|
for (int m = hudMods.size() - 1; m >= 0; m--) {
|
||||||
HudMod mod = hudMods.get(m);
|
HudMod mod = hudMods.get(m);
|
||||||
ModDimensions dim = mod.getDimensions();
|
ModDimensions dim = mod.getDimensions();
|
||||||
|
|
||||||
|
// Check if clicking the corner for resizing
|
||||||
|
if (isCorner(mouseX, mouseY, dim)) {
|
||||||
|
draggingMod = mod;
|
||||||
|
resizing = true;
|
||||||
|
offsetX = (int) (mouseX - (dim.x + dim.width * dim.scale));
|
||||||
|
offsetY = (int) (mouseY - (dim.y + dim.height * dim.scale));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if clicking inside the mod
|
||||||
if (isInside(mouseX, mouseY, dim)) {
|
if (isInside(mouseX, mouseY, dim)) {
|
||||||
draggingMod = mod;
|
draggingMod = mod;
|
||||||
|
resizing = false;
|
||||||
offsetX = (int) (mouseX - dim.x);
|
offsetX = (int) (mouseX - dim.x);
|
||||||
offsetY = (int) (mouseY - dim.y);
|
offsetY = (int) (mouseY - dim.y);
|
||||||
return true;
|
return true;
|
||||||
@@ -49,6 +60,7 @@ public class HudEditor extends Screen {
|
|||||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||||
if (button == 0) {
|
if (button == 0) {
|
||||||
draggingMod = null;
|
draggingMod = null;
|
||||||
|
resizing = false;
|
||||||
}
|
}
|
||||||
return super.mouseReleased(mouseX, mouseY, button);
|
return super.mouseReleased(mouseX, mouseY, button);
|
||||||
}
|
}
|
||||||
@@ -57,9 +69,17 @@ public class HudEditor extends Screen {
|
|||||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||||
if (draggingMod != null) {
|
if (draggingMod != null) {
|
||||||
ModDimensions dim = draggingMod.getDimensions();
|
ModDimensions dim = draggingMod.getDimensions();
|
||||||
|
|
||||||
|
if (resizing) {
|
||||||
|
// Scale based on cursor movement
|
||||||
|
float newScale = Math.max(0.5f, ((float) (mouseX - dim.x) / dim.width));
|
||||||
|
dim.scale = newScale;
|
||||||
|
} else {
|
||||||
|
// Move the mod
|
||||||
dim.x = (int) mouseX - offsetX;
|
dim.x = (int) mouseX - offsetX;
|
||||||
dim.y = (int) mouseY - offsetY;
|
dim.y = (int) mouseY - offsetY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,17 +91,32 @@ public class HudEditor extends Screen {
|
|||||||
matrices.push();
|
matrices.push();
|
||||||
|
|
||||||
matrices.translate(dim.x, dim.y, 0);
|
matrices.translate(dim.x, dim.y, 0);
|
||||||
|
|
||||||
matrices.scale(dim.scale, dim.scale, 1.0f);
|
matrices.scale(dim.scale, dim.scale, 1.0f);
|
||||||
|
|
||||||
|
// Render the mod
|
||||||
mod.renderDummy(context);
|
mod.renderDummy(context);
|
||||||
|
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
|
|
||||||
|
// Draw border around mod
|
||||||
|
int borderX = dim.x;
|
||||||
|
int borderY = dim.y;
|
||||||
|
int borderW = (int) (dim.width * dim.scale);
|
||||||
|
int borderH = (int) (dim.height * dim.scale);
|
||||||
|
|
||||||
|
context.drawBorder(borderX, borderY, borderW, borderH, 0xFFFFFFFF); // White border
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInside(double mouseX, double mouseY, ModDimensions dim) {
|
private boolean isInside(double mouseX, double mouseY, ModDimensions dim) {
|
||||||
return mouseX >= dim.x && mouseX <= dim.x + (dim.width * dim.scale) && mouseY >= dim.y
|
return mouseX >= dim.x && mouseX <= dim.x + (dim.width * dim.scale) &&
|
||||||
&& mouseY <= dim.y + (dim.height * dim.scale);
|
mouseY >= dim.y && mouseY <= dim.y + (dim.height * dim.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCorner(double mouseX, double mouseY, ModDimensions dim) {
|
||||||
|
float rightX = dim.x + dim.width * dim.scale;
|
||||||
|
float bottomY = dim.y + dim.height * dim.scale;
|
||||||
|
|
||||||
|
return Math.abs(mouseX - rightX) < RESIZE_MARGIN && Math.abs(mouseY - bottomY) < RESIZE_MARGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,24 @@ public class ModDimensions {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModDimensions(int x, int y, int width, int height) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
public ModDimensions(int x, int y, float scale) {
|
public ModDimensions(int x, int y, float scale) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ModDimensions(int x, int y, int width, int height, float scale) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.saturnclient.saturnmods;
|
package org.saturnclient.saturnmods;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||||
import org.saturnclient.saturnmods.mods.ArmorDisplay;
|
import org.saturnclient.saturnmods.mods.ArmorDisplay;
|
||||||
import org.saturnclient.saturnmods.mods.Coordinates;
|
import org.saturnclient.saturnmods.mods.Coordinates;
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
@@ -16,9 +17,10 @@ public class ModManager {
|
|||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
HudRenderCallback.EVENT.register((context, tickDelta) -> {
|
HudRenderCallback.EVENT.register((context, tickDelta) -> {
|
||||||
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
TextRenderer textRenderer = client.textRenderer;
|
||||||
|
|
||||||
if (textRenderer != null) {
|
if (textRenderer != null && !(client.currentScreen instanceof HudEditor)) {
|
||||||
SaturnClient.textRenderer = textRenderer;
|
SaturnClient.textRenderer = textRenderer;
|
||||||
|
|
||||||
for (SaturnMod m : MODS) {
|
for (SaturnMod m : MODS) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
|
||||||
public class ArmorDisplay implements SaturnMod, HudMod {
|
public class ArmorDisplay implements SaturnMod, HudMod {
|
||||||
private static ModDimensions dimensions = new ModDimensions(120, 40);
|
private static ModDimensions dimensions = new ModDimensions(0, 0, 34, 75);
|
||||||
public static boolean enabled = false;
|
public static boolean enabled = false;
|
||||||
|
|
||||||
private boolean renderItem(DrawContext context, ItemStack item, int y) {
|
private boolean renderItem(DrawContext context, ItemStack item, int y) {
|
||||||
@@ -23,6 +23,7 @@ public class ArmorDisplay implements SaturnMod, HudMod {
|
|||||||
|
|
||||||
context.drawItem(item, 0, y);
|
context.drawItem(item, 0, y);
|
||||||
|
|
||||||
|
if (item.getMaxDamage() > 0)
|
||||||
context.drawText(SaturnClient.textRenderer, "" + (item.getMaxDamage() - item.getDamage()),
|
context.drawText(SaturnClient.textRenderer, "" + (item.getMaxDamage() - item.getDamage()),
|
||||||
16, y + 4, SaturnClient.WHITE, false);
|
16, y + 4, SaturnClient.WHITE, false);
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public class ArmorDisplay implements SaturnMod, HudMod {
|
|||||||
player.getEquippedStack(EquipmentSlot.MAINHAND),
|
player.getEquippedStack(EquipmentSlot.MAINHAND),
|
||||||
};
|
};
|
||||||
|
|
||||||
int y = 75;
|
int y = 60;
|
||||||
|
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
if (renderItem(context, item, y)) {
|
if (renderItem(context, item, y)) {
|
||||||
@@ -59,16 +60,13 @@ public class ArmorDisplay implements SaturnMod, HudMod {
|
|||||||
new ItemStack(Items.DIAMOND_SWORD),
|
new ItemStack(Items.DIAMOND_SWORD),
|
||||||
};
|
};
|
||||||
|
|
||||||
int y = 75;
|
int y = 60;
|
||||||
|
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
if (renderItem(context, item, y)) {
|
if (renderItem(context, item, y)) {
|
||||||
y -= 15;
|
y -= 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dimensions.width = 28;
|
|
||||||
dimensions.height = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|||||||
Reference in New Issue
Block a user