Added an emptiness representation in the explorer GUI.

It's an item displayed on the center of the GUI if there isn't any data to display.

 * NEW: added an item displayed if the explorer GUI is empty.
 * NEW: implementation of this empty item in the list GUI.
 * NEW: small adjustments on the statistics (removed the last empty line from the lore)
 * BUG: the old method was still used to remove the item attributes (the one from the `gui` package).
This commit is contained in:
Amaury Carrade 2015-09-10 16:00:14 +02:00
parent e7acbb36c4
commit 34b3a66220
2 changed files with 86 additions and 36 deletions

View File

@ -141,6 +141,8 @@ abstract public class ExplorerGui<T> extends ActionGui
updateAction("down", getPageItem("down", canGoDown())); updateAction("down", getPageItem("down", canGoDown()));
} }
if(data != null && data.length > 0)
{
if (!isData2D) if (!isData2D)
{ {
int start = currentPageX * viewSize; int start = currentPageX * viewSize;
@ -167,6 +169,15 @@ abstract public class ExplorerGui<T> extends ActionGui
} }
} }
} }
}
else
{
ItemStack emptyIndicator = getEmptyViewItem();
if(emptyIndicator != null)
{
action("", 22, emptyIndicator);
}
}
if(hasActions()) super.populate(inventory); if(hasActions()) super.populate(inventory);
} }
@ -192,20 +203,32 @@ abstract public class ExplorerGui<T> extends ActionGui
return; return;
} }
if(affectsGui(event)) // The user clicked in its own inventory // The user clicked in the GUI
if(affectsGui(event))
{
if(data != null && data.length > 0)
{ {
switch (event.getAction()) switch (event.getAction())
{ {
case PICKUP_ALL: case PICKUP_HALF: case PICKUP_ONE: case PICKUP_SOME: case PICKUP_ALL:
case HOTBAR_MOVE_AND_READD: case HOTBAR_SWAP: case PICKUP_HALF:
case PICKUP_ONE:
case PICKUP_SOME:
case HOTBAR_MOVE_AND_READD:
case HOTBAR_SWAP:
case MOVE_TO_OTHER_INVENTORY: case MOVE_TO_OTHER_INVENTORY:
onActionPickup(event); break; onActionPickup(event);
break;
case PLACE_ALL: case PLACE_ONE: case PLACE_SOME: case PLACE_ALL:
case PLACE_ONE:
case PLACE_SOME:
case SWAP_WITH_CURSOR: case SWAP_WITH_CURSOR:
onActionPut(event); break; onActionPut(event);
break;
case DROP_ALL_CURSOR: case DROP_ONE_CURSOR: case DROP_ALL_CURSOR:
case DROP_ONE_CURSOR:
break; break;
default: default:
@ -213,6 +236,11 @@ abstract public class ExplorerGui<T> extends ActionGui
} }
} }
else else
{
event.setCancelled(true);
}
}
else
{ {
if(event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) if(event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY))
onActionMove(event); onActionMove(event);
@ -435,6 +463,13 @@ abstract public class ExplorerGui<T> extends ActionGui
*/ */
protected ItemStack getViewItem(T data) { return null; } protected ItemStack getViewItem(T data) { return null; }
/**
* Returns the stack displayed in the center of the GUI if it is empty.
*
* @return The stack.
*/
protected ItemStack getEmptyViewItem() { return null; }
private ItemStack getPickedUpItem(int dataIndex) private ItemStack getPickedUpItem(int dataIndex)
{ {

View File

@ -47,6 +47,22 @@ public class MapListGui extends ExplorerGui<ImageMap>
"Poster map ("+map.getColumnCount()+"x"+map.getRowCount()+")", "#" + data.getId()); "Poster map ("+map.getColumnCount()+"x"+map.getRowCount()+")", "#" + data.getId());
} }
@Override
protected ItemStack getEmptyViewItem()
{
ItemStack empty = new ItemStack(Material.BARRIER);
ItemMeta meta = empty.getItemMeta();
meta.setDisplayName(ChatColor.RED + "You don't have any map.");
meta.setLore(Arrays.asList(
ChatColor.GRAY + "Get started by creating a new one",
ChatColor.GRAY + "using " + ChatColor.WHITE + "/tomap <URL> [resize]" + ChatColor.GRAY + "!"
));
empty.setItemMeta(meta);
return empty;
}
@Override @Override
protected void onRightClick(ImageMap data) protected void onRightClick(ImageMap data)
{ {
@ -124,12 +140,11 @@ public class MapListGui extends ExplorerGui<ImageMap>
lore.add(""); lore.add("");
lore.add(getStatisticText("Current consumption", ((int) Math.rint(percentageUsed)) + " %")); lore.add(getStatisticText("Current consumption", ((int) Math.rint(percentageUsed)) + " %"));
lore.add(getStatisticText("Maps left", mapPartLeft)); lore.add(getStatisticText("Maps left", mapPartLeft));
lore.add("");
meta.setLore(lore); meta.setLore(lore);
} }
fr.moribus.imageonmap.gui.core.GuiUtils.removeVanillaInfos(meta); GuiUtils.hideItemAttributes(meta);
statistics.setItemMeta(meta); statistics.setItemMeta(meta);
action("", getSize() - 5, statistics); action("", getSize() - 5, statistics);