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
+18
-1
@@ -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) {
|
||||
|
||||
@@ -27,6 +27,7 @@ TouchLayout TouchLayout::ForScreen(float w, float h, float safeLeft, float safeT
|
||||
layout.attack_x = w - safeRight - layout.attack_r - unit * 0.06f;
|
||||
layout.attack_y = h - safeBottom - layout.attack_r - unit * 0.06f;
|
||||
layout.tap_slop = unit * 0.02f;
|
||||
layout.double_tap_slop = unit * 0.06f;
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -95,9 +96,9 @@ void TouchRouter::FingerDown(std::uint64_t raw_id, float x, float y, std::uint64
|
||||
if (m_ui_finger || !m_sink) return;
|
||||
finger.owner = Owner::Ui;
|
||||
m_ui_finger = id;
|
||||
finger.ui = Finger::Ui::Pending;
|
||||
m_fingers[id] = finger;
|
||||
m_sink->UiMouseMove(x, y);
|
||||
m_sink->UiMouseDown(x, y);
|
||||
return;
|
||||
}
|
||||
if (!m_attack_finger && InAttack(x, y)) {
|
||||
@@ -137,7 +138,15 @@ void TouchRouter::FingerMove(std::uint64_t raw_id, float x, float y, std::uint64
|
||||
finger.y = y;
|
||||
switch (finger.owner) {
|
||||
case Owner::Ui:
|
||||
if (m_sink) m_sink->UiMouseMove(x, y);
|
||||
if (!m_sink || finger.ui == Finger::Ui::Consumed) break;
|
||||
if (finger.ui == Finger::Ui::Pending) {
|
||||
if (std::hypot(x - finger.start_x, y - finger.start_y) <= m_layout.tap_slop) break;
|
||||
// A drag: the button goes down where the finger landed, as a mouse drag would start.
|
||||
finger.ui = Finger::Ui::Pressed;
|
||||
m_sink->UiMouseMove(finger.start_x, finger.start_y);
|
||||
m_sink->UiMouseDown(finger.start_x, finger.start_y);
|
||||
}
|
||||
m_sink->UiMouseMove(x, y);
|
||||
break;
|
||||
case Owner::Attack:
|
||||
break;
|
||||
@@ -168,8 +177,8 @@ void TouchRouter::Release(std::uint64_t id, Finger& finger, bool cancelled) {
|
||||
switch (finger.owner) {
|
||||
case Owner::Ui:
|
||||
m_ui_finger = 0;
|
||||
// A cancelled UI finger still releases the button so no window keeps the capture.
|
||||
if (m_sink) m_sink->UiMouseUp(finger.x, finger.y);
|
||||
// A cancelled UI finger still releases a pressed button so no window keeps the capture.
|
||||
if (finger.ui == Finger::Ui::Pressed && m_sink) m_sink->UiMouseUp(finger.x, finger.y);
|
||||
break;
|
||||
case Owner::Attack:
|
||||
m_attack_finger = 0;
|
||||
@@ -195,7 +204,12 @@ void TouchRouter::FingerUp(std::uint64_t raw_id, float x, float y, std::uint64_t
|
||||
m_fingers.erase(it);
|
||||
finger.x = x;
|
||||
finger.y = y;
|
||||
if (finger.owner == Owner::Ui && m_sink) m_sink->UiMouseMove(x, y);
|
||||
if (finger.owner == Owner::Ui && finger.ui == Finger::Ui::Pending) {
|
||||
m_ui_finger = 0;
|
||||
UiTap(finger, ms);
|
||||
return;
|
||||
}
|
||||
if (finger.owner == Owner::Ui && finger.ui == Finger::Ui::Pressed && m_sink) m_sink->UiMouseMove(x, y);
|
||||
if (finger.owner == Owner::Camera && finger.tap &&
|
||||
(ms - finger.start_ms > m_layout.tap_ms ||
|
||||
std::hypot(x - finger.start_x, y - finger.start_y) > m_layout.tap_slop))
|
||||
@@ -203,6 +217,40 @@ void TouchRouter::FingerUp(std::uint64_t raw_id, float x, float y, std::uint64_t
|
||||
Release(id, finger, false);
|
||||
}
|
||||
|
||||
void TouchRouter::UiTap(const Finger& finger, std::uint64_t ms) {
|
||||
if (!m_sink) return;
|
||||
// The click lands where the finger landed; a tap moves less than tap_slop anyway.
|
||||
const float x = finger.start_x, y = finger.start_y;
|
||||
const bool second = m_last_tap_valid && finger.start_ms >= m_last_tap_ms &&
|
||||
finger.start_ms - m_last_tap_ms <= m_layout.double_tap_ms &&
|
||||
std::hypot(x - m_last_tap_x, y - m_last_tap_y) <= m_layout.double_tap_slop;
|
||||
m_sink->UiMouseMove(x, y);
|
||||
m_sink->UiMouseDown(x, y);
|
||||
if (second) m_sink->UiDoubleClick(x, y);
|
||||
m_sink->UiMouseUp(x, y);
|
||||
// A third tap starts a new pair.
|
||||
m_last_tap_valid = !second;
|
||||
m_last_tap_ms = ms;
|
||||
m_last_tap_x = x;
|
||||
m_last_tap_y = y;
|
||||
}
|
||||
|
||||
void TouchRouter::Update(std::uint64_t ms) {
|
||||
if (!m_ui_finger || !m_sink) return;
|
||||
auto it = m_fingers.find(m_ui_finger);
|
||||
if (it == m_fingers.end()) return;
|
||||
Finger& finger = it->second;
|
||||
if (finger.ui != Finger::Ui::Pending || ms < finger.start_ms || ms - finger.start_ms < m_layout.long_press_ms) return;
|
||||
m_last_tap_valid = false;
|
||||
if (m_sink->UiLongPress(finger.x, finger.y)) {
|
||||
finger.ui = Finger::Ui::Consumed;
|
||||
return;
|
||||
}
|
||||
finger.ui = Finger::Ui::Pressed;
|
||||
m_sink->UiMouseMove(finger.x, finger.y);
|
||||
m_sink->UiMouseDown(finger.x, finger.y);
|
||||
}
|
||||
|
||||
void TouchRouter::CancelAll() {
|
||||
for (auto& [id, finger] : m_fingers) Release(id, finger, true);
|
||||
m_fingers.clear();
|
||||
|
||||
@@ -3,12 +3,25 @@
|
||||
//
|
||||
// Every finger is assigned an owner when it goes down and keeps it until it lifts:
|
||||
//
|
||||
// UI window under the finger -> mouse events for the window manager (one finger at a time)
|
||||
// UI window under the finger -> mouse events for the window manager (one finger at a time),
|
||||
// see "UI gestures" below
|
||||
// attack button circle -> attack key held while the finger is down
|
||||
// joystick area (lower left) -> floating virtual joystick, camera-relative movement
|
||||
// anything else -> one finger drags the camera, two fingers pinch-zoom,
|
||||
// a short tap clicks the game world (target / ground)
|
||||
//
|
||||
// UI gestures. The button press is held back until the finger shows what it is doing:
|
||||
//
|
||||
// tap -> down + up where the finger lifts (a click: pick up / drop an item)
|
||||
// second tap nearby -> down + double click + up, as PythonApplicationEvent.cpp sends a mouse
|
||||
// double click (use / equip an item)
|
||||
// move past tap_slop -> down at the start point, then moves (drag an item, scroll, move a window)
|
||||
// hold long_press_ms -> UiLongPress; when the host takes it (item details / action sheet) the
|
||||
// rest of the touch is ignored, otherwise the button goes down and the
|
||||
// touch continues as a press
|
||||
//
|
||||
// The pointer follows the finger from the moment it lands, so hover tooltips show while holding.
|
||||
//
|
||||
// Outside the game phase only the UI owner exists. Coordinates are UI pixels (the same space as
|
||||
// wndMgr). The router has no SDL or game dependencies; the host implements TouchSink.
|
||||
|
||||
@@ -24,6 +37,10 @@ struct TouchSink {
|
||||
virtual void UiMouseMove(float x, float y) = 0;
|
||||
virtual void UiMouseDown(float x, float y) = 0;
|
||||
virtual void UiMouseUp(float x, float y) = 0;
|
||||
// Second tap of a double tap, between its UiMouseDown and UiMouseUp.
|
||||
virtual void UiDoubleClick(float, float) {}
|
||||
// Finger held still on UI; true when the host handled it and wants no button press.
|
||||
virtual bool UiLongPress(float, float) { return false; }
|
||||
// Short tap on the game world: the host clicks there as the original left button would.
|
||||
virtual void WorldTap(float x, float y) = 0;
|
||||
// Joystick vector in screen axes (x right, y down), length 0..1; active=false releases it.
|
||||
@@ -45,6 +62,9 @@ struct TouchLayout {
|
||||
float attack_x = 0.0f, attack_y = 0.0f, attack_r = 0.0f;
|
||||
float tap_slop = 14.0f; // movement that turns a tap into a camera drag
|
||||
std::uint64_t tap_ms = 300; // longer presses are not taps
|
||||
std::uint64_t double_tap_ms = 300; // first tap's lift to second tap's landing
|
||||
float double_tap_slop = 40.0f; // distance between the two taps
|
||||
std::uint64_t long_press_ms = 450;
|
||||
|
||||
// Unobstructed-area insets (platform::SafeInsets); the HUD reads them through `touch`.
|
||||
float safe_left = 0.0f, safe_top = 0.0f, safe_right = 0.0f, safe_bottom = 0.0f;
|
||||
@@ -75,6 +95,8 @@ public:
|
||||
void FingerDown(std::uint64_t id, float x, float y, std::uint64_t ms);
|
||||
void FingerMove(std::uint64_t id, float x, float y, std::uint64_t ms);
|
||||
void FingerUp(std::uint64_t id, float x, float y, std::uint64_t ms);
|
||||
// Per-frame tick in the same milliseconds as the finger events (long press detection).
|
||||
void Update(std::uint64_t ms);
|
||||
// Lost focus / app paused: release everything without taps or clicks.
|
||||
void CancelAll();
|
||||
|
||||
@@ -89,6 +111,9 @@ private:
|
||||
float start_x = 0.0f, start_y = 0.0f;
|
||||
std::uint64_t start_ms = 0;
|
||||
bool tap = true; // still a tap candidate (camera fingers)
|
||||
// UI fingers: Pending holds the button press back, Pressed sent it, Consumed was a long
|
||||
// press the host took.
|
||||
enum class Ui { Pending, Pressed, Consumed } ui = Ui::Pending;
|
||||
};
|
||||
|
||||
bool InAttack(float x, float y) const;
|
||||
@@ -96,6 +121,7 @@ private:
|
||||
void UpdateJoystick(float x, float y);
|
||||
Finger* OtherCameraFinger(std::uint64_t id);
|
||||
void Release(std::uint64_t id, Finger& finger, bool cancelled);
|
||||
void UiTap(const Finger& finger, std::uint64_t ms);
|
||||
|
||||
TouchSink* m_sink = nullptr;
|
||||
TouchLayout m_layout;
|
||||
@@ -103,6 +129,10 @@ private:
|
||||
std::map<std::uint64_t, Finger> m_fingers; // ids are offset by one so 0 means "none"
|
||||
std::uint64_t m_ui_finger = 0, m_joy_finger = 0, m_attack_finger = 0;
|
||||
JoystickView m_joy;
|
||||
// Last UI tap for double tap detection; m_last_tap_valid is cleared once it pairs.
|
||||
bool m_last_tap_valid = false;
|
||||
std::uint64_t m_last_tap_ms = 0;
|
||||
float m_last_tap_x = 0.0f, m_last_tap_y = 0.0f;
|
||||
};
|
||||
|
||||
// The client's router, shared by the host loop and the Python `touch` module.
|
||||
|
||||
+479
-56
@@ -2255,6 +2255,12 @@ namespace UI
|
||||
SSlot& slot = it->second;
|
||||
slot.dwItemIndex = 0;
|
||||
slot.isItem = false;
|
||||
// EterPythonLib/PythonSlotWindow.cpp ClearSlot(TSlot*).
|
||||
slot.dwState = 0;
|
||||
slot.byxPlacedItemSize = 1;
|
||||
slot.byyPlacedItemSize = 1;
|
||||
slot.dwCenterSlotNumber = 0xffffffff;
|
||||
slot.bRenderBaseSlotImage = true;
|
||||
slot.dwItemCount = 0;
|
||||
slot.dwGrade = 0;
|
||||
slot.fCoolTime = 0.0f;
|
||||
@@ -2341,7 +2347,10 @@ namespace UI
|
||||
slot.byHeight = byHeight;
|
||||
slot.byxPlacedItemSize = byWidth ? byWidth : 1;
|
||||
slot.byyPlacedItemSize = byHeight ? byHeight : 1;
|
||||
slot.isItem = (pImage != nullptr);
|
||||
// EterPythonLib/PythonSlotWindow.cpp SetSlot: a slot holds an item when it has a virtual
|
||||
// number (the mouse events and tooltips key on this), and setting it resets the state.
|
||||
slot.dwState = 0;
|
||||
slot.isItem = dwItemIndex > 0;
|
||||
if (pImage) {
|
||||
if (!slot.pInstance)
|
||||
slot.pInstance = CGraphicImageInstance::New();
|
||||
@@ -2647,6 +2656,266 @@ namespace UI
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonSlotWindow.cpp GetPickedSlotPointer. Slots are searched in index order
|
||||
// (the original list order for the top-left-first layouts), so a multi-cell item is found by
|
||||
// its own slot before the cells it covers; its size counts even if the cell size is smaller.
|
||||
BOOL CSlotWindow::GetPickedSlotPointer(SSlot** ppSlot)
|
||||
{
|
||||
long lx, ly;
|
||||
CWindowManager::Instance().GetMousePosition(lx, ly);
|
||||
|
||||
const int ixLocal = lx - m_rect.left;
|
||||
const int iyLocal = ly - m_rect.top;
|
||||
|
||||
for (auto& pair : m_slotMap)
|
||||
{
|
||||
SSlot& rSlot = pair.second;
|
||||
|
||||
int ixCellSize = rSlot.ixCellSize;
|
||||
int iyCellSize = rSlot.iyCellSize;
|
||||
|
||||
if (rSlot.isItem)
|
||||
{
|
||||
ixCellSize = std::max(rSlot.ixCellSize, int(rSlot.byxPlacedItemSize * 32));
|
||||
iyCellSize = std::max(rSlot.iyCellSize, int(rSlot.byyPlacedItemSize * 32));
|
||||
}
|
||||
|
||||
if (ixLocal >= rSlot.ixPosition && iyLocal >= rSlot.iyPosition &&
|
||||
ixLocal <= rSlot.ixPosition + ixCellSize && iyLocal <= rSlot.iyPosition + iyCellSize)
|
||||
{
|
||||
*ppSlot = &rSlot;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonSlotWindow.cpp RefreshSlot: re-issue the tooltip of the slot under the
|
||||
// mouse, since its item may have changed.
|
||||
void CSlotWindow::RefreshSlot()
|
||||
{
|
||||
OnRefreshSlot();
|
||||
|
||||
if (IsRendering())
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (GetPickedSlotPointer(&pSlot))
|
||||
{
|
||||
if (pSlot->isItem)
|
||||
{
|
||||
OnOverOutItem();
|
||||
OnOverInItem(pSlot->dwSlotNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnOverOut();
|
||||
OnOverIn(pSlot->dwSlotNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mouse events: EterPythonLib/PythonSlotWindow.cpp (WJ_ENABLE_TRADABLE_ICON branches, which
|
||||
// AVA2 builds with).
|
||||
BOOL CSlotWindow::OnMouseLeftButtonDown()
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetPickedSlotPointer(&pSlot))
|
||||
{
|
||||
UI::CWindowManager::Instance().DeattachIcon();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!(pSlot->dwState & SLOT_STATE_CANT_MOUSE_EVENT))
|
||||
{
|
||||
if (pSlot->isItem && !(pSlot->dwState & SLOT_STATE_LOCK))
|
||||
OnSelectItemSlot(pSlot->dwSlotNumber);
|
||||
else
|
||||
OnSelectEmptySlot(pSlot->dwSlotNumber);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CSlotWindow::OnMouseLeftButtonUp()
|
||||
{
|
||||
auto& wm = UI::CWindowManager::Instance();
|
||||
if (wm.IsAttaching() && wm.IsDragging() && IsIn())
|
||||
{
|
||||
UI::CWindow* pWin = wm.GetPointWindow();
|
||||
|
||||
if (pWin && pWin->IsType(UI::CSlotWindow::Type()))
|
||||
{
|
||||
auto* pSlotWin = static_cast<UI::CSlotWindow*>(pWin);
|
||||
|
||||
SSlot* pSlot;
|
||||
if (!pSlotWin->GetPickedSlotPointer(&pSlot))
|
||||
{
|
||||
wm.DeattachIcon();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!(pSlot->dwState & SLOT_STATE_CANT_MOUSE_EVENT))
|
||||
{
|
||||
if (pSlot->isItem)
|
||||
pSlotWin->OnSelectItemSlot(pSlot->dwSlotNumber);
|
||||
else
|
||||
pSlotWin->OnSelectEmptySlot(pSlot->dwSlotNumber);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CSlotWindow::OnMouseRightButtonDown()
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetPickedSlotPointer(&pSlot))
|
||||
return TRUE;
|
||||
|
||||
if (!(pSlot->dwState & SLOT_STATE_CANT_MOUSE_EVENT))
|
||||
{
|
||||
if (pSlot->isItem)
|
||||
OnUnselectItemSlot(pSlot->dwSlotNumber);
|
||||
else
|
||||
OnUnselectEmptySlot(pSlot->dwSlotNumber);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CSlotWindow::OnMouseLeftButtonDoubleClick()
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (GetPickedSlotPointer(&pSlot))
|
||||
if (!(pSlot->dwState & SLOT_STATE_CANT_MOUSE_EVENT))
|
||||
OnUseSlot();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CSlotWindow::OnMouseOverOut()
|
||||
{
|
||||
OnOverOutItem();
|
||||
OnOverOut();
|
||||
}
|
||||
|
||||
void CSlotWindow::OnMouseOver()
|
||||
{
|
||||
SSlot* pSlot;
|
||||
CWindow* pPointWindow = UI::CWindowManager::Instance().GetPointWindow();
|
||||
if (this == pPointWindow)
|
||||
{
|
||||
if (GetPickedSlotPointer(&pSlot))
|
||||
{
|
||||
if (OnOverInItem(pSlot->dwSlotNumber))
|
||||
return;
|
||||
else
|
||||
OnOverOutItem();
|
||||
|
||||
if (OnOverIn(pSlot->dwSlotNumber))
|
||||
return;
|
||||
else
|
||||
OnOverOut();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
OnOverOutItem();
|
||||
OnOverOut();
|
||||
}
|
||||
|
||||
void CSlotWindow::OnSelectEmptySlot(int iSlotNumber)
|
||||
{
|
||||
PyCallClassMemberFunc(m_poHandler, "OnSelectEmptySlot", Py_BuildValue("(i)", iSlotNumber));
|
||||
}
|
||||
|
||||
void CSlotWindow::OnSelectItemSlot(int iSlotNumber)
|
||||
{
|
||||
PyCallClassMemberFunc(m_poHandler, "OnSelectItemSlot", Py_BuildValue("(i)", iSlotNumber));
|
||||
|
||||
if (UI::CWindowManager::Instance().IsAttaching())
|
||||
OnOverOutItem();
|
||||
}
|
||||
|
||||
void CSlotWindow::OnUnselectEmptySlot(int iSlotNumber)
|
||||
{
|
||||
PyCallClassMemberFunc(m_poHandler, "OnUnselectEmptySlot", Py_BuildValue("(i)", iSlotNumber));
|
||||
}
|
||||
|
||||
void CSlotWindow::OnUnselectItemSlot(int iSlotNumber)
|
||||
{
|
||||
PyCallClassMemberFunc(m_poHandler, "OnUnselectItemSlot", Py_BuildValue("(i)", iSlotNumber));
|
||||
}
|
||||
|
||||
void CSlotWindow::OnUseSlot()
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (GetPickedSlotPointer(&pSlot))
|
||||
if (pSlot->isItem)
|
||||
PyCallClassMemberFunc(m_poHandler, "OnUseSlot", Py_BuildValue("(i)", pSlot->dwSlotNumber));
|
||||
}
|
||||
|
||||
BOOL CSlotWindow::OnOverIn(DWORD dwSlotNumber)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetSlotPointer(dwSlotNumber, &pSlot))
|
||||
return FALSE;
|
||||
|
||||
if (pSlot->isItem)
|
||||
return FALSE;
|
||||
|
||||
if (pSlot->dwSlotNumber == m_dwOverInSlotNumber)
|
||||
return TRUE;
|
||||
|
||||
m_dwOverInSlotNumber = dwSlotNumber;
|
||||
PyCallClassMemberFunc(m_poHandler, "OnOverIn", Py_BuildValue("(i)", dwSlotNumber));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CSlotWindow::OnOverOut()
|
||||
{
|
||||
if (SLOT_NUMBER_NONE == m_dwOverInSlotNumber)
|
||||
return;
|
||||
|
||||
m_dwOverInSlotNumber = SLOT_NUMBER_NONE;
|
||||
PyCallClassMemberFunc(m_poHandler, "OnOverOut", Py_BuildValue("()"));
|
||||
}
|
||||
|
||||
BOOL CSlotWindow::OnOverInItem(DWORD dwSlotNumber)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetSlotPointer(dwSlotNumber, &pSlot))
|
||||
return FALSE;
|
||||
|
||||
if (!pSlot->isItem)
|
||||
return FALSE;
|
||||
|
||||
if (pSlot->dwSlotNumber == m_dwToolTipSlotNumber)
|
||||
return TRUE;
|
||||
|
||||
m_dwToolTipSlotNumber = dwSlotNumber;
|
||||
PyCallClassMemberFunc(m_poHandler, "OnOverInItem",
|
||||
Py_BuildValue("(iii)", dwSlotNumber, pSlot->dwItemIndex, pSlot->dwItemID));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CSlotWindow::OnOverOutItem()
|
||||
{
|
||||
if (SLOT_NUMBER_NONE == m_dwToolTipSlotNumber)
|
||||
return;
|
||||
|
||||
m_dwToolTipSlotNumber = SLOT_NUMBER_NONE;
|
||||
PyCallClassMemberFunc(m_poHandler, "OnOverOutItem", Py_BuildValue("()"));
|
||||
}
|
||||
|
||||
void CSlotWindow::RenderSlotBaseImage()
|
||||
{
|
||||
if (!m_pBaseImageInstance) return;
|
||||
@@ -2963,105 +3232,259 @@ namespace UI
|
||||
CGridSlotWindow::CGridSlotWindow(PyObject * ppyObject) : CSlotWindow(ppyObject) {}
|
||||
CGridSlotWindow::~CGridSlotWindow() {}
|
||||
|
||||
// EterPythonLib/PythonGridSlotWindow.cpp ArrangeGridSlot (slot numbers stand in for the
|
||||
// original's slot pointers, so ClearAllSlot cannot leave them dangling).
|
||||
void CGridSlotWindow::ArrangeGridSlot(DWORD dwStartIndex, DWORD dwxCount, DWORD dwyCount, int ixSlotSize, int iySlotSize, int ixTemporarySize, int iyTemporarySize)
|
||||
{
|
||||
ClearAllSlot();
|
||||
|
||||
m_dwxCount = dwxCount;
|
||||
m_dwyCount = dwyCount;
|
||||
m_SlotVector.assign(dwxCount * dwyCount, SLOT_NUMBER_NONE);
|
||||
|
||||
for (DWORD y = 0; y < dwyCount; ++y) {
|
||||
for (DWORD x = 0; x < dwxCount; ++x) {
|
||||
DWORD dwIndex = dwStartIndex + x + y * dwxCount;
|
||||
int ixPos = x * (ixSlotSize + ixTemporarySize);
|
||||
int iyPos = y * (iySlotSize + iyTemporarySize);
|
||||
AppendSlot(dwIndex, ixPos, iyPos, ixSlotSize, iySlotSize);
|
||||
m_SlotVector[x + y * dwxCount] = dwIndex;
|
||||
}
|
||||
}
|
||||
SetSize(dwxCount * (ixSlotSize + ixTemporarySize), dwyCount * (iySlotSize + iyTemporarySize));
|
||||
}
|
||||
|
||||
BOOL CGridSlotWindow::GetPickedSlotList(BYTE byWidth, BYTE byHeight, std::vector<SSlot*>* pSlotList)
|
||||
BOOL CGridSlotWindow::GetGridSlotPointer(int ix, int iy, SSlot** ppSlot)
|
||||
{
|
||||
if (!pSlotList) return FALSE;
|
||||
pSlotList->clear();
|
||||
if (ix < 0 || iy < 0 || DWORD(ix) >= m_dwxCount)
|
||||
return FALSE;
|
||||
DWORD dwSlotIndex = ix + iy * m_dwxCount;
|
||||
if (dwSlotIndex >= m_SlotVector.size())
|
||||
return FALSE;
|
||||
return GetSlotPointer(m_SlotVector[dwSlotIndex], ppSlot);
|
||||
}
|
||||
|
||||
long lx = 0, ly = 0;
|
||||
GetMouseLocalPosition(lx, ly);
|
||||
|
||||
if (lx < 0 || ly < 0) return FALSE;
|
||||
|
||||
for (auto& pair : m_slotMap)
|
||||
BOOL CGridSlotWindow::GetPickedGridSlotPosition(int ixLocal, int iyLocal, int* pix, int* piy)
|
||||
{
|
||||
for (DWORD x = 0; x < m_dwxCount; ++x)
|
||||
for (DWORD y = 0; y < m_dwyCount; ++y)
|
||||
{
|
||||
SSlot& s = pair.second;
|
||||
if (lx >= s.ixPosition && lx < s.ixPosition + s.ixCellSize &&
|
||||
ly >= s.iyPosition && ly < s.iyPosition + s.iyCellSize)
|
||||
SSlot* pSlot;
|
||||
if (!GetGridSlotPointer(x, y, &pSlot))
|
||||
continue;
|
||||
|
||||
if (ixLocal >= pSlot->ixPosition && iyLocal >= pSlot->iyPosition &&
|
||||
ixLocal <= pSlot->ixPosition + pSlot->ixCellSize && iyLocal <= pSlot->iyPosition + pSlot->iyCellSize)
|
||||
{
|
||||
for (BYTE y = 0; y < byHeight; ++y)
|
||||
{
|
||||
for (BYTE x = 0; x < byWidth; ++x)
|
||||
{
|
||||
int targetX = s.ixPosition + x * s.ixCellSize;
|
||||
int targetY = s.iyPosition + y * s.iyCellSize;
|
||||
bool found = false;
|
||||
for (auto& p2 : m_slotMap)
|
||||
{
|
||||
if (std::abs(p2.second.ixPosition - targetX) < 4 &&
|
||||
std::abs(p2.second.iyPosition - targetY) < 4)
|
||||
{
|
||||
pSlotList->push_back(&p2.second);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) return FALSE;
|
||||
}
|
||||
}
|
||||
*pix = x;
|
||||
*piy = y;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonGridSlotWindow.cpp GetPickedSlotList: the cells an attached item of
|
||||
// iWidth x iHeight would cover around the mouse, shifted to stay inside the grid; in use mode
|
||||
// (refine scrolls) a single picked cell expands to the whole item under it.
|
||||
BOOL CGridSlotWindow::GetPickedSlotList(BYTE iWidth, BYTE iHeight, std::vector<SSlot*>* pSlotPointerList)
|
||||
{
|
||||
if (!pSlotPointerList) return FALSE;
|
||||
|
||||
long lx, ly;
|
||||
GetMouseLocalPosition(lx, ly);
|
||||
|
||||
if (lx < 0 || ly < 0 || lx >= GetWidth() || ly >= GetHeight())
|
||||
return FALSE;
|
||||
|
||||
pSlotPointerList->clear();
|
||||
|
||||
int ix, iy;
|
||||
if (GetPickedGridSlotPosition(lx, ly, &ix, &iy))
|
||||
{
|
||||
int ixHalfStep = (iWidth / 2);
|
||||
|
||||
int ixStart = int(ix) - int(ixHalfStep - (ixHalfStep % 2));
|
||||
int ixEnd = int(ix) + int(ixHalfStep);
|
||||
|
||||
int iyStart = 0, iyEnd = 0;
|
||||
|
||||
if (1 == iHeight)
|
||||
{
|
||||
iyStart = iy;
|
||||
iyEnd = iy;
|
||||
}
|
||||
else if (2 == iHeight)
|
||||
{
|
||||
iyStart = iy;
|
||||
iyEnd = iy + 1;
|
||||
}
|
||||
else if (3 == iHeight)
|
||||
{
|
||||
iyStart = iy - 1;
|
||||
iyEnd = iy + 1;
|
||||
}
|
||||
|
||||
if (ixStart < 0)
|
||||
{
|
||||
ixEnd += -ixStart;
|
||||
ixStart = 0;
|
||||
}
|
||||
|
||||
if (iyStart < 0)
|
||||
{
|
||||
iyEnd += -iyStart;
|
||||
iyStart = 0;
|
||||
}
|
||||
|
||||
if (DWORD(ixEnd) >= m_dwxCount)
|
||||
{
|
||||
int ixTemporary = DWORD(ixEnd) - m_dwxCount + 1;
|
||||
ixStart -= ixTemporary;
|
||||
ixEnd -= ixTemporary;
|
||||
}
|
||||
|
||||
if (DWORD(iyEnd) >= m_dwyCount)
|
||||
{
|
||||
int iyTemporary = DWORD(iyEnd) - m_dwyCount + 1;
|
||||
iyStart -= iyTemporary;
|
||||
iyEnd -= iyTemporary;
|
||||
}
|
||||
|
||||
for (int i = ixStart; i <= ixEnd; ++i)
|
||||
for (int j = iyStart; j <= iyEnd; ++j)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (GetGridSlotPointer(i, j, &pSlot))
|
||||
pSlotPointerList->push_back(pSlot);
|
||||
}
|
||||
|
||||
if (m_isUseMode && 1 == pSlotPointerList->size())
|
||||
{
|
||||
SSlot* pMainSlot = pSlotPointerList->front();
|
||||
|
||||
for (DWORD dwSlotNumber : m_SlotVector)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetSlotPointer(dwSlotNumber, &pSlot))
|
||||
continue;
|
||||
if (pSlot->dwCenterSlotNumber == pMainSlot->dwCenterSlotNumber)
|
||||
if (pSlotPointerList->end() == std::find(pSlotPointerList->begin(), pSlotPointerList->end(), pSlot))
|
||||
pSlotPointerList->push_back(pSlot);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pSlotPointerList->empty())
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonGridSlotWindow.cpp OnRefreshSlot: every cell an item covers points at
|
||||
// the item's slot (dwCenterSlotNumber) and carries its virtual number.
|
||||
void CGridSlotWindow::OnRefreshSlot()
|
||||
{
|
||||
DWORD x, y;
|
||||
|
||||
for (x = 0; x < m_dwxCount; ++x)
|
||||
for (y = 0; y < m_dwyCount; ++y)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetGridSlotPointer(x, y, &pSlot))
|
||||
continue;
|
||||
|
||||
pSlot->dwCenterSlotNumber = pSlot->dwSlotNumber;
|
||||
}
|
||||
|
||||
for (x = 0; x < m_dwxCount; ++x)
|
||||
for (y = 0; y < m_dwyCount; ++y)
|
||||
{
|
||||
SSlot* pSlot;
|
||||
if (!GetGridSlotPointer(x, y, &pSlot))
|
||||
continue;
|
||||
|
||||
if (pSlot->isItem)
|
||||
{
|
||||
for (DWORD xSub = 0; xSub < pSlot->byxPlacedItemSize; ++xSub)
|
||||
for (DWORD ySub = 0; ySub < pSlot->byyPlacedItemSize; ++ySub)
|
||||
{
|
||||
SSlot* pSubSlot;
|
||||
if (!GetGridSlotPointer(x + xSub, y + ySub, &pSubSlot))
|
||||
continue;
|
||||
|
||||
pSubSlot->dwCenterSlotNumber = pSlot->dwSlotNumber;
|
||||
pSubSlot->dwItemIndex = pSlot->dwItemIndex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pSlot->dwItemIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonGridSlotWindow.cpp CheckMoving: in a pick-up grid the attached item may
|
||||
// only land on its own cells, empty cells, or a stack of the same item.
|
||||
BOOL CGridSlotWindow::CheckMoving(DWORD dwSlotNumber, DWORD dwItemIndex, const std::vector<SSlot*>& slotList)
|
||||
{
|
||||
if (m_dwSlotStyle != SLOT_STYLE_PICK_UP)
|
||||
return TRUE;
|
||||
|
||||
for (auto* pSlot : slotList)
|
||||
{
|
||||
if (pSlot->isItem && pSlot->dwSlotNumber != dwSlotNumber && pSlot->dwCenterSlotNumber != dwSlotNumber)
|
||||
return FALSE;
|
||||
if (dwSlotNumber != pSlot->dwCenterSlotNumber)
|
||||
{
|
||||
if (0 != pSlot->dwItemIndex || pSlot->dwCenterSlotNumber != pSlot->dwSlotNumber)
|
||||
{
|
||||
if (dwItemIndex != pSlot->dwItemIndex)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonGridSlotWindow.cpp GetPickedSlotPointer: with an icon attached, the
|
||||
// lowest-numbered covered cell (preferring one with an item) resolves to its item's slot,
|
||||
// except that the attached item's own slot resolves to the cell itself.
|
||||
BOOL CGridSlotWindow::GetPickedSlotPointer(SSlot** ppSlot)
|
||||
{
|
||||
if (!UI::CWindowManager::Instance().IsAttaching())
|
||||
{
|
||||
long lx = 0, ly = 0;
|
||||
GetMouseLocalPosition(lx, ly);
|
||||
for (auto& pair : m_slotMap)
|
||||
{
|
||||
SSlot& s = pair.second;
|
||||
if (lx >= s.ixPosition && lx < s.ixPosition + s.ixCellSize &&
|
||||
ly >= s.iyPosition && ly < s.iyPosition + s.iyCellSize)
|
||||
{
|
||||
if (ppSlot) *ppSlot = &s;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return CSlotWindow::GetPickedSlotPointer(ppSlot);
|
||||
|
||||
BYTE byWidth = 1, byHeight = 1;
|
||||
UI::CWindowManager::Instance().GetAttachingIconSize(&byWidth, &byHeight);
|
||||
|
||||
std::vector<SSlot*> slotList;
|
||||
if (!GetPickedSlotList(byWidth, byHeight, &slotList) || slotList.empty())
|
||||
if (!GetPickedSlotList(byWidth, byHeight, &slotList))
|
||||
return FALSE;
|
||||
|
||||
SSlot* pMin = slotList.front();
|
||||
for (auto* s : slotList)
|
||||
SSlot* pMinSlot = nullptr;
|
||||
for (auto* pSlot : slotList)
|
||||
{
|
||||
if (s->dwSlotNumber < pMin->dwSlotNumber)
|
||||
pMin = s;
|
||||
if (!pMinSlot)
|
||||
pMinSlot = pSlot;
|
||||
else if (pSlot->dwSlotNumber < pMinSlot->dwSlotNumber)
|
||||
pMinSlot = pSlot;
|
||||
else if (!pMinSlot->isItem && pSlot->isItem)
|
||||
pMinSlot = pSlot;
|
||||
}
|
||||
if (ppSlot) *ppSlot = pMin;
|
||||
|
||||
if (!pMinSlot)
|
||||
return FALSE;
|
||||
|
||||
SSlot* pCenterSlot;
|
||||
if (!GetSlotPointer(pMinSlot->dwCenterSlotNumber, &pCenterSlot))
|
||||
return FALSE;
|
||||
|
||||
*ppSlot = pCenterSlot;
|
||||
|
||||
if (UI::CWindowManager::Instance().GetAttachingSlotNumber() == pCenterSlot->dwSlotNumber)
|
||||
*ppSlot = pMinSlot;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -772,7 +772,7 @@ namespace UI
|
||||
void RestoreSlotCoolTime(DWORD dwKey);
|
||||
void ActivateSlot(DWORD dwIndex);
|
||||
void DeactivateSlot(DWORD dwIndex);
|
||||
void RefreshSlot() {}
|
||||
void RefreshSlot();
|
||||
DWORD GetSlotCount() { return (DWORD)m_slotMap.size(); }
|
||||
void LockSlot(DWORD dwIndex);
|
||||
void UnlockSlot(DWORD dwIndex);
|
||||
@@ -803,10 +803,33 @@ namespace UI
|
||||
|
||||
BOOL GetSlotPointer(DWORD dwIndex, SSlot** ppSlot);
|
||||
BOOL GetSelectedSlotPointer(SSlot** ppSlot);
|
||||
// The slot under the mouse (EterPythonLib/PythonSlotWindow.cpp GetPickedSlotPointer).
|
||||
virtual BOOL GetPickedSlotPointer(SSlot** ppSlot);
|
||||
|
||||
// Mouse events and their Python callbacks (EterPythonLib/PythonSlotWindow.cpp).
|
||||
BOOL OnMouseLeftButtonDown() override;
|
||||
BOOL OnMouseLeftButtonUp() override;
|
||||
BOOL OnMouseRightButtonDown() override;
|
||||
BOOL OnMouseLeftButtonDoubleClick() override;
|
||||
void OnMouseOverOut() override;
|
||||
void OnMouseOver() override;
|
||||
|
||||
void OnSelectEmptySlot(int iSlotNumber);
|
||||
void OnSelectItemSlot(int iSlotNumber);
|
||||
void OnUnselectEmptySlot(int iSlotNumber);
|
||||
void OnUnselectItemSlot(int iSlotNumber);
|
||||
void OnUseSlot();
|
||||
BOOL OnOverIn(DWORD dwSlotNumber);
|
||||
void OnOverOut();
|
||||
BOOL OnOverInItem(DWORD dwSlotNumber);
|
||||
void OnOverOutItem();
|
||||
|
||||
static constexpr DWORD SLOT_NUMBER_NONE = 0xffffffff;
|
||||
|
||||
protected:
|
||||
void OnRender() override;
|
||||
BOOL OnIsType(DWORD dwType) override;
|
||||
virtual void OnRefreshSlot() {}
|
||||
virtual void OnRenderPickingSlot();
|
||||
virtual void OnRenderSelectedSlot();
|
||||
void RenderSlotBaseImage();
|
||||
@@ -817,6 +840,8 @@ namespace UI
|
||||
DWORD m_dwSlotStyle;
|
||||
BOOL m_isUseMode;
|
||||
BOOL m_isUsableItem;
|
||||
DWORD m_dwToolTipSlotNumber = SLOT_NUMBER_NONE;
|
||||
DWORD m_dwOverInSlotNumber = SLOT_NUMBER_NONE;
|
||||
std::vector<DWORD> m_slots;
|
||||
std::vector<DWORD> m_dwSelectedSlotIndexList;
|
||||
std::map<DWORD, SSlot> m_slotMap;
|
||||
@@ -833,10 +858,17 @@ namespace UI
|
||||
virtual ~CGridSlotWindow();
|
||||
void ArrangeGridSlot(DWORD dwStartIndex, DWORD dwxCount, DWORD dwyCount, int ixSlotSize, int iySlotSize, int ixTemporarySize, int iyTemporarySize);
|
||||
BOOL GetPickedSlotList(BYTE byWidth, BYTE byHeight, std::vector<SSlot*>* pSlotList);
|
||||
BOOL GetPickedSlotPointer(SSlot** ppSlot);
|
||||
BOOL GetPickedSlotPointer(SSlot** ppSlot) override;
|
||||
BOOL CheckMoving(DWORD dwSlotNumber, DWORD dwItemIndex, const std::vector<SSlot*>& slotList);
|
||||
protected:
|
||||
void OnRenderPickingSlot() override;
|
||||
BOOL OnIsType(DWORD dwType) override;
|
||||
void OnRefreshSlot() override;
|
||||
BOOL GetGridSlotPointer(int ix, int iy, SSlot** ppSlot);
|
||||
BOOL GetPickedGridSlotPosition(int ixLocal, int iyLocal, int* pix, int* piy);
|
||||
|
||||
DWORD m_dwxCount = 0, m_dwyCount = 0;
|
||||
// Slot numbers by grid cell x + y * m_dwxCount (the original keeps slot pointers).
|
||||
std::vector<DWORD> m_SlotVector;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "PythonWindowManager.h"
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace UI
|
||||
{
|
||||
@@ -119,9 +120,16 @@ namespace UI
|
||||
ry = m_lMouseY;
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonWindowManager.cpp: dragging means the mouse moved 10 px (Manhattan)
|
||||
// since the left button went down; a click on a slot picks the item up instead of dropping it.
|
||||
BOOL CWindowManager::IsDragging()
|
||||
{
|
||||
return (m_pLeftCaptureWindow != nullptr);
|
||||
long ldx = std::labs(m_lMouseX - m_lPickedX);
|
||||
long ldy = std::labs(m_lMouseY - m_lPickedY);
|
||||
if (ldx + ldy < 10)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void CWindowManager::SetParent(CWindow * pWindow, CWindow * pParentWindow)
|
||||
@@ -361,10 +369,11 @@ namespace UI
|
||||
m_pPointWindow = pPointWindow;
|
||||
if (m_pPointWindow) m_pPointWindow->OnMouseOverIn();
|
||||
}
|
||||
else if (m_pPointWindow)
|
||||
{
|
||||
|
||||
// The original calls OnMouseOver on every move, also right after OnMouseOverIn (slot
|
||||
// windows show the tooltip of the slot under the mouse from it).
|
||||
if (m_pPointWindow)
|
||||
m_pPointWindow->OnMouseOver();
|
||||
}
|
||||
}
|
||||
|
||||
void CWindowManager::RunMouseLeftButtonDown(long x, long y)
|
||||
@@ -381,6 +390,8 @@ namespace UI
|
||||
|
||||
m_lDragX = m_lMouseX - pWin->GetRect().left;
|
||||
m_lDragY = m_lMouseY - pWin->GetRect().top;
|
||||
m_lPickedX = m_lMouseX;
|
||||
m_lPickedY = m_lMouseY;
|
||||
pWin->OnMouseLeftButtonDown();
|
||||
}
|
||||
|
||||
@@ -394,11 +405,11 @@ namespace UI
|
||||
m_pLeftCaptureWindow = nullptr;
|
||||
return;
|
||||
}
|
||||
m_pLeftCaptureWindow = nullptr;
|
||||
}
|
||||
|
||||
// The capture stays set while the window under the mouse gets the event: a slot window
|
||||
// there drops the dragged icon only while wndMgr.IsDragging()/capture hold (original).
|
||||
CWindow * pWin = __PickWindow(m_lMouseX, m_lMouseY);
|
||||
printf("DEBUG RunMouseLeftButtonUp: pos=(%ld, %ld) m_lMouse=(%ld, %ld) picked=%s\n", x, y, m_lMouseX, m_lMouseY, pWin ? pWin->GetName() : "null");
|
||||
if (!pWin) pWin = GetPointWindow();
|
||||
if (pWin)
|
||||
{
|
||||
@@ -416,16 +427,42 @@ namespace UI
|
||||
if (pWin) pWin->OnMouseLeftButtonDoubleClick();
|
||||
}
|
||||
|
||||
// EterPythonLib/PythonWindowManager.cpp: the right button captures like the left one, and
|
||||
// releasing it drops any attached icon.
|
||||
void CWindowManager::RunMouseRightButtonDown(long x, long y)
|
||||
{
|
||||
SetMousePosition(x, y);
|
||||
if (m_pPointWindow) m_pPointWindow->OnMouseRightButtonDown();
|
||||
CWindow * pWin = GetPointWindow();
|
||||
if (!pWin)
|
||||
return;
|
||||
|
||||
if (pWin->IsFlag(CWindow::FLAG_ATTACH))
|
||||
pWin = pWin->GetRoot();
|
||||
|
||||
if (!pWin->IsFlag(CWindow::FLAG_NOT_CAPTURE))
|
||||
m_pRightCaptureWindow = pWin;
|
||||
|
||||
pWin->OnMouseRightButtonDown();
|
||||
}
|
||||
|
||||
void CWindowManager::RunMouseRightButtonUp(long x, long y)
|
||||
{
|
||||
SetMousePosition(x, y);
|
||||
if (m_pPointWindow) m_pPointWindow->OnMouseRightButtonUp();
|
||||
if (m_pRightCaptureWindow)
|
||||
{
|
||||
if (m_pRightCaptureWindow->OnMouseRightButtonUp())
|
||||
{
|
||||
m_pRightCaptureWindow = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CWindow * pWin = GetPointWindow();
|
||||
if (pWin)
|
||||
pWin->OnMouseRightButtonUp();
|
||||
|
||||
m_pRightCaptureWindow = nullptr;
|
||||
DeattachIcon();
|
||||
}
|
||||
|
||||
void CWindowManager::RunMouseRightButtonDoubleClick(long x, long y)
|
||||
|
||||
@@ -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