diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java index 5fc09c88c..39e55df76 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java @@ -39,19 +39,10 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList addButton(new GuiNpcButton(10, guiLeft + 120, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(10, "advMode.command", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.hideNPC)); - addLabel(new GuiNpcLabel(11, "dialog.hideNPC", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.showWheel)); - addLabel(new GuiNpcLabel(12, "dialog.showWheel", guiLeft + 4, y + 5)); addButton(new GuiNpcButtonYesNo(15, guiLeft + 120, y += 22, dialog.disableEsc)); addLabel(new GuiNpcLabel(15, "dialog.disableEsc", guiLeft + 4, y + 5)); - addButton(new GuiNpcButtonYesNo(16, guiLeft + 120, y += 22, dialog.darkenScreen)); - addLabel(new GuiNpcLabel(16, "Darken Screen", guiLeft + 4, y + 5)); - this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); } @@ -63,18 +54,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList if(button.id == 10){ setSubGui(new SubGuiNpcCommand(dialog.command)); } - if(button.id == 11){ - dialog.hideNPC = button.getValue() == 1; - } - if(button.id == 12){ - dialog.showWheel = button.getValue() == 1; - } if(button.id == 15){ dialog.disableEsc = button.getValue() == 1; } - if(button.id == 16){ - dialog.darkenScreen = button.getValue() == 1; - } if(button.id == 13){ setSubGui(new SubGuiMailmanSendSetup(dialog.mail, getParent())); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java new file mode 100644 index 000000000..61d79ad58 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcVisualOptions.java @@ -0,0 +1,434 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.Minecraft; +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.global.GuiNPCManageDialogs; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; + +import java.util.ArrayList; +import java.util.Collections; + +public class SubGuiNpcVisualOptions extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener { + private final Dialog dialog; + public GuiScreen parent2; + + private GuiMenuTopButton[] topButtons; + private int activeMenu = 1; + + private GuiCustomScroll imageScroll; + private int selected = -1; + private int lastColorClicked = -1; + + public SubGuiNpcVisualOptions(Dialog dialog, GuiScreen parent) { + this.parent2 = parent; + this.dialog = dialog; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + int y = guiTop - 10; + + GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + xSize - 22, guiTop - 17, "X"); + GuiMenuTopButton general = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "General"); + GuiMenuTopButton spacing = new GuiMenuTopButton(2, general.xPosition + general.getWidth(), guiTop - 17, "Spacing"); + GuiMenuTopButton images = new GuiMenuTopButton(3, spacing.xPosition + spacing.getWidth(), guiTop - 17, "Images"); + topButtons = new GuiMenuTopButton[]{general,images,spacing,close}; + for(GuiMenuTopButton button : topButtons) + button.active = button.id == activeMenu; + + if (activeMenu == 1) { + addButton(new GuiNpcButtonYesNo(10, guiLeft + 120, y += 22, dialog.hideNPC)); + addLabel(new GuiNpcLabel(10, "dialog.hideNPC", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.showWheel)); + addLabel(new GuiNpcLabel(11, "dialog.showWheel", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.darkenScreen)); + addLabel(new GuiNpcLabel(12, "dialog.darkenScreen", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(13, guiLeft + 120, y += 22, 50, 20, new String[]{"dialog.instant", "dialog.gradual"}, dialog.renderGradual ? 1 : 0)); + addLabel(new GuiNpcLabel(13, "dialog.renderType", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.show", "display.hide"}, dialog.showPreviousBlocks ? 1 : 0)); + addLabel(new GuiNpcLabel(14, "dialog.previousBlocks", guiLeft + 4, y + 5)); + + if (dialog.renderGradual) { + addTextField(new GuiNpcTextField(15, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(15, "dialog.textSound", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(16, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(16, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(16).floatsOnly = true; + } + } else if (activeMenu == 2) { + addTextField(new GuiNpcTextField(10, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); + addTextField(new GuiNpcTextField(11, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); + addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); + addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); + addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); + addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); + addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); + addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); + addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(18, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); + addTextField(new GuiNpcTextField(19, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); + addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); + + for (int i = 10; i < 20; i++) { + GuiNpcTextField textField = this.getTextField(i); + textField.integersOnly = true; + } + } else if (activeMenu == 3) { + if (imageScroll == null) { + imageScroll = new GuiCustomScroll(this, 0, false); + imageScroll.guiLeft = guiLeft + xSize; + imageScroll.guiTop = guiTop + 25; + imageScroll.setSize(50, this.ySize - 25); + } + + updateScrollData(); + + this.addButton(new GuiNpcButton(1, guiLeft + xSize + 2, guiTop + 5, 20, 20, "+")); + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + this.addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-")); + + addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, String.valueOf(dialogImage.id))); + addTextField(new GuiNpcTextField(11, this, guiLeft + 92, y, 150, 20, dialogImage.texture)); + addLabel(new GuiNpcLabel(10, "gui.id", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(11, "display.texture", guiLeft + 50, y + 5)); + getTextField(10).integersOnly = true; + + addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.x))); + addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.y))); + addLabel(new GuiNpcLabel(12, "gui.position", guiLeft + 4, y + 5)); + getTextField(12).integersOnly = true; + getTextField(13).integersOnly = true; + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.width))); + addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.height))); + addLabel(new GuiNpcLabel(13, "gui.widthHeight", guiLeft + 4, y + 5)); + getTextField(14).integersOnly = true; + getTextField(15).integersOnly = true; + + addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.textureX))); + addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.textureY))); + addLabel(new GuiNpcLabel(14, "dialog.textureOffset", guiLeft + 4, y + 5)); + getTextField(16).integersOnly = true; + getTextField(17).integersOnly = true; + + String color = Integer.toHexString(dialogImage.color); + while(color.length() < 6) + color = 0 + color; + addButton(new GuiNpcButton(18, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(15, "gui.color", guiLeft + 4, y + 5)); + getButton(18).setTextColor(dialogImage.color); + + String selectedColor = Integer.toHexString(dialogImage.selectedColor); + while(selectedColor.length() < 6) + selectedColor = 0 + selectedColor; + addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); + addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); + getButton(19).setTextColor(dialogImage.selectedColor); + + addTextField(new GuiNpcTextField(20, this, guiLeft + 35, y += 25, 60, 20, String.valueOf(dialogImage.scale))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 180, y, 60, 20, String.valueOf(dialogImage.alpha))); + addLabel(new GuiNpcLabel(17, "model.scale", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 100, y + 5)); + getTextField(20).floatsOnly = true; + getTextField(21).floatsOnly = true; + + addTextField(new GuiNpcTextField(22, this, guiLeft + 47, y += 25, 60, 20, String.valueOf(dialogImage.rotation))); + addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 4, y + 5)); + getTextField(22).floatsOnly = true; + + addButton(new GuiNpcButton(23, guiLeft + 180, y, 60, 20, new String[]{"gui.default","gui.text","gui.option"}, dialogImage.imageType)); + addLabel(new GuiNpcLabel(20, "dialog.imageType", guiLeft + 115, y + 5)); + + if (dialogImage.imageType == 0) { + addButton(new GuiNpcButton(24, guiLeft + 180, y += 25, 60, 20, + new String[]{"display.topLeft", "display.topCenter", "display.topRight", + "display.left", "display.center", "display.right", + "display.botLeft", "display.botCenter", "display.botRight"}, + dialogImage.alignment)); + addLabel(new GuiNpcLabel(21, "display.alignment", guiLeft + 115, y + 5)); + } + } + } + } + + public void updateScrollData() { + ArrayList ids = new ArrayList<>(dialog.dialogImages.keySet()); + Collections.sort(ids); + ArrayList strings = new ArrayList<>(); + for (int i : ids) { + strings.add(String.valueOf(i)); + } + imageScroll.setList(strings); + addScroll(imageScroll); + } + + public void mouseClicked(int i, int j, int k) { + super.mouseClicked(i,j,k); + if (k == 0) { + Minecraft mc = Minecraft.getMinecraft(); + for (GuiMenuTopButton button : topButtons) { + if (button.mousePressed(mc, i, j)) { + topButtonPressed(button); + } + } + } + } + + private void topButtonPressed(GuiMenuTopButton button) { + Minecraft mc = Minecraft.getMinecraft(); + NoppesUtil.clickSound(); + + int id = button.id; + if(id == 0){ + close(); + if(parent2 != null) + NoppesUtil.openGUI(player, parent2); + return; + } + save(); + + activeMenu = id; + initGui(); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + GuiNpcButton button = (GuiNpcButton) guibutton; + + if (activeMenu == 1) { + if (button.id == 10) { + dialog.hideNPC = button.getValue() == 1; + } + if (button.id == 11) { + dialog.showWheel = button.getValue() == 1; + } + if (button.id == 12) { + dialog.darkenScreen = button.getValue() == 1; + } + if (button.id == 13) { + dialog.renderGradual = button.getValue() == 1; + } + if (button.id == 14) { + dialog.showPreviousBlocks = button.getValue() == 1; + } + } + + if (activeMenu == 3) { + if (button.id == 1) { + int addId = 0; + if (selected != -1 && imageScroll.getSelected() != null) { + DialogImage selectedImage = dialog.dialogImages.get(Integer.valueOf(imageScroll.getSelected())); + ArrayList keys = new ArrayList<>(dialog.dialogImages.keySet()); + int keyIndex = keys.indexOf(selectedImage.id); + do { + addId = keys.get(keyIndex) + 1; + keyIndex++; + } while (dialog.dialogImages.containsKey(addId)); + } else if (dialog.dialogImages.size() > 0) { + addId = (Integer) dialog.dialogImages.keySet().toArray()[dialog.dialogImages.size() - 1] + 1; + } + + dialog.dialogImages.put(addId, new DialogImage(addId)); + updateScrollData(); + selected = imageScroll.getList().indexOf(String.valueOf(addId)); + } + if (button.id == 2) { + if (imageScroll.getSelected() != null) { + dialog.dialogImages.remove(Integer.valueOf(imageScroll.getSelected())); + selected--; + } + } + if (button.id == 18) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.color)); + lastColorClicked = 0; + } + } + if (button.id == 19) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.selectedColor)); + lastColorClicked = 1; + } + } + if (button.id == 23) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.imageType = button.getValue(); + } + } + if (button.id == 24) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.alignment = button.getValue(); + } + } + } + + initGui(); + } + + @Override + public void drawScreen(int i, int j, float f){ + super.drawScreen(i,j,f); + for(GuiMenuTopButton button: topButtons) + button.drawButton(mc, i, j); + } + + + @Override + public void subGuiClosed(SubGuiInterface subgui){ + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + if (lastColorClicked == 0) { + dialogImage.color = ((SubGuiColorSelector) subgui).color; + } else if (lastColorClicked == 1) { + dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + } + initGui(); + } + save(); + } + + public void save() { + GuiNpcTextField.unfocus(); + if(dialog.id >= 0) + Client.sendData(EnumPacketServer.DialogSave, ((GuiNPCManageDialogs)parent2).category.id, dialog.writeToNBT(new NBTTagCompound())); + } + + private DialogImage getSelectedImage() { + if (selected > -1) { + return dialog.dialogImages.get((dialog.dialogImages.keySet().toArray(new Integer[0]))[selected]); + } else { + return null; + } + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if (activeMenu == 1) { + if (textfield.id == 15) { + dialog.textSound = textfield.getText(); + } + if (textfield.id == 16) { + dialog.textPitch = textfield.getFloat(); + } + } + + if (activeMenu == 2) { + int i = textfield.getInteger(); + + if (textfield.id == 10) { + dialog.textWidth = i; + } + if (textfield.id == 11) { + dialog.textHeight = i; + } + + if (textfield.id == 12) { + dialog.textOffsetX = i; + } + if (textfield.id == 13) { + dialog.textOffsetY = i; + } + + if (textfield.id == 14) { + dialog.titleOffsetX = i; + } + if (textfield.id == 15) { + dialog.titleOffsetY = i; + } + + if (textfield.id == 14) { + dialog.optionOffsetX = i; + } + if (textfield.id == 15) { + dialog.optionOffsetY = i; + } + + if (textfield.id == 14) { + dialog.optionSpaceX = i; + } + if (textfield.id == 15) { + dialog.optionSpaceY = i; + } + } + + if (activeMenu == 3) { + DialogImage dialogImage = getSelectedImage(); + if (dialogImage == null) { + return; + } + + if (textfield.id == 10) { + dialogImage.id = textfield.getInteger(); + } + if (textfield.id == 11) { + dialogImage.texture = textfield.getText(); + } + if (textfield.id == 12) { + dialogImage.x = textfield.getInteger(); + } + if (textfield.id == 13) { + dialogImage.y = textfield.getInteger(); + } + if (textfield.id == 14) { + dialogImage.width = textfield.getInteger(); + } + if (textfield.id == 15) { + dialogImage.height = textfield.getInteger(); + } + if (textfield.id == 16) { + dialogImage.textureX = textfield.getInteger(); + } + if (textfield.id == 17) { + dialogImage.textureY = textfield.getInteger(); + } + if (textfield.id == 20) { + dialogImage.scale = textfield.getFloat(); + } + if (textfield.id == 21) { + dialogImage.alpha = textfield.getFloat(); + } + if (textfield.id == 22) { + dialogImage.rotation = textfield.getFloat(); + } + } + + save(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0 && imageScroll != null) { + selected = guiCustomScroll.selected; + initGui(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java index b1402308f..2525b1d42 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -71,7 +71,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent float green = (color >> 8 & 255) / 255f; float blue = (color & 255) / 255f; - GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glScalef(this.scale, this.scale, this.scale); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 77d9025b8..ff3455fd8 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -7,12 +7,7 @@ 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.GuiNpcSoundSelection; -import noppes.npcs.client.gui.SubGuiNpcAvailability; -import noppes.npcs.client.gui.SubGuiNpcDialogExtra; -import noppes.npcs.client.gui.SubGuiNpcDialogOptions; -import noppes.npcs.client.gui.SubGuiNpcFactionOptions; -import noppes.npcs.client.gui.SubGuiNpcTextArea; +import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.client.gui.util.GuiNPCInterface2; @@ -35,7 +30,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData private GuiCustomScroll scroll; private HashMap data = new HashMap(); private Dialog dialog = new Dialog(); - private DialogCategory category = new DialogCategory(); + public DialogCategory category = new DialogCategory(); private boolean categorySelection = true; private GuiNpcSoundSelection gui; @@ -88,14 +83,17 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData addLabel(new GuiNpcLabel(6, "dialog.options", guiLeft + 4, guiTop + 93)); addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 89, 50, 20, "selectServer.edit")); - addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 114, 144, 20, "availability.selectquest")); - addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 114, 20, 20, "X")); + addLabel(new GuiNpcLabel(11, "dialog.visualOption", guiLeft + 4, guiTop + 115)); + addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 110, 50, 20, "selectServer.edit")); - addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 138)); - addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 148, 144, 20, dialog.sound)); - addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 148, 60, 20, "mco.template.button.select")); + addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 134, 144, 20, "availability.selectquest")); + addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 134, 20, 20, "X")); - addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 172, 120, 20, "gui.showmore")); + 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() { @@ -183,6 +181,9 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData if(id == 10){ setSubGui(new SubGuiNpcDialogExtra(dialog, this)); } + if(id == 11){ + setSubGui(new SubGuiNpcVisualOptions(dialog, this)); + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java index 4ac3b5360..f001c5139 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java @@ -7,45 +7,53 @@ import net.minecraft.client.renderer.texture.ITextureObject; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.ImageDownloadAlt; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.renderer.ImageBufferDownloadAlt; -import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; -import noppes.npcs.scripted.interfaces.gui.ICustomGuiComponent; +import noppes.npcs.controllers.data.DialogImage; import org.lwjgl.opengl.GL11; public class GuiDialogImage extends Gui { GuiDialogInteract parent; - String texture; ResourceLocation location; - int id; - int x; - int y; - int width; - int height; - int textureX; - int textureY; - float scale; - int color; - float alpha; - float rotation; + public int id; + public String texture; + public int x; + public int y; + public int width; + public int height; + public int textureX; + public int textureY; + public float scale; - public GuiDialogImage(int id, String texture, int x, int y, int width, int height) { - this(id, texture, x, y, width, height, 0, 0); - } + public int color; + public int selectedColor; + public float alpha; + public float rotation; - public GuiDialogImage(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { - this.color = 0xFFFFFF; - this.alpha = 1.0F; - this.scale = 1.0F; - this.id = id; - this.texture = texture; - this.location = new ResourceLocation(texture); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.textureX = textureX; - this.textureY = textureY; + public int imageType = 0; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public GuiDialogImage(DialogImage dialogImage) { + this.location = new ResourceLocation(dialogImage.texture); + + this.id = dialogImage.id; + this.texture = dialogImage.texture; + this.x = dialogImage.x; + this.y = dialogImage.y; + this.width = dialogImage.width; + this.height = dialogImage.height; + this.textureX = dialogImage.textureX; + this.textureY = dialogImage.textureY; + this.scale = dialogImage.scale; + + this.color = dialogImage.color; + this.selectedColor = dialogImage.selectedColor; + this.rotation = dialogImage.rotation; + this.alpha = dialogImage.alpha; + + this.imageType = dialogImage.imageType; + this.alignment = dialogImage.alignment; if(texture.startsWith("https://")){ TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); @@ -73,6 +81,7 @@ public class GuiDialogImage extends Gui { float blue = (color & 255) / 255f; GL11.glColor4f(red,green,blue,this.alpha); + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); GL11.glScalef(this.scale, this.scale, this.scale); @@ -96,29 +105,4 @@ public class GuiDialogImage extends Gui { tessellator.draw(); GL11.glPopMatrix(); } - - public ICustomGuiComponent toComponent() { - ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.location.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); - component.setScale(this.scale); - component.setColor(color); - component.setAlpha(alpha); - component.setRotation(rotation); - return component; - } - - public static GuiDialogImage fromComponent(ScriptGuiTexturedRect component) { - GuiDialogImage rect; - if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { - rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); - } else { - rect = new GuiDialogImage(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); - } - - rect.scale = component.getScale(); - rect.color = component.getColor(); - rect.alpha = component.getAlpha(); - rect.rotation = component.getRotation(); - - return rect; - } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index df5c95e16..1d960ceea 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -25,6 +25,7 @@ import noppes.npcs.client.gui.util.IGuiClose; import noppes.npcs.constants.EnumOptionType; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.entity.EntityNPCInterface; @@ -69,25 +70,22 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose * DIALOG VARIABLES * * */ - private boolean renderGradual = false; - private boolean showPreviousBlocks = true; + private final boolean renderGradual; + private final boolean showPreviousBlocks; - private int dialogWidth = 300; - private int dialogHeight = 400; + private final String textSound; + private final float textPitch; - private int textOffsetX, textOffsetY; - private int titleOffsetX, titleOffsetY; + private final int textWidth; + private final int textHeight; - private int optionSpaceX, optionSpaceY; - private int optionOffsetX, optionOffsetY; + private final int textOffsetX, textOffsetY; + private final int titleOffsetX, titleOffsetY; - private String textSound = "minecraft:random.wood_click"; - private float textPitch = 1.0F; + private final int optionSpaceX, optionSpaceY; + private final int optionOffsetX, optionOffsetY; - private HashMap dialogImages = new HashMap<>(); - private GuiDialogImage textImage; - private GuiDialogImage optionImage; - private int selectedImageColor = 0xFFFF00; + private final ArrayList dialogImages = new ArrayList<>(); public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); @@ -95,9 +93,24 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose appendDialog(dialog); ySize = 238; - //textImage = new GuiDialogImage(0, "customnpcs:textures/gui/largebg.png", 0,0, 176, 71); - //textImage.scale = 2; - optionImage = new GuiDialogImage(0, "customnpcs:textures/gui/info.png", 0,0, 256, 256); + this.renderGradual = dialog.renderGradual; + this.showPreviousBlocks = dialog.showPreviousBlocks; + this.textSound = dialog.textSound; + this.textPitch = dialog.textPitch; + this.textWidth = dialog.textWidth; + this.textHeight = dialog.textHeight; + this.textOffsetX = dialog.textOffsetX; + this.textOffsetY = dialog.textOffsetY; + this.titleOffsetX = dialog.titleOffsetX; + this.titleOffsetY = dialog.titleOffsetY; + this.optionSpaceX = dialog.optionSpaceX; + this.optionSpaceY = dialog.optionSpaceY; + this.optionOffsetX = dialog.optionOffsetX; + this.optionOffsetY = dialog.optionOffsetY; + + for (DialogImage dialogImage : dialog.dialogImages.values()) { + dialogImages.add(new GuiDialogImage(dialogImage)); + } wheel = this.getResource("wheel.png"); indicator = this.getResource("indicator.png"); @@ -192,7 +205,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); } - for (GuiDialogImage image : dialogImages.values()) { + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 0) + continue; + GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GL11.glDisable(GL11.GL_ALPHA_TEST); @@ -207,12 +223,23 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glPushMatrix(); GL11.glTranslatef(textOffsetX, 0.0F, 0.0F); - if (textImage != null && !textImage.texture.isEmpty()) { - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - textImage.height * textImage.scale, 0.0F); - textImage.onRender(mc); - GL11.glPopMatrix(); + GL11.glPushMatrix(); + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 1) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft + textOffsetX, optionStart + textOffsetY - image.height * image.scale, 0.0F); + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } + GL11.glPopMatrix(); if (!renderGradual) { int count = 0; @@ -453,17 +480,25 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - if (optionImage != null && !optionImage.texture.equals("")) { - int originalColor = optionImage.color; - if(selected == k){ - optionImage.color = selectedImageColor; - } - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); - optionImage.onRender(mc); - optionImage.color = originalColor; - GL11.glPopMatrix(); + + GL11.glPushMatrix(); + for (GuiDialogImage image : dialogImages) { + if (image.imageType != 2) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft - 30 + optionSpaceX * k, y, 0.0F); + image.color = selected == k ? image.selectedColor : image.color; + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } + GL11.glPopMatrix(); drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + optionSpaceX * k, y, option.optionColor); GL11.glPopMatrix(); @@ -475,7 +510,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose int height = count - totalRows + lineOffset; int screenPos = optionStart; int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; - if (y < screenPos - dialogHeight || y > screenPos - ClientProxy.Font.height()) { + if (y < screenPos - textHeight || y > screenPos - ClientProxy.Font.height()) { return; } @@ -575,7 +610,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, dialogWidth, option.optionColor, player, npc)); + lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, textWidth, option.optionColor, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; @@ -611,7 +646,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, dialogWidth, 0xe0e0e0, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog.text, textWidth, 0xe0e0e0, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 76ef188c1..4373f1ccb 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -33,6 +33,28 @@ public class Dialog implements ICompatibilty, IDialog { public boolean showWheel = false; public boolean disableEsc = false; public boolean darkenScreen = true; + + + /** + * Add these variables to NBT reads & writes + */ + + public boolean renderGradual = false; + public boolean showPreviousBlocks = true; + + public String textSound = "minecraft:random.wood_click"; + public float textPitch = 1.0F; + + public int textWidth = 300; + public int textHeight = 400; + + public int textOffsetX, textOffsetY; + public int titleOffsetX, titleOffsetY; + + public int optionSpaceX, optionSpaceY; + public int optionOffsetX, optionOffsetY; + + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { for(DialogOption option: options.values()) @@ -82,6 +104,44 @@ public class Dialog implements ICompatibilty, IDialog { } this.options = newoptions; + NBTTagList images = compound.getTagList("Images", 10); + HashMap newImages = new HashMap<>(); + for(int i = 0; i < images.tagCount(); i++){ + NBTTagCompound imageCompound = images.getCompoundTagAt(i); + int id = imageCompound.getInteger("ID"); + DialogImage image = new DialogImage(id); + image.readNBT(imageCompound); + newImages.put(id, image); + } + this.dialogImages = newImages; + + renderGradual = compound.getBoolean("RenderGradual"); + showPreviousBlocks = compound.getBoolean("PreviousBlocks"); + textSound = compound.getString("TextSound"); + textPitch = compound.getFloat("TextPitch"); + textWidth = compound.getInteger("TextWidth"); + textHeight = compound.getInteger("TextHeight"); + textOffsetX = compound.getInteger("TextOffsetX"); + textOffsetY = compound.getInteger("TextOffsetY"); + titleOffsetX = compound.getInteger("TitleOffsetX"); + titleOffsetY = compound.getInteger("TitleOffsetY"); + optionOffsetX = compound.getInteger("OptionOffsetX"); + optionOffsetY = compound.getInteger("OptionOffsetY"); + optionSpaceX = compound.getInteger("OptionSpaceX"); + optionSpaceY = compound.getInteger("OptionSpaceY"); + + if (!compound.hasKey("PreviousBlocks")) + showPreviousBlocks = true; + if (!compound.hasKey("TextSound")) + textSound = "minecraft:random.wood_click"; + if (!compound.hasKey("TextPitch")) + textPitch = 1.0F; + if (!compound.hasKey("TextWidth")) + textWidth = 300; + if (!compound.hasKey("TextHeight")) + textWidth = 400; + + availability.readFromNBT(compound); factionOptions.readFromNBT(compound); } @@ -119,6 +179,29 @@ public class Dialog implements ICompatibilty, IDialog { availability.writeToNBT(compound); factionOptions.writeToNBT(compound); compound.setInteger("ModRev", version); + + compound.setBoolean("RenderGradual", renderGradual); + compound.setBoolean("PreviousBlocks", showPreviousBlocks); + compound.setString("TextSound", textSound); + compound.setFloat("TextPitch", textPitch); + compound.setInteger("TextWidth", textWidth); + compound.setInteger("TextHeight", textHeight); + compound.setInteger("TextOffsetX", textOffsetX); + compound.setInteger("TextOffsetY", textOffsetY); + compound.setInteger("TitleOffsetX", titleOffsetX); + compound.setInteger("TitleOffsetY", titleOffsetY); + compound.setInteger("OptionOffsetX", optionOffsetX); + compound.setInteger("OptionOffsetY", optionOffsetY); + compound.setInteger("OptionSpaceX", optionSpaceX); + compound.setInteger("OptionSpaceY", optionSpaceY); + + NBTTagList images = new NBTTagList(); + for (DialogImage dialogImage : dialogImages.values()) { + NBTTagCompound imageCompound = dialogImage.writeToNBT(new NBTTagCompound()); + images.appendTag(imageCompound); + } + compound.setTag("Images",images); + return compound; } diff --git a/src/main/java/noppes/npcs/controllers/data/DialogImage.java b/src/main/java/noppes/npcs/controllers/data/DialogImage.java new file mode 100644 index 000000000..e02957fda --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/DialogImage.java @@ -0,0 +1,65 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; + +public class DialogImage { + public int id; + public String texture = ""; + public int x = 0; + public int y = 0; + public int width = 0; + public int height = 0; + public int textureX = 0; + public int textureY = 0; + public float scale = 1.0F; + + public int color = 0xFFFFFF; + public int selectedColor = 0xFFFFFF; + public float alpha = 1.0F; + public float rotation = 0; + + public int imageType = 1; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public DialogImage(int id) { + this.id = id; + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setInteger("ID", id); + compound.setString("Texture", texture); + compound.setInteger("PosX", x); + compound.setInteger("PosY", y); + compound.setInteger("Width", width); + compound.setInteger("Height", height); + compound.setInteger("TextureX", textureX); + compound.setInteger("TextureY", textureY); + compound.setFloat("Scale", scale); + compound.setInteger("Color", color); + compound.setInteger("SelectedColor", selectedColor); + compound.setFloat("Alpha", alpha); + compound.setFloat("Rotation", rotation); + compound.setInteger("ImageType", imageType); + compound.setInteger("Alignment", alignment); + + return compound; + } + + public void readNBT(NBTTagCompound compound) { + id = compound.getInteger("ID"); + texture = compound.getString("Texture"); + x = compound.getInteger("PosX"); + y = compound.getInteger("PosY"); + width = compound.getInteger("Width"); + height = compound.getInteger("Height"); + textureX = compound.getInteger("TextureX"); + textureY = compound.getInteger("TextureY"); + scale = compound.getFloat("Scale"); + color = compound.getInteger("Color"); + selectedColor = compound.getInteger("SelectedColor"); + alpha = compound.getFloat("Alpha"); + rotation = compound.getFloat("Rotation"); + imageType = compound.getInteger("ImageType"); + alignment = compound.getInteger("Alignment"); + } +} diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 2891b0adc..aa52c7982 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -116,6 +116,12 @@ gui.update=Update gui.editor=Editor gui.playernearby=Player nearby gui.forum=Forum +gui.id=ID +gui.widthHeight=Width & Height +gui.position=Position +gui.option=Option +gui.text=Text +gui.default=Default remote.title=Nearby NPCs remote.reset=Reset @@ -175,6 +181,17 @@ display.bossbar=BossBar display.squareTexture=Square Texture display.url=Url display.urlSix=Url64 +display.alpha=Alpha +display.alignment=Alignment +display.topLeft=Top Left +display.topCenter=Top Center +display.topRight=Top Right +display.left=Left +display.center=Center +display.right=Right +display.botLeft=Bottom Left +display.botCenter=Bottom Center +display.botRight=Bottom Right inv.minExp=Min Exp inv.maxExp=Max Exp @@ -416,6 +433,21 @@ dialog.commandoptionplayer=Use "@dp" to target the player using this dialog.hideNPC=Hide NPC dialog.showWheel=Show Dialog Wheel dialog.disableEsc=Disable Esc +dialog.visualOption=Visual Options +dialog.darkenScreen=Darken Screen +dialog.renderType=Render Type +dialog.instant=Instant +dialog.gradual=Gradual +dialog.previousBlocks=Previous Text Blocks +dialog.textOffset=Text Offset +dialog.titleOffset=Title Offset +dialog.optionOffset=Option Offset +dialog.optionSpacing=Option Spacing +dialog.textSound=Text Sound +dialog.textPitch=Text Pitch +dialog.textureOffset=Texture Offset +dialog.selectedColor=Selected Color +dialog.imageType=Image Type quest.quest=Quest quest.quests=Quests