#pragma once #include #ifdef __cplusplus extern "C" { #endif enum { DM_TC_MAX_TOUCH = 16, DM_TC_COUNT = 12 }; enum { DM_TC_NONE = -1, DM_TC_JOYSTICK = -2, DM_TC_SWAP = -3, DM_TC_DIFF = -4, /* DIFF:难度格 / 选择条占用的手指,不发按键 | DIFF: a finger captured by the difficulty cell / selector bar; sends no key */ DM_TC_EDGE = -5, /* 屏幕底边归系统的那一条里起手的手指:不当摇杆,松手也不当点地 | A finger that started in the strip along the bottom edge of the screen that belongs to the system: not treated as the stick, and its release is not treated as a ground tap */ DM_TC_MAIN = 0, DM_TC_SKILL1, DM_TC_SKILL2, DM_TC_SKILL3, DM_TC_SKILL4, DM_TC_PORTAL, DM_TC_BELT1, DM_TC_BELT2, DM_TC_BELT3, DM_TC_BELT4, DM_TC_MENU, DM_TC_MAP }; typedef struct { float x, y, r; uint64_t button; } dm_tc_target; typedef struct { float width, height; dm_tc_target target[DM_TC_COUNT]; float joy_x, joy_y, joy_radius; dm_tc_target swap; /* 技能组切换键:本地开关,不直接发按键 | Skill set switch key: a local toggle; does not send a key directly */ dm_tc_target diff; /* 底部 UI v4 第 0 格难度:点开 / 收起 1–8 选择条,不发按键 | Bottom UI v4 cell 0 difficulty: tap to open / collapse the 1–8 selector bar; sends no key */ dm_tc_target pick[8]; /* 选择条 8 格(第 i 格 = 人数档 i+1),在七格上方 | The selector bar's 8 cells (cell i = player-count level i+1), above the seven cells */ } dm_tc_layout; typedef struct { int active, target; float x, y; float aim_origin_x, aim_origin_y; uint64_t aim_move_sequence; int aim_cancelled; int key_down; double key_down_s; /* 技能钮:键是否已按下过、几时按下的(按下后先等判定时间,见 update) | Skill button: whether the key has gone down and when (after press, first wait the decision time, see update) */ double start_time_s; int pointer_dragged, pointer_long; /* 界面连续手势(鼠标点击模式、起手不在物品区也不在面板外、位移过阈值时按起始方向定型,定型后不变):1 = 纵向拖(滚动),2 = 横向拖(滑块)。 手势层只定型,前端看到后把起手点与当前点转给宿主(dm_ui_drag_*),滚动 / 滑块由宿主按游戏自己的命中去做 Continuous UI gesture (mouse click mode, started neither in the item area nor outside the panel; when displacement crosses the threshold the type is fixed by the initial direction and does not change afterwards): 1 = vertical drag (scroll), 2 = horizontal drag (slider). The gesture layer only fixes the type; on seeing it the front end forwards the start point and current point to the host (dm_ui_drag_*), and the scroll / slider is done by the host according to the game's own hit testing */ int ui_drag; int shop_drag; /* 从商人货架的货上起拖(不拿起):松手按落点买 / 不买 | Drag starting from goods on the vendor shelf (not picked up): on release, buy / do not buy by the drop point */ int locked_drag; /* 单件任务槽占用时从别的物品上起拖:不拿起,松手不发任何键 | Drag starting from another item while the single-item quest slot is occupied: do not pick up, and send no key on release */ } dm_tc_finger; typedef struct { dm_tc_layout layout; dm_tc_finger finger[DM_TC_MAX_TOUCH]; int joy_slot; float joy_origin_x, joy_origin_y; uint32_t enabled_targets; uint64_t buttons; int32_t lx, ly, rx, ry; int aim_slot, navigation_mode, map_cancel_active; uint64_t aim_move_sequence; int portal_pending, portal_phase; // 0idle / 1modifier-pending / 2armed uint64_t gesture_epoch, portal_binding_identity, portal_scene_epoch; /* 松手施放的短按脉冲:按键与右轴方向同时发布,前端到时调 dm_tc_pulse_end 收回 | Short-press pulse for release-to-cast: the key and the right-axis direction are published together, and the front end calls dm_tc_pulse_end to release it when due */ uint64_t pulse_button, pulse_epoch; int32_t pulse_rx, pulse_ry; uint64_t defer_button; double defer_at_s; /* 第二组里点得太短的那一下:等 ZL 领先够了再补发 | The too-short tap in the second set: make it up once ZL has led long enough */ /* 技能组:0 = 第一套;1 = 第二套(原版 Switch 按住 ZL 用 alt 槽)。是模式,不随取消/尺寸变化清零 | Skill set: 0 = first set; 1 = second set (on the original Switch game, holding ZL uses the alt slots). It is a mode and is not cleared on cancel/size change */ int skill_set; /* 第二组技能(ZL 修饰):ZL 只在手指按着主钮 / 技能钮、或技能脉冲在发时按着,且先于技能键 DM_TC_ZL_LEAD_S 按下。 松手施放按得太短时,这一下脉冲延到 ZL 领先够了再发(dm_tc_tick 到点起)。 Second skill set (ZL modifier): ZL is held only while a finger is on the main button / a skill button or a skill pulse is being sent, and goes down DM_TC_ZL_LEAD_S before the skill button. When a release-to-cast press is too short, that pulse is delayed until ZL has led long enough (dm_tc_tick starts it when due). */ int pointer_slot; double last_time_s; int pointer_pickup_done; int pointer_pulse_active, pointer_pulse_pending; float pointer_pending_x, pointer_pending_y; int pointer_valid; float pointer_x, pointer_y; /* 物品手势:pointer_item = 当前指针手指落在物品区(前端在松手前按宿主命中结果置位)。物品区单击只移光标(出说明)、 双击 = 按住 A(游戏提示:按住 = 打开 / 使用 / 装备;开着箱子时按住 Y = 移到另一侧);非物品区单击照旧 = 移光标 + 按 A。 pulse_hold_s > 0 = 这个脉冲要按住这么久,前端在「游戏已取走」之外再等满它才收 Item gestures: pointer_item = the current pointer finger landed in the item area (set by the front end before release from the host's hit result). A single tap in the item area only moves the cursor (shows the tooltip), double tap = hold A (game hint: hold = open / use / equip; with the stash open, hold Y = move to the other side); a single tap outside the item area is as before = move the cursor + press A. pulse_hold_s > 0 = this pulse must be held this long, and the front end waits it out in full in addition to "the game has consumed it" before releasing */ int pointer_item; /* 非物品区的点按走鼠标点击(暂停菜单按钮、布局里插回的关闭 / 修理等按钮只认鼠标):mouse_click_mode 由前端打开; 每次这样的点按 mouse_click_seq 加一,前端看到变化就在 (mouse_click_x, mouse_click_y) 发一次界面鼠标点击,不再按 A Taps outside the item area go through mouse clicks (pause menu buttons and the close / repair buttons inserted back into the layout only respond to the mouse): mouse_click_mode is turned on by the front end; each such tap increments mouse_click_seq, and on seeing a change the front end sends one UI mouse click at (mouse_click_x, mouse_click_y) and no longer presses A */ /* 拖放松手处(物品抬在手指上方的那个落点)是不是物品区:前端松手前置位。不是 = 拖到面板外 = 丢弃(指针回原处、到位后按 Y)。 holding = 光标上还拿着物品(上一次没放成):这时点物品区 = 放下(A),点别处不动 Whether the drag-and-drop release spot (the drop point where the item is lifted above the finger) is the item area: set by the front end before release. If not = dragged outside the panel = discard (pointer returns to the original spot and presses Y once in place). holding = the cursor is still holding an item (the last drop did not succeed): then tapping the item area = put down (A), tapping elsewhere does nothing */ int pointer_release_item, holding; float release_x, release_y; /* 游戏态(没开面板)的点按 = 点游戏世界:手指没落在任何控件目标上(含落在摇杆区但没拖动)、按下到抬起不到 0.35 秒、位移不超过点按阈值 → world_tap_seq 加一,前端看到变化调宿主 dm_world_tap(点物品名拾取 / 点 NPC 对话 / 点箱子,点空地什么都不发)。 A tap in game state (no panel open) = tap the game world: the finger did not land on any widget target (including landing in the stick area without dragging), less than 0.35 seconds from press to lift, displacement within the tap threshold → world_tap_seq is incremented, and on seeing a change the front end calls the host's dm_world_tap (tap an item name to pick up / tap an NPC to talk / tap a chest; tapping empty ground sends nothing). */ unsigned world_tap_seq; float world_tap_x, world_tap_y; int close_left; double close_next_s; /* 面板外点按后还要按几下 B、下一下最早什么时候(按到面板关掉为止) | After a tap outside the panel, how many more B presses remain and the earliest time of the next one (press until the panel is closed) */ /* 商人页:这次按下落在货架的货上(前端按宿主命中结果 7 置位)。从货上起拖 = 想买:不发「拿起」、光标留在那件货上(宿主买的是光标选中的那件); 松手时 shop_drop_seq 加一,前端按落点决定——落在背包类物品区 = 买,拖回货架 / 面板外 / 别处 = 不买 Vendor page: this press landed on goods on the shelf (set by the front end on host hit result 7). A drag starting from goods = intent to buy: do not send "pick up", and the cursor stays on that item (the host buys the item the cursor has selected); on release shop_drop_seq is incremented and the front end decides by the drop point -- landing in an inventory-type item area = buy; dragged back to the shelf / outside the panel / elsewhere = do not buy */ int pointer_shop; unsigned shop_drop_seq; int pointer_lock; /* 单件任务槽里有东西时按在别的物品上(宿主命中结果 10):照物品区移光标出说明,但不拿起、双击 / 长按 / 单击都不动它,也不把槽里那件放过来 | Pressing on another item while the single-item quest slot holds something (host hit result 10): move the cursor and show the tooltip as in the item area, but do not pick it up; double tap / long press / single tap do not move it, and the item in the slot is not placed here either */ /* 高级仓库的成叠格(前端按宿主命中结果 8 置位):别的都照物品区,只有双击不同——stack_take_seq 加一,前端调宿主 dm_stash_take(1) 取 1 件到背包 | Stacked cell of the advanced stash (set by the front end on host hit result 8): everything else follows the item area, only double tap differs -- stack_take_seq is incremented and the front end calls the host's dm_stash_take(1) to take 1 into the inventory */ int pointer_stack; unsigned stack_take_seq; unsigned ident_seq; /* 物品区双击了一件未鉴定物品的次数(只有未鉴定时双击 = 免费鉴定,各页都先判这一条):前端看到变化调宿主 dm_ui_identify_hovered | Number of double taps on an unidentified item in the item area (only when unidentified does double tap = free identify, and this rule is checked first on every page): on seeing a change the front end calls the host's dm_ui_identify_hovered */ unsigned use_seq; /* 物品区双击的次数(没开箱子时):前端看到变化调宿主 dm_ui_use_item——按光标下物品走原生的使用 / 购买 / 装备,不等「按住 A」的门槛 | Number of double taps in the item area (when no stash is open): on seeing a change the front end calls the host's dm_ui_use_item -- performs the native use / buy / equip on the item under the cursor without waiting for the "hold A" threshold */ unsigned item_tap_seq; /* 物品区单击的次数(前端看到变化调宿主 dm_ui_item_tap:鉴定态下单击物品 = 鉴定它) | Number of single taps in the item area (on seeing a change the front end calls the host's dm_ui_item_tap: in identify state, single-tapping an item = identify it) */ unsigned long_press_seq; /* 物品区按住不动满长按时长的次数(前端看到变化调宿主 dm_ui_long_press:背包药水 → 腰带) | Number of times the item area was held still for the full long-press duration (on seeing a change the front end calls the host's dm_ui_long_press: inventory potion → belt) */ unsigned tab_tap_seq; /* 点按落在页签上的次数(前端看到变化调宿主 dm_ui_tab_go) | Number of taps that landed on a tab (on seeing a change the front end calls the host's dm_ui_tab_go) */ int mouse_click_mode; unsigned mouse_click_seq; float mouse_click_x, mouse_click_y; /* 前端临时改写「面板内非物品区的点按」:非 0 = 不发鼠标点击,改成手柄光标走到触点、到位后按这个键(技能绑定流程里点技能 = 光标到它身上按 Y)。页签 / 面板外照旧 | Temporary front-end rewrite of "taps inside a panel outside the item area": non-zero = send no mouse click; instead the controller cursor walks to the touch point and presses this key on arrival (tapping a skill in the skill binding flow = cursor onto it and press Y). Tabs / outside the panel behave as before */ uint64_t tap_button; float tap_x, tap_y; int tap_move; unsigned tap_move_seq; /* tap_move:本次点按只把光标移到 tap_x / tap_y,不发点击(技能图标 / 属性「+」:先选中、再确认) | tap_move: this tap only moves the cursor to tap_x / tap_y and sends no click (skill icon / attribute "+": select first, then confirm) */ double pulse_hold_s; double last_tap_s; float last_tap_x, last_tap_y; double stash_x_check_s; float stash_x_x, stash_x_y; unsigned stash_x_id; /* 开着箱子双击背包物品先发了 X:到这个时刻那件还在光标下(游戏没收这下 X)就退回按住 Y | With the stash open, double-tapping an inventory item sent X first: if at this time the item is still under the cursor (the game did not accept that X), fall back to hold Y */ uint64_t pointer_pending_button; double pointer_pending_hold; /* 难度:diff_open = 选择条展开;diff_request = 刚选中的人数档(1–8),前端交给宿主 dm_hud_request_players 后清零 | Difficulty: diff_open = selector bar expanded; diff_request = the player-count level just selected (1–8), cleared after the front end hands it to the host's dm_hud_request_players */ int diff_open, diff_request; /* 腰带展开(原版键鼠「显示腰带」的那几排,手柄版没有入口):身上的腰带多于 1 排时,在腰带格上向上滑 = 展开、向下滑 / 点别处 = 收起, 展开后点上面几排的药 = 喝。belt_rows / belt_open 由前端每次触摸前按宿主读数写入;belt_request 前端取走后清零: 1 展开,2 收起,0x100 | 排 << 4 | 列 = 喝那一格(排 1–3 = 底排之上第几排) Belt expansion (the rows of the original game's keyboard-and-mouse "show belt"; the controller version has no entry for it): when the worn belt has more than 1 row, swiping up on a belt cell = expand, swiping down / tapping elsewhere = collapse, and after expansion tapping a potion in the upper rows = drink. belt_rows / belt_open are written by the front end from host readings before each touch; belt_request is cleared after the front end takes it: 1 expand, 2 collapse, 0x100 | row << 4 | column = drink that cell (row 1–3 = which row above the bottom row) */ int belt_rows, belt_open, belt_request; /* 腰带点一下 = 自己喝,松手那一刻就喝,点几下喝几瓶;不判双击、腰带上不做喂雇佣兵的手势 | one tap on the belt = the player drinks, at the moment of release, several taps drink several; no double-tap detection, no mercenary feeding gesture on the belt */ int belt_gap_cell; double belt_gap_at; /* 按着第二组技能时要喝药:先把 ZL 和技能键松开、空出 DM_TC_ZL_LEAD_S,到 belt_gap_at 才按腰带键(belt_gap_cell = 等着的那一格,0 = 没有) | to drink a potion while a skill of the second skill set is held: first release ZL and the skill key and leave a gap of DM_TC_ZL_LEAD_S, and only at belt_gap_at press the belt key (belt_gap_cell = the cell that is waiting, 0 = none) */ double joy_lost_s; float joy_lost_x, joy_lost_y; /* 摇杆手指被系统取消的时刻与当时的位置(0 = 没有):紧接着在附近重新落下的手指接着当摇杆 | time and position at which the joystick finger was cancelled by the system (0 = none): a finger landing again nearby right afterwards continues as the joystick */ int joy_block; /* 讲话文字框单独开着(前端不进面板态):这时落在底座上的手指不起摇杆,照旧只当一次点击(关讲话框)。前端按面板栈写 | speech text box open on its own (the front end does not enter panel state): a finger on the base starts no stick and is still just one click (closes the speech box). Written by the front end from the panel stack */ double belt_pulse_s; /* 最近一次「给玩家喝」的腰带脉冲还在发的时刻:其间按着的第二组技能连同 ZL 一起让开,收回后 ZL 重新领先 DM_TC_ZL_LEAD_S 技能键才回来 | Time until which the most recent "player drinks" belt pulse is still being sent: during it the held second-set skill gives way together with ZL, and after the release ZL again leads by DM_TC_ZL_LEAD_S before the skill key comes back */ int belt_q; /* 此刻有别的脉冲在发 / 别的补发在等:排着,空了再落地(不互相盖掉)。值 = 格 | another pulse is being sent / another resend is pending: queue and fire when free (they never overwrite each other). Value = cell */ } dm_tc_state; /* 原版UI消息驱动,不根据输入键猜面板。AutoMap是战斗叠加,不切导航。 | Driven by the original game's UI messages; panels are not guessed from input keys. AutoMap is a combat overlay and does not switch to navigation. */ typedef struct { int game; uint64_t panels; } dm_tc_scene; int dm_tc_navigation(dm_tc_scene *scene, const char *cat, const char *act, const char *arg); int dm_tc_scene_dialog_only(const dm_tc_scene *scene); /* 只开着 NPC 对话菜单 | Only the NPC dialog menu is open */ int dm_tc_scene_dead(void); /* 死亡弹窗开着(导航态,但不给手柄圆钮) | Death popup open (navigation state, but no controller round buttons) */ /* 坐标使用 UIKit 点;布局本身不画球、不声称游戏已绑定回城/腰带。 | Coordinates use UIKit points; the layout itself does not draw the orbs and does not claim the game has bound town portal/belt. */ /* 安全区左右内缩(点);在 init / resize 之前设,之后的布局按它把右侧技能键组与左摇杆移进安全区。缺省 0。 | Left/right safe-area insets (points); set before init / resize, and the layout afterwards uses them to move the right-side skill key group and the left stick into the safe area. Default 0. */ void dm_tc_set_safe_insets(float left, float right); void dm_tc_set_edge_bottom(float bottom); /* 屏幕底边归系统的那一条的高度(点);0 = 没有。只约束移动摇杆的起手 | Height (points) of the strip along the bottom edge of the screen that belongs to the system; 0 = none. Constrains only where the movement stick may start */ void dm_tc_layout_make(dm_tc_layout *layout, float width, float height); int dm_tc_hit(const dm_tc_layout *layout, float x, float y); #define DM_TC_POINTER_LIFT_PT 40.0f // 功能页拖动时物品抬在手指上方的点数(× 控件缩放) | Number of points the item is lifted above the finger while dragging on function pages (× widget scale) void dm_tc_set_tall_scale(int on); // 画面高 > 440 点时按 高/440 放大的开关;缺省关(Mac 宿主触屏用例传的是像素数,不能放大),iOS 前端建视图时开 | Switch for scaling up by height/440 when picture height > 440 points; default off (the Mac host touch test cases pass pixel counts and must not be scaled up); the iOS front end turns it on when creating the view float dm_tc_scale_for_size(float width, float height); // 控件缩放:手机 min(1, 宽/667, 高/375);画面高 > 440 点(iPad)时按 高/440 等比放大 | Widget scale: phone min(1, width/667, height/375); when picture height > 440 points (iPad), scale up proportionally by height/440 void dm_tc_init(dm_tc_state *state, float width, float height); /* 尺寸变更会取消全部触点,调用者随后推送归零状态。 | A size change cancels all touch points, and the caller then pushes the zeroed state. */ void dm_tc_resize(dm_tc_state *state, float width, float height); /* 控件开关不改变布局;切换有效位时取消已有触点。 | Widget switches do not change the layout; existing touch points are cancelled when the valid bits are toggled. */ void dm_tc_enable_targets(dm_tc_state *state, uint32_t mask); /* 导航模式(面板 / 对话 / 前端页开着)下可用的控件:右侧五个虚拟手柄圆钮(确认 / 返回 / 操作 / 绑定 / 下一页 = A B X Y R)。 底栏十字位置的「关闭」不再给:面板的关闭入口只留一个(外框右上角的关闭按钮;圆钮还在时另有「返回」)。 pad = 0:五个圆钮也不给(局内手指直接点界面接上之后用,开关 DM_TOUCH_NAV_PAD=0,缺省 1)。两个前端共用这一处,不各写各的。 Widgets available in navigation mode (a panel / dialog / front-end page is open): the five virtual controller round buttons on the right (confirm / back / action / bind / next page = A B X Y R). The "close" at the bottom bar's cross position is no longer offered: only one close entry for panels remains (the close button at the top-right corner of the frame; while the round buttons are present there is also "back"). pad = 0: the five round buttons are not offered either (used once in-run fingers tapping the UI directly is hooked up; switch DM_TOUCH_NAV_PAD=0, default 1). Both front ends share this one place and do not each write their own. */ static inline uint32_t dm_tc_nav_mask(int pad) { return pad ? ((1u<