More work on the party GUI, which can now properly start a party. Created a party controller.

This commit is contained in:
luisc committed 2024-01-10 22:14:00 -06:00
1 parent 0ecc94bdb0
commit 2ef38dfdf4
6 files changed
+263 -23

No files matched your search

@@ -111,6 +111,26 @@ public class PacketHandlerServer{
} else if (type == EnumPacketServer.CacheAnimation) {
PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt());
return;
} else if (type == EnumPacketServer.GetPartyData || type == EnumPacketServer.CreateParty) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (type == EnumPacketServer.CreateParty) {
Party party = PartyController.Instance().createParty();
party.addPlayer(player);
party.setLeader(player);
}
NBTTagCompound compound = new NBTTagCompound();
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
compound = party.writeToNBT();
Quest quest = (Quest) QuestController.Instance.get(party.getCurrentQuestID());
if (quest != null) {
compound.setString("QuestName", quest.getName());
compound.setString("QuestCategory", quest.getCategory().getName());
}
}
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
if(type.needsNpc && npc == null){
@@ -7,6 +7,7 @@ import noppes.npcs.client.gui.OverlayQuestTracking;
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.SkinOverlay;
import noppes.npcs.util.CacheHashMap;
@@ -22,6 +23,8 @@ public class ClientCacheHandler {
public static HashMap<UUID, HashMap<Integer, SkinOverlay>> skinOverlays = new HashMap<>();
public static HashMap<UUID, AnimationData> playerAnimations = new HashMap<>();
public static Party party;
public static ImageData getImageData(String directory) {
synchronized (imageDataCache) {
if (!imageDataCache.containsKey(directory)) {
@@ -47,5 +50,6 @@ public class ClientCacheHandler {
ClientCacheHandler.customOverlays.clear();
ClientCacheHandler.skinOverlays.clear();
ClientCacheHandler.playerAnimations.clear();
party = null;
}
}
@@ -8,13 +8,19 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import noppes.npcs.CustomItems;
import noppes.npcs.client.Client;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Party;
import org.lwjgl.opengl.GL11;
import tconstruct.client.tabs.InventoryTabQuests;
import tconstruct.client.tabs.TabRegistry;
public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICustomScrollListener, IGuiData {
import java.util.UUID;
public class GuiParty extends GuiNPCInterface implements ITextfieldListener, ITopButtonListener,ICustomScrollListener, IGuiData {
private final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/standardbg.png");
private final EntityPlayer player;
@@ -28,10 +34,12 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus
ySize = 180;
drawDefaultBackground = false;
//TODO: Send initial data packet
Client.sendData(EnumPacketServer.GetPartyData);
}
public void initGui(){
Party party = ClientCacheHandler.party;
super.initGui();
guiTop +=10;
@@ -48,10 +56,93 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus
partyButton.active = true;
partyButton.renderStack = new ItemStack(CustomItems.bag);
addButton(partyButton);
if (receivedData) {
if (party == null) {
//
//create party button
//
GuiNpcButton createPartyButton = new GuiNpcButton(200, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 20, "Create Party");
createPartyButton.width = 100;
this.addButton(createPartyButton);
this.addLabel(new GuiNpcLabel(201, "You're not in a party!", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 30));
this.addLabel(new GuiNpcLabel(202, "Either wait for an invite", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 20));
this.addLabel(new GuiNpcLabel(203, "or create one.", guiLeft + xSize/2 + 30, guiTop + ySize/2 - 10));
//party invites list
//
GuiCustomScroll inviteScroll = new GuiCustomScroll(this, 210, false);
inviteScroll.setSize(150, 160);
inviteScroll.guiLeft = guiLeft + 5;
inviteScroll.guiTop = guiTop + 5;
this.addScroll(inviteScroll);
GuiNpcButton acceptButton = new GuiNpcButton(215, guiLeft + 15, guiTop + ySize - 12, "Accept");
acceptButton.width = 60;
this.addButton(acceptButton);
GuiNpcButton ignoreButton = new GuiNpcButton(220, guiLeft + 80, guiTop + ySize - 12, "Ignore");
ignoreButton.width = 60;
this.addButton(ignoreButton);
} else {
//
//party player list
//
GuiCustomScroll playerScroll = new GuiCustomScroll(this, 300, false);
playerScroll.setSize(150, 160);
playerScroll.guiLeft = guiLeft + 5;
playerScroll.guiTop = guiTop + 5;
this.addScroll(playerScroll);
//set leader button
//
GuiNpcButton leaderButton = new GuiNpcButton(305, guiLeft + 5, guiTop + ySize - 12, "Make Leader");
leaderButton.width = 70;
this.addButton(leaderButton);
//kick player button
//
GuiNpcButton kickButton = new GuiNpcButton(315, guiLeft + 85, guiTop + ySize - 12, "Kick");
kickButton.width = 70;
this.addButton(kickButton);
//toggle friendly fire
//
GuiNpcButton friendlyFireButton = new GuiNpcButton(320, guiLeft + xSize/2 + 95, guiTop + ySize/2, new String[] {"On", "Off"}, 0); //party.friendlyFire() ? 0 : 1
friendlyFireButton.width = 40;
this.addButton(friendlyFireButton);
GuiNpcLabel friendlyFireLabel = new GuiNpcLabel(321, "Friendly Fire:", guiLeft + xSize/2 + 20, guiTop + ySize/2 + 5);
this.addLabel(friendlyFireLabel);
//send invite button (opens subgui)
//
GuiNpcTextField playerTextField = new GuiNpcTextField(325, this, guiLeft + xSize/2 + 20, guiTop + ySize/2 + 40,100, 20, "");
this.addTextField(playerTextField);
GuiNpcButton inviteButton = new GuiNpcButton(330, guiLeft + xSize/2 + 125, guiTop + ySize/2 + 40, "Invite");
inviteButton.width = 50;
this.addButton(inviteButton);
//disband party
//
GuiNpcButton disbandButton = new GuiNpcButton(335, guiLeft + xSize/2 + 45, guiTop + ySize/2 + 70, "Disband Party");
disbandButton.width = 100;
this.addButton(disbandButton);
}
}
}
@Override
protected void actionPerformed(GuiButton guibutton){
switch (guibutton.id) {
case 200:
Client.sendData(EnumPacketServer.CreateParty);
receivedData = false;
break;
}
initGui();
if (guibutton.id == 100) {
@@ -77,17 +168,19 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus
periods += ".";
}
fontRendererObj.drawString(StatCollector.translateToLocal("gui.loading") + periods,guiLeft + xSize/2,guiTop + 80, CustomNpcResourceListener.DefaultTextColor);
return;
}
}
@Override
public void keyTyped(char c, int i)
{
if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key
{
mc.displayGuiScreen(null);
mc.setIngameFocus();
super.keyTyped(c, i);
if (!GuiNpcTextField.isFieldActive()) {
if (i == 1 || i == mc.gameSettings.keyBindInventory.getKeyCode()) // inventory key
{
mc.displayGuiScreen(null);
mc.setIngameFocus();
}
}
}
@@ -100,6 +193,17 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus
@Override
public void setGuiData(NBTTagCompound compound) {
this.receivedData = true;
if (compound.hasKey("PartyUUID")) {
Party party = ClientCacheHandler.party;
UUID uuid = UUID.fromString(compound.getString("PartyUUID"));
if (party == null || !party.getPartyUUID().equals(uuid)) {
ClientCacheHandler.party = new Party(uuid);
party = ClientCacheHandler.party;
}
party.readFromNBT(compound);
}
initGui();
}
@@ -118,4 +222,9 @@ public class GuiParty extends GuiNPCInterface implements ITopButtonListener,ICus
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
}
@Override
public void unFocused(GuiNpcTextField textfield) {
}
}
@@ -95,7 +95,7 @@ public enum EnumPacketServer {
CustomGuiButton,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused,
CreateParty,
CreateParty, GetPartyData,
ServerUpdateSkinOverlays;
@@ -0,0 +1,36 @@
package noppes.npcs.controllers;
import noppes.npcs.controllers.data.Party;
import java.util.HashMap;
import java.util.UUID;
public class PartyController {
private static PartyController Instance;
private HashMap<UUID, Party> parties = new HashMap<>();
private PartyController() {
}
public static PartyController Instance() {
if (Instance == null) {
Instance = new PartyController();
}
return Instance;
}
public Party createParty() {
Party party = new Party();
this.parties.put(party.getPartyUUID(), party);
return party;
}
public Party getParty(UUID partyUUID) {
return this.parties.get(partyUUID);
}
public void deleteParty(UUID partyUUID) {
this.parties.remove(partyUUID);
}
}
@@ -2,7 +2,13 @@ package noppes.npcs.controllers.data;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.api.handler.IPlayerQuestData;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.controllers.PlayerDataController;
@@ -14,8 +20,7 @@ import java.net.URL;
import java.util.*;
public class Party {
private final UUID partyUUID = UUID.randomUUID();
private final UUID partyUUID;
private UUID partyLeader;
private final HashMap<UUID, String> partyMembers = new HashMap<>();
@@ -23,12 +28,21 @@ public class Party {
private int currentQuestID = -1;
public UUID getPartyLeader() {
return partyLeader;
private boolean friendlyFire;
//Client-sided
private String partyLeaderName;
public Party() {
this.partyUUID = UUID.randomUUID();
}
public void setPartyLeader(UUID partyLeader) {
this.partyLeader = partyLeader;
public Party(UUID uuid) {
this.partyUUID = uuid;
}
public UUID getPartyUUID() {
return this.partyUUID;
}
public int getCurrentQuestID() {
@@ -44,6 +58,9 @@ public class Party {
return false;
}
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
playerData.partyUUID = this.partyUUID;
partyMembers.put(player.getUniqueID(), player.getCommandSenderName());
partyOrder.add(player.getUniqueID());
return true;
@@ -71,12 +88,13 @@ public class Party {
return false;
}
public boolean removePlayer(UUID player) {
if(partyMembers.containsKey(player)){
partyMembers.remove(player);
partyOrder.remove(player);
public boolean removePlayer(EntityPlayer player) {
UUID uuid = player.getUniqueID();
if(partyMembers.containsKey(uuid)){
partyMembers.remove(uuid);
partyOrder.remove(uuid);
if(player.equals(partyLeader)){
if(uuid.equals(partyLeader)){
if(partyMembers.size() > 0){
partyLeader = partyOrder.get(0);
}
@@ -88,8 +106,8 @@ public class Party {
return false;
}
public boolean hasPlayer(UUID player) {
return partyMembers.containsKey(player);
public boolean hasPlayer(EntityPlayer player) {
return partyMembers.containsKey(player.getUniqueID());
}
public boolean hasPlayer(String playerName) {
@@ -100,8 +118,18 @@ public class Party {
return partyMembers.containsKey(uuid);
}
public boolean setLeader(UUID uuid){
if(partyLeader.equals(uuid)){
public EntityPlayer getPartyLeader() {
return NoppesUtilServer.getPlayer(this.partyLeader);
}
@SideOnly(Side.CLIENT)
public String getPartyLeaderName() {
return this.partyLeaderName;
}
public boolean setLeader(EntityPlayer player){
UUID uuid = player.getUniqueID();
if(partyLeader != null && partyLeader.equals(uuid)){
return false;
}
@@ -120,6 +148,10 @@ public class Party {
return true;
}
public Collection<String> getPlayerNames() {
return this.partyMembers.values();
}
// To Be Called DURING Invite, Leave, Quest Switch, Leader Switch, etc.
public static boolean validateQuest(int questID, Collection<EntityPlayer> players){
IQuest quest = QuestController.Instance.get(questID);
@@ -154,6 +186,14 @@ public class Party {
}
}
public void toggleFriendlyFire() {
this.friendlyFire = !this.friendlyFire;
}
public boolean friendlyFire() {
return this.friendlyFire;
}
public static UUID getUUID(String name) {
UUID uuid = null;
try {
@@ -168,4 +208,35 @@ public class Party {
return uuid;
}
public void readFromNBT(NBTTagCompound compound) {
this.partyLeaderName = compound.getString("PartyLeader");
this.currentQuestID = compound.getInteger("PartyQuestID");
NBTTagList list = compound.getTagList("PartyMembers", 10);
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound tagCompound = list.getCompoundTagAt(i);
UUID uuid = UUID.fromString(tagCompound.getString("UUID"));
String playerName = tagCompound.getString("PlayerName");
this.partyOrder.add(uuid);
this.partyMembers.put(uuid, playerName);
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setString("PartyUUID", this.partyUUID.toString());
compound.setInteger("PartyQuestID", this.currentQuestID);
compound.setString("PartyLeader", getPartyLeader().getCommandSenderName());
NBTTagList list = new NBTTagList();
for (UUID uuid : this.partyOrder) {
NBTTagCompound uuidCompound = new NBTTagCompound();
uuidCompound.setString("UUID", uuid.toString());
uuidCompound.setString("PlayerName", this.partyMembers.get(uuid));
list.appendTag(uuidCompound);
}
compound.setTag("PartyMembers", list);
return compound;
}
}