Added an option to the explorer GUI: keep the scrolling area empty even without scrolls.

To be able to place controls, or by style/coherence if the developer wants that.

* NEW: added explicit options to keep the scrolling area empty even without scrolls.
This commit is contained in:
Amaury Carrade 2015-09-10 15:14:18 +02:00
parent 149e1225c1
commit a403efcd4e
2 changed files with 50 additions and 20 deletions

View File

@ -64,7 +64,10 @@ abstract public class ExplorerGui<T> extends ActionGui
private int viewSize;
private int viewHeight;
private int viewWidth;
private boolean keepHorizontalScrollingSpace = false;
private boolean keepVerticalScrollingSpace = false;
private int currentPageX = 0;
private int currentPageY = 0;
@ -208,7 +211,7 @@ abstract public class ExplorerGui<T> extends ActionGui
onActionMove(event);
}
}
@Override
protected void onDrag(InventoryDragEvent event)
{
@ -314,8 +317,9 @@ abstract public class ExplorerGui<T> extends ActionGui
viewHeight = Math.min((int)Math.ceil((double)dataLength / (double)viewWidth),
MAX_INVENTORY_COLUMN_SIZE);
if(hasActions() || dataLength > MAX_INVENTORY_SIZE)
if(hasActions() || dataLength > MAX_INVENTORY_SIZE || keepHorizontalScrollingSpace)
viewHeight--;
viewSize = viewWidth * viewHeight;
pageCountX = (int)Math.ceil((double)dataLength / (double)viewSize);
@ -329,8 +333,11 @@ abstract public class ExplorerGui<T> extends ActionGui
pageCountX = (int)Math.ceil((double)dataWidth / (double)viewWidth);
pageCountY = (int)Math.ceil((double)dataHeight / (double)viewHeight);
if(pageCountY > 1 && viewWidth == INVENTORY_ROW_SIZE) viewWidth--;
if(pageCountX > 1 && viewHeight == MAX_INVENTORY_COLUMN_SIZE) viewHeight--;
if((pageCountY > 1 && viewWidth == INVENTORY_ROW_SIZE) || keepVerticalScrollingSpace)
viewWidth--;
if((pageCountX > 1 && viewHeight == MAX_INVENTORY_COLUMN_SIZE) || keepHorizontalScrollingSpace)
viewHeight--;
pageCountX = (int)Math.ceil((double)dataWidth / (double)viewWidth);
pageCountY = (int)Math.ceil((double)dataHeight / (double)viewHeight);
@ -498,7 +505,7 @@ abstract public class ExplorerGui<T> extends ActionGui
if(canUse)
{
meta.setLore(Collections.singletonList(
ChatColor.GRAY + "Go to page " + ChatColor.WHITE + (newPage) + ChatColor.GRAY + " of " + ChatColor.WHITE + lastPage
ChatColor.GRAY + "Go to page " + ChatColor.WHITE + (newPage + 1) + ChatColor.GRAY + " of " + ChatColor.WHITE + lastPage
));
}
@ -619,4 +626,32 @@ abstract public class ExplorerGui<T> extends ActionGui
{
this.mode = mode;
}
/**
* If set to {@code true}, the horizontal scrolling line will remain empty even without
* scrolls (with one page typically), so you can place buttons or things like that in this
* area.
*
* Else, with one page, the place will be used to display an additional row of data.
*
* @param keepHorizontalScrollingSpace {@code true} if enabled.
*/
public void setKeepHorizontalScrollingSpace(boolean keepHorizontalScrollingSpace)
{
this.keepHorizontalScrollingSpace = keepHorizontalScrollingSpace;
}
/**
* If set to {@code true}, the vertical scrolling line will remain empty even without
* scrolls (with one page typically), so you can place buttons or things like that in this
* area.
*
* Else, with one page, the place will be used to display an additional column of data.
*
* @param keepVerticalScrollingSpace {@code true} if enabled.
*/
public void setKeepVerticalScrollingSpace(boolean keepVerticalScrollingSpace)
{
this.keepVerticalScrollingSpace = keepVerticalScrollingSpace;
}
}

View File

@ -18,21 +18,15 @@
package fr.moribus.imageonmap.guiproko.list;
import fr.moribus.imageonmap.guiproko.core.ExplorerGui;
import fr.moribus.imageonmap.guiproko.core.Gui;
import fr.moribus.imageonmap.guiproko.core.GuiUtils;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.moribus.imageonmap.map.SingleMap;
import fr.moribus.imageonmap.ui.MapItemManager;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import fr.moribus.imageonmap.guiproko.core.*;
import fr.moribus.imageonmap.map.*;
import fr.moribus.imageonmap.ui.*;
import org.bukkit.*;
import org.bukkit.inventory.*;
public class MapListGui extends ExplorerGui<ImageMap>
{
@Override
protected ItemStack getViewItem(ImageMap data)
{
@ -60,7 +54,7 @@ public class MapListGui extends ExplorerGui<ImageMap>
return MapItemManager.createMapItem(map.getMapsIDs()[0], map.getName());
}
MapItemManager.give((Player) getPlayer(), map);
MapItemManager.give(getPlayer(), map);
return null;
}
@ -70,6 +64,7 @@ public class MapListGui extends ExplorerGui<ImageMap>
ImageMap[] maps = MapManager.getMaps(getPlayer().getUniqueId());
setData(maps);
setTitle("Your maps (" + maps.length + " total)");
setKeepHorizontalScrollingSpace(true);
}
}