mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 04:57:27 +00:00
Magic GUI WIP Push
This commit is contained in:
1 parent
758485b4d0
commit
58ff772e3c
18 files changed
+1002
-81
No files matched your search
@@ -44,6 +44,7 @@ import kamkeel.npcs.network.packets.request.jobs.JobSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerAddPacket;
|
||||
import kamkeel.npcs.network.packets.request.jobs.JobSpawnerRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.*;
|
||||
import kamkeel.npcs.network.packets.request.magic.*;
|
||||
import kamkeel.npcs.network.packets.request.mainmenu.*;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.naturalspawns.NaturalSpawnGetPacket;
|
||||
@@ -334,6 +335,13 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new ProfileRenamePacket());
|
||||
REQUEST_PACKET.registerPacket(new ProfileChangePacket());
|
||||
|
||||
// Job Packets
|
||||
REQUEST_PACKET.registerPacket(new MagicCycleRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicCycleSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new MagicRemovePacket());
|
||||
|
||||
// Other Packets
|
||||
REQUEST_PACKET.registerPacket(new IsGuiOpenInform());
|
||||
REQUEST_PACKET.registerPacket(new GuiRequestPacket());
|
||||
|
||||
@@ -195,5 +195,5 @@ public enum EnumRequestPacket {
|
||||
ProfileCreate,
|
||||
ProfileRemove,
|
||||
ProfileRename,
|
||||
ProfileChange
|
||||
MagicCycleRemove, MagicCycleSave, MagicGetAll, MagicRemove, MagicSave, ProfileChange
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MagicCycleRemovePacket extends AbstractPacket {
|
||||
|
||||
public static String packetName = "Request|MagicCycleRemove";
|
||||
|
||||
private int cycleId;
|
||||
|
||||
public MagicCycleRemovePacket() { }
|
||||
|
||||
public MagicCycleRemovePacket(int cycleId) {
|
||||
this.cycleId = cycleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicCycleRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(cycleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
int id = in.readInt();
|
||||
MagicController.getInstance().cycles.remove(id);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MagicCycleSavePacket extends AbstractPacket {
|
||||
|
||||
public static String packetName = "Request|MagicCycleSave";
|
||||
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public MagicCycleSavePacket() { }
|
||||
|
||||
public MagicCycleSavePacket(NBTTagCompound compound) {
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicCycleSave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeNBT(out, compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
cycle.readNBT(comp);
|
||||
MagicController.getInstance().cycles.put(cycle.id, cycle);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MagicGetAllPacket extends AbstractPacket {
|
||||
|
||||
public static String packetName = "Request|MagicGetAll";
|
||||
|
||||
public MagicGetAllPacket() { }
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicGetAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
StringBuilder cycleNames = new StringBuilder();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
cycleNames.append(cycle.title).append(",");
|
||||
}
|
||||
compound.setString("CycleNames", cycleNames.toString());
|
||||
// Build comma-separated list of magic names.
|
||||
StringBuilder magicNames = new StringBuilder();
|
||||
for (Magic magic : MagicController.getInstance().magics.values()) {
|
||||
magicNames.append(magic.name).append(",");
|
||||
}
|
||||
compound.setString("MagicNames", magicNames.toString());
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MagicRemovePacket extends AbstractPacket {
|
||||
|
||||
public static String packetName = "Request|MagicRemove";
|
||||
|
||||
private int magicId;
|
||||
|
||||
public MagicRemovePacket() { }
|
||||
|
||||
public MagicRemovePacket(int magicId) {
|
||||
this.magicId = magicId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(magicId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
int id = in.readInt();
|
||||
MagicController.getInstance().magics.remove(id);
|
||||
MagicController.getInstance().saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package kamkeel.npcs.network.packets.request.magic;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MagicSavePacket extends AbstractPacket {
|
||||
|
||||
public static String packetName = "Request|MagicSave";
|
||||
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public MagicSavePacket() { }
|
||||
|
||||
public MagicSavePacket(NBTTagCompound compound) {
|
||||
this.compound = compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.MagicSave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeNBT(out, compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
NBTTagCompound comp = ByteBufUtils.readNBT(in);
|
||||
Magic magic = new Magic();
|
||||
magic.readNBT(comp);
|
||||
MagicController.getInstance().saveMagic(magic);
|
||||
}
|
||||
}
|
||||
@@ -297,6 +297,9 @@ public class ClientProxy extends CommonProxy {
|
||||
else if (gui == EnumGuiType.ManageLinked)
|
||||
return new GuiNPCManageLinked(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageMagic)
|
||||
return new GuiNpcManageMagic(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageTransport)
|
||||
return new GuiNPCManageTransporters(npc);
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import noppes.npcs.client.gui.GuiMagicMap;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class GuiNPCManageMagic extends GuiNPCInterface2 {
|
||||
|
||||
private GuiMagicMap magicMap;
|
||||
|
||||
public GuiNPCManageMagic(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
// Position the map in a designated area (e.g., right panel)
|
||||
int mapX = guiLeft + xSize - 230 + 10;
|
||||
int mapY = guiTop + 10;
|
||||
int mapWidth = 210;
|
||||
int mapHeight = 200;
|
||||
|
||||
magicMap = new GuiMagicMap(this, mapX, mapY, mapWidth, mapHeight);
|
||||
addDiagram(0, magicMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (magicMap != null) {
|
||||
magicMap.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(net.minecraft.client.gui.GuiButton button) {
|
||||
// your existing action handling
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// your save logic
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicCycleRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicCycleSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicSavePacket;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicCycleEdit;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicEdit;
|
||||
import noppes.npcs.client.gui.magic.SubGuiMagicInteractionsEdit;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import static noppes.npcs.client.gui.player.inventory.GuiCNPCInventory.specialIcons;
|
||||
|
||||
public class GuiNpcManageMagic extends GuiNPCInterface2 implements ISubGuiListener, ICustomScrollListener, IGuiData {
|
||||
|
||||
private GuiCustomScroll leftScroll; // left scroll for cycles (viewByCycle)
|
||||
private GuiCustomScroll rightScroll; // right scroll for magics
|
||||
|
||||
// Toggle mode: false = view all magics; true = view by cycle
|
||||
private boolean viewByCycle = false;
|
||||
|
||||
private HashMap<String, Integer> cycleData = new HashMap<>();
|
||||
private HashMap<String, Integer> magicData = new HashMap<>();
|
||||
|
||||
private MagicCycle selectedCycle;
|
||||
private Magic selectedMagic;
|
||||
|
||||
// Divider/resizing variables (only used when viewByCycle is true)
|
||||
private boolean isResizing = false;
|
||||
private int initialDragX = 0;
|
||||
private int dividerOffset = 143; // initial offset from regionLeft
|
||||
private final int dividerWidth = 5;
|
||||
private final int minScrollWidth = 50;
|
||||
private int dividerLineHeight = 20;
|
||||
private int dividerLineYOffset = 0;
|
||||
|
||||
// Search strings – IDs 55 and 66 are used for search text fields
|
||||
private String cycleSearch = "";
|
||||
private String magicSearch = "";
|
||||
|
||||
public GuiNpcManageMagic(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
PacketClient.sendClient(new MagicGetAllPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int y = guiTop + 5;
|
||||
|
||||
addButton(new GuiToggleButton(50, guiLeft + 368, guiTop + ySize - 10, viewByCycle));
|
||||
((GuiToggleButton) getButton(50)).setTextureOff(specialIcons).setTextureOffPos( 16, 0);
|
||||
((GuiToggleButton) getButton(50)).setIconTexture(specialIcons).setIconPos( 16, 16, 16, 0 );
|
||||
|
||||
if (!viewByCycle) {
|
||||
// Define horizontal region (similar to your quest GUI)
|
||||
int regionLeft = guiLeft + 64;
|
||||
int regionRight = guiLeft + 355;
|
||||
int dividerX = regionLeft + dividerOffset;
|
||||
|
||||
// Left scroll (cycles)
|
||||
if (leftScroll == null) {
|
||||
leftScroll = new GuiCustomScroll(this, 0, 0);
|
||||
}
|
||||
leftScroll.guiLeft = regionLeft;
|
||||
leftScroll.guiTop = y;
|
||||
leftScroll.setSize(dividerX - regionLeft, 185);
|
||||
this.addScroll(leftScroll);
|
||||
|
||||
// Right scroll (magics for selected cycle)
|
||||
if (rightScroll == null) {
|
||||
rightScroll = new GuiCustomScroll(this, 1, 0);
|
||||
}
|
||||
rightScroll.guiLeft = dividerX + dividerWidth;
|
||||
rightScroll.guiTop = y;
|
||||
rightScroll.setSize(regionRight - (dividerX + dividerWidth), 185);
|
||||
this.addScroll(rightScroll);
|
||||
|
||||
// Add search bars below each scroll – using text field IDs 55 and 66
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, regionLeft, y + 185 + 3, dividerX - regionLeft, 20, cycleSearch));
|
||||
addTextField(new GuiNpcTextField(66, this, fontRendererObj, dividerX + dividerWidth, y + 185 + 3, regionRight - (dividerX + dividerWidth), 20, magicSearch));
|
||||
|
||||
// Left side cycle management buttons (mirroring your quest GUI style)
|
||||
addButton(new GuiNpcButton(10, guiLeft + 3, guiTop + 8, 58, 20, "Cycles"));
|
||||
getButton(10).setEnabled(false);
|
||||
addButton(new GuiNpcButton(4, guiLeft + 3, guiTop + 38, 58, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(5, guiLeft + 3, guiTop + 61, 58, 20, "gui.remove"));
|
||||
addButton(new GuiNpcButton(6, guiLeft + 3, guiTop + 94, 58, 20, "gui.edit"));
|
||||
|
||||
// Right side magic management buttons
|
||||
addButton(new GuiNpcButton(33, guiLeft + 358, guiTop + 8, 58, 20, "Magics"));
|
||||
getButton(33).setEnabled(false);
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
|
||||
|
||||
addButton(new GuiNpcButton(2, guiLeft + 358, guiTop + 94, 58, 20, "gui.edit"));
|
||||
} else {
|
||||
// Default mode: one list for all magics plus one search bar
|
||||
if (rightScroll == null) {
|
||||
rightScroll = new GuiCustomScroll(this, 1, 0);
|
||||
}
|
||||
rightScroll.guiLeft = guiLeft + 10;
|
||||
rightScroll.guiTop = y;
|
||||
rightScroll.setSize(xSize - 75, 185);
|
||||
this.addScroll(rightScroll);
|
||||
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 10, y + 185 + 3, xSize - 75, 20, magicSearch));
|
||||
|
||||
addButton(new GuiNpcButton(33, guiLeft + 358, guiTop + 8, 58, 20, "Magics"));
|
||||
getButton(33).setEnabled(false);
|
||||
|
||||
// Global magic management buttons
|
||||
addButton(new GuiNpcButton(0, guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
|
||||
|
||||
addButton(new GuiNpcButton(2, guiLeft + 358, guiTop + 94, 58, 20, "gui.edit"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
if (!viewByCycle && !hasSubGui()) {
|
||||
int regionLeft = guiLeft + 64;
|
||||
int dividerX = regionLeft + dividerOffset;
|
||||
int regionTop = guiTop + 30;
|
||||
int regionHeight = 185;
|
||||
int handleTop = regionTop + (regionHeight - dividerLineHeight) / 2 + dividerLineYOffset;
|
||||
drawRect(dividerX + 1, handleTop, dividerX + dividerWidth - 1, handleTop + dividerLineHeight, 0xFF707070);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!viewByCycle && !hasSubGui()) {
|
||||
int regionLeft = guiLeft + 64;
|
||||
int dividerX = regionLeft + dividerOffset;
|
||||
int regionTop = guiTop + 30;
|
||||
int regionHeight = 185;
|
||||
int handleTop = regionTop + (regionHeight - dividerLineHeight) / 2 + dividerLineYOffset;
|
||||
int handleBottom = handleTop + dividerLineHeight;
|
||||
if (mouseX >= dividerX && mouseX <= dividerX + dividerWidth &&
|
||||
mouseY >= handleTop && mouseY <= handleBottom) {
|
||||
isResizing = true;
|
||||
resizingActive = true;
|
||||
initialDragX = mouseX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (!viewByCycle && isResizing) {
|
||||
int dx = mouseX - initialDragX;
|
||||
initialDragX = mouseX;
|
||||
dividerOffset += dx;
|
||||
int regionLeft = guiLeft + 64;
|
||||
int regionRight = guiLeft + 355;
|
||||
int minOffset = minScrollWidth;
|
||||
int maxOffset = (regionRight - regionLeft) - dividerWidth - minScrollWidth;
|
||||
if (dividerOffset < minOffset) {
|
||||
dividerOffset = minOffset;
|
||||
}
|
||||
if (dividerOffset > maxOffset) {
|
||||
dividerOffset = maxOffset;
|
||||
}
|
||||
int dividerX = regionLeft + dividerOffset;
|
||||
leftScroll.setSize(dividerX - regionLeft, 185);
|
||||
rightScroll.guiLeft = dividerX + dividerWidth;
|
||||
rightScroll.setSize(regionRight - (dividerX + dividerWidth), 185);
|
||||
// Update search field sizes
|
||||
if (getTextField(55) != null) {
|
||||
getTextField(55).width = dividerX - regionLeft;
|
||||
}
|
||||
if (getTextField(66) != null) {
|
||||
getTextField(66).width = regionRight - (dividerX + dividerWidth);
|
||||
getTextField(66).xPosition = dividerX + dividerWidth;
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (isResizing) {
|
||||
isResizing = false;
|
||||
resizingActive = false;
|
||||
return;
|
||||
}
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (!viewByCycle) {
|
||||
if (getTextField(55) != null && getTextField(55).isFocused()) {
|
||||
if (!cycleSearch.equals(getTextField(55).getText())) {
|
||||
cycleSearch = getTextField(55).getText().toLowerCase();
|
||||
leftScroll.resetScroll();
|
||||
leftScroll.setList(getCycleSearch());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (getTextField(66) != null && getTextField(66).isFocused()) {
|
||||
if (!magicSearch.equals(getTextField(66).getText())) {
|
||||
magicSearch = getTextField(66).getText().toLowerCase();
|
||||
rightScroll.resetScroll();
|
||||
rightScroll.setList(getMagicSearch());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getCycleSearch() {
|
||||
if (cycleSearch.isEmpty()) {
|
||||
return new ArrayList<>(cycleData.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : cycleData.keySet()) {
|
||||
if (name.toLowerCase().contains(cycleSearch))
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<String> getMagicSearch() {
|
||||
if (magicSearch.isEmpty()) {
|
||||
return new ArrayList<>(magicData.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : magicData.keySet()) {
|
||||
if (name.toLowerCase().contains(magicSearch))
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
switch (button.id) {
|
||||
case 50:
|
||||
viewByCycle = !viewByCycle;
|
||||
initGui();
|
||||
return;
|
||||
// Left side: Cycle management
|
||||
case 4: // Add Cycle
|
||||
{
|
||||
NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
cycleCompound.setString("Title", "New Cycle");
|
||||
PacketClient.sendClient(new MagicCycleSavePacket(cycleCompound));
|
||||
}
|
||||
break;
|
||||
case 5: // Remove Cycle
|
||||
if (selectedCycle != null) {
|
||||
PacketClient.sendClient(new MagicCycleRemovePacket(selectedCycle.id));
|
||||
}
|
||||
break;
|
||||
case 6: // Edit Cycle
|
||||
if (selectedCycle != null) {
|
||||
setSubGui(new SubGuiMagicCycleEdit(selectedCycle));
|
||||
}
|
||||
break;
|
||||
// Right side: Magic management (in viewByCycle)
|
||||
case 0: // Add Magic to selected cycle
|
||||
if (selectedCycle != null) {
|
||||
NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
magicCompound.setString("Name", "New Magic");
|
||||
magicCompound.setInteger("CycleID", selectedCycle.id);
|
||||
magicCompound.setInteger("Index", 0);
|
||||
magicCompound.setInteger("Priority", 0);
|
||||
PacketClient.sendClient(new MagicSavePacket(magicCompound));
|
||||
}
|
||||
break;
|
||||
case 1: // Edit Magic
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
case 2: // Remove Magic
|
||||
if (selectedMagic != null) {
|
||||
PacketClient.sendClient(new MagicRemovePacket(selectedMagic.id));
|
||||
}
|
||||
break;
|
||||
case 3: // Edit Interactions
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicInteractionsEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
// Default mode buttons (global view)
|
||||
case 21:
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
if (selectedMagic != null) {
|
||||
PacketClient.sendClient(new MagicRemovePacket(selectedMagic.id));
|
||||
}
|
||||
break;
|
||||
case 23:
|
||||
if (selectedMagic != null) {
|
||||
setSubGui(new SubGuiMagicInteractionsEdit(selectedMagic));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int id, int index, int clickType, GuiCustomScroll scroll) {
|
||||
if (!viewByCycle) {
|
||||
if (scroll.id == 0) { // Left scroll: cycles
|
||||
String cycleName = scroll.getSelected();
|
||||
for (MagicCycle cycle : MagicController.getInstance().cycles.values()) {
|
||||
if (cycle.title.equals(cycleName)) {
|
||||
selectedCycle = cycle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Update right scroll with magics in selected cycle
|
||||
if (selectedCycle != null) {
|
||||
List<String> magicNames = new ArrayList<>();
|
||||
for (Integer magicId : selectedCycle.associations.keySet()) {
|
||||
Magic m = MagicController.getInstance().magics.get(magicId);
|
||||
if (m != null) {
|
||||
magicNames.add(m.name);
|
||||
}
|
||||
}
|
||||
rightScroll.setList(magicNames);
|
||||
}
|
||||
} else if (scroll.id == 1) { // Right scroll: magics
|
||||
String magicName = scroll.getSelected();
|
||||
for (Magic m : MagicController.getInstance().magics.values()) {
|
||||
if (m.name.equals(magicName)) {
|
||||
selectedMagic = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (scroll.id == 1) {
|
||||
String magicName = scroll.getSelected();
|
||||
for (Magic m : MagicController.getInstance().magics.values()) {
|
||||
if (m.name.equals(magicName)) {
|
||||
selectedMagic = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
PacketClient.sendClient(new MagicGetAllPacket());
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
cycleData.clear();
|
||||
magicData.clear();
|
||||
if (compound.hasKey("CycleNames")) {
|
||||
String cyclesStr = compound.getString("CycleNames");
|
||||
String[] names = cyclesStr.split(",");
|
||||
int id = 0;
|
||||
for (String name : names) {
|
||||
if (!name.trim().isEmpty()) {
|
||||
cycleData.put(name.trim(), id++);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (compound.hasKey("MagicNames")) {
|
||||
String magicsStr = compound.getString("MagicNames");
|
||||
String[] names = magicsStr.split(",");
|
||||
int id = 0;
|
||||
for (String name : names) {
|
||||
if (!name.trim().isEmpty()) {
|
||||
magicData.put(name.trim(), id++);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!viewByCycle) {
|
||||
leftScroll.setList(new ArrayList<>(cycleData.keySet()));
|
||||
}
|
||||
rightScroll.setList(new ArrayList<>(magicData.keySet()));
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package noppes.npcs.client.gui.magic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicCycleSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.data.MagicAssociation;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class SubGuiMagicCycleEdit extends SubGuiInterface implements ITextfieldListener {
|
||||
|
||||
private MagicCycle cycle;
|
||||
private GuiCustomScroll assocScroll;
|
||||
private List<String> assocList = new ArrayList<>();
|
||||
|
||||
public SubGuiMagicCycleEdit(MagicCycle cycle) {
|
||||
this.cycle = cycle;
|
||||
setBackground("menubg.png");
|
||||
xSize = 360;
|
||||
ySize = 240;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
addLabel(new GuiNpcLabel(0, "Cycle: " + cycle.title, guiLeft + 4, guiTop + 4));
|
||||
|
||||
// Build list of associations in the cycle (format: "MagicID: X | Index: Y | Priority: Z")
|
||||
assocList.clear();
|
||||
for (Map.Entry<Integer, MagicAssociation> entry : cycle.associations.entrySet()) {
|
||||
MagicAssociation assoc = entry.getValue();
|
||||
assocList.add("MagicID: " + entry.getKey() + " | Index: " + assoc.index + " | Priority: " + assoc.priority);
|
||||
}
|
||||
if (assocScroll == null) {
|
||||
assocScroll = new GuiCustomScroll(this, 0, 0);
|
||||
}
|
||||
assocScroll.guiLeft = guiLeft + 4;
|
||||
assocScroll.guiTop = guiTop + 20;
|
||||
assocScroll.setSize(200, 100);
|
||||
assocScroll.setList(assocList);
|
||||
this.addScroll(assocScroll);
|
||||
|
||||
// Text fields for editing the selected association’s index and priority
|
||||
addLabel(new GuiNpcLabel(1, "Index:", guiLeft + 210, guiTop + 30));
|
||||
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 250, guiTop + 26, 50, 20, ""));
|
||||
addLabel(new GuiNpcLabel(2, "Priority:", guiLeft + 210, guiTop + 60));
|
||||
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 250, guiTop + 56, 50, 20, ""));
|
||||
|
||||
// Buttons to update or remove the selected association
|
||||
addButton(new GuiNpcButton(10, guiLeft + 210, guiTop + 90, 70, 20, "Update"));
|
||||
addButton(new GuiNpcButton(11, guiLeft + 290, guiTop + 90, 70, 20, "Remove"));
|
||||
|
||||
// Done button to save cycle changes via packet
|
||||
addButton(new GuiNpcButton(99, guiLeft + 4, guiTop + 130, 60, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 10) { // Update association
|
||||
String selected = assocScroll.getSelected();
|
||||
if (selected != null && !selected.isEmpty()) {
|
||||
try {
|
||||
String[] parts = selected.split(" ");
|
||||
int magicId = Integer.parseInt(parts[1]);
|
||||
MagicAssociation assoc = cycle.associations.get(magicId);
|
||||
if (assoc != null) {
|
||||
int newIndex = Integer.parseInt(getTextField(1).getText());
|
||||
int newPriority = Integer.parseInt(getTextField(2).getText());
|
||||
assoc.index = newIndex;
|
||||
assoc.priority = newPriority;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle parse error if needed.
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
if (button.id == 11) { // Remove association
|
||||
String selected = assocScroll.getSelected();
|
||||
if (selected != null && !selected.isEmpty()) {
|
||||
try {
|
||||
String[] parts = selected.split(" ");
|
||||
int magicId = Integer.parseInt(parts[1]);
|
||||
cycle.associations.remove(magicId);
|
||||
} catch (NumberFormatException e) {
|
||||
// Handle error if needed.
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
if (button.id == 99) { // Done: send save packet
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
cycle.writeNBT(compound);
|
||||
PacketClient.sendClient(new MagicCycleSavePacket(compound));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package noppes.npcs.client.gui.magic;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.magic.MagicSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
|
||||
public class SubGuiMagicEdit extends SubGuiInterface implements ITextfieldListener {
|
||||
|
||||
private Magic magic;
|
||||
|
||||
public SubGuiMagicEdit(Magic magic) {
|
||||
this.magic = magic;
|
||||
setBackground("menubg.png");
|
||||
xSize = 360;
|
||||
ySize = 240;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
// Display the Magic's ID
|
||||
addLabel(new GuiNpcLabel(0, "ID: " + magic.id, guiLeft + 4, guiTop + 4));
|
||||
|
||||
// Edit Magic Name
|
||||
addLabel(new GuiNpcLabel(1, "Name:", guiLeft + 4, guiTop + 28));
|
||||
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 60, guiTop + 24, 200, 20, magic.name));
|
||||
|
||||
// Edit Magic Display Name
|
||||
addLabel(new GuiNpcLabel(2, "Display Name:", guiLeft + 4, guiTop + 52));
|
||||
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 90, guiTop + 48, 200, 20, magic.displayName));
|
||||
|
||||
// Button to edit interactions
|
||||
addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 80, 120, 20, "Edit Interactions"));
|
||||
|
||||
// Done button to save changes
|
||||
addButton(new GuiNpcButton(99, guiLeft + 4, guiTop + 110, 60, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 10) {
|
||||
setSubGui(new SubGuiMagicInteractionsEdit(magic));
|
||||
}
|
||||
if (button.id == 99) {
|
||||
// Update magic fields and send save packet
|
||||
magic.name = getTextField(1).getText();
|
||||
magic.displayName = getTextField(2).getText();
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
magic.writeNBT(compound);
|
||||
PacketClient.sendClient(new MagicSavePacket(compound));
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package noppes.npcs.client.gui.magic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class SubGuiMagicInteractionsEdit extends SubGuiInterface implements ITextfieldListener {
|
||||
|
||||
private Magic magic;
|
||||
private GuiCustomScroll interactionsScroll;
|
||||
private List<String> interactionsList = new ArrayList<>();
|
||||
|
||||
public SubGuiMagicInteractionsEdit(Magic magic) {
|
||||
this.magic = magic;
|
||||
setBackground("menubg.png");
|
||||
xSize = 360;
|
||||
ySize = 280;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
addLabel(new GuiNpcLabel(0, "Edit Interactions: " + magic.name, guiLeft + 4, guiTop + 4));
|
||||
|
||||
// Build interactions list from magic.interactions map.
|
||||
interactionsList.clear();
|
||||
for (Map.Entry<Integer, Float> entry : magic.interactions.entrySet()) {
|
||||
interactionsList.add("MagicID: " + entry.getKey() + " | Percent: " + entry.getValue());
|
||||
}
|
||||
if (interactionsScroll == null) {
|
||||
interactionsScroll = new GuiCustomScroll(this, 0, 0);
|
||||
}
|
||||
interactionsScroll.guiLeft = guiLeft + 4;
|
||||
interactionsScroll.guiTop = guiTop + 20;
|
||||
interactionsScroll.setSize(200, 100);
|
||||
interactionsScroll.setList(interactionsList);
|
||||
this.addScroll(interactionsScroll);
|
||||
|
||||
// Text fields for adding/updating an interaction
|
||||
addLabel(new GuiNpcLabel(1, "Target Magic ID:", guiLeft + 210, guiTop + 30));
|
||||
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 310, guiTop + 26, 40, 20, ""));
|
||||
addLabel(new GuiNpcLabel(2, "Percent:", guiLeft + 210, guiTop + 60));
|
||||
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 310, guiTop + 56, 40, 20, ""));
|
||||
|
||||
// Buttons to add, update, or remove an interaction
|
||||
addButton(new GuiNpcButton(10, guiLeft + 210, guiTop + 90, 70, 20, "Add"));
|
||||
addButton(new GuiNpcButton(11, guiLeft + 290, guiTop + 90, 70, 20, "Update"));
|
||||
addButton(new GuiNpcButton(12, guiLeft + 210, guiTop + 115, 70, 20, "Remove"));
|
||||
|
||||
// Done button to send changes
|
||||
addButton(new GuiNpcButton(99, guiLeft + 4, guiTop + 240, 60, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 10) { // Add interaction
|
||||
try {
|
||||
int targetId = Integer.parseInt(getTextField(1).getText());
|
||||
float percent = Float.parseFloat(getTextField(2).getText());
|
||||
magic.interactions.put(targetId, percent);
|
||||
} catch (NumberFormatException e) { }
|
||||
initGui();
|
||||
}
|
||||
if (button.id == 11) { // Update interaction
|
||||
String selected = interactionsScroll.getSelected();
|
||||
if (selected != null && !selected.isEmpty()) {
|
||||
try {
|
||||
int targetId = Integer.parseInt(selected.split(" ")[1]);
|
||||
float percent = Float.parseFloat(getTextField(2).getText());
|
||||
magic.interactions.put(targetId, percent);
|
||||
} catch (NumberFormatException e) { }
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
if (button.id == 12) { // Remove interaction
|
||||
String selected = interactionsScroll.getSelected();
|
||||
if (selected != null && !selected.isEmpty()) {
|
||||
try {
|
||||
int targetId = Integer.parseInt(selected.split(" ")[1]);
|
||||
magic.interactions.remove(targetId);
|
||||
} catch (NumberFormatException e) { }
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
if (button.id == 99) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(noppes.npcs.client.gui.util.GuiNpcTextField textField) {
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
private GuiNpcSquareButton animationButton;
|
||||
private GuiNpcSquareButton tagButton;
|
||||
private GuiNpcSquareButton effectsButton;
|
||||
private GuiNpcSquareButton magicsButton;
|
||||
|
||||
public GuiNPCGlobalMainMenu(EntityNPCInterface npc) {
|
||||
super(npc, 5);
|
||||
@@ -85,6 +86,10 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
registerButton(effectsButton = new GuiNpcSquareButton(19, 0, 0, 20, "global.customeffects", 0xFF333333));
|
||||
effectsButton.setIconPos(24, 24, 24, 56).setIconTexture(specialIcons);
|
||||
|
||||
registerButton(magicsButton = new GuiNpcSquareButton(20, 0, 0, 20, "global.magic", 0xFF333333));
|
||||
magicsButton.setIconPos(24, 24, 48, 56).setIconTexture(specialIcons);
|
||||
|
||||
|
||||
// Layout composite buttons optimally.
|
||||
layoutButtons();
|
||||
// Add all composite buttons to the GUI.
|
||||
@@ -220,6 +225,9 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
if (id == 16) {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageLinked);
|
||||
}
|
||||
if (id == 20) {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageMagic);
|
||||
}
|
||||
if (id == 19) {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageEffects);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import noppes.npcs.scripted.ScriptBlock;
|
||||
|
||||
public enum EnumGuiType {
|
||||
MainMenuDisplay,
|
||||
MainMenuInv,
|
||||
@@ -58,6 +60,7 @@ public enum EnumGuiType {
|
||||
CompanionTalent,
|
||||
CompanionTrader,
|
||||
ManageLinked,
|
||||
ManageMagic,
|
||||
CustomGui,
|
||||
ScriptItem,
|
||||
ScriptBlock,
|
||||
|
||||
@@ -8,7 +8,7 @@ import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicCategory;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import noppes.npcs.controllers.data.MagicAssociation;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
@@ -24,10 +24,10 @@ public class MagicController {
|
||||
public HashMap<Integer, Magic> magics = new HashMap<>();
|
||||
public HashMap<Integer, Magic> magicSync = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, MagicCategory> categories = new HashMap<>();
|
||||
public HashMap<Integer, MagicCategory> categoriesSync = new HashMap<>();
|
||||
public HashMap<Integer, MagicCycle> cycles = new HashMap<>();
|
||||
public HashMap<Integer, MagicCycle> cyclesSync = new HashMap<>();
|
||||
|
||||
public int lastUsedCategoryID = 0;
|
||||
public int lastUsedCycleID = 0;
|
||||
private int lastUsedID = 0;
|
||||
|
||||
private static MagicController instance;
|
||||
@@ -44,8 +44,8 @@ public class MagicController {
|
||||
return magics.get(magicId);
|
||||
}
|
||||
|
||||
public MagicCategory getCategory(int categoryId) {
|
||||
return categories.get(categoryId);
|
||||
public MagicCycle getCycle(int cycleID) {
|
||||
return cycles.get(cycleID);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
@@ -136,7 +136,7 @@ public class MagicController {
|
||||
public void loadMagic(DataInputStream stream) throws IOException {
|
||||
NBTTagCompound compound = CompressedStreamTools.read(stream);
|
||||
lastUsedID = compound.getInteger("lastID");
|
||||
lastUsedCategoryID = compound.getInteger("lastCatID");
|
||||
lastUsedCycleID = compound.getInteger("lastCatID");
|
||||
|
||||
// Load magics
|
||||
magics.clear();
|
||||
@@ -149,13 +149,13 @@ public class MagicController {
|
||||
}
|
||||
|
||||
// Load categories
|
||||
categories.clear();
|
||||
NBTTagList catList = compound.getTagList("Categories", 10);
|
||||
cycles.clear();
|
||||
NBTTagList catList = compound.getTagList("Cycles", 10);
|
||||
for (int i = 0; i < catList.tagCount(); i++) {
|
||||
NBTTagCompound catCompound = catList.getCompoundTagAt(i);
|
||||
MagicCategory cat = new MagicCategory();
|
||||
MagicCycle cat = new MagicCycle();
|
||||
cat.readNBT(catCompound);
|
||||
categories.put(cat.id, cat);
|
||||
cycles.put(cat.id, cat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,16 +167,16 @@ public class MagicController {
|
||||
magicList.appendTag(magCompound);
|
||||
}
|
||||
NBTTagList catList = new NBTTagList();
|
||||
for (MagicCategory cat : categories.values()) {
|
||||
for (MagicCycle cat : cycles.values()) {
|
||||
NBTTagCompound catCompound = new NBTTagCompound();
|
||||
cat.writeNBT(catCompound);
|
||||
catList.appendTag(catCompound);
|
||||
}
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setInteger("lastID", lastUsedID);
|
||||
compound.setInteger("lastCatID", lastUsedCategoryID);
|
||||
compound.setInteger("lastCycleID", lastUsedCycleID);
|
||||
compound.setTag("Magics", magicList);
|
||||
compound.setTag("Categories", catList);
|
||||
compound.setTag("Cycles", catList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -232,21 +232,21 @@ public class MagicController {
|
||||
|
||||
// === Category management methods ===
|
||||
|
||||
public void addCategory(MagicCategory category) {
|
||||
public void addCycle(MagicCycle category) {
|
||||
if (category.id < 0) {
|
||||
lastUsedCategoryID++;
|
||||
category.id = lastUsedCategoryID;
|
||||
lastUsedCycleID++;
|
||||
category.id = lastUsedCycleID;
|
||||
} else {
|
||||
while (containsCategoryName(category.title))
|
||||
category.title += "_";
|
||||
}
|
||||
categories.put(category.id, category);
|
||||
cycles.put(category.id, category);
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public boolean containsCategoryName(String title) {
|
||||
title = title.toLowerCase();
|
||||
for (MagicCategory cat : categories.values()) {
|
||||
for (MagicCycle cat : cycles.values()) {
|
||||
if (cat.title.toLowerCase().equals(title))
|
||||
return true;
|
||||
}
|
||||
@@ -254,8 +254,8 @@ public class MagicController {
|
||||
}
|
||||
|
||||
public void removeCategory(int categoryId) {
|
||||
if (categories.containsKey(categoryId)) {
|
||||
categories.remove(categoryId);
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
@@ -263,8 +263,8 @@ public class MagicController {
|
||||
/**
|
||||
* Associates a magic with a category along with its per-category ordering data.
|
||||
*/
|
||||
public void addMagicToCategory(int magicId, int categoryId, int index, int priority) {
|
||||
MagicCategory cat = categories.get(categoryId);
|
||||
public void addMagicToCycle(int magicId, int categoryId, int index, int priority) {
|
||||
MagicCycle cat = cycles.get(categoryId);
|
||||
if (cat == null) return;
|
||||
MagicAssociation assoc = new MagicAssociation();
|
||||
assoc.magicId = magicId;
|
||||
@@ -274,8 +274,8 @@ public class MagicController {
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeMagicFromCategory(int magicId, int categoryId) {
|
||||
MagicCategory cat = categories.get(categoryId);
|
||||
public void removeMagicFromCycle(int magicId, int categoryId) {
|
||||
MagicCycle cat = cycles.get(categoryId);
|
||||
if (cat == null) return;
|
||||
cat.associations.remove(magicId);
|
||||
saveMagicData();
|
||||
|
||||
+2
-2
@@ -8,12 +8,12 @@ import java.util.HashMap;
|
||||
* Holds category information for magic.
|
||||
* Each category can have many magic associations.
|
||||
*/
|
||||
public class MagicCategory {
|
||||
public class MagicCycle {
|
||||
public int id = -1;
|
||||
public String title = "";
|
||||
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
|
||||
|
||||
public MagicCategory() {}
|
||||
public MagicCycle() {}
|
||||
|
||||
public void readNBT(NBTTagCompound compound) {
|
||||
id = compound.getInteger("CategoryID");
|
||||
Reference in new issue
Block a user