[Arcade] Attempt at fixing spectator gui bugs

This commit is contained in:
Shaun Bennett 2015-05-12 06:23:32 -05:00
parent 06a0f3d0d5
commit c7a9ae8cd5

View File

@ -32,151 +32,153 @@ import nautilus.game.arcade.gui.spectatorMenu.button.SpectatorButton;
public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
{
private ArcadeManager _arcadeManager;
private ArcadeManager _arcadeManager;
public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager,
DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Spectator Menu", player);
_arcadeManager = arcadeManager;
buildPage();
}
public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager,
DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Spectator Menu", player);
_arcadeManager = arcadeManager;
buildPage();
}
@Override
protected void buildPage()
{
int playerCount = _arcadeManager.GetGame().GetPlayers(true).size();
List<GameTeam> teamList = _arcadeManager.GetGame().GetTeamList();
@Override
protected void buildPage()
{
int playerCount = _arcadeManager.GetGame().GetPlayers(true).size();
List<GameTeam> teamList = _arcadeManager.GetGame().GetTeamList();
if (teamList.size() == 1 && playerCount < 28)
buildSingleTeam(teamList.get(0), playerCount);
else
buildMultipleTeams(teamList, playerCount);
if (teamList.size() == 1 && playerCount < 28)
buildSingleTeam(teamList.get(0), playerCount);
else
buildMultipleTeams(teamList, playerCount);
}
}
private void buildSingleTeam(GameTeam team, int playerCount)
{
setItem(13, getTeamItem(team, playerCount));
ArrayList<Player> players = team.GetPlayers(true);
Collections.sort(players, new Comparator<Player>()
{
private void buildSingleTeam(GameTeam team, int playerCount)
{
setItem(13, getTeamItem(team, playerCount));
@Override
public int compare(Player o1, Player o2)
{
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
ArrayList<Player> players = team.GetPlayers(true);
int slot = 19;
Collections.sort(players, new Comparator<Player>()
{
for (Player other : players)
{
addPlayerItem(slot, team, other);
@Override
public int compare(Player o1, Player o2)
{
return o1.getName().compareToIgnoreCase(o2.getName());
}
if ((slot + 2) % 9 == 0)
slot += 3;
else
slot++;
}
}
});
private void buildMultipleTeams(List<GameTeam> teamList, int playerCount)
{
int currentRow = 0;
int slot = 19;
for (GameTeam team : teamList)
{
ArrayList<Player> teamPlayers = team.GetPlayers(true);
int rowsNeeded = (teamPlayers.size() / 8) + 1;
Collections.sort(teamPlayers, new Comparator<Player>()
{
for (Player other : players)
{
addPlayerItem(slot, team, other);
@Override
public int compare(Player o1, Player o2)
{
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
if ((slot + 2) % 9 == 0)
slot += 3;
else
slot++;
}
}
for (int row = 0; row < rowsNeeded; row++)
{
int woolSlot = (row * 9) + (currentRow * 9);
private void buildMultipleTeams(List<GameTeam> teamList, int playerCount)
{
int currentRow = 0;
// TODO Need to handle too many players in a better way
if (woolSlot >= getSize())
continue;
for (GameTeam team : teamList)
{
ArrayList<Player> teamPlayers = team.GetPlayers(true);
int rowsNeeded = (int) Math.ceil(teamPlayers.size() / 8.0);
setItem(woolSlot, getTeamItem(team, teamPlayers.size()));
Collections.sort(teamPlayers, new Comparator<Player>()
{
int startPlayerIndex = row * 9;
for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && playerIndex < startPlayerIndex + 9; playerIndex++)
{
Player other = teamPlayers.get(playerIndex);
int slot = woolSlot + 1 + playerIndex;
@Override
public int compare(Player o1, Player o2)
{
return o1.getName().compareToIgnoreCase(o2.getName());
}
// TODO Need to handle too many players in a better way
if (slot >= getSize())
continue;
});
addPlayerItem(slot, team, other);
}
}
for (int row = 0; row < rowsNeeded; row++)
{
int woolSlot = (row * 9) + (currentRow * 9);
// Add a line in between teams if the player count is low enough and there are less than 4 teams
if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26)
currentRow += 2;
else
currentRow += rowsNeeded;
}
}
// TODO Need to handle too many players in a better way
if (woolSlot >= getSize())
continue;
private void addPlayerItem(int slot, GameTeam team, Player other)
{
ItemStack playerItem = getPlayerItem(team, other);
ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false);
addButton(slot, shopItem, new SpectatorButton(_arcadeManager, getPlayer(), other));
}
setItem(woolSlot, getTeamItem(team, teamPlayers.size()));
private ItemStack getTeamItem(GameTeam team, int playerCount)
{
ItemStack item = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor()));
int startPlayerIndex = row * 8;
int count = 0;
for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && count < 8; playerIndex++)
{
count++;
Player other = teamPlayers.get(playerIndex);
int slot = woolSlot + 1 + playerIndex;
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(team.GetFormattedName());
meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount));
item.setItemMeta(meta);
// TODO Need to handle too many players in a better way
if (slot >= getSize())
continue;
return item;
}
addPlayerItem(slot, team, other);
}
}
private ItemStack getPlayerItem(GameTeam team, Player other)
{
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
// Add a line in between teams if the player count is low enough and there are less than 4 teams
if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26)
currentRow += 2;
else
currentRow += rowsNeeded;
}
}
double distance = UtilMath.offset(getPlayer(), other);
double heightDifference = other.getLocation().getY() - getPlayer().getLocation().getY();
private void addPlayerItem(int slot, GameTeam team, Player other)
{
ItemStack playerItem = getPlayerItem(team, other);
ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false);
addButton(slot, shopItem, new SpectatorButton(_arcadeManager, getPlayer(), other));
}
ArrayList<String> lore = new ArrayList<String>();
lore.add(" ");
lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName());
lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance));
lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference));
lore.add(" ");
lore.add(ChatColor.RESET + C.Line + "Click to Spectate");
SkullMeta skullMeta = ((SkullMeta) item.getItemMeta());
skullMeta.setOwner(other.getName());
skullMeta.setDisplayName(team.GetColor() + other.getName());
skullMeta.setLore(lore);
item.setItemMeta(skullMeta);
private ItemStack getTeamItem(GameTeam team, int playerCount)
{
ItemStack item = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor()));
return item;
}
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(team.GetFormattedName());
meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount));
item.setItemMeta(meta);
return item;
}
private ItemStack getPlayerItem(GameTeam team, Player other)
{
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
double distance = UtilMath.offset(getPlayer(), other);
double heightDifference = other.getLocation().getY() - getPlayer().getLocation().getY();
ArrayList<String> lore = new ArrayList<String>();
lore.add(" ");
lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName());
lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance));
lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference));
lore.add(" ");
lore.add(ChatColor.RESET + C.Line + "Click to Spectate");
SkullMeta skullMeta = ((SkullMeta) item.getItemMeta());
skullMeta.setOwner(other.getName());
skullMeta.setDisplayName(team.GetColor() + other.getName());
skullMeta.setLore(lore);
item.setItemMeta(skullMeta);
return item;
}
}