Implemented title positions for dialogs.

This commit is contained in:
Luis C.M committed 2022-06-10 04:47:28 -05:00
1 parent ff8fc68e88
commit 486e37cd7f
5 files changed
+95 -69

No files matched your search

@@ -8,21 +8,25 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.TextBlock;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.entity.EntityNPCInterface;
public class TextBlockClient extends TextBlock{
private ChatStyle style;
public int color = 0xe0e0e0;
public int titleColor = 0xe0e0e0;
public int titlePos = 0;
private String name;
private ICommandSender sender;
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;
public TextBlockClient(ICommandSender sender, Dialog dialog, Object... obs) {
this(dialog.text, dialog.textWidth, false, obs);
this.color = dialog.color;
this.titleColor = dialog.titleColor;
this.titlePos = dialog.titlePos;
this.sender = sender;
}
public TextBlockClient(String name, String text, int lineWidth, int color, Object... obs) {
this(text, lineWidth, false, obs);
this.color = color;
@@ -1,9 +1,7 @@
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.client.gui.ScaledResolution;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.Client;
import noppes.npcs.client.NoppesUtil;
@@ -83,7 +81,7 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
while (color.length() < 6) {
color = 0 + color;
}
addButton(new GuiNpcButton(17, guiLeft + 180, y, 60, 20, color));
addButton(new GuiNpcButton(17, guiLeft + 157, y, 60, 20, color));
addLabel(new GuiNpcLabel(17, "dialog.titleColor", guiLeft + 100, y + 5));
getButton(17).setTextColor(dialog.titleColor);
@@ -98,62 +96,65 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
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)));
addButton(new GuiNpcButton(10, guiLeft + 70, y += 22, 50, 20, new String[]{"gui.text", "gui.option", "display.fixed"}, dialog.titlePos));
addLabel(new GuiNpcLabel(10, "dialog.titlePos", guiLeft + 4, y + 5));
addTextField(new GuiNpcTextField(11, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth)));
addTextField(new GuiNpcTextField(12, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight)));
addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5));
getTextField(10).integersOnly = true;
getTextField(10).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
getTextField(11).integersOnly = true;
getTextField(11).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
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));
getTextField(12).integersOnly = true;
getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
addTextField(new GuiNpcTextField(13, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX)));
addTextField(new GuiNpcTextField(14, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY)));
addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5));
getTextField(13).integersOnly = true;
getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
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));
getTextField(14).integersOnly = true;
getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX)));
addTextField(new GuiNpcTextField(16, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY)));
addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5));
getTextField(15).integersOnly = true;
getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
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));
getTextField(16).integersOnly = true;
getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
addTextField(new GuiNpcTextField(17, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX)));
addTextField(new GuiNpcTextField(18, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY)));
addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5));
getTextField(17).integersOnly = true;
getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
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));
getTextField(18).integersOnly = true;
getTextField(18).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
addTextField(new GuiNpcTextField(19, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX)));
addTextField(new GuiNpcTextField(20, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY)));
addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5));
getTextField(19).integersOnly = true;
getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
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);
addTextField(new GuiNpcTextField(21, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX)));
addTextField(new GuiNpcTextField(22, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY)));
addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5));
getTextField(21).integersOnly = true;
getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
getTextField(21).setVisible(!dialog.hideNPC);
getTextField(22).integersOnly = true;
getTextField(22).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0);
getTextField(22).setVisible(!dialog.hideNPC);
getLabel(25).enabled = !dialog.hideNPC;
addTextField(new GuiNpcTextField(22, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale)));
addTextField(new GuiNpcTextField(23, 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);
getTextField(23).floatsOnly = true;
getTextField(23).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
getTextField(23).setVisible(!dialog.hideNPC);
getLabel(26).enabled = !dialog.hideNPC;
} else if (activeMenu == 3) {
if (imageScroll == null) {
@@ -314,6 +315,12 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
}
}
if (activeMenu == 2) {
if (button.id == 10) {
dialog.titlePos = button.getValue();
}
}
if (activeMenu == 3) {
if (button.id == 1) {
int addId = 0;
@@ -428,48 +435,48 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
}
if (activeMenu == 2) {
if (textfield.id == 10) {
if (textfield.id == 11) {
dialog.textWidth = textfield.getInteger();
}
if (textfield.id == 11) {
if (textfield.id == 12) {
dialog.textHeight = textfield.getInteger();
}
if (textfield.id == 12) {
if (textfield.id == 13) {
dialog.textOffsetX = textfield.getInteger();
}
if (textfield.id == 13) {
if (textfield.id == 14) {
dialog.textOffsetY = textfield.getInteger();
}
if (textfield.id == 14) {
if (textfield.id == 15) {
dialog.titleOffsetX = textfield.getInteger();
}
if (textfield.id == 15) {
if (textfield.id == 16) {
dialog.titleOffsetY = textfield.getInteger();
}
if (textfield.id == 16) {
if (textfield.id == 17) {
dialog.optionOffsetX = textfield.getInteger();
}
if (textfield.id == 17) {
if (textfield.id == 18) {
dialog.optionOffsetY = textfield.getInteger();
}
if (textfield.id == 18) {
if (textfield.id == 19) {
dialog.optionSpaceX = textfield.getInteger();
}
if (textfield.id == 19) {
if (textfield.id == 20) {
dialog.optionSpaceY = textfield.getInteger();
}
if (textfield.id == 20) {
if (textfield.id == 21) {
dialog.npcOffsetX = textfield.getInteger();
}
if (textfield.id == 21) {
if (textfield.id == 22) {
dialog.npcOffsetY = textfield.getInteger();
}
if (textfield.id == 22) {
if (textfield.id == 23) {
dialog.npcScale = textfield.getFloat();
}
}
@@ -1,7 +1,6 @@
package noppes.npcs.client.gui.player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.client.Minecraft;
@@ -20,7 +19,6 @@ import noppes.npcs.client.ClientProxy;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.TextBlockClient;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.gui.util.GuiNPCInterface;
import noppes.npcs.client.gui.util.IGuiClose;
import noppes.npcs.constants.EnumOptionType;
@@ -212,7 +210,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.titleColor, count, false);
drawDialogString(block.getName() + " ", -4 - size, count, false, block);
for (int l = 0; l < block.lines.size(); l++) {
IChatComponent line = block.lines.get(l);
@@ -222,7 +220,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
if (drawText.matches("(.*)(\\{(\\d+)})(.*)")) {
if (textPauseTime > 0) {
drawText = drawText.substring(0, prevPausePos);
drawDialogString(drawText, 0, block.color, count, true);
drawDialogString(drawText, 0, count, true, block);
textPauseTime--;
break blockLoop;
}
@@ -243,7 +241,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
if (!strInt.isEmpty()) {
drawText = drawText.substring(0, prevPausePos);
drawDialogString(drawText, 0, block.color, count, true);
drawDialogString(drawText, 0, count, true, block);
instantBlockPos = b;
instantLinePos = l;
@@ -255,7 +253,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
}
}
drawDialogString(drawText, 0, block.color, count, true);
drawDialogString(drawText, 0, count, true, block);
count++;
}
count++;
@@ -265,10 +263,10 @@ 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.titleColor, count, false);
drawDialogString(block.getName() + " ", -4 - size, count, false, block);
for (IChatComponent line : block.lines) {
drawDialogString(line.getFormattedText(), 0, block.color, count, true);
drawDialogString(line.getFormattedText(), 0, count, true, block);
count++;
}
count++;
@@ -277,11 +275,11 @@ 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.titleColor, count, false);
drawDialogString(block.getName() + " ", -4 - size, count, false, block);
for (int pastLine = 0; pastLine < currentLine; pastLine++) {
IChatComponent line = block.lines.get(pastLine);
drawDialogString(line.getFormattedText(), 0, block.color, count, true);
drawDialogString(line.getFormattedText(), 0, count, true, block);
count++;
}
@@ -335,7 +333,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
gradualText = line.getFormattedText();
}
drawDialogString(gradualText, 0, block.color, count, true);
drawDialogString(gradualText, 0, count, true, block);
if (gradualText.length() == line.getFormattedText().length()) {
gradualText = "";
@@ -474,26 +472,39 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
}
}
private void drawDialogString(String text, int left, int color, int count, boolean mainDialogText){
private void drawDialogString(String text, int left, int count, boolean mainDialogText, TextBlockClient block){
int lineOffset = dialog.renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0;
int height = count - totalRows + lineOffset;
int screenPos = optionStart;
int y = (height * ClientProxy.Font.height()) + screenPos + scrollY;
if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) {
return;
if (block.titlePos == 0 || mainDialogText) {
if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) {
return;
}
}
int offsetX, offsetY;
int offsetX, offsetY, color;
if (mainDialogText) {
offsetX = dialog.textOffsetX;
offsetY = dialog.textOffsetY;
color = block.color;
} else {
offsetX = dialog.titleOffsetX;
offsetY = dialog.titleOffsetY;
color = block.titleColor;
if (block.titlePos == 1 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) {
y = screenPos - ClientProxy.Font.height() - 5;
}
}
text = text.replaceAll("\\{(\\d+)}","");
drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color);
if (!mainDialogText && block.titlePos == 2 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) {
drawString(fontRendererObj, text, offsetX, offsetY, color);
} else {
drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color);
}
}
public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){
@@ -531,8 +542,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
textSoundEnabled = !textSoundEnabled;
}
int firstBlockSize = lineBlocks.size() > 0 ? lineBlocks.get(0).lines.size() + 1 : 0;
if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - firstBlockSize) * ClientProxy.Font.height()) {//Page up
if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up
scrollY += ClientProxy.Font.height() * 2;
}
if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down
@@ -615,7 +625,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose
if (!dialog.showPreviousBlocks) {
lineBlocks.clear();
}
lineBlocks.add(new TextBlockClient(npc, dialog.text, dialog.textWidth, dialog.color, dialog.titleColor, player, npc));
lineBlocks.add(new TextBlockClient(npc, dialog, player, npc));
gradualText = "";
currentBlock = lineBlocks.size()-1;
currentLine = 0;
@@ -47,6 +47,7 @@ public class Dialog implements ICompatibilty, IDialog {
public int textWidth = 300;
public int textHeight = 400;
public int titlePos;
public int textOffsetX, textOffsetY;
public int titleOffsetX, titleOffsetY;
@@ -128,6 +129,7 @@ public class Dialog implements ICompatibilty, IDialog {
textHeight = compound.getInteger("TextHeight");
textOffsetX = compound.getInteger("TextOffsetX");
textOffsetY = compound.getInteger("TextOffsetY");
titlePos = compound.getInteger("TitlePos");
titleOffsetX = compound.getInteger("TitleOffsetX");
titleOffsetY = compound.getInteger("TitleOffsetY");
optionOffsetX = compound.getInteger("OptionOffsetX");
@@ -206,6 +208,7 @@ public class Dialog implements ICompatibilty, IDialog {
compound.setInteger("TextHeight", textHeight);
compound.setInteger("TextOffsetX", textOffsetX);
compound.setInteger("TextOffsetY", textOffsetY);
compound.setInteger("TitlePos", titlePos);
compound.setInteger("TitleOffsetX", titleOffsetX);
compound.setInteger("TitleOffsetY", titleOffsetY);
compound.setInteger("OptionOffsetX", optionOffsetX);
@@ -262,6 +265,7 @@ public class Dialog implements ICompatibilty, IDialog {
dialog.textHeight = textHeight;
dialog.textOffsetX = textOffsetX;
dialog.textOffsetY = textOffsetY;
dialog.titlePos = titlePos;
dialog.titleOffsetX = titleOffsetX;
dialog.titleOffsetY = titleOffsetY;
dialog.optionOffsetX = optionOffsetX;