Overhaul Dialog GUI

This commit is contained in:
Kam committed 2023-06-07 22:49:54 -04:00
1 parent 327fa061cc
commit 22bc05ddcc
10 files changed
+592 -228

No files matched your search

@@ -571,6 +571,18 @@ public class NoppesUtilServer {
Server.sendData(player, EnumPacketClient.SCROLL_DATA, send);
}
public static void sendScrollGroup(EntityPlayerMP player, Map<String,Integer> map){
Map<String, Integer> send = new HashMap<String, Integer>();
for(String key : map.keySet()){
send.put(key, map.get(key));
if(send.size() == 100){
Server.sendData(player, EnumPacketClient.SCROLL_GROUP_PART, send);
send = new HashMap<String, Integer>();
}
}
Server.sendData(player, EnumPacketClient.SCROLL_GROUP, send);
}
public static void sendDialogData(EntityPlayerMP player, DialogCategory category) {
if(category == null)
return;
@@ -581,6 +593,27 @@ public class NoppesUtilServer {
sendScrollData(player, map);
}
public static void sendDialogGroup(EntityPlayerMP player, DialogCategory category) {
if(category == null)
return;
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(Dialog dialog : category.dialogs.values()){
map.put(dialog.title, dialog.id);
}
Map<String, Integer> send = new HashMap<String, Integer>();
for(String key : map.keySet()){
send.put(key, map.get(key));
if(send.size() == 100){
Server.sendData(player, EnumPacketClient.SCROLL_GROUP_PART, send);
send = new HashMap<String, Integer>();
}
}
Server.sendData(player, EnumPacketClient.SCROLL_GROUP, send);
sendScrollGroup(player, map);
}
public static void sendQuestData(EntityPlayerMP player, QuestCategory category) {
if(category == null)
return;
@@ -357,7 +357,14 @@ public class PacketHandlerServer{
NoppesUtilServer.sendDialogData(player,dialog.category);
}
else if(type == EnumPacketServer.DialogsGet){
NoppesUtilServer.sendDialogData(player,DialogController.Instance.categories.get(buffer.readInt()));
int catID = buffer.readInt();
boolean sendGroup = buffer.readBoolean();
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,DialogController.Instance.categories.get(catID));
}
else {
NoppesUtilServer.sendDialogData(player,DialogController.Instance.categories.get(catID));
}
}
else if(type == EnumPacketServer.QuestsGetFromQuest){
Quest quest = QuestController.Instance.quests.get(buffer.readInt());
@@ -581,9 +588,16 @@ public class PacketHandlerServer{
int category = buffer.readInt();
Dialog dialog = new Dialog();
dialog.readNBT(Server.readNBT(buffer));
boolean sendGroup = buffer.readBoolean();
DialogController.Instance.saveDialog(category,dialog);
if(dialog.category != null)
NoppesUtilServer.sendDialogData(player,dialog.category);
if(dialog.category != null){
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,dialog.category);
}
else {
NoppesUtilServer.sendDialogData(player,dialog.category);
}
}
}
else if(type == EnumPacketServer.QuestOpenGui){
Quest quest = new Quest();
@@ -593,10 +607,17 @@ public class PacketHandlerServer{
player.openGui(CustomNpcs.instance, gui , player.worldObj, 0, 0, 0);
}
else if(type == EnumPacketServer.DialogRemove){
Dialog dialog = DialogController.Instance.dialogs.get(buffer.readInt());
int diagId = buffer.readInt();
boolean sendGroup = buffer.readBoolean();
Dialog dialog = DialogController.Instance.dialogs.get(diagId);
if(dialog != null && dialog.category != null){
DialogController.Instance.removeDialog(dialog);
NoppesUtilServer.sendDialogData(player,dialog.category);
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,dialog.category);
}
else {
NoppesUtilServer.sendDialogData(player,dialog.category);
}
}
}
else if(type == EnumPacketServer.DialogNpcGet){
@@ -20,6 +20,7 @@ import noppes.npcs.client.gui.player.GuiQuestCompletion;
import noppes.npcs.client.gui.util.GuiContainerNPCInterface;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.client.gui.util.IScrollGroup;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.DialogController;
@@ -208,6 +209,43 @@ public class NoppesUtil {
}
private static HashMap<String,Integer> data = new HashMap<String,Integer>();
private static HashMap<String,Integer> group = new HashMap<String,Integer>();
public static void addScrollGroup(ByteBuf buffer) {
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
group.put(name, id);
}
} catch (Exception ignored) {
}
}
public static void setScrollGroup(ByteBuf buffer) {
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null)
return;
try {
int size = buffer.readInt();
for(int i = 0; i < size; i++){
int id = buffer.readInt();
String name = Server.readString(buffer);
group.put(name, id);
}
} catch (Exception ignored) {
}
if(gui instanceof GuiNPCInterface && ((GuiNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiNPCInterface)gui).getSubGui();
}
if(gui instanceof GuiContainerNPCInterface && ((GuiContainerNPCInterface)gui).hasSubGui()){
gui = (GuiScreen) ((GuiContainerNPCInterface)gui).getSubGui();
}
if(gui instanceof IScrollGroup)
((IScrollGroup)gui).setScrollGroup(new Vector<String>(group.keySet()), group);
group = new HashMap<String,Integer>();
}
public static void addScrollData(ByteBuf buffer) {
try {
@@ -168,6 +168,12 @@ public class PacketHandlerClient extends PacketHandlerServer{
else if(type == EnumPacketClient.SCROLL_DATA_PART){
NoppesUtil.addScrollData(buffer);
}
else if(type == EnumPacketClient.SCROLL_GROUP){
NoppesUtil.setScrollGroup(buffer);
}
else if(type == EnumPacketClient.SCROLL_GROUP_PART){
NoppesUtil.addScrollGroup(buffer);
}
else if(type == EnumPacketClient.SCROLL_SELECTED){
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
if(gui == null || !(gui instanceof IScrollData))
@@ -0,0 +1,160 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.GuiNpcSoundSelection;
import noppes.npcs.client.gui.SubGuiEditText;
import noppes.npcs.client.gui.SubGuiNpcTextArea;
import noppes.npcs.client.gui.global.GuiNPCManageDialogs;
import noppes.npcs.client.gui.global.GuiNPCQuestSelection;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogCategory;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, GuiSelectionListener,ITextfieldListener
{
public int dialogCategoryID;
public Dialog dialog;
private final GuiNPCManageDialogs parent;
public SubGuiNpcDialog(GuiNPCManageDialogs parent, Dialog dialog, int catId)
{
this.parent = parent;
this.dialog = dialog;
this.dialogCategoryID = catId;
setBackground("menubg.png");
xSize = 360;
ySize = 216;
}
public void initGui()
{
super.initGui();
addLabel(new GuiNpcLabel(1,"gui.title", guiLeft + 4, guiTop + 8));
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 36, guiTop + 3, 140, 20, dialog.title));
addLabel(new GuiNpcLabel(0,"ID", guiLeft + 178, guiTop + 4));
addLabel(new GuiNpcLabel(2, dialog.id + "", guiLeft + 178, guiTop + 14));
addLabel(new GuiNpcLabel(3, "dialog.dialogtext", guiLeft + 4, guiTop + 30));
addButton(new GuiNpcButton(3, guiLeft + 120, guiTop + 25, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(4, "availability.options", guiLeft + 4, guiTop + 51));
addButton(new GuiNpcButton(4, guiLeft + 120, guiTop + 46, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(5, "faction.options", guiLeft + 4, guiTop + 72));
addButton(new GuiNpcButton(5, guiLeft + 120, guiTop + 67, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(6, "dialog.options", guiLeft + 4, guiTop + 93));
addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 89, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(11, "dialog.visualOption", guiLeft + 4, guiTop + 115));
addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 110, 50, 20, "selectServer.edit"));
addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 134, 144, 20, "availability.selectquest"));
addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 134, 20, 20, "X"));
addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 158));
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 168, 144, 20, dialog.sound));
addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 168, 60, 20, "mco.template.button.select"));
addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 192, 120, 20, "gui.showmore"));
addButton(new GuiNpcButton(14, guiLeft + 130, guiTop + 192, 50, 20, "gui.done"));
if(!parent.dialogQuestName.equals(""))
getButton(7).setDisplayText(parent.dialogQuestName);
}
public void buttonEvent(GuiButton guibutton)
{
int id = guibutton.id;
if(id == 3 && dialog.id >= 0){
setSubGui(new SubGuiNpcTextArea(dialog.text));
}
if(id == 4 && dialog.id >= 0){
setSubGui(new SubGuiNpcAvailability(dialog.availability));
}
if(id == 5 && dialog.id >= 0){
setSubGui(new SubGuiNpcFactionOptions(dialog.factionOptions));
}
if(id == 6 && dialog.id >= 0){
setSubGui(new SubGuiNpcDialogOptions(dialog));
}
if(id == 7 && dialog.id >= 0){
NoppesUtil.openGUI(player, new GuiNPCQuestSelection(npc, this, dialog.quest));
}
if(id == 8 && dialog.id >= 0){
dialog.quest = -1;
initGui();
}
if(id == 9 && dialog.id >= 0){
NoppesUtil.openGUI(player, new GuiNpcSoundSelection(npc, this, getTextField(2).getText()));
}
if(id == 10){
setSubGui(new SubGuiNpcDialogExtra(dialog));
}
if(id == 11){
setSubGui(new SubGuiNpcDialogVisual(dialog));
}
if(id == 14){
close();
}
}
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
if(guiNpcTextField.id == 1) {
if(dialog.id < 0)
guiNpcTextField.setText("");
else{
String name = guiNpcTextField.getText();
if(name.isEmpty() || this.parent.dialogData.containsKey(name)){
guiNpcTextField.setText(dialog.title);
}
else if(dialog.id >= 0){
String old = dialog.title;
this.parent.dialogData.remove(old);
dialog.title = name;
this.parent.dialogData.put(dialog.title, dialog.id);
this.parent.dialogScroll.replace(old,dialog.title);
}
}
}
if(guiNpcTextField.id == 2) {
dialog.sound = guiNpcTextField.getText();
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui){
if(subgui instanceof SubGuiNpcTextArea){
SubGuiNpcTextArea gui = (SubGuiNpcTextArea) subgui;
dialog.text = gui.text;
}
}
@Override
public void selected(int ob, String name) {
dialog.quest = ob;
Client.sendData(EnumPacketServer.DialogSave, this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()));
}
public void save(){
Client.sendData(EnumPacketServer.DialogSave, this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()));
}
}
@@ -10,12 +10,9 @@ import noppes.npcs.controllers.data.PlayerMail;
public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiListener
{
private Dialog dialog;
private int slot = 0;
public GuiScreen parent2;
public SubGuiNpcDialogExtra(Dialog dialog, GuiScreen parent)
public SubGuiNpcDialogExtra(Dialog dialog)
{
this.parent2 = parent;
this.dialog = dialog;
setBackground("menubg.png");
xSize = 256;
@@ -64,8 +61,6 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList
if(button.id == 66)
{
close();
if(parent2 != null)
NoppesUtil.openGUI(player, parent2);
}
}
@@ -17,7 +17,6 @@ import java.util.Collections;
public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener {
private final Dialog dialog;
public GuiScreen parent2;
private GuiMenuTopButton[] topButtons;
private int activeMenu = 1;
@@ -27,8 +26,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
private int lastColorClicked = -1;
private int changedId = -1;
public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) {
this.parent2 = parent;
public SubGuiNpcDialogVisual(Dialog dialog) {
this.dialog = dialog;
setBackground("menubg.png");
xSize = 256;
@@ -269,8 +267,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
int id = button.id;
if(id == 0){
close();
if(parent2 != null)
NoppesUtil.openGUI(player, parent2);
return;
}
save();
@@ -417,7 +413,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
public void save() {
GuiNpcTextField.unfocus();
if(dialog.id >= 0)
Client.sendData(EnumPacketServer.DialogSave, ((GuiNPCManageDialogs)parent2).category.id, dialog.writeToNBT(new NBTTagCompound()));
Client.sendData(EnumPacketServer.DialogSave, ((SubGuiNpcDialog)parent).dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()));
}
private DialogImage getSelectedImage() {
@@ -3,7 +3,6 @@ package noppes.npcs.client.gui.global;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.*;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
@@ -11,18 +10,28 @@ import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogCategory;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, GuiSelectionListener,ICustomScrollListener,ITextfieldListener, IGuiData
public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGroup, IScrollData, ISubGuiListener, GuiSelectionListener,ICustomScrollListener, IGuiData
{
private GuiCustomScroll scroll;
private HashMap<String,Integer> data = new HashMap<String,Integer>();
private Dialog dialog = new Dialog();
public DialogCategory category = new DialogCategory();
private boolean categorySelection = true;
private GuiCustomScroll catScroll;
public GuiCustomScroll dialogScroll;
private GuiNpcSoundSelection gui;
private String prevCatName = "";
private String prevDialogName = "";
public DialogCategory category = new DialogCategory();
public Dialog dialog = new Dialog();
public String dialogQuestName = "";
private HashMap<String,Integer> catData = new HashMap<String,Integer>();
public HashMap<String,Integer> dialogData = new HashMap<String,Integer>();
private String catSearch = "";
private String diagSearch = "";
public GuiNPCManageDialogs(EntityNPCInterface npc)
{
@@ -33,229 +42,254 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
public void initGui()
{
super.initGui();
this.addButton(new GuiNpcButton(0,guiLeft + 358, guiTop + 8, 58, 20,categorySelection?"dialog.dialogs":"gui.categories"));
this.addButton(new GuiNpcButton(1,guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
if(scroll == null){
scroll = new GuiCustomScroll(this,0);
scroll.setSize(143, 208);
}
scroll.guiLeft = guiLeft + 214;
scroll.guiTop = guiTop + 4;
this.addScroll(scroll);
if(categorySelection && category.id >= 0)
categoryGuiInit();
if(!categorySelection && dialog.id >= 0)
dialogGuiInit();
}
private void dialogGuiInit() {
addLabel(new GuiNpcLabel(1,"gui.title", guiLeft + 4, guiTop + 8));
addTextField(new GuiNpcTextField(1, this, this.fontRendererObj, guiLeft + 36, guiTop + 3, 140, 20, dialog.title));
if(catScroll == null){
catScroll = new GuiCustomScroll(this,0);
catScroll.setSize(143, 185);
}
catScroll.guiLeft = guiLeft + 64;
catScroll.guiTop = guiTop + 4;
this.addScroll(catScroll);
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 64, guiTop + 4 + 3 + 185, 143, 20, catSearch));
addLabel(new GuiNpcLabel(0,"ID", guiLeft + 178, guiTop + 4));
addLabel(new GuiNpcLabel(2, dialog.id + "", guiLeft + 178, guiTop + 14));
addLabel(new GuiNpcLabel(3, "dialog.dialogtext", guiLeft + 4, guiTop + 30));
addButton(new GuiNpcButton(3, guiLeft + 120, guiTop + 25, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(4, "availability.options", guiLeft + 4, guiTop + 51));
addButton(new GuiNpcButton(4, guiLeft + 120, guiTop + 46, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(5, "faction.options", guiLeft + 4, guiTop + 72));
addButton(new GuiNpcButton(5, guiLeft + 120, guiTop + 67, 50, 20, "selectServer.edit"));
this.addButton(new GuiNpcButton(44,guiLeft + 3, guiTop + 8, 58, 20, "gui.categories"));
getButton(44).setEnabled(false);
this.addButton(new GuiNpcButton(4,guiLeft + 3, guiTop + 38, 58, 20, "gui.add"));
this.addButton(new GuiNpcButton(5,guiLeft + 3, guiTop + 61, 58, 20, "gui.remove"));
this.addButton(new GuiNpcButton(6,guiLeft + 3, guiTop + 94, 58, 20, "gui.edit"));
addLabel(new GuiNpcLabel(6, "dialog.options", guiLeft + 4, guiTop + 93));
addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 89, 50, 20, "selectServer.edit"));
addLabel(new GuiNpcLabel(11, "dialog.visualOption", guiLeft + 4, guiTop + 115));
addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 110, 50, 20, "selectServer.edit"));
if(dialogScroll == null){
dialogScroll = new GuiCustomScroll(this,1);
dialogScroll.setSize(143, 185);
}
dialogScroll.guiLeft = guiLeft + 212;
dialogScroll.guiTop = guiTop + 4;
this.addScroll(dialogScroll);
addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 212, guiTop + 4 + 3 + 185, 143, 20, diagSearch));
addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 134, 144, 20, "availability.selectquest"));
addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 134, 20, 20, "X"));
this.addButton(new GuiNpcButton(33,guiLeft + 358, guiTop + 8, 58, 20, "dialog.dialogs"));
getButton(33).setEnabled(false);
this.addButton(new GuiNpcButton(0,guiLeft + 358, guiTop + 94, 58, 20, "gui.edit"));
this.addButton(new GuiNpcButton(1,guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
this.addButton(new GuiNpcButton(3,guiLeft + 358, guiTop + 117, 58, 20, "gui.copy"));
addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 158));
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 168, 144, 20, dialog.sound));
addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 168, 60, 20, "mco.template.button.select"));
addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 192, 120, 20, "gui.showmore"));
}
private void categoryGuiInit() {
addTextField(new GuiNpcTextField(0,this, this.fontRendererObj, guiLeft+8, guiTop + 8, 160, 16, category.title));
updateButtons();
}
@Override
public void elementClicked() {
getTextField(2).setText(gui.getSelected());
unFocused(getTextField(2));
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(getTextField(55) != null){
if(getTextField(55).isFocused()){
if(catSearch.equals(getTextField(55).getText()))
return;
catSearch = getTextField(55).getText().toLowerCase();
catScroll.setList(getCatSearch());
}
}
if(getTextField(66) != null){
if(getTextField(66).isFocused()){
if(diagSearch.equals(getTextField(66).getText()))
return;
diagSearch = getTextField(66).getText().toLowerCase();
dialogScroll.setList(getDiagSearch());
}
}
}
public void resetDiagList(){
if(dialogScroll != null){
diagSearch = "";
if(getTextField(66) != null){
getTextField(66).setText("");
}
dialogScroll.setList(getDiagSearch());
}
}
private List<String> getCatSearch(){
if(catSearch.isEmpty()){
return new ArrayList<String>(this.catData.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.catData.keySet()){
if(name.toLowerCase().contains(catSearch))
list.add(name);
}
return list;
}
private List<String> getDiagSearch(){
if(category != null){
if(category.id < 0){
return new ArrayList<String>();
}
}
else {
return new ArrayList<String>();
}
if(diagSearch.isEmpty()){
return new ArrayList<String>(this.dialogData.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.dialogData.keySet()){
if(name.toLowerCase().contains(diagSearch))
list.add(name);
}
return list;
}
public void buttonEvent(GuiButton guibutton)
{
int id = guibutton.id;
if(id == 0){
save();
if(categorySelection){
if(category.id < 0)
return;
dialog = new Dialog();
Client.sendData(EnumPacketServer.DialogsGet, category.id);
}
else if(!categorySelection){
dialog = new Dialog();
category = new DialogCategory();
Client.sendData(EnumPacketServer.DialogCategoriesGet);
}
categorySelection = !categorySelection;
getButton(0).setEnabled(false);
scroll.clear();
data.clear();
// Edit Cat
if(id == 6){
saveType(false);
if(category != null && category.id > -1){
setSubGui(new SubGuiEditText(category.title));
}
else {
getCategory(false);
}
}
if(id == 1){
save();
String name = "New";
while(data.containsKey(name))
name += "_";
if(categorySelection){
DialogCategory category = new DialogCategory();
category.title = name;
Client.sendData(EnumPacketServer.DialogCategorySave, category.writeNBT(new NBTTagCompound()));
// Add Cat
if(id == 4){
saveType(false);
String name = "New";
while(catData.containsKey(name))
name += "_";
if(catScroll != null){
setPrevCatName(name);
}
DialogCategory category = new DialogCategory();
category.title = name;
Client.sendData(EnumPacketServer.DialogCategorySave, category.writeNBT(new NBTTagCompound()));
}
// Remove Cat
if(id == 5){
saveType(false);
if(catData.containsKey(catScroll.getSelected())) {
Client.sendData(EnumPacketServer.DialogCategoryRemove, category.id);
clearCategory();
}
else{
Dialog dialog = new Dialog();
dialog.title = name;
Client.sendData(EnumPacketServer.DialogSave, category.id, dialog.writeToNBT(new NBTTagCompound()));
}
}
if(id == 2){
if(data.containsKey(scroll.getSelected())) {
if(categorySelection){
Client.sendData(EnumPacketServer.DialogCategoryRemove, category.id);
category = new DialogCategory();
}
if(category != null && category.id >= 0){
// Add Dialog
if(id == 1){
saveType(true);
String name = "New";
while(dialogData.containsKey(name))
name += "_";
if(dialogScroll != null){
setPrevDialogName(name);
}
else{
Client.sendData(EnumPacketServer.DialogRemove, dialog.id);
Dialog dialog = new Dialog();
dialog.title = name;
Client.sendData(EnumPacketServer.DialogSave, category.id, dialog.writeToNBT(new NBTTagCompound()), true);
}
// Remove Dialog
if(id == 2) {
saveType(true);
if (dialogData.containsKey(dialogScroll.getSelected())) {
Client.sendData(EnumPacketServer.DialogRemove, dialog.id, true);
dialog = new Dialog();
dialogData.clear();
}
scroll.clear();
}
}
// Edit Dialog
if(id == 0) {
saveType(true);
if (dialogData.containsKey(dialogScroll.getSelected()) && dialog != null && dialog.id >= 0) {
setSubGui(new SubGuiNpcDialog(this, dialog, category.id));
}
}
}
if(id == 3 && dialog.id >= 0){
setSubGui(new SubGuiNpcTextArea(dialog.text));
}
if(id == 4 && dialog.id >= 0){
setSubGui(new SubGuiNpcAvailability(dialog.availability));
}
if(id == 5 && dialog.id >= 0){
setSubGui(new SubGuiNpcFactionOptions(dialog.factionOptions));
}
if(id == 6 && dialog.id >= 0){
setSubGui(new SubGuiNpcDialogOptions(dialog));
}
if(id == 7 && dialog.id >= 0){
NoppesUtil.openGUI(player, new GuiNPCQuestSelection(npc, this, dialog.quest));
}
if(id == 8 && dialog.id >= 0){
dialog.quest = -1;
initGui();
}
if(id == 9 && dialog.id >= 0){
NoppesUtil.openGUI(player, gui = new GuiNpcSoundSelection(npc, this, getTextField(2).getText()));
}
if(id == 10){
setSubGui(new SubGuiNpcDialogExtra(dialog, this));
}
if(id == 11){
setSubGui(new SubGuiNpcDialogVisual(dialog, this));
}
updateButtons();
}
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
if(guiNpcTextField.id == 0) {
if(category.id < 0)
guiNpcTextField.setText("");
else{
String name = guiNpcTextField.getText();
if(name.isEmpty() || data.containsKey(name)){
guiNpcTextField.setText(category.title);
}
else if(categorySelection && category.id >= 0){
String old = category.title;
data.remove(category.title);
category.title = name;
data.put(category.title, category.id);
scroll.replace(old,category.title);
}
public void updateButtons(){
boolean enabled = category != null;
if(enabled){
if(!(category.id >= 0)){
enabled = false;
}
}
if(guiNpcTextField.id == 1) {
if(dialog.id < 0)
guiNpcTextField.setText("");
else{
String name = guiNpcTextField.getText();
if(name.isEmpty() || data.containsKey(name)){
guiNpcTextField.setText(dialog.title);
}
else if(!categorySelection && dialog.id >= 0){
String old = dialog.title;
data.remove(old);
dialog.title = name;
data.put(dialog.title, dialog.id);
scroll.replace(old,dialog.title);
}
boolean diagEnabled = dialogData != null;
if(diagEnabled){
if(!(dialog.id >= 0)){
diagEnabled = false;
}
}
if(guiNpcTextField.id == 2) {
dialog.sound = guiNpcTextField.getText();
}
getButton(6).setEnabled(enabled);
getButton(1).setEnabled(enabled);
getButton(2).setEnabled(enabled);
getButton(0).setEnabled(enabled && diagEnabled);
getButton(3).setEnabled(enabled && diagEnabled);
}
@Override
public void setGuiData(NBTTagCompound compound) {
if(categorySelection){
category.readNBT(compound);
setSelected(category.title);
initGui();
}
else{
if(compound.hasKey("DialogTitle")){
dialog.readNBT(compound);
setSelected(dialog.title);
initGui();
if(compound.hasKey("DialogQuestName"))
getButton(7).setDisplayText(compound.getString("DialogQuestName"));
if(compound.hasKey("DialogQuestName")){
dialogQuestName = compound.getString("DialogQuestName");
}
else {
dialogQuestName = "";
}
setPrevDialogName(dialog.title);
}
else {
category.readNBT(compound);
setPrevCatName(category.title);
Client.sendData(EnumPacketServer.DialogsGet, category.id, true);
resetDiagList();
}
initGui();
}
@Override
public void subGuiClosed(SubGuiInterface subgui){
if(subgui instanceof SubGuiNpcTextArea){
SubGuiNpcTextArea gui = (SubGuiNpcTextArea) subgui;
dialog.text = gui.text;
if(subgui instanceof SubGuiEditText){
if(!((SubGuiEditText)subgui).cancelled){
if(category != null && category.id > -1){
String name = ((SubGuiEditText)subgui).text;
if(name != null && !name.equalsIgnoreCase(category.title)){
if(!(name.isEmpty() || catData.containsKey(name))){
String old = category.title;
catData.remove(category.title);
category.title = name;
catData.put(category.title, category.id);
catScroll.replace(old,category.title);
}
saveType(false);
}
}
}
clearCategory();
}
if(subgui instanceof SubGuiNpcDialog){
saveType(true);
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
getButton(0).setEnabled(true);
String name = scroll.getSelected();
this.data = data;
scroll.setList(list);
if(name != null)
scroll.setSelected(name);
initGui();
public void setPrevCatName(String selectedCat){
prevCatName = selectedCat;
this.catScroll.setSelected(prevCatName);
}
@Override
public void setSelected(String selected) {
public void setPrevDialogName(String selectedCat){
prevDialogName = selectedCat;
this.dialogScroll.setSelected(prevDialogName);
}
@Override
@@ -268,26 +302,96 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if(guiCustomScroll.id == 0)
{
save();
String selected = scroll.getSelected();
if(categorySelection){
category = new DialogCategory();
Client.sendData(EnumPacketServer.DialogCategoryGet, data.get(selected));
}
else{
dialog = new Dialog();
Client.sendData(EnumPacketServer.DialogGet, data.get(selected));
}
saveType(false);
getCategory(false);
}
if(guiCustomScroll.id == 1)
{
saveType(false);
getDialog(false);
}
}
public void save() {
GuiNpcTextField.unfocus();
if(!categorySelection && dialog.id >= 0)
Client.sendData(EnumPacketServer.DialogSave, category.id, dialog.writeToNBT(new NBTTagCompound()));
else if(categorySelection && category.id >= 0)
Client.sendData(EnumPacketServer.DialogCategorySave, category.writeNBT(new NBTTagCompound()));
public void getCategory(boolean override){
if(catScroll.selected != -1){
String selected = catScroll.getSelected();
if(!selected.equals(prevCatName) || override){
category = new DialogCategory();
Client.sendData(EnumPacketServer.DialogCategoryGet, catData.get(selected));
setPrevCatName(selected);
}
}
}
public void getDialog(boolean override){
if(dialogScroll.selected != -1){
String selected = dialogScroll.getSelected();
if(!selected.equals(prevDialogName) || override){
dialog = new Dialog();
Client.sendData(EnumPacketServer.DialogGet, dialogData.get(selected));
setPrevDialogName(selected);
}
}
}
public void clearCategory(){
catScroll.setList(getCatSearch());
catScroll.selected = -1;
prevCatName = "";
category = new DialogCategory();
this.dialogData.clear();
resetDiagList();
}
public void saveType(boolean saveDiag){
if(saveDiag){
if(dialogScroll.selected != -1 && dialog.id >= 0){
if(catScroll.selected != -1 && category.id >= 0){
Client.sendData(EnumPacketServer.DialogSave, category.id, dialog.writeToNBT(new NBTTagCompound()), true);
}
}
}
else{
if(catScroll.selected != -1 && category.id >= 0)
Client.sendData(EnumPacketServer.DialogCategorySave, category.writeNBT(new NBTTagCompound()));
}
}
public void save() {}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
String name = catScroll.getSelected();
this.catData = data;
catScroll.setList(getCatSearch());
if(name != null){
catScroll.setSelected(name);
getCategory(false);
} else {
catScroll.setSelected(prevCatName);
getCategory(true);
}
initGui();
}
@Override
public void setSelected(String selected) {}
@Override
public void setScrollGroup(Vector<String> list, HashMap<String, Integer> data) {
String name = dialogScroll.getSelected();
this.dialogData = data;
dialogScroll.setList(getDiagSearch());
if(name != null){
dialogScroll.setSelected(name);
getDialog(false);
} else {
dialogScroll.setSelected(prevDialogName);
getDialog(true);
}
initGui();
}
@Override
public void setSelectedGroup(String selected) {}
}
@@ -0,0 +1,9 @@
package noppes.npcs.client.gui.util;
import java.util.HashMap;
import java.util.Vector;
public interface IScrollGroup {
public void setScrollGroup(Vector<String> list,HashMap<String,Integer> data);
public void setSelectedGroup(String selected);
}
@@ -20,6 +20,8 @@ public enum EnumPacketClient {
SCROLL_LIST,
SCROLL_DATA,
SCROLL_DATA_PART,
SCROLL_GROUP,
SCROLL_GROUP_PART,
SCROLL_SELECTED,
GUI_REDSTONE,
GUI_WAYPOINT,