-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathCyclingOptionWidget.java
More file actions
155 lines (123 loc) · 5.9 KB
/
CyclingOptionWidget.java
File metadata and controls
155 lines (123 loc) · 5.9 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
package net.vulkanmod.config.widget;
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.renderer.GameRenderer;
import net.minecraft.network.chat.Component;
import net.vulkanmod.config.CyclingOption;
import org.joml.Matrix4f;
public class CyclingOptionWidget extends OptionWidget {
CyclingOption<?> option;
private Button leftButton;
private Button rightButton;
private boolean focused;
public CyclingOptionWidget(CyclingOption<?> option, int x, int y, int width, int height, Component name) {
super(x, y, width, height, name);
this.option = option;
this.leftButton = new Button(this.controlX, 16, 0);
this.rightButton = new Button(this.controlX + this.controlWidth - 16, 16, 1);
updateDisplayedValue(option.getValueText());
}
@Override
protected int getYImage(boolean hovered) {
return 0;
}
public void renderBackground(GuiGraphics guiGraphics, Minecraft client, int mouseX, int mouseY) {
// RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
int i = (this.isHovered() ? 2 : 1) * 20;
// this.drawTexture(matrices, this.controlX, this.y, 0, 46 + i, 8, this.height);
// this.drawTexture(matrices, this.controlX + 8, this.y, 192, 46 + i, 8, this.height);
// this.drawTexture(matrices, this.controlX + this.controlWidth - 16, this.y, 0, 46 + i, 8, this.height);
// this.drawTexture(matrices, this.controlX + this.controlWidth - 8, this.y, 192, 46 + i, 8, this.height);
this.leftButton.setStatus(option.index() > 0);
this.rightButton.setStatus(option.index() < option.getValues().length - 1);
this.leftButton.renderButton(guiGraphics.pose(), mouseX, mouseY);
this.rightButton.renderButton(guiGraphics.pose(), mouseX, mouseY);
}
@Override
public void onClick(double mouseX, double mouseY) {
// this.setValueFromMouse(mouseX);
boolean buttonClicked = false;
if(leftButton.isHovered((int)mouseX, (int)mouseY)) {
option.prevValue();
buttonClicked = true;
}
else if(rightButton.isHovered((int)mouseX, (int)mouseY)) {
option.nextValue();
buttonClicked = true;
}
if(buttonClicked)
updateDisplayedValue(this.option.getValueText());
}
public Component getTooltip() {
return this.option.getTooltip();
}
@Override
public void setFocused(boolean bl) {
this.focused = bl;
}
@Override
public boolean isFocused() {
return this.focused;
}
class Button {
int x;
int width;
boolean active;
int direction;
Button(int x, int width, int direction) {
this.x = x;
this.width = width;
this.active = true;
this.direction = direction;
if(direction < 0 || direction > 1) throw new RuntimeException("direction not allowed.");
}
boolean isHovered(int mouseX, int mouseY) {
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height;
}
void setStatus(boolean status) {
this.active = status;
}
void renderButton(PoseStack matrices, int mouseX, int mouseY) {
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
int i = (this.isHovered(mouseX, mouseY) ? 2 : 1) * 20;
i = this.active ? i : 0;
// drawTexture(matrices, x, y, 0, 46 + i, 8, height);
// drawTexture(matrices, x + 8, y, 192, 46 + i, 8, height);
float f = this.isHovered(mouseX, mouseY) && this.active ? 3.0f : 4.0f;
Matrix4f matrix4f = matrices.last().pose();
// if(this.isHovered(mouseX, mouseY)) matrix4f.multiply(Matrix4f.scale(1.1f, 1.1f, 1.1f));
RenderSystem.setShader(GameRenderer::getPositionShader);
RenderSystem.enableBlend();
if(this.isHovered(mouseX, mouseY) && this.active)
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
else if(this.active)
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 0.8f);
else
RenderSystem.setShaderColor(0.5f, 0.5f, 0.5f, 0.8f);
bufferBuilder.begin(VertexFormat.Mode.TRIANGLE_STRIP, DefaultVertexFormat.POSITION);
if(direction == 0) {
bufferBuilder.vertex(matrix4f, x + f, y + height * 0.5f, 0).endVertex();
bufferBuilder.vertex(matrix4f, x + 16 - f, y + height - f, 0).endVertex();
bufferBuilder.vertex(matrix4f, x + 16 - f, y + f, 0).endVertex();
} else {
bufferBuilder.vertex(matrix4f, x + 16 - f, y + height * 0.5f, 0).endVertex();
bufferBuilder.vertex(matrix4f, x + f, y + f, 0).endVertex();
bufferBuilder.vertex(matrix4f, x + f, y + height - f, 0).endVertex();
}
tesselator.end();
// bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
// bufferBuilder.vertex(matrix4f, x + f, y + height - f, 0).color(255, 255, 255, 255).endVertex();
// bufferBuilder.vertex(matrix4f, x + 16 - f, y + height - f, 0).color(255, 255, 255, 255).endVertex();
// bufferBuilder.vertex(matrix4f, x + 16 - f, y + f, 0).color(255, 255, 255, 255).endVertex();
// bufferBuilder.vertex(matrix4f, x + f, y + f, 0).color(255, 255, 255, 255).endVertex();
// tessellator.draw();
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
}
}
}