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
|
/*
* Copyright (c) 2018, 2019, 2020 shedaniel
* Licensed under the MIT License (the "License").
*/
package me.shedaniel.rei.gui.widget;
import com.mojang.blaze3d.systems.RenderSystem;
import me.shedaniel.clothconfig2.api.ModifierKeyCode;
import me.shedaniel.math.api.Point;
import me.shedaniel.math.api.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import me.shedaniel.rei.api.ClientHelper;
import me.shedaniel.rei.api.ConfigManager;
import me.shedaniel.rei.api.ConfigObject;
import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.impl.ScreenHelper;
import me.shedaniel.rei.utils.CollectionUtils;
import net.minecraft.client.gui.Element;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import java.util.*;
public class EntryWidget extends WidgetWithBounds {
protected static final Identifier RECIPE_GUI = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
protected static final Identifier RECIPE_GUI_DARK = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer_dark.png");
protected boolean highlight = true;
protected boolean tooltips = true;
protected boolean background = true;
protected boolean interactable = true;
protected boolean interactableFavorites = true;
private Rectangle bounds;
private List<EntryStack> entryStacks;
protected EntryWidget(int x, int y) {
this(new Point(x, y));
}
protected EntryWidget(Point point) {
this.bounds = new Rectangle(point.x - 1, point.y - 1, 18, 18);
this.entryStacks = new ArrayList<>();
}
public static EntryWidget create(int x, int y) {
return create(new Point(x, y));
}
public static EntryWidget create(Point point) {
return new EntryWidget(point);
}
public EntryWidget disableInteractions() {
return interactable(false);
}
public EntryWidget interactable(boolean b) {
interactable = b;
interactableFavorites = interactableFavorites && interactable;
return this;
}
public EntryWidget disableFavoritesInteractions() {
return interactableFavorites(false);
}
public EntryWidget interactableFavorites(boolean b) {
interactableFavorites = b && interactable;
return this;
}
public EntryWidget noHighlight() {
return highlight(false);
}
public EntryWidget highlight(boolean b) {
highlight = b;
return this;
}
public EntryWidget noTooltips() {
return tooltips(false);
}
public EntryWidget tooltips(boolean b) {
tooltips = b;
return this;
}
public EntryWidget noBackground() {
return background(false);
}
public EntryWidget background(boolean b) {
background = b;
return this;
}
public EntryWidget clearStacks() {
entryStacks.clear();
return this;
}
public EntryWidget entry(EntryStack stack) {
entryStacks.add(stack);
return this;
}
public EntryWidget entries(Collection<EntryStack> stacks) {
entryStacks.addAll(stacks);
return this;
}
protected EntryStack getCurrentEntry() {
if (entryStacks.isEmpty())
return EntryStack.empty();
if (entryStacks.size() == 1)
return entryStacks.get(0);
return entryStacks.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) entryStacks.size()) / 1f));
}
public List<EntryStack> entries() {
return entryStacks;
}
@Override
public Rectangle getBounds() {
return bounds;
}
protected Rectangle getInnerBounds() {
return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2);
}
@Override
public void render(int mouseX, int mouseY, float delta) {
drawBackground(mouseX, mouseY, delta);
drawCurrentEntry(mouseX, mouseY, delta);
boolean highlighted = containsMouse(mouseX, mouseY);
if (hasTooltips() && highlighted) {
queueTooltip(mouseX, mouseY, delta);
}
if (hasHighlight() && highlighted) {
drawHighlighted(mouseX, mouseY, delta);
}
}
public final boolean hasTooltips() {
return tooltips;
}
public final boolean hasHighlight() {
return highlight;
}
protected void drawBackground(int mouseX, int mouseY, float delta) {
if (background) {
minecraft.getTextureManager().bindTexture(ScreenHelper.isDarkModeEnabled() ? RECIPE_GUI_DARK : RECIPE_GUI);
blit(bounds.x, bounds.y, 0, 222, bounds.width, bounds.height);
}
}
protected void drawCurrentEntry(int mouseX, int mouseY, float delta) {
EntryStack entry = getCurrentEntry();
entry.setZ(100);
entry.render(getInnerBounds(), mouseX, mouseY, delta);
}
protected void queueTooltip(int mouseX, int mouseY, float delta) {
QueuedTooltip tooltip = getCurrentTooltip(mouseX, mouseY);
if (tooltip != null) {
if (interactableFavorites && ConfigObject.getInstance().doDisplayFavoritesTooltip() && !ConfigObject.getInstance().getFavoriteKeyCode().isUnknown()) {
String name = ConfigObject.getInstance().getFavoriteKeyCode().getLocalizedName();
if (reverseFavoritesAction())
tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.remove_favorites_tooltip", name).split("\n")));
else
tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.favorites_tooltip", name).split("\n")));
}
ScreenHelper.getLastOverlay().addTooltip(tooltip);
}
}
public QueuedTooltip getCurrentTooltip(int mouseX, int mouseY) {
return getCurrentEntry().getTooltip(mouseX, mouseY);
}
protected void drawHighlighted(int mouseX, int mouseY, float delta) {
RenderSystem.disableDepthTest();
RenderSystem.colorMask(true, true, true, false);
int color = ScreenHelper.isDarkModeEnabled() ? -1877929711 : -2130706433;
setZ(300);
Rectangle bounds = getInnerBounds();
fillGradient(bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), color, color);
setZ(0);
RenderSystem.colorMask(true, true, true, true);
RenderSystem.enableDepthTest();
}
@Override
public List<? extends Element> children() {
return Collections.emptyList();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!interactable)
return false;
if (containsMouse(mouseX, mouseY)) {
if (button == 0)
return ClientHelper.getInstance().executeRecipeKeyBind(getCurrentEntry());
else if (button == 1)
return ClientHelper.getInstance().executeUsageKeyBind(getCurrentEntry());
}
return false;
}
protected
|