Mobile gestures: item tap/drag/double-tap/long-press on original windows

Port the EterPythonLib CSlotWindow/CGridSlotWindow mouse handlers
(select, drop, use, right click, tooltips, grid picking/CheckMoving) and
CWindowManager IsDragging/right button, which were missing so item
interaction did not work on desktop either. app.SetMouseHandler now
renders the attached icon, app.IsPressed reads real key state, desktop
double clicks reach the window manager.

The touch router maps UI touches to the original mouse: tap = click at
the touch-down point, drag = press-and-drag, double tap = double click,
long press on an item slot = touch.SetLongPressEvent, which opens the
ui_mobile_actions item sheet (use / split / quick slot via virtual
Shift/Ctrl). New ava2.inventory_touch test drives uiinventory.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-13 05:16:12 +09:00
co-authored by Claude Opus 5.5
parent 908838c8f9
commit 6244b1d860
17 changed files with 1301 additions and 81 deletions
+18 -1
View File
@@ -37,6 +37,7 @@
#include "player_settings.h"
#include "eter_render/RaceData.h"
#include "app/input/touch_router.h"
#include "python_touch.h"
#endif
#include "app/platform/platform.h"
#include <algorithm>
@@ -712,7 +713,9 @@ ava2::app::AppLoop::Frame RunClient(ava2::app::AppLoop* loop, int argc, char** a
}
void UiMouseMove(float x, float y) override { if (wm) wm->RunMouseMove(long(x), long(y)); }
void UiMouseDown(float x, float y) override { if (wm) wm->RunMouseLeftButtonDown(long(x), long(y)); }
void UiMouseUp(float x, float y) override { if (wm) wm->RunMouseLeftButtonUp(long(x), long(y)); }
void UiMouseUp(float x, float y) override { if (wm) ava2::TouchUiMouseUp(*wm, long(x), long(y)); }
void UiDoubleClick(float x, float y) override { if (wm) wm->RunMouseLeftButtonDoubleClick(long(x), long(y)); }
bool UiLongPress(float x, float y) override { return wm && ava2::TouchUiLongPress(*wm, long(x), long(y)); }
void WorldTap(float x, float y) override {
if (!wm) return;
// GameWindow.OnMouseLeftButtonDown sets player.SetMouseState; holding it for one
@@ -1326,6 +1329,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
if (touch_mode) {
touch_sink.FlushRelease();
touch_router.SetWorldEnabled(last_phase == "game");
touch_router.Update(SDL_GetTicks());
}
#endif
SDL_Event event;
@@ -1348,6 +1352,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
if (event.type == SDL_EVENT_WINDOW_FOCUS_LOST) {
ava2::CancelPlayerMovement(); orbit_camera.EndDrag();
key_move_fwd = key_move_back = key_turn_left = key_turn_right = false;
ava2::ReleaseAllKeys();
if (touch_mode) touch_router.CancelAll();
}
if (touch_mode) {
@@ -1391,6 +1396,9 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
SDL_RenderCoordinatesFromWindow(renderer.get(), event.button.x, event.button.y, &bx, &by);
if (event.button.button == SDL_BUTTON_LEFT) {
wm->RunMouseLeftButtonDown(static_cast<long>(bx), static_cast<long>(by));
// PythonApplicationEvent.cpp OnMouseLeftButtonDoubleClick: down, then double click.
if (event.button.clicks >= 2)
wm->RunMouseLeftButtonDoubleClick(static_cast<long>(bx), static_cast<long>(by));
if (last_phase == "game" && renderer3d) {
// Ignore clicks on the minimap radar at top-right
bool is_minimap_area = (bx >= static_cast<float>(screen_width) - 135.0f && by <= 140.0f);
@@ -1722,6 +1730,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
SDL_Log("3D Rasterizer toggled: %s", use_gpu_raster ? "GPU Hardware Accelerated (Metal)" : "CPU Software Rasterizer");
}
int dik = SDLKeyToDIK(event.key.key);
if (dik) ava2::SetKeyPressed(dik, true);
if (dik) wm->RunKeyDown(dik);
} else if (event.type == SDL_EVENT_KEY_UP) {
if (original_phase_mode && last_phase == "game") {
@@ -1731,6 +1740,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
else if (event.key.key == SDLK_D || event.key.key == SDLK_RIGHT) key_turn_right = false;
}
int dik = SDLKeyToDIK(event.key.key);
if (dik) ava2::SetKeyPressed(dik, false);
if (dik) wm->RunKeyUp(dik);
} else if (event.type == SDL_EVENT_TEXT_INPUT && original_phase_mode && python) {
if (ava2::IME_IsCaptureInput()) {
@@ -1786,6 +1796,7 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
#ifdef AVA2_HAS_PYTHON
ava2::CancelPlayerMovement(); orbit_camera.EndDrag();
key_move_fwd = key_move_back = key_turn_left = key_turn_right = false;
ava2::ReleaseAllKeys();
if (touch_mode) touch_router.CancelAll();
// The OS may kill a background app without another event.
if (python) {
@@ -2502,6 +2513,12 @@ const auto profileActiveStart = std::chrono::steady_clock::now();
" if hasattr(stream.curPhaseWindow, 'OnRender'): stream.curPhaseWindow.OnRender()\n"
);
}
if (python && wm) {
// CPythonApplication OnMouseUpdate/OnMouseRender: the attached icon over the UI.
long mouse_x = 0, mouse_y = 0;
wm->GetMousePosition(mouse_x, mouse_y);
ava2::RunMouseHandler(mouse_x, mouse_y);
}
graphicDevice.EndScene(false);
if (last_phase == "game" && renderer3d && preview_data) {