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:
co-authored by
Claude Opus 5.5
parent
908838c8f9
commit
6244b1d860
@@ -363,7 +363,17 @@ PyObject* app_set_hair_color_enable(PyObject*, PyObject* args) { int f = 0; if(!
|
||||
PyObject* app_set_armor_specular_enable(PyObject*, PyObject* args) { int f = 0; if(!PyArg_ParseTuple(args, "i", &f)) return nullptr; s_armor_specular = (f != 0); NetworkActorManager::SetArmorSpecularEnable(f != 0); Py_RETURN_NONE; }
|
||||
PyObject* app_set_weapon_specular_enable(PyObject*, PyObject* args) { int f = 0; if(!PyArg_ParseTuple(args, "i", &f)) return nullptr; s_weapon_specular = (f != 0); Py_RETURN_NONE; }
|
||||
|
||||
PyObject* app_set_mouse_handler(PyObject*, PyObject* args) { Py_RETURN_NONE; }
|
||||
// app.SetMouseHandler (CPythonApplication::SetMouseHandler): mouseModule.mouseController, which
|
||||
// draws the icon attached to the mouse; RunMouseHandler is OnMouseUpdate + OnMouseRender.
|
||||
PyObject* s_mouse_handler = nullptr;
|
||||
PyObject* app_set_mouse_handler(PyObject*, PyObject* args) {
|
||||
PyObject* handler = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O", &handler)) return nullptr;
|
||||
Py_XINCREF(handler);
|
||||
Py_XDECREF(s_mouse_handler);
|
||||
s_mouse_handler = handler;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
// appCreate: after the window, LoadPythonPlayerSettingsModuleLibrary registers the
|
||||
// PythonPlayerSettingsModule tables and CPythonPlayerSettingsModule::Load runs
|
||||
// introLoading.__main__ (name/title colours, title names, emotion icons, dungeon names),
|
||||
@@ -394,7 +404,16 @@ PyObject* app_abort(PyObject*, PyObject*) {
|
||||
SDL_PushEvent(&ev);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
PyObject* app_is_pressed(PyObject*, PyObject* args) { return PyInt_FromLong(0); }
|
||||
// app.IsPressed(DIK_*) (CPythonApplication::IsPressed, the DirectInput keyboard state): the host
|
||||
// reports key changes as DIK codes; touch actions can hold a key virtually (SetVirtualKey).
|
||||
bool s_dik_pressed[256] = {};
|
||||
bool s_dik_virtual[256] = {};
|
||||
PyObject* app_is_pressed(PyObject*, PyObject* args) {
|
||||
int key = 0;
|
||||
if (!PyArg_ParseTuple(args, "i", &key)) return nullptr;
|
||||
const bool pressed = key >= 0 && key < 256 && (s_dik_pressed[key] || s_dik_virtual[key]);
|
||||
return PyInt_FromLong(pressed ? 1 : 0);
|
||||
}
|
||||
|
||||
PyObject* app_get_locale_service_name(PyObject*, PyObject*) {
|
||||
return PyString_FromString(s_locale_service_name.c_str());
|
||||
@@ -493,7 +512,15 @@ std::uint32_t GetLocalMSec() { return local_milliseconds(); }
|
||||
std::int32_t GetApplicationSeconds() { return static_cast<std::int32_t>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now()-app_start).count()); }
|
||||
void SetServerMSec(std::uint32_t time) { if(time==0) return;elt_server_time=time;elt_client_time=local_milliseconds(); ELTimer_SetServerMSec(time); }
|
||||
std::uint32_t GetServerMSec() { return local_milliseconds()-elt_client_time+elt_server_time; }
|
||||
void ResetPythonAppState() { s_cameraSettingPending=false; elt_server_time=elt_client_time=0;ELTimer_Init();server_clock=ServerClock(local_milliseconds());app_start=std::chrono::steady_clock::now();s_test_server_flag=false;twoHandedAttackSpeedDecrease=0; }
|
||||
void SetKeyPressed(int dik, bool pressed) { if (dik >= 0 && dik < 256) s_dik_pressed[dik] = pressed; }
|
||||
void SetVirtualKey(int dik, bool pressed) { if (dik >= 0 && dik < 256) s_dik_virtual[dik] = pressed; }
|
||||
void ReleaseAllKeys() { for (int i = 0; i < 256; ++i) s_dik_pressed[i] = s_dik_virtual[i] = false; }
|
||||
void RunMouseHandler(long x, long y) {
|
||||
if (!s_mouse_handler) return;
|
||||
PyCallClassMemberFunc(s_mouse_handler, "Update", Py_BuildValue("(ii)", int(x), int(y)));
|
||||
PyCallClassMemberFunc(s_mouse_handler, "Render", Py_BuildValue("()"));
|
||||
}
|
||||
void ResetPythonAppState() { s_mouse_handler=nullptr;ReleaseAllKeys();s_cameraSettingPending=false; elt_server_time=elt_client_time=0;ELTimer_Init();server_clock=ServerClock(local_milliseconds());app_start=std::chrono::steady_clock::now();s_test_server_flag=false;twoHandedAttackSpeedDecrease=0; }
|
||||
std::uint8_t GetEnterGameLanguage() {
|
||||
const char* locales[]={"ymir","en","de","tr","pt","es","fr","ro","pl","it","cz","hu"};
|
||||
for(std::uint8_t i=1;i<12;++i) if(s_locale_name==locales[i]) return i;
|
||||
|
||||
@@ -9,6 +9,12 @@ bool IsYmirLocale();
|
||||
std::int32_t GetServerTimeStamp();
|
||||
void SetServerTime(std::int32_t time);
|
||||
void ResetPythonAppState();
|
||||
// app.IsPressed key state in DIK codes: host keyboard, and keys held virtually by touch actions.
|
||||
void SetKeyPressed(int dik, bool pressed);
|
||||
void SetVirtualKey(int dik, bool pressed);
|
||||
void ReleaseAllKeys();
|
||||
// Calls the app.SetMouseHandler object's Update(x, y) and Render() (attached icon, cursor).
|
||||
void RunMouseHandler(long x, long y);
|
||||
std::uint32_t GetLocalMSec();
|
||||
std::int32_t GetApplicationSeconds();
|
||||
void SetServerMSec(std::uint32_t time);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "python_touch.h"
|
||||
#include "app/input/touch_router.h"
|
||||
#include "python_app.h"
|
||||
#include "eter_ui/PythonWindow.h"
|
||||
#include "eter_ui/PythonWindowManager.h"
|
||||
#include <Python.h>
|
||||
|
||||
namespace ava2 {
|
||||
@@ -62,9 +65,60 @@ PyObject* touch_get_safe_area(PyObject*, PyObject*) {
|
||||
int(l.safe_right + 0.5f), int(l.safe_bottom + 0.5f));
|
||||
}
|
||||
|
||||
// SetLongPressEvent(func): func(slotWindow, slotNumber, itemCount, x, y) runs when a finger rests on an item
|
||||
// slot; a true result takes the touch (no click follows). None clears it.
|
||||
PyObject* s_long_press_event = nullptr;
|
||||
PyObject* touch_set_long_press_event(PyObject*, PyObject* args) {
|
||||
PyObject* event = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "O", &event)) return nullptr;
|
||||
if (event == Py_None) event = nullptr;
|
||||
Py_XINCREF(event);
|
||||
Py_XDECREF(s_long_press_event);
|
||||
s_long_press_event = event;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// SetVirtualKey(dik, pressed): holds a key for app.IsPressed, e.g. DIK_LSHIFT while an action
|
||||
// runs the original Shift+click item split.
|
||||
PyObject* touch_set_virtual_key(PyObject*, PyObject* args) {
|
||||
int dik = 0, pressed = 0;
|
||||
if (!PyArg_ParseTuple(args, "ii", &dik, &pressed)) return nullptr;
|
||||
SetVirtualKey(dik, pressed != 0);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool RunTouchLongPress(PyObject* slot_window, unsigned long slot_number, unsigned long item_count, long x, long y) {
|
||||
if (!s_long_press_event || !slot_window) return false;
|
||||
PyObject* result = PyObject_CallFunction(s_long_press_event, const_cast<char*>("Okkll"), slot_window, slot_number,
|
||||
item_count, x, y);
|
||||
if (!result) {
|
||||
PyErr_Print();
|
||||
return false;
|
||||
}
|
||||
const bool taken = PyObject_IsTrue(result) == 1;
|
||||
Py_DECREF(result);
|
||||
return taken;
|
||||
}
|
||||
|
||||
void TouchUiMouseUp(UI::CWindowManager& wm, long x, long y) {
|
||||
wm.RunMouseLeftButtonUp(x, y);
|
||||
if (!wm.IsAttaching()) wm.RunMouseMove(-10000, -10000);
|
||||
}
|
||||
|
||||
bool TouchUiLongPress(UI::CWindowManager& wm, long x, long y) {
|
||||
if (wm.IsAttaching()) return false;
|
||||
wm.RunMouseMove(x, y);
|
||||
auto* slots = dynamic_cast<UI::CSlotWindow*>(wm.PickWindow(x, y));
|
||||
UI::CSlotWindow::SSlot* slot = nullptr;
|
||||
if (!slots || !slots->GetPickedSlotPointer(&slot) || !slot || !slot->isItem) return false;
|
||||
return RunTouchLongPress(slots->GetHandler(), slot->dwSlotNumber, slot->dwItemCount, x, y);
|
||||
}
|
||||
|
||||
void inittouch() {
|
||||
// A new interpreter: the old callback object belonged to the previous one.
|
||||
s_long_press_event = nullptr;
|
||||
static PyMethodDef methods[] = {
|
||||
{"IsEnabled", touch_is_enabled, METH_NOARGS, nullptr},
|
||||
{"GetJoystick", touch_get_joystick, METH_NOARGS, nullptr},
|
||||
@@ -73,6 +127,8 @@ void inittouch() {
|
||||
{"SetJoystickArea", touch_set_joystick_area, METH_VARARGS, nullptr},
|
||||
{"GetLayout", touch_get_layout, METH_NOARGS, nullptr},
|
||||
{"GetSafeArea", touch_get_safe_area, METH_NOARGS, nullptr},
|
||||
{"SetLongPressEvent", touch_set_long_press_event, METH_VARARGS, nullptr},
|
||||
{"SetVirtualKey", touch_set_virtual_key, METH_VARARGS, nullptr},
|
||||
{nullptr, nullptr, 0, nullptr}
|
||||
};
|
||||
Py_InitModule("touch", methods);
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct _object PyObject;
|
||||
namespace UI { class CWindowManager; }
|
||||
|
||||
namespace ava2 {
|
||||
// `touch` module: lets the mobile HUD place the attack button / joystick area of the native
|
||||
// touch router (src/app/input/touch_router.h) and draw the joystick it drives.
|
||||
void inittouch();
|
||||
// Long press on an item slot: calls the touch.SetLongPressEvent function with the slot window's
|
||||
// Python object; true when it took the touch.
|
||||
bool RunTouchLongPress(PyObject* slot_window, unsigned long slot_number, unsigned long item_count, long x, long y);
|
||||
|
||||
// Touch router sink helpers shared by the host loop and tests:
|
||||
// left button up for a finger; afterwards the pointer leaves the screen (a lifted finger does not
|
||||
// hover, so tooltips close) unless an icon is attached and must stay where it was picked up.
|
||||
void TouchUiMouseUp(UI::CWindowManager& wm, long x, long y);
|
||||
// Long press: on an item slot (nothing attached) the pointer rests there, so the original item
|
||||
// tooltip shows, and RunTouchLongPress decides; true when the touch was taken.
|
||||
bool TouchUiLongPress(UI::CWindowManager& wm, long x, long y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user