-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8856f5e
commit d5601c4
Showing
27 changed files
with
673 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/tauri/dev/jsg/gui/admincontroller/Notifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package tauri.dev.jsg.gui.admincontroller; | ||
|
||
import tauri.dev.jsg.util.JSGMinecraftHelper; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
@SuppressWarnings("all") | ||
public class Notifier { | ||
private String lastText = null; | ||
private int color = 0x202020; | ||
private long lastTextEntered = 0; | ||
private int showSeconds = 0; | ||
|
||
public enum EnumAlertType{ | ||
INFO(0x21CEB7), | ||
WARNING(0xCEA021), | ||
ERROR(0xCE2121); | ||
|
||
private final int color; | ||
EnumAlertType(int color){ | ||
this.color = color; | ||
} | ||
} | ||
|
||
public void clearText(){ | ||
this.lastText = null; | ||
} | ||
|
||
public void setText(@Nonnull String text, @Nonnull EnumAlertType type, int secondsToShow){ | ||
lastTextEntered = JSGMinecraftHelper.getClientTick(); | ||
showSeconds = secondsToShow; | ||
lastText = text; | ||
color = type.color; | ||
} | ||
|
||
public void render(GuiAdminController baseGui, int x, int y){ | ||
if((JSGMinecraftHelper.getClientTick() - lastTextEntered) > (showSeconds * 20L) || lastText == null) return; | ||
baseGui.drawString(baseGui.mc.fontRenderer, lastText, x, y, color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/main/java/tauri/dev/jsg/gui/admincontroller/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package tauri.dev.jsg.gui.admincontroller; | ||
|
||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.client.renderer.RenderHelper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static net.minecraftforge.fml.client.config.GuiUtils.drawGradientRect; | ||
|
||
public class Util { | ||
/** | ||
* Method grabbed from {@link net.minecraftforge.fml.client.config.GuiUtils} | ||
*/ | ||
public static void drawHoveringText(List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font) { | ||
if (!textLines.isEmpty()) { | ||
GlStateManager.disableRescaleNormal(); | ||
RenderHelper.disableStandardItemLighting(); | ||
GlStateManager.disableLighting(); | ||
int tooltipTextWidth = 0; | ||
|
||
for (String textLine : textLines) { | ||
int textLineWidth = font.getStringWidth(textLine); | ||
|
||
if (textLineWidth > tooltipTextWidth) { | ||
tooltipTextWidth = textLineWidth; | ||
} | ||
} | ||
|
||
boolean needsWrap = false; | ||
|
||
int titleLinesCount = 1; | ||
int tooltipX = mouseX + 12; | ||
if (tooltipX + tooltipTextWidth + 4 > screenWidth) { | ||
tooltipX = mouseX - 16 - tooltipTextWidth; | ||
if (tooltipX < 4) // if the tooltip doesn't fit on the screen | ||
{ | ||
if (mouseX > screenWidth / 2) { | ||
tooltipTextWidth = mouseX - 12 - 8; | ||
} else { | ||
tooltipTextWidth = screenWidth - 16 - mouseX; | ||
} | ||
needsWrap = true; | ||
} | ||
} | ||
|
||
if (maxTextWidth > 0 && tooltipTextWidth > maxTextWidth) { | ||
tooltipTextWidth = maxTextWidth; | ||
needsWrap = true; | ||
} | ||
|
||
if (needsWrap) { | ||
int wrappedTooltipWidth = 0; | ||
List<String> wrappedTextLines = new ArrayList<>(); | ||
for (int i = 0; i < textLines.size(); i++) { | ||
String textLine = textLines.get(i); | ||
List<String> wrappedLine = font.listFormattedStringToWidth(textLine, tooltipTextWidth); | ||
if (i == 0) { | ||
titleLinesCount = wrappedLine.size(); | ||
} | ||
|
||
for (String line : wrappedLine) { | ||
int lineWidth = font.getStringWidth(line); | ||
if (lineWidth > wrappedTooltipWidth) { | ||
wrappedTooltipWidth = lineWidth; | ||
} | ||
wrappedTextLines.add(line); | ||
} | ||
} | ||
tooltipTextWidth = wrappedTooltipWidth; | ||
textLines = wrappedTextLines; | ||
|
||
if (mouseX > screenWidth / 2) { | ||
tooltipX = mouseX - 16 - tooltipTextWidth; | ||
} else { | ||
tooltipX = mouseX + 12; | ||
} | ||
} | ||
|
||
int tooltipY = mouseY - 12; | ||
int tooltipHeight = 8; | ||
|
||
if (textLines.size() > 1) { | ||
tooltipHeight += (textLines.size() - 1) * 10; | ||
if (textLines.size() > titleLinesCount) { | ||
tooltipHeight += 2; // gap between title lines and next lines | ||
} | ||
} | ||
|
||
if (tooltipY < 4) { | ||
tooltipY = 4; | ||
} else if (tooltipY + tooltipHeight + 4 > screenHeight) { | ||
tooltipY = screenHeight - tooltipHeight - 4; | ||
} | ||
|
||
final int zLevel = 300; | ||
int backgroundColor = 0xF0100010; | ||
int borderColorStart = 0x505000FF; | ||
int borderColorEnd = (borderColorStart & 0xFEFEFE) >> 1 | borderColorStart & 0xFF000000; | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 4, tooltipX + tooltipTextWidth + 3, tooltipY - 3, backgroundColor, backgroundColor); | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 4, backgroundColor, backgroundColor); | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); | ||
drawGradientRect(zLevel, tooltipX - 4, tooltipY - 3, tooltipX - 3, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); | ||
drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 3, tooltipY - 3, tooltipX + tooltipTextWidth + 4, tooltipY + tooltipHeight + 3, backgroundColor, backgroundColor); | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3 + 1, tooltipX - 3 + 1, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); | ||
drawGradientRect(zLevel, tooltipX + tooltipTextWidth + 2, tooltipY - 3 + 1, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3 - 1, borderColorStart, borderColorEnd); | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY - 3, tooltipX + tooltipTextWidth + 3, tooltipY - 3 + 1, borderColorStart, borderColorStart); | ||
drawGradientRect(zLevel, tooltipX - 3, tooltipY + tooltipHeight + 2, tooltipX + tooltipTextWidth + 3, tooltipY + tooltipHeight + 3, borderColorEnd, borderColorEnd); | ||
|
||
GlStateManager.pushMatrix(); | ||
GlStateManager.translate(0, 0, zLevel + 5); | ||
for (int lineNumber = 0; lineNumber < textLines.size(); ++lineNumber) { | ||
String line = textLines.get(lineNumber); | ||
font.drawStringWithShadow(line, (float) tooltipX, (float) tooltipY, -1); | ||
|
||
if (lineNumber + 1 == titleLinesCount) { | ||
tooltipY += 2; | ||
} | ||
|
||
tooltipY += 10; | ||
} | ||
GlStateManager.popMatrix(); | ||
|
||
GlStateManager.enableLighting(); | ||
RenderHelper.enableStandardItemLighting(); | ||
GlStateManager.enableRescaleNormal(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.