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

128 lines
4.5 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.select.GuiDialogSelection;
2023-01-12 21:33:06 -05:00
import noppes.npcs.client.gui.util.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.constants.EnumOptionType;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
2018-09-13 12:03:28 -04:00
public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, ITextfieldListener, GuiSelectionListener, ISubGuiListener{
private DialogOption option;
public static int LastColor = 0xe0e0e0;
2018-09-13 12:03:28 -04:00
public SubGuiNpcDialogOption(DialogOption option){
this.option = option;
setBackground("menubg.png");
xSize = 256;
ySize = 216;
closeOnEsc = true;
}
@Override
public void initGui(){
super.initGui();
this.addLabel(new GuiNpcLabel(66, "dialog.editoption", guiLeft, guiTop + 4));
this.getLabel(66).center(xSize);
2018-09-13 12:03:28 -04:00
this.addLabel(new GuiNpcLabel(0, "gui.title", guiLeft + 4, guiTop + 20));
this.addTextField(new GuiNpcTextField(0, this, this.fontRendererObj, guiLeft + 40, guiTop + 15, 196, 20, option.title));
2018-09-13 12:03:28 -04:00
String color = Integer.toHexString(option.optionColor);
while(color.length() < 6)
color = 0 + color;
addLabel(new GuiNpcLabel(2, "gui.color", guiLeft + 4, guiTop + 45));
this.addButton(new GuiNpcButton(2, guiLeft + 62, guiTop + 40, 92, 20, color));
this.getButton(2).setTextColor(option.optionColor);
2018-09-13 12:03:28 -04:00
this.addLabel(new GuiNpcLabel(1, "dialog.optiontype", guiLeft + 4, guiTop + 67));
this.addButton(new GuiNpcButton(1, guiLeft + 62, guiTop + 62, 92, 20, new String[]{"gui.close","dialog.dialog","gui.disabled","menu.role","tile.commandBlock.name"},option.optionType.ordinal()));
if(option.optionType == EnumOptionType.DialogOption){
this.addButton(new GuiNpcButton(3, guiLeft + 4, guiTop + 84, "availability.selectdialog"));
if(option.dialogId >= 0)
Client.sendData(EnumPacketServer.DialogGet, option.dialogId);
}
if(option.optionType == EnumOptionType.CommandBlock){
this.addTextField(new GuiNpcTextField(4, this, this.fontRendererObj, guiLeft + 4, guiTop + 84, 248, 20, option.command));
this.getTextField(4).setMaxStringLength(32767);
2024-03-13 19:32:22 -04:00
this.addLabel(new GuiNpcLabel(5, "advMode.nearestPlayer", guiLeft + 4, guiTop + 110));
this.addLabel(new GuiNpcLabel(6, "advMode.randomPlayer", guiLeft + 4, guiTop + 125));
this.addLabel(new GuiNpcLabel(7, "advMode.allPlayers", guiLeft + 4, guiTop + 140));
this.addLabel(new GuiNpcLabel(8, "dialog.commandoptionplayer", guiLeft + 4, guiTop + 155));
this.addLabel(new GuiNpcLabel(9, "dialog.commandmultiple", guiLeft + 4, guiTop + 170));
2018-09-13 12:03:28 -04:00
}
this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190,98, 20, "gui.done"));
2018-09-13 12:03:28 -04:00
}
@Override
protected void actionPerformed(GuiButton guibutton){
GuiNpcButton button = (GuiNpcButton) guibutton;
if(button.id == 1){
option.optionType = EnumOptionType.values()[button.getValue()];
initGui();
}
if(button.id == 2){
this.setSubGui(new SubGuiColorSelector(option.optionColor));
}
if(button.id == 3){
setSubGui(new GuiDialogSelection(option.dialogId));
2018-09-13 12:03:28 -04:00
}
if(button.id == 66)
{
close();
}
}
@Override
public void unFocused(GuiNpcTextField textfield) {
if(textfield.id == 0){
if(textfield.isEmpty())
textfield.setText(option.title);
else{
option.title = textfield.getText();
}
}
if(textfield.id == 4){
option.command = textfield.getText();
}
}
@Override
public void setGuiData(NBTTagCompound compound) {
if(compound.hasKey("DialogId")){
Dialog dialog = new Dialog();
dialog.readNBT(compound);
option.dialogId = dialog.id;
if(this.getButton(3) != null)
getButton(3).setDisplayText(dialog.title);
}
}
@Override
public void selected(int ob, String name) {
option.dialogId = ob;
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if(subgui instanceof SubGuiColorSelector) {
LastColor = option.optionColor = ((SubGuiColorSelector)subgui).color;
}
if(subgui instanceof GuiDialogSelection) {
Dialog dialog = ((GuiDialogSelection)subgui).selectedDialog;
if(dialog != null) {
option.dialogId = dialog.id;
}
}
initGui();
2018-09-13 12:03:28 -04:00
}
}