From d25bf9bd0ec732990d2bba1054377903164eeb7e Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Thu, 10 Sep 2015 18:17:35 +0200 Subject: [PATCH] Updated the details GUI and fixed list GUI only opening the details GUI for posters. * NEW: added icons from the olg details GUI. * NEW: rewrote the map parts items (from the old GUI). * BUG: the list GUI don't open the details one when a single map is right-clicked. --- .../guiproko/list/MapDetailGui.java | 90 +++++++++++++++++-- .../imageonmap/guiproko/list/MapListGui.java | 3 +- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/moribus/imageonmap/guiproko/list/MapDetailGui.java b/src/main/java/fr/moribus/imageonmap/guiproko/list/MapDetailGui.java index 45bd389..689050f 100644 --- a/src/main/java/fr/moribus/imageonmap/guiproko/list/MapDetailGui.java +++ b/src/main/java/fr/moribus/imageonmap/guiproko/list/MapDetailGui.java @@ -20,29 +20,107 @@ package fr.moribus.imageonmap.guiproko.list; import fr.moribus.imageonmap.guiproko.core.*; import fr.moribus.imageonmap.map.*; -import fr.moribus.imageonmap.ui.*; import org.bukkit.*; import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.*; + +import java.util.*; public class MapDetailGui extends ExplorerGui { - private final PosterMap map; - public MapDetailGui(PosterMap map) + private final ImageMap map; + + public MapDetailGui(ImageMap map) { this.map = map; } - + @Override protected ItemStack getViewItem(int x, int y) { - return MapItemManager.createSubMapItem(map, x, y); + Material partMaterial = Material.PAPER; + if((y % 2 == 0 && x % 2 == 0) || (y % 2 == 1 && x % 2 == 1)) + partMaterial = Material.EMPTY_MAP; + + ItemStack part = new ItemStack(partMaterial); + ItemMeta meta = part.getItemMeta(); + + meta.setDisplayName(ChatColor.GREEN + "Map part"); + meta.setLore(Arrays.asList( + ChatColor.GRAY + "Column: " + ChatColor.WHITE + (y + 1), + ChatColor.GRAY + "Row: " + ChatColor.WHITE + (x + 1), + "", + ChatColor.GRAY + "» Click to get only this part" + )); + + part.setItemMeta(meta); + return part; + } + + @Override + protected ItemStack getEmptyViewItem() + { + if(map instanceof SingleMap) + { + return getViewItem(0, 0); + } + else return null; } @Override protected void onUpdate() { setTitle("Your maps » " + ChatColor.BLACK + map.getName()); - setDataShape(map.getColumnCount(), map.getRowCount()); + setKeepHorizontalScrollingSpace(true); + + if(map instanceof PosterMap) + setDataShape(((PosterMap) map).getColumnCount(), ((PosterMap) map).getRowCount()); + else + setData(null); // Fallback to the empty view item. + + + ItemStack back = new ItemStack(Material.EMERALD); + ItemMeta meta = back.getItemMeta(); + meta.setDisplayName(ChatColor.GREEN + "« Back"); + meta.setLore(Collections.singletonList( + ChatColor.GRAY + "Go back to the list." + )); + back.setItemMeta(meta); + + ItemStack rename = new ItemStack(Material.BOOK_AND_QUILL); + meta = rename.getItemMeta(); + meta.setDisplayName(ChatColor.BLUE + "Rename this image"); + meta.setLore(Arrays.asList( + ChatColor.GRAY + "Click here to rename this image;", + ChatColor.GRAY + "this is used for your own organization." + )); + rename.setItemMeta(meta); + + ItemStack delete = new ItemStack(Material.BARRIER); + meta = delete.getItemMeta(); + meta.setDisplayName(ChatColor.RED + "Delete this image"); + meta.setLore(Arrays.asList( + ChatColor.GRAY + "Deletes this map " + ChatColor.WHITE + "forever" + ChatColor.GRAY + ".", + ChatColor.GRAY + "This action cannot be undone!", + "", + ChatColor.GRAY + "You will be asked to confirm your", + ChatColor.GRAY + "choice if you click here." + )); + delete.setItemMeta(meta); + + + action("rename", getSize() - 7, rename); + action("delete", getSize() - 6, delete); + + + // To keep the controls centered, the back button is shifted to the right when the + // arrow isn't displayed, so when the map fit on the grid without sliders. + int backSlot = getSize() - 4; + + if(map instanceof PosterMap && ((PosterMap) map).getColumnCount() <= INVENTORY_ROW_SIZE) + backSlot++; + + action("back", backSlot, back); } } diff --git a/src/main/java/fr/moribus/imageonmap/guiproko/list/MapListGui.java b/src/main/java/fr/moribus/imageonmap/guiproko/list/MapListGui.java index fe64658..ffad2fd 100644 --- a/src/main/java/fr/moribus/imageonmap/guiproko/list/MapListGui.java +++ b/src/main/java/fr/moribus/imageonmap/guiproko/list/MapListGui.java @@ -87,8 +87,7 @@ public class MapListGui extends ExplorerGui @Override protected void onRightClick(ImageMap data) { - if(data instanceof SingleMap) return; - Gui.open(getPlayer(), new MapDetailGui((PosterMap)data)); + Gui.open(getPlayer(), new MapDetailGui(data)); } @Override