mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 20:24:30 +00:00
Completed Tag Support for Auras, Forms, Outlines, Effects, Linked Items, Abilities
This commit is contained in:
1 parent
0eeeec5d22
commit
111156da5a
15 files changed
+503
-5
No files matched your search
@@ -0,0 +1,102 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Scroll list that renders CNPC tags next to item names.
|
||||
* Used in directory/fullscreen GUIs for Forms, Auras, Outlines, etc.
|
||||
*/
|
||||
public class GuiCustomScrollTagged extends GuiCustomScroll {
|
||||
private HashMap<String, HashSet<UUID>> itemTagMap = new HashMap<>();
|
||||
private boolean showTags = true;
|
||||
|
||||
public GuiCustomScrollTagged(GuiScreen parent, int id) {
|
||||
super(parent, id);
|
||||
}
|
||||
|
||||
public void setItemTagMap(HashMap<String, HashSet<UUID>> tagMap) {
|
||||
this.itemTagMap = tagMap != null ? tagMap : new HashMap<>();
|
||||
}
|
||||
|
||||
public HashMap<String, HashSet<UUID>> getItemTagMap() {
|
||||
return itemTagMap;
|
||||
}
|
||||
|
||||
public void setShowTags(boolean show) {
|
||||
this.showTags = show;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawItems() {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
int j = 4;
|
||||
int k = (14 * i + 4) - scrollY;
|
||||
if (k >= 4 && k + 12 < ySize) {
|
||||
int xOffset = scrollHeight < ySize - 8 ? 0 : 10;
|
||||
String rawEntry = list.get(i);
|
||||
String displayString = StatCollector.translateToLocal(rawEntry);
|
||||
|
||||
String text = "";
|
||||
float maxWidth = showTags && itemTagMap.containsKey(rawEntry)
|
||||
? (xSize + xOffset - 8) * 0.5f
|
||||
: (xSize + xOffset - 8) * 0.8f;
|
||||
|
||||
if (fontRendererObj.getStringWidth(displayString) > maxWidth) {
|
||||
for (int h = 0; h < displayString.length(); h++) {
|
||||
char c = displayString.charAt(h);
|
||||
text += c;
|
||||
if (fontRendererObj.getStringWidth(text) > maxWidth)
|
||||
break;
|
||||
}
|
||||
if (displayString.length() > text.length())
|
||||
text += "...";
|
||||
} else {
|
||||
text = displayString;
|
||||
}
|
||||
|
||||
Integer customColor = colors.get(rawEntry);
|
||||
if (customColor != null) {
|
||||
if (!text.isEmpty())
|
||||
fontRendererObj.drawString(text, j, k, customColor);
|
||||
} else if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
|
||||
drawVerticalLine(j - 2, k - 4, k + 10, 0xffffffff);
|
||||
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
|
||||
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3, 0xffffffff);
|
||||
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k + 10, 0xffffffff);
|
||||
fontRendererObj.drawString(text, j, k, 0xffffff);
|
||||
} else if (i == hover) {
|
||||
fontRendererObj.drawString(text, j, k, 0x00ff00);
|
||||
} else {
|
||||
fontRendererObj.drawString(text, j, k, 0xffffff);
|
||||
}
|
||||
|
||||
// Draw tags after item name
|
||||
if (showTags && itemTagMap.containsKey(rawEntry)) {
|
||||
int tagStartX = j + fontRendererObj.getStringWidth(text) + 3;
|
||||
int maxX = j + xSize - 18 + xOffset;
|
||||
HashSet<UUID> tagUUIDs = itemTagMap.get(rawEntry);
|
||||
TagController tc = TagController.getInstance();
|
||||
if (tc != null && tagUUIDs != null) {
|
||||
for (UUID uuid : tagUUIDs) {
|
||||
Tag tag = tc.getTagFromUUID(uuid);
|
||||
if (tag != null && !tag.hideTag) {
|
||||
String tagText = "[" + tag.name + "]";
|
||||
int tagWidth = fontRendererObj.getStringWidth(tagText);
|
||||
if (tagStartX + tagWidth > maxX) break;
|
||||
fontRendererObj.drawString(tagText, tagStartX, k, tag.color);
|
||||
tagStartX += tagWidth + 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.data.Category;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -20,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -32,7 +35,7 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
|
||||
|
||||
// ========== Scrolls ==========
|
||||
protected GuiCustomScrollIcons catScroll = new GuiCustomScrollIcons(this, 2);
|
||||
protected GuiCustomScroll itemScroll = new GuiCustomScroll(this, 0);
|
||||
protected GuiCustomScrollTagged itemScroll = new GuiCustomScrollTagged(this, 0);
|
||||
|
||||
// ========== Data ==========
|
||||
protected HashMap<String, Integer> catData = new HashMap<>();
|
||||
@@ -463,8 +466,24 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
|
||||
if (selectedCatId < 0) return new ArrayList<>();
|
||||
if (itemSearch.isEmpty()) return new ArrayList<>(itemData.keySet());
|
||||
List<String> list = new ArrayList<>();
|
||||
HashMap<String, HashSet<UUID>> tagMap = itemScroll.getItemTagMap();
|
||||
for (String name : itemData.keySet()) {
|
||||
if (name.toLowerCase().contains(itemSearch)) list.add(name);
|
||||
if (name.toLowerCase().contains(itemSearch)) {
|
||||
list.add(name);
|
||||
} else if (tagMap != null && tagMap.containsKey(name)) {
|
||||
// Search by tag name — match [tagname] or just tagname
|
||||
HashSet<UUID> uuids = tagMap.get(name);
|
||||
TagController tc = TagController.getInstance();
|
||||
if (tc != null) {
|
||||
for (UUID uuid : uuids) {
|
||||
noppes.npcs.controllers.data.Tag tag = tc.getTagFromUUID(uuid);
|
||||
if (tag != null && tag.name.toLowerCase().contains(itemSearch.replace("[", "").replace("]", ""))) {
|
||||
list.add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -693,6 +712,21 @@ public abstract class GuiDirectoryCategorized extends GuiDirectory
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (compound.hasKey("CategoryTagMap")) {
|
||||
// Tag map for category items
|
||||
HashMap<String, HashSet<UUID>> tagMap = new HashMap<>();
|
||||
NBTTagList entries = compound.getTagList("CategoryTagMap", 10);
|
||||
for (int i = 0; i < entries.tagCount(); i++) {
|
||||
NBTTagCompound entry = entries.getCompoundTagAt(i);
|
||||
String itemName = entry.getString("Name");
|
||||
HashSet<UUID> uuids = TagController.readTagUUIDs(entry, "Tags");
|
||||
if (!uuids.isEmpty()) {
|
||||
tagMap.put(itemName, uuids);
|
||||
}
|
||||
}
|
||||
itemScroll.setItemTagMap(tagMap);
|
||||
return;
|
||||
}
|
||||
onItemReceived(compound);
|
||||
if (pendingNewItemCatId > 0 && hasSelectedItem() && getSelectedItemId() >= 0) {
|
||||
sendMovePacket(getSelectedItemId(), pendingNewItemCatId);
|
||||
|
||||
Reference in new issue
Block a user