aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/render/MinionHelperOverlayHover.java
blob: df3559ba8f716cfe62f75c3e99ba1294536f7199 (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * 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.miscgui.minionhelper.render;

import com.google.common.collect.ArrayListMultimap;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.util.StringUtils;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.ApiData;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.Minion;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.OverviewLine;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.render.renderables.OverviewText;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.CollectionRequirement;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.MinionRequirement;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.requirements.ReputationRequirement;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.CraftingSource;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.MinionSource;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.sources.NpcSource;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.gui.inventory.GuiChest;
import org.lwjgl.input.Mouse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class MinionHelperOverlayHover {

	private final MinionHelperOverlay overlay;
	private final MinionHelperManager manager;

	public MinionHelperOverlayHover(MinionHelperOverlay overlay, MinionHelperManager manager) {
		this.overlay = overlay;
		this.manager = manager;
	}

	void renderHover(LinkedHashMap<String, OverviewLine> renderMap) {
		if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) return;

		final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
		final int scaledWidth = scaledresolution.getScaledWidth();
		final int scaledHeight = scaledresolution.getScaledHeight();
		int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth;
		int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;

		OverviewLine mouseObject = overlay.getObjectOverMouse(renderMap);
		if (mouseObject != null) {
			Utils.drawHoveringText(getTooltip(mouseObject), mouseX, mouseY, scaledWidth, scaledHeight, -1);
		}

		renderButtons();
	}

	private void renderButtons() {
		GuiScreen gui = Minecraft.getMinecraft().currentScreen;
		if (!(gui instanceof GuiChest)) return;

		int xSize = ((AccessorGuiContainer) gui).getXSize();
		int guiLeft = ((AccessorGuiContainer) gui).getGuiLeft();
		int guiTop = ((AccessorGuiContainer) gui).getGuiTop();

		final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft());
		final int scaledWidth = scaledresolution.getScaledWidth();
		final int scaledHeight = scaledresolution.getScaledHeight();
		int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth;
		int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1;

		int x = guiLeft + xSize + 4 + 149 - 3;
		int y = guiTop + 109 - 3;
		if (mouseX > x && mouseX < x + 16 &&
			mouseY > y && mouseY < y + 16) {
			renderFilterButton(scaledWidth, scaledHeight, mouseX, mouseY);
		}

		x = guiLeft + xSize + 4 + 149 - 3 - 16 - 3;
		y = guiTop + 109 - 3;
		if (mouseX > x && mouseX < x + 16 &&
			mouseY > y && mouseY < y + 16) {
			renderBuyPriceButton(scaledWidth, scaledHeight, mouseX, mouseY);
		}
	}

	private void renderFilterButton(int scaledWidth, int scaledHeight, int mouseX, int mouseY) {
		List<String> list = new ArrayList<>();

		if (overlay.isFilterEnabled()) {
			list.add("§aFilter enabled");
			list.add("§7Only show minions that can be");
			list.add("§7crafted and meet requirements.");
		} else {
			list.add("§cFilter disabled");
			list.add("§7Show all minions. §cRed ones §7have");
			list.add("§7missing requirements.");
		}

		list.add("");
		list.add("§eClick to toggle!");

		Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1);
	}

	private void renderBuyPriceButton(int scaledWidth, int scaledHeight, int mouseX, int mouseY) {
		List<String> list = new ArrayList<>();

		if (overlay.isUseInstantBuyPrice()) {
			list.add("§bUse Instant Buy price");
			list.add("§7Use the price to pay when");
			list.add("§7buying the item right now.");
			list.add("§7This will be more expensive!");
		} else {
			list.add("§6Use Buy Offer price");
			list.add("§7Use the price for creating an");
			list.add("§7offer to buy the item cheaper.");
			list.add("§7This can take longer!");
		}

		list.add("");
		list.add("§eClick to toggle!");

		Utils.drawHoveringText(list, mouseX, mouseY, scaledWidth, scaledHeight, -1);
	}

	private List<String> getTooltip(OverviewLine overviewLine) {
		List<String> lines = new ArrayList<>();

		if (overviewLine instanceof OverviewText) {
			OverviewText overviewText = (OverviewText) overviewLine;
			lines.addAll(overviewText.getLines());
		} else if (overviewLine instanceof Minion) {

			Minion minion = (Minion) overviewLine;
			MinionSource minionSource = minion.getMinionSource();
			if (minion.getCustomSource() != null) {
				minionSource = minion.getCustomSource();
			}
			String displayName = minion.getDisplayName();
			lines.add("§9" + displayName + " " + minion.getTier());
			List<MinionRequirement> requirements = manager.getRequirementsManager().getRequirements(minion);
			if (!requirements.isEmpty()) {
				for (MinionRequirement requirement : requirements) {
					String result = getRequirementDescription(minion, requirement);
					if (result == null) continue;
					lines.add(result);
				}
			} else {
				lines.add("§cNo requirements loaded!");
			}

			if (minionSource instanceof CraftingSource) {
				CraftingSource craftingSource = (CraftingSource) minionSource;
				lines.add("");
				String format = manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true);
				if (minion.getTier() == 1) {
					lines.add("§7Full crafting cost: " + format);
				} else {
					lines.add("§7Upgrade cost: " + format);
				}
				formatItems(lines, grabAllItems(craftingSource.getItems()));

			} else if (minionSource instanceof NpcSource) {
				NpcSource npcSource = (NpcSource) minionSource;
				String npcName = npcSource.getNpcName();
				lines.add("");
				lines.add("§7Buy from: §9" + npcName + " (NPC)");
				lines.add("");
				lines.add("§7Cost: " + manager.getPriceCalculation().calculateUpgradeCostsFormat(minion, true));
				int coins = npcSource.getCoins();
				if (coins != 0) {
					lines.add(" §8- " + manager.getPriceCalculation().formatCoins(coins));
				}
				formatItems(lines, grabAllItems(npcSource.getItems()));
			}

			lines.add("");
			lines.add("§eClick to view recipe!");
			lines.add("§eCtrl-Click to open bazaar!");
		}
		return lines;
	}

	private String getRequirementDescription(Minion minion, MinionRequirement requirement) {
		boolean meetRequirement = manager.getRequirementsManager().meetRequirement(minion, requirement);
		String