-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathOptionList2.java
More file actions
259 lines (227 loc) · 12.6 KB
/
OptionList2.java
File metadata and controls
259 lines (227 loc) · 12.6 KB
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
package net.vulkanmod.config;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.util.Mth;
import net.vulkanmod.config.widget.OptionWidget;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class OptionList2 extends ContainerObjectSelectionList<OptionList2.Entry> {
public OptionList2(Minecraft minecraftClient, int width, int height, int top, int bottom, int itemHeight) {
super(minecraftClient, width, height, top, bottom, itemHeight);
this.centerListVertically = false;
}
public void addButton(OptionWidget widget) {
this.addEntry(new net.vulkanmod.config.OptionList2.Entry(widget));
}
public void addAll(Option<?>[] options) {
for (int i = 0; i < options.length; i++) {
this.addEntry(new net.vulkanmod.config.OptionList2.Entry(options[i].createOptionWidget((int) (0.1f * width), 0, (int) (0.8f * width), 20)));
// this.addEntry(new Entry(options[i].createOptionWidget(width / 2 - 155, 0, 200, 20)));
}
}
public boolean mouseClicked(double mouseX, double mouseY, int button) {
this.updateScrollingState(mouseX, mouseY, button);
if (!this.isMouseOver(mouseX, mouseY)) {
return false;
} else {
OptionList2.Entry entry = this.getEntryAtPos(mouseX, mouseY);
if (entry != null) {
if (entry.mouseClicked(mouseX, mouseY, button)) {
this.setFocused(entry);
this.setDragging(true);
return true;
}
} else if (button == 0) {
this.clickedHeader((int)(mouseX - (double)(this.x0 + this.width / 2 - this.getRowWidth() / 2)), (int)(mouseY - (double)this.y0) + (int)this.getScrollAmount() - 4);
return true;
}
return false;
}
}
@Nullable
protected net.vulkanmod.config.OptionList2.Entry getEntryAtPos(double x, double y) {
int i = this.getRowWidth() / 2;
int j = this.x0 + this.width / 2;
int k = j - i;
int l = j + i;
int m = Mth.floor(y - (double)this.y0) - this.headerHeight + (int)this.getScrollAmount() - 4;
int n = m / this.itemHeight;
if (x < this.getScrollbarPosition() && x >= (double)k && x <= (double)l && n >= 0 && m >= 0 && n < this.getItemCount()) {
return (net.vulkanmod.config.OptionList2.Entry)this.children().get(n);
}
return null;
}
@Override
public void render(GuiGraphics matrices, int mouseX, int mouseY, float delta) {
int o;
int n;
int m;
// this.renderBackground(matrices);
int i = this.getScrollbarPosition();
int j = i + 6;
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
// this.hoveredEntry = this.isMouseOver(mouseX, mouseY) ? this.getEntryAtPosition(mouseX, mouseY) : null;
// Object v0 = this.hoveredEntry;
//Render Background
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
float f = 32.0f;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
int color = 45;
bufferBuilder.vertex(this.x0, this.y1, 0.0).uv((float)this.x0 / 32.0f, (float)(this.y1 + (int)this.getScrollAmount()) / 32.0f).color(color, color, color, 255).endVertex();
bufferBuilder.vertex(this.x1, this.y1, 0.0).uv((float)this.x1 / 32.0f, (float)(this.y1 + (int)this.getScrollAmount()) / 32.0f).color(color, color, color, 255).endVertex();
bufferBuilder.vertex(this.x1, this.y0, 0.0).uv((float)this.x1 / 32.0f, (float)(this.y0 + (int)this.getScrollAmount()) / 32.0f).color(color, color, color, 255).endVertex();
bufferBuilder.vertex(this.x0, this.y0, 0.0).uv((float)this.x0 / 32.0f, (float)(this.y0 + (int)this.getScrollAmount()) / 32.0f).color(color, color, color, 255).endVertex();
tesselator.end();
int k = this.getRowLeft();
int l = this.y0 + 4 - (int)this.getScrollAmount();
this.renderHeader(matrices, k, l);
this.renderList(matrices, k, l, mouseX, mouseY, delta);
//Render horizontal shadows
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
RenderSystem.enableDepthTest();
RenderSystem.depthFunc(519);
float g = 32.0f;
m = -100;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
bufferBuilder.vertex(this.x0, this.y0, -100.0).uv(0.0f, (float)this.y0 / 32.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0 + this.width, this.y0, -100.0).uv((float)this.width / 32.0f, (float)this.y0 / 32.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0 + this.width, 0.0, -100.0).uv((float)this.width / 32.0f, 0.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0, 0.0, -100.0).uv(0.0f, 0.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0, this.height, -100.0).uv(0.0f, (float)this.height / 32.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0 + this.width, this.height, -100.0).uv((float)this.width / 32.0f, (float)this.height / 32.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0 + this.width, this.y1, -100.0).uv((float)this.width / 32.0f, (float)this.y1 / 32.0f).color(64, 64, 64, 255).endVertex();
bufferBuilder.vertex(this.x0, this.y1, -100.0).uv(0.0f, (float)this.y1 / 32.0f).color(64, 64, 64, 255).endVertex();
tesselator.end();
RenderSystem.depthFunc(515);
RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
n = 4;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bufferBuilder.vertex(this.x0, this.y0 + 4, 0.0).color(0, 0, 0, 0).endVertex();
bufferBuilder.vertex(this.x1, this.y0 + 4, 0.0).color(0, 0, 0, 0).endVertex();
bufferBuilder.vertex(this.x1, this.y0, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(this.x0, this.y0, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(this.x0, this.y1, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(this.x1, this.y1, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(this.x1, this.y1 - 4, 0.0).color(0, 0, 0, 0).endVertex();
bufferBuilder.vertex(this.x0, this.y1 - 4, 0.0).color(0, 0, 0, 0).endVertex();
tesselator.end();
if ((o = this.getMaxScroll()) > 0) {
RenderSystem.setShader(GameRenderer::getPositionColorShader);
m = (int)((float)((this.y1 - this.y0) * (this.y1 - this.y0)) / (float)this.getMaxPosition());
m = Mth.clamp(m, 32, this.y1 - this.y0 - 8);
n = (int)this.getScrollAmount() * (this.y1 - this.y0 - m) / o + this.y0;
if (n < this.y0) {
n = this.y0;
}
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
bufferBuilder.vertex(i, this.y1, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(j, this.y1, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(j, this.y0, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(i, this.y0, 0.0).color(0, 0, 0, 255).endVertex();
bufferBuilder.vertex(i, n + m, 0.0).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(j, n + m, 0.0).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(j, n, 0.0).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(i, n, 0.0).color(128, 128, 128, 255).endVertex();
bufferBuilder.vertex(i, n + m - 1, 0.0).color(192, 192, 192, 255).endVertex();
bufferBuilder.vertex(j - 1, n + m - 1, 0.0).color(192, 192, 192, 255).endVertex();
bufferBuilder.vertex(j - 1, n, 0.0).color(192, 192, 192, 255).endVertex();
bufferBuilder.vertex(i, n, 0.0).color(192, 192, 192, 255).endVertex();
tesselator.end();
}
this.renderDecorations(matrices, mouseX, mouseY);
RenderSystem.disableBlend();
}
@Override
public int getRowWidth() {
return this.width;
}
@Override
protected int getScrollbarPosition() {
// return this.width / 2 + 124 + 32;
return (int) (this.width * 0.95f);
}
public Optional<OptionWidget> getHoveredButton(double mouseX, double mouseY) {
for (net.vulkanmod.config.OptionList2.Entry buttonEntry : this.children()) {
if (!buttonEntry.button.isMouseOver(mouseX, mouseY)) continue;
return Optional.of(buttonEntry.button);
}
return Optional.empty();
}
protected void renderList(GuiGraphics guiGraphics, int x, int y, int mouseX, int mouseY, float delta) {
int i = this.getItemCount();
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
for (int j = 0; j < i; ++j) {
int p;
int k = this.getRowTop(j);
int l = this.getRowBottom(j);
if (l < this.y0 || k > this.y1) continue;
int m = y + j * this.itemHeight + this.headerHeight;
int n = this.itemHeight - 4;
net.vulkanmod.config.OptionList2.Entry entry = this.getEntry(j);
int o = this.getRowWidth();
if (this.isSelectedItem(j)) {
p = this.x0 + this.width / 2 - o / 2;
int q = this.x0 + this.width / 2 + o / 2;
RenderSystem.setShader(GameRenderer::getPositionShader);
float f = this.isFocused() ? 1.0f : 0.5f;
RenderSystem.setShaderColor(f, f, f, 1.0f);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
bufferBuilder.vertex(p, m + n + 2, 0.0).endVertex();
bufferBuilder.vertex(q, m + n + 2, 0.0).endVertex();
bufferBuilder.vertex(q, m - 2, 0.0).endVertex();
bufferBuilder.vertex(p, m - 2, 0.0).endVertex();
tesselator.end();
RenderSystem.setShaderColor(0.0f, 0.0f, 0.0f, 1.0f);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION);
bufferBuilder.vertex(p + 1, m + n + 1, 0.0).endVertex();
bufferBuilder.vertex(q - 1, m + n + 1, 0.0).endVertex();
bufferBuilder.vertex(q - 1, m - 1, 0.0).endVertex();
bufferBuilder.vertex(p + 1, m - 1, 0.0).endVertex();
tesselator.end();
}
p = this.getRowLeft();
entry.render(guiGraphics, j, k, p, o, n, mouseX, mouseY, false, delta);
}
}
protected int getRowBottom(int index) {
return this.getRowTop(index) + this.itemHeight;
}
protected static class Entry
extends ContainerObjectSelectionList.Entry<net.vulkanmod.config.OptionList2.Entry> {
final OptionWidget button;
private NarratableEntry focusedSelectable;
private Entry(OptionWidget button) {
this.button = button;
}
@Override
public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.y = y;
button.render(guiGraphics, mouseX, mouseY, tickDelta);
}
@Override
public List<? extends GuiEventListener> children() {
return List.of(this.button);
}
@Override
public List<? extends NarratableEntry> narratables() {
return List.of(this.button);
}
}
}