Search in sources :

Example 16 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project buildinggame by stefvanschie.

the class SubjectMenu method show.

/**
 * Opens this gui for the specified human entity
 *
 * @param humanEntity the human entity to open the gui for
 * @since 9.0.3
 */
public void show(@NotNull HumanEntity humanEntity) {
    ChestGui gui = new ChestGui(CONFIG.getInt("subject-gui.rows"), MessageManager.translate(MESSAGES.getString("subject-gui.title")));
    int rows = gui.getRows();
    var paginatedPane = new PaginatedPane(0, 0, 9, rows - 1);
    initializePages(gui, paginatedPane);
    if (paginatedPane.getPages() == 1 && !CONFIG.getBoolean("subject-gui.close-item.enable")) {
        paginatedPane.setHeight(gui.getRows());
        initializePages(gui, paginatedPane);
    }
    gui.addPane(paginatedPane);
    if (paginatedPane.getPages() != 1) {
        var previousPane = new OutlinePane(2, rows - 1, 1, 1);
        var nextPane = new OutlinePane(6, rows - 1, 1, 1);
        // previous page
        var prevItem = new ItemStack(Material.SUGAR_CANE);
        var prevMeta = prevItem.getItemMeta();
        prevMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.previous-page.name")));
        prevMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.previous-page.lores")));
        prevItem.setItemMeta(prevMeta);
        previousPane.addItem(new GuiItem(prevItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() - 1);
            if (paginatedPane.getPage() == 0)
                previousPane.setVisible(false);
            nextPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        previousPane.setVisible(false);
        gui.addPane(previousPane);
        // next page
        var nextItem = new ItemStack(Material.SUGAR_CANE);
        var nextMeta = nextItem.getItemMeta();
        nextMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.next-page.name")));
        nextMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.next-page.lores")));
        nextItem.setItemMeta(nextMeta);
        nextPane.addItem(new GuiItem(nextItem, event -> {
            paginatedPane.setPage(paginatedPane.getPage() + 1);
            if (paginatedPane.getPage() == paginatedPane.getPages() - 1)
                nextPane.setVisible(false);
            previousPane.setVisible(true);
            update();
            event.setCancelled(true);
        }));
        gui.addPane(nextPane);
    }
    if (CONFIG.getBoolean("subject-gui.close-item.enable")) {
        var closePane = new OutlinePane(4, rows - 1, 1, 1);
        var closeItem = new ItemStack(Material.BOOK);
        var closeMeta = closeItem.getItemMeta();
        closeMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.close-menu.name")));
        closeMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.close-menu.lores")));
        closeItem.setItemMeta(closeMeta);
        closePane.addItem(new GuiItem(closeItem, event -> {
            event.getWhoClicked().closeInventory();
            event.setCancelled(true);
        }));
        gui.addPane(closePane);
    }
    // additional items
    CONFIG.getConfigurationSection("subject-gui.additional-items").getKeys(false).forEach(section -> {
        String baseNode = "subject-gui.additional-items." + section;
        int x = CONFIG.getInt(baseNode + ".x") - 1;
        int y = CONFIG.getInt(baseNode + ".y") - 1;
        var pane = new OutlinePane(x, y, 1, 1);
        Material material = SettingsManager.getInstance().getMaterial(baseNode + ".id", Material.BARRIER);
        var item = new ItemStack(material);
        var itemMeta = item.getItemMeta();
        var name = MESSAGES.getString(baseNode + ".name");
        if (name == null) {
            var baseName = item.getType().name().substring(1).replace('_', ' ');
            var lowerCaseName = baseName.toLowerCase(Locale.getDefault());
            var prettyName = Character.toUpperCase(item.getType().name().charAt(0)) + lowerCaseName;
            MESSAGES.set(baseNode + ".name", prettyName);
            name = MESSAGES.getString(baseNode + ".name");
        }
        itemMeta.setDisplayName(MessageManager.translate(name));
        var lore = MESSAGES.getStringList(baseNode + ".lore");
        if (lore == null) {
            MESSAGES.set(baseNode + ".name", new ArrayList<String>());
            lore = new ArrayList<>();
        }
        itemMeta.setLore(MessageManager.translate(lore));
        item.setItemMeta(itemMeta);
        pane.addItem(new GuiItem(item, event -> event.setCancelled(true)));
        gui.addPane(pane);
    });
    gui.setOnClose(event -> openGuis.remove(gui));
    gui.show(humanEntity);
    openGuis.put(gui, paginatedPane);
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) HumanEntity(org.bukkit.entity.HumanEntity) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) java.util(java.util) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) Orientable(com.github.stefvanschie.inventoryframework.pane.Orientable) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Player(org.bukkit.entity.Player) SubjectVote(com.gmail.stefvanschiedev.buildinggame.utils.SubjectVote) ItemStack(org.bukkit.inventory.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Main(com.gmail.stefvanschiedev.buildinggame.Main) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PercentageBar(com.github.stefvanschie.inventoryframework.pane.component.PercentageBar) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) Material(org.bukkit.Material) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 17 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project EmployMe by DavidTheExplorer.

