aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java
blob: c806feebf0d9bea85c945c514850493043778950 (plain)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * 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.miscfeatures;

import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.GuiElement;
import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils;
import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
import io.github.moulberry.notenoughupdates.util.SBInfo;
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.renderer.GlStateManager;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

public class AbiphoneWarning extends GuiElement {
	private static final AbiphoneWarning INSTANCE = new AbiphoneWarning();

	private boolean showWarning = false;
	private String contactName = null;
	private int contactSlot = -1;

	public static AbiphoneWarning getInstance() {
		return INSTANCE;
	}

	private boolean shouldPerformCheck() {
		if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) {
			showWarning = false;
			return false;
		}

		if (Minecraft.getMinecraft().currentScreen instanceof GuiChest &&
			SBInfo.getInstance().lastOpenContainerName.startsWith("Abiphone ")) {
			return true;
		} else {
			showWarning = false;
			return false;
		}
	}

	public boolean shouldShow() {
		return shouldPerformCheck() && showWarning;
	}

	public boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
		if (!shouldPerformCheck()) return false;
		if (!NotEnoughUpdates.INSTANCE.config.misc.abiphoneWarning) return false;
		if (slotId == -999) return false;
		if (clickedButton == 0) return false;

		GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen;

		ItemStack clickedContact = chest.inventorySlots.getSlot(slotId).getStack();
		if (clickedContact == null) return false;

		List<String> list = ItemUtils.getLore(clickedContact);
		if (list.isEmpty()) return false;

		String last = list.get(list.size() - 1);
		if (last.contains("Right-click to remove contact!")) {
			showWarning = true;
			contactName = clickedContact.getDisplayName();
			contactSlot = slotId;
			return true;
		}

		return false;
	}

	public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) {
		if (shouldShow()) {
			cir.setReturnValue(false);
		}
	}

	@Override
	public void render() {
		final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
		final int width = scaledResolution.getScaledWidth();
		final int height = scaledResolution.getScaledHeight();

		GlStateManager.disableLighting();

		GlStateManager.pushMatrix();
		GlStateManager.translate(0, 0, 500);

		Gui.drawRect(0, 0, width, height, 0x80000000);

		RenderUtils.drawFloatingRectDark(width / 2 - 90, height / 2 - 45, 180, 90);

		int neuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth("\u00a7lNEU");
		Minecraft.getMinecraft().fontRendererObj.drawString(
			"\u00a7lNEU",
			width / 2 + 90 - neuLength - 3,
			height / 2 - 45 + 4,
			0xff000000
		);

		TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", Minecraft.getMinecraft().fontRendererObj,
			width / 2, height / 2 - 45 + 10, false, 170, 0xffff4040
		);

		String sellLine = "\u00a77[ \u00a7r" + contactName + "\u00a77 ]";

		TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj,
			width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff
		);

		TextRenderUtils.drawStringCenteredScaledMaxWidth(
			"Continue removing the contact?",
			Minecraft.getMinecraft().fontRendererObj,
			width / 2,
			height / 2 - 45 + 50,
			false,
			170,
			0xffa0a0a0
		);

		RenderUtils.drawFloatingRectDark(width / 2 - 43, height / 2 + 23, 40, 16, false);
		RenderUtils.drawFloatingRectDark(width / 2 + 3, height / 2 + 23, 40, 16, false);

		TextRenderUtils.drawStringCenteredScaledMaxWidth(
			EnumChatFormatting.GREEN + "[Y]es",
			Minecraft.getMinecraft().fontRendererObj,
			width / 2 - 23,
			height / 2 + 31,
			true,
			36,
			0xff00ff00
		);
		TextRenderUtils.drawStringCenteredScaledMaxWidth(
			EnumChatFormatting.RED + "[N]o",
			Minecraft.getMinecraft().fontRendererObj,
			width / 2 + 23,
			height / 2 + 31,
			true,
			36,
			0xffff0000
		);

		GlStateManager.popMatrix();
	}

	@Override
	public boolean mouseInput(int mouseX, int mouseY) {
		final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
		final int width = scaledResolution.getScaledWidth();
		final int height = scaledResolution.getScaledHeight();

		if (Mouse.getEventButtonState()) {
			if (mouseY >= height / 2 + 23 && mouseY <= height / 2 + 23 + 16) {
				if (mouseX >= width / 2 - 43 && mouseX <= width / 2 - 3) {
					makeClick();
				}
				showWarning = false;
			}

			if (mouseX < width / 2 - 90 || mouseX > width / 2 + 90 ||
				mouseY < height / 2 - 45 || mouseY > height / 2 + 45) {
				showWarning = false;
			}
		}

		return false;
	}

	@Override
	public boolean keyboardInput() {
		if (!Keyboard.getEventKeyState()) {
			if (Keyboard.getEventKey() == Keyboard.KEY_Y || Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
				makeClick();
			}
			showWarning = false;
		}

		return false;
	}

	private void makeClick() {
		if (contactSlot != -1) {
			GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen;
			Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId,
				contactSlot, 1, 0, Minecraft.getMinecraft().thePlayer
			);
			contactSlot = -1;
		}
	}
}