mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 23:39:50 +00:00
Ability Preview GUI
This commit is contained in:
1 parent
216a3dbbf8
commit
55658a7956
37 files changed
+2396
-162
No files matched your search
@@ -2,28 +2,39 @@ 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.SavedAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.SavedAbilityGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
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.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* Uses packet-based communication for proper client-server architecture.
|
||||
*/
|
||||
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener {
|
||||
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener, IScrollData, IGuiData {
|
||||
|
||||
private final SubGuiAbilityConfig parentConfig;
|
||||
private final GuiNPCAbilities parentAbilities;
|
||||
private String selectedName = null;
|
||||
private List<String> abilityNames = new ArrayList<>();
|
||||
private HashMap<String, Integer> abilityData = new HashMap<>();
|
||||
private GuiCustomScroll scroll;
|
||||
|
||||
// Track if we're waiting for a load
|
||||
private boolean waitingForLoad = false;
|
||||
|
||||
public SubGuiAbilityLoad(SubGuiAbilityConfig parentConfig) {
|
||||
this.parentConfig = parentConfig;
|
||||
@@ -32,6 +43,9 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
|
||||
// Request ability list from server
|
||||
PacketClient.sendClient(new SavedAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
public SubGuiAbilityLoad(GuiNPCAbilities parentAbilities) {
|
||||
@@ -41,28 +55,29 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
|
||||
// Request ability list from server
|
||||
PacketClient.sendClient(new SavedAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
@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);
|
||||
if (scroll == null) {
|
||||
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.setList(getFilteredList());
|
||||
if (selectedName != null && abilityData.containsKey(selectedName)) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
@@ -70,13 +85,15 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
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"));
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.load"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 115, y, 95, 20, "gui.cancel"));
|
||||
|
||||
// Disable load/delete if nothing selected
|
||||
// Disable load if nothing selected
|
||||
getButton(0).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
}
|
||||
|
||||
private List<String> getFilteredList() {
|
||||
return new ArrayList<>(abilityData.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,19 +101,9 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
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));
|
||||
// Request ability data from server
|
||||
waitingForLoad = true;
|
||||
PacketClient.sendClient(new SavedAbilityGetPacket(selectedName));
|
||||
} else if (id == 2) {
|
||||
close();
|
||||
}
|
||||
@@ -113,8 +120,34 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
@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);
|
||||
// Double-click to load - request from server
|
||||
selectedName = selection;
|
||||
waitingForLoad = true;
|
||||
PacketClient.sendClient(new SavedAbilityGetPacket(selection));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.ABILITIES) {
|
||||
String name = scroll != null ? scroll.getSelected() : null;
|
||||
this.abilityData = data;
|
||||
if (scroll != null) {
|
||||
scroll.setList(getFilteredList());
|
||||
if (name != null && abilityData.containsKey(name)) {
|
||||
scroll.setSelected(name);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// Received ability data from server
|
||||
if (waitingForLoad) {
|
||||
waitingForLoad = false;
|
||||
Ability loaded = AbilityController.Instance.fromNBT(compound);
|
||||
if (loaded != null) {
|
||||
if (parentConfig != null) {
|
||||
parentConfig.loadAbility(loaded);
|
||||
@@ -126,13 +159,11 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after an ability is deleted to refresh the list.
|
||||
*/
|
||||
public void onAbilityDeleted(String name) {
|
||||
if (name.equals(selectedName)) {
|
||||
selectedName = null;
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selectedName = selected;
|
||||
if (scroll != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user