Added button to main GUI to toggle particle visibility

This commit is contained in:
Esophose 2021-02-08 13:08:33 -07:00
parent 875b3b3170
commit 5758ff8564
8 changed files with 48 additions and 2 deletions

View file

@ -16,12 +16,26 @@ import org.bukkit.material.Dye;
public class GuiActionButton {
private int slot;
private ItemStack itemStack;
private Material[] icons;
private ColorData[] colors;
private String name;
private String[] lore;
private GuiActionButtonClickCallback onClick;
private int iconIndex;
/**
* Constructor for creating a non-animated item from an already created ItemStack
*
* @param slot The slot ID of the inventory
* @param itemStack The ItemStack to display
* @param onClick The callback to execute when this button is clicked
*/
public GuiActionButton(int slot, ItemStack itemStack, GuiActionButtonClickCallback onClick) {
this.slot = slot;
this.itemStack = itemStack;
this.onClick = onClick;
}
/**
* Constructor for creating animated icons
@ -101,6 +115,9 @@ public class GuiActionButton {
* @return The icon ItemStack for the GUI
*/
public ItemStack getIcon(PPlayer pplayer) {
if (this.itemStack != null)
return this.itemStack;
ItemStack itemStack;
if (this.icons != null) {
itemStack = new ItemStack(this.icons[this.iconIndex]);

View file

@ -49,14 +49,25 @@ public class GuiInventoryDefault extends GuiInventory {
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-saved-groups", StringPlaceholders.single("amount", pplayer.getParticleGroups().size() - 1)),
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-fixed-effects", StringPlaceholders.single("amount", pplayer.getFixedEffectIds().size())),
" ",
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-commands-info")
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-commands-info"),
" ",
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-toggle-visibility-" + (pplayer.canSeeParticles() ? "on" : "off")),
localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-toggle-visibility-info")
};
currentIconMeta.setLore(GuiActionButton.parseLore(this.pplayer, currentIconLore));
currentIconMeta.setOwner(pplayer.getPlayer().getName());
headIcon.setItemMeta(currentIconMeta);
}
this.inventory.setItem(13, headIcon);
GuiActionButton headButton = new GuiActionButton(
13,
headIcon,
(button, isShiftClick) -> {
PlayerParticlesAPI.getInstance().togglePlayerParticleVisibility(pplayer.getPlayer(), pplayer.canSeeParticles());
guiManager.transition(new GuiInventoryDefault(pplayer));
}
);
this.actionButtons.add(headButton);
// Define what slots to put the icons at based on what other slots are visible
boolean manageGroupsVisible = PlayerParticles.getInstance().getManager(PermissionManager.class).canPlayerSaveGroups(pplayer);

View file

@ -251,6 +251,9 @@ public class EnglishLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "Find info about commands with &b/pp help");
this.put("gui-toggle-visibility-on", "Particles are currently &avisible");
this.put("gui-toggle-visibility-off", "Particles are currently &chidden");
this.put("gui-toggle-visibility-info", "Click to toggle particle visibility");
this.put("gui-back-button", "Go Back");
this.put("gui-next-page-button", "Next Page (%start%/%end%)");
this.put("gui-previous-page-button", "Previous Page (%start%/%end%)");

View file

@ -251,6 +251,9 @@ public class FrenchLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "Affichez des informations avec &b/pp help");
this.put("gui-toggle-visibility-on", "Les particules sont actuellement &avisibles");
this.put("gui-toggle-visibility-off", "Les particules sont actuellement &ccachées");
this.put("gui-toggle-visibility-info", "Cliquer pour basculer la visibilité des particules");
this.put("gui-back-button", "Retour en arrière");
this.put("gui-next-page-button", "Page Suivante (%start%/%end%)");
this.put("gui-previous-page-button", "Page Précédente (%start%/%end%)");

View file

@ -251,6 +251,9 @@ public class GermanLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "Informationen zu Befehlen finden Sie mit Hilfe von &b/pp help");
this.put("gui-toggle-visibility-on", "Partikel sind derzeit &asichtbar");
this.put("gui-toggle-visibility-off", "Partikel sind derzeit &causgeblendet");
this.put("gui-toggle-visibility-info", "Klicken Sie, um die Sichtbarkeit der Partikel einzuschalten");
this.put("gui-back-button", "Zurück");
this.put("gui-next-page-button", "Nächste Seite (%start%/%end%)");
this.put("gui-previous-page-button", "Vorherige Seite (%start%/%end%)");

View file

@ -251,6 +251,9 @@ public class RussianLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "Узнать подробнее о командах - &b/pp help");
this.put("gui-toggle-visibility-on", "Частицы в настоящее время &aвидны");
this.put("gui-toggle-visibility-off", "В настоящее время частицы &cскрыты");
this.put("gui-toggle-visibility-info", "Нажмите, чтобы переключить видимость частиц");
this.put("gui-back-button", "Назад");
this.put("gui-next-page-button", "Следующая страница (%start%/%end%)");
this.put("gui-previous-page-button", "Предыдущая страница (%start%/%end%)");

View file

@ -251,6 +251,9 @@ public class SimplifiedChineseLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "输入 &b/pp help 查看指令帮助");
this.put("gui-toggle-visibility-on", "粒子目前可见");
this.put("gui-toggle-visibility-off", "粒子目前被隐藏");
this.put("gui-toggle-visibility-info", "单击以切换粒子的可见性");
this.put("gui-back-button", "返回");
this.put("gui-next-page-button", "下一页 (%start%/%end%)");
this.put("gui-previous-page-button", "上一页 (%start%/%end%)");

View file

@ -251,6 +251,9 @@ public class VietnameseLocale implements Locale {
this.put("#28", "GUI Info Messages");
this.put("gui-commands-info", "Hiển thị thêm các lệnh bằng cách gõ &b/pp help");
this.put("gui-toggle-visibility-on", "Các hạt hiện có thể nhìn thấy được");
this.put("gui-toggle-visibility-off", "Các hạt hiện đang bị ẩn");
this.put("gui-toggle-visibility-info", "Nhấp để chuyển đổi chế độ hiển thị hạt");
this.put("gui-back-button", "Quay trở về");
this.put("gui-next-page-button", "Trang tiếp theo (%start%/%end%)");
this.put("gui-previous-page-button", "Trang trước (%start%/%end%)");