One GUI to rule them all, One GUI to find them, One GUI to bring them all and in the darkness bind them.

* NEW: removed the category selector GUI.
* NEW: the map list GUI lists all the maps.
This commit is contained in:
Amaury Carrade 2015-07-12 01:45:17 +02:00
parent 892f6d2834
commit e1cd920d4c
3 changed files with 18 additions and 149 deletions

View File

@ -27,13 +27,14 @@ import fr.moribus.imageonmap.gui.list.*;
@CommandInfo(name = "manage")
public class ManageCommand extends Command
{
public ManageCommand(Commands commandGroup) {
public ManageCommand(Commands commandGroup)
{
super(commandGroup);
}
@Override
protected void run() throws CommandException {
GuiManager.openGui(playerSender(), new CategorySelectionGui());
protected void run() throws CommandException
{
GuiManager.openGui(playerSender(), new MapListGui());
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.moribus.imageonmap.gui.list;
import fr.moribus.imageonmap.gui.core.*;
import fr.moribus.imageonmap.map.*;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.*;
import java.util.*;
public class CategorySelectionGui extends AbstractGui {
@Override
public void display(Player player)
{
inventory = Bukkit.createInventory(player, 3 * 9, ChatColor.BLACK + "Maps");
/* ****** Data gathering ***** */
List<ImageMap> maps = MapManager.getMapList(player.getUniqueId());
Integer singleCount = 0;
Integer posterCount = 0;
for(ImageMap map : maps)
{
if(map.getType() == ImageMap.Type.POSTER)
posterCount++;
else
singleCount++;
}
/* ****** Access to the sub-categories ***** */
ItemStack singleMaps = new ItemStack(Material.MAP);
ItemMeta meta = singleMaps.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "Single maps");
meta.setLore(Collections.singletonList(ChatColor.WHITE + "" + singleCount + " image" + (singleCount != 1 ? "s" : "")));
GuiUtils.removeVanillaInfos(meta);
singleMaps.setItemMeta(meta);
ItemStack postersMaps = new ItemStack(Material.PAINTING);
meta = postersMaps.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "Posters");
meta.setLore(Collections.singletonList(ChatColor.WHITE + "" + posterCount + " image" + (posterCount != 1 ? "s" : "")));
postersMaps.setItemMeta(meta);
/* ****** Registration ***** */
setSlotData(singleMaps, 11, "single");
setSlotData(postersMaps, 15, "poster");
player.openInventory(getInventory());
}
@Override
public void onClick(Player player, ItemStack stack, String action)
{
switch (action)
{
case "poster":
GuiManager.openGui(player, new MapListGui(ImageMap.Type.POSTER));
break;
case "single":
GuiManager.openGui(player, new MapListGui(ImageMap.Type.SINGLE));
break;
}
}
}

View File

@ -42,32 +42,18 @@ public class MapListGui extends AbstractGui {
private int lastPage = 0;
public MapListGui(ImageMap.Type mapsType) {
this.mapsType = mapsType;
public MapListGui() {
}
public MapListGui(Integer initialPage) {
currentPage = initialPage;
}
@Override
public void display(Player player) {
String inventoryTitle = "Maps » ";
if(mapsType == ImageMap.Type.POSTER) {
inventoryTitle += "Posters";
} else {
inventoryTitle += "Single maps";
}
inventory = Bukkit.createInventory(player, 6 * 9, ChatColor.BLACK + inventoryTitle);
ItemStack back = new ItemStack(Material.EMERALD);
ItemMeta meta = back.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + "« Back");
meta.setLore(Arrays.asList(
ChatColor.GRAY + "Go back to the map",
ChatColor.GRAY + "type selector."
));
back.setItemMeta(meta);
setSlotData(back, inventory.getSize() - 5, "back");
inventory = Bukkit.createInventory(player, 6 * 9, ChatColor.BLACK + "Your maps");
player.openInventory(getInventory());
@ -90,10 +76,9 @@ public class MapListGui extends AbstractGui {
ItemMeta meta = empty.getItemMeta();
meta.setDisplayName(ChatColor.RED + "Nothing to display here");
meta.setLore(Arrays.asList(
ChatColor.GRAY + "You don't have any map in",
ChatColor.GRAY + "this category. Try the other",
ChatColor.GRAY + "one, or create a new map with",
ChatColor.WHITE + "/tomap <URL> [resize]"
ChatColor.GRAY + "You don't have any map.",
ChatColor.GRAY + "Get started by creating a new one",
ChatColor.GRAY + "with " + ChatColor.WHITE + "/tomap <URL> [resize]" + ChatColor.GRAY + "!"
));
empty.setItemMeta(meta);
@ -138,10 +123,6 @@ public class MapListGui extends AbstractGui {
{
switch (action)
{
case "back":
GuiManager.openGui(player, new CategorySelectionGui());
return;
case "previousPage":
previousPage(player);
return;
@ -223,10 +204,7 @@ public class MapListGui extends AbstractGui {
private void updateMapCache(Player player)
{
for(ImageMap map : MapManager.getMapList(player.getUniqueId()))
{
if(map.getType() == mapsType) maps.add(map);
}
maps = MapManager.getMapList(player.getUniqueId());
lastPage = (int) Math.ceil(((double) maps.size()) / ((double) MAPS_PER_PAGE)) - 1;
@ -243,27 +221,12 @@ public class MapListGui extends AbstractGui {
meta.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + map.getId().replace("-", " "));
if(map.getType() == ImageMap.Type.POSTER)
{
meta.setLore(Arrays.asList(
ChatColor.WHITE + "" + map.getMapCount() + " map" + (map.getMapCount() != 1 ? "s" : "")
));
}
else
{
meta.setLore(Arrays.asList(
ChatColor.WHITE + "Single map"
));
}
List<String> lore = meta.getLore();
lore.addAll(Arrays.asList(
meta.setLore(Arrays.asList(
ChatColor.WHITE + "" + map.getMapCount() + " map" + (map.getMapCount() != 1 ? "s" : ""),
"",
ChatColor.GRAY + "» Left-click to get this map",
ChatColor.GRAY + "» Right-click for details"
));
meta.setLore(lore);
GuiUtils.removeVanillaInfos(meta);