aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
Diffstat (limited to 'mod')
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInvite.java117
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInviteElement.java104
2 files changed, 221 insertions, 0 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInvite.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInvite.java
new file mode 100644
index 00000000..f3d05ff4
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInvite.java
@@ -0,0 +1,117 @@
+/*
+ * 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.mod.features.impl.discord.invteTooltip;
+
+import kr.syeyoung.dungeonsguide.mod.discord.DiscordIntegrationManager;
+import kr.syeyoung.dungeonsguide.mod.discord.JDiscordRelation;
+import kr.syeyoung.dungeonsguide.mod.gui.MPanel;
+import kr.syeyoung.dungeonsguide.mod.gui.elements.*;
+import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils;
+import net.minecraft.client.renderer.GlStateManager;
+
+import java.awt.*;
+import java.util.HashSet;
+import java.util.Set;
+
+public class MTooltipInvite extends MModal {
+ private MScrollablePanel mScrollablePanel;
+ private MList list;
+ private MTextField search;
+ private MButton close;
+ private Set<Long> invited = new HashSet<>();
+ public MTooltipInvite() {
+ setTitle("Invite Discord Friend");
+ mScrollablePanel = new MScrollablePanel(1);
+ mScrollablePanel.setHideScrollBarWhenNotNecessary(true);
+ add(mScrollablePanel);
+
+ list = new MList() {
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ setSize(new Dimension(parentWidth, 9999));
+ realignChildren();
+ }
+ };
+ list.setGap(1);
+ list.setDrawLine(true);
+ list.setGapLineColor(RenderUtils.blendAlpha(0x141414, 0.13f));
+ mScrollablePanel.add(list);
+ mScrollablePanel.getScrollBarY().setWidth(5);
+
+ search = new MTextField() {
+ @Override
+ public void edit(String str) {
+ super.edit(str); resetListContent();
+ }
+ };
+ search.setPlaceHolder("Search...");
+ add(search);
+
+ close = new MButton();
+ close.setText("X");
+ close.setBackground( RenderUtils.blendAlpha(0x141414, 0.20f));
+ close.setHover( RenderUtils.blendAlpha(0x141414, 0.25f));
+ close.setClicked( RenderUtils.blendAlpha(0x141414, 0.24f));
+ close.setOnActionPerformed(this::close);
+ addSuper(close);
+ resetListContent();
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ super.onBoundsUpdate();
+ Dimension effDim = getModalContent().getSize();
+ search.setBounds(new Rectangle(5,2,effDim.width-10, 15));
+ mScrollablePanel.setBounds(new Rectangle(10,18,effDim.width-20, effDim.height-25));
+ close.setBounds(new Rectangle(getModalContent().getBounds().x + effDim.width-15,getModalContent().getBounds().y - 16,15,15));
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ GlStateManager.pushMatrix();
+ super.render(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor);
+ GlStateManager.popMatrix();
+
+ Dimension modalSize = getModalSize();
+ Dimension effDim = getEffectiveDimension();
+ int x = (effDim.width-modalSize.width)/2;
+ int y = (effDim.height - modalSize.height)/2;
+ GlStateManager.translate(x,y, 0);
+ }
+
+ private void resetListContent() {
+ for (MPanel childComponent : list.getChildComponents()) {
+ list.remove(childComponent);
+ }
+
+ String searchTxt = search.getText().trim().toLowerCase();
+ for (JDiscordRelation value : DiscordIntegrationManager.INSTANCE.getRelationMap().values()) {
+// if (value.getDiscordActivity().getApplicationId() != 816298079732498473L) continue;
+ if (value.getRelationType() == JDiscordRelation.DiscordRelationType.Blocked) continue;
+ if (!searchTxt.isEmpty() && !(value.getDiscordUser().getName().toLowerCase().contains(searchTxt))) continue;
+ list.add(new MTooltipInviteElement(value, invited.contains(value.getDiscordUser().getId()), this::invite));
+ }
+ setBounds(getBounds());
+ }
+
+ public void invite(long id) {
+ invited.add(id);
+ DiscordIntegrationManager.INSTANCE.sendInvite(Long.toUnsignedString(id), "Pls join my game");
+ }
+}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInviteElement.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInviteElement.java
new file mode 100644
index 00000000..e7583728
--- /dev/null
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/invteTooltip/MTooltipInviteElement.java
@@ -0,0 +1,104 @@
+/*
+ * 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.mod.features.impl.discord.invteTooltip;
+
+
+import kr.syeyoung.dungeonsguide.mod.discord.JDiscordRelation;
+import kr.syeyoung.dungeonsguide.mod.gui.MPanel;
+import kr.syeyoung.dungeonsguide.mod.gui.elements.MButton;
+import kr.syeyoung.dungeonsguide.mod.guiv2.elements.image.ImageTexture;
+import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.renderer.GlStateManager;
+
+import java.awt.*;
+import java.util.function.Consumer;
+
+public class MTooltipInviteElement extends MPanel {
+ private JDiscordRelation relation;
+ private MButton invite;
+ private ImageTexture texture;
+
+ public MTooltipInviteElement(JDiscordRelation jDiscordRelation, boolean invited, Consumer<Long> inviteCallback) {
+ this.relation = jDiscordRelation;
+ this.invite = new MButton();
+ if (!invited) {
+ invite.setText("Invite");
+ invite.setRoundness(2);
+ invite.setBorder(0xFF02EE67);
+ invite.setHover(RenderUtils.blendAlpha(0x141414, 0.2f));
+ invite.setBackground(RenderUtils.blendAlpha(0x141414, 0.17f));
+ invite.setForeground(new Color(0xFF02EE67));
+
+ invite.setOnActionPerformed(() -> {
+ if (invite.isEnabled())
+ inviteCallback.accept(jDiscordRelation.getDiscordUser().getIdLong());
+
+ invite.setText("Sent");
+ invite.setRoundness(2);
+ invite.setHover(0); invite.setBorder(0);
+ invite.setBackground(0); invite.setDisabled(0); invite.setEnabled(false);
+ invite.setForeground(new Color(0xFF02EE67));
+ });
+ } else {
+ invite.setText("Sent");
+ invite.setRoundness(2);
+ invite.setHover(0);
+ invite.setBackground(0); invite.setDisabled(0); invite.setEnabled(false);
+ invite.setForeground(new Color(0xFF02EE67));
+ }
+
+ if (!jDiscordRelation.getDiscordUser().getEffectiveAvatarUrl().isEmpty()) {
+ ImageTexture.loadImage(jDiscordRelation.getDiscordUser().getEffectiveAvatarUrl(), (cback) -> {
+ this.texture = cback;
+ });
+ }
+
+ add(invite);
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ if (lastAbsClip.contains(absMousex, absMousey) && getTooltipsOpen() == 0) {
+ RenderUtils.drawRoundedRectangle(0,0,bounds.width, bounds.height, 3, Math.PI/8, RenderUtils.blendAlpha(0x141414, 0.17f));
+ GlStateManager.enableTexture2D();
+ }
+
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+ if (texture != null) {
+ texture.drawFrame( 3,3,bounds.height-6,bounds.height-6);
+ } else {
+ Gui.drawRect(3, 3, bounds.height - 6, bounds.height-6, 0xFF4E4E4E);
+ }
+
+ fr.drawString(relation.getDiscordUser().getName()+"#"+relation.getDiscordUser().getDiscriminator(), bounds.height,(bounds.height-fr.FONT_HEIGHT)/2, -1);
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ return new Dimension(100, 20);
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ invite.setBounds(new Rectangle(bounds.width-53,2,50,bounds.height-4));
+ }
+}