mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 22:27:32 +00:00
Fix some Selection Handling for Abilities
This commit is contained in:
1 parent
b59f0b8f2f
commit
2ba2372bde
4 files changed
+65
-23
No files matched your search
@@ -794,11 +794,10 @@ public class NoppesUtilServer {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
AbilityController controller = AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String name : controller.getAbilityNames()) {
|
||||
Ability ability = controller.getAbility(name);
|
||||
if (ability != null) {
|
||||
map.put(ability.getName(), index++);
|
||||
map.put(ability.getName(), ability.getAllowedBy().ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -809,11 +808,10 @@ public class NoppesUtilServer {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
AbilityController controller = AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String name : controller.getCustomAbilityNames()) {
|
||||
Ability ability = controller.getCustomAbility(name);
|
||||
if (ability == null || !ability.getAllowedBy().allowsNpc()) continue;
|
||||
map.put(name, index++);
|
||||
if (ability == null) continue;
|
||||
map.put(name, ability.getAllowedBy().ordinal());
|
||||
}
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.CUSTOM_ABILITIES);
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
@@ -21,6 +22,7 @@ import noppes.npcs.constants.EnumScrollData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -98,14 +100,18 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
}
|
||||
|
||||
private List<String> getFilteredList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(rawData.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : rawData.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
for (Map.Entry<String, Integer> entry : rawData.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
|
||||
// Only show NPC-valid abilities (NPC_ONLY or BOTH)
|
||||
UserType ut = UserType.fromOrdinal(entry.getValue());
|
||||
if (!ut.allowsNpc()) continue;
|
||||
|
||||
if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -15,6 +16,7 @@ import noppes.npcs.constants.EnumScrollData;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -93,14 +95,18 @@ public class SubGuiAbilitySelect extends SubGuiInterface implements ICustomScrol
|
||||
merged.putAll(builtInData);
|
||||
}
|
||||
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(merged.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : merged.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
for (Map.Entry<String, Integer> entry : merged.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
|
||||
// Only show NPC-valid abilities (NPC_ONLY or BOTH)
|
||||
UserType ut = UserType.fromOrdinal(entry.getValue());
|
||||
if (!ut.allowsNpc()) continue;
|
||||
|
||||
if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -48,6 +49,7 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -72,6 +74,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private static final int BTN_PREVIEW_PLAY = 91;
|
||||
private static final int BTN_PREVIEW_PAUSE = 92;
|
||||
private static final int BTN_PREVIEW_STOP = 93;
|
||||
private static final int BTN_USER_TYPE_FILTER = 11;
|
||||
|
||||
// ── TextField / Label IDs ─────────────────────────────────────────────────
|
||||
private static final int TF_SEARCH = 55;
|
||||
@@ -99,6 +102,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private boolean showingChained = false;
|
||||
private boolean currentIsBuiltIn = false;
|
||||
|
||||
// ==================== USER TYPE FILTER ====================
|
||||
// 0 = Both, 1 = NPC Only, 2 = Player Only
|
||||
private int userTypeFilter = 0;
|
||||
private static final String[] USER_TYPE_FILTER_LABELS = {"gui.both", "gui.npcs", "gui.players"};
|
||||
|
||||
// ==================== CHAINED DATA ====================
|
||||
private HashMap<String, Integer> chainedData = new HashMap<>();
|
||||
private ChainedAbility selectedChain = null;
|
||||
@@ -176,6 +184,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
// Search bar
|
||||
addTextField(new GuiNpcTextField(TF_SEARCH, this, fontRendererObj, guiLeft + 220, guiTop + 192, 143, 20, search));
|
||||
|
||||
// User type filter button (only for Custom and Built-in views)
|
||||
if (!showingChained) {
|
||||
addButton(new GuiNpcButton(BTN_USER_TYPE_FILTER, guiLeft + 368, guiTop + 192, 45, 20, USER_TYPE_FILTER_LABELS[userTypeFilter]));
|
||||
}
|
||||
|
||||
// Check if we have something to preview
|
||||
if (showingChained) {
|
||||
if (selectedChain == null || selected == null || selectedChain.getEntries().isEmpty()) {
|
||||
@@ -213,14 +226,23 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
private List<String> getSearchList() {
|
||||
HashMap<String, Integer> data = getCurrentData();
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(data.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : data.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
for (Map.Entry<String, Integer> entry : data.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
|
||||
// Apply search filter
|
||||
if (!search.isEmpty() && !name.toLowerCase().contains(search.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Apply UserType filter (only for Custom and Built-in views)
|
||||
if (!showingChained && userTypeFilter != 0) {
|
||||
UserType ut = UserType.fromOrdinal(entry.getValue());
|
||||
if (userTypeFilter == 1 && !ut.allowsNpc()) continue;
|
||||
if (userTypeFilter == 2 && !ut.allowsPlayer()) continue;
|
||||
}
|
||||
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -278,6 +300,16 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
int id = guibutton.id;
|
||||
|
||||
// User type filter: Both → NPC → Player → Both
|
||||
if (id == BTN_USER_TYPE_FILTER) {
|
||||
userTypeFilter = (userTypeFilter + 1) % 3;
|
||||
if (scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle: Custom → Built-in → Chained → Custom
|
||||
if (id == BTN_TOGGLE_VIEW) {
|
||||
if (!showingBuiltIn && !showingChained) {
|
||||
|
||||
Reference in new issue
Block a user