finished page system.

This commit is contained in:
alexcrea 2024-03-26 18:32:47 +01:00
parent 21c39421b9
commit a30f471c6a
9 changed files with 95 additions and 37 deletions

View file

@ -1,4 +1,4 @@
package xyz.alexcrea.cuanvil.gui.config.openable;
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
@ -10,7 +10,6 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;

View file

@ -1,4 +1,4 @@
package xyz.alexcrea.cuanvil.gui.config.openable;
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
@ -16,7 +16,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
@ -36,11 +35,11 @@ public class EnchantConflictGui extends ChestGui {
private final HashMap<EnchantConflictGroup, EnchantConflictSubSettingGui> conflictGuiMap;
private EnchantConflictGui() {
super(6, "§eConflict Config", CustomAnvil.instance);
super(6, "Conflict Config", CustomAnvil.instance);
this.conflictGuiMap = new HashMap<>();
}
private OutlinePane filledEnchant;
private OutlinePane firstPage;
private ArrayList<OutlinePane> pages;
private HashMap<UUID, Integer> pageMap;
private PatternPane backgroundPane;
@ -69,8 +68,8 @@ public class EnchantConflictGui extends ChestGui {
this.pageMap = new HashMap<>();
// enchant item panel
this.filledEnchant = creatEmptyPage();
this.pages.add(this.filledEnchant);
this.firstPage = creatEmptyPage();
this.pages.add(this.firstPage);
prepareOtherValues();
reloadValues();
@ -82,19 +81,33 @@ public class EnchantConflictGui extends ChestGui {
private void prepareOtherValues() {
//TODO item x2
this.goLeftItem = new GuiItem(new ItemStack(Material.PAPER), event -> {
UUID playerUUID = event.getWhoClicked().getUniqueId();
int page =this.pageMap.getOrDefault(event.getWhoClicked().getUniqueId(), 0);
HumanEntity viewer = event.getWhoClicked();
UUID playerUUID = viewer.getUniqueId();
int page =this.pageMap.getOrDefault(playerUUID, 0);
this.pageMap.put(playerUUID, page-1);
show(event.getWhoClicked());
ItemStack cursor = viewer.getItemOnCursor();
viewer.setItemOnCursor(new ItemStack(Material.AIR));
viewer.closeInventory();// Hacky trick to make the inventory update properly
show(viewer);
viewer.setItemOnCursor(cursor);
}, CustomAnvil.instance);
this.goRightItem = new GuiItem(new ItemStack(Material.PAPER), event -> {
UUID playerUUID = event.getWhoClicked().getUniqueId();
int page = pageMap.getOrDefault(event.getWhoClicked().getUniqueId(), 0);
HumanEntity viewer = event.getWhoClicked();
UUID playerUUID = viewer.getUniqueId();
int page = pageMap.getOrDefault(playerUUID, 0);
this.pageMap.put(playerUUID, page+1);
show(event.getWhoClicked());
ItemStack cursor = viewer.getItemOnCursor();
viewer.setItemOnCursor(new ItemStack(Material.AIR));
viewer.closeInventory();// Hacky trick to make the inventory update properly
show(viewer);
viewer.setItemOnCursor(cursor);
}, CustomAnvil.instance);
}
@ -110,7 +123,9 @@ public class EnchantConflictGui extends ChestGui {
public void reloadValues(){
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
this.conflictGuiMap.clear();
this.filledEnchant.clear();
this.firstPage.clear();
this.pages.clear();
this.pages.add(this.firstPage);
for (EnchantConflictGroup conflict : ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList()) {
updateValueForConflict(conflict, false);
@ -143,7 +158,7 @@ public class EnchantConflictGui extends ChestGui {
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
this.conflictGuiMap.put(conflict, gui);
this.filledEnchant.addItem(guiItem);
addToPage(guiItem);
}else{
// replace item with the updated one
guiItem = gui.getParentItemForThisGui();
@ -161,11 +176,55 @@ public class EnchantConflictGui extends ChestGui {
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
if(gui == null) return;
this.filledEnchant.removeItem(gui.getParentItemForThisGui());
this.conflictGuiMap.remove(conflict);
removeFromPage(gui.getParentItemForThisGui());
update();
}
private void addToPage(GuiItem guiItem) {
// Get first available page or create one
OutlinePane page = this.pages.get(this.pages.size()-1);
if(page.getItems().size() >= 5*9){
page = creatEmptyPage();
this.pages.add(page);
}
page.addItem(guiItem);
}
private void removeFromPage(GuiItem guiItem) {
// get item page
OutlinePane page = null;
int pageID = 0;
while(pageID < this.pages.size()){
OutlinePane tempPage = this.pages.get(pageID++);
if(tempPage.getItems().contains(guiItem)){
page = tempPage;
break;
}
}
if(page == null){// Why...
return;
}
removeFromPage(page, pageID, guiItem);
}
private void removeFromPage(OutlinePane page, int pageID, GuiItem guiItem) {
page.removeItem(guiItem);
// There is now a slot available, let fill it if possible
if(pageID < this.pages.size() - 1){
OutlinePane newPage = this.pages.get(pageID+1);
GuiItem newItem = newPage.getItems().get(0);
removeFromPage(newPage, pageID+1, newItem);
}else if(pageID > 0 && page.getItems().isEmpty()){
this.pages.remove(pageID);
}
}
public int getPlayerPageID(UUID uuid){
int pageId = this.pageMap.getOrDefault(uuid, 0);
if(pageId >= this.pages.size()){
@ -176,14 +235,15 @@ public class EnchantConflictGui extends ChestGui {
public void placeArrow(int page){
// Place left arrow
addPane(this.backgroundPane);
if(page > 0){
this.backgroundPane.bindItem('R', this.goLeftItem);
this.backgroundPane.bindItem('L', this.goLeftItem);
}else{
this.backgroundPane.bindItem('L', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
}
// Place right arrow
if(page < pages.size()){
if(page < pages.size()-1){
this.backgroundPane.bindItem('R', this.goRightItem);
}else{
this.backgroundPane.bindItem('R', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
@ -195,12 +255,14 @@ public class EnchantConflictGui extends ChestGui {
int pageID = getPlayerPageID(humanEntity.getUniqueId());
OutlinePane page = this.pages.get(pageID);
getPanes().clear();
// display the page arrow pane
placeArrow(pageID);
// and add actual page
addPane(page);
super.show(humanEntity);
getPanes().remove(page);
}
@ -209,13 +271,14 @@ public class EnchantConflictGui extends ChestGui {
int pageID = getPlayerPageID(event.getWhoClicked().getUniqueId());
OutlinePane page = this.pages.get(pageID);
getPanes().clear();
// set the page arrow pane
placeArrow(pageID);
// use the clicked page
// and add actual page
addPane(page);
super.click(event);
getPanes().remove(page);
}
}

View file

@ -1,4 +1,4 @@
package xyz.alexcrea.cuanvil.gui.config.openable;
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import org.bukkit.Material;

View file

@ -1,4 +1,4 @@
package xyz.alexcrea.cuanvil.gui.config.openable;
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import org.bukkit.Material;

View file

@ -1,4 +1,4 @@
package xyz.alexcrea.cuanvil.gui;
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
@ -8,10 +8,6 @@ import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.alexcrea.cuanvil.gui.config.openable.BasicConfigGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantConflictGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantCostConfigGui;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantLimitConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;

View file

@ -18,7 +18,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.ConfirmActionGui;
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantConflictGui;
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;

View file

@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.config.global.MainConfigGui;
import java.util.Arrays;
import java.util.Comparator;

View file

@ -5,7 +5,7 @@ import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.HumanEntity
import xyz.alexcrea.cuanvil.gui.MainConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.MainConfigGui
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
class EditConfigExecutor : CommandExecutor {

View file

@ -5,9 +5,9 @@ import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.gui.config.openable.BasicConfigGui
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantCostConfigGui
import xyz.alexcrea.cuanvil.gui.config.openable.EnchantLimitConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.EnchantCostConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.EnchantLimitConfigGui
import xyz.alexcrea.cuanvil.util.MetricsUtil
class ReloadExecutor : CommandExecutor {