From 903fb9664c9e1c94ffaeb5a287e37c3adeb10d75 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Tue, 13 Feb 2024 19:37:35 +0800 Subject: [PATCH] Small Update --- core/src/cn/harryh/arkpets/ArkPets.java | 85 +++++++++---------- .../src/cn/harryh/arkpets/utils/HWndCtrl.java | 17 ++-- 2 files changed, 53 insertions(+), 49 deletions(-) diff --git a/core/src/cn/harryh/arkpets/ArkPets.java b/core/src/cn/harryh/arkpets/ArkPets.java index 4278a207..4c0a78b2 100644 --- a/core/src/cn/harryh/arkpets/ArkPets.java +++ b/core/src/cn/harryh/arkpets/ArkPets.java @@ -182,49 +182,43 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) { if (!isMouseAtSolidPixel()) { // Transfer mouse event RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY); - if (rwp != null) { - int msg = switch (button) { + if (rwp != null) + rwp.sendMouseEvent(switch (button) { case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONDOWN; case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONDOWN; case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONDOWN; default -> 0; - }; - if (msg != 0) - rwp.sendMouseEvent(msg); - } + }); } else { if (button == Input.Buttons.LEFT) { - Logger.debug("Status Msg", "FPS" + Gdx.graphics.getFramesPerSecond() + ", Heap" + (int) Math.ceil((Gdx.app.getJavaHeap() >> 10) / 1024f) + "MB"); + // Left Click: Play the specified animation changeAnimation(behavior.clickStart()); tray.hideDialog(); - return true; } else if (button == Input.Buttons.RIGHT) { - // Toggle tray dialog: - tray.toggleDialog((int) (plane.getX() + screenX), (int) (-plane.getY() - WD_H)); - return true; + // Right Click: Toggle the menu + tray.toggleDialog((int)(plane.getX() + screenX), (int)(-plane.getY() - WD_H)); } } } - return false; + return true; } @Override public boolean touchDragged(int screenX, int screenY, int pointer) { - // Logger.debug("Input", "Dragged to " + screenX + ", " + screenY); - if (!isMouseAtSolidPixel()) { - // Transfer mouse event - RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY); - if (rwp != null) - rwp.sendMouseEvent(HWndCtrl.WM_MOUSEMOVE); - } else { - mouse_drag = true; - int t = (int) Math.signum(screenX - mouse_pos.x); - mouse_intention_x = t == 0 ? mouse_intention_x : t; - int x = (int) (windowPosition.now().x + screenX - mouse_pos.x); - int y = (int) (windowPosition.now().y + screenY - mouse_pos.y); - plane.changePosition(Gdx.graphics.getDeltaTime(), x, -(WD_H + y)); - windowPosition.setToEnd(); - return true; + Logger.debug("Input", "Dragged to " + screenX + ", " + screenY); + if (pointer <= 0) { + if (isMouseAtSolidPixel()) { + mouse_drag = true; + int t = (int)Math.signum(screenX - mouse_pos.x); + mouse_intention_x = t == 0 ? mouse_intention_x : t; + // Update window position + int x = (int)(windowPosition.now().x + screenX - mouse_pos.x); + int y = (int)(windowPosition.now().y + screenY - mouse_pos.y); + plane.changePosition(Gdx.graphics.getDeltaTime(), x, -(WD_H + y)); + windowPosition.setToEnd(); + tray.hideDialog(); + return true; + } } return false; } @@ -234,20 +228,8 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) { Logger.debug("Input", "Click- Btn " + button +" @ " + screenX + ", " + screenY); mouse_pos.set(screenX, screenY); if (pointer <= 0) { - if (!isMouseAtSolidPixel()) { - // Transfer mouse event - RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY); - if (rwp != null) { - int msg = switch (button) { - case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONUP; - case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONUP; - case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONUP; - default -> 0; - }; - if (msg != 0) - rwp.sendMouseEvent(msg); - } - } else if (mouse_drag) { + if (mouse_drag) { + // Update the z-axis of the character cha.position.reset(cha.position.end().x, cha.position.end().y, mouse_intention_x); if (cha.getPlaying() != null && cha.getPlaying().mobility() != 0) { AnimData anim = cha.getPlaying(); @@ -257,8 +239,20 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) { AnimData anim = tray.keepAnim; tray.keepAnim = anim.derive(anim.offsetY(), Math.abs(anim.mobility()) * mouse_intention_x); } - } else if (button == Input.Buttons.LEFT) { + } else if (!isMouseAtSolidPixel()) { + // Transfer mouse event + RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY); + if (rwp != null) + rwp.sendMouseEvent(switch (button) { + case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONUP; + case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONUP; + case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONUP; + default -> 0; + }); + } else if (button == Input.Buttons.LEFT) { + // Left Click: Play the specified animation changeAnimation(behavior.clickEnd()); + tray.hideDialog(); } } mouse_drag = false; @@ -278,6 +272,7 @@ public boolean keyUp(int keycode) { @Override public boolean keyTyped(char character) { Logger.debug("Plane Debug Msg", plane.getDebugMsg()); + Logger.debug("Status Msg", "FPS" + Gdx.graphics.getFramesPerSecond() + ", Heap" + (int) Math.ceil((Gdx.app.getJavaHeap() >> 10) / 1024f) + "MB"); return false; } @@ -516,8 +511,10 @@ public boolean isExecutable(float deltaTime) { private record RelativeWindowPosition(HWndCtrl hWndCtrl, int relX, int relY) { public void sendMouseEvent(int msg) { - //Logger.debug("Input", "Transfer mouse event to `" + hWndCtrl.windowText + "` @ " + relX + ", " + relY); - hWndCtrl.sendMouseEvent(msg, relX, relY); + if (msg == 0) + return; + //Logger.debug("Input", "Transfer mouse event " + msg + " to `" + hWndCtrl.windowText + "` @ " + relX + ", " + relY); + hWndCtrl.updated().sendMouseEvent(msg, relX, relY); } } } diff --git a/core/src/cn/harryh/arkpets/utils/HWndCtrl.java b/core/src/cn/harryh/arkpets/utils/HWndCtrl.java index 353e2056..2177a13a 100644 --- a/core/src/cn/harryh/arkpets/utils/HWndCtrl.java +++ b/core/src/cn/harryh/arkpets/utils/HWndCtrl.java @@ -25,6 +25,7 @@ public class HWndCtrl { public final int posRight; public final int windowWidth; public final int windowHeight; + public static final HWndCtrl EMPTY = new HWndCtrl(); public static final int WS_EX_TOPMOST = 0x00000008; @@ -195,16 +196,22 @@ public void setWindowTransparent(boolean transparent) { */ public void sendMouseEvent(int msg, int x, int y) { int wParam = switch (msg) { - case WM_LBUTTONDOWN, WM_LBUTTONUP -> MK_LBUTTON; - case WM_RBUTTONDOWN, WM_RBUTTONUP -> MK_RBUTTON; - case WM_MBUTTONDOWN, WM_MBUTTONUP -> MK_MBUTTON; + case WM_LBUTTONDOWN -> MK_LBUTTON; + case WM_RBUTTONDOWN -> MK_RBUTTON; + case WM_MBUTTONDOWN -> MK_MBUTTON; default -> 0; }; - int lParam = (y << 16) | (x & 0xFFFF); - User32.INSTANCE.SendMessage(hWnd, msg, new WinDef.WPARAM(0x0021), new WinDef.LPARAM(0)); + int lParam = (y << 16) | x; User32.INSTANCE.SendMessage(hWnd, msg, new WinDef.WPARAM(wParam), new WinDef.LPARAM(lParam)); } + /** Gets a new HWndCtrl which contains the updated information of this window. + * @return The up-to-dated HWndCtrl. + */ + public HWndCtrl updated() { + return new HWndCtrl(hWnd); + } + /** Gets the current list of windows. * @param only_visible Whether exclude the invisible window. * @return An ArrayList consists of HWndCtrls.