GuiModInfoPanel.java
5.85 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.client.gui.modlist;
import static com.mumfrey.liteloader.gl.GL.*;
import static com.mumfrey.liteloader.gl.GLClippingPlanes.*;
import com.google.common.base.Strings;
import com.mumfrey.liteloader.client.api.LiteLoaderBrandingProvider;
import com.mumfrey.liteloader.client.gui.GuiSimpleScrollBar;
import com.mumfrey.liteloader.client.util.render.IconAbsolute;
import com.mumfrey.liteloader.core.ModInfo;
import com.mumfrey.liteloader.util.render.IconTextured;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
public class GuiModInfoPanel extends Gui
{
private static final int TITLE_COLOUR = GuiModListPanel.WHITE;
private static final int AUTHORS_COLOUR = GuiModListPanel.WHITE;
private static final int DIVIDER_COLOUR = GuiModListPanel.GREY;
private static final int DESCRIPTION_COLOUR = GuiModListPanel.WHITE;
private static final IconAbsolute infoIcon = new IconAbsolute(LiteLoaderBrandingProvider.ABOUT_TEXTURE, "Info", 12, 12, 146, 92, 158, 104);
private final ModListEntry owner;
private final FontRenderer fontRenderer;
private final int brandColour;
private final ModInfo<?> modInfo;
private GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar();
private boolean mouseOverPanel, mouseOverScrollBar;
private boolean showHelp;
private String helpTitle, helpText;
public GuiModInfoPanel(ModListEntry owner, FontRenderer fontRenderer, int brandColour, ModInfo<?> modInfo)
{
this.owner = owner;
this.fontRenderer = fontRenderer;
this.brandColour = brandColour;
this.modInfo = modInfo;
}
public void draw(int mouseX, int mouseY, float partialTicks, int xPosition, int yPosition, int width, int height)
{
int bottom = height + yPosition;
int yPos = yPosition + 2;
this.mouseOverPanel = this.isMouseOver(mouseX, mouseY, xPosition, yPos, width, height);
this.fontRenderer.drawString(this.owner.getTitleText(), xPosition + 5, yPos, GuiModInfoPanel.TITLE_COLOUR); yPos += 10;
this.fontRenderer.drawString(this.owner.getVersionText(), xPosition + 5, yPos, GuiModListPanel.VERSION_TEXT_COLOUR); yPos += 10;
drawRect(xPosition + 5, yPos, xPosition + width, yPos + 1, GuiModInfoPanel.DIVIDER_COLOUR); yPos += 4; // divider
this.fontRenderer.drawString(I18n.format("gui.about.authors") + ": \2477" + this.modInfo.getAuthor(), xPosition + 5, yPos,
GuiModInfoPanel.AUTHORS_COLOUR); yPos += 10;
if (!Strings.isNullOrEmpty(this.modInfo.getURL()))
{
this.fontRenderer.drawString(this.modInfo.getURL(), xPosition + 5, yPos, GuiModListPanel.BLEND_2THRDS & this.brandColour); yPos += 10;
}
drawRect(xPosition + 5, yPos, xPosition + width, yPos + 1, GuiModInfoPanel.DIVIDER_COLOUR); yPos += 4; // divider
drawRect(xPosition + 5, bottom - 1, xPosition + width, bottom, GuiModInfoPanel.DIVIDER_COLOUR); // divider
glEnableClipping(-1, -1, yPos, bottom - 3);
int scrollHeight = bottom - yPos - 3;
int contentHeight = this.drawContent(xPosition, width, yPos);
this.scrollBar.setMaxValue(contentHeight - scrollHeight);
this.scrollBar.drawScrollBar(mouseX, mouseY, partialTicks, xPosition + width - 5, yPos, 5, scrollHeight, contentHeight);
this.mouseOverScrollBar = this.isMouseOver(mouseX, mouseY, xPosition + width - 5, yPos, 5, scrollHeight);
}
private int drawContent(int xPosition, int width, int yPos)
{
yPos -= this.scrollBar.getValue();
if (this.showHelp)
{
this.drawIcon(xPosition + 3, yPos, GuiModInfoPanel.infoIcon); yPos += 2;
this.fontRenderer.drawString(this.helpTitle, xPosition + 17, yPos, this.brandColour); yPos += 12;
return this.drawText(xPosition + 17, width - 24, yPos, this.helpText, GuiModInfoPanel.DESCRIPTION_COLOUR) + 15;
}
return this.drawText(xPosition + 5, width - 11, yPos, this.modInfo.getDescription(), GuiModInfoPanel.DESCRIPTION_COLOUR);
}
protected void drawIcon(int xPosition, int yPosition, IconTextured icon)
{
glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(icon.getTextureResource());
glEnableBlend();
this.drawTexturedModalRect(xPosition, yPosition, icon.getUPos(), icon.getVPos(), icon.getIconWidth(), icon.getIconHeight());
glDisableBlend();
}
private int drawText(int xPosition, int width, int yPos, String text, int colour)
{
int totalHeight = this.fontRenderer.getWordWrappedHeight(text, width);
this.fontRenderer.drawSplitString(text, xPosition, yPos, width, colour);
return totalHeight;
}
private boolean isMouseOver(int mouseX, int mouseY, int x, int y, int width, int height)
{
return mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height;
}
public void mousePressed()
{
if (this.mouseOverScrollBar)
{
this.scrollBar.setDragging(true);
}
}
public void mouseReleased()
{
this.scrollBar.setDragging(false);
}
public boolean mouseWheelScrolled(int mouseWheelDelta)
{
if (this.mouseOverPanel)
{
this.scrollBar.offsetValue(-mouseWheelDelta / 8);
return true;
}
return false;
}
public void displayHelpMessage(String title, String text)
{
this.showHelp = true;
this.helpTitle = I18n.format(title);
this.helpText = I18n.format(text);
this.scrollBar.setValue(0);
}
public void clearHelpMessage()
{
this.showHelp = false;
}
}