2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.gui;
|
|
|
|
|
|
2025-02-02 18:10:57 -05:00
|
|
|
import kamkeel.npcs.network.packets.request.dialog.DialogGetPacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2024-03-13 18:40:40 -04:00
|
|
|
import noppes.npcs.client.gui.select.GuiDialogSelection;
|
2025-07-23 14:22:52 -04:00
|
|
|
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.GuiSelectionListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.IGuiData;
|
|
|
|
|
import noppes.npcs.client.gui.util.ISubGuiListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.ITextfieldListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.SubGuiInterface;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.constants.EnumOptionType;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.data.Dialog;
|
|
|
|
|
import noppes.npcs.controllers.data.DialogOption;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, ITextfieldListener, GuiSelectionListener, ISubGuiListener {
|
|
|
|
|
private DialogOption option;
|
|
|
|
|
public static int LastColor = 0xe0e0e0;
|
|
|
|
|
|
|
|
|
|
public SubGuiNpcDialogOption(DialogOption option) {
|
|
|
|
|
this.option = option;
|
|
|
|
|
setBackground("menubg.png");
|
|
|
|
|
xSize = 256;
|
|
|
|
|
ySize = 216;
|
|
|
|
|
closeOnEsc = true;
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public void initGui() {
|
2018-09-13 12:03:28 -04:00
|
|
|
super.initGui();
|
|
|
|
|
this.addLabel(new GuiNpcLabel(66, "dialog.editoption", guiLeft, guiTop + 4));
|
|
|
|
|
this.getLabel(66).center(xSize);
|
2024-03-13 18:40:40 -04:00
|
|
|
|
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));
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
String color = Integer.toHexString(option.optionColor);
|
2025-03-13 17:14:45 -04:00
|
|
|
while (color.length() < 6)
|
|
|
|
|
color = 0 + color;
|
2018-09-13 12:03:28 -04:00
|
|
|
addLabel(new GuiNpcLabel(2, "gui.color", guiLeft + 4, guiTop + 45));
|
2025-03-13 17:14:45 -04:00
|
|
|
this.addButton(new GuiNpcButton(2, guiLeft + 62, guiTop + 40, 92, 20, color));
|
|
|
|
|
this.getButton(2).setTextColor(option.optionColor);
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
this.addLabel(new GuiNpcLabel(1, "dialog.optiontype", guiLeft + 4, guiTop + 67));
|
2025-03-13 17:14:45 -04:00
|
|
|
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()));
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (option.optionType == EnumOptionType.DialogOption) {
|
|
|
|
|
this.addButton(new GuiNpcButton(3, guiLeft + 4, guiTop + 84, "availability.selectdialog"));
|
|
|
|
|
if (option.dialogId >= 0)
|
2025-02-02 18:10:57 -05:00
|
|
|
DialogGetPacket.getDialog(option.dialogId);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
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);
|
2018-09-13 12:03:28 -04:00
|
|
|
|
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));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190, 98, 20, "gui.done"));
|
2024-03-13 18:40:40 -04:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
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) {
|
2024-03-13 18:40:40 -04:00
|
|
|
setSubGui(new GuiDialogSelection(option.dialogId));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (button.id == 66) {
|
|
|
|
|
close();
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@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();
|
2024-03-13 18:40:40 -04:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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) {
|
2024-03-13 18:40:40 -04:00
|
|
|
option.dialogId = dialog.id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
initGui();
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
}
|