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
|
/*
* Copyright (C) 2022 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.util;
import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.ContainerChest;
import java.util.List;
public class NotificationHandler {
public static List<String> notificationLines = null;
public static boolean showNotificationOverInv = false;
public static long notificationDisplayMillis = 0;
public static void displayNotification(List<String> lines, boolean showForever) {
displayNotification(lines, showForever, false);
}
public static void displayNotification(List<String> lines, boolean showForever, boolean overInventory) {
if (showForever) {
notificationDisplayMillis = -420;
} else {
notificationDisplayMillis = System.currentTimeMillis();
}
notificationLines = lines;
showNotificationOverInv = overInventory;
}
/**
* Stops rendering the notification, if one is displayed
*/
public static void cancelNotification() {
notificationDisplayMillis = 0;
}
public static void renderNotification() {
long timeRemaining = 15000 - (System.currentTimeMillis() - notificationDisplayMillis);
boolean display = timeRemaining > 0 || notificationDisplayMillis == -420;
if (display && notificationLines != null && notificationLines.size() > 0) {
int width = 0;
int height = notificationLines.size() * 10 + 10;
for (String line : notificationLines) {
int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(line) + 8;
if (len > width) {
width = len;
}
}
ScaledResolution sr = Utils.pushGuiScale(2);
int midX = sr.getScaledWidth() / 2;
int topY = sr.getScaledHeight() * 3 / 4 - height / 2;
RenderUtils.drawFloatingRectDark(midX - width / 2, sr.getScaledHeight() * 3 / 4 - height / 2, width, height);
/*Gui.drawRect(midX-width/2, sr.getScaledHeight()*3/4-height/2,
midX+width/2, sr.getScaledHeight()*3/4+height/2, 0xFF3C3C3C);
Gui.drawRect(midX-width/2+2, sr.getScaledHeight()*3/4-height/2+2,
midX+width/2-2, sr.getScaledHeight()*3/4+height/2-2, 0xFFC8C8C8);*/
int xLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth("[X] Close");
Minecraft.getMinecraft().fontRendererObj.drawString(
"[X] Close",
midX + width / 2f - 3 - xLen,
topY + 3,
0xFFFF5555,
false
);
if (notificationDisplayMillis > 0) {
Minecraft.getMinecraft().fontRendererObj.drawString(
(timeRemaining / 1000) + "s",
midX - width / 2f + 3,
topY + 3,
0xFFaaaaaa,
false
);
}
Utils.drawStringCentered(
notificationLines.get(0),
Minecraft.getMinecraft().fontRendererObj,
midX,
topY + 4 + 5,
false,
-1
);
for (int i = 1; i < notificationLines.size(); i++) {
String line = notificationLines.get(i);
Utils.drawStringCentered(
line,
Minecraft.getMinecraft().fontRendererObj,
midX,
topY + 4 + 5 + 2 + i * 10,
false,
-1
);
}
Utils.pushGuiScale(-1);
}
}
public static boolean shouldRenderOverlay(Gui gui) {
boolean validGui = gui instanceof GuiContainer || gui instanceof GuiItemRecipe;
if (gui instanceof GuiChest) {
GuiChest eventGui = (GuiChest) gui;
ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
if (containerName.trim().equals("Fast Travel")) {
validGui = false;
}
}
return validGui;
}
}
|