mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 20:52:36 +00:00
Revamp Sound Selection Menu
This commit is contained in:
1 parent
14b430089e
commit
b3846e32c8
8 files changed
+108
-380
No files matched your search
@@ -4,10 +4,8 @@ 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.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.select.GuiSoundSelection;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumPacketServer;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
import noppes.npcs.controllers.data.Lines;
|
||||
@@ -15,12 +13,12 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData
|
||||
public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData, ISubGuiListener, ITextfieldListener
|
||||
{
|
||||
private Lines lines;
|
||||
private GuiNpcTextField field;
|
||||
private GuiNpcSoundSelection gui;
|
||||
|
||||
private int selectedId = -1;
|
||||
private GuiSoundSelection gui;
|
||||
|
||||
public GuiNPCLinesEdit(EntityNPCInterface npc, Lines lines)
|
||||
{
|
||||
super(npc);
|
||||
@@ -35,57 +33,63 @@ public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData
|
||||
String text = "";
|
||||
String sound = "";
|
||||
if(lines.lines.containsKey(i)){
|
||||
Line line = lines.lines.get(i);
|
||||
text = line.text;
|
||||
sound = line.sound;
|
||||
Line line = lines.lines.get(i);
|
||||
text = line.getText();
|
||||
sound = line.getSound();
|
||||
}
|
||||
addTextField(new GuiNpcTextField(i,this, fontRendererObj, guiLeft + 4, guiTop + 4 + i * 24, 200, 20,text));
|
||||
addTextField(new GuiNpcTextField(i + 8,this, fontRendererObj, guiLeft + 208, guiTop + 4 + i * 24, 146, 20,sound));
|
||||
addButton(new GuiNpcButton(i, guiLeft + 358, guiTop + 4 + i * 24, 60, 20, "gui.select"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton guibutton)
|
||||
{
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
field = getTextField(button.id + 8);
|
||||
gui = new GuiNpcSoundSelection(this, field.getText());
|
||||
NoppesUtil.openGUI(player, gui);
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
selectedId = button.id + 8;
|
||||
setSubGui(new GuiSoundSelection(getTextField(selectedId).getText()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void elementClicked() {
|
||||
field.setText(gui.getSelected());
|
||||
saveLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
npc.advanced.readToNBT(compound);
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void saveLines(){
|
||||
HashMap<Integer,Line> lines = new HashMap<Integer,Line>();
|
||||
for(int i = 0; i < 8; i++){
|
||||
GuiNpcTextField tf = getTextField(i);
|
||||
GuiNpcTextField tf2 = getTextField(i + 8);
|
||||
if(!tf.isEmpty()){
|
||||
Line line = new Line();
|
||||
line.text = tf.getText();
|
||||
line.sound = tf2.getText();
|
||||
lines.put(i, line);
|
||||
}
|
||||
|
||||
}
|
||||
this.lines.lines = lines;
|
||||
}
|
||||
|
||||
|
||||
private void saveLines(){
|
||||
HashMap<Integer,Line> lines = new HashMap<Integer,Line>();
|
||||
for(int i = 0; i < 8; i++){
|
||||
GuiNpcTextField tf = getTextField(i);
|
||||
GuiNpcTextField tf2 = getTextField(i + 8);
|
||||
if(!tf.isEmpty() || !tf2.isEmpty()){
|
||||
Line line = new Line();
|
||||
line.setText(tf.getText());
|
||||
line.setSound(tf2.getText());
|
||||
lines.put(i, line);
|
||||
}
|
||||
|
||||
}
|
||||
this.lines.lines = lines;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
saveLines();
|
||||
Client.sendData(EnumPacketServer.MainmenuAdvancedSave, npc.advanced.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
GuiSoundSelection gss = (GuiSoundSelection) subgui;
|
||||
if(gss.selectedResource != null) {
|
||||
getTextField(selectedId).setText(gss.selectedResource.toString());
|
||||
saveLines();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
saveLines();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user