Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/gui/global/GuiMagicMap.java
T

130 lines
4.6 KiB
Java
Raw Normal View History

2025-02-03 16:59:06 -05:00
package noppes.npcs.client.gui.global;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
2025-02-03 21:18:45 -05:00
import noppes.npcs.client.gui.util.GuiNPCInterface;
2025-02-03 16:59:06 -05:00
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.Magic;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
2025-02-03 21:18:45 -05:00
public class GuiMagicMap extends GuiDiagram {
2025-02-03 16:59:06 -05:00
private List<Magic> magics;
2025-02-03 21:18:45 -05:00
// Single RenderItem instance for efficiency.
2025-02-03 17:28:03 -05:00
private RenderItem renderItem = new RenderItem();
2025-02-03 16:59:06 -05:00
2025-02-03 21:18:45 -05:00
public GuiMagicMap(GuiNPCInterface parent, int x, int y, int width, int height) {
super(parent, x, y, width, height);
2025-02-03 17:28:03 -05:00
magics = new ArrayList<>();
2025-02-03 21:18:45 -05:00
// Cache all magics from the MagicController.
2025-02-03 16:59:06 -05:00
for (Magic magic : MagicController.getInstance().magics.values()) {
magics.add(magic);
}
2025-02-04 14:38:13 -05:00
setLayout(DiagramLayout.CHART);
2025-02-04 03:48:25 -05:00
this.setCurvedArrows(true);
2025-02-04 14:38:13 -05:00
this.setCurveAngle(-20);
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
@Override
2025-02-03 21:18:45 -05:00
protected List<DiagramIcon> createIcons() {
2025-02-03 17:28:03 -05:00
List<DiagramIcon> icons = new ArrayList<>();
for (Magic magic : magics) {
2025-02-03 21:18:45 -05:00
MagicIcon icon = new MagicIcon(magic);
// Set your desired flags (for example, enabled and pressable).
icon.enabled = true;
icon.pressable = true;
icons.add(icon);
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
return icons;
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
@Override
2025-02-03 21:18:45 -05:00
protected List<DiagramConnection> createConnections() {
2025-02-03 17:28:03 -05:00
List<DiagramConnection> conns = new ArrayList<>();
// For each Magic, generate connections from each weakness (attacker) to this magic.
2025-02-03 16:59:06 -05:00
for (Magic magic : magics) {
2025-02-03 21:18:45 -05:00
if (magic.weaknesses == null)
continue;
2025-02-03 17:28:03 -05:00
for (Map.Entry<Integer, Float> entry : magic.weaknesses.entrySet()) {
int attackerId = entry.getKey();
float percent = entry.getValue();
String hover = "+" + (int) (percent * 100) + "%";
conns.add(new DiagramConnection(attackerId, magic.id, percent, hover));
2025-02-03 16:59:06 -05:00
}
}
2025-02-03 17:28:03 -05:00
return conns;
}
2025-02-03 16:59:06 -05:00
2025-02-03 17:28:03 -05:00
@Override
protected void renderIcon(DiagramIcon icon, int posX, int posY, IconRenderState state) {
2025-02-03 17:28:03 -05:00
Magic magic = ((MagicIcon) icon).magic;
Minecraft mc = Minecraft.getMinecraft();
FontRenderer fontRenderer = mc.fontRenderer;
int size = this.iconSize;
int iconX = posX - size / 2;
int iconY = posY - size / 2;
2025-02-03 16:59:06 -05:00
RenderHelper.enableGUIStandardItemLighting();
2025-02-03 17:28:03 -05:00
if (magic.iconItem != null) {
renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), magic.iconItem, iconX, iconY);
} else if (magic.iconTexture != null && !magic.iconTexture.isEmpty()) {
mc.getTextureManager().bindTexture(new ResourceLocation(magic.iconTexture));
this.drawTexturedModalRect(iconX, iconY, 0, 0, size, size);
2025-02-03 17:28:03 -05:00
} else {
ItemStack sword = new ItemStack(Items.iron_sword);
renderItem.renderItemAndEffectIntoGUI(fontRenderer, mc.getTextureManager(), sword, iconX, iconY);
2025-02-03 16:59:06 -05:00
}
RenderHelper.disableStandardItemLighting();
2025-02-03 21:18:45 -05:00
// If the icon is not highlighted, draw a translucent overlay.
if (state == IconRenderState.NOT_HIGHLIGHTED) {
drawRect(iconX, iconY, iconX + size, iconY + size, 0x80202020);
2025-02-03 16:59:06 -05:00
}
// Reset color.
GL11.glColor4f(1f, 1f, 1f, 1f);
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
@Override
protected List<String> getIconTooltip(DiagramIcon icon) {
Magic magic = ((MagicIcon) icon).magic;
List<String> tooltip = new ArrayList<>();
tooltip.add(magic.getName());
return tooltip;
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
@Override
protected void drawHoveringText(List<String> text, int mouseX, int mouseY, FontRenderer fontRenderer) {
2025-02-03 21:18:45 -05:00
parent.renderHoveringText(text, mouseX, mouseY, fontRenderer);
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
/**
* Override getIconName so that connection tooltips can show Magic names.
*/
@Override
protected String getIconName(DiagramIcon icon) {
Magic magic = ((MagicIcon) icon).magic;
return magic.getName();
2025-02-03 16:59:06 -05:00
}
2025-02-03 17:28:03 -05:00
// Wrap a Magic object as a DiagramIcon.
private class MagicIcon extends DiagramIcon {
public Magic magic;
public MagicIcon(Magic magic) {
2025-02-04 03:48:25 -05:00
super(magic.id, magic.index, magic.priority);
2025-02-03 17:28:03 -05:00
this.magic = magic;
}
2025-02-03 16:59:06 -05:00
}
}