the class ItemPaletteGUI method createPage.

private Pane createPage(Deque<GuiItem> items) {
    OutlinePane itemsPane = new OutlinePane(0, 0, 9, 6, Priority.LOWEST);
    itemsPane.setOrientation(HORIZONTAL);
    for (int i = 1; i <= ITEMS_PER_PAGE; i++) {
        if (// a little trick to avoid NoSuchElementException at the last page
        !items.isEmpty())
            itemsPane.addItem(items.removeFirst());
    }
    return itemsPane;
}
Also used : OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane)

Example 18 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project EmployMe by DavidTheExplorer.

the class JobDeletionGUI method createJobsPane.

private Pane createJobsPane() {
    OutlinePane pane = new OutlinePane(0, 0, 9, 6, Priority.LOW);
    pane.setOrientation(HORIZONTAL);
    this.jobsToDisplay.stream().map(this::createDeletionIcon).forEach(pane::addItem);
    return pane;
}
Also used : OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane)

Example 19 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project EmployMe by DavidTheExplorer.

the class InventoryFrameworkUtils method createRectangle.

public static Pane createRectangle(Priority priority, int x, int y, int length, int height, GuiItem item) {
    OutlinePane pane = new OutlinePane(x, y, length, height, priority);
    pane.addItem(item);
    pane.setRepeat(true);
    return pane;
}
Also used : OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane)

Example 20 with OutlinePane

use of com.github.stefvanschie.inventoryframework.pane.OutlinePane in project Nodewar by Rosstail.

the class PlayerAdminEmpireGUIs method initGUI.

public static void initGUI(Player player, fr.rosstail.nodewar.Nodewar plugin, ChestGui previousGui, Player target) {
    int invSize = 6;
    String display = target.getName() + "'s Empires - Page 1";
    ChestGui gui = new ChestGui(invSize, AdaptMessage.playerMessage(player, display));
    PaginatedPane paginatedPane = new PaginatedPane(0, 0, 9, invSize);
    OutlinePane background = new OutlinePane(0, 0, 9, gui.getRows(), Pane.Priority.LOWEST);
    background.addItem(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)));
    background.setRepeat(true);
    gui.addPane(background);
    int page = 0;
    while (true) {
        StaticPane staticPane = initPane(player, plugin, gui, previousGui, paginatedPane, target, page);
        paginatedPane.addPane(page, staticPane);
        if (staticPane.getItems().size() < 47) {
            // 9 * 5 lines + 2 buttons
            break;
        }
        page++;
    }
    gui.setOnGlobalClick(event -> {
        event.setCancelled(true);
    });
    gui.addPane(paginatedPane);
    gui.show(player);
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) PaginatedPane(com.github.stefvanschie.inventoryframework.pane.PaginatedPane) OutlinePane(com.github.stefvanschie.inventoryframework.pane.OutlinePane) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

OutlinePane (com.github.stefvanschie.inventoryframework.pane.OutlinePane)23 GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)17 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)17 ItemStack (org.bukkit.inventory.ItemStack)16 PaginatedPane (com.github.stefvanschie.inventoryframework.pane.PaginatedPane)9 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)9 Material (org.bukkit.Material)7 Player (org.bukkit.entity.Player)7 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)5 HumanEntity (org.bukkit.entity.HumanEntity)5 NotNull (org.jetbrains.annotations.NotNull)5 Main (com.gmail.stefvanschiedev.buildinggame.Main)4 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)4 ChatColor (org.bukkit.ChatColor)4 Pane (com.github.stefvanschie.inventoryframework.pane.Pane)3 Priority (com.github.stefvanschie.inventoryframework.pane.Pane.Priority)3 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)3 MessageService (dte.employme.messages.service.MessageService)3 IOException (java.io.IOException)3 List (java.util.List)3