Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/gui/GuiNpcRemoteEditor.java
T

176 lines
6.4 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.client.gui;
2025-02-01 23:43:06 -05:00
import kamkeel.npcs.network.PacketClient;
2025-07-23 14:22:52 -04:00
import kamkeel.npcs.network.packets.request.npc.RemoteDeletePacket;
import kamkeel.npcs.network.packets.request.npc.RemoteFreezeGetPacket;
import kamkeel.npcs.network.packets.request.npc.RemoteFreezePacket;
import kamkeel.npcs.network.packets.request.npc.RemoteGlobalMenuPacket;
import kamkeel.npcs.network.packets.request.npc.RemoteMainMenuPacket;
import kamkeel.npcs.network.packets.request.npc.RemoteNpcsGetPacket;
import kamkeel.npcs.network.packets.request.npc.RemoteResetPacket;
import kamkeel.npcs.network.packets.request.npc.RemoteTpToNpcPacket;
2018-09-13 12:03:28 -04:00
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.entity.Entity;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.NoppesUtil;
2025-07-23 14:22:52 -04:00
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.IScrollData;
2025-03-03 18:44:05 -05:00
import noppes.npcs.constants.EnumScrollData;
2018-09-13 12:03:28 -04:00
import noppes.npcs.entity.EntityNPCInterface;
2025-02-03 12:36:28 -05:00
import java.util.ArrayList;
2023-01-12 21:33:06 -05:00
import java.util.HashMap;
2025-02-03 12:36:28 -05:00
import java.util.List;
2023-01-12 21:33:06 -05:00
import java.util.Vector;
2025-03-12 20:12:01 -04:00
public class GuiNpcRemoteEditor extends GuiNPCInterface implements IScrollData, GuiYesNoCallback {
2024-02-19 19:14:51 -05:00
2018-09-13 12:03:28 -04:00
private GuiCustomScroll scroll;
private HashMap<String, Integer> data = new HashMap<String, Integer>();
2025-02-03 12:36:28 -05:00
private String search = "";
2025-03-12 20:12:01 -04:00
public GuiNpcRemoteEditor() {
super();
2018-09-13 12:03:28 -04:00
xSize = 256;
setBackground("menubg.png");
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteNpcsGetPacket());
PacketClient.sendClient(new RemoteFreezeGetPacket());
2025-03-12 20:12:01 -04:00
}
public void initGui() {
2018-09-13 12:03:28 -04:00
super.initGui();
2025-03-12 20:12:01 -04:00
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0, 0);
scroll.setSize(165, 188);
2018-09-13 12:03:28 -04:00
}
scroll.guiLeft = guiLeft + 4;
scroll.guiTop = guiTop + 4;
addScroll(scroll);
2024-02-19 19:14:51 -05:00
2018-09-13 12:03:28 -04:00
String title = StatCollector.translateToLocal("remote.title");
int x = (xSize - this.fontRendererObj.getStringWidth(title)) / 2;
2024-02-19 19:14:51 -05:00
2025-02-03 12:36:28 -05:00
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 4, guiTop + 5 + scroll.ySize, scroll.xSize, 20, search));
2018-09-13 12:03:28 -04:00
this.addLabel(new GuiNpcLabel(0, title, guiLeft + x, guiTop - 8));
2025-03-12 20:12:01 -04:00
this.addButton(new GuiNpcButton(0, guiLeft + 170, guiTop + 6, 82, 20, "selectServer.edit"));
this.addButton(new GuiNpcButton(1, guiLeft + 170, guiTop + 28, 82, 20, "selectWorld.deleteButton"));
this.addButton(new GuiNpcButton(2, guiLeft + 170, guiTop + 50, 82, 20, "remote.reset"));
this.addButton(new GuiNpcButton(3, guiLeft + 170, guiTop + 132, 82, 20, "remote.freeze"));
this.addButton(new GuiNpcButton(4, guiLeft + 170, guiTop + 72, 82, 20, "remote.tp"));
this.addButton(new GuiNpcButton(5, guiLeft + 170, guiTop + 110, 82, 20, "remote.resetall"));
this.addButton(new GuiNpcButton(6, guiLeft + 170, guiTop + 165, 82, 20, "menu.global"));
2018-09-13 12:03:28 -04:00
}
@Override
2025-03-12 20:12:01 -04:00
public void confirmClicked(boolean flag, int i) {
if (flag) {
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteDeletePacket(data.get(scroll.getSelected())));
2025-03-12 20:12:01 -04:00
}
NoppesUtil.openGUI(player, this);
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
protected void actionPerformed(GuiButton guibutton) {
int id = guibutton.id;
if (id == 3) {
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteFreezePacket());
2025-03-12 20:12:01 -04:00
}
if (id == 5) {
for (int ids : data.values()) {
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteResetPacket(ids));
2025-03-12 20:12:01 -04:00
Entity entity = player.worldObj.getEntityByID(ids);
if (entity != null && entity instanceof EntityNPCInterface)
((EntityNPCInterface) entity).reset();
}
}
if (id == 6) {
NoppesUtil.setLastNpc(null);
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteGlobalMenuPacket());
2025-03-12 20:12:01 -04:00
}
2024-02-19 19:14:51 -05:00
2025-03-12 20:12:01 -04:00
if (!data.containsKey(scroll.getSelected()))
return;
2024-02-19 19:14:51 -05:00
2025-03-12 20:12:01 -04:00
if (id == 0) {
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteMainMenuPacket(data.get(scroll.getSelected())));
2025-03-12 20:12:01 -04:00
}
if (id == 1) {
2018-09-13 12:03:28 -04:00
GuiYesNo guiyesno = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("gui.delete"), 0);
displayGuiScreen(guiyesno);
2025-03-12 20:12:01 -04:00
}
if (id == 2) {
2025-02-01 23:43:06 -05:00
int selected = data.get(scroll.getSelected());
PacketClient.sendClient(new RemoteResetPacket(selected));
2025-03-12 20:12:01 -04:00
Entity entity = player.worldObj.getEntityByID(selected);
if (entity != null && entity instanceof EntityNPCInterface)
((EntityNPCInterface) entity).reset();
}
if (id == 4) {
2025-02-01 23:43:06 -05:00
PacketClient.sendClient(new RemoteTpToNpcPacket(data.get(scroll.getSelected())));
2025-03-12 20:12:01 -04:00
close();
}
2018-09-13 12:03:28 -04:00
}
2024-02-19 19:14:51 -05:00
2018-09-13 12:03:28 -04:00
@Override
2025-03-12 20:12:01 -04:00
public void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
scroll.mouseClicked(i, j, k);
2018-09-13 12:03:28 -04:00
}
2025-03-12 20:12:01 -04:00
2018-09-13 12:03:28 -04:00
@Override
2025-03-12 20:12:01 -04:00
public void keyTyped(char c, int i) {
2025-02-03 12:36:28 -05:00
super.keyTyped(c, i);
2025-03-12 20:12:01 -04:00
if (getTextField(66) != null) {
if (getTextField(66).isFocused()) {
if (i == 1) {
2025-02-03 12:36:28 -05:00
close();
return;
}
2025-03-12 20:12:01 -04:00
if (search.equals(getTextField(66).getText()))
2025-02-03 12:36:28 -05:00
return;
search = getTextField(66).getText().toLowerCase();
scroll.resetScroll();
scroll.setList(getNPCSearch());
}
}
2025-03-12 20:12:01 -04:00
if (i == 1) {
2018-09-13 12:03:28 -04:00
close();
}
}
2025-02-03 12:36:28 -05:00
2025-03-12 20:12:01 -04:00
private List<String> getNPCSearch() {
if (search.isEmpty()) {
2025-02-03 12:36:28 -05:00
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
2025-03-12 20:12:01 -04:00
for (String name : this.data.keySet()) {
if (name.toLowerCase().contains(search))
2025-02-03 12:36:28 -05:00
list.add(name);
}
return list;
}
2025-03-12 20:12:01 -04:00
@Override
public void save() {
}
2024-02-19 19:14:51 -05:00
2025-03-12 20:12:01 -04:00
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
2025-02-03 12:36:28 -05:00
this.data = data;
scroll.resetScroll();
scroll.setList(getNPCSearch());
2025-03-12 20:12:01 -04:00
}
@Override
public void setSelected(String selected) {
getButton(3).setDisplayText(selected);
}
2018-09-13 12:03:28 -04:00
}