mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[BugFix] NumberComponent dragging cannot be stopped
This commit is contained in:
1 parent
59b79c6f14
commit
752bd07d50
3 files changed
+62
-30
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
public abstract class DragComponent extends ValueComponent {
|
||||
|
||||
protected boolean dragging = false;
|
||||
|
||||
public DragComponent(double x, double y, double width, double height, Component parent) {
|
||||
super(x, y, width, height, parent);
|
||||
}
|
||||
|
||||
// Called when dragging starts
|
||||
protected void onDragStart(int mouseX, int mouseY) {}
|
||||
|
||||
// Called every tick while dragging
|
||||
protected abstract void onDrag(int mouseX, int mouseY);
|
||||
|
||||
// Called when dragging ends
|
||||
protected void onDragEnd(int mouseX, int mouseY) {}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0) return;
|
||||
if (!isHovered(mouseX, mouseY)) return;
|
||||
|
||||
dragging = true;
|
||||
onDragStart(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
if (button == 0 && dragging) {
|
||||
dragging = false;
|
||||
onDragEnd(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int mouseX, int mouseY) {
|
||||
// Safety release if mouseReleased event is lost
|
||||
if (dragging && !Mouse.isButtonDown(0)) {
|
||||
dragging = false;
|
||||
onDragEnd(mouseX, mouseY);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragging) {
|
||||
onDrag(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-11
@@ -28,11 +28,7 @@ public class ModuleButton extends Component {
|
||||
double ax = getAbsoluteX();
|
||||
double ay = getAbsoluteY();
|
||||
|
||||
int bgColor = 0x80000000;
|
||||
|
||||
if (module.isEnabled()) {
|
||||
bgColor = 0xFF2E8B57;
|
||||
}
|
||||
int bgColor = module.isEnabled() ? 0xFF2E8B57 : 0x80000000;
|
||||
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
bgColor = GuiRenderUtils.blendColor(bgColor, 0xFFFFFFFF, 0.15f);
|
||||
@@ -74,17 +70,15 @@ public class ModuleButton extends Component {
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
|
||||
// 先让子组件处理点击(优先级更高)
|
||||
if (expanded) {
|
||||
for (Component component : components) {
|
||||
if (component.isHovered(mouseX, mouseY)) {
|
||||
component.mouseClicked(mouseX, mouseY, button);
|
||||
return; // 子组件处理后,不再继续处理 module 的开关
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 只有点击到 ModuleButton 自己时才处理开关/展开
|
||||
if (!isHovered(mouseX, mouseY)) return;
|
||||
|
||||
if (button == 0) {
|
||||
@@ -96,8 +90,7 @@ public class ModuleButton extends Component {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
if (!expanded) return;
|
||||
|
||||
// IMPORTANT: always propagate release to children
|
||||
for (Component component : components) {
|
||||
component.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
@@ -106,5 +99,4 @@ public class ModuleButton extends Component {
|
||||
public void addComponent(Component component) {
|
||||
components.add(component);
|
||||
}
|
||||
|
||||
}
|
||||
+7
-19
@@ -2,13 +2,12 @@ package cn.xiaozhou233.orangex.ui.clickgui.component.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.module.value.NumberValue;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.ValueComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.DragComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.render.GuiRenderUtils;
|
||||
|
||||
public class NumberComponent extends ValueComponent {
|
||||
public class NumberComponent extends DragComponent {
|
||||
|
||||
private final NumberValue value;
|
||||
private boolean dragging = false;
|
||||
|
||||
public NumberComponent(double x, double y, double width, NumberValue value, Component parent) {
|
||||
super(x, y, width, 14, parent);
|
||||
@@ -25,12 +24,14 @@ public class NumberComponent extends ValueComponent {
|
||||
double cur = value.getValue();
|
||||
|
||||
double ratio = (cur - min) / (max - min);
|
||||
ratio = Math.max(0, Math.min(1, ratio));
|
||||
|
||||
double fillWidth = ratio * (width - 10);
|
||||
|
||||
int bgColor = 0xFF333333;
|
||||
int fillColor = 0xFF2E8B57;
|
||||
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
if (isHovered(mouseX, mouseY) || dragging) {
|
||||
bgColor = GuiRenderUtils.blendColor(bgColor, 0xFFFFFFFF, 0.12f);
|
||||
}
|
||||
|
||||
@@ -44,9 +45,7 @@ public class NumberComponent extends ValueComponent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(int mouseX, int mouseY) {
|
||||
if (!dragging) return;
|
||||
|
||||
protected void onDrag(int mouseX, int mouseY) {
|
||||
double ax = getAbsoluteX();
|
||||
double rel = mouseX - ax - 5;
|
||||
double ratio = rel / (width - 10);
|
||||
@@ -57,19 +56,8 @@ public class NumberComponent extends ValueComponent {
|
||||
applyValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (!isHovered(mouseX, mouseY)) return;
|
||||
if (button == 0) dragging = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyValue() {
|
||||
// no-op
|
||||
// hook point
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user