mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 01:32:55 +00:00
Implemented textfield unfocused event
This commit is contained in:
1 parent
2874643c84
commit
791adfc1b4
9 files changed
+50
-13
No files matched your search
@@ -328,6 +328,11 @@ public class EventHooks {
|
||||
CustomGuiController.onSlotChange(event);
|
||||
}
|
||||
|
||||
public static void onCustomGuiUnfocused(ScriptPlayer player, ICustomGui gui, int textfieldId) {
|
||||
CustomGuiEvent.UnfocusedEvent event = new CustomGuiEvent.UnfocusedEvent(player, gui, textfieldId);
|
||||
CustomGuiController.onCustomGuiUnfocused(event);
|
||||
}
|
||||
|
||||
public static void onCustomGuiScrollClick(ScriptPlayer player, ICustomGui gui, int scrollId, int scrollIndex, String[] selection, boolean doubleClick) {
|
||||
CustomGuiEvent.ScrollEvent event = new CustomGuiEvent.ScrollEvent(player, gui, scrollId, scrollIndex, selection, doubleClick);
|
||||
CustomGuiController.onScrollClick(event);
|
||||
|
||||
@@ -75,24 +75,25 @@ public class PacketHandlerServer{
|
||||
if(type == EnumPacketServer.IsGuiOpen) {
|
||||
isGuiOpenPacket(buffer, player);
|
||||
return;
|
||||
} else if (type == EnumPacketServer.CustomGuiButton) {
|
||||
if (player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
|
||||
return;
|
||||
}
|
||||
} else if (type == EnumPacketServer.CustomGuiSlotChange) {
|
||||
if (player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
|
||||
return;
|
||||
}
|
||||
} else if (type == EnumPacketServer.CustomGuiButton && player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
|
||||
return;
|
||||
} else if (type == EnumPacketServer.CustomGuiSlotChange && player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt());
|
||||
return;
|
||||
} else if(type == EnumPacketServer.CustomGuiUnfocused && player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiUnfocused((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt());
|
||||
return;
|
||||
} else if (type == EnumPacketServer.CustomGuiScrollClick && player.openContainer instanceof ContainerCustomGui) {
|
||||
((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer));
|
||||
EventHooks.onCustomGuiScrollClick((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt(), buffer.readInt(), CustomGuiController.readScrollSelection(buffer), buffer.readBoolean());
|
||||
return;
|
||||
} else if (type == EnumPacketServer.CustomGuiClose) {
|
||||
EventHooks.onCustomGuiClose((ScriptPlayer)NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(Server.readNBT(buffer)));
|
||||
return;
|
||||
}
|
||||
|
||||
if(type.needsNpc && npc == null){
|
||||
|
||||
@@ -466,6 +466,10 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD
|
||||
}
|
||||
}
|
||||
|
||||
public void onTextFieldUnfocused(CustomGuiTextField textField){
|
||||
Client.sendData(EnumPacketServer.CustomGuiUnfocused, new Object[]{this.updateGui().toNBT(), textField.getID()});
|
||||
}
|
||||
|
||||
ScriptGui updateGui() {
|
||||
Iterator var1 = this.dataHolders.iterator();
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@ package noppes.npcs.client.gui.custom.components;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
import noppes.npcs.client.gui.custom.interfaces.IClickListener;
|
||||
import noppes.npcs.client.gui.custom.interfaces.IDataHolder;
|
||||
import noppes.npcs.client.gui.custom.interfaces.IKeyListener;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTextField;
|
||||
import noppes.npcs.scripted.interfaces.ICustomGuiComponent;
|
||||
|
||||
@@ -75,6 +77,11 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
|
||||
|
||||
public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) {
|
||||
this.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
if (!this.isFocused() && mouseButton == 0){
|
||||
parent.onTextFieldUnfocused(this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -146,6 +146,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
hookList.add("customGuiButton");
|
||||
hookList.add("customGuiSlot");
|
||||
hookList.add("customGuiScroll");
|
||||
hookList.add("customGuiTextfield");
|
||||
}
|
||||
else if(handler instanceof ForgeDataScript) {
|
||||
hooks.setSize(238, 198);
|
||||
|
||||
@@ -78,7 +78,7 @@ public enum EnumPacketServer {
|
||||
NaturalSpawnGetAll, MailOpenSetup,
|
||||
DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen,
|
||||
|
||||
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose;
|
||||
CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused;
|
||||
|
||||
public CustomNpcsPermissions.Permission permission = null;
|
||||
public boolean needsNpc = false;
|
||||
|
||||
@@ -57,6 +57,7 @@ public enum EnumScriptType {
|
||||
CUSTOM_GUI_BUTTON("customGuiButton"),
|
||||
CUSTOM_GUI_SLOT("customGuiSlot"),
|
||||
CUSTOM_GUI_SCROLL("customGuiScroll"),
|
||||
CUSTOM_GUI_TEXTFIELD("customGuiTextfield"),
|
||||
PICKUP_XP("pickupXP"),
|
||||
MOUSE_CLICKED("mouseClicked"),
|
||||
START_USING_ITEM("startItem"),
|
||||
|
||||
@@ -83,6 +83,15 @@ public class CustomGuiController {
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onCustomGuiUnfocused(CustomGuiEvent.UnfocusedEvent event) {
|
||||
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
|
||||
if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) {
|
||||
getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_TEXTFIELD, event);
|
||||
}
|
||||
|
||||
WrapperNpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onScrollClick(CustomGuiEvent.ScrollEvent event) {
|
||||
EntityPlayer player = (EntityPlayer) event.player.getMCEntity();
|
||||
if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) {
|
||||
|
||||
@@ -23,6 +23,15 @@ public class CustomGuiEvent extends Event {
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnfocusedEvent extends CustomGuiEvent {
|
||||
public final int textfieldId;
|
||||
|
||||
public UnfocusedEvent(IPlayer player, ICustomGui gui, int textfieldId) {
|
||||
super(player, gui);
|
||||
this.textfieldId = textfieldId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CloseEvent extends CustomGuiEvent {
|
||||
public CloseEvent(IPlayer player, ICustomGui gui) {
|
||||
super(player, gui);
|
||||
|
||||
Reference in new issue
Block a user