Changes in the skills GUI.

This commit is contained in:
Guillaume 2022-05-07 18:30:25 +02:00
parent 55d421861e
commit 285e753a02
3 changed files with 175 additions and 191 deletions

View File

@ -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.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders; import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem; 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.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.RegisteredSkill;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
@ -38,8 +39,6 @@ public class SkillList extends EditableInventory {
if (function.equals("skill")) if (function.equals("skill"))
return new SkillItem(config); return new SkillItem(config);
if (function.equals("switch"))
return new SwitchItem(config);
if (function.equals("level")) if (function.equals("level"))
return new LevelItem(config); return new LevelItem(config);
@ -49,7 +48,7 @@ public class SkillList extends EditableInventory {
@Override @Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { 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(); Placeholders holders = new Placeholders();
holders.register("skill_caps", selected.getName().toUpperCase()); holders.register("skill_caps", selected.getName().toUpperCase());
@ -59,10 +58,6 @@ public class SkillList extends EditableInventory {
return holders; return holders;
} }
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return !inv.binding;
}
}; };
if (function.equals("slot")) if (function.equals("slot"))
@ -74,7 +69,7 @@ public class SkillList extends EditableInventory {
@Override @Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { 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; RegisteredSkill skill = inv.getPlayerData().hasSkillBound(n) ? inv.getPlayerData().getBoundSkill(n).getSkill() : null;
Placeholders holders = new Placeholders(); Placeholders holders = new Placeholders();
@ -82,7 +77,7 @@ public class SkillList extends EditableInventory {
holders.register("skill", skill == null ? none : skill.getName()); holders.register("skill", skill == null ? none : skill.getName());
holders.register("index", "" + (n + 1)); holders.register("index", "" + (n + 1));
holders.register("slot", MMOCoreUtils.intToRoman(n + 1)); holders.register("slot", MMOCoreUtils.intToRoman(n + 1));
holders.register("selected", selected.getName()); holders.register("selected", selected==null?none:selected.getName());
return holders; return holders;
} }
@ -102,16 +97,28 @@ public class SkillList extends EditableInventory {
return item; return item;
} }
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return inv.binding;
}
@Override @Override
public boolean hasDifferentDisplay() { public boolean hasDifferentDisplay() {
return true; return true;
} }
}; };
if (function.equals("previous"))
return new SimplePlaceholderItem<SkillViewerInventory>(config) {
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return inv.page > 0;
}
};
if (function.equals("next")) {
return new SimplePlaceholderItem<SkillViewerInventory>(config) {
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return inv.page < inv.skills.size() / 12;
}
};
}
return new SimplePlaceholderItem(config); return new SimplePlaceholderItem(config);
} }
@ -120,30 +127,6 @@ public class SkillList extends EditableInventory {
return new SkillViewerInventory(data, this); return new SkillViewerInventory(data, this);
} }
public class SwitchItem extends SimplePlaceholderItem<SkillViewerInventory> {
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<SkillViewerInventory> { public class LevelItem extends InventoryItem<SkillViewerInventory> {
private final int offset; 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(); return NBTItem.get(item).addTag(new ItemTag("skillId", skill.getSkill().getHandler().getId())).toItem();
} }
@Override @Override
public Placeholders getPlaceholders(SkillViewerInventory inv, int n) { public Placeholders getPlaceholders(SkillViewerInventory inv, int n) {
return new Placeholders(); return new Placeholders();
} }
@Override
public boolean canDisplay(SkillViewerInventory inv) {
return !inv.binding;
}
} }
public class SkillItem extends InventoryItem<SkillViewerInventory> { public class SkillItem extends InventoryItem<SkillViewerInventory> {
private final int selectedSkillSlot;
public SkillItem(ConfigurationSection config) { public SkillItem(ConfigurationSection config) {
super(Material.BARRIER, config); super(Material.BARRIER, config);
selectedSkillSlot = config.getInt("selected-slot");
} }
@Override @Override
@ -220,12 +200,16 @@ public class SkillList extends EditableInventory {
/* /*
* calculate placeholders * 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); Placeholders holders = getPlaceholders(inv.getPlayerData(), skill);
List<String> lore = new ArrayList<>(getLore()); List<String> lore = new ArrayList<>(getLore());
int index = lore.indexOf("{lore}"); index = lore.indexOf("{lore}");
lore.remove(index); lore.remove(index);
List<String> skillLore = skill.calculateLore(inv.getPlayerData()); List<String> skillLore = skill.calculateLore(inv.getPlayerData());
for (int j = 0; j < skillLore.size(); j++) for (int j = 0; j < skillLore.size(); j++)
@ -272,8 +256,9 @@ public class SkillList extends EditableInventory {
private final List<Integer> skillSlots; private final List<Integer> skillSlots;
private final List<Integer> slotSlots; private final List<Integer> slotSlots;
private boolean binding; //The skill the player Selected
private ClassSkill selected; private ClassSkill selected;
private int page = 0;
public SkillViewerInventory(PlayerData playerData, EditableInventory editable) { public SkillViewerInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable); super(playerData, editable);
@ -281,24 +266,23 @@ public class SkillList extends EditableInventory {
skills = new ArrayList<>(playerData.getProfess().getSkills()); skills = new ArrayList<>(playerData.getProfess().getSkills());
skillSlots = getEditable().getByFunction("skill").getSlots(); skillSlots = getEditable().getByFunction("skill").getSlots();
slotSlots = getEditable().getByFunction("slot").getSlots(); slotSlots = getEditable().getByFunction("slot").getSlots();
selected=skills.get(page*skillSlots.size());
} }
@Override @Override
public String calculateName() { public String calculateName() {
return getName(); return getName().replace("{skill}", selected.getSkill().getName());
} }
@Override @Override
public void open() { public void open() {
int selectedSkillSlot = ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot;
selected = skills.get(mod(selectedSkillSlot + playerData.skillGuiDisplayOffset, skills.size()));
super.open(); super.open();
} }
@Override @Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) { public void whenClicked(InventoryClickEvent event, InventoryItem item) {
/*
if (skillSlots.contains(event.getRawSlot()) if (skillSlots.contains(event.getRawSlot())
&& event.getRawSlot() != ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot) { && event.getRawSlot() != ((SkillItem) getEditable().getByFunction("skill")).selectedSkillSlot) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
@ -306,24 +290,26 @@ public class SkillList extends EditableInventory {
open(); open();
return; 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")) { if (item.getFunction().equals("previous")) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
playerData.skillGuiDisplayOffset = (playerData.skillGuiDisplayOffset - 1) % skills.size(); page--;
open(); open();
return; return;
} }
if (item.getFunction().equals("next")) { if (item.getFunction().equals("next")) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2); player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
playerData.skillGuiDisplayOffset = (playerData.skillGuiDisplayOffset + 1) % skills.size(); page++;
open();
return;
}
if (item.getFunction().equals("switch")) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 2);
binding = !binding;
open(); open();
return; return;
} }
@ -331,10 +317,9 @@ public class SkillList extends EditableInventory {
/* /*
* binding or unbinding skills. * binding or unbinding skills.
*/ */
if (binding) { if (item.getFunction().equals("slot")) {
for (int index = 0; index < slotSlots.size(); index++) { int index = slotSlots.indexOf(event.getRawSlot());
int slot = slotSlots.get(index);
if (event.getRawSlot() == slot) {
// unbind if there is a current spell. // unbind if there is a current spell.
if (event.getAction() == InventoryAction.PICKUP_HALF) { if (event.getAction() == InventoryAction.PICKUP_HALF) {
@ -370,12 +355,12 @@ public class SkillList extends EditableInventory {
open(); open();
return; return;
} }
}
/* /*
* upgrading a player skill * upgrading a player skill
*/ */
} else if (item.getFunction().equals("upgrade")) { if (item.getFunction().equals("upgrade")) {
if (!playerData.hasSkillUnlocked(selected)) { if (!playerData.hasSkillUnlocked(selected)) {
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player); MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-skill").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2); player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 2);
@ -402,6 +387,7 @@ public class SkillList extends EditableInventory {
open(); open();
} }
} }
} }
private int mod(int x, int n) { private int mod(int x, int n) {

View File

@ -1,18 +1,13 @@
# GUI display name # GUI display name
name: Your Skills name: 'Selected Skill: &6{skill}'
# Number of slots in your inventory. Must be # Number of slots in your inventory. Must be
# between 9 and 54 and must be a multiple of 9. # between 9 and 54 and must be a multiple of 9.
slots: 45 slots: 54
items: items:
skill: skill:
slots: [11,12,13,14,15] slots: [ 10,11,12,19,20,21,28,29,30,37,38,39]
# Index from 'slots' of the skill
# currently selected in the GUI
selected-slot: 2
function: skill function: skill
name: '&a{skill} &6[{level}]' name: '&a{skill} &6[{level}]'
@ -24,33 +19,36 @@ items:
- '' - ''
- '{lore}' - '{lore}'
next: next:
slots: [16] slots: [ 47 ]
function: next function: next
item: PLAYER_HEAD item: PLAYER_HEAD
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19 texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZjMyOTJlMTI2YTEwNWI1NGViYTcxM2FhMWIxNTJkNTQxYTFkODkzODgyOWM1NjM2NGQxNzhlZDIyYmYifX19
name: '&aNext' name: '&aNext'
lore: { } lore: { }
previous: previous:
slots: [10] slots: [ 2 ]
function: previous function: previous
item: PLAYER_HEAD item: PLAYER_HEAD
texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ== texture: eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYmQ2OWUwNmU1ZGFkZmQ4NGU1ZjNkMWMyMTA2M2YyNTUzYjJmYTk0NWVlMWQ0ZDcxNTJmZGM1NDI1YmMxMmE5In19fQ==
name: '&aPrevious' name: '&aPrevious'
lore: { } lore: { }
switch:
slots: [28]
function: switch #switch:
item: PLAYER_HEAD #
binding: # slots: [28]
item: PINK_STAINED_GLASS # function: switch
name: '&aSwitch to Binding' # item: PLAYER_HEAD
lore: {} # binding:
upgrading: # item: PINK_STAINED_GLASS
item: PINK_STAINED_GLASS # name: '&aSwitch to Binding'
name: '&aSwitch to Upgrading' # lore: {}
lore: {} # upgrading:
# item: PINK_STAINED_GLASS
# name: '&aSwitch to Upgrading'
# lore: {}
skill-slot: skill-slot:
slots: [29,30,31,32,33,34] slots: [ 8,17,26,35,44,53 ]
function: slot function: slot
item: BOOK item: BOOK
@ -68,7 +66,7 @@ items:
- '&e► Left click to bind {selected}.' - '&e► Left click to bind {selected}.'
- '&e► Right click to unbind.' - '&e► Right click to unbind.'
skill-level: skill-level:
slots: [29,30,31,32,33,34] slots: [ 6,15,24,33,42,51 ]
function: level function: level
# Skill level offset, should be changed # Skill level offset, should be changed
@ -87,7 +85,7 @@ items:
- '' - ''
- '{lore}' - '{lore}'
upgrade: upgrade:
slots: [31] slots: [ 15 ]
function: upgrade function: upgrade
item: GREEN_STAINED_GLASS_PANE item: GREEN_STAINED_GLASS_PANE
name: '&a&lUPGRADE {skill_caps}' name: '&a&lUPGRADE {skill_caps}'