1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
* 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.gui.elements;
import kr.syeyoung.dungeonsguide.gui.MPanel;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.util.List;
public class MPopupMenu extends MTooltip {
private int x, y;
public MPopupMenu(int x, int y, List<MPanel> popupMenuElementList) {
this.x = x; this.y = y;
int maxWidth = 150;
for (MPanel mPanel : popupMenuElementList) {
Dimension dimension = mPanel.getPreferredSize();
if (dimension.width > maxWidth) maxWidth = dimension.width;
}
int h1 = 7;
for (MPanel mPanel : popupMenuElementList) {
Dimension dimension = mPanel.getPreferredSize();
mPanel.setBounds(new Rectangle(7,h1, maxWidth-13, dimension.height));
h1 += dimension.height + 7;
add(mPanel);
}
if (y + h1 > Minecraft.getMinecraft().displayHeight)
y = Minecraft.getMinecraft().displayHeight - h1;
if (x + maxWidth+ 2 > Minecraft.getMinecraft().displayWidth)
x = Minecraft.getMinecraft().displayWidth - maxWidth-2;
setBounds(new Rectangle(x,y,maxWidth+2, h1));
}
@Override
public void setScale(double scale) {
super.setScale(scale);
int maxWidth = 150;
for (MPanel mPanel : getChildComponents()) {
Dimension dimension = mPanel.getPreferredSize();
if (dimension.width > maxWidth) maxWidth = dimension.width;
}
int h1 = 7;
for (MPanel mPanel : getChildComponents()) {
Dimension dimension = mPanel.getPreferredSize();
mPanel.setBounds(new Rectangle(7,h1, maxWidth-13, dimension.height));
h1 += dimension.height + 7;
}
maxWidth += 2;
maxWidth *= scale; h1 *= scale;
if (y + h1 > Minecraft.getMinecraft().displayHeight)
y = Minecraft.getMinecraft().displayHeight - h1;
if (x + maxWidth > Minecraft.getMinecraft().displayWidth)
x = Minecraft.getMinecraft().displayWidth - maxWidth;
setBounds(new Rectangle(x,y,maxWidth, h1));
}
@Override
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
super.render(absMousex, absMousey, relMousex0, relMousey0, partialTicks, scissor);
int radius = 7;
double deltaDegree = Math.PI/6;
Dimension effectiveDim = getEffectiveDimension();
RenderUtils.drawRoundedRectangle(0,0,effectiveDim.width,effectiveDim.height,radius,deltaDegree, RenderUtils.blendAlpha(0x121212, 0.0f));
for (int i = 1; i < getChildComponents().size(); i++) {
MPanel childComponent = getChildComponents().get(i);
Gui.drawRect(7,childComponent.getBounds().y - 4, effectiveDim.width-7, childComponent.getBounds().y - 3, RenderUtils.blendAlpha(0x121212, 0.10f));
}
}
@Override
public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
if (!getBounds().contains(absMouseX, absMouseY)) {
close();
}
}
}
|