From 285e753a0236bd2ac74b4b2949ffd50cbcfcd16d Mon Sep 17 00:00:00 2001 From: Guillaume Date: Sat, 7 May 2022 18:30:25 +0200 Subject: [PATCH] Changes in the skills GUI. --- .../net/Indyuce/mmocore/gui/SkillList.java | 184 ++++++++---------- src/main/resources/default/gui/skill-list.yml | 180 +++++++++-------- src/main/resources/default/gui/waypoints.yml | 2 +- 3 files changed, 175 insertions(+), 191 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java index a60e027d..af983f3c 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/SkillList.java +++ b/src/main/java/net/Indyuce/mmocore/gui/SkillList.java @@ -11,6 +11,7 @@ import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.item.InventoryItem; import net.Indyuce.mmocore.gui.api.item.Placeholders; import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem; +import net.Indyuce.mmocore.manager.SkillManager; import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.RegisteredSkill; import org.apache.commons.lang.Validate; @@ -38,8 +39,6 @@ public class SkillList extends EditableInventory { if (function.equals("skill")) return new SkillItem(config); - if (function.equals("switch")) - return new SwitchItem(config); if (function.equals("level")) return new LevelItem(config); @@ -49,7 +48,7 @@ public class SkillList extends EditableInventory { @Override public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { - RegisteredSkill selected = inv.selected.getSkill(); + RegisteredSkill selected = inv.selected==null?null:inv.selected.getSkill(); Placeholders holders = new Placeholders(); holders.register("skill_caps", selected.getName().toUpperCase()); @@ -59,10 +58,6 @@ public class SkillList extends EditableInventory { return holders; } - @Override - public boolean canDisplay(SkillViewerInventory inv) { - return !inv.binding; - } }; if (function.equals("slot")) @@ -74,7 +69,7 @@ public class SkillList extends EditableInventory { @Override public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { - RegisteredSkill selected = inv.selected.getSkill(); + RegisteredSkill selected = inv.selected==null?null:inv.selected.getSkill(); RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n) ? inv.getPlayerData().getBoundSkill(n).getSkill() : null; Placeholders holders = new Placeholders(); @@ -82,7 +77,7 @@ public class SkillList extends EditableInventory { holders.register("skill", skill == null ? none : skill.getName()); holders.register("index", "" + (n + 1)); holders.register("slot", MMOCoreUtils.intToRoman(n + 1)); - holders.register("selected", selected.getName()); + holders.register("selected", selected==null?none:selected.getName()); return holders; } @@ -102,16 +97,28 @@ public class SkillList extends EditableInventory { return item; } - @Override - public boolean canDisplay(SkillViewerInventory inv) { - return inv.binding; - } - @Override public boolean hasDifferentDisplay() { return true; } }; + if (function.equals("previous")) + return new SimplePlaceholderItem(config) { + + @Override + public boolean canDisplay(SkillViewerInventory inv) { + return inv.page > 0; + } + }; + if (function.equals("next")) { + return new SimplePlaceholderItem(config) { + + @Override + public boolean canDisplay(SkillViewerInventory inv) { + return inv.page < inv.skills.size() / 12; + } + }; + } return new SimplePlaceholderItem(config); } @@ -120,30 +127,6 @@ public class SkillList extends EditableInventory { return new SkillViewerInventory(data, this); } - public class SwitchItem extends SimplePlaceholderItem { - private final SimplePlaceholderItem binding, upgrading; - - public SwitchItem(ConfigurationSection config) { - super(config); - - Validate.isTrue(config.contains("binding"), "Config must have 'binding'"); - Validate.isTrue(config.contains("upgrading"), "Config must have 'upgrading'"); - - binding = new SimplePlaceholderItem(config.getConfigurationSection("binding")); - upgrading = new SimplePlaceholderItem(config.getConfigurationSection("upgrading")); - } - - @Override - public ItemStack display(SkillViewerInventory inv, int n) { - return inv.binding ? upgrading.display(inv) : binding.display(inv); - } - - @Override - public boolean canDisplay(SkillViewerInventory inv) { - return true; - } - } - public class LevelItem extends InventoryItem { private final int offset; @@ -189,24 +172,21 @@ public class SkillList extends EditableInventory { return NBTItem.get(item).addTag(new ItemTag("skillId", skill.getSkill().getHandler().getId())).toItem(); } + @Override public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { return new Placeholders(); } - @Override - public boolean canDisplay(SkillViewerInventory inv) { - return !inv.binding; - } + } public class SkillItem extends InventoryItem { - private final int selectedSkillSlot; + public SkillItem(ConfigurationSection config) { super(Material.BARRIER, config); - selectedSkillSlot = config.getInt("selected-slot"); } @Override @@ -220,12 +200,16 @@ public class SkillList extends EditableInventory { /* * calculate placeholders */ - ClassSkill skill = inv.skills.get(mod(n + inv.getPlayerData().skillGuiDisplayOffset, inv.skills.size())); + int index=n+inv.skillSlots.size()*inv.page; + if(index>=inv.skills.size()) + return new ItemStack(Material.AIR); + + ClassSkill skill = inv.skills.get(index); Placeholders holders = getPlaceholders(inv.getPlayerData(), skill); List lore = new ArrayList<>(getLore()); - int index = lore.indexOf("{lore}"); + index = lore.indexOf("{lore}"); lore.remove(index); List skillLore = skill.calculateLore(inv.getPlayerData()); for (int j = 0; j < skillLore.size(); j++) @@ -272,8 +256,9 @@ public class SkillList extends EditableInventory { private final List skillSlots; private final List slotSlots; - private boolean binding; + //The skill the player Selected private ClassSkill selected; + private int page = 0; public SkillViewerInventory(PlayerData playerData, EditableInventory editable) { super(playerData, editable); @@ -281,24 +266,23 @@ public class SkillList extends EditableInventory { skills = new ArrayList<>(playerData.getProfess().getSkills()); skillSlots = getEditable().getByFunction("skill").getSlots(); slotSlots = getEditable().getByFunction("slot").getSlots(); + selected=skills.get(page*skillSlots.size()); } @Override public String calculateName() { - return getName(); + return getName().replace("{skill}", selected.getSkill().getName()); } @Override public void open() { - int selectedSkillSlot = ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot; - selected = skills.get(mod(selectedSkillSlot + playerData.skillGuiDisplayOffset, skills.size())); - super.open(); } @Override public void whenClicked(InventoryClickEvent event, InventoryItem item) { + /* if (skillSlots.contains(event.getRawSlot()) && event.getRawSlot() != ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot) { player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); @@ -306,24 +290,26 @@ public class SkillList extends EditableInventory { open(); return; } + */ + + if (item.getFunction().equals("skill")) { + int index = skillSlots.size() * page + skillSlots.indexOf(event.getRawSlot()); + player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); + selected = skills.get(index); + open(); + return; + } if (item.getFunction().equals("previous")) { player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); - playerData.skillGuiDisplayOffset = (playerData.skillGuiDisplayOffset - 1) % skills.size(); + page--; open(); return; } if (item.getFunction().equals("next")) { player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); - playerData.skillGuiDisplayOffset = (playerData.skillGuiDisplayOffset + 1) % skills.size(); - open(); - return; - } - - if (item.getFunction().equals("switch")) { - player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); - binding = !binding; + page++; open(); return; } @@ -331,51 +317,50 @@ public class SkillList extends EditableInventory { /* * binding or unbinding skills. */ - if (binding) { - for (int index = 0; index < slotSlots.size(); index++) { - int slot = slotSlots.get(index); - if (event.getRawSlot() == slot) { + if (item.getFunction().equals("slot")) { + int index = slotSlots.indexOf(event.getRawSlot()); - // unbind if there is a current spell. - if (event.getAction() == InventoryAction.PICKUP_HALF) { - if (!playerData.hasSkillBound(index)) { - MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); - return; - } - player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); - playerData.unbindSkill(index); - open(); - return; - } - - if (selected == null) - return; - - if (selected.getSkill().getTrigger().isPassive()) { - MMOCore.plugin.configManager.getSimpleMessage("not-active-skill").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); - return; - } - - if (!playerData.hasSkillUnlocked(selected)) { - MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player); - player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); - return; - } - - player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); - playerData.setBoundSkill(index, selected); - open(); + // unbind if there is a current spell. + if (event.getAction() == InventoryAction.PICKUP_HALF) { + if (!playerData.hasSkillBound(index)) { + MMOCore.plugin.configManager.getSimpleMessage("no-skill-bound").send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); return; } + + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); + playerData.unbindSkill(index); + open(); + return; } - /* - * upgrading a player skill - */ - } else if (item.getFunction().equals("upgrade")) { + if (selected == null) + return; + + if (selected.getSkill().getTrigger().isPassive()) { + MMOCore.plugin.configManager.getSimpleMessage("not-active-skill").send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); + return; + } + + if (!playerData.hasSkillUnlocked(selected)) { + MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player); + player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); + return; + } + + player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2); + playerData.setBoundSkill(index, selected); + open(); + return; + } + + + /* + * upgrading a player skill + */ + if (item.getFunction().equals("upgrade")) { if (!playerData.hasSkillUnlocked(selected)) { MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); @@ -402,6 +387,7 @@ public class SkillList extends EditableInventory { open(); } } + } private int mod(int x, int n) { diff --git a/src/main/resources/default/gui/skill-list.yml b/src/main/resources/default/gui/skill-list.yml index 60993b92..04dc88a6 100644 --- a/src/main/resources/default/gui/skill-list.yml +++ b/src/main/resources/default/gui/skill-list.yml @@ -1,97 +1,95 @@ - # GUI display name -name: Your Skills +name: 'Selected Skill: &6{skill}' # Number of slots in your inventory. Must be # between 9 and 54 and must be a multiple of 9. -slots: 45 +slots: 54 items: - skill: - slots: [11,12,13,14,15] - - # Index from 'slots' of the skill - # currently selected in the GUI - selected-slot: 2 - - function: skill - name: '&a{skill} &6[{level}]' - lore: - - '' - - '{unlocked}&a✔ Requires Level {unlock}' - - '{locked}&c✖ Requires Level {unlock}' - - '{max_level}&e✔ Maximum Level Hit!' - - '' - - '{lore}' - next: - slots: [16] - function: next - item: PLAYER_HEAD - texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19 - name: '&aNext' - lore: {} - previous: - slots: [10] - function: previous - item: PLAYER_HEAD - texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ== - name: '&aPrevious' - lore: {} - switch: - slots: [28] - function: switch - item: PLAYER_HEAD - binding: - item: PINK_STAINED_GLASS - name: '&aSwitch to Binding' - lore: {} - upgrading: - item: PINK_STAINED_GLASS - name: '&aSwitch to Upgrading' - lore: {} - skill-slot: - slots: [29,30,31,32,33,34] - function: slot - item: BOOK - - # Material used when the slot is empty - empty-item: GRAY_DYE - - name: '&aSkill Slot {slot}' - no-skill: '&cNone' - lore: - - '&7Current Skill: &6{skill}' - - '' - - '&7&oCast this spell by pressing [F] followed' - - '&7&oby the keybind displayed on the action bar.' - - '' - - '&e► Left click to bind {selected}.' - - '&e► Right click to unbind.' - skill-level: - slots: [29,30,31,32,33,34] - function: level - - # Skill level offset, should be changed - # according to the amount of inventory - # slots the skill-level item occupies. - offset: 2 - - # Item displayed if the skill level is - # too low to display a level item in the GUI - too-low: - item: AIR - - item: LIME_DYE - name: '&a{skill} Level {roman}' - lore: - - '' - - '{lore}' - upgrade: - slots: [31] - function: upgrade - item: GREEN_STAINED_GLASS_PANE - name: '&a&lUPGRADE {skill_caps}' - lore: - - '&7Costs 1 skill point.' - - '' - - '&eCurrent Skill Points: {skill_points}' + skill: + slots: [ 10,11,12,19,20,21,28,29,30,37,38,39] + + function: skill + name: '&a{skill} &6[{level}]' + lore: + - '' + - '{unlocked}&a✔ Requires Level {unlock}' + - '{locked}&c✖ Requires Level {unlock}' + - '{max_level}&e✔ Maximum Level Hit!' + - '' + - '{lore}' + next: + slots: [ 47 ] + function: next + item: PLAYER_HEAD + texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19 + name: '&aNext' + lore: { } + previous: + slots: [ 2 ] + function: previous + item: PLAYER_HEAD + texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ== + name: '&aPrevious' + lore: { } + + + #switch: + # + # slots: [28] + # function: switch + # item: PLAYER_HEAD + # binding: + # item: PINK_STAINED_GLASS + # name: '&aSwitch to Binding' + # lore: {} + # upgrading: + # item: PINK_STAINED_GLASS + # name: '&aSwitch to Upgrading' + # lore: {} + skill-slot: + slots: [ 8,17,26,35,44,53 ] + function: slot + item: BOOK + + # Material used when the slot is empty + empty-item: GRAY_DYE + + name: '&aSkill Slot {slot}' + no-skill: '&cNone' + lore: + - '&7Current Skill: &6{skill}' + - '' + - '&7&oCast this spell by pressing [F] followed' + - '&7&oby the keybind displayed on the action bar.' + - '' + - '&e► Left click to bind {selected}.' + - '&e► Right click to unbind.' + skill-level: + slots: [ 6,15,24,33,42,51 ] + function: level + + # Skill level offset, should be changed + # according to the amount of inventory + # slots the skill-level item occupies. + offset: 2 + + # Item displayed if the skill level is + # too low to display a level item in the GUI + too-low: + item: AIR + + item: LIME_DYE + name: '&a{skill} Level {roman}' + lore: + - '' + - '{lore}' + upgrade: + slots: [ 15 ] + function: upgrade + item: GREEN_STAINED_GLASS_PANE + name: '&a&lUPGRADE {skill_caps}' + lore: + - '&7Costs 1 skill point.' + - '' + - '&eCurrent Skill Points: {skill_points}' diff --git a/src/main/resources/default/gui/waypoints.yml b/src/main/resources/default/gui/waypoints.yml index ff58f2c2..cd90f0c8 100644 --- a/src/main/resources/default/gui/waypoints.yml +++ b/src/main/resources/default/gui/waypoints.yml @@ -68,7 +68,7 @@ items: lore: - '&7You can teleport to this waypoint.' - - '&7Intermediary waypoints : {intermediary_waypoints}' + - '&7Intermediary waypoints: {intermediary_waypoints}' - '&7Click to teleport for &b{current_cost} &7Stellium.' next: