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
276
277
278
279
280
281
282
283
284
|
package me.shedaniel.rei.gui;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.platform.GlStateManager;
import com.zeitheron.hammercore.client.utils.Scissors;
import me.shedaniel.rei.api.*;
import me.shedaniel.rei.client.ScreenHelper;
import me.shedaniel.rei.gui.renderables.RecipeRenderer;
import me.shedaniel.rei.gui.widget.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.audio.PositionedSoundInstance;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Screen;
import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.StringTextComponent;
import net.minecraft.text.TranslatableTextComponent;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import java.awt.*;
import java.nio.IntBuffer;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static me.shedaniel.rei.gui.RecipeViewingScreen.getSpeedCraftFunctionalByCategory;
public class VillagerRecipeViewingScreen extends Screen {
private static final int TABS_PER_PAGE = 8;
private final Map<RecipeCategory, List<RecipeDisplay>> categoryMap;
private final List<RecipeCategory> categories;
private final List<Widget> widgets;
private final List<ButtonWidget> buttonWidgets;
private final List<Renderer> recipeRenderers;
private final List<TabWidget> tabs;
public Rectangle bounds, scrollListBounds;
private int selectedCategoryIndex, selectedRecipeIndex;
private double scroll;
private int tabsPage;
public VillagerRecipeViewingScreen(Map<RecipeCategory, List<RecipeDisplay>> map) {
super(new StringTextComponent(""));
this.widgets = Lists.newArrayList();
this.categoryMap = Maps.newLinkedHashMap();
this.selectedCategoryIndex = 0;
this.selectedRecipeIndex = 0;
this.scroll = 0;
this.tabsPage = 0;
this.categories = Lists.newArrayList();
this.buttonWidgets = Lists.newArrayList();
this.tabs = Lists.newArrayList();
this.recipeRenderers = Lists.newArrayList();
RecipeHelper.getInstance().getAllCategories().forEach(category -> {
if (map.containsKey(category)) {
categories.add(category);
categoryMap.put(category, map.get(category));
}
});
}
@Override
protected void init() {
super.init();
this.children.clear();
this.widgets.clear();
this.buttonWidgets.clear();
this.recipeRenderers.clear();
this.tabs.clear();
int largestWidth = width - 100;
int largestHeight = height - 40;
RecipeCategory category = categories.get(selectedCategoryIndex);
RecipeDisplay display = categoryMap.get(category).get(selectedRecipeIndex);
int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100;
int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight);
this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
this.widgets.add(new CategoryBaseWidget(bounds));
this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97 + 5, guiHeight - 17 - 7);
this.widgets.add(new SlotBaseWidget(scrollListBounds));
Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight());
this.widgets.addAll(category.setupDisplay(() -> display, recipeBounds));
Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getSpeedCraftButtonArea(category);
final SpeedCraftFunctional functional = getSpeedCraftFunctionalByCategory(ScreenHelper.getLastContainerScreen(), category);
if (supplier.isPresent())
this.widgets.add(new SpeedCraftingButtonWidget(supplier.get().get(recipeBounds), supplier.get().getButtonText(), functional, () -> display));
int index = 0;
for(RecipeDisplay recipeDisplay : categoryMap.get(category)) {
int finalIndex = index;
RecipeRenderer recipeRenderer;
recipeRenderers.add(recipeRenderer = category.getSimpleRenderer(recipeDisplay));
buttonWidgets.add(new ButtonWidget(bounds.x + 5, 0, recipeRenderer.getWidth(), recipeRenderer.getHeight(), "") {
@Override
public void onPressed() {
selectedRecipeIndex = finalIndex;
VillagerRecipeViewingScreen.this.init();
}
});
index++;
}
for(int i = 0; i < TABS_PER_PAGE; i++) {
int j = i + tabsPage * TABS_PER_PAGE;
if (categories.size() > j) {
TabWidget tab;
tabs.add(tab = new TabWidget(i, new Rectangle(bounds.x + bounds.width / 2 - Math.min(categories.size() - tabsPage * TABS_PER_PAGE, TABS_PER_PAGE) * 14 + i * 28, bounds.y - 28, 28, 28)) {
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (getBounds().contains(mouseX, mouseY)) {
MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
if (getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex)
return false;
selectedCategoryIndex = getId() + tabsPage * TABS_PER_PAGE;
scroll = 0;
selectedRecipeIndex = 0;
VillagerRecipeViewingScreen.this.init();
return true;
}
return false;
}
});
tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getCategoryName(), tab.getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex);
}
}
ButtonWidget w, w2;
this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableTextComponent("text.rei.left_arrow")) {
@Override
public void onPressed() {
tabsPage--;
if (tabsPage < 0)
tabsPage = MathHelper.ceil(categories.size() / (float) TABS_PER_PAGE) - 1;
VillagerRecipeViewingScreen.this.init();
}
});
this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableTextComponent("text.rei.right_arrow")) {
@Override
public void onPressed() {
tabsPage++;
if (tabsPage > MathHelper.ceil(categories.size() / (float) TABS_PER_PAGE) - 1)
tabsPage = 0;
VillagerRecipeViewingScreen.this.init();
}
});
|