Implemented dialog and text colors.

This commit is contained in:
Luis C.M committed 2022-06-10 01:38:01 -05:00
1 parent 4fe61a904f
commit ff8fc68e88
6 files changed
+132 -47

No files matched your search

@@ -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) {
@@ -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();
}
}
@@ -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;
@@ -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;
@@ -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<Integer, DialogImage> 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()){