use of dev.rosewood.guiframework.gui.screen.GuiScreenSection in project RoseStacker by Rosewood-Development.
the class StackedBlockGui method buildGui.
/**
* Builds the GUI from scratch
*/
private void buildGui() {
this.guiContainer = GuiFactory.createContainer();
List<Integer> paginatedSlots = new ArrayList<>();
for (int i = 10; i <= 16; i++) paginatedSlots.add(i);
for (int i = 19; i <= 25; i++) paginatedSlots.add(i);
for (int i = 28; i <= 34; i++) paginatedSlots.add(i);
for (int i = 37; i <= 43; i++) paginatedSlots.add(i);
List<Integer> borderSlots = new ArrayList<>();
for (int i = 0; i <= 8; i++) borderSlots.add(i);
for (int i = 9; i <= 36; i += 9) borderSlots.add(i);
for (int i = 17; i <= 44; i += 9) borderSlots.add(i);
for (int i = 46; i <= 52; i += 2) borderSlots.add(i);
borderSlots.addAll(Arrays.asList(45, 53));
ItemStack borderItem = new ItemStack(GuiHelper.parseMaterial(Setting.BLOCK_GUI_BORDER_MATERIAL.getString()));
ItemMeta itemMeta = borderItem.getItemMeta();
if (itemMeta != null) {
itemMeta.setDisplayName(" ");
itemMeta.addItemFlags(ItemFlag.values());
borderItem.setItemMeta(itemMeta);
}
List<Integer> destroyBorderSlots = new ArrayList<>();
for (int i = 0; i <= 26; i++) destroyBorderSlots.add(i);
destroyBorderSlots.removeAll(Arrays.asList(12, 14));
GuiScreenSection editableSection = GuiFactory.createScreenSection(paginatedSlots);
LocaleManager localeManager = this.rosePlugin.getManager(LocaleManager.class);
BlockStackSettings stackSettings = this.stackedBlock.getStackSettings();
GuiStringHelper pageBackString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-page-back", StringPlaceholders.empty()));
GuiStringHelper destroyString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy", StringPlaceholders.empty()));
GuiStringHelper pageForwardString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-page-forward", StringPlaceholders.empty()));
GuiStringHelper confirmDestroyString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy-confirm", StringPlaceholders.empty()));
GuiStringHelper confirmCancelString = new GuiStringHelper(localeManager.getGuiLocaleMessage("gui-stacked-block-destroy-cancel", StringPlaceholders.empty()));
List<ItemStack> stackItems = GuiUtil.getMaterialAmountAsItemStacks(this.stackedBlock.getBlock().getType(), this.stackedBlock.getStackSize());
int pages = (int) Math.ceil((double) stackItems.size() / paginatedSlots.size()) + 1;
while (stackItems.size() < pages * paginatedSlots.size()) stackItems.add(new ItemStack(Material.AIR));
GuiScreen mainScreen = GuiFactory.createScreen(this.guiContainer, GuiSize.ROWS_SIX).setTitle(localeManager.getLocaleMessage("gui-stacked-block-title", StringPlaceholders.single("name", stackSettings.getDisplayName()))).setEditableSection(editableSection, stackItems, this::updateStackedBlock).setEditFilters(GuiFactory.createScreenEditFilters().setWhitelist(this.stackedBlock.getBlock().getType()).setAllowModified(false)).addButtonAt(47, GuiFactory.createButton().setIcon(Material.PAPER).setName(pageBackString.getName()).setLore(pageBackString.getLore()).setClickAction(event -> ClickAction.PAGE_BACKWARDS).setFlags(GuiButtonFlag.HIDE_IF_FIRST_PAGE).setHiddenReplacement(borderItem)).addButtonAt(49, GuiFactory.createButton().setIcon(Material.BARRIER).setName(destroyString.getName()).setLore(destroyString.getLore()).setClickAction(event -> ClickAction.TRANSITION_FORWARDS)).addButtonAt(51, GuiFactory.createButton().setIcon(Material.PAPER).setName(pageForwardString.getName()).setLore(pageForwardString.getLore()).setClickAction(event -> ClickAction.PAGE_FORWARDS).setFlags(GuiButtonFlag.HIDE_IF_LAST_PAGE).setHiddenReplacement(borderItem));
for (int slot : borderSlots) mainScreen.addItemStackAt(slot, borderItem);
GuiScreen confirmScreen = GuiFactory.createScreen(this.guiContainer, GuiSize.ROWS_THREE).setTitle(localeManager.getLocaleMessage("gui-stacked-block-destroy-title", StringPlaceholders.single("name", stackSettings.getDisplayName()))).addButtonAt(12, GuiFactory.createButton().setIcon(Material.EMERALD_BLOCK).setName(confirmDestroyString.getName()).setLore(confirmDestroyString.getLore()).setClickAction(event -> {
this.destroyStackedBlock((Player) event.getWhoClicked());
return ClickAction.NOTHING;
})).addButtonAt(14, GuiFactory.createButton().setIcon(Material.REDSTONE_BLOCK).setName(confirmCancelString.getName()).setLore(confirmCancelString.getLore()).setClickAction(event -> ClickAction.TRANSITION_BACKWARDS));
for (int slot : destroyBorderSlots) confirmScreen.addItemStackAt(slot, borderItem);
this.guiContainer.addScreen(mainScreen);
this.guiContainer.addScreen(confirmScreen);
this.guiFramework.getGuiManager().registerGui(this.guiContainer);
}
Aggregations