diff options
author | syeyoung <cyong06@naver.com> | 2021-08-10 23:35:14 +0900 |
---|---|---|
committer | syeyoung <cyong06@naver.com> | 2021-08-10 23:35:14 +0900 |
commit | a48cb5c96e16fae589cb7d4f09146a17b3787924 (patch) | |
tree | f96af8b3c438357dad8ea6e0b223ce5351e82212 /src/main/java/kr/syeyoung/dungeonsguide/party | |
parent | 3f2a8ec601bdc43bbb2a48ef61e372e4c907ce8d (diff) | |
download | Skyblock-Dungeons-Guide-a48cb5c96e16fae589cb7d4f09146a17b3787924.tar.gz Skyblock-Dungeons-Guide-a48cb5c96e16fae589cb7d4f09146a17b3787924.tar.bz2 Skyblock-Dungeons-Guide-a48cb5c96e16fae589cb7d4f09146a17b3787924.zip |
Better Rich Presence
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/party')
4 files changed, 1 insertions, 425 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java b/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java deleted file mode 100644 index ca3764d9..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/LoadedImage.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod - * Copyright (C) 2021 cyoung06 - * - * 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.party; - - -import lombok.Data; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.util.ResourceLocation; - -import java.awt.image.BufferedImage; - -@Data -public class LoadedImage { - private String url; - private BufferedImage image; - private DynamicTexture previewTexture; - private ResourceLocation resourceLocation; - - public void buildGLThings() { - previewTexture = new DynamicTexture(image); - resourceLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("dgurl/"+url, previewTexture); - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java deleted file mode 100644 index 8dbdf2bb..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyInviteViewer.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod - * Copyright (C) 2021 cyoung06 - * - * 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.party; - -import kr.syeyoung.dungeonsguide.DungeonsGuide; -import kr.syeyoung.dungeonsguide.RichPresenceManager; -import kr.syeyoung.dungeonsguide.gamesdk.jna.enumuration.EDiscordActivityJoinRequestReply; -import kr.syeyoung.dungeonsguide.utils.TextUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.*; -import java.util.List; -import java.util.concurrent.*; - -public class PartyInviteViewer { - public static final PartyInviteViewer INSTANCE = new PartyInviteViewer(); - - @SubscribeEvent - public void onRender(RenderGameOverlayEvent.Post postRender) { - try { - if (postRender.type == RenderGameOverlayEvent.ElementType.TEXT) { - renderRequests(false); - } - } catch (Throwable t) { - t.printStackTrace(); - } - } - - @SubscribeEvent - public void onRender(GuiScreenEvent.DrawScreenEvent.Post postRender) { - renderRequests(true); - } - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent clientTickEvent) { - try { - if (clientTickEvent.phase != TickEvent.Phase.START) return; - List<PartyJoinRequest> partyJoinRequestList = new ArrayList<>(); - boolean isOnHypixel = DungeonsGuide.getDungeonsGuide().getSkyblockStatus().isOnHypixel(); - for (PartyJoinRequest joinRequest:joinRequests) { - if (joinRequest.getTtl() != -1) { - joinRequest.setTtl(joinRequest.getTtl() - 1); - if (joinRequest.getTtl() == 0 || !isOnHypixel) { - partyJoinRequestList.add(joinRequest); - } - } else if (!isOnHypixel){ -// DiscordRPC.discordRespond(joinRequest.getDiscordUser().userId, DiscordRPC.DiscordReply.NO); - partyJoinRequestList.add(joinRequest); - } else if (joinRequest.getExpire() < System.currentTimeMillis()) { - partyJoinRequestList.add(joinRequest); - } - } - joinRequests.removeAll(partyJoinRequestList); - } catch (Throwable e) {e.printStackTrace();} - } - - - - @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGH) - public void onRender(GuiScreenEvent.MouseInputEvent.Pre mouseInput) { - int mouseX = Mouse.getX(); - int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3; - for (PartyJoinRequest joinRequest:joinRequests) { - if (joinRequest.getWholeRect() != null && joinRequest.getWholeRect().contains(mouseX, mouseY)) { - mouseInput.setCanceled(true); - - if (Mouse.getEventButton() == -1) return; - - if (joinRequest.getReply() != null) { - joinRequests.remove(joinRequest); - return; - } - - if (!joinRequest.isInvite()) { - if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Yes); - return; - } - - if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.DENY); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_No); - return; - } - - if (joinRequest.getIgnoreRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.IGNORE); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.respond(joinRequest.getDiscordUser().id, EDiscordActivityJoinRequestReply.DiscordActivityJoinRequestReply_Ignore); - return; - } - } else { - if (joinRequest.getAcceptRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.ACCEPT); - joinRequest.setTtl(60); - RichPresenceManager.INSTANCE.accept(joinRequest.getDiscordUser().id); - return; - } - - if (joinRequest.getDenyRect().contains(mouseX, mouseY)) { - joinRequest.setReply(PartyJoinRequest.Reply.DENY); - joinRequest.setTtl(60); - return; - } - } - - return; - } - } - } - - - public CopyOnWriteArrayList<PartyJoinRequest> joinRequests = new CopyOnWriteArrayList<>(); - - ExecutorService executorService = Executors.newFixedThreadPool(3); - public Map<String, Future<LoadedImage>> futureMap = new HashMap<>(); - public Map<String, LoadedImage> imageMap = new HashMap<>(); - - public Future<LoadedImage> loadImage(String url) { - if (imageMap.containsKey(url)) return CompletableFuture.completedFuture(imageMap.get(url)); - if (futureMap.containsKey(url)) return futureMap.get(url); - Future<LoadedImage> future = executorService.submit(() -> { - try { - URL urlObj = new URL(url); - HttpURLConnection huc = (HttpURLConnection) urlObj.openConnection(); - huc.addRequestProperty("User-Agent", "DungeonsGuideMod (dungeons.guide, 1.0)"); - BufferedImage bufferedImage = ImageIO.read(huc.getInputStream()); - BufferedImage newImage = new BufferedImage(128,128, BufferedImage.TYPE_INT_RGB); - Graphics g = newImage.createGraphics(); - g.drawImage(bufferedImage, 0, 0, 128, 128, null); - g.dispose(); - LoadedImage loadedImage = new LoadedImage(); - loadedImage.setImage(newImage); - imageMap.put(url, loadedImage); - return loadedImage; - } catch (Exception e) { - throw e; - } - }); - futureMap.put(url,future); - return future; - } - - - public void renderRequests(boolean hover) { - try { - GlStateManager.pushMatrix(); - ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); - GlStateManager.scale(1.0 / sr.getScaleFactor(), 1.0 / sr.getScaleFactor(), 1.0); - int height = 90; - int gap = 5; - int x = 5; - int y = 5; - for (PartyJoinRequest partyJoinRequest : joinRequests) { - renderRequest(partyJoinRequest, x, y, 350,height, hover); - y += height + gap; - } - GlStateManager.popMatrix(); - GlStateManager.enableBlend(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - - public void renderRequest(PartyJoinRequest partyJoinRequest, int x, int y, int width, int height, boolean hover) { - ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); - - int mouseX = Mouse.getX(); - int mouseY = Minecraft.getMinecraft().displayHeight - Mouse.getY() +3; - - partyJoinRequest.getWholeRect().setBounds(x,y,width,height); - - - GlStateManager.pushMatrix(); - GlStateManager.translate(x,y,0); - - Gui.drawRect(0, 0,width,height, 0xFF23272a); - Gui.drawRect(2, 2, width-2, height-2, 0XFF2c2f33); - { - String avatar = "https://cdn.discordapp.com/avatars/"+Long.toUnsignedString(partyJoinRequest.getDiscordUser().id.longValue())+"/"+partyJoinRequest.getAvatar()+"."+(partyJoinRequest.getAvatar().startsWith("a_") ? "gif":"png"); - Future<LoadedImage> loadedImageFuture = loadImage(avatar); - LoadedImage loadedImage = null; - if (loadedImageFuture.isDone()) { - try { - loadedImage = loadedImageFuture.get(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - } - if (loadedImage != null) { - if (loadedImage.getResourceLocation() == null) loadedImage.buildGLThings(); - TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); - textureManager.bindTexture(loadedImage.getResourceLocation()); - - GlStateManager.color(1, 1, 1, 1.0F); - - Gui.drawScaledCustomSizeModalRect(7, 7, 0, 0, loadedImage.getImage().getWidth(),loadedImage.getImage().getHeight(),height-14,height-14, loadedImage.getImage().getWidth(), loadedImage.getImage().getHeight()); - } else { - Gui.drawRect(7, 7, height - 7, height-7, 0xFF4E4E4E); - } - } - - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - GlStateManager.pushMatrix(); - GlStateManager.translate(height +3,7, 0); - - GlStateManager.pushMatrix(); - GlStateManager.scale(3.0,3.0,1.0); - fr.drawString(partyJoinRequest.getUsername()+"", 0,0, 0xFFFFFFFF, true); - GlStateManager.popMatrix(); - - GlStateManager.pushMatrix(); - GlStateManager.translate(fr.getStringWidth(partyJoinRequest.getUsername()+"") * 3 + 1, (int)(fr.FONT_HEIGHT*1.5), 0); - fr.drawString("#"+partyJoinRequest.getDiscriminator(), 0,0,0xFFaaaaaa, true); - GlStateManager.popMatrix(); - GlStateManager.pushMatrix(); - GlStateManager.translate(0, fr.FONT_HEIGHT * 3 + 5, 0); - GlStateManager.scale(1.0,1.0,1.0); - if (partyJoinRequest.isInvite()) - fr.drawString("§ewants to you to join their party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false); - else - fr.drawString("wants to join your party! ("+(TextUtils.formatTime(partyJoinRequest.getExpire() - System.currentTimeMillis()))+")", 0,0,0xFFFFFFFF,false); - GlStateManager.popMatrix(); - GlStateManager.popMatrix(); - if (partyJoinRequest.getReply() == null) { - GlStateManager.pushMatrix(); - GlStateManager.translate(height + 3, height - 32, 0); - int widthForTheThing = (width - height) / 3; - GlStateManager.pushMatrix(); - String text = "Accept"; - partyJoinRequest.getAcceptRect().setBounds(x + height + 3, y + height - 25, widthForTheThing - 10, 25); - Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getAcceptRect().contains(mouseX, mouseY) ? 0xFF859DF0 : 0xFF7289da); - GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); - - GlStateManager.scale(2.0f, 2.0f, 1.0f); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - fr.drawString(text, 0, 0, 0xFFFFFFFF); - GlStateManager.popMatrix(); - GlStateManager.translate(widthForTheThing, 0, 0); - partyJoinRequest.getDenyRect().setBounds(x + height + 3 + widthForTheThing, y + height - 25, widthForTheThing - 10, 25); - Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getDenyRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5); - GlStateManager.pushMatrix(); - text = "Deny"; - GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); - GlStateManager.scale(2.0f, 2.0f, 1.0f); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - fr.drawString(text, 0, 0, 0xFFFFFFFF); - GlStateManager.popMatrix(); - if (!partyJoinRequest.isInvite()) { - GlStateManager.translate(widthForTheThing, 0, 0); - partyJoinRequest.getIgnoreRect().setBounds(x + height + 3 + widthForTheThing + widthForTheThing, y + height - 25, widthForTheThing - 10, 25); - Gui.drawRect(0, 0, widthForTheThing - 10, 25, hover && partyJoinRequest.getIgnoreRect().contains(mouseX, mouseY) ? 0xFFAEC0CB : 0xFF99aab5); // AEC0CB - - GlStateManager.pushMatrix(); - text = "Ignore"; - GlStateManager.translate((widthForTheThing - 10 - fr.getStringWidth(text) * 2) / 2, 15 - fr.FONT_HEIGHT, 0); - GlStateManager.scale(2.0f, 2.0f, 1.0f); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - fr.drawString(text, 0, 0, 0xFFFFFFFF); - GlStateManager.popMatrix(); - } - GlStateManager.popMatrix(); - } else { - GlStateManager.pushMatrix(); - GlStateManager.translate(height + 3, height - 28, 0); - GlStateManager.scale(2.0f,2.0f,1.0f); - GlStateManager.enableBlend(); - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - fr.drawString(partyJoinRequest.getReply().getPast()+" the invite.",0,0,0xFFFFFFFF); - GlStateManager.popMatrix(); - } - GlStateManager.popMatrix(); - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java deleted file mode 100644 index a894ee4e..00000000 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyJoinRequest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod - * Copyright (C) 2021 cyoung06 - * - * 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.party; - -import kr.syeyoung.dungeonsguide.gamesdk.GameSDK; -import kr.syeyoung.dungeonsguide.gamesdk.jna.datastruct.DiscordUser; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.Getter; - -import java.awt.*; - -@Data -public class PartyJoinRequest { - private DiscordUser discordUser; - - public void setDiscordUser(DiscordUser discordUser) { - this.discordUser = discordUser; - username = GameSDK.readString(discordUser.username); - discriminator = GameSDK.readString(discordUser.discriminator); - avatar = GameSDK.readString(discordUser.avatar); - System.out.println(username+"/"+discriminator+"/"+avatar); - } - - private String username, discriminator, avatar; - private long expire; - - private Rectangle wholeRect = new Rectangle(); - private Rectangle acceptRect = new Rectangle(); - private Rectangle denyRect = new Rectangle(); - private Rectangle ignoreRect = new Rectangle(); - - private boolean isInvite; - private int ttl = -1; - private Reply reply; - - @AllArgsConstructor - public enum Reply { - ACCEPT("Accepted"), DENY("Denied"), IGNORE("Ignored"); - - @Getter - private final String past; - } -} diff --git a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java index eaebc433..7382f203 100644 --- a/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java +++ b/src/main/java/kr/syeyoung/dungeonsguide/party/PartyManager.java @@ -18,7 +18,7 @@ package kr.syeyoung.dungeonsguide.party; -import kr.syeyoung.dungeonsguide.RichPresenceManager; +import kr.syeyoung.dungeonsguide.rpc.RichPresenceManager; import kr.syeyoung.dungeonsguide.DungeonsGuide; import kr.syeyoung.dungeonsguide.events.HypixelJoinedEvent; import kr.syeyoung.dungeonsguide.events.StompConnectedEvent; @@ -42,7 +42,6 @@ import org.json.JSONObject; import java.security.SecureRandom; import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.SynchronousQueue; import java.util.function.Consumer; public class PartyManager implements StompMessageHandler { |