From af84e75ef9c313f01c47860af9b41d2fd23b53d3 Mon Sep 17 00:00:00 2001 From: KID Date: Fri, 5 Apr 2019 14:28:05 +0800 Subject: [PATCH] Add simple preview mode --- .../inspectionProfiles/profiles_settings.xml | 6 ---- .../club/kid7/bannermaker/PlayerData.java | 9 +++++ .../customMenu/CreateBannerMenu.java | 34 +++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index cb2fdb3..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/main/java/club/kid7/bannermaker/PlayerData.java b/src/main/java/club/kid7/bannermaker/PlayerData.java index 220e45a..4218cd8 100644 --- a/src/main/java/club/kid7/bannermaker/PlayerData.java +++ b/src/main/java/club/kid7/bannermaker/PlayerData.java @@ -17,6 +17,7 @@ public class PlayerData { private ItemStack currentEditBanner = null; private boolean showMorePatterns = false; private DyeColor selectedColor = DyeColor.BLACK; + private boolean inSimplePreviewMode = false; public Integer getCurrentPage() { return currentPage; @@ -81,4 +82,12 @@ public DyeColor getSelectedColor() { public void setSelectedColor(DyeColor selectedColor) { this.selectedColor = selectedColor; } + + public boolean isInSimplePreviewMode() { + return inSimplePreviewMode; + } + + public void setInSimplePreviewMode(boolean inSimplePreviewMode) { + this.inSimplePreviewMode = inSimplePreviewMode; + } } diff --git a/src/main/java/club/kid7/bannermaker/customMenu/CreateBannerMenu.java b/src/main/java/club/kid7/bannermaker/customMenu/CreateBannerMenu.java index 4c2e8b6..aa1171b 100644 --- a/src/main/java/club/kid7/bannermaker/customMenu/CreateBannerMenu.java +++ b/src/main/java/club/kid7/bannermaker/customMenu/CreateBannerMenu.java @@ -10,6 +10,7 @@ import club.kid7.pluginutilities.gui.CustomGUIManager; import club.kid7.pluginutilities.gui.CustomGUIMenu; import club.kid7.pluginutilities.kitemstack.KItemStack; +import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.block.banner.Pattern; @@ -61,9 +62,32 @@ public CustomGUIInventory build(final Player player) { CustomGUIManager.openPrevious(player); }); } - //Pattern //選擇的顏色 DyeColor selectedColor = playerData.getSelectedColor(); + //預覽模式 + boolean isInSimplePreviewMode = playerData.isInSimplePreviewMode(); + //預覽模式切換按鈕 + final KItemStack previewDye = new KItemStack(DyeColorUtil.toDyeMaterial(selectedColor)) + .name(ChatColor.BLUE + "Selected pattern color") + .lore(ChatColor.GREEN + "Toggle preview mode"); + menu.setClickableItem(18, previewDye).set(ClickType.LEFT, event -> { + playerData.setInSimplePreviewMode(!isInSimplePreviewMode); + CustomGUIManager.openPrevious(player); + }); + + //預覽模式 + final KItemStack baseBannerForPreview; + final DyeColor selectedColorForPreview; + if (isInSimplePreviewMode) { + //簡易預覽模式:一律黑底+白色圖樣 + baseBannerForPreview = new KItemStack(Material.WHITE_BANNER); + selectedColorForPreview = DyeColor.BLACK; + } else { + //預設預覽模式:與旗幟相同底色+選擇顏色之圖樣 + baseBannerForPreview = new KItemStack(DyeColorUtil.toBannerMaterial(DyeColorUtil.of(currentBanner.getType()))); + selectedColorForPreview = selectedColor; + } + //Pattern for (int i = 0; i < 24; i++) { int patternIndex = i; if (playerData.isShowMorePatterns()) { @@ -74,14 +98,12 @@ public CustomGUIInventory build(final Player player) { } //預覽旗幟 PatternType patternType = BannerUtil.getPatternTypeList().get(patternIndex); - final KItemStack banner = new KItemStack(DyeColorUtil.toBannerMaterial(DyeColorUtil.of(currentBanner.getType()))) - .pattern(new Pattern(selectedColor, patternType)); + final KItemStack banner = ((KItemStack) baseBannerForPreview.clone()) + .pattern(new Pattern(selectedColorForPreview, patternType)); menu.setClickableItem(i + 19 + (i / 8), banner).set(ClickType.LEFT, event -> { //新增Pattern - BannerMeta bm = (BannerMeta) banner.getItemMeta(); - Pattern pattern = bm.getPattern(bm.numberOfPatterns() - 1); BannerMeta currentBm = (BannerMeta) currentBanner.getItemMeta(); - currentBm.addPattern(pattern); + currentBm.addPattern(new Pattern(selectedColor, patternType)); currentBanner.setItemMeta(currentBm); playerData.setCurrentEditBanner(currentBanner); CustomGUIManager.openPrevious(player);