diff options
author | Lulonaut <lulonaut@lulonaut.tech> | 2023-07-27 18:12:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 18:12:51 +0200 |
commit | 247239132ad481d5ba9d775e723e134ca116837e (patch) | |
tree | 19ecbb2106b9fa818391fb7ab83d5750d30dac87 /src/main/java | |
parent | 2c58c09f12eb4cceeacbb31fcca4804198be140b (diff) | |
download | NotEnoughUpdates-247239132ad481d5ba9d775e723e134ca116837e.tar.gz NotEnoughUpdates-247239132ad481d5ba9d775e723e134ca116837e.tar.bz2 NotEnoughUpdates-247239132ad481d5ba9d775e723e134ca116837e.zip |
buttons for guild name & status in PV (#776)
Co-authored-by: nea <nea@nea.moe>
Diffstat (limited to 'src/main/java')
5 files changed, 94 insertions, 24 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index 331d2ad3..a1135205 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NotEnoughUpdates contributors + * Copyright (C) 2022-2023 NotEnoughUpdates contributors * * This file is part of NotEnoughUpdates. * @@ -25,12 +25,14 @@ import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.profileviewer.level.LevelPage; import io.github.moulberry.notenoughupdates.profileviewer.weight.lily.LilyWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.PronounDB; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -121,6 +123,7 @@ public class BasicPage extends GuiProfileViewerPage { private boolean onSecondPage; private final LevelPage levelPage; + private boolean clickedLoadStatusButton = false; public BasicPage(GuiProfileViewer instance) { super(instance); @@ -141,7 +144,7 @@ public class BasicPage extends GuiProfileViewerPage { } String location = null; - JsonObject status = profile.getPlayerStatus(); + JsonObject status = clickedLoadStatusButton ? profile.getPlayerStatus() : null; if (status != null && status.has("mode")) { location = status.get("mode").getAsString(); } @@ -438,6 +441,29 @@ public class BasicPage extends GuiProfileViewerPage { } Utils.drawStringCentered(statusStr, guiLeft + 63, guiTop + 160, true, 0); + } else { + Rectangle buttonRect = new Rectangle( + guiLeft + 24, + guiTop + 155, + 80, + 12 + ); + + RenderUtils.drawFloatingRectWithAlpha(buttonRect.getX(), buttonRect.getY(), buttonRect.getWidth(), + buttonRect.getHeight(), 100, true + ); + Utils.renderShadowedString( + clickedLoadStatusButton + ? EnumChatFormatting.AQUA + "Loading..." + : EnumChatFormatting.WHITE + "Load Status", + guiLeft + 63, + guiTop + 157, + 79 + ); + + if (Mouse.getEventButtonState() && Utils.isWithinRect(mouseX, mouseY, buttonRect)) { + clickedLoadStatusButton = true; + } } if (entityPlayer == null) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index fb1b3364..1672fa83 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 NotEnoughUpdates contributors + * Copyright (C) 2022-2023 NotEnoughUpdates contributors * * This file is part of NotEnoughUpdates. * @@ -25,8 +25,10 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.Weight; import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.Rectangle; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.util.EnumChatFormatting; @@ -63,6 +65,7 @@ public class ExtraPage extends GuiProfileViewerPage { private TreeMap<Integer, Set<String>> topDeaths = null; private int deathScroll = 0; private int killScroll = 0; + private boolean clickedLoadGuildInfoButton = false; public ExtraPage(GuiProfileViewer instance) { super(instance); @@ -217,29 +220,61 @@ public class ExtraPage extends GuiProfileViewerPage { ); } } - JsonObject guildInfo = GuiProfileViewer.getProfile().getOrLoadGuildInformation(null); - boolean shouldRenderGuild = guildInfo != null && guildInfo.has("name"); - { - if (shouldRenderGuild) { - Utils.renderAlignedString( - EnumChatFormatting.AQUA + "Guild", - EnumChatFormatting.WHITE + guildInfo.get("name").getAsString(), - guiLeft + xStart, - guiTop + yStartTop + yOffset * 3, - 76 - ); - } + + JsonObject guildInfo; + if (GuiProfileViewer.getProfile().isPlayerInGuild()) { + guildInfo = + clickedLoadGuildInfoButton ? GuiProfileViewer.getProfile().getOrLoadGuildInformation(null) : null; + } else { + guildInfo = new JsonObject(); + guildInfo.add("name", new JsonPrimitive("N/A")); } - { - GuiProfileViewer.pronouns.peekValue().flatMap(it -> it).ifPresent(choice -> Utils.renderAlignedString( - EnumChatFormatting.GREEN + "Pronouns", - EnumChatFormatting.WHITE + String.join(" / ", choice.render()), + + boolean shouldRenderGuild = guildInfo != null && guildInfo.has("name"); + + // Render the info when the button has been clicked + if (shouldRenderGuild) { + Utils.renderAlignedString( + EnumChatFormatting.AQUA + "Guild", + EnumChatFormatting.WHITE + guildInfo.get("name").getAsString(), guiLeft + xStart, - guiTop + yStartTop + yOffset * (shouldRenderGuild ? 4 : 3), + guiTop + yStartTop + yOffset * 3, 76 - )); + ); + } else { + // Render a button to click to load the guild info + Rectangle buttonRect = new Rectangle( + (int) (guiLeft + xStart - 1), + (int) (guiTop + yStartTop + yOffset * 3), + 78, + 12 + ); + + RenderUtils.drawFloatingRectWithAlpha(buttonRect.getX(), buttonRect.getY(), buttonRect.getWidth(), + buttonRect.getHeight(), 100, true + ); + Utils.renderShadowedString( + clickedLoadGuildInfoButton + ? EnumChatFormatting.AQUA + "Loading..." + : EnumChatFormatting.WHITE + "Load Guild Info", + guiLeft + xStart + 38, + guiTop + yStartTop + yOffset * 3 + 2, + 70 + ); + + if (Mouse.getEventButtonState() && Utils.isWithinRect(mouseX, mouseY, buttonRect)) { + clickedLoadGuildInfoButton = true; + } } + GuiProfileViewer.pronouns.peekValue().flatMap(it -> it).ifPresent(choice -> Utils.renderAlignedString( + EnumChatFormatting.GREEN + "Pronouns", + EnumChatFormatting.WHITE + String.join(" / ", choice.render()), + guiLeft + xStart, + guiTop + yStartTop + yOffset * 4 + (shouldRenderGuild ? 0 : 5), + 76 + )); + float fairySouls = Utils.getElementAsFloat(Utils.getElement(profileInfo, "fairy_souls_collected"), 0); int fairySoulMax = 227; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index 4df5a675..4e3ef022 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -258,8 +258,6 @@ public class GuiProfileViewer extends GuiScreen { profileName = profile.getLatestProfileName(); } - // Preload guild info - profile.getOrLoadGuildInformation(null); } this.sizeX = 431; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java index 61872980..c16d8df0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/SkyblockProfiles.java @@ -100,6 +100,8 @@ public class SkyblockProfiles { private long soopyNetworthLeaderboardPosition = -1; // -1 = default, -2 = loading, -3 = error private long soopyWeightLeaderboardPosition = -1; // -1 = default, -2 = loading, -3 = error private JsonObject guildInformation = null; + // Assume the player is in a guild until proven otherwise + private boolean isInGuild = true; private JsonObject playerStatus = null; private JsonObject bingoInformation = null; private long lastPlayerInfoState = 0; @@ -390,7 +392,8 @@ public class SkyblockProfiles { updatingGuildInfoState.set(false); if (jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { - if (!jsonObject.has("guild")) { + if (jsonObject.get("guild").isJsonNull()) { + isInGuild = false; return null; } @@ -406,6 +409,10 @@ public class SkyblockProfiles { return null; } + public boolean isPlayerInGuild() { + return isInGuild; + } + public List<String> getProfileNames() { return profileNames; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 7f607ab7..052ea33f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -2112,6 +2112,10 @@ public class Utils { top <= y && y < top + height; } + public static boolean isWithinRect(int x, int y, Rectangle rectangle) { + return isWithinRect(x, y, rectangle.getLeft(), rectangle.getTop(), rectangle.getWidth(), rectangle.getHeight()); + } + public static int getNumberOfStars(ItemStack stack) { if (stack != null && stack.hasTagCompound()) { NBTTagCompound tag = stack.getTagCompound(); |