diff options
| author | syeyoung <cyoung06@naver.com> | 2023-02-24 02:00:28 +0900 |
|---|---|---|
| committer | syeyoung <cyoung06@naver.com> | 2023-02-24 02:00:28 +0900 |
| commit | ec4017f1a465b9ac443bc85818a0bf82f5616698 (patch) | |
| tree | 0b4de4d9403cd3c2dcb5944086386714154857a5 /mod/src | |
| parent | 0c787aa9e54331eb42bfb82804926df173c6f04f (diff) | |
| download | Skyblock-Dungeons-Guide-ec4017f1a465b9ac443bc85818a0bf82f5616698.tar.gz Skyblock-Dungeons-Guide-ec4017f1a465b9ac443bc85818a0bf82f5616698.tar.bz2 Skyblock-Dungeons-Guide-ec4017f1a465b9ac443bc85818a0bf82f5616698.zip | |
- New Cosmetics
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'mod/src')
18 files changed, 833 insertions, 29 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CosmeticsManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CosmeticsManager.java index 1dae8679..ea5dba43 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CosmeticsManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CosmeticsManager.java @@ -274,19 +274,30 @@ public class CosmeticsManager { if (replacementContext.getUsername().isEmpty()) continue; List<ActiveCosmetic> activeCosmetics = getActiveCosmeticByPlayerNameLowerCase() .get(replacementContext.getUsername().toLowerCase()); - String color=null, prefix=null; + String color=null, rawPrefix=null, rawPrefixColor=null; if (activeCosmetics != null) { for (ActiveCosmetic activeCosmetic : activeCosmetics) { CosmeticData cosmeticData = getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); - if (cosmeticData != null && cosmeticData.getCosmeticType().equals("color")) { + if (cosmeticData != null && cosmeticData.getCosmeticType().equals("ncolor")) { color = cosmeticData.getData().replace("&", "§"); - } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("prefix")) { - prefix = cosmeticData.getData().replace("&", "§"); + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("nprefix")) { + rawPrefix = cosmeticData.getData().replace("&", "§"); + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("bracket_color")) { + rawPrefixColor = cosmeticData.getData().replace("&", "§"); } } } - if (color == null && prefix == null) continue; + if (color == null && rawPrefix == null) continue; + + String prefix = null; + if (rawPrefix != null) { + prefix = rawPrefix.substring(1); + if (!rawPrefix.startsWith("T")) { + if (rawPrefixColor != null) + prefix = rawPrefixColor+"["+prefix+"§r"+rawPrefixColor+"]"; + } + } StringBuilder sb = new StringBuilder(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CustomNetworkPlayerInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CustomNetworkPlayerInfo.java index 86bded25..de4c3fd5 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CustomNetworkPlayerInfo.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/cosmetics/CustomNetworkPlayerInfo.java @@ -93,7 +93,7 @@ public class CustomNetworkPlayerInfo extends NetworkPlayerInfo { for (ActiveCosmetic activeCosmetic : activeCosmetics) { CosmeticData cosmeticData = DungeonsGuide.getDungeonsGuide().getCosmeticsManager().getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); if (cosmeticData == null) continue; - if (cosmeticData.getCosmeticType().equals("color")) color = cosmeticData; + if (cosmeticData.getCosmeticType().equals("ncolor")) color = cosmeticData; } if (color != null) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknameColor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknameColor.java index 1d8af9dc..c481c05e 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknameColor.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknameColor.java @@ -19,6 +19,7 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics; import kr.syeyoung.dungeonsguide.mod.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget.WidgetNicknameColor; import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.CompatLayer; @@ -29,14 +30,15 @@ public class FeatureNicknameColor extends SimpleFeature { @Override public Widget getConfigureWidget() { - return new CompatLayer( new PrefixSelectorGUI("color", new String[] { - "§9Party §8> §r§a[RANK§6+§a] %prefix%%name%§f: TEST", - "§2Guild > §r§a[RANK§6+§a] %prefix%%name% §3[Vet]§f: TEST", - "§dTo §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", - "§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", - "§r§b[RANK§c+§b] %prefix%%name%§f: TEST", - "§r§bCo-op > §r§a[RANK§6+§a] %prefix%%name%§f: §rTEST§r" - }, a -> (a.replace("&", "§")+"Color "+(a.replace("&", "§").equals("§z") ? "(Rainbow on sba)" : "")))); +// return new CompatLayer( new PrefixSelectorGUI("color", new String[] { +// "§9Party §8> §r§a[RANK§6+§a] %prefix%%name%§f: TEST", +// "§2Guild > §r§a[RANK§6+§a] %prefix%%name% §3[Vet]§f: TEST", +// "§dTo §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", +// "§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", +// "§r§b[RANK§c+§b] %prefix%%name%§f: TEST", +// "§r§bCo-op > §r§a[RANK§6+§a] %prefix%%name%§f: §rTEST§r" +// }, a -> (a.replace("&", "§")+"Color "+(a.replace("&", "§").equals("§z") ? "(Rainbow on sba)" : "")))); + return new WidgetNicknameColor(); } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknamePrefix.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknamePrefix.java index 52ef5396..2b7510ee 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknamePrefix.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/FeatureNicknamePrefix.java @@ -21,6 +21,7 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics; import kr.syeyoung.dungeonsguide.mod.config.types.TCString; import kr.syeyoung.dungeonsguide.mod.features.FeatureParameter; import kr.syeyoung.dungeonsguide.mod.features.SimpleFeature; +import kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget.WidgetNicknamePrefix; import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; import kr.syeyoung.dungeonsguide.mod.guiv2.elements.CompatLayer; @@ -32,14 +33,15 @@ public class FeatureNicknamePrefix extends SimpleFeature { @Override public Widget getConfigureWidget() { - return new CompatLayer(new PrefixSelectorGUI("prefix", new String[] { - "§9Party §8> §r%prefix% §a[RANK§6+§a] %name%§f: TEST", - "§2Guild > §r%prefix% §a[RANK§6+§a] %name% §3[Vet]§f: TEST", - "§dTo §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", - "§dFrom §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", - "§r%prefix% §b[RANK§c+§b] %name%§f: TEST", - "§r§bCo-op > §r%prefix% §a[RANK§6+§a] %name%§f: §rTEST§r" - }, a->a.replace("&", "§"))); +// return new CompatLayer(new PrefixSelectorGUI("prefix", new String[] { +// "§9Party §8> §r%prefix% §a[RANK§6+§a] %name%§f: TEST", +// "§2Guild > §r%prefix% §a[RANK§6+§a] %name% §3[Vet]§f: TEST", +// "§dTo §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", +// "§dFrom §r%prefix% §r§a[RANK§r§6+§r§a] %name%§r§7: §r§7TEST§r", +// "§r%prefix% §b[RANK§c+§b] %name%§f: TEST", +// "§r§bCo-op > §r%prefix% §a[RANK§6+§a] %name%§f: §rTEST§r" +// }, a->a.replace("&", "§"))); + return new WidgetNicknamePrefix(); } @Override diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetButton.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetButton.java new file mode 100644 index 00000000..dc6f38ec --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetButton.java @@ -0,0 +1,63 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget; + +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.Renderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.RenderingContext; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.SingleChildRenderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; +import net.minecraft.util.ResourceLocation; + +import java.util.Locale; + +public class WidgetButton extends AnnotatedImportOnlyWidget { + @Bind(variableName = "text") + public final BindableAttribute<String> text = new BindableAttribute<>(String.class); + @Bind(variableName = "normal") + public final BindableAttribute<Integer> normal = new BindableAttribute<>(Integer.class); + @Bind(variableName = "hover") + public final BindableAttribute<Integer> hover = new BindableAttribute<>(Integer.class); + @Bind(variableName = "press") + public final BindableAttribute<Integer> press = new BindableAttribute<>(Integer.class); + + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> _ = new BindableAttribute<>(Boolean.class, false); + + @Bind(variableName = "click") + public final BindableAttribute<Runnable> onClick = new BindableAttribute<>(Runnable.class); + + public WidgetButton(boolean enabled, String prefix, Runnable onClick) { + super(new ResourceLocation("dungeonsguide:gui/config/cosmetics/button2.gui")); + text.setValue(prefix); + this.onClick.setValue(onClick); + if (enabled) { + normal.setValue(0xFF1E387A); + hover.setValue(0xFF356091); + press.setValue(0xFF50799E); + } else { + normal.setValue(0xFF2E2D2C); + hover.setValue(RenderUtils.blendAlpha(0xFF2E2D2C, 0.2f)); + press.setValue(RenderUtils.blendAlpha(0xFF2E2D2C, 0.4f)); + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetColorButton.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetColorButton.java new file mode 100644 index 00000000..c4ab59d5 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetColorButton.java @@ -0,0 +1,103 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget; + +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.DomElement; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.Renderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.RenderingContext; +import kr.syeyoung.dungeonsguide.mod.guiv2.renderer.SingleChildRenderer; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; +import net.minecraft.util.ResourceLocation; + +import java.util.Locale; + +public class WidgetColorButton extends AnnotatedImportOnlyWidget implements Renderer { + @Bind(variableName = "text") + public final BindableAttribute<String> text = new BindableAttribute<>(String.class); + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> disabled = new BindableAttribute<>(Boolean.class); + @Bind(variableName = "normal") + public final BindableAttribute<Integer> normal = new BindableAttribute<>(Integer.class); + @Bind(variableName = "hover") + public final BindableAttribute<Integer> hover = new BindableAttribute<>(Integer.class); + @Bind(variableName = "press") + public final BindableAttribute<Integer> press = new BindableAttribute<>(Integer.class); + + @Bind(variableName = "click") + public final BindableAttribute<Runnable> onClick = new BindableAttribute<>(Runnable.class); + + private static final int[] colorCode = new int[32]; + static { + for(int i = 0; i < 32; ++i) { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i & 1) * 170 + j; + if (i == 6) { + k += 85; + } + + if (i >= 16) { + k /= 4; + l /= 4; + i1 /= 4; + } + + colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } + } + + private boolean chroma = false; + public WidgetColorButton(boolean enabled, String colorcode, Runnable onClick) { + super(new ResourceLocation("dungeonsguide:gui/config/cosmetics/button.gui")); + text.setValue(enabled ? "Available" : "Locked"); + disabled.setValue(false); + this.onClick.setValue(onClick); + int i1 = "0123456789abcdefz".indexOf(colorcode.toLowerCase(Locale.ENGLISH).charAt(0)); + + if (i1 == 16) { + chroma = true; + + int color =RenderUtils.getChromaColorAt(0, 0, 0.5f, 1, 1, 1.0f); + normal.setValue(color); + hover.setValue(RenderUtils.blendAlpha(color, 0.2f)); + press.setValue(RenderUtils.blendAlpha(color, 0.4f)); + } else { + int color = colorCode[i1] | 0xFF000000; + normal.setValue(color); + hover.setValue(RenderUtils.blendAlpha(color, 0.2f)); + press.setValue(RenderUtils.blendAlpha(color, 0.4f)); + } + } + + @Override + public void doRender(int absMouseX, int absMouseY, double relMouseX, double relMouseY, float partialTicks, RenderingContext context, DomElement buildContext) { + if (chroma) { + int color =RenderUtils.getChromaColorAt(0, 0, 0.3f, 1, 1, 1.0f); + normal.setValue(color); + hover.setValue(RenderUtils.blendAlpha(color, 0.2f)); + press.setValue(RenderUtils.blendAlpha(color, 0.4f)); + } + + SingleChildRenderer.INSTANCE.doRender(absMouseX, absMouseY, relMouseX, relMouseY, partialTicks, context, buildContext); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknameColor.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknameColor.java new file mode 100644 index 00000000..5a174b74 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknameColor.java @@ -0,0 +1,141 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget; + +import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.util.ResourceLocation; + +import java.awt.*; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; + +public class WidgetNicknameColor extends AnnotatedImportOnlyWidget { + @Bind(variableName = "preview") + public final BindableAttribute<String> preview = new BindableAttribute<>(String.class); + @Bind(variableName = "colors") + public final BindableAttribute colors = new BindableAttribute<>(WidgetList.class); + + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> disabled = new BindableAttribute<>(Boolean.class, false); + + private CosmeticData previouslySelected; + private CosmeticData currentSelected; + + public WidgetNicknameColor() { + super(new ResourceLocation("dungeonsguide:gui/config/cosmetics/nicknameColor.gui")); + + + ArrayList<Widget> list = new ArrayList<>(); + + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + for (CosmeticData value : cosmeticsManager.getCosmeticDataMap().values()) { + if (value.getCosmeticType().equals("ncolor")) { + list.add(new WidgetColorButton(cosmeticsManager.getPerms().contains(value.getReqPerm()), value.getData().substring(1), () -> { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + currentSelected = value; + update(); + })); + } + } + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData != null && cosmeticData.getCosmeticType().equals("ncolor")) { + currentSelected = cosmeticData; + previouslySelected = cosmeticData; + } + } + update(); + + colors.setValue(list); + } + + private void update() { + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + preview.setValue(String.join("\n",new String[] { + "§9Party §8> §r§a[RANK§6+§a] %prefix%%name%§f: TEST", + "§2Guild > §r§a[RANK§6+§a] %prefix%%name% §3[Vet]§f: TEST", + "§dTo §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", + "§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%%name%§r§7: §r§7TEST§r", + "§r§b[RANK§c+§b] %prefix%%name%§f: TEST", + "§r§bCo-op > §r§a[RANK§6+§a] %prefix%%name%§f: §rTEST§r" + }).replace("%name%", Minecraft.getMinecraft().getSession().getUsername()) + .replace("%prefix%", currentSelected == null ? "" : currentSelected.getData())); + + boolean disable = currentSelected == previouslySelected + || (currentSelected != null && !cosmeticsManager.getPerms().contains(currentSelected.getReqPerm())); + disabled.setValue(disable); + } + + @On(functionName = "apply") + public void onApply() { + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + boolean disable = currentSelected == previouslySelected + || (currentSelected != null && !cosmeticsManager.getPerms().contains(currentSelected.getReqPerm())); + if (disable) return; + + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + + if (previouslySelected != null) { + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + if (activeCosmetic.getCosmeticData().equals(previouslySelected.getId())) { + cosmeticsManager.removeCosmetic(activeCosmetic); + } + } + } + if (currentSelected != null) + cosmeticsManager.setCosmetic(currentSelected); + + previouslySelected = currentSelected; + + update(); + } + + @On(functionName = "clear") + public void onClear() { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + currentSelected = null; + update(); + } + + @On(functionName = "shop") + public void openShop() { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + try { + Desktop.getDesktop().browse(new URI("https://store.dungeons.guide/")); + } catch (IOException | URISyntaxException e) { + e.printStackTrace(); + } + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknamePrefix.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknamePrefix.java new file mode 100644 index 00000000..f69c4efb --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/cosmetics/widget/WidgetNicknamePrefix.java @@ -0,0 +1,196 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package kr.syeyoung.dungeonsguide.mod.features.impl.cosmetics.widget; + +import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; +import kr.syeyoung.dungeonsguide.mod.cosmetics.ActiveCosmetic; +import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticData; +import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticsManager; +import kr.syeyoung.dungeonsguide.mod.guiv2.BindableAttribute; +import kr.syeyoung.dungeonsguide.mod.guiv2.Widget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.AnnotatedImportOnlyWidget; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.Bind; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.annotations.On; +import kr.syeyoung.dungeonsguide.mod.guiv2.xml.data.WidgetList; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.util.ResourceLocation; + +import java.awt.*; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; + +public class WidgetNicknamePrefix extends AnnotatedImportOnlyWidget { + @Bind(variableName = "preview") + public final BindableAttribute<String> preview = new BindableAttribute<>(String.class); + @Bind(variableName = "prefixes") + public final BindableAttribute prefixes = new BindableAttribute<>(WidgetList.class); + @Bind(variableName = "colors") + public final BindableAttribute colors = new BindableAttribute<>(WidgetList.class); + + @Bind(variableName = "disabled") + public final BindableAttribute<Boolean> disabled = new BindableAttribute<>(Boolean.class, false); + + private CosmeticData previouslySelectedColor; + private CosmeticData currentSelectedColor; + + + private CosmeticData previouslySelectedPrefix; + private CosmeticData currentSelectedPrefix; + + public WidgetNicknamePrefix() { + super(new ResourceLocation("dungeonsguide:gui/config/cosmetics/nicknamePrefix.gui")); + + + ArrayList<Widget> list = new ArrayList<>(); + ArrayList<Widget> list2 = new ArrayList<>(); + + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + for (CosmeticData value : cosmeticsManager.getCosmeticDataMap().values()) { + if (value.getCosmeticType().equals("bracket_color")) { + list.add(new WidgetColorButton(cosmeticsManager.getPerms().contains(value.getReqPerm()), value.getData().substring(1), () -> { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + currentSelectedColor = value; + update(); + })); + } else if (value.getCosmeticType().equals("nprefix")) { + list2.add(new WidgetButton(cosmeticsManager.getPerms().contains(value.getReqPerm()), value.getData().substring(1), () -> { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + currentSelectedPrefix = value; + update(); + })); + } + } + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + CosmeticData cosmeticData = cosmeticsManager.getCosmeticDataMap().get(activeCosmetic.getCosmeticData()); + if (cosmeticData != null && cosmeticData.getCosmeticType().equals("bracket_color")) { + currentSelectedColor = cosmeticData; + previouslySelectedColor = cosmeticData; + } else if (cosmeticData != null && cosmeticData.getCosmeticType().equals("nprefix")) { + currentSelectedPrefix = cosmeticData; + previouslySelectedPrefix = cosmeticData; + } + } + + if (currentSelectedColor == null) { + for (CosmeticData value : cosmeticsManager.getCosmeticDataMap().values()) { + if (value.getCosmeticType().equals("bracket_color") && cosmeticsManager.getPerms().contains(value.getReqPerm())) { + currentSelectedColor = value; + break; + } + } + } + update(); + + colors.setValue(list); + prefixes.setValue(list2); + } + + private void update() { + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + String prefix = currentSelectedPrefix == null ? "" : currentSelectedPrefix.getData().substring(1); + if (currentSelectedColor != null && currentSelectedPrefix != null && currentSelectedPrefix.getData().startsWith("F")) + prefix = currentSelectedColor.getData()+"["+prefix+"§r"+currentSelectedColor.getData()+"]"; + + if (!prefix.isEmpty()) prefix += " "; + + preview.setValue(String.join("\n",new String[] { + "§9Party §8> §r§a[RANK§6+§a] %prefix%§a%name%§f: TEST", + "§2Guild > §r§a[RANK§6+§a] %prefix%§a%name% §3[Vet]§f: TEST", + "§dTo §r§r§a[RANK§r§6+§r§a] %prefix%§a%name%§r§7: §r§7TEST§r", + "§dFrom §r§r§a[RANK§r§6+§r§a] %prefix%§a%name%§r§7: §r§7TEST§r", + "§r§b[RANK§c+§b] %prefix%§a%name%§f: TEST", + "§r§bCo-op > §r§a[RANK§6+§a] %prefix%§a%name%§f: §rTEST§r" + }).replace("%name%", Minecraft.getMinecraft().getSession().getUsername()) + .replace("%prefix%", prefix)); + + boolean disable = (currentSelectedColor == previouslySelectedColor && currentSelectedPrefix == previouslySelectedPrefix) + || (currentSelectedColor != null && !cosmeticsManager.getPerms().contains(currentSelectedColor.getReqPerm())) + || (currentSelectedPrefix != null && !cosmeticsManager.getPerms().contains(currentSelectedPrefix.getReqPerm())); + disabled.setValue(disable); + } + + @On(functionName = "apply") + public void onApply() { + CosmeticsManager cosmeticsManager = DungeonsGuide.getDungeonsGuide().getCosmeticsManager(); + boolean disable = (currentSelectedColor == previouslySelectedColor && currentSelectedPrefix == previouslySelectedPrefix) + || (currentSelectedColor != null && !cosmeticsManager.getPerms().contains(currentSelectedColor.getReqPerm())) + || (currentSelectedPrefix != null && !cosmeticsManager.getPerms().contains(currentSelectedPrefix.getReqPerm())); + if (disable) return; + + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); + + if (previouslySelectedColor != null) { + List<ActiveCosmetic> activeCosmeticList = cosmeticsManager.getActiveCosmeticByPlayer().computeIfAbsent(Minecraft.getMinecraft().thePlayer.getGameProfile().getId(), (a) -> new ArrayList<>()); + for (ActiveCosmetic activeCosmetic : activeCosmeticList) { + if (activeCosmetic.getCosmeticData().equals(previouslySelectedColor.getId())) { + cosmeticsManager.removeCosmetic(activeCosmetic); < |
