Merge branch 'dev' into syntax-highlighter-unified

This commit is contained in:
Kam committed 2026-03-03 20:30:02 -05:00
commit 513956062d
68 files changed
+2634 -246

No files matched your search

@@ -369,6 +369,8 @@ public class GuiScript extends GuiScriptInterface {
@Override
public void setGuiData(NBTTagCompound compound) {
script.readFromNBT(compound);
if (compound.hasKey("ScriptSessionToken"))
scriptSessionToken = compound.getString("ScriptSessionToken");
loadLanguagesData(compound);
loaded = true;
}
@@ -377,7 +379,10 @@ public class GuiScript extends GuiScriptInterface {
public void save() {
if (loaded) {
setScript();
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
NBTTagCompound compound = script.writeToNBT(new NBTTagCompound());
if (scriptSessionToken != null)
compound.setString("ScriptSessionToken", scriptSessionToken);
NPCScriptPacket.Save(compound);
}
}
@@ -0,0 +1,250 @@
package noppes.npcs.client.gui.advanced;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Sub-GUI for editing magic splits on an Ability.
* Dual-scroll layout: available magics on left, assigned magics on right.
* Only split values (no flat damage) are editable.
*/
public class SubGuiAbilityMagic extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
public MagicData magicData;
private GuiCustomScroll availableScroll;
private GuiCustomScroll assignedScroll;
/** Maps display name → magic ID for all available magics. */
private final HashMap<String, Integer> allMagic = new HashMap<>();
/** Maps formatted display string (right scroll) → base display name. */
private final HashMap<String, String> assignedDisplayToName = new HashMap<>();
private String search = "";
private GuiNpcTextField splitField;
public SubGuiAbilityMagic(MagicData data) {
this.magicData = data;
setBackground("menubg.png");
xSize = 420;
ySize = 222;
// Load all available magics from the controller
MagicController controller = MagicController.getInstance();
for (Map.Entry<Integer, Magic> entry : controller.magics.entrySet()) {
allMagic.put(entry.getValue().getDisplayName(), entry.getKey());
}
}
@Override
public void initGui() {
super.initGui();
int scrollW = 150;
int scrollH = 140;
int leftX = guiLeft + 10;
int rightX = guiLeft + 250;
int topY = guiTop + 20;
// Title
addLabel(new GuiNpcLabel(0, "ability.magic.editor", guiLeft + 10, guiTop + 5));
// Left scroll: available magics
if (availableScroll == null) {
availableScroll = new GuiCustomScroll(this, 0);
availableScroll.setSize(scrollW, scrollH);
}
availableScroll.guiLeft = leftX;
availableScroll.guiTop = topY;
availableScroll.setList(getSearchList());
addScroll(availableScroll);
// Search field below left scroll
addTextField(new GuiNpcTextField(4, this, fontRendererObj, leftX, topY + scrollH + 5, scrollW, 20, search));
// Right scroll: assigned magics
if (assignedScroll == null) {
assignedScroll = new GuiCustomScroll(this, 1);
assignedScroll.setSize(scrollW, scrollH);
}
assignedScroll.guiLeft = rightX;
assignedScroll.guiTop = topY;
updateAssignedList();
addScroll(assignedScroll);
// Arrow buttons between scrolls
int midX = guiLeft + 175;
addButton(new GuiNpcButton(70, midX, topY + 40, 55, 20, ">"));
addButton(new GuiNpcButton(71, midX, topY + 62, 55, 20, "<"));
// Standardize button
addButton(new GuiNpcButton(72, midX, topY + 90, 55, 20, "magic.dist"));
getButton(72).setHoverText("magic.distInfo");
// Split field below right scroll
int tfY = topY + scrollH + 5;
addLabel(new GuiNpcLabel(5002, "magic.split", rightX - 57, tfY + 5));
splitField = new GuiNpcTextField(73, this, fontRendererObj, rightX, tfY, 60, 20, "");
splitField.setFloatsOnly();
splitField.setMinMaxDefaultFloat(0, 1, 0);
splitField.enabled = false;
addTextField(splitField);
// Done button
addButton(new GuiNpcButton(80, guiLeft + xSize / 2 - 40, guiTop + ySize - 34, 80, 20, "gui.done"));
}
@Override
public void buttonEvent(GuiButton guibutton) {
// Add magic
if (guibutton.id == 70) {
if (availableScroll.hasSelected()) {
String selected = availableScroll.getSelected();
Integer id = allMagic.get(selected);
if (id != null && !magicData.hasMagic(id)) {
magicData.addMagic(id, 0, 0);
}
}
updateAssignedList();
return;
}
// Remove magic
if (guibutton.id == 71) {
if (assignedScroll.hasSelected()) {
Integer id = resolveAssignedId(assignedScroll.getSelected());
if (id != null && magicData.hasMagic(id)) {
magicData.removeMagic(id);
}
}
updateAssignedList();
if (splitField != null) {
splitField.setText("");
splitField.enabled = false;
}
return;
}
// Standardize splits
if (guibutton.id == 72) {
if (magicData.getMagics().size() > 0) {
int count = magicData.getMagics().size();
float stdSplit = 1.0f / count;
for (Integer key : magicData.getMagics().keySet()) {
magicData.getMagic(key).split = stdSplit;
}
// Update field if something is selected
if (assignedScroll.getSelected() != null && splitField != null) {
Integer id = resolveAssignedId(assignedScroll.getSelected());
if (id != null && magicData.hasMagic(id)) {
splitField.setText(magicData.getMagic(id).split + "");
}
}
updateAssignedList();
}
return;
}
// Done
if (guibutton.id == 80) {
close();
return;
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(4) != null && getTextField(4).isFocused()) {
if (search.equals(getTextField(4).getText()))
return;
search = getTextField(4).getText().toLowerCase();
availableScroll.setList(getSearchList());
availableScroll.resetScroll();
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll == assignedScroll) {
if (assignedScroll.getSelected() != null) {
Integer id = resolveAssignedId(assignedScroll.getSelected());
if (id != null && magicData.hasMagic(id)) {
if (splitField != null) {
splitField.setText(magicData.getMagic(id).split + "");
splitField.enabled = true;
}
}
}
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
}
@Override
public void unFocused(GuiNpcTextField textField) {
if (textField.id == 73) {
if (assignedScroll != null && assignedScroll.getSelected() != null) {
Integer id = resolveAssignedId(assignedScroll.getSelected());
if (id != null && magicData.hasMagic(id)) {
try {
float split = Float.parseFloat(textField.getText());
magicData.getMagic(id).split = split;
updateAssignedList();
} catch (NumberFormatException e) {
}
}
}
}
}
private List<String> getSearchList() {
if (search.isEmpty()) {
return new ArrayList<>(allMagic.keySet());
}
List<String> list = new ArrayList<>();
for (String name : allMagic.keySet()) {
if (name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
/**
* Resolves the magic ID from a right-scroll selection (which may be formatted as "Name - XX%").
*/
private Integer resolveAssignedId(String selection) {
if (selection == null) return null;
String baseName = assignedDisplayToName.get(selection);
if (baseName == null) baseName = selection;
return allMagic.get(baseName);
}
private void updateAssignedList() {
assignedDisplayToName.clear();
List<String> selected = new ArrayList<>();
for (Map.Entry<String, Integer> entry : allMagic.entrySet()) {
if (magicData.hasMagic(entry.getValue())) {
float split = magicData.getMagic(entry.getValue()).split;
String display = entry.getKey() + " - " + Math.round(split * 100) + "%";
assignedDisplayToName.put(display, entry.getKey());
selected.add(display);
}
}
if (assignedScroll != null) {
assignedScroll.setList(selected);
}
}
}
@@ -25,11 +25,17 @@ import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import tconstruct.client.tabs.AbstractTab;
import noppes.npcs.controllers.MagicController;
import noppes.npcs.controllers.data.Magic;
import noppes.npcs.controllers.data.MagicData;
import noppes.npcs.controllers.data.MagicEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/standardbg.png");
@@ -92,6 +98,11 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
private AbilityIcon cachedDetailIcon = null;
private int cachedDetailIndex = -1;
// ═══ Info panel scroll ═══
private int infoScrollOffset = 0;
private int infoContentHeight = 0;
private int lastInfoIndex = -1;
// ═══ Hotbar state ═══
private int hoveredSlotIndex = -1;
private AbilityIcon[] hotbarIcons = new AbilityIcon[AbilityHotbarData.TOTAL_SLOTS];
@@ -436,11 +447,17 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
int infoIndex = hoveredGridIndex >= 0 ? hoveredGridIndex : selectedIndex;
if (infoIndex < 0 || infoIndex >= filteredKeys.size()) return;
// Reset scroll when ability changes
if (infoIndex != lastInfoIndex) {
infoScrollOffset = 0;
lastInfoIndex = infoIndex;
}
FontRenderer fr = mc.fontRenderer;
int panelInnerLeft = guiLeft + infoLeft + infoPad;
int panelInnerTop = guiTop + infoTop + infoPad;
int panelInnerWidth = (infoRight - infoLeft) - infoPad * 2;
int y = panelInnerTop;
int panelHeight = infoBottom - infoTop;
// Cached icon for detail preview
if (cachedDetailIndex != infoIndex) {
@@ -448,14 +465,28 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
cachedDetailIndex = infoIndex;
}
Ability ability = filteredAbilities.get(infoIndex);
// Get toggle state for icon rendering and state display
int toggleState = 0;
PlayerData togglePlayerData = ClientCacheHandler.playerData;
Ability infoAbility = filteredAbilities.get(infoIndex);
if (infoAbility != null && infoAbility.isToggleable() && togglePlayerData != null && togglePlayerData.abilityData != null) {
if (ability != null && ability.isToggleable() && togglePlayerData != null && togglePlayerData.abilityData != null) {
toggleState = togglePlayerData.abilityData.getToggleState(filteredKeys.get(infoIndex));
}
// GL Scissor to clip info panel content
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int scaleFactor = sr.getScaleFactor();
int scissorX = (guiLeft + infoLeft) * scaleFactor;
int scissorY = mc.displayHeight - (guiTop + infoBottom) * scaleFactor;
int scissorW = (infoRight - infoLeft) * scaleFactor;
int scissorH = panelHeight * scaleFactor;
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor(scissorX, scissorY, scissorW, scissorH);
int y = panelInnerTop - infoScrollOffset;
// Preview icon (centered, state-aware for multi-state toggles)
if (cachedDetailIcon != null) {
float drawSize = cachedDetailIcon.getDrawSize();
@@ -490,9 +521,8 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
}
y += 4;
// Type info
Ability ability = filteredAbilities.get(infoIndex);
if (ability != null) {
// Type info
String typeId = ability.getTypeId();
if (typeId != null && !typeId.isEmpty()) {
String translated = StatCollector.translateToLocal(typeId);
@@ -503,6 +533,7 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
}
}
// Toggle info
if (ability.isToggleable()) {
String toggleText = "[" + StatCollector.translateToLocal("gui.toggle") + "]";
int textW = fr.getStringWidth(toggleText);
@@ -510,12 +541,11 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
y += fr.FONT_HEIGHT + 3;
}
// Toggle state (uses pre-computed toggleState)
// Toggle state
if (ability.isToggleable()) {
String stateText;
String prefix;
if (toggleState > 0) {
// Active — check for state label (multi-state toggles like Ki Weapon)
String stateLabel = ability.getToggleStateLabel(toggleState);
stateText = stateLabel != null ? stateLabel : StatCollector.translateToLocal("gui.toggle.active");
prefix = "\u00A72";
@@ -528,20 +558,110 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
y += fr.FONT_HEIGHT + 3;
}
// Cooldown info
// Cooldown info — yellow if per-ability cooldown
if (ability.getCooldownTicks() > 0) {
float seconds = ability.getCooldownTicks() / 20.0f;
String cdText = StatCollector.translateToLocal("ability.cooldown") + ": " + String.format("%.1f", seconds) + "s";
int textW2 = fr.getStringWidth(cdText);
fr.drawStringWithShadow("\u00A77" + cdText, panelInnerLeft + (panelInnerWidth - textW2) / 2, y, 0xAAAAAA);
boolean perAbility = ability.isPerAbilityCooldown();
String cdColor = perAbility ? "\u00A7e" : "\u00A77";
int cdColorInt = perAbility ? 0xFFFF55 : 0xAAAAAA;
fr.drawStringWithShadow(cdColor + cdText, panelInnerLeft + (panelInnerWidth - textW2) / 2, y, cdColorInt);
y += fr.FONT_HEIGHT + 3;
if (ability.isPerAbilityCooldown()) {
if (perAbility) {
String perText = "[" + StatCollector.translateToLocal("ability.perAbilityCooldown") + "]";
int ptW = fr.getStringWidth(perText);
fr.drawStringWithShadow("\u00A7e" + perText, panelInnerLeft + (panelInnerWidth - ptW) / 2, y, 0xFFFF55);
y += fr.FONT_HEIGHT + 3;
}
}
// Damage info
float baseDamage = ability.getDisplayDamage();
if (baseDamage > 0) {
float displayDamage = baseDamage;
if (AbilityController.Instance != null && mc.thePlayer != null) {
displayDamage = AbilityController.Instance.fireModifyProjectileDamage(ability, mc.thePlayer, baseDamage);
}
String label = ability.isDisplayDamageDPS()
? StatCollector.translateToLocal("gui.dps")
: StatCollector.translateToLocal("ability.preview.damage");
String dmgText = label + ": " + String.format("%.1f", displayDamage);
int textW = fr.getStringWidth(dmgText);
fr.drawStringWithShadow("\u00A7c" + dmgText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0xFF5555);
y += fr.FONT_HEIGHT + 3;
}
// Barrier health
float baseHealth = ability.getDisplayBarrierHealth();
if (baseHealth > 0) {
float displayHealth = baseHealth;
if (AbilityController.Instance != null && mc.thePlayer != null) {
displayHealth = AbilityController.Instance.fireModifyBarrierHealth(ability, mc.thePlayer, baseHealth);
}
String healthText = StatCollector.translateToLocal("ability.preview.health") + ": " + String.format("%.0f", displayHealth);
int textW = fr.getStringWidth(healthText);
fr.drawStringWithShadow("\u00A7a" + healthText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0x55FF55);
y += fr.FONT_HEIGHT + 3;
}
// Barrier reflection
if (ability.isDisplayReflect()) {
String reflectText = StatCollector.translateToLocal("ability.reflect") + ": " + String.format("%.0f%%", ability.getDisplayReflectStrength());
int textW = fr.getStringWidth(reflectText);
fr.drawStringWithShadow("\u00A7d" + reflectText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0xFF55FF);
y += fr.FONT_HEIGHT + 3;
}
// Barrier absorbing
if (ability.isDisplayAbsorbing()) {
String absorbText = "[" + StatCollector.translateToLocal("ability.absorbing") + "]";
int textW = fr.getStringWidth(absorbText);
fr.drawStringWithShadow("\u00A7b" + absorbText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0x55FFFF);
y += fr.FONT_HEIGHT + 3;
}
// Magic info
if (ability.hasMagic()) {
y += 2;
MagicData magicData = ability.getMagicData();
if (magicData.isEmpty()) {
String magicText = StatCollector.translateToLocal("ability.preview.magic.casters");
int textW = fr.getStringWidth(magicText);
fr.drawStringWithShadow("\u00A79" + magicText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0x5555FF);
y += fr.FONT_HEIGHT + 3;
} else {
for (Map.Entry<Integer, MagicEntry> entry : magicData.getMagics().entrySet()) {
Magic magic = MagicController.getInstance() != null
? MagicController.getInstance().getMagic(entry.getKey()) : null;
String magicName = magic != null ? magic.getDisplayName() : "Magic #" + entry.getKey();
String splitText = magicName + ": " + Math.round(entry.getValue().split * 100) + "%";
int textW = fr.getStringWidth(splitText);
fr.drawStringWithShadow("\u00A79" + splitText, panelInnerLeft + (panelInnerWidth - textW) / 2, y, 0x5555FF);
y += fr.FONT_HEIGHT + 1;
}
y += 2;
}
}
}
// Track content height for scroll limits
infoContentHeight = (y + infoScrollOffset) - panelInnerTop + infoPad * 2;
GL11.glDisable(GL11.GL_SCISSOR_TEST);
// Scroll indicator
if (infoContentHeight > panelHeight) {
int maxScroll = Math.max(1, infoContentHeight - panelHeight);
if (infoScrollOffset > maxScroll) infoScrollOffset = maxScroll;
float scrollPercent = (float) infoScrollOffset / maxScroll;
int barHeight = panelHeight - 4;
int thumbHeight = Math.max(8, barHeight * panelHeight / infoContentHeight);
int thumbY = guiTop + infoTop + 2 + (int) ((barHeight - thumbHeight) * scrollPercent);
int barX = guiLeft + infoRight - 3;
drawRect(barX, guiTop + infoTop + 2, barX + 2, guiTop + infoTop + 2 + barHeight, 0x40FFFFFF);
drawRect(barX, thumbY, barX + 2, thumbY + thumbHeight, 0xA0FFFFFF);
}
}
@@ -903,11 +1023,26 @@ public class GuiAbilities extends GuiCNPCInventory implements ISubGuiListener {
int wheel = Mouse.getEventDWheel();
if (wheel != 0) {
int maxScroll = getMaxScrollRow();
if (wheel > 0) {
scrollRow = Math.max(0, scrollRow - 1);
int mouseX = Mouse.getEventX() * width / mc.displayWidth;
int mouseY = height - Mouse.getEventY() * height / mc.displayHeight - 1;
if (mouseX >= guiLeft + infoLeft && mouseX < guiLeft + infoRight
&& mouseY >= guiTop + infoTop && mouseY < guiTop + infoBottom) {
// Info panel scroll
int panelHeight = infoBottom - infoTop;
int maxInfoScroll = Math.max(0, infoContentHeight - panelHeight);
if (wheel > 0) {
infoScrollOffset = Math.max(0, infoScrollOffset - 10);
} else {
infoScrollOffset = Math.min(maxInfoScroll, infoScrollOffset + 10);
}
} else {
scrollRow = Math.min(maxScroll, scrollRow + 1);
int maxScroll = getMaxScrollRow();
if (wheel > 0) {
scrollRow = Math.max(0, scrollRow - 1);
} else {
scrollRow = Math.min(maxScroll, scrollRow + 1);
}
}
}
}
@@ -46,8 +46,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
public Map<String, List<String>> languages = new HashMap();
protected int scriptLimit = 1;
public List<String> hookList = new ArrayList<String>();
protected boolean loaded = false;
protected volatile boolean loaded = false;
protected boolean serverDataReceived = false;
protected String scriptSessionToken = null;
protected Map<Integer, GuiScriptTextArea> textAreas = new HashMap<>();
protected GuiScreen parent;
@@ -766,6 +767,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
return;
}
if (result.kind == IScriptHandlerPacket.GuiDataKind.METADATA) {
if (compound.hasKey("ScriptSessionToken"))
scriptSessionToken = compound.getString("ScriptSessionToken");
loadLanguagesData(compound);
return;
}
@@ -776,6 +779,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
return;
}
if (compound.hasKey("ScriptSessionToken"))
scriptSessionToken = compound.getString("ScriptSessionToken");
loadLanguagesData(compound);
}
@@ -825,9 +830,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
this.setScript();
if (handler instanceof IScriptHandlerPacket)
((IScriptHandlerPacket) handler).sync();
((IScriptHandlerPacket) handler).sync(scriptSessionToken);
}
public void textUpdate(String text) {