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

@ -140,31 +140,42 @@ abstract public class ExplorerGui<T> extends ActionGui
updateAction("up", getPageItem("up", canGoUp()));
updateAction("down", getPageItem("down", canGoDown()));
}
if(!isData2D)
{
int start = currentPageX * viewSize;
int max = Math.min(viewSize, data.length - start);
for(int i = 0; i < max; i++)
if(data != null && data.length > 0)
{
if (!isData2D)
{
inventory.setItem(i, getViewItem(i + start));
int start = currentPageX * viewSize;
int max = Math.min(viewSize, data.length - start);
for (int i = 0; i < max; i++)
{
inventory.setItem(i, getViewItem(i + start));
}
}
else
{
int startX = currentPageX * viewWidth;
int startY = currentPageY * viewHeight;
int maxX = Math.min(viewWidth, dataWidth - startX);
int maxY = Math.min(viewHeight, dataHeight - startY);
for (int i = maxY; i-- > 0; )
{
for (int j = maxX; j-- > 0; )
{
inventory.setItem(i * INVENTORY_ROW_SIZE + j, getViewItem(j + startX, i + startY));
}
}
}
}
else
{
int startX = currentPageX * viewWidth;
int startY = currentPageY * viewHeight;
int maxX = Math.min(viewWidth, dataWidth - startX);
int maxY = Math.min(viewHeight, dataHeight - startY);
for(int i = maxY; i --> 0;)
ItemStack emptyIndicator = getEmptyViewItem();
if(emptyIndicator != null)
{
for(int j = maxX; j --> 0;)
{
inventory.setItem(i * INVENTORY_ROW_SIZE + j, getViewItem(j + startX, i + startY));
}
action("", 22, emptyIndicator);
}
}
@ -177,7 +188,7 @@ abstract public class ExplorerGui<T> extends ActionGui
int slot = event.getRawSlot();
// Clicked in the action bar
if(hasActions() &&
if(hasActions() &&
slot >= MAX_INVENTORY_SIZE - INVENTORY_ROW_SIZE
&& slot < MAX_INVENTORY_SIZE)
{
@ -191,25 +202,42 @@ abstract public class ExplorerGui<T> extends ActionGui
super.onClick(event);
return;
}
if(affectsGui(event)) // The user clicked in its own inventory
// The user clicked in the GUI
if(affectsGui(event))
{
switch(event.getAction())
if(data != null && data.length > 0)
{
case PICKUP_ALL: case PICKUP_HALF: case PICKUP_ONE: case PICKUP_SOME:
case HOTBAR_MOVE_AND_READD: case HOTBAR_SWAP:
case MOVE_TO_OTHER_INVENTORY:
onActionPickup(event); break;
switch (event.getAction())
{
case PICKUP_ALL:
case PICKUP_HALF:
case PICKUP_ONE:
case PICKUP_SOME:
case HOTBAR_MOVE_AND_READD:
case HOTBAR_SWAP:
case MOVE_TO_OTHER_INVENTORY:
onActionPickup(event);
break;
case PLACE_ALL: case PLACE_ONE: case PLACE_SOME:
case SWAP_WITH_CURSOR:
onActionPut(event); break;
case PLACE_ALL:
case PLACE_ONE:
case PLACE_SOME:
case SWAP_WITH_CURSOR:
onActionPut(event);
break;
case DROP_ALL_CURSOR: case DROP_ONE_CURSOR:
break;
case DROP_ALL_CURSOR:
case DROP_ONE_CURSOR:
break;
default:
event.setCancelled(true);
default:
event.setCancelled(true);
}
}
else
{
event.setCancelled(true);
}
}
else
@ -435,6 +463,13 @@ abstract public class ExplorerGui<T> extends ActionGui
*/
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)
{

View File

@ -46,7 +46,23 @@ public class MapListGui extends ExplorerGui<ImageMap>
return GuiUtils.makeItem(Material.MAP, data.getName(),
"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
protected void onRightClick(ImageMap data)
{
@ -124,12 +140,11 @@ public class MapListGui extends ExplorerGui<ImageMap>
lore.add("");
lore.add(getStatisticText("Current consumption", ((int) Math.rint(percentageUsed)) + " %"));
lore.add(getStatisticText("Maps left", mapPartLeft));
lore.add("");
meta.setLore(lore);
}
fr.moribus.imageonmap.gui.core.GuiUtils.removeVanillaInfos(meta);
GuiUtils.hideItemAttributes(meta);
statistics.setItemMeta(meta);
action("", getSize() - 5, statistics);