-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathRangeOptionWidget.java
More file actions
130 lines (107 loc) · 4.19 KB
/
RangeOptionWidget.java
File metadata and controls
130 lines (107 loc) · 4.19 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
package net.vulkanmod.config.widget;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.vulkanmod.config.RangeOption;
import net.vulkanmod.vulkan.util.ColorUtil;
import net.vulkanmod.vulkan.util.VUtil;
import org.lwjgl.glfw.GLFW;
public class RangeOptionWidget extends OptionWidget {
protected double value;
private RangeOption option;
private boolean focused;
public RangeOptionWidget(RangeOption option, int x, int y, int width, int height, Component name) {
super(x, y, width, height, name);
this.option = option;
this.setValue(option.getScaledValue());
}
public RangeOptionWidget(RangeOption option, int x, int y, int width, int height, String name) {
this(option, x, y, width, height, Component.nullToEmpty(name));
}
@Override
protected int getYImage(boolean hovered) {
return 0;
}
@Override
protected void renderBackground(GuiGraphics guiGraphics, Minecraft client, int mouseX, int mouseY) {
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
int i = (this.isHovered() ? 2 : 1) * 20;
// this.drawTexture(matrices, this.controlX + (int)(this.value * (this.controlWidth - 8)), this.y, 0, 46 + i, 4, 20);
// this.drawTexture(matrices, this.controlX + (int)(this.value * (this.controlWidth - 8)) + 4, this.y, 196, 46 + i, 4, 20);
int color = this.controlHovered ? ColorUtil.packColorInt(1.0f, 1.0f, 1.0f, 1.0f) : ColorUtil.packColorInt(1.0f, 1.0f, 1.0f, 0.8f);
guiGraphics.fill(this.controlX + (int)(this.value * (this.controlWidth - 8)), this.y + 20, this.controlX + (int)(this.value * (this.controlWidth - 8)) + 8, this.y, color);
}
@Override
public void onClick(double mouseX, double mouseY) {
this.setValueFromMouse(mouseX);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
boolean bl;
boolean bl2 = bl = keyCode == GLFW.GLFW_KEY_LEFT;
if (bl || keyCode == GLFW.GLFW_KEY_RIGHT) {
float f = bl ? -1.0f : 1.0f;
this.setValue(this.value + (double)(f / (float)(this.width - 8)));
}
return false;
}
@Override
public void setFocused(boolean bl) {
this.focused = bl;
}
@Override
public boolean isFocused() {
return this.focused;
}
private void setValueFromMouse(double mouseX) {
this.setValue((mouseX - (double)(this.controlX + 4)) / (double)((this.controlWidth) - 8));
}
private void setValue(double value) {
double d = this.value;
this.value = Mth.clamp(value, 0.0, 1.0);
if (d != this.value) {
this.applyValue();
}
this.updateDisplayedValue();
}
@Override
protected void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {
this.setValueFromMouse(mouseX);
super.onDrag(mouseX, mouseY, deltaX, deltaY);
}
protected void applyValue() {
option.setValue((float) this.value);
this.value = option.getScaledValue();
}
private void updateDisplayedValue() {
this.displayedValue = Component.nullToEmpty(option.getDisplayedValue());
}
@Override
public Component getTooltip() {
return this.option.getTooltip();
}
@Override
public void playDownSound(SoundManager soundManager) {
}
@Override
public void onRelease(double mouseX, double mouseY) {
super.playDownSound(Minecraft.getInstance().getSoundManager());
}
// @Override
// public void playDownSound(SoundManager soundManager) {
// }
//
// @Override
// public void onRelease(double mouseX, double mouseY) {
// super.playDownSound(MinecraftClient.getInstance().getSoundManager());
// }
// @Override
// protected void applyValue() {
// ((RangeOption)(option)).setValue((float) this.value);
// this.displayedValue = Text.of(Float.toString(((RangeOption)(option)).getScaledValue()));
// }
}