From ff8fc68e88052039ddb844c4d4af224f0b786048 Mon Sep 17 00:00:00 2001 From: "Luis C.M" Date: Fri, 10 Jun 2022 01:38:01 -0500 Subject: [PATCH] Implemented dialog and text colors. --- .../noppes/npcs/client/TextBlockClient.java | 4 +- .../client/gui/SubGuiNpcDialogVisual.java | 123 ++++++++++++------ .../client/gui/player/GuiDialogInteract.java | 16 +-- .../npcs/client/gui/util/GuiNpcTextField.java | 4 + .../noppes/npcs/controllers/data/Dialog.java | 29 ++++- .../assets/customnpcs/lang/en_US.lang | 3 + 6 files changed, 132 insertions(+), 47 deletions(-) diff --git a/src/main/java/noppes/npcs/client/TextBlockClient.java b/src/main/java/noppes/npcs/client/TextBlockClient.java index b5f476bcc..68c40cf92 100644 --- a/src/main/java/noppes/npcs/client/TextBlockClient.java +++ b/src/main/java/noppes/npcs/client/TextBlockClient.java @@ -13,12 +13,14 @@ import noppes.npcs.entity.EntityNPCInterface; public class TextBlockClient extends TextBlock{ private ChatStyle style; public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; private String name; private ICommandSender sender; - public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, Object... obs) { + public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, int titleColor, Object... obs) { this(text, lineWidth, false, obs); this.color = color; + this.titleColor = titleColor; this.sender = sender; } public TextBlockClient(String name, String text, int lineWidth, int color, Object... obs) { diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java index 0e4d940c6..0f514285a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -26,8 +26,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis private GuiCustomScroll imageScroll; private int selected = -1; private int lastColorClicked = -1; - - private long lastClickedTime = 0; private int changedId = -1; public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) { @@ -73,16 +71,32 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis addButton(new GuiNpcButton(15, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); addLabel(new GuiNpcLabel(15, "dialog.optionLine", guiLeft + 4, y + 5)); - addTextField(new GuiNpcTextField(16, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); - addLabel(new GuiNpcLabel(16, "dialog.textSound", guiLeft + 4, y + 5)); - getTextField(16).setVisible(dialog.renderGradual); - getLabel(16).enabled = dialog.renderGradual; + String color = Integer.toHexString(dialog.color); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(16, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(16, "gui.color", guiLeft + 4, y + 5)); + getButton(16).setTextColor(dialog.color); - addTextField(new GuiNpcTextField(17, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); - addLabel(new GuiNpcLabel(17, "dialog.textPitch", guiLeft + 4, y + 5)); - getTextField(17).floatsOnly = true; - getTextField(17).setVisible(dialog.renderGradual); - getLabel(17).enabled = dialog.renderGradual; + color = Integer.toHexString(dialog.titleColor); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(17, guiLeft + 180, y, 60, 20, color)); + addLabel(new GuiNpcLabel(17, "dialog.titleColor", guiLeft + 100, y + 5)); + getButton(17).setTextColor(dialog.titleColor); + + addTextField(new GuiNpcTextField(18, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(18, "dialog.textSound", guiLeft + 4, y + 5)); + getTextField(18).setVisible(dialog.renderGradual); + getLabel(18).enabled = dialog.renderGradual; + + addTextField(new GuiNpcTextField(19, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(19, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(19).floatsOnly = true; + getTextField(19).setVisible(dialog.renderGradual); + getLabel(19).enabled = dialog.renderGradual; } 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))); @@ -124,10 +138,23 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis getTextField(19).integersOnly = true; getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); - for (int i = 10; i < 20; i++) { - GuiNpcTextField textField = this.getTextField(i); - textField.integersOnly = true; - } + addTextField(new GuiNpcTextField(20, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY))); + addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5)); + getTextField(20).integersOnly = true; + getTextField(20).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(20).setVisible(!dialog.hideNPC); + getTextField(21).integersOnly = true; + getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(21).setVisible(!dialog.hideNPC); + getLabel(25).enabled = !dialog.hideNPC; + + addTextField(new GuiNpcTextField(22, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale))); + addLabel(new GuiNpcLabel(26, "dialog.npcScale", guiLeft + 4, y + 5)); + getTextField(22).floatsOnly = true; + getTextField(22).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0); + getTextField(22).setVisible(!dialog.hideNPC); + getLabel(26).enabled = !dialog.hideNPC; } else if (activeMenu == 3) { if (imageScroll == null) { imageScroll = new GuiCustomScroll(this, 0, false); @@ -277,6 +304,14 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (button.id == 15) { dialog.showOptionLine = button.getValue() == 1; } + if (button.id == 16) { + setSubGui(new SubGuiColorSelector(dialog.color)); + lastColorClicked = 0; + } + if (button.id == 17) { + setSubGui(new SubGuiColorSelector(dialog.titleColor)); + lastColorClicked = 1; + } } if (activeMenu == 3) { @@ -322,10 +357,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis if (getSelectedImage() != null) { DialogImage dialogImage = getSelectedImage(); dialogImage.imageType = button.getValue(); - - if (dialogImage.imageType == 2) { - lastClickedTime++; - } } } if (button.id == 24) { @@ -349,15 +380,25 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis @Override public void subGuiClosed(SubGuiInterface subgui){ - if (getSelectedImage() != null) { - DialogImage dialogImage = getSelectedImage(); + if (activeMenu == 1) { if (lastColorClicked == 0) { - dialogImage.color = ((SubGuiColorSelector) subgui).color; + dialog.color = ((SubGuiColorSelector) subgui).color; } else if (lastColorClicked == 1) { - dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + dialog.titleColor = ((SubGuiColorSelector) subgui).color; } initGui(); } + if (activeMenu == 3) { + 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(); } @@ -378,50 +419,58 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis @Override public void unFocused(GuiNpcTextField textfield) { if (activeMenu == 1) { - if (textfield.id == 16) { + if (textfield.id == 18) { dialog.textSound = textfield.getText(); } - if (textfield.id == 17) { + if (textfield.id == 19) { dialog.textPitch = textfield.getFloat(); } } if (activeMenu == 2) { - int i = textfield.getInteger(); - if (textfield.id == 10) { - dialog.textWidth = i; + dialog.textWidth = textfield.getInteger(); } if (textfield.id == 11) { - dialog.textHeight = i; + dialog.textHeight = textfield.getInteger(); } if (textfield.id == 12) { - dialog.textOffsetX = i; + dialog.textOffsetX = textfield.getInteger(); } if (textfield.id == 13) { - dialog.textOffsetY = i; + dialog.textOffsetY = textfield.getInteger(); } if (textfield.id == 14) { - dialog.titleOffsetX = i; + dialog.titleOffsetX = textfield.getInteger(); } if (textfield.id == 15) { - dialog.titleOffsetY = i; + dialog.titleOffsetY = textfield.getInteger(); } if (textfield.id == 16) { - dialog.optionOffsetX = i; + dialog.optionOffsetX = textfield.getInteger(); } if (textfield.id == 17) { - dialog.optionOffsetY = i; + dialog.optionOffsetY = textfield.getInteger(); } if (textfield.id == 18) { - dialog.optionSpaceX = i; + dialog.optionSpaceX = textfield.getInteger(); } if (textfield.id == 19) { - dialog.optionSpaceY = i; + dialog.optionSpaceY = textfield.getInteger(); + } + + if (textfield.id == 20) { + dialog.npcOffsetX = textfield.getInteger(); + } + if (textfield.id == 21) { + dialog.npcOffsetY = textfield.getInteger(); + } + if (textfield.id == 22) { + dialog.npcScale = textfield.getFloat(); } } 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 14ead84cb..8eaf66eb9 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -111,7 +111,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose float i1 = (guiTop + ySize); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glPushMatrix(); - GL11.glTranslatef(l, i1, 50F); + GL11.glTranslatef(l + dialog.npcOffsetX, i1 + dialog.npcOffsetY, 50F); float zoomed = npc.height; if(npc.width * 2 > zoomed) zoomed = npc.width * 2; @@ -138,10 +138,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose RenderManager.instance.playerViewY = 180F; try{ + GL11.glScalef(dialog.npcScale,dialog.npcScale,dialog.npcScale); RenderManager.instance.renderEntityWithPosYaw(npc, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - } - catch(Exception e){ - } + } catch(Exception ignored){} + npc.ai.orientation = rotation; npc.renderYawOffset = f2; npc.rotationYaw = f3; @@ -212,7 +212,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose TextBlockClient block = lineBlocks.get(b); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (int l = 0; l < block.lines.size(); l++) { IChatComponent line = block.lines.get(l); @@ -265,7 +265,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { TextBlockClient block = lineBlocks.get(pastBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (IChatComponent line : block.lines) { drawDialogString(line.getFormattedText(), 0, block.color, count, true); @@ -277,7 +277,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (currentBlock < lineBlocks.size()) { TextBlockClient block = lineBlocks.get(currentBlock); int size = ClientProxy.Font.width(block.getName() + " "); - drawDialogString(block.getName() + " ", -4 - size, block.color, count, false); + drawDialogString(block.getName() + " ", -4 - size, block.titleColor, count, false); for (int pastLine = 0; pastLine < currentLine; pastLine++) { IChatComponent line = block.lines.get(pastLine); @@ -615,7 +615,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose if (!dialog.showPreviousBlocks) { lineBlocks.clear(); } - lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, 0xe0e0e0, player, npc)); + lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, dialog.color, dialog.titleColor, player, npc)); gradualText = ""; currentBlock = lineBlocks.size()-1; currentLine = 0; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 6060d5cea..a45c5d062 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -43,6 +43,10 @@ public class GuiNpcTextField extends GuiTextField{ private boolean charAllowed(char c, int i){ if(!integersOnly || Character.isDigit(c)) return true; + + if(integersOnly && getText().isEmpty() && c == '-') + return true; + for(int j : allowedSpecialChars) if(j == i) return true; diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index ae753f1c2..5eea59e46 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -28,7 +28,10 @@ public class Dialog implements ICompatibilty, IDialog { public String sound; public String command = ""; public PlayerMail mail = new PlayerMail(); - + + public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; + public boolean hideNPC = false; public boolean showWheel = false; public boolean disableEsc = false; @@ -50,6 +53,9 @@ public class Dialog implements ICompatibilty, IDialog { public int optionSpaceX, optionSpaceY; public int optionOffsetX, optionOffsetY; + public float npcScale = 1.0F; + public int npcOffsetX, npcOffsetY; + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { @@ -111,6 +117,8 @@ public class Dialog implements ICompatibilty, IDialog { } this.dialogImages = newImages; + color = compound.getInteger("Color"); + titleColor = compound.getInteger("TitleColor"); renderGradual = compound.getBoolean("RenderGradual"); showPreviousBlocks = compound.getBoolean("PreviousBlocks"); showOptionLine = compound.getBoolean("ShowOptionLine"); @@ -126,6 +134,9 @@ public class Dialog implements ICompatibilty, IDialog { optionOffsetY = compound.getInteger("OptionOffsetY"); optionSpaceX = compound.getInteger("OptionSpaceX"); optionSpaceY = compound.getInteger("OptionSpaceY"); + npcScale = compound.getFloat("NPCScale"); + npcOffsetX = compound.getInteger("NPCOffsetX"); + npcOffsetY = compound.getInteger("NPCOffsetY"); if (!compound.hasKey("PreviousBlocks")) showPreviousBlocks = true; @@ -139,6 +150,12 @@ public class Dialog implements ICompatibilty, IDialog { textHeight = 400; if (!compound.hasKey("ShowOptionLine")) showOptionLine = true; + if (!compound.hasKey("NPCScale")) + npcScale = 1.0F; + if (!compound.hasKey("Color")) + color = 0xe0e0e0; + if (!compound.hasKey("TitleColor")) + titleColor = 0xe0e0e0; availability.readFromNBT(compound); factionOptions.readFromNBT(compound); @@ -178,6 +195,8 @@ public class Dialog implements ICompatibilty, IDialog { factionOptions.writeToNBT(compound); compound.setInteger("ModRev", version); + compound.setInteger("Color", color); + compound.setInteger("TitleColor", titleColor); compound.setBoolean("RenderGradual", renderGradual); compound.setBoolean("PreviousBlocks", showPreviousBlocks); compound.setBoolean("ShowOptionLine", showOptionLine); @@ -193,6 +212,9 @@ public class Dialog implements ICompatibilty, IDialog { compound.setInteger("OptionOffsetY", optionOffsetY); compound.setInteger("OptionSpaceX", optionSpaceX); compound.setInteger("OptionSpaceY", optionSpaceY); + compound.setFloat("NPCScale", npcScale); + compound.setInteger("NPCOffsetX", npcOffsetX); + compound.setInteger("NPCOffsetY", npcOffsetY); NBTTagList images = new NBTTagList(); for (DialogImage dialogImage : dialogImages.values()) { @@ -225,6 +247,8 @@ public class Dialog implements ICompatibilty, IDialog { dialog.sound = sound; dialog.mail = mail; dialog.command = command; + dialog.color = color; + dialog.titleColor = titleColor; dialog.hideNPC = hideNPC; dialog.showWheel = showWheel; dialog.disableEsc = disableEsc; @@ -244,6 +268,9 @@ public class Dialog implements ICompatibilty, IDialog { dialog.optionOffsetY = optionOffsetY; dialog.optionSpaceX = optionSpaceX; dialog.optionSpaceY = optionSpaceY; + dialog.npcScale = npcScale; + dialog.npcOffsetX = npcOffsetX; + dialog.npcOffsetY = npcOffsetY; dialog.dialogImages = dialogImages; for(int slot : options.keySet()){ diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 20f0946c9..4875768c4 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -450,6 +450,9 @@ dialog.textPitch=Text Pitch dialog.textureOffset=Texture Offset dialog.selectedColor=Selected Color dialog.optionLine=Option Line +dialog.npcScale=NPC Scale +dialog.npcOffset=NPC Offset +dialog.titleColor=Title Color quest.quest=Quest quest.quests=Quests