From eb45a6a95999fe0887743e4ef0467efdbdfbf609 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 25 Jan 2022 14:44:24 -0600 Subject: [PATCH 01/15] Added several more dialog functions for the rest of the dialog options. --- .../java/noppes/npcs/controllers/Dialog.java | 35 +++++++++++++++++++ .../npcs/scripted/handler/data/IDialog.java | 15 ++++++++ 2 files changed, 50 insertions(+) diff --git a/src/main/java/noppes/npcs/controllers/Dialog.java b/src/main/java/noppes/npcs/controllers/Dialog.java index 8606491ce..8111230d0 100644 --- a/src/main/java/noppes/npcs/controllers/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/Dialog.java @@ -224,4 +224,39 @@ public class Dialog implements ICompatibilty, IDialog { public void setCommand(String command) { this.command = command; } + + public void setDarkenScreen(boolean darkenScreen) { + this.darkenScreen = darkenScreen; + } + public boolean getDarkenScreen() { + return this.darkenScreen; + } + + public void setDisableEsc(boolean disableEsc) { + this.disableEsc = disableEsc; + } + public boolean getDisableEsc() { + return this.disableEsc; + } + + public void setShowWheel(boolean showWheel) { + this.showWheel = showWheel; + } + public boolean getShowWheel() { + return this.showWheel; + } + + public void setHideNPC(boolean hideNPC) { + this.hideNPC = hideNPC; + } + public boolean getHideNPC() { + return this.hideNPC; + } + + public void setSound(String sound) { + this.sound = sound; + } + public String getSound() { + return this.sound; + } } diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java b/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java index 7ad032f33..e45e978aa 100644 --- a/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java +++ b/src/main/java/noppes/npcs/scripted/handler/data/IDialog.java @@ -34,5 +34,20 @@ public interface IDialog { IDialogCategory getCategory(); + void setDarkenScreen(boolean darkenScreen); + boolean getDarkenScreen(); + + void setDisableEsc(boolean disableEsc); + boolean getDisableEsc(); + + void setShowWheel(boolean showWheel); + boolean getShowWheel(); + + void setHideNPC(boolean hideNPC); + boolean getHideNPC(); + + void setSound(String sound); + String getSound(); + void save(); } From f14337f1bbf398720a9e5b58fa02df8753c61b95 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 25 Jan 2022 14:54:15 -0600 Subject: [PATCH 02/15] Added config for NPC sizes, default 100. --- src/main/java/noppes/npcs/CustomNpcs.java | 6 ++++++ src/main/java/noppes/npcs/DataDisplay.java | 3 +++ .../java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java | 3 ++- src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java | 4 ++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index e6fb99756..48cd4942a 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -72,6 +72,9 @@ public class CustomNpcs { @ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.") public static int NpcNavRange = 32; + @ConfigProp(info = "Size limit for NPCs. Default 100, larger sizes may cause lag on clients and servers that can't take it!") + public static int NpcSizeLimit = 100; + @ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc") public static boolean NpcUseOpCommands = false; @@ -171,6 +174,9 @@ public class CustomNpcs { NpcNavRange = 96; } + if(NpcSizeLimit < 1) + NpcSizeLimit = 1; + EnchantInterface.load(); CustomItems.load(); diff --git a/src/main/java/noppes/npcs/DataDisplay.java b/src/main/java/noppes/npcs/DataDisplay.java index 0fceb1a52..32781013b 100644 --- a/src/main/java/noppes/npcs/DataDisplay.java +++ b/src/main/java/noppes/npcs/DataDisplay.java @@ -133,6 +133,9 @@ public class DataDisplay { glowTexture = nbttagcompound.getString("GlowTexture"); modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE); + if(modelSize > CustomNpcs.NpcSizeLimit) + modelSize = CustomNpcs.NpcSizeLimit; + modelType = nbttagcompound.getInteger("modelType"); showName = nbttagcompound.getInteger("ShowName"); diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 4794d6593..ca2055e63 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.CustomNpcs; import noppes.npcs.DataDisplay; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; @@ -56,7 +57,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene addLabel(new GuiNpcLabel(2,"display.size", guiLeft + 175, y + 5)); addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 203, y, 40, 20, display.modelSize + "")); getTextField(2).integersOnly = true; - getTextField(2).setMinMaxDefault(1, Integer.MAX_VALUE, 5); + getTextField(2).setMinMaxDefault(1, CustomNpcs.NpcSizeLimit, 5); //addLabel(new GuiNpcLabel(3,"(1-30)", guiLeft + 246 , y + 5)); y+=23; diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index 7145c6bb7..ffa0bbe8c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -1,6 +1,7 @@ package noppes.npcs.scripted.entity; import net.minecraft.item.ItemStack; +import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.*; import noppes.npcs.controllers.Line; @@ -53,6 +54,9 @@ public class ScriptNpc extends ScriptLiving imp public void setSize(int size){ if(size < 1) size = 1; + if(size > CustomNpcs.NpcSizeLimit) + size = CustomNpcs.NpcSizeLimit; + npc.display.modelSize = size; npc.script.clientNeedsUpdate = true; } From 989effb5c55d1c9219d14eb26e5c8145f028733b Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 27 Jan 2022 03:50:36 -0600 Subject: [PATCH 03/15] Added more a full inventory to NPCs, selectable on two tabs and double-point values for NPC droprates. --- src/main/java/noppes/npcs/DataInventory.java | 19 +++- src/main/java/noppes/npcs/NBTTags.java | 24 ++++ .../npcs/client/gui/mainmenu/GuiNPCInv.java | 104 ++++++++++++------ .../npcs/containers/ContainerNPCInv.java | 7 +- .../npcs/scripted/entity/ScriptNpc.java | 6 +- .../npcs/scripted/interfaces/ICustomNpc.java | 4 +- 6 files changed, 116 insertions(+), 48 deletions(-) diff --git a/src/main/java/noppes/npcs/DataInventory.java b/src/main/java/noppes/npcs/DataInventory.java index 4f96b2f01..57f57563d 100644 --- a/src/main/java/noppes/npcs/DataInventory.java +++ b/src/main/java/noppes/npcs/DataInventory.java @@ -18,7 +18,7 @@ import noppes.npcs.entity.EntityNPCInterface; public class DataInventory implements IInventory{ public HashMap items = new HashMap(); - public HashMap dropchance = new HashMap(); + public HashMap dropchance = new HashMap(); public HashMap weapons = new HashMap(); public HashMap armor = new HashMap(); @@ -38,7 +38,7 @@ public class DataInventory implements IInventory{ nbttagcompound.setTag("NpcInv", NBTTags.nbtItemStackList(items)); nbttagcompound.setTag("Armor", NBTTags.nbtItemStackList(getArmor())); nbttagcompound.setTag("Weapons", NBTTags.nbtItemStackList(getWeapons())); - nbttagcompound.setTag("DropChance", NBTTags.nbtIntegerIntegerMap(dropchance)); + nbttagcompound.setTag("DoubleDropChance", NBTTags.nbtIntegerDoubleMap(dropchance)); nbttagcompound.setInteger("LootMode", lootMode); return nbttagcompound; @@ -49,7 +49,16 @@ public class DataInventory implements IInventory{ items = NBTTags.getItemStackList(nbttagcompound.getTagList("NpcInv", 10)); setArmor(NBTTags.getItemStackList(nbttagcompound.getTagList("Armor", 10))); setWeapons(NBTTags.getItemStackList(nbttagcompound.getTagList("Weapons", 10))); - dropchance = NBTTags.getIntegerIntegerMap(nbttagcompound.getTagList("DropChance", 10)); + + if(!nbttagcompound.hasKey("DoubleDropChance")) { + dropchance.clear(); + HashMap oldDropChance = NBTTags.getIntegerIntegerMap(nbttagcompound.getTagList("DropChance", 10)); + for(int i = 0; i < oldDropChance.entrySet().size(); i++){ + dropchance.put(i, Double.valueOf(oldDropChance.get(i))); + } + } + dropchance = NBTTags.getIntegerDoubleMap(nbttagcompound.getTagList("DoubleDropChance", 10)); + lootMode = nbttagcompound.getInteger("LootMode"); } public HashMap getWeapons() { @@ -89,10 +98,10 @@ public class DataInventory implements IInventory{ ItemStack item = items.get(i); if(item == null) continue; - int dchance = 100; + double dchance = 100; if(dropchance.containsKey(i)) dchance = dropchance.get(i); - int chance = npc.worldObj.rand.nextInt(100) + dchance; + double chance = Math.random()*100 + dchance; if(chance >= 100){ EntityItem e = getEntityItem(item.copy()); if(e != null) diff --git a/src/main/java/noppes/npcs/NBTTags.java b/src/main/java/noppes/npcs/NBTTags.java index 8323fe5df..85b7eb08b 100644 --- a/src/main/java/noppes/npcs/NBTTags.java +++ b/src/main/java/noppes/npcs/NBTTags.java @@ -69,6 +69,17 @@ public class NBTTags { } return list; } + + public static HashMap getIntegerDoubleMap( + NBTTagList tagList) { + HashMap list = new HashMap(); + for(int i = 0; i < tagList.tagCount(); i++) + { + NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i); + list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getDouble("Double")); + } + return list; + } public static HashMap getIntegerLongMap( NBTTagList tagList) { @@ -239,6 +250,19 @@ public class NBTTags { return nbttaglist; } + public static NBTTagList nbtIntegerDoubleMap(HashMap lines) { + NBTTagList nbttaglist = new NBTTagList(); + if(lines == null) + return nbttaglist; + for (int slot : lines.keySet()) { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + nbttagcompound.setInteger("Slot", slot); + nbttagcompound.setDouble("Double", lines.get(slot)); + nbttaglist.appendTag(nbttagcompound); + } + return nbttaglist; + } + public static NBTTagList nbtIntegerLongMap(HashMap lines) { NBTTagList nbttaglist = new NBTTagList(); if(lines == null) diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java index 17ab799b6..690adbdd8 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCInv.java @@ -6,29 +6,30 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; -import noppes.npcs.client.gui.util.GuiContainerNPCInterface2; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcLabel; -import noppes.npcs.client.gui.util.GuiNpcSlider; -import noppes.npcs.client.gui.util.GuiNpcTextField; -import noppes.npcs.client.gui.util.IGuiData; -import noppes.npcs.client.gui.util.ISliderListener; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.containers.ContainerNPCInv; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.opengl.GL11; -public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListener, IGuiData +public class GuiNPCInv extends GuiContainerNPCInterface2 implements IGuiData, ITextfieldListener { - private HashMap chances = new HashMap(); + private HashMap chances = new HashMap(); private ContainerNPCInv container; private ResourceLocation slot; + private int inventoryTab = 0; + public GuiNPCInv(EntityNPCInterface npc,ContainerNPCInv container) { super(npc,container,3); @@ -56,25 +57,58 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe addLabel(new GuiNpcLabel(2,"inv.npcInventory", guiLeft + 191, guiTop + 5)); addLabel(new GuiNpcLabel(3,"inv.inventory", guiLeft + 8, guiTop + 101)); - - for(int i = 0; i < 9; i++){ - int chance = 100; - if(npc.inventory.dropchance.containsKey(i)){ - chance = npc.inventory.dropchance.get(i); - } - if(chance <= 0 || chance > 100) - chance = 100; - chances.put(i, chance); - GuiNpcSlider slider = new GuiNpcSlider(this, i, guiLeft + 211, guiTop + 14 + i * 21, ((float)chance)/100); - addSlider(slider); + + addLabel(new GuiNpcLabel(4,"Tab", guiLeft + 381, guiTop + 5)); + addButton(new GuiNpcButton(11, guiLeft + 375, guiTop + 13, 30, 20, "1")); + addButton(new GuiNpcButton(12, guiLeft + 375, guiTop + 34, 30, 20, "2")); + + for(int c = 0; c < 4; c++) { + for (int r = 0; r < 9; r++) { + double chance = 100; + if (npc.inventory.dropchance.containsKey(r + c*9)) { + chance = npc.inventory.dropchance.get(r + c*9); + } + if (chance <= 0 || chance > 100) + chance = 100; + chances.put(r + c*9, chance); + + if(Math.floor((float)c/2) != this.inventoryTab) { + container.getSlot(r + c*9 + 7).xDisplayPosition = 10000; + container.getSlot(r + c*9 + 7).yDisplayPosition = 10000; + continue; + } else { + container.getSlot(r + c*9 + 7).xDisplayPosition = 191 + (c-this.inventoryTab*2) * 90; + container.getSlot(r + c*9 + 7).yDisplayPosition = 16 + r * 21; + } + + GuiNpcTextField textField = new GuiNpcTextField(2 + r + c*9, this, fontRendererObj, guiLeft + 210 + (c-this.inventoryTab*2)*90, guiTop + 14 + r * 21, 60, 18, chance + ""); + addLabel(new GuiNpcLabel(c*9 + r + 5,"%", guiLeft + 272 + (c-this.inventoryTab*2)*90, guiTop + 16 + r * 21)); + textField.doublesOnly = true; + textField.setMinMaxDefaultDouble(0, 100, 100); + addTextField(textField); + } } } + private void drawSlot(int x, int y) + { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); // Forge: Blending needs to be enabled for this. + this.mc.getTextureManager().bindTexture(slot); + this.drawTexturedModalRect(x, y, 0,0,18, 18); + GL11.glDisable(GL11.GL_BLEND); // Forge: And clean that up + GL11.glEnable(GL11.GL_LIGHTING); + } + @Override protected void actionPerformed(GuiButton guibutton) { if(guibutton.id == 10){ npc.inventory.lootMode = ((GuiNpcButton)guibutton).getValue(); } + if(guibutton.id == 11 || guibutton.id == 12){ + this.inventoryTab = Integer.parseInt(guibutton.displayString)-1; + initGui(); + } } protected void drawGuiContainerBackgroundLayer(float f, int i, int j) @@ -82,12 +116,18 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe super.drawGuiContainerBackgroundLayer(f, i, j); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(slot); - + for(int id = 4; id <= 6;id++){ Slot slot = container.getSlot(id); if(slot.getHasStack()) drawTexturedModalRect(guiLeft + slot.xDisplayPosition - 1, guiTop + slot.yDisplayPosition -1, 0, 0, 18, 18); } + + for(int c = 0; c < 2; c++) { + for (int r = 0; r < 9; r++) { + this.drawSlot(guiLeft + 190 + c*90, guiTop + 15 + r * 21); + } + } } public void drawScreen(int i, int j, float f) { @@ -149,18 +189,12 @@ public class GuiNPCInv extends GuiContainerNPCInterface2 implements ISliderListe npc.inventory.readEntityFromNBT(compound); initGui(); } - - @Override - public void mouseDragged(GuiNpcSlider guiNpcSlider) { - guiNpcSlider.displayString = StatCollector.translateToLocal("inv.dropChance") + ": " + (int) (guiNpcSlider.sliderValue * 100) + "%"; - } - - @Override - public void mousePressed(GuiNpcSlider guiNpcSlider) { - } - - @Override - public void mouseReleased(GuiNpcSlider guiNpcSlider) { - chances.put(guiNpcSlider.id, (int) (guiNpcSlider.sliderValue * 100)); - } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if(textfield.id >= 2){ + chances.put(textfield.id-2, Double.parseDouble(textfield.getText())); + this.save(); + } + } } diff --git a/src/main/java/noppes/npcs/containers/ContainerNPCInv.java b/src/main/java/noppes/npcs/containers/ContainerNPCInv.java index 8b51da54e..00186b177 100644 --- a/src/main/java/noppes/npcs/containers/ContainerNPCInv.java +++ b/src/main/java/noppes/npcs/containers/ContainerNPCInv.java @@ -16,15 +16,16 @@ public class ContainerNPCInv extends Container{ addSlotToContainer(new Slot(npc.inventory, 5, 81, 40)); addSlotToContainer(new Slot(npc.inventory, 6, 81, 58)); - for(int l = 0; l < 9; l++){ - addSlotToContainer(new Slot(npc.inventory, l + 7 , 191 , 16 + l * 21)); + for(int c = 0; c < 4; c++) { + for (int r = 0; r < 9; r++) { + addSlotToContainer(new Slot(npc.inventory, c*9 + r + 7, 191 + (c%2)*90, 16 + r * 21)); + } } for(int i1 = 0; i1 < 3; i1++){ for(int l1 = 0; l1 < 9; l1++){ addSlotToContainer(new Slot(player.inventory, l1 + i1 * 9 + 9, l1 * 18 + 8, 113 + i1 * 18)); } - } for(int j1 = 0; j1 < 9; j1++){ diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java index ffa0bbe8c..6e5bef216 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptNpc.java @@ -532,7 +532,7 @@ public class ScriptNpc extends ScriptLiving imp * @param slot The slot from the NPC's drop list to return (0-8) * @return The chance of dropping the item in this slot. Returns 100 if the slot is not found. */ - public int getLootChance(int slot) { + public double getLootChance(int slot) { if(!npc.inventory.dropchance.containsKey(slot)) return 100; @@ -544,8 +544,8 @@ public class ScriptNpc extends ScriptLiving imp * @param slot The slot from the NPC's drop list to change * @param chance The new chance of dropping the item in this slot */ - public void setLootChance(int slot, int chance) { - if(slot < 0 || slot > 8) + public void setLootChance(int slot, double chance) { + if(!npc.inventory.dropchance.containsKey(slot)) return; if(chance < 0) diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java index 27bf7121c..47f0fa7ab 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomNpc.java @@ -299,14 +299,14 @@ public interface ICustomNpc extends IEntityLiving { * @param slot The slot from the NPC's drop list to return (0-8) * @return The chance of dropping the item in this slot. Returns 100 if the slot is not found. */ - public int getLootChance(int slot); + public double getLootChance(int slot); /** * * @param slot The slot from the NPC's drop list to change * @param chance The new chance of dropping the item in this slot */ - public void setLootChance(int slot, int chance); + public void setLootChance(int slot, double chance); /** * From f876f13d77367dca63043d888d3075316d7ec931 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 27 Jan 2022 05:40:51 -0600 Subject: [PATCH 04/15] Added 9 more slots for quest kill objectives, and an option for kill quests to progress only if a player kills an NPC with that name. Added quest interface support to get and modify data from specific quest types. --- .../java/noppes/npcs/ServerEventsHandler.java | 4 +- .../gui/questtypes/GuiNpcQuestTypeKill.java | 49 ++++++++++++------- .../npcs/client/gui/util/GuiNPCInterface.java | 17 ++++--- .../java/noppes/npcs/controllers/Quest.java | 5 ++ .../java/noppes/npcs/quests/QuestDialog.java | 3 +- .../noppes/npcs/quests/QuestInterface.java | 3 +- .../java/noppes/npcs/quests/QuestItem.java | 24 ++++++++- .../java/noppes/npcs/quests/QuestKill.java | 18 ++++++- .../noppes/npcs/quests/QuestLocation.java | 24 ++++++++- .../npcs/scripted/handler/data/IQuest.java | 2 + .../scripted/handler/data/IQuestDialog.java | 4 ++ .../handler/data/IQuestInterface.java | 4 ++ .../scripted/handler/data/IQuestItem.java | 12 +++++ .../scripted/handler/data/IQuestKill.java | 6 +++ .../scripted/handler/data/IQuestLocation.java | 12 +++++ 15 files changed, 155 insertions(+), 32 deletions(-) create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestDialog.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestInterface.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestItem.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestKill.java create mode 100644 src/main/java/noppes/npcs/scripted/handler/data/IQuestLocation.java diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index a5e620ce6..705dc2e75 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -21,7 +21,6 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import net.minecraft.village.MerchantRecipeList; -import net.minecraftforge.event.CommandEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; @@ -43,7 +42,6 @@ import noppes.npcs.items.ItemShield; import noppes.npcs.items.ItemSoulstoneEmpty; import noppes.npcs.quests.QuestKill; import noppes.npcs.roles.RoleFollower; -import noppes.npcs.scripted.event.ForgeEvent; public class ServerEventsHandler { @@ -309,6 +307,8 @@ public class ServerEventsHandler { } String name = entityName; QuestKill quest = (QuestKill) data.quest.questInterface; + if(quest.targetType == 1 && !(entity instanceof EntityNPCInterface)) + continue; if(quest.targets.containsKey(entity.getCommandSenderName())) name = entity.getCommandSenderName(); else if(!quest.targets.containsKey(name)) diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java index a753c28bc..40a5cc9ae 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java @@ -37,29 +37,35 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi quest = (QuestKill) q.questInterface; - setBackground("menubg.png"); - xSize = 356; - ySize = 216; + setBackground("largebg.png"); + bgScale = 1.7F; + bgScaleX = 1.1F; + + xSize = 300; + ySize = 300; closeOnEsc = true; } public void initGui() { super.initGui(); + + guiTop -= 20; + int i = 0; - addLabel(new GuiNpcLabel(0, "You can fill in npc or player names too", guiLeft + 4, guiTop + 50)); + addLabel(new GuiNpcLabel(0, "You can fill in npc or player names too", guiLeft + 4, guiTop + 20)); for (String name : quest.targets.keySet()) { - this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 70 + i * 22, 180, 20, name)); - this.addTextField(new GuiNpcTextField(i + 3, this, fontRendererObj, guiLeft + 186, guiTop + 70 + i * 22, 24, 20, quest.targets.get(name) + "")); - this.getTextField(i+3).integersOnly = true; - this.getTextField(i+3).setMinMaxDefault(1, Integer.MAX_VALUE, 1); + this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 40 + i * 22, 180, 20, name)); + this.addTextField(new GuiNpcTextField(i + 12, this, fontRendererObj, guiLeft + 186, guiTop + 40 + i * 22, 24, 20, quest.targets.get(name) + "")); + this.getTextField(i+12).integersOnly = true; + this.getTextField(i+12).setMinMaxDefault(1, Integer.MAX_VALUE, 1); i++; } - for(;i < 3; i++){ - this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 70 + i * 22, 180, 20, "")); - this.addTextField(new GuiNpcTextField(i + 3, this, fontRendererObj, guiLeft + 186, guiTop + 70 + i * 22, 24, 20, "1")); - this.getTextField(i+3).integersOnly = true; - this.getTextField(i+3).setMinMaxDefault(1, Integer.MAX_VALUE, 1); + for(;i < 12; i++){ + this.addTextField(new GuiNpcTextField(i, this, fontRendererObj, guiLeft + 4, guiTop + 40 + i * 22, 180, 20, "")); + this.addTextField(new GuiNpcTextField(i + 12, this, fontRendererObj, guiLeft + 186, guiTop + 40 + i * 22, 24, 20, "1")); + this.getTextField(i+12).integersOnly = true; + this.getTextField(i+12).setMinMaxDefault(1, Integer.MAX_VALUE, 1); } Map data = EntityList.stringToClassMapping; ArrayList list = new ArrayList(); @@ -78,9 +84,13 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi scroll.setList(list); scroll.setSize(130, 198); scroll.guiLeft = guiLeft + 220; - scroll.guiTop = guiTop + 14; + scroll.guiTop = guiTop + 40; addScroll(scroll); - this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 140, 98, 20, "gui.back")); + + guiTop += 50; + this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 300, 98, 20, "gui.back")); + this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + 260, 98, 20, new String[]{"Any", "NPCs"}, quest.targetType)); + guiTop -= 50; scroll.visible = GuiNpcTextField.isFieldActive(); } @@ -90,6 +100,9 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi if (guibutton.id == 0) { close(); } + if (guibutton.id == 1) { + quest.targetType = guibutton.displayString.equals("NPCs") ? 1 : 0; + } } public void mouseClicked(int i, int j, int k) { @@ -101,18 +114,18 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi @Override public void unFocused(GuiNpcTextField guiNpcTextField) { - if(guiNpcTextField.id < 3) + if(guiNpcTextField.id < 12) lastSelected = guiNpcTextField; saveTargets(); } private void saveTargets(){ HashMap map = new HashMap(); - for(int i = 0; i< 3; i++){ + for(int i = 0; i< 12; i++){ String name = getTextField(i).getText(); if(name.isEmpty()) continue; - map.put(name, getTextField(i+3).getInteger()); + map.put(name, getTextField(i+12).getInteger()); } quest.targets = map; } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index cb6e52ce0..1e896158f 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -45,7 +45,10 @@ public abstract class GuiNPCInterface extends GuiScreen public int mouseX, mouseY; public float bgScale = 1; - + public float bgScaleX = 1; + public float bgScaleY = 1; + public float bgScaleZ = 1; + public GuiNPCInterface(EntityNPCInterface npc) { this.player = Minecraft.getMinecraft().thePlayer; @@ -102,7 +105,7 @@ public abstract class GuiNPCInterface extends GuiScreen gui.setWorldAndResolution(mc, 350, 250); extra.put(gui.id, gui); } - + public void mouseClicked(int i, int j, int k) { if(AWTWindow != null) @@ -202,11 +205,11 @@ public abstract class GuiNPCInterface extends GuiScreen scrolls.put(scroll.id, scroll); } public GuiCustomScroll getScroll(int id){ - return scrolls.get(id); + return scrolls.get(id); } - + public abstract void save(); - + @Override public void drawScreen(int i, int j, float f){ if(AWTWindow != null){ @@ -223,12 +226,12 @@ public abstract class GuiNPCInterface extends GuiScreen mouseY = j; if(drawDefaultBackground && subgui == null) drawDefaultBackground(); - + if(background != null && mc.renderEngine != null){ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPushMatrix(); GL11.glTranslatef(guiLeft, guiTop, 0); - GL11.glScalef(bgScale, bgScale, bgScale); + GL11.glScalef(bgScale*bgScaleX, bgScale*bgScaleY, bgScale*bgScaleZ); mc.renderEngine.bindTexture(background); if(xSize > 256){ drawTexturedModalRect(0, 0, 0, 0, 250, ySize); diff --git a/src/main/java/noppes/npcs/controllers/Quest.java b/src/main/java/noppes/npcs/controllers/Quest.java index a290314c9..3205d3073 100644 --- a/src/main/java/noppes/npcs/controllers/Quest.java +++ b/src/main/java/noppes/npcs/controllers/Quest.java @@ -20,6 +20,7 @@ import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.handler.data.IQuest; import noppes.npcs.scripted.handler.data.IQuestCategory; +import noppes.npcs.scripted.handler.data.IQuestInterface; import noppes.npcs.scripted.handler.data.IQuestObjective; import noppes.npcs.scripted.interfaces.IContainer; import noppes.npcs.scripted.interfaces.IPlayer; @@ -242,4 +243,8 @@ public class Quest implements ICompatibilty, IQuest { public IContainer getRewards() { return NpcAPI.Instance().getIContainer(this.rewardItems); } + + public IQuestInterface getQuestInterface(){ + return this.questInterface; + } } diff --git a/src/main/java/noppes/npcs/quests/QuestDialog.java b/src/main/java/noppes/npcs/quests/QuestDialog.java index b23f91742..6dd84633b 100644 --- a/src/main/java/noppes/npcs/quests/QuestDialog.java +++ b/src/main/java/noppes/npcs/quests/QuestDialog.java @@ -14,9 +14,10 @@ import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.PlayerData; import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.handler.data.IQuestDialog; import noppes.npcs.scripted.handler.data.IQuestObjective; -public class QuestDialog extends QuestInterface{ +public class QuestDialog extends QuestInterface implements IQuestDialog { public HashMap dialogs = new HashMap(); diff --git a/src/main/java/noppes/npcs/quests/QuestInterface.java b/src/main/java/noppes/npcs/quests/QuestInterface.java index a2b192100..dd1ef4fa7 100644 --- a/src/main/java/noppes/npcs/quests/QuestInterface.java +++ b/src/main/java/noppes/npcs/quests/QuestInterface.java @@ -4,9 +4,10 @@ import java.util.Vector; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.handler.data.IQuestInterface; import noppes.npcs.scripted.handler.data.IQuestObjective; -public abstract class QuestInterface { +public abstract class QuestInterface implements IQuestInterface { public int questId; public abstract void writeEntityToNBT(NBTTagCompound compound); public abstract void readEntityFromNBT(NBTTagCompound compound); diff --git a/src/main/java/noppes/npcs/quests/QuestItem.java b/src/main/java/noppes/npcs/quests/QuestItem.java index c37e3cd88..fb3221a21 100644 --- a/src/main/java/noppes/npcs/quests/QuestItem.java +++ b/src/main/java/noppes/npcs/quests/QuestItem.java @@ -9,10 +9,11 @@ import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.NoppesUtilServer; import noppes.npcs.NpcMiscInventory; import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.handler.data.IQuestItem; import noppes.npcs.scripted.handler.data.IQuestObjective; import noppes.npcs.util.ValueUtil; -public class QuestItem extends QuestInterface{ +public class QuestItem extends QuestInterface implements IQuestItem { public NpcMiscInventory items = new NpcMiscInventory(3); public boolean leaveItems = false; public boolean ignoreDamage = false; @@ -137,6 +138,27 @@ public class QuestItem extends QuestInterface{ return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]); } + public void setLeaveItems(boolean leaveItems){ + this.leaveItems = leaveItems; + } + public boolean getLeaveItems(){ + return this.leaveItems; + } + + public void setIgnoreDamage(boolean ignoreDamage){ + this.ignoreDamage = ignoreDamage; + } + public boolean getIgnoreDamage(){ + return this.ignoreDamage; + } + + public void setIgnoreNbt(boolean ignoreNbt){ + this.ignoreNBT = ignoreNbt; + } + public boolean getIgnoreNbt(){ + return this.ignoreNBT; + } + class QuestItemObjective implements IQuestObjective { private final QuestItem parent; private final EntityPlayer player; diff --git a/src/main/java/noppes/npcs/quests/QuestKill.java b/src/main/java/noppes/npcs/quests/QuestKill.java index 89536bf2a..0f84bd422 100644 --- a/src/main/java/noppes/npcs/quests/QuestKill.java +++ b/src/main/java/noppes/npcs/quests/QuestKill.java @@ -14,19 +14,23 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.QuestData; import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.handler.data.IQuestKill; import noppes.npcs.scripted.handler.data.IQuestObjective; -public class QuestKill extends QuestInterface{ +public class QuestKill extends QuestInterface implements IQuestKill { public HashMap targets = new HashMap(); + public int targetType = 0; @Override public void readEntityFromNBT(NBTTagCompound compound) { targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10)); + targetType = compound.getInteger("TargetType"); } @Override public void writeEntityToNBT(NBTTagCompound compound) { compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets)); + compound.setInteger("TargetType",targetType); } @Override @@ -90,6 +94,18 @@ public class QuestKill extends QuestInterface{ return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]); } + public void setTargetType(int type) { + if(type < 0) + type = 0; + if(type > 1) + type = 1; + + this.targetType = type; + } + public int getTargetType() { + return this.targetType; + } + class QuestKillObjective implements IQuestObjective { private final QuestKill parent; private final EntityPlayer player; diff --git a/src/main/java/noppes/npcs/quests/QuestLocation.java b/src/main/java/noppes/npcs/quests/QuestLocation.java index 17f1ce4a2..edefd2887 100644 --- a/src/main/java/noppes/npcs/quests/QuestLocation.java +++ b/src/main/java/noppes/npcs/quests/QuestLocation.java @@ -13,9 +13,10 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.PlayerQuestData; import noppes.npcs.controllers.QuestData; import noppes.npcs.scripted.CustomNPCsException; +import noppes.npcs.scripted.handler.data.IQuestLocation; import noppes.npcs.scripted.handler.data.IQuestObjective; -public class QuestLocation extends QuestInterface{ +public class QuestLocation extends QuestInterface implements IQuestLocation { public String location = ""; public String location2 = ""; public String location3 = ""; @@ -118,6 +119,27 @@ public class QuestLocation extends QuestInterface{ return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]); } + public void setLocation1(String loc1){ + this.location = loc1; + } + public String getLocation1(){ + return location; + } + + public void setLocation2(String loc2){ + this.location2 = loc2; + } + public String getLocation2(){ + return location2; + } + + public void setLocation3(String loc3){ + this.location3 = loc3; + } + public String getLocation3(){ + return location3; + } + class QuestLocationObjective implements IQuestObjective { private final QuestLocation parent; private final EntityPlayer player; diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java index f16b7674f..bfd640ec1 100644 --- a/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuest.java @@ -44,4 +44,6 @@ public interface IQuest { void save(); boolean getIsRepeatable(); + + IQuestInterface getQuestInterface(); } diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestDialog.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestDialog.java new file mode 100644 index 000000000..1e285efc0 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestDialog.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.handler.data; + +public interface IQuestDialog extends IQuestInterface { +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestInterface.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestInterface.java new file mode 100644 index 000000000..5edc4f1e0 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestInterface.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.handler.data; + +public interface IQuestInterface { +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestItem.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestItem.java new file mode 100644 index 000000000..7adca2254 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestItem.java @@ -0,0 +1,12 @@ +package noppes.npcs.scripted.handler.data; + +public interface IQuestItem extends IQuestInterface { + void setLeaveItems(boolean leaveItems); + boolean getLeaveItems(); + + void setIgnoreDamage(boolean ignoreDamage); + boolean getIgnoreDamage(); + + void setIgnoreNbt(boolean ignoreNbt); + boolean getIgnoreNbt(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestKill.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestKill.java new file mode 100644 index 000000000..7193f1aa8 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestKill.java @@ -0,0 +1,6 @@ +package noppes.npcs.scripted.handler.data; + +public interface IQuestKill extends IQuestInterface { + void setTargetType(int type); + int getTargetType(); +} diff --git a/src/main/java/noppes/npcs/scripted/handler/data/IQuestLocation.java b/src/main/java/noppes/npcs/scripted/handler/data/IQuestLocation.java new file mode 100644 index 000000000..7496b81ba --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/handler/data/IQuestLocation.java @@ -0,0 +1,12 @@ +package noppes.npcs.scripted.handler.data; + +public interface IQuestLocation extends IQuestInterface { + void setLocation1(String loc1); + String getLocation1(); + + void setLocation2(String loc2); + String getLocation2(); + + void setLocation3(String loc3); + String getLocation3(); +} From fcaafe4b269b00f22a848dd5dfe76f4d46c56e25 Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 27 Jan 2022 06:14:03 -0600 Subject: [PATCH 05/15] Fixed NBT issue with the new quest kill amounts. --- src/main/java/noppes/npcs/DataInventory.java | 3 ++- .../java/noppes/npcs/quests/QuestKill.java | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/noppes/npcs/DataInventory.java b/src/main/java/noppes/npcs/DataInventory.java index 57f57563d..601cf1791 100644 --- a/src/main/java/noppes/npcs/DataInventory.java +++ b/src/main/java/noppes/npcs/DataInventory.java @@ -56,8 +56,9 @@ public class DataInventory implements IInventory{ for(int i = 0; i < oldDropChance.entrySet().size(); i++){ dropchance.put(i, Double.valueOf(oldDropChance.get(i))); } + } else { + dropchance = NBTTags.getIntegerDoubleMap(nbttagcompound.getTagList("DoubleDropChance", 10)); } - dropchance = NBTTags.getIntegerDoubleMap(nbttagcompound.getTagList("DoubleDropChance", 10)); lootMode = nbttagcompound.getInteger("LootMode"); } diff --git a/src/main/java/noppes/npcs/quests/QuestKill.java b/src/main/java/noppes/npcs/quests/QuestKill.java index 0f84bd422..ed716b300 100644 --- a/src/main/java/noppes/npcs/quests/QuestKill.java +++ b/src/main/java/noppes/npcs/quests/QuestKill.java @@ -22,15 +22,24 @@ public class QuestKill extends QuestInterface implements IQuestKill { public int targetType = 0; @Override - public void readEntityFromNBT(NBTTagCompound compound) { - targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10)); - targetType = compound.getInteger("TargetType"); + public void writeEntityToNBT(NBTTagCompound compound) { + compound.setTag("QuestKills", NBTTags.nbtStringIntegerMap(targets)); + //compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets)); + compound.setInteger("TargetType",targetType); } @Override - public void writeEntityToNBT(NBTTagCompound compound) { - compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets)); - compound.setInteger("TargetType",targetType); + public void readEntityFromNBT(NBTTagCompound compound) { + if(!compound.hasKey("QuestKills")) { + targets.clear(); + HashMap oldTargets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10)); + targets.putAll(oldTargets); + } else { + targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestKills", 10)); + } + + //targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10)); + targetType = compound.getInteger("TargetType"); } @Override From 8b24dad2111801444968fc75f52cec0487581fcf Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 28 Jan 2022 03:21:00 -0600 Subject: [PATCH 06/15] Added Custom GUI Lines, with configurable thickness & color. Draws a line between one point defined by (x1,y1), and another defined by (x2,y2) --- .../npcs/client/gui/custom/GuiCustom.java | 5 + .../gui/custom/components/CustomGuiLine.java | 64 +++++++++++ .../noppes/npcs/scripted/gui/ScriptGui.java | 23 ++-- .../npcs/scripted/gui/ScriptGuiComponent.java | 2 + .../npcs/scripted/gui/ScriptGuiLine.java | 107 ++++++++++++++++++ .../npcs/scripted/interfaces/ICustomGui.java | 4 + .../npcs/scripted/interfaces/ILine.java | 17 +++ 7 files changed, 212 insertions(+), 10 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ILine.java diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 7ad35397e..23a6d6e57 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -429,6 +429,11 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD this.components.put(scroll.getID(), scroll); this.addDataHolder(scroll); this.addClickListener(scroll); + break; + case 6: + CustomGuiLine line = CustomGuiLine.fromComponent((ScriptGuiLine) component); + this.components.put(line.getID(),line); + break; } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java new file mode 100644 index 000000000..03685e9db --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java @@ -0,0 +1,64 @@ +package noppes.npcs.client.gui.custom.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.scripted.gui.ScriptGuiLine; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class CustomGuiLine extends Gui implements IGuiComponent { + int id; + GuiCustom parent; + int x1; + int y1; + int x2; + int y2; + int color; + int thickness; + + public CustomGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.id = id; + this.x1 = GuiCustom.guiLeft + x1; + this.y1 = GuiCustom.guiTop + y1; + this.x2 = GuiCustom.guiLeft + x2; + this.y2 = GuiCustom.guiTop + y2; + this.color = color; + this.thickness = thickness; + } + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + @Override + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); + + float particleRed = (color >> 16 & 255) / 255f; + float particleGreen = (color >> 8 & 255) / 255f; + float particleBlue = (color & 255) / 255f; + + mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); + GL11.glPushMatrix(); + GL11.glColor4f(particleRed,particleGreen,particleBlue,1.0F); + GL11.glTranslatef(this.x1,this.y1,0.0F); + GL11.glRotatef((float) (Math.sin((x1-x2)/distance)*180/Math.PI),0.0F,0.0F,1.0F); + this.drawTexturedModalRect((int) -Math.ceil((double)thickness/2),0,0,0, thickness, (int) distance); + GL11.glPopMatrix(); + } + + public ICustomGuiComponent toComponent() { + return new ScriptGuiLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); + } + + public static CustomGuiLine fromComponent(ScriptGuiLine component) { + return new CustomGuiLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index 378bf3f82..c840cff66 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -13,17 +13,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.scripted.interfaces.*; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; -import noppes.npcs.scripted.interfaces.IPlayer; -import noppes.npcs.scripted.interfaces.IButton; -import noppes.npcs.scripted.interfaces.ICustomGui; -import noppes.npcs.scripted.interfaces.ICustomGuiComponent; -import noppes.npcs.scripted.interfaces.IItemSlot; -import noppes.npcs.scripted.interfaces.ILabel; -import noppes.npcs.scripted.interfaces.IScroll; -import noppes.npcs.scripted.interfaces.ITextField; -import noppes.npcs.scripted.interfaces.ITexturedRect; -import noppes.npcs.scripted.interfaces.IItemStack; import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.controllers.CustomGuiController; import noppes.npcs.controllers.ScriptContainer; @@ -170,6 +161,18 @@ public class ScriptGui implements ICustomGui { return (IScroll)this.components.get(this.components.size() - 1); } + public ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) { + ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2, color, thickness); + this.components.add(line); + return (ILine) this.components.get(this.components.size() - 1); + } + + public ILine addLine(int id, int x1, int y1, int x2, int y2) { + ScriptGuiLine line = new ScriptGuiLine(id, x1, y1, x2, y2); + this.components.add(line); + return (ILine) this.components.get(this.components.size() - 1); + } + public void showPlayerInventory(int x, int y) { this.showPlayerInv = true; this.playerInvX = x; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java index 4d218b0db..4ae43e774 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java @@ -112,6 +112,8 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent { return (new ScriptGuiScroll()).fromNBT(nbt); case 5: return (new ScriptGuiItemSlot()).fromNBT(nbt); + case 6: + return (new ScriptGuiLine()).fromNBT(nbt); default: return null; } diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java new file mode 100644 index 000000000..69c72a711 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java @@ -0,0 +1,107 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.ILine; + +public class ScriptGuiLine extends ScriptGuiComponent implements ILine { + int x1; + int y1; + int x2; + int y2; + int color = 0; + int thickness = 2; + + public ScriptGuiLine(){ + } + + public ScriptGuiLine(int id, int x1, int y1, int x2, int y2){ + this.setPos(x1, y1); + this.setID(id); + this.hoverText = new String[]{""}; + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + + public ScriptGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.setPos(x1, y1); + this.setID(id); + this.hoverText = new String[]{""}; + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.thickness = thickness; + } + + @Override + public int getType() { + return 6; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setInteger("X1",x1); + nbt.setInteger("Y1",y1); + nbt.setInteger("X2",x2); + nbt.setInteger("Y2",y2); + nbt.setInteger("Color",color); + nbt.setInteger("Thickness",thickness); + + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + x1 = nbt.getInteger("X1"); + y1 = nbt.getInteger("Y1"); + x2 = nbt.getInteger("X2"); + y2 = nbt.getInteger("Y2"); + color = nbt.getInteger("Color"); + thickness = nbt.getInteger("Thickness"); + + return this; + } + + public int getX1(){ + return this.x1; + } + public int getY1(){ + return this.y1; + } + public int getX2(){ + return this.x2; + } + public int getY2(){ + return this.y2; + } + public int getColor(){ + return this.color; + } + public int getThickness(){ + return this.thickness; + } + + public void setX1(int x1){ + this.x1 = x1; + } + public void setY1(int y1){ + this.y1 = y1; + } + public void setX2(int x2){ + this.x2 = x2; + } + public void setY2(int y2){ + this.y2 = y2; + } + public void setColor(int color){ + this.color = color; + } + public void setThickness(int thickness){ + this.thickness = thickness; + } +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java index 02f6a958e..2f803b32e 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java @@ -44,6 +44,10 @@ public interface ICustomGui { IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6); + ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness); + + ILine addLine(int id, int x1, int y1, int x2, int y2); + IItemSlot addItemSlot(int var1, int var2); IItemSlot addItemSlot(int var1, int var2, IItemStack var3); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ILine.java b/src/main/java/noppes/npcs/scripted/interfaces/ILine.java new file mode 100644 index 000000000..b1a6690b0 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ILine.java @@ -0,0 +1,17 @@ +package noppes.npcs.scripted.interfaces; + +public interface ILine extends ICustomGuiComponent { + int getX1(); + int getY1(); + int getX2(); + int getY2(); + int getColor(); + int getThickness(); + + void setX1(int x1); + void setY1(int y1); + void setX2(int x2); + void setY2(int y2); + void setColor(int color); + void setThickness(int thickness); +} From 534f716991833c6cfde46056cc5a97542c29cf7e Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 04:05:01 -0600 Subject: [PATCH 07/15] Implemented Scripted Overlays which stay on the player's screen. Overlays persist in the client, and can be removed from the screen as well. --- src/main/java/noppes/npcs/client/Client.java | 3 + .../npcs/client/ClientEventHandler.java | 11 +- .../npcs/client/PacketHandlerClient.java | 11 ++ .../gui/custom/components/CustomGuiLabel.java | 1 - .../gui/custom/components/CustomGuiLine.java | 13 +- .../gui/customoverlay/OverlayCustom.java | 104 +++++++++++ .../components/CustomOverlayLabel.java | 125 ++++++++++++++ .../components/CustomOverlayLine.java | 73 ++++++++ .../components/CustomOverlayTexturedRect.java | 83 +++++++++ .../interfaces/IOverlayComponent.java | 7 + .../npcs/client/renderer/RenderCustomNpc.java | 2 - .../npcs/constants/EnumPacketClient.java | 2 +- .../npcs/controllers/CustomGuiController.java | 13 +- .../npcs/scripted/entity/ScriptPlayer.java | 16 +- .../scripted/interfaces/ICustomOverlay.java | 4 + .../interfaces/ICustomOverlayComponent.java | 17 ++ .../scripted/interfaces/IOverlayLabel.java | 21 +++ .../scripted/interfaces/IOverlayLine.java | 17 ++ .../interfaces/IOverlayTexturedRect.java | 23 +++ .../npcs/scripted/overlay/ScriptOverlay.java | 161 ++++++++++++++++++ .../overlay/ScriptOverlayComponent.java | 88 ++++++++++ .../scripted/overlay/ScriptOverlayLabel.java | 109 ++++++++++++ .../scripted/overlay/ScriptOverlayLine.java | 106 ++++++++++++ .../overlay/ScriptOverlayTexturedRect.java | 109 ++++++++++++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 5 + 25 files changed, 1105 insertions(+), 19 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java diff --git a/src/main/java/noppes/npcs/client/Client.java b/src/main/java/noppes/npcs/client/Client.java index 7d57987b3..cb37e5d72 100644 --- a/src/main/java/noppes/npcs/client/Client.java +++ b/src/main/java/noppes/npcs/client/Client.java @@ -4,13 +4,16 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.io.IOException; +import java.util.HashMap; import noppes.npcs.CustomNpcs; import noppes.npcs.Server; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.constants.EnumPacketServer; import cpw.mods.fml.common.network.internal.FMLProxyPacket; public class Client { + public static HashMap customOverlays = new HashMap<>(); public static void sendData(EnumPacketServer enu, Object... obs) { ByteBuf buffer = Unpooled.buffer(); diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 919318be6..6c1bbc382 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -1,5 +1,14 @@ package noppes.npcs.client; -public class ClientEventHandler { +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +public class ClientEventHandler { + @SubscribeEvent + public void onOverlayRender(RenderGameOverlayEvent.Pre event){ + for(OverlayCustom overlayCustom : Client.customOverlays.values()){ + overlayCustom.renderGameOverlay(event.partialTicks); + } + } } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 138958ed4..ea6c4891c 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -26,6 +26,7 @@ import noppes.npcs.ServerEventsHandler; import noppes.npcs.client.ClientProxy.FontContainer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.player.GuiBook; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; import noppes.npcs.client.gui.util.GuiNPCInterface; @@ -259,5 +260,15 @@ public class PacketHandlerClient extends PacketHandlerServer{ NoppesUtil.isGUIOpen(isGUIOpen); } + else if(type == EnumPacketClient.OVERLAY_DATA){ + OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft()); + overlayCustom.setOverlayData(Server.readNBT(buffer)); + + Client.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom); + } + else if(type == EnumPacketClient.OVERLAY_CLOSE){ + int id = buffer.readInt(); + Client.customOverlays.remove(id); + } } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index 31eb61e01..1a7085efe 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -44,7 +44,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { private int field_146165_q; private FontRenderer field_146164_r; private int field_146163_s; - private static final String __OBFID = "CL_00000671"; public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ this.id = id; diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java index 03685e9db..5bfcfe404 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java @@ -41,16 +41,17 @@ public class CustomGuiLine extends Gui implements IGuiComponent { public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); - float particleRed = (color >> 16 & 255) / 255f; - float particleGreen = (color >> 8 & 255) / 255f; - float particleBlue = (color & 255) / 255f; + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); GL11.glPushMatrix(); - GL11.glColor4f(particleRed,particleGreen,particleBlue,1.0F); + GL11.glColor4f(red,green,blue,1.0F); GL11.glTranslatef(this.x1,this.y1,0.0F); - GL11.glRotatef((float) (Math.sin((x1-x2)/distance)*180/Math.PI),0.0F,0.0F,1.0F); - this.drawTexturedModalRect((int) -Math.ceil((double)thickness/2),0,0,0, thickness, (int) distance); + GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); + GL11.glScaled(thickness, distance,0.0D); + this.drawTexturedModalRect(0,0,0,0, 1, 1); GL11.glPopMatrix(); } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java new file mode 100644 index 000000000..9c4d17fb5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java @@ -0,0 +1,104 @@ +package noppes.npcs.client.gui.customoverlay; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLabel; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLine; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayTexturedRect; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.*; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class OverlayCustom extends Gui { + protected final Minecraft mc; + + private ScaledResolution res = null; + public static int scaledWidth = 0; + public static int scaledHeight = 0; + + public ScriptOverlay overlay; + Map components = new HashMap(); + + float scale = 1.0F; + int x = 0; + int y = 0; + int textureX = 0; + int textureY = 0; + int width = 200; + int height = 200; + + public OverlayCustom(Minecraft mc) { + this.mc = mc; + } + + public void initOverlay(){ + res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + if(this.overlay != null){ + scaledWidth = res.getScaledWidth(); + scaledHeight = res.getScaledHeight(); + + this.components.clear(); + Iterator var1 = this.overlay.getComponents().iterator(); + + while(var1.hasNext()) { + ICustomOverlayComponent c = (ICustomOverlayComponent)var1.next(); + this.addComponent(c); + } + } + } + + private void addComponent(ICustomOverlayComponent component) { + ScriptOverlayComponent c = (ScriptOverlayComponent)component; + switch(c.getType()) { + case 0: + CustomOverlayTexturedRect rect = CustomOverlayTexturedRect.fromComponent((ScriptOverlayTexturedRect) component); + rect.setParent(this); + this.components.put(rect.getID(), rect); + break; + case 1: + CustomOverlayLabel lbl = CustomOverlayLabel.fromComponent((ScriptOverlayLabel)component); + lbl.setParent(this); + this.components.put(lbl.getID(), lbl); + break; + case 2: + CustomOverlayLine line = CustomOverlayLine.fromComponent((ScriptOverlayLine) component); + line.setParent(this); + this.components.put(line.getID(), line); + break; + } + } + + public void renderGameOverlay(float partialTicks){ + res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + scaledWidth = res.getScaledWidth(); + scaledHeight = res.getScaledHeight(); + + GL11.glPushMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_BLEND); + + Iterator var4 = this.components.values().iterator(); + + while(var4.hasNext()) { + IOverlayComponent component = (IOverlayComponent)var4.next(); + component.onRender(this.mc, partialTicks); + } + + GL11.glEnable(GL11.GL_BLEND); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } + + public void setOverlayData(NBTTagCompound compound) { + this.overlay = (ScriptOverlay)(new ScriptOverlay()).fromNBT(compound); + this.initOverlay(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java new file mode 100644 index 000000000..3095d31f7 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -0,0 +1,125 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayLabel; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; + +public class CustomOverlayLabel extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + int x, y, width, height; + String fullLabel; + int color; + String[] hoverText; + float scale; + int border = 2; + boolean labelBgEnabled = true; + boolean labelShadowEnabled = false; + + protected int field_146167_a; + protected int field_146161_f; + public int field_146162_g; + public int field_146174_h; + private ArrayList field_146173_k; + private boolean field_146170_l; + public boolean field_146172_j; + private boolean field_146171_m; + private int field_146168_n; + private int field_146169_o; + private int field_146166_p; + private int field_146165_q; + private FontRenderer field_146164_r; + private int field_146163_s; + + public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ + this.id = id; + this.fullLabel = fullLabel; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.labelShadowEnabled = shadow; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public void onRender(Minecraft mc, float partialTicks) { + this.drawLabel(); + } + + public int getID() { + return this.id; + } + + public void setScale(float scale) { + this.scale = scale; + } + + public static CustomOverlayLabel fromComponent(ScriptOverlayLabel component) { + CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow()); + lbl.scale = 1.0F; + lbl.color = component.getColor(); + lbl.field_146172_j = true; + lbl.setScale(component.getScale()); + + lbl.labelShadowEnabled = component.hasShadow(); + lbl.alignment = component.getAlignment(); + + return lbl; + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); + component.enableShadow(this.labelShadowEnabled); + component.setAlignment(alignment); + return component; + } + + public void drawLabel() + { + if (this.field_146172_j) + { + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + this.drawLabelBackground(); + GL11.glPushMatrix(); + 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.x,this.y,0.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + GL11.glPopMatrix(); + } + } + + protected void drawLabelBackground() + { + if (this.labelBgEnabled) + { + int k = (int)(this.width*this.scale) + this.border * 2; + int l = (int)(this.height*this.scale) + this.border * 2; + int i1 = this.x - this.border; + int j1 = this.y - this.border; + drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor + this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor + this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor + this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor + this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java new file mode 100644 index 000000000..28b020a21 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -0,0 +1,73 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayLine; +import org.lwjgl.opengl.GL11; + +public class CustomOverlayLine extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + int x1; + int y1; + int x2; + int y2; + int color; + int thickness; + + public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.id = id; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.thickness = thickness; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, float partialTicks) { + double distance = Math.hypot(x1-x2, y1-y2); + + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + + mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); + GL11.glPushMatrix(); + 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.glColor4f(red,green,blue,1.0F); + GL11.glTranslatef(this.x1,this.y1,0.0F); + GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); + GL11.glScaled(thickness, distance,0.0D); + this.drawTexturedModalRect(0,0,0,0, 1, 1); + GL11.glPopMatrix(); + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayLine line = new ScriptOverlayLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); + line.setAlignment(alignment); + return line; + } + + public static CustomOverlayLine fromComponent(ScriptOverlayLine component) { + CustomOverlayLine line = new CustomOverlayLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); + line.alignment = component.getAlignment(); + + return line; + } +} 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 new file mode 100644 index 000000000..5d0b97ba5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -0,0 +1,83 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; +import org.lwjgl.opengl.GL11; + +public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + ResourceLocation texture; + int x; + int y; + int width; + int height; + int textureX; + int textureY; + float scale; + + public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { + this(id, texture, x, y, width, height, 0, 0); + } + + public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this.scale = 1.0F; + this.alignment = 0; + this.id = id; + this.texture = new ResourceLocation(texture); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.textureX = textureX; + this.textureY = textureY; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, float partialTicks) { + mc.getTextureManager().bindTexture(this.texture); + + GL11.glPushMatrix(); + 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.glColor4f(1.0F,1.0F,1.0F,1.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); + GL11.glPopMatrix(); + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); + component.setScale(this.scale); + component.setAlignment(alignment); + return component; + } + + public static CustomOverlayTexturedRect fromComponent(ScriptOverlayTexturedRect component) { + CustomOverlayTexturedRect rect; + if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { + rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); + } else { + rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + } + + rect.scale = component.getScale(); + rect.alignment = component.getAlignment(); + + return rect; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java b/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java new file mode 100644 index 000000000..685cb46da --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java @@ -0,0 +1,7 @@ +package noppes.npcs.client.gui.customoverlay.interfaces; + +import net.minecraft.client.Minecraft; + +public interface IOverlayComponent { + void onRender(Minecraft mc, float partialTicks); +} diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index 57e9dd460..51a0ff9aa 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -112,8 +112,6 @@ public class RenderCustomNpc extends RenderNPCHumanMale{ @Override public void doRender(EntityLiving entityliving, double d, double d1, double d2, float f, float f1){ - EntityNPCInterface npc = (EntityNPCInterface) entityliving; - super.doRender(entityliving, d, d1, d2, f, f1); } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index c11a36d6e..243674a9a 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -1,6 +1,6 @@ package noppes.npcs.constants; public enum EnumPacketClient { - CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN + CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN, OVERLAY_DATA, OVERLAY_CLOSE } diff --git a/src/main/java/noppes/npcs/controllers/CustomGuiController.java b/src/main/java/noppes/npcs/controllers/CustomGuiController.java index edb1cf15c..53cbc932d 100644 --- a/src/main/java/noppes/npcs/controllers/CustomGuiController.java +++ b/src/main/java/noppes/npcs/controllers/CustomGuiController.java @@ -3,10 +3,7 @@ package noppes.npcs.controllers; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import noppes.npcs.CustomNpcs; import noppes.npcs.Server; import noppes.npcs.constants.EnumGuiType; @@ -18,6 +15,7 @@ import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.event.CustomGuiEvent; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import java.io.IOException; @@ -42,6 +40,15 @@ public class CustomGuiController { } } + public static void openOverlay(ScriptPlayer player, ScriptOverlay gui) { + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()}); + } + + public static boolean updateOverlay(ScriptPlayer player, ScriptOverlay gui) { + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()}); + return true; + } + static boolean checkGui(CustomGuiEvent event) { EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); if (!(player.openContainer instanceof ContainerCustomGui)) { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 042302d19..05d577214 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -25,10 +25,8 @@ import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.data.IQuest; -import noppes.npcs.scripted.interfaces.IContainer; -import noppes.npcs.scripted.interfaces.ICustomGui; -import noppes.npcs.scripted.interfaces.IPlayer; -import noppes.npcs.scripted.interfaces.ITimers; +import noppes.npcs.scripted.interfaces.*; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.util.ValueUtil; import java.util.ArrayList; @@ -459,7 +457,15 @@ public class ScriptPlayer extends ScriptLivingBase public void closeGui() { ((EntityPlayerMP)this.entity).closeContainer(); - Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, new Object[]{-1, new NBTTagCompound()}); + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, -1, new NBTTagCompound()); + } + + public void showCustomOverlay(ICustomOverlay overlay) { + CustomGuiController.openOverlay(this, (ScriptOverlay) overlay); + } + + public void closeOverlay(int id) { + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.OVERLAY_CLOSE, id, new NBTTagCompound()); } public IQuest[] getFinishedQuests() { diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java new file mode 100644 index 000000000..d95a12598 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces; + +public interface ICustomOverlay { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java new file mode 100644 index 000000000..49d81bf53 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java @@ -0,0 +1,17 @@ +package noppes.npcs.scripted.interfaces; + +public interface ICustomOverlayComponent { + int getID(); + + ICustomOverlayComponent setID(int id); + + int getPosX(); + + int getPosY(); + + ICustomOverlayComponent setPos(int x, int y); + + int getAlignment(); + + void setAlignment(int alignment); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java new file mode 100644 index 000000000..d2283c103 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java @@ -0,0 +1,21 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayLabel extends ICustomOverlayComponent { + String getText(); + + IOverlayLabel setText(String var1); + + int getWidth(); + + int getHeight(); + + IOverlayLabel setSize(int var1, int var2); + + int getColor(); + + IOverlayLabel setColor(int var1); + + float getScale(); + + IOverlayLabel setScale(float var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java new file mode 100644 index 000000000..18a1c9b2a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java @@ -0,0 +1,17 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayLine extends ICustomOverlayComponent { + int getX1(); + int getY1(); + int getX2(); + int getY2(); + int getColor(); + int getThickness(); + + void setX1(int x1); + void setY1(int y1); + void setX2(int x2); + void setY2(int y2); + void setColor(int color); + void setThickness(int thickness); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java new file mode 100644 index 000000000..bd5b6a2d6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java @@ -0,0 +1,23 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayTexturedRect extends ICustomOverlayComponent { + String getTexture(); + + IOverlayTexturedRect setTexture(String var1); + + int getWidth(); + + int getHeight(); + + IOverlayTexturedRect setSize(int var1, int var2); + + float getScale(); + + IOverlayTexturedRect setScale(float var1); + + int getTextureX(); + + int getTextureY(); + + IOverlayTexturedRect setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java new file mode 100644 index 000000000..a3394a7eb --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java @@ -0,0 +1,161 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.CustomGuiController; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.gui.ScriptGuiItemSlot; +import noppes.npcs.scripted.gui.ScriptGuiLabel; +import noppes.npcs.scripted.gui.ScriptGuiLine; +import noppes.npcs.scripted.interfaces.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ScriptOverlay implements ICustomOverlay { + int id; + int defaultAlignment = 0; + List components = new ArrayList(); + + public ScriptOverlay(){ + } + + public ScriptOverlay(int id){ + this.id = id; + } + + public int getID() { + return this.id; + } + + public List getComponents() { + return this.components; + } + + public PlayerDataScript getScriptHandler() { + return ScriptController.Instance.playerScripts;//this.scriptHandler; + } + + public int getDefaultAlignment(){ + return this.defaultAlignment; + } + + public void setDefaultAlignment(int defaultAlignment) { + this.defaultAlignment = defaultAlignment; + } + + public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height); + this.components.add(component); + return (IOverlayTexturedRect)this.components.get(this.components.size() - 1); + } + + public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height, textureX, textureY); + this.components.add(component); + return (IOverlayTexturedRect)this.components.get(this.components.size() - 1); + } + + public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height) { + ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height); + this.components.add(component); + return (IOverlayLabel)this.components.get(this.components.size() - 1); + } + + public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height, int color) { + ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height, color); + this.components.add(component); + return (IOverlayLabel)this.components.get(this.components.size() - 1); + } + + public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) { + ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2, color, thickness); + this.components.add(line); + return (IOverlayLine) this.components.get(this.components.size() - 1); + } + + public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2) { + ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2); + this.components.add(line); + return (IOverlayLine) this.components.get(this.components.size() - 1); + } + + public ICustomOverlayComponent getComponent(int componentID) { + Iterator var2 = this.components.iterator(); + + ICustomOverlayComponent component; + do { + if (!var2.hasNext()) { + return null; + } + + component = (ICustomOverlayComponent)var2.next(); + } while(component.getID() != componentID); + + return component; + } + + public void removeComponent(int componentID) { + for(int i = 0; i < this.components.size(); ++i) { + if (((ICustomOverlayComponent)this.components.get(i)).getID() == componentID) { + this.components.remove(i); + return; + } + } + + } + + public void updateComponent(ICustomOverlayComponent component) { + for(int i = 0; i < this.components.size(); ++i) { + ICustomOverlayComponent c = (ICustomOverlayComponent)this.components.get(i); + if (c.getID() == component.getID()) { + this.components.set(i, component); + return; + } + } + + } + + public void update(IPlayer player) { + CustomGuiController.updateOverlay((ScriptPlayer)player, this); + } + + public ICustomOverlay fromNBT(NBTTagCompound tag) { + this.id = tag.getInteger("id"); + List components = new ArrayList(); + + NBTTagList list = tag.getTagList("components", 10); + for(int i = 0; i < list.tagCount(); i++){ + NBTBase b = list.getCompoundTagAt(i); + ScriptOverlayComponent component = ScriptOverlayComponent.createFromNBT((NBTTagCompound)b); + components.add(component); + } + + this.components = components; + + return this; + } + + public NBTTagCompound toNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("id", this.id); + + NBTTagList list = new NBTTagList(); + Iterator var3 = this.components.iterator(); + + ICustomOverlayComponent c; + while(var3.hasNext()) { + c = (ICustomOverlayComponent)var3.next(); + list.appendTag(((ScriptOverlayComponent)c).toNBT(new NBTTagCompound())); + } + + tag.setTag("components", list); + + return tag; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java new file mode 100644 index 000000000..d9e8a3933 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -0,0 +1,88 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.gui.*; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; + +public abstract class ScriptOverlayComponent implements ICustomOverlayComponent { + int id; + int posX; + int posY; + int alignment = 0; + /* ========ALIGNMENTS======== + 0 1 2 + + 3 4 5 + + 6 7 8 + */ + + public ScriptOverlayComponent(){ + } + + public int getID() { + return this.id; + } + + public ICustomOverlayComponent setID(int id) { + this.id = id; + return this; + } + + public int getPosX() { + return this.posX; + } + + public int getPosY() { + return this.posY; + } + + public ICustomOverlayComponent setPos(int x, int y) { + this.posX = x; + this.posY = y; + return this; + } + + public int getAlignment() { + return this.alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public abstract int getType(); + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + nbt.setInteger("id", this.id); + nbt.setIntArray("pos", new int[]{this.posX, this.posY}); + nbt.setInteger("alignment",this.alignment); + + nbt.setInteger("type", this.getType()); + return nbt; + } + + public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) { + this.setID(nbt.getInteger("id")); + this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); + this.setAlignment(nbt.getInteger("alignment")); + + return this; + } + + public static ScriptOverlayComponent createFromNBT(NBTTagCompound nbt) { + switch(nbt.getInteger("type")) { + case 0: + return (new ScriptOverlayTexturedRect()).fromNBT(nbt); + case 1: + return (new ScriptOverlayLabel()).fromNBT(nbt); + case 2: + return (new ScriptOverlayLine()).fromNBT(nbt); + default: + return null; + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java new file mode 100644 index 000000000..080800f92 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -0,0 +1,109 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.ILabel; +import noppes.npcs.scripted.interfaces.IOverlayLabel; + +public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverlayLabel { + String label; + int width; + int height; + int color; + float scale; + boolean shadow; + + public ScriptOverlayLabel() { + this.color = 16777215; + this.scale = 1.0F; + } + + public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height) { + this.color = 16777215; + this.scale = 1.0F; + this.setID(id); + this.setText(label); + this.setPos(x, y); + this.setSize(width, height); + this.enableShadow(false); + } + + public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height, int color) { + this(id, label, x, y, width, height); + this.setColor(color); + } + + public String getText() { + return this.label; + } + + public IOverlayLabel setText(String label) { + this.label = label; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IOverlayLabel setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public int getColor() { + return this.color; + } + + public IOverlayLabel setColor(int color) { + this.color = color; + return this; + } + + public float getScale() { + return this.scale; + } + + public IOverlayLabel setScale(float scale) { + this.scale = scale; + return this; + } + + public boolean hasShadow(){ + return this.shadow; + } + + public void enableShadow(boolean shadow){ + this.shadow = shadow; + } + + @Override + public int getType() { + return 1; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setString("label", this.label); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setInteger("color", this.color); + nbt.setFloat("scale", this.scale); + nbt.setBoolean("shadow",this.shadow); + return nbt; + } + + public ScriptOverlayLabel fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setText(nbt.getString("label")); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setColor(nbt.getInteger("color")); + this.setScale(nbt.getFloat("scale")); + this.enableShadow(this.shadow); + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java new file mode 100644 index 000000000..3ad778b3c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java @@ -0,0 +1,106 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.IOverlayLine; + +public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverlayLine { + int x1; + int y1; + int x2; + int y2; + int color = 0; + int thickness = 2; + + public ScriptOverlayLine(){ + } + + public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2){ + this.setPos(x1, y1); + this.setID(id); + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + + public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.setPos(x1, y1); + this.setID(id); + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.thickness = thickness; + } + + @Override + public int getType() { + return 2; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setInteger("X1",x1); + nbt.setInteger("Y1",y1); + nbt.setInteger("X2",x2); + nbt.setInteger("Y2",y2); + nbt.setInteger("Color",color); + nbt.setInteger("Thickness",thickness); + + return nbt; + } + + public ScriptOverlayLine fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + x1 = nbt.getInteger("X1"); + y1 = nbt.getInteger("Y1"); + x2 = nbt.getInteger("X2"); + y2 = nbt.getInteger("Y2"); + color = nbt.getInteger("Color"); + thickness = nbt.getInteger("Thickness"); + + return this; + } + + public int getX1(){ + return this.x1; + } + public int getY1(){ + return this.y1; + } + public int getX2(){ + return this.x2; + } + public int getY2(){ + return this.y2; + } + public int getColor(){ + return this.color; + } + public int getThickness(){ + return this.thickness; + } + + public void setX1(int x1){ + this.x1 = x1; + } + public void setY1(int y1){ + this.y1 = y1; + } + public void setX2(int x2){ + this.x2 = x2; + } + public void setY2(int y2){ + this.y2 = y2; + } + public void setColor(int color){ + this.color = color; + } + public void setThickness(int thickness){ + this.thickness = thickness; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java new file mode 100644 index 000000000..0fb2d0bd6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java @@ -0,0 +1,109 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.IOverlayTexturedRect; +import noppes.npcs.scripted.interfaces.ITexturedRect; + +public class ScriptOverlayTexturedRect extends ScriptOverlayComponent implements IOverlayTexturedRect { + int width; + int height; + int textureX; + int textureY; + float scale; + String texture; + + public ScriptOverlayTexturedRect() { + this.textureY = -1; + this.scale = 1.0F; + } + + public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { + this.textureY = -1; + this.scale = 1.0F; + this.setID(id); + this.setTexture(texture); + this.setPos(x, y); + this.setSize(width, height); + } + + public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this(id, texture, x, y, width, height); + this.setTextureOffset(textureX, textureY); + } + + public String getTexture() { + return this.texture; + } + + public IOverlayTexturedRect setTexture(String texture) { + this.texture = texture; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IOverlayTexturedRect setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public float getScale() { + return this.scale; + } + + public IOverlayTexturedRect setScale(float scale) { + this.scale = scale; + return this; + } + + public int getTextureX() { + return this.textureX; + } + + public int getTextureY() { + return this.textureY; + } + + public IOverlayTexturedRect setTextureOffset(int offsetX, int offsetY) { + this.textureX = offsetX; + this.textureY = offsetY; + return this; + } + + @Override + public int getType() { + return 0; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setFloat("scale", this.scale); + nbt.setString("texture", this.texture); + if (this.textureX >= 0 && this.textureY >= 0) { + nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY}); + } + + return nbt; + } + + public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setScale(nbt.getFloat("scale")); + this.setTexture(nbt.getString("texture")); + if (nbt.hasKey("texPos")) { + this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 7788edac9..631f486c6 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -41,6 +41,7 @@ import noppes.npcs.scripted.entity.*; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.*; import noppes.npcs.scripted.interfaces.*; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.util.JsonException; import noppes.npcs.util.LRUHashMap; import noppes.npcs.util.NBTJsonUtil; @@ -275,4 +276,8 @@ public class WrapperNpcAPI extends NpcAPI { public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) { return new ScriptGui(id, width, height, pauseGame); } + + public ICustomOverlay createCustomOverlay(int id) { + return new ScriptOverlay(id); + } } From be61bd4e1719464219b12b44e5cce55ba7787525 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 04:33:00 -0600 Subject: [PATCH 08/15] Made color and alpha components global among ScriptOverlay classes. --- .../components/CustomOverlayLabel.java | 10 ++++++++ .../components/CustomOverlayLine.java | 17 ++++++++----- .../components/CustomOverlayTexturedRect.java | 15 ++++++++++-- .../npcs/scripted/gui/ScriptGuiLabel.java | 2 +- .../interfaces/ICustomOverlayComponent.java | 8 +++++++ .../scripted/interfaces/IOverlayLabel.java | 4 ---- .../scripted/interfaces/IOverlayLine.java | 4 ++-- .../overlay/ScriptOverlayComponent.java | 24 +++++++++++++++++++ .../scripted/overlay/ScriptOverlayLabel.java | 14 +---------- .../scripted/overlay/ScriptOverlayLine.java | 9 ------- .../overlay/ScriptOverlayTexturedRect.java | 1 + 11 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 3095d31f7..0d74aeaf9 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -21,6 +21,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { int x, y, width, height; String fullLabel; int color; + float alpha; String[] hoverText; float scale; int border = 2; @@ -77,6 +78,8 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { lbl.labelShadowEnabled = component.hasShadow(); lbl.alignment = component.getAlignment(); + lbl.alpha = component.getAlpha(); + lbl.color = component.getColor(); return lbl; } @@ -85,6 +88,8 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); component.enableShadow(this.labelShadowEnabled); component.setAlignment(alignment); + component.setAlpha(alpha); + component.setColor(color); return component; } @@ -98,6 +103,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { this.drawLabelBackground(); GL11.glPushMatrix(); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + 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);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 GL11.glTranslatef(this.x,this.y,0.0F); diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java index 28b020a21..8bac43c13 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -20,6 +20,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { int y2; int color; int thickness; + float alpha; public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ this.id = id; @@ -42,16 +43,16 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { public void onRender(Minecraft mc, float partialTicks) { double distance = Math.hypot(x1-x2, y1-y2); - float red = (color >> 16 & 255) / 255f; - float green = (color >> 8 & 255) / 255f; - float blue = (color & 255) / 255f; - mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); GL11.glPushMatrix(); - 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 + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); - GL11.glColor4f(red,green,blue,1.0F); + 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.x1,this.y1,0.0F); + GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); GL11.glScaled(thickness, distance,0.0D); this.drawTexturedModalRect(0,0,0,0, 1, 1); @@ -61,12 +62,16 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { public ICustomOverlayComponent toComponent() { ScriptOverlayLine line = new ScriptOverlayLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); line.setAlignment(alignment); + line.setAlpha(alpha); + line.setColor(color); return line; } public static CustomOverlayLine fromComponent(ScriptOverlayLine component) { CustomOverlayLine line = new CustomOverlayLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); line.alignment = component.getAlignment(); + line.alpha = component.getAlpha(); + line.color = component.getColor(); return line; } 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 5d0b97ba5..9d5917d94 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 @@ -23,6 +23,9 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent int textureY; float scale; + int color; + float alpha; + public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { this(id, texture, x, y, width, height, 0, 0); } @@ -52,9 +55,13 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent mc.getTextureManager().bindTexture(this.texture); GL11.glPushMatrix(); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + 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);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 - GL11.glColor4f(1.0F,1.0F,1.0F,1.0F); GL11.glScalef(this.scale, this.scale, this.scale); this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); GL11.glPopMatrix(); @@ -62,8 +69,10 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent public ICustomOverlayComponent toComponent() { ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); - component.setScale(this.scale); + component.setScale(scale); component.setAlignment(alignment); + component.setAlpha(alpha); + component.setColor(color); return component; } @@ -77,6 +86,8 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent rect.scale = component.getScale(); rect.alignment = component.getAlignment(); + rect.alpha = component.getAlpha(); + rect.color = component.getColor(); return rect; } diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java index 6467f60f8..c4e36ec20 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java @@ -100,7 +100,7 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); this.setColor(nbt.getInteger("color")); this.setScale(nbt.getFloat("scale")); - this.enableShadow(this.shadow); + this.enableShadow(nbt.getBoolean("shadow")); return this; } } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java index 49d81bf53..806983ba1 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java @@ -14,4 +14,12 @@ public interface ICustomOverlayComponent { int getAlignment(); void setAlignment(int alignment); + + int getColor(); + + ICustomOverlayComponent setColor(int color); + + float getAlpha(); + + void setAlpha(float alpha); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java index d2283c103..e69d13ec8 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java @@ -11,10 +11,6 @@ public interface IOverlayLabel extends ICustomOverlayComponent { IOverlayLabel setSize(int var1, int var2); - int getColor(); - - IOverlayLabel setColor(int var1); - float getScale(); IOverlayLabel setScale(float var1); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java index 18a1c9b2a..517eb7e51 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java @@ -1,17 +1,17 @@ package noppes.npcs.scripted.interfaces; +import noppes.npcs.scripted.overlay.ScriptOverlayLine; + public interface IOverlayLine extends ICustomOverlayComponent { int getX1(); int getY1(); int getX2(); int getY2(); - int getColor(); int getThickness(); void setX1(int x1); void setY1(int y1); void setX2(int x2); void setY2(int y2); - void setColor(int color); void setThickness(int thickness); } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java index d9e8a3933..10891007f 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -6,12 +6,15 @@ import net.minecraft.nbt.NBTTagString; import noppes.npcs.scripted.gui.*; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.interfaces.IOverlayTexturedRect; public abstract class ScriptOverlayComponent implements ICustomOverlayComponent { int id; int posX; int posY; int alignment = 0; + int color = 0xFFFFFF; + float alpha = 1.0F; /* ========ALIGNMENTS======== 0 1 2 @@ -54,12 +57,31 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.alignment = alignment; } + public int getColor() { + return this.color; + } + + public ICustomOverlayComponent setColor(int color) { + this.color = color; + return this; + } + + public float getAlpha() { + return this.alpha; + } + + public void setAlpha(float alpha) { + this.alpha = alpha; + } + public abstract int getType(); public NBTTagCompound toNBT(NBTTagCompound nbt) { nbt.setInteger("id", this.id); nbt.setIntArray("pos", new int[]{this.posX, this.posY}); nbt.setInteger("alignment",this.alignment); + nbt.setInteger("color", this.color); + nbt.setFloat("alpha",this.alpha); nbt.setInteger("type", this.getType()); return nbt; @@ -69,6 +91,8 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.setID(nbt.getInteger("id")); this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); this.setAlignment(nbt.getInteger("alignment")); + this.setColor(nbt.getInteger("color")); + this.setAlpha(nbt.getInteger("alpha")); return this; } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java index 080800f92..2394e0a72 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -9,7 +9,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl String label; int width; int height; - int color; float scale; boolean shadow; @@ -56,15 +55,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl return this; } - public int getColor() { - return this.color; - } - - public IOverlayLabel setColor(int color) { - this.color = color; - return this; - } - public float getScale() { return this.scale; } @@ -91,7 +81,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl super.toNBT(nbt); nbt.setString("label", this.label); nbt.setIntArray("size", new int[]{this.width, this.height}); - nbt.setInteger("color", this.color); nbt.setFloat("scale", this.scale); nbt.setBoolean("shadow",this.shadow); return nbt; @@ -101,9 +90,8 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl super.fromNBT(nbt); this.setText(nbt.getString("label")); this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); - this.setColor(nbt.getInteger("color")); this.setScale(nbt.getFloat("scale")); - this.enableShadow(this.shadow); + this.enableShadow(nbt.getBoolean("shadow")); return this; } } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java index 3ad778b3c..07590298c 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java @@ -9,7 +9,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla int y1; int x2; int y2; - int color = 0; int thickness = 2; public ScriptOverlayLine(){ @@ -48,7 +47,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla nbt.setInteger("Y1",y1); nbt.setInteger("X2",x2); nbt.setInteger("Y2",y2); - nbt.setInteger("Color",color); nbt.setInteger("Thickness",thickness); return nbt; @@ -60,7 +58,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla y1 = nbt.getInteger("Y1"); x2 = nbt.getInteger("X2"); y2 = nbt.getInteger("Y2"); - color = nbt.getInteger("Color"); thickness = nbt.getInteger("Thickness"); return this; @@ -78,9 +75,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla public int getY2(){ return this.y2; } - public int getColor(){ - return this.color; - } public int getThickness(){ return this.thickness; } @@ -97,9 +91,6 @@ public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverla public void setY2(int y2){ this.y2 = y2; } - public void setColor(int color){ - this.color = color; - } public void setThickness(int thickness){ this.thickness = thickness; } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java index 0fb2d0bd6..85d0fa155 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java @@ -2,6 +2,7 @@ package noppes.npcs.scripted.overlay; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.IOverlayLabel; import noppes.npcs.scripted.interfaces.IOverlayTexturedRect; import noppes.npcs.scripted.interfaces.ITexturedRect; From e5e1aa1972defa41ccdf6180a4eaa62ac81b0d43 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 05:20:45 -0600 Subject: [PATCH 09/15] Made color and alpha components global among ScriptGui classes. --- .../custom/components/CustomGuiButton.java | 94 ++++++++++--------- .../gui/custom/components/CustomGuiLabel.java | 13 ++- .../gui/custom/components/CustomGuiLine.java | 24 +++-- .../components/CustomGuiScrollComponent.java | 23 +++-- .../custom/components/CustomGuiTextField.java | 14 +++ .../components/CustomGuiTexturedRect.java | 17 +++- .../components/CustomOverlayLabel.java | 9 +- .../components/CustomOverlayLine.java | 4 + .../components/CustomOverlayTexturedRect.java | 4 + .../npcs/scripted/gui/ScriptGuiComponent.java | 25 +++++ .../npcs/scripted/gui/ScriptGuiLabel.java | 14 --- .../npcs/scripted/gui/ScriptGuiLine.java | 9 -- .../npcs/scripted/interfaces/ILabel.java | 4 - .../npcs/scripted/interfaces/ILine.java | 2 - .../overlay/ScriptOverlayComponent.java | 2 +- .../scripted/overlay/ScriptOverlayLabel.java | 8 +- 16 files changed, 168 insertions(+), 98 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java index 57ad3bc66..9cce17988 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java @@ -6,7 +6,6 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; @@ -23,17 +22,17 @@ public class CustomGuiButton extends GuiButton implements IClickListener { public int textureY; boolean field_146123_n; String label; - int colour; String[] hoverText; + int color; + float alpha; + public CustomGuiButton(int id, String buttonText, int x, int y) { super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, buttonText); - this.colour = 16777215; } public CustomGuiButton(int id, String buttonText, int x, int y, int width, int height) { super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height, buttonText); - this.colour = 16777215; } public CustomGuiButton(int buttonId, String buttonText, int x, int y, int width, int height, String texture) { @@ -66,6 +65,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener { btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY()); } + btn.color = component.getColor(); + btn.alpha = component.getAlpha(); + if (component.hasHoverText()) { btn.hoverText = component.getHoverText(); } @@ -81,59 +83,59 @@ public class CustomGuiButton extends GuiButton implements IClickListener { //GL11.func_179094_E(); //GL11.func_179109_b(0.0F, 0.0F, (float)this.id); GL11.glPushMatrix(); - GL11.glTranslatef(0.0F, 0.0F, (float)this.id); - FontRenderer fontRenderer = mc.fontRenderer; - int i; - if (this.texture == null) { - mc.getTextureManager().bindTexture(buttonTextures); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; - i = this.getHoverState(this.field_146123_n); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); - //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); - this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height); - this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); - this.mouseDragged(mc, mouseX, mouseY); - int j = 14737632; - if (this.packedFGColour != 0) { - j = this.packedFGColour; - } else if (!this.enabled) { - j = 10526880; - } else if (this.field_146123_n) { - j = 16777120; - } + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); - GL11.glTranslated(0.0D, 0.0D, 0.1D); - this.drawCenteredString(fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j); - } else { - mc.getTextureManager().bindTexture(this.texture); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; - i = this.hoverState(this.field_146123_n); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); - //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); - this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height); - this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.colour); - if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) { - this.parent.hoverText = this.hoverText; - } - } + GL11.glTranslatef(0.0F, 0.0F, (float)this.id); + FontRenderer fontRenderer = mc.fontRenderer; + int i; + if (this.texture == null) { + mc.getTextureManager().bindTexture(buttonTextures); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + i = this.getHoverState(this.field_146123_n); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height); + this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); + this.mouseDragged(mc, mouseX, mouseY); + int j = 14737632; + if (this.packedFGColour != 0) { + j = this.packedFGColour; + } else if (!this.enabled) { + j = 10526880; + } else if (this.field_146123_n) { + j = 16777120; + } + GL11.glTranslated(0.0D, 0.0D, 0.1D); + this.drawCenteredString(fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j); + } else { + mc.getTextureManager().bindTexture(this.texture); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + i = this.hoverState(this.field_146123_n); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height); + this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.color); + if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + } GL11.glPopMatrix(); } public ICustomGuiComponent toComponent() { ScriptGuiButton component = new ScriptGuiButton(this.id, this.label, this.xPosition, this.yPosition, this.width, this.height, this.texture.toString(), this.textureX, this.textureY); component.setHoverText(this.hoverText); + component.setColor(this.color); + component.setAlpha(this.alpha); return component; } - public void setColour(int colour) { - this.colour = colour; - } - protected int hoverState(boolean mouseOver) { int i = 0; if (mouseOver) { diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index 1a7085efe..aab12ed58 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -22,7 +22,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { int x, y, width, height; GuiCustom parent; String fullLabel; - int color; String[] hoverText; float scale; int id; @@ -30,6 +29,9 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { boolean labelBgEnabled = true; boolean labelShadowEnabled = false; + int color; + float alpha; + protected int field_146167_a; protected int field_146161_f; public int field_146162_g; @@ -85,6 +87,8 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { lbl.hoverText = component.getHoverText(); } lbl.labelShadowEnabled = component.hasShadow(); + lbl.color = component.getColor(); + lbl.alpha = component.getAlpha(); return lbl; } @@ -93,6 +97,8 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { ScriptGuiLabel component = new ScriptGuiLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); component.setHoverText(this.hoverText); component.enableShadow(this.labelShadowEnabled); + component.setColor(this.color); + component.setAlpha(this.alpha); return component; } @@ -106,6 +112,11 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { this.drawLabelBackground(); GL11.glPushMatrix(); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + GL11.glTranslatef(this.x,this.y,0.0F); GL11.glScalef(this.scale, this.scale, this.scale); Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java index 5bfcfe404..b4948aa6a 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java @@ -9,6 +9,9 @@ import noppes.npcs.scripted.gui.ScriptGuiLine; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; + public class CustomGuiLine extends Gui implements IGuiComponent { int id; GuiCustom parent; @@ -17,6 +20,7 @@ public class CustomGuiLine extends Gui implements IGuiComponent { int x2; int y2; int color; + float alpha; int thickness; public CustomGuiLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ @@ -41,13 +45,13 @@ public class CustomGuiLine extends Gui implements IGuiComponent { public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); - float red = (color >> 16 & 255) / 255f; - float green = (color >> 8 & 255) / 255f; - float blue = (color & 255) / 255f; - mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); GL11.glPushMatrix(); - GL11.glColor4f(red,green,blue,1.0F); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + GL11.glTranslatef(this.x1,this.y1,0.0F); GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); GL11.glScaled(thickness, distance,0.0D); @@ -56,10 +60,16 @@ public class CustomGuiLine extends Gui implements IGuiComponent { } public ICustomGuiComponent toComponent() { - return new ScriptGuiLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); + ScriptGuiLine line = new ScriptGuiLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); + line.setColor(this.color); + line.setAlpha(this.alpha); + return line; } public static CustomGuiLine fromComponent(ScriptGuiLine component) { - return new CustomGuiLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); + CustomGuiLine line = new CustomGuiLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); + line.color = component.getColor(); + line.alpha = component.getAlpha(); + return line; } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java index eba41ba2c..26f626ad9 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java @@ -25,6 +25,9 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo String[] hoverText; public boolean multiSelect = false; + int color; + float alpha; + public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id) { super(parent, id); this.mc = mc; @@ -48,13 +51,17 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { GL11.glPushMatrix(); - GL11.glTranslatef(0.0F, 0.0F, (float)this.id); - boolean hovered = mouseX >= this.guiLeft && mouseY >= this.guiTop && mouseX < this.guiLeft + this.xSize && mouseY < this.guiTop + this.ySize; - super.drawScreen(mouseX, mouseY, partialTicks, mouseWheel); - if (hovered && this.hoverText != null && this.hoverText.length > 0) { - this.parent.hoverText = this.hoverText; - } + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + GL11.glTranslatef(0.0F, 0.0F, (float)this.id); + boolean hovered = mouseX >= this.guiLeft && mouseY >= this.guiTop && mouseX < this.guiLeft + this.xSize && mouseY < this.guiTop + this.ySize; + super.drawScreen(mouseX, mouseY, partialTicks, mouseWheel); + if (hovered && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } GL11.glPopMatrix(); } @@ -79,11 +86,15 @@ public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHo this.hoverText = component.getHoverText(); } + this.color = component.getColor(); + this.alpha = component.getAlpha(); } public ICustomGuiComponent toComponent() { ScriptGuiScroll component = new ScriptGuiScroll(this.id, this.guiLeft - GuiCustom.guiLeft, this.guiTop - GuiCustom.guiTop, this.width, this.height, (String[])this.getList().toArray(new String[0])); component.setHoverText(this.hoverText); + component.setColor(color); + component.setAlpha(alpha); return component; } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java index 0e0c1eb73..876eccd41 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java @@ -16,12 +16,16 @@ import noppes.npcs.client.gui.custom.interfaces.IKeyListener; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.scripted.gui.ScriptGuiTextField; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; public class CustomGuiTextField extends GuiTextField implements IKeyListener, IDataHolder, IClickListener { GuiCustom parent; String[] hoverText; int id; + int color; + float alpha; + public CustomGuiTextField(int id, int x, int y, int width, int height) { super(Minecraft.getMinecraft().fontRenderer, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height); this.id = id; @@ -34,7 +38,12 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { boolean hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); this.drawTextBox(); + GL11.glColor4f(1.0F,1.0F,1.0F,1.0F); if (hovered && this.hoverText != null && this.hoverText.length > 0) { this.parent.hoverText = this.hoverText; } @@ -59,6 +68,8 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID ScriptGuiTextField component = new ScriptGuiTextField(this.id, this.xPosition - GuiCustom.guiLeft, this.yPosition - GuiCustom.guiTop, this.width, this.height); component.setText(this.getText()); component.setHoverText(this.hoverText); + component.setColor(color); + component.setAlpha(alpha); return component; } @@ -72,6 +83,9 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID txt.setText(component.getText()); } + txt.color = component.getColor(); + txt.alpha = component.getAlpha(); + return txt; } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index 992e024ca..0f480771c 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -15,6 +15,9 @@ import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; + public class CustomGuiTexturedRect extends Gui implements IGuiComponent { GuiCustom parent; ResourceLocation texture; @@ -28,6 +31,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { float scale; String[] hoverText; + int color; + float alpha; + public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) { this(id, texture, x, y, width, height, 0, 0); } @@ -57,7 +63,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { mc.getTextureManager().bindTexture(this.texture); GL11.glPushMatrix(); - GL11.glColor4f(1.0F,1.0F,1.0F,1.0F); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + GL11.glScalef(this.scale, this.scale, this.scale); this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); GL11.glPopMatrix(); @@ -71,6 +81,8 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); component.setHoverText(this.hoverText); component.setScale(this.scale); + component.setColor(color); + component.setAlpha(alpha); return component; } @@ -87,6 +99,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { rect.hoverText = component.getHoverText(); } + rect.color = component.getColor(); + rect.alpha = component.getAlpha(); + return rect; } } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 0d74aeaf9..c6302e318 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -13,6 +13,9 @@ import org.lwjgl.opengl.GL11; import java.util.ArrayList; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; + public class CustomOverlayLabel extends Gui implements IOverlayComponent { OverlayCustom parent; int alignment; @@ -70,13 +73,13 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { } public static CustomOverlayLabel fromComponent(ScriptOverlayLabel component) { - CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow()); + CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); lbl.field_146172_j = true; lbl.setScale(component.getScale()); - lbl.labelShadowEnabled = component.hasShadow(); + lbl.labelShadowEnabled = component.getShadow(); lbl.alignment = component.getAlignment(); lbl.alpha = component.getAlpha(); lbl.color = component.getColor(); @@ -86,7 +89,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { public ICustomOverlayComponent toComponent() { ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); - component.enableShadow(this.labelShadowEnabled); + component.setShadow(this.labelShadowEnabled); component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java index 8bac43c13..2c06ef275 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -2,6 +2,7 @@ package noppes.npcs.client.gui.customoverlay.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; @@ -9,6 +10,9 @@ import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayLine; import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; + public class CustomOverlayLine extends Gui implements IOverlayComponent { OverlayCustom parent; int alignment; 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 9d5917d94..323552240 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 @@ -2,6 +2,7 @@ package noppes.npcs.client.gui.customoverlay.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; @@ -9,6 +10,9 @@ import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; import org.lwjgl.opengl.GL11; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; + public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent { OverlayCustom parent; int alignment; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java index 4ae43e774..68158b762 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java @@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; public abstract class ScriptGuiComponent implements ICustomGuiComponent { int id; @@ -11,6 +12,9 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent { int posY; String[] hoverText; + int color = 0xFFFFFF; + float alpha = 1.0F; + public ScriptGuiComponent() { } @@ -55,11 +59,30 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent { return this; } + public int getColor() { + return this.color; + } + + public ICustomGuiComponent setColor(int color) { + this.color = color; + return this; + } + + public float getAlpha() { + return this.alpha; + } + + public void setAlpha(float alpha) { + this.alpha = alpha; + } + public abstract int getType(); public NBTTagCompound toNBT(NBTTagCompound nbt) { nbt.setInteger("id", this.id); nbt.setIntArray("pos", new int[]{this.posX, this.posY}); + nbt.setInteger("color", this.color); + nbt.setFloat("alpha",this.alpha); if (this.hoverText != null) { NBTTagList list = new NBTTagList(); String[] var3 = this.hoverText; @@ -84,6 +107,8 @@ public abstract class ScriptGuiComponent implements ICustomGuiComponent { public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { this.setID(nbt.getInteger("id")); this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); + this.setColor(nbt.getInteger("color")); + this.setAlpha(nbt.getFloat("alpha")); if (nbt.hasKey("hover")) { NBTTagList list = nbt.getTagList("hover", 8); String[] hoverText = new String[list.tagCount()]; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java index c4e36ec20..bba1444d2 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java @@ -7,17 +7,14 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { String label; int width; int height; - int color; float scale; boolean shadow; public ScriptGuiLabel() { - this.color = 16777215; this.scale = 1.0F; } public ScriptGuiLabel(int id, String label, int x, int y, int width, int height) { - this.color = 16777215; this.scale = 1.0F; this.setID(id); this.setText(label); @@ -54,15 +51,6 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { return this; } - public int getColor() { - return this.color; - } - - public ILabel setColor(int color) { - this.color = color; - return this; - } - public float getScale() { return this.scale; } @@ -88,7 +76,6 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { super.toNBT(nbt); nbt.setString("label", this.label); nbt.setIntArray("size", new int[]{this.width, this.height}); - nbt.setInteger("color", this.color); nbt.setFloat("scale", this.scale); nbt.setBoolean("shadow",this.shadow); return nbt; @@ -98,7 +85,6 @@ public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { super.fromNBT(nbt); this.setText(nbt.getString("label")); this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); - this.setColor(nbt.getInteger("color")); this.setScale(nbt.getFloat("scale")); this.enableShadow(nbt.getBoolean("shadow")); return this; diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java index 69c72a711..c59a425c0 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLine.java @@ -8,7 +8,6 @@ public class ScriptGuiLine extends ScriptGuiComponent implements ILine { int y1; int x2; int y2; - int color = 0; int thickness = 2; public ScriptGuiLine(){ @@ -49,7 +48,6 @@ public class ScriptGuiLine extends ScriptGuiComponent implements ILine { nbt.setInteger("Y1",y1); nbt.setInteger("X2",x2); nbt.setInteger("Y2",y2); - nbt.setInteger("Color",color); nbt.setInteger("Thickness",thickness); return nbt; @@ -61,7 +59,6 @@ public class ScriptGuiLine extends ScriptGuiComponent implements ILine { y1 = nbt.getInteger("Y1"); x2 = nbt.getInteger("X2"); y2 = nbt.getInteger("Y2"); - color = nbt.getInteger("Color"); thickness = nbt.getInteger("Thickness"); return this; @@ -79,9 +76,6 @@ public class ScriptGuiLine extends ScriptGuiComponent implements ILine { public int getY2(){ return this.y2; } - public int getColor(){ - return this.color; - } public int getThickness(){ return this.thickness; } @@ -98,9 +92,6 @@ public class ScriptGuiLine extends ScriptGuiComponent implements ILine { public void setY2(int y2){ this.y2 = y2; } - public void setColor(int color){ - this.color = color; - } public void setThickness(int thickness){ this.thickness = thickness; } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java b/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java index 6e3b00e99..30a09704f 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java @@ -16,10 +16,6 @@ public interface ILabel extends ICustomGuiComponent { ILabel setSize(int var1, int var2); - int getColor(); - - ILabel setColor(int var1); - float getScale(); ILabel setScale(float var1); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ILine.java b/src/main/java/noppes/npcs/scripted/interfaces/ILine.java index b1a6690b0..2ea987d5c 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ILine.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ILine.java @@ -5,13 +5,11 @@ public interface ILine extends ICustomGuiComponent { int getY1(); int getX2(); int getY2(); - int getColor(); int getThickness(); void setX1(int x1); void setY1(int y1); void setX2(int x2); void setY2(int y2); - void setColor(int color); void setThickness(int thickness); } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java index 10891007f..edbcab83d 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -92,7 +92,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); this.setAlignment(nbt.getInteger("alignment")); this.setColor(nbt.getInteger("color")); - this.setAlpha(nbt.getInteger("alpha")); + this.setAlpha(nbt.getFloat("alpha")); return this; } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java index 2394e0a72..3e2e041ad 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -24,7 +24,7 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.setText(label); this.setPos(x, y); this.setSize(width, height); - this.enableShadow(false); + this.setShadow(false); } public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height, int color) { @@ -64,11 +64,11 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl return this; } - public boolean hasShadow(){ + public boolean getShadow(){ return this.shadow; } - public void enableShadow(boolean shadow){ + public void setShadow(boolean shadow){ this.shadow = shadow; } @@ -91,7 +91,7 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.setText(nbt.getString("label")); this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); this.setScale(nbt.getFloat("scale")); - this.enableShadow(nbt.getBoolean("shadow")); + this.setShadow(nbt.getBoolean("shadow")); return this; } } From 966ab4bf729b99a2ab41ed26be4c81e5e4fa581e Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 13:29:00 -0600 Subject: [PATCH 10/15] Custom Overlays and GUIs now properly set alpha values for some components. --- .../npcs/client/ClientEventHandler.java | 18 ++++++++++--- .../npcs/client/gui/custom/GuiCustom.java | 6 +++++ .../gui/customoverlay/OverlayCustom.java | 27 +++++-------------- .../components/CustomOverlayLabel.java | 8 ++---- .../components/CustomOverlayLine.java | 22 +++++++++++++-- .../components/CustomOverlayTexturedRect.java | 26 +++++++++++++++--- 6 files changed, 71 insertions(+), 36 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 6c1bbc382..331b0de66 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -1,14 +1,26 @@ package noppes.npcs.client; import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraftforge.client.event.RenderGameOverlayEvent; import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import org.lwjgl.opengl.GL11; public class ClientEventHandler { @SubscribeEvent - public void onOverlayRender(RenderGameOverlayEvent.Pre event){ - for(OverlayCustom overlayCustom : Client.customOverlays.values()){ - overlayCustom.renderGameOverlay(event.partialTicks); + public void onOverlayRender(RenderGameOverlayEvent.Post event){ + if(event.type == RenderGameOverlayEvent.ElementType.ALL) { + 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); + + for (OverlayCustom overlayCustom : Client.customOverlays.values()) { + overlayCustom.renderGameOverlay(event.partialTicks); + } + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 23a6d6e57..4e66719c8 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -129,10 +129,16 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD Iterator var4 = this.components.values().iterator(); + 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); while(var4.hasNext()) { IGuiComponent component = (IGuiComponent)var4.next(); component.onRender(this.mc, mouseX, mouseY, Mouse.getDWheel(), partialTicks); } + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); if (this.hoverText != null) { this.func_146283_a(Arrays.asList(this.hoverText), mouseX, mouseY); diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java index 9c4d17fb5..df6c1a1c0 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java @@ -3,6 +3,7 @@ package noppes.npcs.client.gui.customoverlay; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLabel; @@ -27,14 +28,6 @@ public class OverlayCustom extends Gui { public ScriptOverlay overlay; Map components = new HashMap(); - float scale = 1.0F; - int x = 0; - int y = 0; - int textureX = 0; - int textureY = 0; - int width = 200; - int height = 200; - public OverlayCustom(Minecraft mc) { this.mc = mc; } @@ -81,20 +74,12 @@ public class OverlayCustom extends Gui { scaledWidth = res.getScaledWidth(); scaledHeight = res.getScaledHeight(); - GL11.glPushMatrix(); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_BLEND); + Iterator var4 = this.components.values().iterator(); - Iterator var4 = this.components.values().iterator(); - - while(var4.hasNext()) { - IOverlayComponent component = (IOverlayComponent)var4.next(); - component.onRender(this.mc, partialTicks); - } - - GL11.glEnable(GL11.GL_BLEND); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPopMatrix(); + while(var4.hasNext()) { + IOverlayComponent component = (IOverlayComponent)var4.next(); + component.onRender(this.mc, partialTicks); + } } public void setOverlayData(NBTTagCompound compound) { diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index c6302e318..2e871af64 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -100,19 +100,15 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { { if (this.field_146172_j) { - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(770, 771, 1, 0); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - this.drawLabelBackground(); GL11.glPushMatrix(); + 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 + float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; 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);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 - GL11.glTranslatef(this.x,this.y,0.0F); GL11.glScalef(this.scale, this.scale, this.scale); Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java index 2c06ef275..eef06f3ff 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -3,6 +3,7 @@ package noppes.npcs.client.gui.customoverlay.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; @@ -52,14 +53,31 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; 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);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 GL11.glTranslatef(this.x1,this.y1,0.0F); GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); GL11.glScaled(thickness, distance,0.0D); - this.drawTexturedModalRect(0,0,0,0, 1, 1); + + int p_73729_1_ = 0; + int p_73729_2_ = 0; + int p_73729_3_ = 0; + int p_73729_4_ = 0; + int p_73729_5_ = 1; + int p_73729_6_ = 1; + + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_F(1, 1, 1); + tessellator.setColorRGBA_F(red, green, blue, alpha); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); GL11.glPopMatrix(); } 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 323552240..8447964b5 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 @@ -3,6 +3,7 @@ package noppes.npcs.client.gui.customoverlay.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; @@ -10,8 +11,8 @@ import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; import org.lwjgl.opengl.GL11; -import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; -import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL14.glBlendFuncSeparate; public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent { OverlayCustom parent; @@ -62,12 +63,29 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent float red = (color >> 16 & 255) / 255f; float green = (color >> 8 & 255) / 255f; 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);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 GL11.glScalef(this.scale, this.scale, this.scale); - this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); + + int p_73729_1_ = (int) (this.x/this.scale); + int p_73729_2_ = (int) (this.y/this.scale); + int p_73729_3_ = this.textureX; + int p_73729_4_ = this.textureY; + int p_73729_5_ = (int)(this.width); + int p_73729_6_ = (int)(this.height); + + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_F(1, 1, 1); + tessellator.setColorRGBA_F(red, green, blue, alpha); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); GL11.glPopMatrix(); } From e7a19264b2866a627778121eafcfe00d8b98e339 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 14:22:29 -0600 Subject: [PATCH 11/15] Added alpha and style options for overlay labels. --- .../components/CustomOverlayLabel.java | 442 +++++++++++++++++- .../scripted/overlay/ScriptOverlayLabel.java | 50 ++ 2 files changed, 486 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 2e871af64..05b2403c3 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -1,9 +1,14 @@ package noppes.npcs.client.gui.customoverlay.components; +import com.ibm.icu.text.ArabicShaping; +import com.ibm.icu.text.ArabicShapingException; +import com.ibm.icu.text.Bidi; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; @@ -11,6 +16,10 @@ import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayLabel; import org.lwjgl.opengl.GL11; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; @@ -46,7 +55,34 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { private FontRenderer field_146164_r; private int field_146163_s; + private boolean randomStyle = false; + private boolean boldStyle = false; + private boolean italicStyle = false; + private boolean underlineStyle = false; + private boolean strikethroughStyle = false; + private boolean bidiFlag = false; + private boolean unicodeFlag = false; + + private static final ResourceLocation[] unicodePageLocations = new ResourceLocation[256]; + protected final ResourceLocation locationFontTexture; + protected int[] charWidth = new int[256]; + protected byte[] glyphWidth = new byte[65536]; + + + private float red; + private float green; + private float blue; + private int[] colorCode = new int[32]; + private int textColor; + + private float posX; + private float posY; + public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -84,6 +120,12 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { lbl.alpha = component.getAlpha(); lbl.color = component.getColor(); + lbl.strikethroughStyle = component.getStrikethroughStyle(); + lbl.boldStyle = component.getBoldStyle(); + lbl.italicStyle = component.getItalicStyle(); + lbl.randomStyle = component.getRandomStyle(); + lbl.underlineStyle = component.getUnderlineStyle(); + return lbl; } @@ -93,6 +135,12 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); + + component.setStrikethroughStyle(strikethroughStyle); + component.setBoldStyle(boldStyle); + component.setItalicStyle(italicStyle); + component.setRandomStyle(randomStyle); + component.setUnderlineStyle(underlineStyle); return component; } @@ -100,18 +148,17 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { { if (this.field_146172_j) { - this.drawLabelBackground(); + //this.drawLabelBackground(); GL11.glPushMatrix(); 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 - float red = (color >> 16 & 255) / 255f; - float green = (color >> 8 & 255) / 255f; - float blue = (color & 255) / 255f; - GL11.glColor4f(red,green,blue,this.alpha); + red = (color >> 16 & 255) / 255f; + green = (color >> 8 & 255) / 255f; + blue = (color & 255) / 255f; GL11.glTranslatef(this.x,this.y,0.0F); GL11.glScalef(this.scale, this.scale, this.scale); - Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); GL11.glPopMatrix(); } } @@ -131,4 +178,387 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor } } + + public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) + { + int l; + + if (p_85187_5_) + { + l = this.renderString(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true); + l = Math.max(l, this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false)); + } + else + { + l = this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false); + } + + return l; + } + + private void resetStyles() + { + this.randomStyle = false; + this.boldStyle = false; + this.italicStyle = false; + this.underlineStyle = false; + this.strikethroughStyle = false; + } + + private int renderString(String p_78258_1_, int p_78258_2_, int p_78258_3_, int p_78258_4_, boolean p_78258_5_) + { + if (p_78258_1_ == null) + { + return 0; + } + else + { + if (this.bidiFlag) + { + p_78258_1_ = this.bidiReorder(p_78258_1_); + } + + setColor(this.red, this.green, this.blue, this.alpha); + this.posX = (float)p_78258_2_; + this.posY = (float)p_78258_3_; + this.renderStringAtPos(p_78258_1_, p_78258_5_); + return (int)this.posX; + } + } + + private void renderStringAtPos(String p_78255_1_, boolean p_78255_2_) + { + for (int i = 0; i < p_78255_1_.length(); ++i) + { + char c0 = p_78255_1_.charAt(i); + int j; + int k; + + if (c0 == 167 && i + 1 < p_78255_1_.length()) + { + j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); + + if (j < 16) + { + if (j < 0 || j > 15) + { + j = 15; + } + + if (p_78255_2_) + { + j += 16; + } + + k = this.colorCode[j]; + this.textColor = k; + setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); + } + else if (j == 16) + { + this.randomStyle = true; + } + else if (j == 17) + { + this.boldStyle = true; + } + else if (j == 18) + { + this.strikethroughStyle = true; + } + else if (j == 19) + { + this.underlineStyle = true; + } + else if (j == 20) + { + this.italicStyle = true; + } + else if (j == 21) + { + setColor(this.red, this.green, this.blue, this.alpha); + } + + ++i; + } + else + { + j = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(c0); + + if (this.randomStyle && j != -1) + { + do + { + k = Minecraft.getMinecraft().fontRenderer.fontRandom.nextInt(this.charWidth.length); + } + while (this.charWidth[j] != this.charWidth[k]); + + j = k; + } + + float f1 = this.unicodeFlag ? 0.5F : 1.0F; + boolean flag1 = (c0 == 0 || j == -1 || this.unicodeFlag) && p_78255_2_; + + if (flag1) + { + this.posX -= f1; + this.posY -= f1; + } + + float f = this.renderCharAtPos(j, c0, this.italicStyle); + + if (flag1) + { + this.posX += f1; + this.posY += f1; + } + + if (this.boldStyle) + { + this.posX += f1; + + if (flag1) + { + this.posX -= f1; + this.posY -= f1; + } + + this.renderCharAtPos(j, c0, this.italicStyle); + this.posX -= f1; + + if (flag1) + { + this.posX += f1; + this.posY += f1; + } + + ++f; + } + + doDraw(f); + } + } + } + + protected void doDraw(float f) + { + { + { + Tessellator tessellator; + + if (this.strikethroughStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + if (this.underlineStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + int l = this.underlineStyle ? -1 : 0; + tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + this.posX += (float)((int)f); + } + } + } + + private float renderCharAtPos(int p_78278_1_, char p_78278_2_, boolean p_78278_3_) + { + return p_78278_2_ == 32 ? 4.0F : ("\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(p_78278_2_) != -1 && !this.unicodeFlag ? this.renderDefaultChar(p_78278_1_, p_78278_3_) : this.renderUnicodeChar(p_78278_2_, p_78278_3_)); + } + + protected float renderDefaultChar(int p_78266_1_, boolean p_78266_2_) + { + float f = (float)(p_78266_1_ % 16 * 8); + float f1 = (float)(p_78266_1_ / 16 * 8); + float f2 = p_78266_2_ ? 1.0F : 0.0F; + bindTexture(this.locationFontTexture); + float f3 = (float)this.charWidth[p_78266_1_] - 0.01F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f2, this.posY, 0.0F); + GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (float)this.charWidth[p_78266_1_]; + } + + private ResourceLocation getUnicodePageLocation(int p_111271_1_) + { + if (unicodePageLocations[p_111271_1_] == null) + { + unicodePageLocations[p_111271_1_] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] {Integer.valueOf(p_111271_1_)})); + } + + return unicodePageLocations[p_111271_1_]; + } + + private void loadGlyphTexture(int p_78257_1_) + { + bindTexture(this.getUnicodePageLocation(p_78257_1_)); + } + + /** + * Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files... + */ + protected float renderUnicodeChar(char p_78277_1_, boolean p_78277_2_) + { + if (this.glyphWidth[p_78277_1_] == 0) + { + return 0.0F; + } + else + { + int i = p_78277_1_ / 256; + this.loadGlyphTexture(i); + int j = this.glyphWidth[p_78277_1_] >>> 4; + int k = this.glyphWidth[p_78277_1_] & 15; + float f = (float)j; + float f1 = (float)(k + 1); + float f2 = (float)(p_78277_1_ % 16 * 16) + f; + float f3 = (float)((p_78277_1_ & 255) / 16 * 16); + float f4 = f1 - f - 0.02F; + float f5 = p_78277_2_ ? 1.0F : 0.0F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f5, this.posY, 0.0F); + GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (f1 - f) / 2.0F + 1.0F; + } + } + + protected void setColor(float r, float g, float b, float a) + { + GL11.glColor4f(r, g, b, alpha); + } + + protected void bindTexture(ResourceLocation location) + { + Minecraft.getMinecraft().renderEngine.bindTexture(location); + } + + private void readFontTexture() + { + BufferedImage bufferedimage; + + try + { + bufferedimage = ImageIO.read(getResourceInputStream(this.locationFontTexture)); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + + int i = bufferedimage.getWidth(); + int j = bufferedimage.getHeight(); + int[] aint = new int[i * j]; + bufferedimage.getRGB(0, 0, i, j, aint, 0, i); + int k = j / 16; + int l = i / 16; + byte b0 = 1; + float f = 8.0F / (float)l; + int i1 = 0; + + while (i1 < 256) + { + int j1 = i1 % 16; + int k1 = i1 / 16; + + if (i1 == 32) + { + this.charWidth[i1] = 3 + b0; + } + + int l1 = l - 1; + + while (true) + { + if (l1 >= 0) + { + int i2 = j1 * l + l1; + boolean flag = true; + + for (int j2 = 0; j2 < k && flag; ++j2) + { + int k2 = (k1 * l + j2) * i; + + if ((aint[i2 + k2] >> 24 & 255) != 0) + { + flag = false; + } + } + + if (flag) + { + --l1; + continue; + } + } + + ++l1; + this.charWidth[i1] = (int)(0.5D + (double)((float)l1 * f)) + b0; + ++i1; + break; + } + } + } + + private void readGlyphSizes() + { + try + { + InputStream inputstream = getResourceInputStream(new ResourceLocation("font/glyph_sizes.bin")); + inputstream.read(this.glyphWidth); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + } + + protected InputStream getResourceInputStream(ResourceLocation location) throws IOException + { + return Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); + } + + private String bidiReorder(String p_147647_1_) + { + try + { + Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127); + bidi.setReorderingMode(0); + return bidi.writeReordered(2); + } + catch (ArabicShapingException arabicshapingexception) + { + return p_147647_1_; + } + } } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java index 3e2e041ad..16f6d31b8 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -12,6 +12,12 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl float scale; boolean shadow; + boolean randomStyle = false; + boolean boldStyle = false; + boolean italicStyle = false; + boolean underlineStyle = false; + boolean strikethroughStyle = false; + public ScriptOverlayLabel() { this.color = 16777215; this.scale = 1.0F; @@ -72,6 +78,38 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.shadow = shadow; } + public void setRandomStyle(boolean randomStyle){ + this.randomStyle = randomStyle; + } + public void setUnderlineStyle(boolean underlineStyle){ + this.underlineStyle = underlineStyle; + } + public void setBoldStyle(boolean boldStyle){ + this.boldStyle = boldStyle; + } + public void setItalicStyle(boolean italicStyle){ + this.italicStyle = italicStyle; + } + public void setStrikethroughStyle(boolean strikethroughStyle){ + this.strikethroughStyle = strikethroughStyle; + } + + public boolean getRandomStyle(){ + return this.randomStyle; + } + public boolean getUnderlineStyle(){ + return this.underlineStyle; + } + public boolean getBoldStyle(){ + return this.boldStyle; + } + public boolean getItalicStyle(){ + return this.italicStyle; + } + public boolean getStrikethroughStyle(){ + return this.strikethroughStyle; + } + @Override public int getType() { return 1; @@ -83,6 +121,12 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl nbt.setIntArray("size", new int[]{this.width, this.height}); nbt.setFloat("scale", this.scale); nbt.setBoolean("shadow",this.shadow); + + nbt.setBoolean("strikethrough",this.strikethroughStyle); + nbt.setBoolean("bold",this.boldStyle); + nbt.setBoolean("italic",this.italicStyle); + nbt.setBoolean("random",this.randomStyle); + nbt.setBoolean("underline",this.underlineStyle); return nbt; } @@ -92,6 +136,12 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); this.setScale(nbt.getFloat("scale")); this.setShadow(nbt.getBoolean("shadow")); + + this.setStrikethroughStyle(nbt.getBoolean("strikethrough")); + this.setBoldStyle(nbt.getBoolean("bold")); + this.setItalicStyle(nbt.getBoolean("italic")); + this.setRandomStyle(nbt.getBoolean("random")); + this.setUnderlineStyle(nbt.getBoolean("underline")); return this; } } From da3b04e78e664a351a2f22ec2b374bbe14dfdd0d Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 22:41:55 -0600 Subject: [PATCH 12/15] Implemented MC chat formatting for color codes: &l, &m, &r, &o, and &k all affect overlay labels. --- .../components/CustomOverlayLabel.java | 48 +++--------------- .../scripted/overlay/ScriptOverlayLabel.java | 50 ------------------- 2 files changed, 8 insertions(+), 90 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 05b2403c3..363bc4f52 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -34,7 +34,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { String fullLabel; int color; float alpha; - String[] hoverText; float scale; int border = 2; boolean labelBgEnabled = true; @@ -44,16 +43,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected int field_146161_f; public int field_146162_g; public int field_146174_h; - private ArrayList field_146173_k; - private boolean field_146170_l; public boolean field_146172_j; - private boolean field_146171_m; - private int field_146168_n; - private int field_146169_o; - private int field_146166_p; - private int field_146165_q; - private FontRenderer field_146164_r; - private int field_146163_s; private boolean randomStyle = false; private boolean boldStyle = false; @@ -120,12 +110,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { lbl.alpha = component.getAlpha(); lbl.color = component.getColor(); - lbl.strikethroughStyle = component.getStrikethroughStyle(); - lbl.boldStyle = component.getBoldStyle(); - lbl.italicStyle = component.getItalicStyle(); - lbl.randomStyle = component.getRandomStyle(); - lbl.underlineStyle = component.getUnderlineStyle(); - return lbl; } @@ -136,11 +120,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { component.setAlpha(alpha); component.setColor(color); - component.setStrikethroughStyle(strikethroughStyle); - component.setBoldStyle(boldStyle); - component.setItalicStyle(italicStyle); - component.setRandomStyle(randomStyle); - component.setUnderlineStyle(underlineStyle); return component; } @@ -181,6 +160,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) { + this.resetStyles(); int l; if (p_85187_5_) @@ -234,27 +214,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { int j; int k; - if (c0 == 167 && i + 1 < p_78255_1_.length()) + if (c0 == 38 && i + 1 < p_78255_1_.length()) { j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - if (j < 16) - { - if (j < 0 || j > 15) - { - j = 15; - } - - if (p_78255_2_) - { - j += 16; - } - - k = this.colorCode[j]; - this.textColor = k; - setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); - } - else if (j == 16) + if (j == 16) { this.randomStyle = true; } @@ -276,7 +240,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { } else if (j == 21) { - setColor(this.red, this.green, this.blue, this.alpha); + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; } ++i; diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java index 16f6d31b8..3e2e041ad 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -12,12 +12,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl float scale; boolean shadow; - boolean randomStyle = false; - boolean boldStyle = false; - boolean italicStyle = false; - boolean underlineStyle = false; - boolean strikethroughStyle = false; - public ScriptOverlayLabel() { this.color = 16777215; this.scale = 1.0F; @@ -78,38 +72,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.shadow = shadow; } - public void setRandomStyle(boolean randomStyle){ - this.randomStyle = randomStyle; - } - public void setUnderlineStyle(boolean underlineStyle){ - this.underlineStyle = underlineStyle; - } - public void setBoldStyle(boolean boldStyle){ - this.boldStyle = boldStyle; - } - public void setItalicStyle(boolean italicStyle){ - this.italicStyle = italicStyle; - } - public void setStrikethroughStyle(boolean strikethroughStyle){ - this.strikethroughStyle = strikethroughStyle; - } - - public boolean getRandomStyle(){ - return this.randomStyle; - } - public boolean getUnderlineStyle(){ - return this.underlineStyle; - } - public boolean getBoldStyle(){ - return this.boldStyle; - } - public boolean getItalicStyle(){ - return this.italicStyle; - } - public boolean getStrikethroughStyle(){ - return this.strikethroughStyle; - } - @Override public int getType() { return 1; @@ -121,12 +83,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl nbt.setIntArray("size", new int[]{this.width, this.height}); nbt.setFloat("scale", this.scale); nbt.setBoolean("shadow",this.shadow); - - nbt.setBoolean("strikethrough",this.strikethroughStyle); - nbt.setBoolean("bold",this.boldStyle); - nbt.setBoolean("italic",this.italicStyle); - nbt.setBoolean("random",this.randomStyle); - nbt.setBoolean("underline",this.underlineStyle); return nbt; } @@ -136,12 +92,6 @@ public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverl this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); this.setScale(nbt.getFloat("scale")); this.setShadow(nbt.getBoolean("shadow")); - - this.setStrikethroughStyle(nbt.getBoolean("strikethrough")); - this.setBoldStyle(nbt.getBoolean("bold")); - this.setItalicStyle(nbt.getBoolean("italic")); - this.setRandomStyle(nbt.getBoolean("random")); - this.setUnderlineStyle(nbt.getBoolean("underline")); return this; } } From 54fadbe63f2d89914eaba300b83946f4cce0edcc Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 22:49:03 -0600 Subject: [PATCH 13/15] Implemented label, alpha, and formatting for Custom GUI labels. --- .../gui/custom/components/CustomGuiLabel.java | 428 +++++++++++++++++- .../components/CustomOverlayLabel.java | 4 +- 2 files changed, 411 insertions(+), 21 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index aab12ed58..caa3a69d4 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -5,17 +5,26 @@ package noppes.npcs.client.gui.custom.components; +import com.ibm.icu.text.ArabicShaping; +import com.ibm.icu.text.ArabicShapingException; +import com.ibm.icu.text.Bidi; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiLabel; import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; import noppes.npcs.scripted.gui.ScriptGuiLabel; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; public class CustomGuiLabel extends Gui implements IGuiComponent { @@ -36,18 +45,34 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected int field_146161_f; public int field_146162_g; public int field_146174_h; - private ArrayList field_146173_k; - private boolean field_146170_l; public boolean field_146172_j; - private boolean field_146171_m; - private int field_146168_n; - private int field_146169_o; - private int field_146166_p; - private int field_146165_q; - private FontRenderer field_146164_r; - private int field_146163_s; + + private boolean randomStyle = false; + private boolean boldStyle = false; + private boolean italicStyle = false; + private boolean underlineStyle = false; + private boolean strikethroughStyle = false; + private boolean bidiFlag = false; + private boolean unicodeFlag = false; + + private static final ResourceLocation[] unicodePageLocations = new ResourceLocation[256]; + protected final ResourceLocation locationFontTexture; + protected int[] charWidth = new int[256]; + protected byte[] glyphWidth = new byte[65536]; + + + private float red; + private float green; + private float blue; + + private float posX; + private float posY; public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -106,20 +131,15 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { { if (this.field_146172_j) { - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(770, 771, 1, 0); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - this.drawLabelBackground(); GL11.glPushMatrix(); - float red = (color >> 16 & 255) / 255f; - float green = (color >> 8 & 255) / 255f; - float blue = (color & 255) / 255f; - GL11.glColor4f(red,green,blue,this.alpha); + red = (color >> 16 & 255) / 255f; + green = (color >> 8 & 255) / 255f; + blue = (color & 255) / 255f; GL11.glTranslatef(this.x,this.y,0.0F); GL11.glScalef(this.scale, this.scale, this.scale); - Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); GL11.glPopMatrix(); } } @@ -139,4 +159,376 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor } } + + public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) + { + this.resetStyles(); + int l; + + if (p_85187_5_) + { + l = this.renderString(p_85187_1_, p_85187_2_ + 1, p_85187_3_ + 1, p_85187_4_, true); + l = Math.max(l, this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false)); + } + else + { + l = this.renderString(p_85187_1_, p_85187_2_, p_85187_3_, p_85187_4_, false); + } + + return l; + } + + private void resetStyles() + { + this.randomStyle = false; + this.boldStyle = false; + this.italicStyle = false; + this.underlineStyle = false; + this.strikethroughStyle = false; + } + + private int renderString(String p_78258_1_, int p_78258_2_, int p_78258_3_, int p_78258_4_, boolean p_78258_5_) + { + if (p_78258_1_ == null) + { + return 0; + } + else + { + if (this.bidiFlag) + { + p_78258_1_ = this.bidiReorder(p_78258_1_); + } + + setColor(this.red, this.green, this.blue, this.alpha); + this.posX = (float)p_78258_2_; + this.posY = (float)p_78258_3_; + this.renderStringAtPos(p_78258_1_, p_78258_5_); + return (int)this.posX; + } + } + + private void renderStringAtPos(String p_78255_1_, boolean p_78255_2_) + { + for (int i = 0; i < p_78255_1_.length(); ++i) + { + char c0 = p_78255_1_.charAt(i); + int j; + int k; + + if (c0 == 38 && i + 1 < p_78255_1_.length()) + { + j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); + + if (j == 16) + { + this.randomStyle = true; + } + else if (j == 17) + { + this.boldStyle = true; + } + else if (j == 18) + { + this.strikethroughStyle = true; + } + else if (j == 19) + { + this.underlineStyle = true; + } + else if (j == 20) + { + this.italicStyle = true; + } + else if (j == 21) + { + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + } + + ++i; + } + else + { + j = "\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(c0); + + if (this.randomStyle && j != -1) + { + do + { + k = Minecraft.getMinecraft().fontRenderer.fontRandom.nextInt(this.charWidth.length); + } + while (this.charWidth[j] != this.charWidth[k]); + + j = k; + } + + float f1 = this.unicodeFlag ? 0.5F : 1.0F; + boolean flag1 = (c0 == 0 || j == -1 || this.unicodeFlag) && p_78255_2_; + + if (flag1) + { + this.posX -= f1; + this.posY -= f1; + } + + float f = this.renderCharAtPos(j, c0, this.italicStyle); + + if (flag1) + { + this.posX += f1; + this.posY += f1; + } + + if (this.boldStyle) + { + this.posX += f1; + + if (flag1) + { + this.posX -= f1; + this.posY -= f1; + } + + this.renderCharAtPos(j, c0, this.italicStyle); + this.posX -= f1; + + if (flag1) + { + this.posX += f1; + this.posY += f1; + } + + ++f; + } + + doDraw(f); + } + } + } + + protected void doDraw(float f) + { + { + { + Tessellator tessellator; + + if (this.strikethroughStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2)), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.addVertex((double)this.posX, (double)(this.posY + (float)(Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT / 2) - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + if (this.underlineStyle) + { + tessellator = Tessellator.instance; + GL11.glDisable(GL11.GL_TEXTURE_2D); + tessellator.startDrawingQuads(); + int l = this.underlineStyle ? -1 : 0; + tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT), 0.0D); + tessellator.addVertex((double)(this.posX + f), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.addVertex((double)(this.posX + (float)l), (double)(this.posY + (float)Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 1.0F), 0.0D); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + } + + this.posX += (float)((int)f); + } + } + } + + private float renderCharAtPos(int p_78278_1_, char p_78278_2_, boolean p_78278_3_) + { + return p_78278_2_ == 32 ? 4.0F : ("\u00c0\u00c1\u00c2\u00c8\u00ca\u00cb\u00cd\u00d3\u00d4\u00d5\u00da\u00df\u00e3\u00f5\u011f\u0130\u0131\u0152\u0153\u015e\u015f\u0174\u0175\u017e\u0207\u0000\u0000\u0000\u0000\u0000\u0000\u0000 !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u0000\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u03b2\u0393\u03c0\u03a3\u03c3\u03bc\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u2205\u2208\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0\u0000".indexOf(p_78278_2_) != -1 && !this.unicodeFlag ? this.renderDefaultChar(p_78278_1_, p_78278_3_) : this.renderUnicodeChar(p_78278_2_, p_78278_3_)); + } + + protected float renderDefaultChar(int p_78266_1_, boolean p_78266_2_) + { + float f = (float)(p_78266_1_ % 16 * 8); + float f1 = (float)(p_78266_1_ / 16 * 8); + float f2 = p_78266_2_ ? 1.0F : 0.0F; + bindTexture(this.locationFontTexture); + float f3 = (float)this.charWidth[p_78266_1_] - 0.01F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f2, this.posY, 0.0F); + GL11.glTexCoord2f(f / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX - f2, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, f1 / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F + f2, this.posY, 0.0F); + GL11.glTexCoord2f((f + f3 - 1.0F) / 128.0F, (f1 + 7.99F) / 128.0F); + GL11.glVertex3f(this.posX + f3 - 1.0F - f2, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (float)this.charWidth[p_78266_1_]; + } + + private ResourceLocation getUnicodePageLocation(int p_111271_1_) + { + if (unicodePageLocations[p_111271_1_] == null) + { + unicodePageLocations[p_111271_1_] = new ResourceLocation(String.format("textures/font/unicode_page_%02x.png", new Object[] {Integer.valueOf(p_111271_1_)})); + } + + return unicodePageLocations[p_111271_1_]; + } + + private void loadGlyphTexture(int p_78257_1_) + { + bindTexture(this.getUnicodePageLocation(p_78257_1_)); + } + + /** + * Render a single Unicode character at current (posX,posY) location using one of the /font/glyph_XX.png files... + */ + protected float renderUnicodeChar(char p_78277_1_, boolean p_78277_2_) + { + if (this.glyphWidth[p_78277_1_] == 0) + { + return 0.0F; + } + else + { + int i = p_78277_1_ / 256; + this.loadGlyphTexture(i); + int j = this.glyphWidth[p_78277_1_] >>> 4; + int k = this.glyphWidth[p_78277_1_] & 15; + float f = (float)j; + float f1 = (float)(k + 1); + float f2 = (float)(p_78277_1_ % 16 * 16) + f; + float f3 = (float)((p_78277_1_ & 255) / 16 * 16); + float f4 = f1 - f - 0.02F; + float f5 = p_78277_2_ ? 1.0F : 0.0F; + GL11.glBegin(GL11.GL_TRIANGLE_STRIP); + GL11.glTexCoord2f(f2 / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f5, this.posY, 0.0F); + GL11.glTexCoord2f(f2 / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX - f5, this.posY + 7.99F, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, f3 / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F + f5, this.posY, 0.0F); + GL11.glTexCoord2f((f2 + f4) / 256.0F, (f3 + 15.98F) / 256.0F); + GL11.glVertex3f(this.posX + f4 / 2.0F - f5, this.posY + 7.99F, 0.0F); + GL11.glEnd(); + return (f1 - f) / 2.0F + 1.0F; + } + } + + protected void setColor(float r, float g, float b, float a) + { + GL11.glColor4f(r, g, b, alpha); + } + + protected void bindTexture(ResourceLocation location) + { + Minecraft.getMinecraft().renderEngine.bindTexture(location); + } + + private void readFontTexture() + { + BufferedImage bufferedimage; + + try + { + bufferedimage = ImageIO.read(getResourceInputStream(this.locationFontTexture)); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + + int i = bufferedimage.getWidth(); + int j = bufferedimage.getHeight(); + int[] aint = new int[i * j]; + bufferedimage.getRGB(0, 0, i, j, aint, 0, i); + int k = j / 16; + int l = i / 16; + byte b0 = 1; + float f = 8.0F / (float)l; + int i1 = 0; + + while (i1 < 256) + { + int j1 = i1 % 16; + int k1 = i1 / 16; + + if (i1 == 32) + { + this.charWidth[i1] = 3 + b0; + } + + int l1 = l - 1; + + while (true) + { + if (l1 >= 0) + { + int i2 = j1 * l + l1; + boolean flag = true; + + for (int j2 = 0; j2 < k && flag; ++j2) + { + int k2 = (k1 * l + j2) * i; + + if ((aint[i2 + k2] >> 24 & 255) != 0) + { + flag = false; + } + } + + if (flag) + { + --l1; + continue; + } + } + + ++l1; + this.charWidth[i1] = (int)(0.5D + (double)((float)l1 * f)) + b0; + ++i1; + break; + } + } + } + + private void readGlyphSizes() + { + try + { + InputStream inputstream = getResourceInputStream(new ResourceLocation("font/glyph_sizes.bin")); + inputstream.read(this.glyphWidth); + } + catch (IOException ioexception) + { + throw new RuntimeException(ioexception); + } + } + + protected InputStream getResourceInputStream(ResourceLocation location) throws IOException + { + return Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream(); + } + + private String bidiReorder(String p_147647_1_) + { + try + { + Bidi bidi = new Bidi((new ArabicShaping(8)).shape(p_147647_1_), 127); + bidi.setReorderingMode(0); + return bidi.writeReordered(2); + } + catch (ArabicShapingException arabicshapingexception) + { + return p_147647_1_; + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 363bc4f52..52f52f195 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -62,8 +62,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { private float red; private float green; private float blue; - private int[] colorCode = new int[32]; - private int textColor; private float posX; private float posY; @@ -127,7 +125,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { { if (this.field_146172_j) { - //this.drawLabelBackground(); + this.drawLabelBackground(); GL11.glPushMatrix(); 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 From 3be088c4cc4b3a7df8d9794495397f2ca42641a7 Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 22:58:12 -0600 Subject: [PATCH 14/15] Moved OpenGL lines to within the loop that renders each component, fixing some weird alpha errors. --- .../npcs/client/ClientEventHandler.java | 8 ---- .../npcs/client/gui/custom/GuiCustom.java | 14 ++++--- .../gui/custom/components/CustomGuiLabel.java | 38 ++++-------------- .../gui/customoverlay/OverlayCustom.java | 8 ++++ .../components/CustomOverlayLabel.java | 40 +++++-------------- 5 files changed, 33 insertions(+), 75 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 331b0de66..90c49f506 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -10,17 +10,9 @@ public class ClientEventHandler { @SubscribeEvent public void onOverlayRender(RenderGameOverlayEvent.Post event){ if(event.type == RenderGameOverlayEvent.ElementType.ALL) { - 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); - for (OverlayCustom overlayCustom : Client.customOverlays.values()) { overlayCustom.renderGameOverlay(event.partialTicks); } - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_ALPHA_TEST); } } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 4e66719c8..f94cb1461 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -129,16 +129,18 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD Iterator var4 = this.components.values().iterator(); - 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); while(var4.hasNext()) { + 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); + IGuiComponent component = (IGuiComponent)var4.next(); component.onRender(this.mc, mouseX, mouseY, Mouse.getDWheel(), partialTicks); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_ALPHA_TEST); if (this.hoverText != null) { this.func_146283_a(Arrays.asList(this.hoverText), mouseX, mouseY); diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index caa3a69d4..d7fde5ad7 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -45,7 +45,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected int field_146161_f; public int field_146162_g; public int field_146174_h; - public boolean field_146172_j; private boolean randomStyle = false; private boolean boldStyle = false; @@ -106,7 +105,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { CustomGuiLabel lbl = new CustomGuiLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); - lbl.field_146172_j = true; lbl.setScale(component.getScale()); if (component.hasHoverText()) { lbl.hoverText = component.getHoverText(); @@ -129,35 +127,15 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { public void drawLabel() { - if (this.field_146172_j) - { - this.drawLabelBackground(); - GL11.glPushMatrix(); - red = (color >> 16 & 255) / 255f; - green = (color >> 8 & 255) / 255f; - blue = (color & 255) / 255f; + GL11.glPushMatrix(); + red = (color >> 16 & 255) / 255f; + green = (color >> 8 & 255) / 255f; + blue = (color & 255) / 255f; - GL11.glTranslatef(this.x,this.y,0.0F); - GL11.glScalef(this.scale, this.scale, this.scale); - this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); - GL11.glPopMatrix(); - } - } - - protected void drawLabelBackground() - { - if (this.labelBgEnabled) - { - int k = (int)(this.width*this.scale) + this.border * 2; - int l = (int)(this.height*this.scale) + this.border * 2; - int i1 = this.x - this.border; - int j1 = this.y - this.border; - drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor - this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor - this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor - this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor - this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor - } + GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + GL11.glPopMatrix(); } public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java index df6c1a1c0..dea871e62 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java @@ -77,8 +77,16 @@ public class OverlayCustom extends Gui { Iterator var4 = this.components.values().iterator(); while(var4.hasNext()) { + 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); + IOverlayComponent component = (IOverlayComponent)var4.next(); component.onRender(this.mc, partialTicks); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); } } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 52f52f195..74a47455a 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -43,7 +43,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected int field_146161_f; public int field_146162_g; public int field_146174_h; - public boolean field_146172_j; private boolean randomStyle = false; private boolean boldStyle = false; @@ -100,7 +99,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); - lbl.field_146172_j = true; lbl.setScale(component.getScale()); lbl.labelShadowEnabled = component.getShadow(); @@ -123,37 +121,17 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { public void drawLabel() { - if (this.field_146172_j) - { - this.drawLabelBackground(); - GL11.glPushMatrix(); - 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.glPushMatrix(); + 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 - red = (color >> 16 & 255) / 255f; - green = (color >> 8 & 255) / 255f; - blue = (color & 255) / 255f; + red = (color >> 16 & 255) / 255f; + green = (color >> 8 & 255) / 255f; + blue = (color & 255) / 255f; - GL11.glTranslatef(this.x,this.y,0.0F); - GL11.glScalef(this.scale, this.scale, this.scale); - this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); - GL11.glPopMatrix(); - } - } - - protected void drawLabelBackground() - { - if (this.labelBgEnabled) - { - int k = (int)(this.width*this.scale) + this.border * 2; - int l = (int)(this.height*this.scale) + this.border * 2; - int i1 = this.x - this.border; - int j1 = this.y - this.border; - drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor - this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor - this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor - this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor - this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor - } + GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + GL11.glPopMatrix(); } public int drawString(String p_85187_1_, int p_85187_2_, int p_85187_3_, int p_85187_4_, boolean p_85187_5_) From 83e13285f9298306822adf94db86dea7f4406b15 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 31 Jan 2022 14:51:06 -0600 Subject: [PATCH 15/15] Added rotation to overlay components, and color codes to overlay labels --- .../custom/components/CustomGuiButton.java | 11 +++ .../gui/custom/components/CustomGuiLabel.java | 64 +++++++++++++-- .../components/CustomGuiTexturedRect.java | 11 +++ .../components/CustomOverlayLabel.java | 78 +++++++++++++++---- .../components/CustomOverlayLine.java | 4 + .../components/CustomOverlayTexturedRect.java | 16 ++++ .../interfaces/ICustomOverlayComponent.java | 4 + .../overlay/ScriptOverlayComponent.java | 11 +++ 8 files changed, 180 insertions(+), 19 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java index 9cce17988..b2d73a5cd 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java @@ -8,9 +8,14 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IClickListener; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.gui.ScriptGuiButton; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; @@ -45,6 +50,12 @@ public class CustomGuiButton extends GuiButton implements IClickListener { this.textureY = textureY; this.label = buttonText; this.texture = new ResourceLocation(texture); + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(GuiCustom parent) { diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index d7fde5ad7..7ab9f2d64 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -58,6 +58,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected final ResourceLocation locationFontTexture; protected int[] charWidth = new int[256]; protected byte[] glyphWidth = new byte[65536]; + private final int[] colorCode = new int[32]; private float red; @@ -68,10 +69,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { private float posY; public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ - locationFontTexture = new ResourceLocation("textures/font/ascii.png"); - readFontTexture(); - readGlyphSizes(); - this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -79,6 +76,41 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { this.width = width; this.height = height; this.labelShadowEnabled = shadow; + + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + for (int i = 0; i < 32; ++i) + { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i >> 0 & 1) * 170 + j; + + if (i == 6) + { + k += 85; + } + + if (Minecraft.getMinecraft().gameSettings.anaglyph) + { + int j1 = (k * 30 + l * 59 + i1 * 11) / 100; + int k1 = (k * 30 + l * 70) / 100; + int l1 = (k * 30 + i1 * 70) / 100; + k = j1; + l = k1; + i1 = l1; + } + + if (i >= 16) + { + k /= 4; + l /= 4; + i1 /= 4; + } + + this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } } public void setParent(GuiCustom parent) { @@ -198,7 +230,27 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { { j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - if (j == 16) + if(j < 16){ + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + + if (j < 0 || j > 15) + { + j = 15; + } + + if (p_78255_2_) + { + j += 16; + } + + k = this.colorCode[j]; + setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); + } + else if (j == 16) { this.randomStyle = true; } @@ -403,7 +455,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected void setColor(float r, float g, float b, float a) { - GL11.glColor4f(r, g, b, alpha); + GL11.glColor4f(r, g, b, a); } protected void bindTexture(ResourceLocation location) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index 0f480771c..b17939da4 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -8,9 +8,14 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; @@ -48,6 +53,12 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { this.height = height; this.textureX = textureX; this.textureY = textureY; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(GuiCustom parent) { diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 74a47455a..741ee9ed9 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -27,14 +27,14 @@ import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; public class CustomOverlayLabel extends Gui implements IOverlayComponent { OverlayCustom parent; - int alignment; int id; - int x, y, width, height; String fullLabel; + int x, y, width, height, alignment; + float scale, rotation; int color; float alpha; - float scale; + int border = 2; boolean labelBgEnabled = true; boolean labelShadowEnabled = false; @@ -56,7 +56,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected final ResourceLocation locationFontTexture; protected int[] charWidth = new int[256]; protected byte[] glyphWidth = new byte[65536]; - + private final int[] colorCode = new int[32]; private float red; private float green; @@ -66,10 +66,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { private float posY; public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ - locationFontTexture = new ResourceLocation("textures/font/ascii.png"); - readFontTexture(); - readGlyphSizes(); - this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -77,6 +73,41 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { this.width = width; this.height = height; this.labelShadowEnabled = shadow; + + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + for (int i = 0; i < 32; ++i) + { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i >> 0 & 1) * 170 + j; + + if (i == 6) + { + k += 85; + } + + if (Minecraft.getMinecraft().gameSettings.anaglyph) + { + int j1 = (k * 30 + l * 59 + i1 * 11) / 100; + int k1 = (k * 30 + l * 70) / 100; + int l1 = (k * 30 + i1 * 70) / 100; + k = j1; + l = k1; + i1 = l1; + } + + if (i >= 16) + { + k /= 4; + l /= 4; + i1 /= 4; + } + + this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } } public void setParent(OverlayCustom parent) { @@ -99,12 +130,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); - lbl.setScale(component.getScale()); - lbl.labelShadowEnabled = component.getShadow(); lbl.alignment = component.getAlignment(); lbl.alpha = component.getAlpha(); - lbl.color = component.getColor(); + lbl.rotation = component.getRotation(); + lbl.setScale(component.getScale()); return lbl; } @@ -115,6 +145,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); + component.setRotation(rotation); return component; } @@ -129,6 +160,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { blue = (color & 255) / 255f; GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glRotated(rotation,0.0D,0.0D,1.0D); GL11.glScalef(this.scale, this.scale, this.scale); this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); GL11.glPopMatrix(); @@ -194,7 +226,27 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { { j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - if (j == 16) + if(j < 16){ + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + + if (j < 0 || j > 15) + { + j = 15; + } + + if (p_78255_2_) + { + j += 16; + } + + k = this.colorCode[j]; + setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); + } + else if (j == 16) { this.randomStyle = true; } @@ -399,7 +451,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected void setColor(float r, float g, float b, float a) { - GL11.glColor4f(r, g, b, alpha); + GL11.glColor4f(r, g, b, a); } protected void bindTexture(ResourceLocation location) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java index eef06f3ff..be019ee22 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -26,6 +26,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { int color; int thickness; float alpha; + float rotation; public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ this.id = id; @@ -58,6 +59,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { GL11.glTranslatef(this.x1,this.y1,0.0F); GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); + GL11.glRotated(rotation,0.0D,0.0D,1.0D); GL11.glScaled(thickness, distance,0.0D); int p_73729_1_ = 0; @@ -86,6 +88,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { line.setAlignment(alignment); line.setAlpha(alpha); line.setColor(color); + line.setRotation(rotation); return line; } @@ -94,6 +97,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { line.alignment = component.getAlignment(); line.alpha = component.getAlpha(); line.color = component.getColor(); + line.rotation = component.getRotation(); return line; } 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 8447964b5..06867b921 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 @@ -4,9 +4,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; import org.lwjgl.opengl.GL11; @@ -30,6 +35,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent int color; float alpha; + float rotation; public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { this(id, texture, x, y, width, height, 0, 0); @@ -46,6 +52,12 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent this.height = height; this.textureX = textureX; this.textureY = textureY; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(OverlayCustom parent) { @@ -68,6 +80,8 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent GL11.glScalef(this.scale, this.scale, this.scale); + GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); + int p_73729_1_ = (int) (this.x/this.scale); int p_73729_2_ = (int) (this.y/this.scale); int p_73729_3_ = this.textureX; @@ -95,6 +109,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); + component.setRotation(rotation); return component; } @@ -110,6 +125,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent rect.alignment = component.getAlignment(); rect.alpha = component.getAlpha(); rect.color = component.getColor(); + rect.rotation = component.getRotation(); return rect; } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java index 806983ba1..7abb2155d 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java @@ -22,4 +22,8 @@ public interface ICustomOverlayComponent { float getAlpha(); void setAlpha(float alpha); + + float getRotation(); + + void setRotation(float rotation); } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java index edbcab83d..88aa3f396 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -15,6 +15,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent int alignment = 0; int color = 0xFFFFFF; float alpha = 1.0F; + float rotation = 0; /* ========ALIGNMENTS======== 0 1 2 @@ -74,6 +75,14 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.alpha = alpha; } + public float getRotation() { + return rotation; + } + + public void setRotation(float rotation) { + this.rotation = rotation; + } + public abstract int getType(); public NBTTagCompound toNBT(NBTTagCompound nbt) { @@ -82,6 +91,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent nbt.setInteger("alignment",this.alignment); nbt.setInteger("color", this.color); nbt.setFloat("alpha",this.alpha); + nbt.setFloat("rotation",this.rotation); nbt.setInteger("type", this.getType()); return nbt; @@ -93,6 +103,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.setAlignment(nbt.getInteger("alignment")); this.setColor(nbt.getInteger("color")); this.setAlpha(nbt.getFloat("alpha")); + this.setRotation(nbt.getInteger("rotation")); return this; }