Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fix clickGui panel mouse moving
Browse files Browse the repository at this point in the history
  • Loading branch information
CubeWhy committed Jul 31, 2023
1 parent 77145ea commit a1b9ac5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ minecraft {
runDir = "run"
mappings = "stable_22"
makeObfSourceJar = false
clientJvmArgs += ["-Dfml.coreMods.load=org.cubewhy.lunarcn.injection.forge.TransformerLoader", "-Xmx4096m -Xms4096m", "-Ddev-mode"]
clientJvmArgs += ["-Dfml.coreMods.load=org.cubewhy.lunarcn.injection.forge.TransformerLoader", "-Xmx2048m -Xms2048m", "-Ddev-mode"]
}

jar {
Expand Down
35 changes: 16 additions & 19 deletions src/main/java/org/cubewhy/lunarcn/gui/clickgui/ClickGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.util.ArrayList;

import static org.cubewhy.lunarcn.utils.ClientUtils.logger;
import static org.cubewhy.lunarcn.utils.MinecraftInstance.fontRenderer;

public class ClickGui extends GuiScreen {
Expand All @@ -32,18 +31,17 @@ public class ClickGui extends GuiScreen {
private int panelY;
private int panelWidth;
private int panelHeight;

private int lastMouseX;
private int lastMouseY;
private int movedX;
private int movedY;

@Override
public void initGui() {
EventManager.register(this);

this.panelWidth = this.width / 2 + 100;
this.panelHeight = this.height / 2 + 100;
this.panelX = this.width / 2;
this.panelY = this.height / 2;
this.panelX = this.width / 2 - panelWidth / 2;
this.panelY = this.height / 2 - panelHeight / 2;

scroller = new VerticalScroller(this.panelX, this.panelY, 10, this.panelHeight, 0);
timer.reset();
Expand All @@ -67,8 +65,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);

// Module doc
for (int i = 0; i < this.buttonList.size(); i++) {
GuiButton button = this.buttonList.get(i);
for (GuiButton button : this.buttonList) {
if (button instanceof SwitchButton) {
SwitchButton button1 = (SwitchButton) button;
if (button1.isMouseOver()) {
Expand Down Expand Up @@ -169,22 +166,22 @@ protected void actionPerformed(GuiButton button) {

@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
if (mouseButton == 0) {
this.lastMouseX = mouseX;
this.lastMouseY = mouseY;
}
super.mouseClicked(mouseX, mouseY, mouseButton);
}

@Override
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
int MX = lastMouseX - panelX;
int MY = lastMouseY - panelY;

if (clickedMouseButton == 0 && RenderUtils.isHovering(mouseX, mouseY, panelX, panelY, panelX + panelWidth, panelY + 20)) {
this.panelX = mouseX - MX;
this.panelY = mouseY - MY;
// TODO 修复窗口位置
if (clickedMouseButton == 0 && RenderUtils.isHovering(mouseX, mouseY, panelX, panelY, panelX + panelWidth, panelY +80)) {
if (movedX == 0 && movedY == 0) {
movedX = mouseX - panelX;
movedY = mouseY - panelY;
} else {
panelX = mouseX - movedX;
panelY = mouseY - movedY;
}
} else if (movedX != 0 || movedY != 0) {
movedX = 0;
movedY = 0;
}
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
}
Expand Down

0 comments on commit a1b9ac5

Please sign in to comment.