Remove json, implement mutual exclusives, adjustments & fix bugs
This commit is contained in:
@@ -10,6 +10,7 @@ import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AbilityBindingScreen extends Screen {
|
||||
|
||||
@@ -74,7 +75,7 @@ public class AbilityBindingScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
this.renderBackground(gfx);
|
||||
int x = (width - PANEL_WIDTH) / 2;
|
||||
int y = (height - PANEL_HEIGHT) / 2;
|
||||
|
||||
@@ -10,19 +10,17 @@ import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AbilitySelectScreen extends Screen {
|
||||
|
||||
private final Screen parent;
|
||||
private final int slot; // 1..3
|
||||
|
||||
private final int slot;
|
||||
private final List<AbilityNode> unlockedAbilities = new ArrayList<>();
|
||||
private int page = 0;
|
||||
private static final int PAGE_SIZE = 8;
|
||||
|
||||
private static final int PANEL_WIDTH = 260;
|
||||
private static final int PANEL_HEIGHT = 220;
|
||||
|
||||
@@ -54,7 +52,6 @@ public class AbilitySelectScreen extends Screen {
|
||||
for (int i = start; i < end; i++) {
|
||||
AbilityNode node = unlockedAbilities.get(i);
|
||||
String label = node.getTitle().getString();
|
||||
// Disable if already in this slot to avoid redundant bind
|
||||
boolean alreadyInThisSlot = SkilltreeClientState.getSlotOfAbility(node.getId()) == slot;
|
||||
Button btn = Button.builder(Component.literal(label), b -> select(node))
|
||||
.pos(x + 15, rowY)
|
||||
@@ -67,7 +64,6 @@ public class AbilitySelectScreen extends Screen {
|
||||
addRenderableWidget(btn);
|
||||
rowY += 24;
|
||||
}
|
||||
// paging controls
|
||||
if (page > 0) {
|
||||
addRenderableWidget(Button.builder(Component.literal("< Prev"), b -> {
|
||||
page--;
|
||||
@@ -86,7 +82,6 @@ public class AbilitySelectScreen extends Screen {
|
||||
|
||||
private void select(AbilityNode node) {
|
||||
ResourceLocation id = node.getId();
|
||||
// optimistic client update, then send to server
|
||||
SkilltreeClientState.bindAbilityLocal(slot, id);
|
||||
PacketHandler.CHANNEL.sendToServer(new ServerboundBindAbilityPacket(id, slot));
|
||||
back();
|
||||
@@ -107,7 +102,7 @@ public class AbilitySelectScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
this.renderBackground(gfx);
|
||||
int x = (width - PANEL_WIDTH) / 2;
|
||||
int y = (height - PANEL_HEIGHT) / 2;
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AbilitySlotsScreen extends Screen {
|
||||
private static final int PANEL_WIDTH = 260;
|
||||
@@ -24,7 +25,6 @@ public class AbilitySlotsScreen extends Screen {
|
||||
int buttonW = 80;
|
||||
int buttonH = 20;
|
||||
int buttonX = x + PANEL_WIDTH - buttonW - 15;
|
||||
|
||||
// Y slot = 1
|
||||
addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(1))
|
||||
.pos(buttonX, rowY).size(buttonW, buttonH).build());
|
||||
@@ -34,7 +34,6 @@ public class AbilitySlotsScreen extends Screen {
|
||||
// C slot = 3
|
||||
addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(3))
|
||||
.pos(buttonX, rowY + 70).size(buttonW, buttonH).build());
|
||||
|
||||
addRenderableWidget(Button.builder(Component.literal("Close"), b -> onClose())
|
||||
.pos(x + PANEL_WIDTH - 70, y + PANEL_HEIGHT - 28).size(60, 20).build());
|
||||
}
|
||||
@@ -54,20 +53,17 @@ public class AbilitySlotsScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
|
||||
this.renderBackground(gfx);
|
||||
int x = (width - PANEL_WIDTH) / 2;
|
||||
int y = (height - PANEL_HEIGHT) / 2;
|
||||
|
||||
gfx.fill(0, 0, width, height, 0xAA000000);
|
||||
gfx.fill(x, y, x + PANEL_WIDTH, y + PANEL_HEIGHT, 0xFF222222);
|
||||
gfx.drawCenteredString(font, Component.literal("Ability Slots"), x + PANEL_WIDTH / 2, y + 12, 0xFFFFFF);
|
||||
|
||||
int rowY = y + 40;
|
||||
drawSlotRow(gfx, x + 15, rowY, 1, "Y");
|
||||
drawSlotRow(gfx, x + 15, rowY + 35, 2, "X");
|
||||
drawSlotRow(gfx, x + 15, rowY + 70, 3, "C");
|
||||
|
||||
super.render(gfx, mouseX, mouseY, partialTick);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
modid = SkillEngine.MODID,
|
||||
value = Dist.CLIENT
|
||||
)
|
||||
|
||||
public class ClientEvents {
|
||||
@SubscribeEvent
|
||||
public static void onKeyInput(InputEvent.Key event) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.fretux.skillengine.client;
|
||||
|
||||
import net.fretux.skillengine.SkillEngine;
|
||||
import net.fretux.skillengine.capability.PlayerSkillData;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -65,14 +66,7 @@ public class SkilltreeClientState {
|
||||
}
|
||||
|
||||
public static void bindAbilityLocal(int slot, ResourceLocation abilityId) {
|
||||
int index = slot - 1;
|
||||
if (index < 0 || index >= abilitySlots.length) return;
|
||||
if (abilityId != null) {
|
||||
for (int i = 0; i < abilitySlots.length; i++) {
|
||||
if (abilityId.equals(abilitySlots[i])) abilitySlots[i] = null;
|
||||
}
|
||||
}
|
||||
abilitySlots[index] = abilityId;
|
||||
PlayerSkillData.bindHelperFunc(slot, abilityId, abilitySlots);
|
||||
}
|
||||
|
||||
public static void setAbilitySlots(ResourceLocation[] slots) {
|
||||
|
||||
@@ -17,33 +17,23 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SkilltreeScreen extends Screen {
|
||||
|
||||
private static final int NODE_RADIUS = 12;
|
||||
private static final int ABILITY_RADIUS = 12;
|
||||
|
||||
private static final int OVERLAY_WIDTH = 240;
|
||||
private static final int OVERLAY_HEIGHT = 180;
|
||||
private static final int OVERLAY_CONTENT_HEIGHT = 160;
|
||||
|
||||
private static final float ZOOM_STEP = 0.1f;
|
||||
private static final float LINE_THICKNESS = 2.0f;
|
||||
|
||||
private float zoom = 1.0f;
|
||||
private final float minZoom = 0.5f;
|
||||
private final float maxZoom = 2.0f;
|
||||
|
||||
private double panX = 0;
|
||||
private double panY = 0;
|
||||
|
||||
private boolean dragging = false;
|
||||
private double lastMouseX;
|
||||
private double lastMouseY;
|
||||
|
||||
private SkillNode hoveredNode = null;
|
||||
private SkillNode selectedNode = null;
|
||||
private AbilityNode hoveredAbility = null;
|
||||
@@ -60,7 +50,9 @@ public class SkilltreeScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||
zoom += delta * ZOOM_STEP;
|
||||
zoom += (float) (delta * ZOOM_STEP);
|
||||
float minZoom = 0.5f;
|
||||
float maxZoom = 2.0f;
|
||||
zoom = Mth.clamp(zoom, minZoom, maxZoom);
|
||||
return true;
|
||||
}
|
||||
@@ -74,6 +66,7 @@ public class SkilltreeScreen extends Screen {
|
||||
SkillNode clickedNode = findNodeAt(mouseX, mouseY);
|
||||
if (clickedNode != null) {
|
||||
if (isLockedByExclusivity(clickedNode)) {
|
||||
assert Minecraft.getInstance().player != null;
|
||||
Minecraft.getInstance().player.playSound(
|
||||
net.minecraft.sounds.SoundEvents.VILLAGER_NO, 1f, 1f
|
||||
);
|
||||
@@ -97,8 +90,6 @@ public class SkilltreeScreen extends Screen {
|
||||
return true;
|
||||
}
|
||||
dragging = true;
|
||||
lastMouseX = mouseX;
|
||||
lastMouseY = mouseY;
|
||||
}
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
@@ -125,7 +116,7 @@ public class SkilltreeScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) {
|
||||
public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) {
|
||||
this.renderBackground(gfx);
|
||||
renderSkillPointHeader(gfx);
|
||||
hoveredNode = findNodeAt(mouseX, mouseY);
|
||||
@@ -244,6 +235,7 @@ public class SkilltreeScreen extends Screen {
|
||||
if (!node.getPrereqAttributes().isEmpty()) {
|
||||
tooltip.add(Component.literal("Requirements:")
|
||||
.withStyle(ChatFormatting.GOLD));
|
||||
assert Minecraft.getInstance().player != null;
|
||||
Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS)
|
||||
.ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> {
|
||||
int current = stats.getAttributeLevel(attr);
|
||||
@@ -287,6 +279,7 @@ public class SkilltreeScreen extends Screen {
|
||||
0xFFFFFF
|
||||
);
|
||||
textY[0] += 12;
|
||||
assert Minecraft.getInstance().player != null;
|
||||
Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS)
|
||||
.ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> {
|
||||
int current = stats.getAttributeLevel(attr);
|
||||
|
||||
Reference in New Issue
Block a user