Ability Push

This commit is contained in:
Kam committed 2026-01-09 15:29:00 -05:00
1 parent 3e85557984
commit 166c8aa228
66 files changed
+10780 -42

No files matched your search

@@ -136,6 +136,8 @@ import noppes.npcs.client.renderer.RenderNpcCrystal;
import noppes.npcs.client.renderer.RenderNpcDragon;
import noppes.npcs.client.renderer.RenderNpcSlime;
import noppes.npcs.client.renderer.RenderProjectile;
import kamkeel.npcs.client.renderer.TelegraphRenderer;
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
import noppes.npcs.client.renderer.blocks.BlockBannerRenderer;
import noppes.npcs.client.renderer.blocks.BlockBarrelRenderer;
import noppes.npcs.client.renderer.blocks.BlockBeamRenderer;
@@ -306,6 +308,10 @@ public class ClientProxy extends CommonProxy {
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
// Telegraph rendering system
TelegraphManager.initClient();
MinecraftForge.EVENT_BUS.register(new TelegraphRenderer());
if (ConfigClient.InventoryGuiEnabled) {
MinecraftForge.EVENT_BUS.register(new TabRegistry());
if (TabRegistry.getTabList().isEmpty()) {
@@ -18,6 +18,7 @@ import net.minecraft.world.World;
import noppes.npcs.CustomNpcs;
import noppes.npcs.client.controllers.MusicController;
import noppes.npcs.client.controllers.ScriptSoundController;
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
import noppes.npcs.client.gui.hud.ClientHudManager;
import noppes.npcs.client.gui.hud.CompassHudComponent;
import noppes.npcs.client.gui.hud.EnumHudComponent;
@@ -109,6 +110,11 @@ public class ClientTickHandler {
MusicController.Instance.onUpdate();
ScriptSoundController.Instance.onUpdate();
// Tick telegraph manager for ability warnings
if (TelegraphManager.ClientInstance != null) {
TelegraphManager.ClientInstance.tick(mc.theWorld);
}
if (Minecraft.getMinecraft().thePlayer != null && (prevWidth != mc.displayWidth || prevHeight != mc.displayHeight)) {
prevWidth = mc.displayWidth;
prevHeight = mc.displayHeight;
@@ -0,0 +1,463 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcSavePacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
/**
* GUI for managing NPC abilities.
* Shows list of assigned abilities with add/remove/edit controls.
*/
public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, ICustomScrollListener, IGuiData, ITextfieldListener, ISubGuiListener, IAbilityConfigCallback {
private GuiCustomScroll availableTypesScroll;
private GuiCustomScroll npcAbilitiesScroll;
// All available ability types (typeId -> index)
private final HashMap<String, Integer> allAbilityTypes = new HashMap<>();
// NPC's current abilities
private final List<Ability> npcAbilities = new ArrayList<>();
// Settings
private boolean abilitiesEnabled = false;
private int globalCooldown = 20;
private String search = "";
private int selectedAbilityIndex = -1;
public GuiNPCAbilities(EntityNPCInterface npc) {
super(npc);
PacketClient.sendClient(new AbilitiesGetAllPacket());
PacketClient.sendClient(new AbilitiesNpcGetPacket());
}
@Override
public void initGui() {
super.initGui();
int y = guiTop + 10;
// Enabled checkbox
addLabel(new GuiNpcLabel(100, "gui.enabled", guiLeft + 5, y + 5));
addButton(new GuiNpcButton(100, guiLeft + 55, y, 50, 20, new String[]{"gui.no", "gui.yes"}, abilitiesEnabled ? 1 : 0));
// Global cooldown (spaced out since combat only is removed)
addLabel(new GuiNpcLabel(101, "ability.globalCooldown", guiLeft + 140, y + 5));
GuiNpcTextField cooldownField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 230, y, 50, 20, String.valueOf(globalCooldown));
cooldownField.setIntegersOnly();
cooldownField.setMinMaxDefault(0, 10000, 20);
addTextField(cooldownField);
y += 28;
// Left scroll: available ability types
addLabel(new GuiNpcLabel(1, "ability.availableTypes", guiLeft + 5, y));
if (availableTypesScroll == null) {
availableTypesScroll = new GuiCustomScroll(this, 0);
availableTypesScroll.setSize(140, 130);
}
availableTypesScroll.guiLeft = guiLeft + 5;
availableTypesScroll.guiTop = y + 12;
availableTypesScroll.setList(getFilteredTypeList());
addScroll(availableTypesScroll);
// Search bar for types
addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 5, y + 145, 140, 18, search));
// Right scroll: NPC's abilities (widened to use available space)
addLabel(new GuiNpcLabel(2, "ability.npcAbilities", guiLeft + 210, y));
if (npcAbilitiesScroll == null) {
npcAbilitiesScroll = new GuiCustomScroll(this, 1);
npcAbilitiesScroll.setSize(160, 130);
} else {
npcAbilitiesScroll.setSize(160, 130);
}
npcAbilitiesScroll.guiLeft = guiLeft + 210;
npcAbilitiesScroll.guiTop = y + 12;
updateNpcAbilitiesList();
addScroll(npcAbilitiesScroll);
// Center buttons: Add/Remove
int centerX = guiLeft + 158;
addButton(new GuiNpcButton(70, centerX, y + 40, 40, 20, ">>>")); // Add
addButton(new GuiNpcButton(71, centerX, y + 62, 40, 20, "<<<")); // Remove
// Load button (under the add/remove arrows)
addButton(new GuiNpcButton(75, centerX, y + 90, 40, 20, "gui.load"));
// Right side buttons: Edit and Up/Down carrots with Save button
addButton(new GuiNpcButton(72, guiLeft + 210, y + 145, 55, 20, "gui.edit"));
getButton(72).setEnabled(selectedAbilityIndex >= 0);
// Up/Down carrot buttons
addButton(new GuiNpcButton(73, guiLeft + 270, y + 145, 20, 20, "<"));
addButton(new GuiNpcButton(74, guiLeft + 292, y + 145, 20, 20, ">"));
getButton(73).setEnabled(selectedAbilityIndex > 0);
getButton(74).setEnabled(selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1);
// Save button (to the right of carrots, only enabled when ability is selected)
addButton(new GuiNpcButton(76, guiLeft + 320, y + 145, 50, 20, "gui.save"));
getButton(76).setEnabled(selectedAbilityIndex >= 0);
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
// Enabled toggle
if (id == 100) {
abilitiesEnabled = ((GuiNpcButton) guibutton).getValue() == 1;
save();
return;
}
// Add ability
if (id == 70) {
if (availableTypesScroll.hasSelected()) {
String displayName = availableTypesScroll.getSelected();
String typeId = getTypeIdFromDisplayName(displayName);
Ability newAbility = AbilityController.Instance.create(typeId);
if (newAbility != null) {
newAbility.setId("ability_" + System.currentTimeMillis());
// Don't set custom name - let it default to type name
npcAbilities.add(newAbility);
// Auto-select the newly added ability
selectedAbilityIndex = npcAbilities.size() - 1;
updateNpcAbilitiesList();
selectAbilityByIndex(selectedAbilityIndex);
initGui();
save();
}
}
return;
}
// Remove ability
if (id == 71) {
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
npcAbilities.remove(selectedAbilityIndex);
selectedAbilityIndex = -1;
updateNpcAbilitiesList();
initGui();
save();
}
return;
}
// Edit ability
if (id == 72) {
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
setSubGui(new SubGuiAbilityConfig(npcAbilities.get(selectedAbilityIndex), this));
}
return;
}
// Move up (carrot left = earlier in list)
if (id == 73) {
if (selectedAbilityIndex > 0) {
Ability temp = npcAbilities.get(selectedAbilityIndex);
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex - 1));
npcAbilities.set(selectedAbilityIndex - 1, temp);
selectedAbilityIndex--;
updateNpcAbilitiesList();
selectAbilityByIndex(selectedAbilityIndex);
initGui();
save();
}
return;
}
// Move down (carrot right = later in list)
if (id == 74) {
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1) {
Ability temp = npcAbilities.get(selectedAbilityIndex);
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex + 1));
npcAbilities.set(selectedAbilityIndex + 1, temp);
selectedAbilityIndex++;
updateNpcAbilitiesList();
selectAbilityByIndex(selectedAbilityIndex);
initGui();
save();
}
return;
}
// Load ability (opens load dialog to add ability directly to NPC)
if (id == 75) {
setSubGui(new SubGuiAbilityLoad(this));
return;
}
// Save selected ability
if (id == 76) {
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
Ability abilityToSave = npcAbilities.get(selectedAbilityIndex);
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
// Need a name to save - open edit dialog first
setSubGui(new SubGuiAbilityConfig(abilityToSave, this));
} else {
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave));
}
}
return;
}
initGui();
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
if (type == EnumScrollData.ABILITY_TYPES) {
allAbilityTypes.clear();
allAbilityTypes.putAll(data);
if (availableTypesScroll != null) {
availableTypesScroll.setList(getFilteredTypeList());
}
}
initGui();
}
@Override
public void setGuiData(NBTTagCompound compound) {
abilitiesEnabled = compound.getBoolean("AbilitiesEnabled");
globalCooldown = compound.hasKey("AbilityGlobalCooldown") ? compound.getInteger("AbilityGlobalCooldown") : 20;
npcAbilities.clear();
NBTTagList abilityList = compound.getTagList("Abilities", 10);
for (int i = 0; i < abilityList.tagCount(); i++) {
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
Ability ability = AbilityController.Instance.fromNBT(abilityNBT);
if (ability != null) {
npcAbilities.add(ability);
}
}
initGui();
}
@Override
public void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
if (k == 0 && availableTypesScroll != null) {
availableTypesScroll.mouseClicked(i, j, k);
}
}
@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();
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.resetScroll();
}
}
private List<String> getFilteredTypeList() {
List<String> list = new ArrayList<>();
for (String typeId : allAbilityTypes.keySet()) {
String displayName = getDisplayName(typeId);
if (search.isEmpty() || typeId.toLowerCase().contains(search) || displayName.toLowerCase().contains(search)) {
list.add(displayName);
}
}
return list;
}
/**
* Gets the typeId from a display name shown in the available types list.
*/
private String getTypeIdFromDisplayName(String displayName) {
for (String typeId : allAbilityTypes.keySet()) {
if (getDisplayName(typeId).equals(displayName)) {
return typeId;
}
}
return displayName;
}
private void updateNpcAbilitiesList() {
List<String> list = new ArrayList<>();
for (int i = 0; i < npcAbilities.size(); i++) {
list.add(getAbilityListEntry(i));
}
if (npcAbilitiesScroll != null) {
npcAbilitiesScroll.setList(list);
}
}
/**
* Creates the display entry for an ability in the list.
* Format: "[●] 1. Custom Name (Type)" or "[●] 1. Type" if no custom name
* Circle is green (§a) for enabled, red (§c) for disabled
*/
private String getAbilityListEntry(int index) {
Ability ability = npcAbilities.get(index);
String typeName = getDisplayName(ability.getTypeId());
String customName = ability.getName();
// Color prefix: green circle for enabled, red for disabled
String colorPrefix = ability.isEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
if (customName != null && !customName.isEmpty() && !customName.equals(typeName)) {
return colorPrefix + (index + 1) + ". " + customName + " (" + typeName + ")";
}
return colorPrefix + (index + 1) + ". " + typeName;
}
private void selectAbilityByIndex(int index) {
if (index >= 0 && index < npcAbilities.size()) {
String entry = getAbilityListEntry(index);
if (npcAbilitiesScroll != null) {
npcAbilitiesScroll.setSelected(entry);
}
}
}
/**
* Gets the localized display name for an ability type.
* Uses lang key "ability.type.cnpc_slam" for "cnpc:slam"
*/
private String getDisplayName(String typeId) {
// Convert "cnpc:slam" to lang key "ability.type.cnpc_slam"
String langKey = "ability.type." + typeId.replace(":", "_");
String translated = I18n.format(langKey);
// If translation exists and is different from key, use it
if (!translated.equals(langKey)) {
return translated;
}
// Fallback: Convert "cnpc:slam" to "Slam"
if (typeId.contains(":")) {
String name = typeId.substring(typeId.indexOf(":") + 1);
name = name.replace("_", " ");
StringBuilder sb = new StringBuilder();
for (String word : name.split(" ")) {
if (word.length() > 0) {
sb.append(Character.toUpperCase(word.charAt(0)));
if (word.length() > 1) {
sb.append(word.substring(1));
}
sb.append(" ");
}
}
return sb.toString().trim();
}
return typeId;
}
public void save() {
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("AbilitiesEnabled", abilitiesEnabled);
compound.setInteger("AbilityGlobalCooldown", globalCooldown);
NBTTagList abilityList = new NBTTagList();
for (Ability ability : npcAbilities) {
abilityList.appendTag(ability.writeNBT());
}
compound.setTag("Abilities", abilityList);
PacketClient.sendClient(new AbilitiesNpcSavePacket(compound));
}
/**
* Called from SubGuiAbilityLoad when a saved ability is loaded.
* Adds the ability to the NPC's ability list.
*/
public void loadAbility(Ability loadedAbility) {
if (loadedAbility != null) {
loadedAbility.setId("ability_" + System.currentTimeMillis());
npcAbilities.add(loadedAbility);
// Auto-select the newly added ability
selectedAbilityIndex = npcAbilities.size() - 1;
updateNpcAbilitiesList();
selectAbilityByIndex(selectedAbilityIndex);
initGui();
save();
}
}
@Override
public void setSelected(String selected) {
if (availableTypesScroll != null) {
availableTypesScroll.setSelected(selected);
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll == npcAbilitiesScroll) {
String selected = npcAbilitiesScroll.getSelected();
if (selected != null) {
// Parse index from "[●] 1. Name" format - strip color codes first
String stripped = selected.replaceAll("\u00A7.", "").trim();
// Now format is "● 1. Name" - find the number after the circle
int dotIndex = stripped.indexOf(".");
if (dotIndex > 0) {
try {
// Extract just the number portion (skip "● " prefix)
String numPart = stripped.substring(0, dotIndex).replaceAll("[^0-9]", "");
selectedAbilityIndex = Integer.parseInt(numPart) - 1;
} catch (NumberFormatException e) {
selectedAbilityIndex = -1;
}
}
}
initGui();
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (scroll == npcAbilitiesScroll && selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
setSubGui(new SubGuiAbilityConfig(npcAbilities.get(selectedAbilityIndex), this));
}
}
@Override
public void unFocused(GuiNpcTextField textField) {
if (textField.id == 101) {
globalCooldown = textField.getInteger();
save();
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if (subgui instanceof SubGuiAbilityConfig) {
// Ability was saved in the SubGui, refresh list
updateNpcAbilitiesList();
save();
}
}
/**
* Called from SubGuiAbilityConfig when ability is saved.
*/
public void onAbilitySaved(Ability ability) {
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
npcAbilities.set(selectedAbilityIndex, ability);
updateNpcAbilitiesList();
save();
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,55 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
/**
* Confirmation dialog for deleting an ability preset.
*/
public class SubGuiAbilityDeleteConfirm extends SubGuiInterface {
private final String abilityName;
private final SubGuiAbilityLoad loadGui;
public SubGuiAbilityDeleteConfirm(String abilityName, SubGuiAbilityLoad loadGui) {
this.abilityName = abilityName;
this.loadGui = loadGui;
setBackground("menubg.png");
xSize = 200;
ySize = 100;
}
@Override
public void initGui() {
super.initGui();
int y = guiTop + 10;
addLabel(new GuiNpcLabel(0, "ability.delete.confirm", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + abilityName + "'?", guiLeft + 10, y));
y += 30;
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id == 0) {
// Delete the ability
AbilityController.Instance.deleteAbility(abilityName);
loadGui.onAbilityDeleted(abilityName);
close();
} else if (id == 1) {
close();
}
}
}
@@ -0,0 +1,134 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Dialog for loading a saved ability preset.
* Can be opened from SubGuiAbilityConfig (to load into editing ability)
* or from GuiNPCAbilities (to add ability directly to NPC).
*/
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener {
private final SubGuiAbilityConfig parentConfig;
private final GuiNPCAbilities parentAbilities;
private String selectedName = null;
private List<String> abilityNames = new ArrayList<>();
public SubGuiAbilityLoad(SubGuiAbilityConfig parentConfig) {
this.parentConfig = parentConfig;
this.parentAbilities = null;
setBackground("menubg.png");
xSize = 220;
ySize = 180;
}
public SubGuiAbilityLoad(GuiNPCAbilities parentAbilities) {
this.parentConfig = null;
this.parentAbilities = parentAbilities;
setBackground("menubg.png");
xSize = 220;
ySize = 180;
}
@Override
public void initGui() {
super.initGui();
// Load ability names
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
abilityNames = new ArrayList<>(names);
int y = guiTop + 5;
addLabel(new GuiNpcLabel(0, "ability.load.select", guiLeft + 10, y));
y += 14;
// Scroll list of saved abilities
GuiCustomScroll scroll = new GuiCustomScroll(this, 0);
scroll.setSize(200, 110);
scroll.guiLeft = guiLeft + 10;
scroll.guiTop = y;
scroll.setUnsortedList(abilityNames);
if (selectedName != null && abilityNames.contains(selectedName)) {
scroll.setSelected(selectedName);
}
addScroll(scroll);
y += 115;
// Buttons
addButton(new GuiNpcButton(0, guiLeft + 10, y, 60, 20, "gui.load"));
addButton(new GuiNpcButton(1, guiLeft + 80, y, 60, 20, "gui.delete"));
addButton(new GuiNpcButton(2, guiLeft + 150, y, 60, 20, "gui.cancel"));
// Disable load/delete if nothing selected
getButton(0).setEnabled(selectedName != null && !selectedName.isEmpty());
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id == 0 && selectedName != null) {
// Load the selected ability
Ability loaded = AbilityController.Instance.getSavedAbility(selectedName);
if (loaded != null) {
if (parentConfig != null) {
parentConfig.loadAbility(loaded);
} else if (parentAbilities != null) {
parentAbilities.loadAbility(loaded);
}
}
close();
} else if (id == 1 && selectedName != null) {
// Delete confirmation
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, this));
} else if (id == 2) {
close();
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0) {
selectedName = scroll.getSelected();
initGui();
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
// Double-click to load immediately
Ability loaded = AbilityController.Instance.getSavedAbility(selection);
if (loaded != null) {
if (parentConfig != null) {
parentConfig.loadAbility(loaded);
} else if (parentAbilities != null) {
parentAbilities.loadAbility(loaded);
}
}
close();
}
}
/**
* Called after an ability is deleted to refresh the list.
*/
public void onAbilityDeleted(String name) {
if (name.equals(selectedName)) {
selectedName = null;
}
initGui();
}
}
@@ -0,0 +1,61 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.SubGuiInterface;
/**
* Confirmation dialog for saving an ability preset.
*/
public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
private final Ability ability;
private final boolean exists;
public SubGuiAbilitySaveConfirm(Ability ability) {
this.ability = ability;
this.exists = AbilityController.Instance.hasSavedAbility(ability.getName());
setBackground("menubg.png");
xSize = 200;
ySize = 100;
}
@Override
public void initGui() {
super.initGui();
int y = guiTop + 10;
if (exists) {
addLabel(new GuiNpcLabel(0, "ability.save.overwrite", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
} else {
addLabel(new GuiNpcLabel(0, "ability.save.confirm", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
}
y += 30;
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id == 0) {
// Save the ability
AbilityController.Instance.saveAbility(ability);
close();
} else if (id == 1) {
close();
}
}
}
@@ -0,0 +1,163 @@
package noppes.npcs.client.gui.global;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
import noppes.npcs.client.gui.advanced.SubGuiAbilityDeleteConfirm;
import noppes.npcs.client.gui.advanced.SubGuiAbilityLoad;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.*;
/**
* Global GUI for managing saved ability presets.
* Allows viewing, editing, and deleting saved abilities.
*/
public class GuiNpcManageAbilities extends GuiNPCInterface2 implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback {
private GuiCustomScroll scroll;
private String selectedName = null;
private List<String> abilityNames = new ArrayList<>();
private String search = "";
public GuiNpcManageAbilities(EntityNPCInterface npc) {
super(npc);
loadAbilityNames();
}
private void loadAbilityNames() {
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
abilityNames = new ArrayList<>(names);
}
@Override
public void initGui() {
super.initGui();
int y = guiTop + 10;
// Title label
addLabel(new GuiNpcLabel(0, "ability.manager.title", guiLeft + 10, y));
y += 20;
// Scroll list of saved abilities
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
}
scroll.setSize(xSize - 90, 160);
scroll.guiLeft = guiLeft + 10;
scroll.guiTop = y;
scroll.setUnsortedList(getFilteredList());
if (selectedName != null && abilityNames.contains(selectedName)) {
scroll.setSelected(selectedName);
}
addScroll(scroll);
// Search bar
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 10, y + 163, xSize - 90, 18, search));
// Right side buttons
int btnX = guiLeft + xSize - 70;
addButton(new GuiNpcButton(1, btnX, y, 60, 20, "gui.edit"));
addButton(new GuiNpcButton(2, btnX, y + 25, 60, 20, "gui.delete"));
addButton(new GuiNpcButton(3, btnX, y + 60, 60, 20, "selectServer.refresh"));
// Enable/disable buttons based on selection
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
getButton(2).setEnabled(selectedName != null && !selectedName.isEmpty());
}
private List<String> getFilteredList() {
if (search.isEmpty()) {
return new ArrayList<>(abilityNames);
}
List<String> filtered = new ArrayList<>();
for (String name : abilityNames) {
if (name.toLowerCase().contains(search.toLowerCase())) {
filtered.add(name);
}
}
return filtered;
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id == 1 && selectedName != null) {
// Edit
Ability ability = AbilityController.Instance.getSavedAbility(selectedName);
if (ability != null) {
setSubGui(new SubGuiAbilityConfig(ability, this));
}
} else if (id == 2 && selectedName != null) {
// Delete
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, null));
} else if (id == 3) {
// Refresh
AbilityController.Instance.load();
loadAbilityNames();
selectedName = null;
initGui();
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0) {
selectedName = scroll.getSelected();
initGui();
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
// Double-click to edit
Ability ability = AbilityController.Instance.getSavedAbility(selection);
if (ability != null) {
setSubGui(new SubGuiAbilityConfig(ability, this));
}
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(1) != null && getTextField(1).isFocused()) {
if (!search.equals(getTextField(1).getText())) {
search = getTextField(1).getText();
scroll.setUnsortedList(getFilteredList());
scroll.resetScroll();
}
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
// Refresh list after any sub gui closes
loadAbilityNames();
if (subgui instanceof SubGuiAbilityDeleteConfirm) {
// After delete, clear selection if it was deleted
if (selectedName != null && !abilityNames.contains(selectedName)) {
selectedName = null;
}
}
initGui();
}
@Override
public void onAbilitySaved(Ability ability) {
// Save the edited ability
AbilityController.Instance.saveAbility(ability);
loadAbilityNames();
initGui();
}
@Override
public void save() {
// Nothing to save - abilities are saved individually
}
}
@@ -38,6 +38,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
private GuiNpcSquareButton tagButton;
private GuiNpcSquareButton effectsButton;
private GuiNpcSquareButton magicsButton;
private GuiNpcSquareButton abilitiesButton;
public GuiNPCGlobalMainMenu(EntityNPCInterface npc) {
super(npc, 5);
@@ -94,6 +95,8 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
registerButton(magicsButton = new GuiNpcSquareButton(20, 0, 0, 20, "global.magic", 0xFF333333));
magicsButton.setIconPos(24, 24, 48, 56).setIconTexture(specialIcons);
registerButton(abilitiesButton = new GuiNpcSquareButton(21, 0, 0, 20, "global.abilities", 0xFF333333));
abilitiesButton.setIconPos(24, 24, 72, 56).setIconTexture(specialIcons); // Placeholder icon position
// Layout composite buttons optimally.
layoutButtons();
@@ -236,6 +239,9 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
if (id == 19) {
NoppesUtil.requestOpenGUI(EnumGuiType.ManageEffects);
}
if (id == 21) {
NoppesUtil.openGUI(player, new noppes.npcs.client.gui.global.GuiNpcManageAbilities(npc));
}
}
@Override
@@ -13,6 +13,7 @@ import noppes.npcs.client.gui.advanced.GuiNPCAdvancedLinkedNpc;
import noppes.npcs.client.gui.advanced.GuiNPCDialogNpcOptions;
import noppes.npcs.client.gui.advanced.GuiNPCFactionSetup;
import noppes.npcs.client.gui.advanced.GuiNPCLinesMenu;
import noppes.npcs.client.gui.advanced.GuiNPCAbilities;
import noppes.npcs.client.gui.advanced.GuiNPCMagic;
import noppes.npcs.client.gui.advanced.GuiNPCMarks;
import noppes.npcs.client.gui.advanced.GuiNPCNightSetup;
@@ -69,6 +70,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks"));
this.addButton(new GuiNpcButton(16, guiLeft + 15, y += 22, 190, 20, "menu.magics"));
this.addButton(new GuiNpcButton(17, guiLeft + 208, y, 190, 20, "menu.abilities"));
}
@Override
@@ -130,6 +132,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
save();
NoppesUtil.openGUI(player, new GuiNPCMagic(npc));
}
if (button.id == 17) {
save();
NoppesUtil.openGUI(player, new GuiNPCAbilities(npc));
}
}
@Override
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.script;
import kamkeel.npcs.network.packets.request.script.EventScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.data.DataScript;
import noppes.npcs.entity.EntityNPCInterface;
@@ -15,23 +16,30 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
public GuiNPCEventScripts(EntityNPCInterface npc) {
this.hookList = new ArrayList<>();
hookList.add("init");
hookList.add("tick");
hookList.add("interact");
hookList.add("dialog");
hookList.add("damaged");
hookList.add("killed");
hookList.add("meleeAttack");
hookList.add("meleeSwing");
hookList.add("rangedLaunched");
hookList.add("target");
hookList.add("collide");
hookList.add("kills");
hookList.add("dialogClose");
hookList.add("timer");
hookList.add("targetLost");
hookList.add("projectileTick");
hookList.add("projectileImpact");
hookList.add(EnumScriptType.INIT.function);
hookList.add(EnumScriptType.TICK.function);
hookList.add(EnumScriptType.INTERACT.function);
hookList.add(EnumScriptType.DIALOG.function);
hookList.add(EnumScriptType.DAMAGED.function);
hookList.add(EnumScriptType.KILLED.function);
hookList.add(EnumScriptType.ATTACK_MELEE.function);
hookList.add(EnumScriptType.ATTACK_SWING.function);
hookList.add(EnumScriptType.RANGED_LAUNCHED.function);
hookList.add(EnumScriptType.TARGET.function);
hookList.add(EnumScriptType.COLLIDE.function);
hookList.add(EnumScriptType.KILLS.function);
hookList.add(EnumScriptType.DIALOG_CLOSE.function);
hookList.add(EnumScriptType.TIMER.function);
hookList.add(EnumScriptType.TARGET_LOST.function);
hookList.add(EnumScriptType.PROJECTILE_TICK.function);
hookList.add(EnumScriptType.PROJECTILE_IMPACT.function);
// Ability hooks
hookList.add(EnumScriptType.ABILITY_START.function);
hookList.add(EnumScriptType.ABILITY_EXECUTE.function);
hookList.add(EnumScriptType.ABILITY_INTERRUPT.function);
hookList.add(EnumScriptType.ABILITY_COMPLETE.function);
hookList.add(EnumScriptType.ABILITY_HIT.function);
hookList.add(EnumScriptType.ABILITY_TICK.function);
this.script = new DataScript(npc);
this.handler = this.script;
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.script;
import kamkeel.npcs.network.packets.request.script.GlobalNPCScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.data.GlobalNPCDataScript;
@@ -12,23 +13,30 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
private final GlobalNPCDataScript script = new GlobalNPCDataScript(null);
public GuiScriptAllNPCs() {
hookList.add("init");
hookList.add("tick");
hookList.add("interact");
hookList.add("dialog");
hookList.add("damaged");
hookList.add("killed");
hookList.add("meleeAttack");
hookList.add("meleeSwing");
hookList.add("rangedLaunched");
hookList.add("target");
hookList.add("collide");
hookList.add("kills");
hookList.add("dialogClose");
hookList.add("timer");
hookList.add("targetLost");
hookList.add("projectileTick");
hookList.add("projectileImpact");
hookList.add(EnumScriptType.INIT.function);
hookList.add(EnumScriptType.TICK.function);
hookList.add(EnumScriptType.INTERACT.function);
hookList.add(EnumScriptType.DIALOG.function);
hookList.add(EnumScriptType.DAMAGED.function);
hookList.add(EnumScriptType.KILLED.function);
hookList.add(EnumScriptType.ATTACK_MELEE.function);
hookList.add(EnumScriptType.ATTACK_SWING.function);
hookList.add(EnumScriptType.RANGED_LAUNCHED.function);
hookList.add(EnumScriptType.TARGET.function);
hookList.add(EnumScriptType.COLLIDE.function);
hookList.add(EnumScriptType.KILLS.function);
hookList.add(EnumScriptType.DIALOG_CLOSE.function);
hookList.add(EnumScriptType.TIMER.function);
hookList.add(EnumScriptType.TARGET_LOST.function);
hookList.add(EnumScriptType.PROJECTILE_TICK.function);
hookList.add(EnumScriptType.PROJECTILE_IMPACT.function);
// Ability hooks
hookList.add(EnumScriptType.ABILITY_START.function);
hookList.add(EnumScriptType.ABILITY_EXECUTE.function);
hookList.add(EnumScriptType.ABILITY_INTERRUPT.function);
hookList.add(EnumScriptType.ABILITY_COMPLETE.function);
hookList.add(EnumScriptType.ABILITY_HIT.function);
hookList.add(EnumScriptType.ABILITY_TICK.function);
this.handler = this.script;
GlobalNPCScriptPacket.Get();
@@ -0,0 +1,175 @@
package noppes.npcs.client.gui.select;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
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.IScrollData;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.constants.EnumScrollData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
/**
* Animation selection dialog for choosing global animations.
* Requests animation data from the server via packets.
*/
public class GuiAnimationSelection extends SubGuiInterface implements ICustomScrollListener, IScrollData {
private GuiCustomScroll scrollAnimations;
private HashMap<String, Integer> animationData = new HashMap<String, Integer>();
private int initialAnimationId;
public int selectedAnimationId = -1;
private String selectedName = null;
private String search = "";
public GuiAnimationSelection(int animationId) {
drawDefaultBackground = false;
title = "";
setBackground("menubg.png");
xSize = 220;
ySize = 226;
this.initialAnimationId = animationId;
this.selectedAnimationId = animationId;
// Request animation data from server
PacketClient.sendClient(new AnimationsGetPacket());
}
@Override
public void initGui() {
super.initGui();
this.addLabel(new GuiNpcLabel(0, "gui.animations", guiLeft + 8, guiTop + 4));
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 50, 20, "gui.clear"));
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done"));
this.addButton(new GuiNpcButton(3, guiLeft + xSize - 108, guiTop + ySize - 35, 50, 20, "gui.cancel"));
if (scrollAnimations == null) {
scrollAnimations = new GuiCustomScroll(this, 0, 0);
scrollAnimations.setSize(212, 163);
}
scrollAnimations.setList(getSearchList());
if (selectedName != null) {
scrollAnimations.setSelected(selectedName);
}
scrollAnimations.guiLeft = guiLeft + 4;
scrollAnimations.guiTop = guiTop + 14;
this.addScroll(scrollAnimations);
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 179, 212, 20, search));
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
this.animationData = data;
// Find the name for our initial animation ID
if (initialAnimationId >= 0) {
for (String name : data.keySet()) {
if (data.get(name) == initialAnimationId) {
selectedName = name;
break;
}
}
}
if (scrollAnimations != null) {
scrollAnimations.setList(getSearchList());
if (selectedName != null) {
scrollAnimations.setSelected(selectedName);
}
}
}
@Override
public void setSelected(String selected) {
this.selectedName = selected;
if (scrollAnimations != null) {
scrollAnimations.setSelected(selected);
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(55) != null) {
if (getTextField(55).isFocused()) {
if (search.equals(getTextField(55).getText()))
return;
search = getTextField(55).getText().toLowerCase();
scrollAnimations.resetScroll();
scrollAnimations.setList(getSearchList());
}
}
}
private List<String> getSearchList() {
if (search.isEmpty()) {
return new ArrayList<String>(animationData.keySet());
}
List<String> list = new ArrayList<String>();
for (String name : animationData.keySet()) {
if (name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0) {
String selected = scrollAnimations.getSelected();
if (selected != null && animationData.containsKey(selected)) {
selectedName = selected;
selectedAnimationId = animationData.get(selected);
}
}
initGui();
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (selectedAnimationId < 0)
return;
close();
}
@Override
protected void actionPerformed(GuiButton guibutton) {
int id = guibutton.id;
if (id == 1) {
// Clear selection
selectedName = null;
selectedAnimationId = -1;
close();
}
if (id == 2) {
// Done - keep selection
close();
}
if (id == 3) {
// Cancel - restore initial value
selectedAnimationId = initialAnimationId;
close();
}
}
/**
* Get the name of the selected animation (for display purposes).
*/
public String getSelectedName() {
return selectedName;
}
}
@@ -0,0 +1,15 @@
package noppes.npcs.client.gui.util;
import kamkeel.npcs.controllers.data.ability.Ability;
/**
* Callback interface for SubGuiAbilityConfig.
* Implemented by GUIs that open the ability config dialog.
*/
public interface IAbilityConfigCallback {
/**
* Called when an ability has been edited and saved.
* @param ability The edited ability
*/
void onAbilitySaved(Ability ability);
}