Skip to content

Commit

Permalink
Add simple preview mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhsu2000 committed Apr 5, 2019
1 parent 00fd640 commit af84e75
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/java/club/kid7/bannermaker/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down

0 comments on commit af84e75

Please sign in to comment.