#include "dm_touch_controls.h" #include "../../host/dm_input.h" #include #include #include static int checks; #define CHECK(x) do { ++checks; if (!(x)) { fprintf(stderr,"FAIL line=%d %s\n",__LINE__,#x); exit(1); } } while (0) static void begin(dm_tc_state *s,int n,int target) { dm_tc_begin(s,n,s->layout.target[target].x,s->layout.target[target].y); if(target>=DM_TC_MAIN && target<=DM_TC_SKILL4) dm_tc_tick(s,s->last_time_s+0.1); /* 主钮 / 技能钮按下后有判定时间(点按还是拖动),这里的「按下」= 已过判定时间 | After the main button / a skill button is pressed there is a decision time (tap or drag); here "pressed" = the decision time has passed */ } static void drag(dm_tc_state *s,int n,int target,float dx,float dy) { dm_tc_move(s,n,s->layout.target[target].x+dx,s->layout.target[target].y+dy); } int main(void) { dm_tc_state s; dm_tc_init(&s,667,375); CHECK(s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && !s.navigation_mode && !s.map_cancel_active); begin(&s,0,DM_TC_MAIN); CHECK(s.buttons==DM_BTN_A && s.rx==0 && s.ry==0); drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.rx==32767 && s.ry==0 && s.aim_slot==0); drag(&s,0,DM_TC_MAIN,0,60); CHECK(s.rx==0 && s.ry==-32767); drag(&s,0,DM_TC_MAIN,30,-30); CHECK(s.rx==16384 && s.ry==16384); drag(&s,0,DM_TC_MAIN,120,-120); CHECK(s.rx==32767 && s.ry==32767); drag(&s,0,DM_TC_MAIN,0,0); CHECK(s.rx==0 && s.ry==0 && s.aim_slot==0); dm_tc_begin(&s,1,90,275); dm_tc_move(&s,1,150,275); drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.lx==32767 && s.ly==0 && s.rx==32767 && s.ry==0); /* 技能钮与主钮同一套:按下即键下、按住 = 持续施放,后拖动的那根手指定方向,松手键起、不发脉冲 | On-screen skill buttons use the same scheme as the main button: key down on press, hold = continuous cast, the finger that dragged later sets the direction, on release the key goes up, no pulse sent */ begin(&s,2,DM_TC_SKILL1); CHECK(s.buttons==(DM_BTN_A|DM_BTN_B)); drag(&s,2,DM_TC_SKILL1,0,60); CHECK(s.lx==32767 && s.rx==0 && s.ry==-32767 && s.aim_slot==2 && s.buttons==(DM_BTN_A|DM_BTN_B)); dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,2); CHECK(s.buttons==DM_BTN_A && s.rx==32767 && s.ry==0 && s.aim_slot==0 && !s.pulse_button); /* 键已按住够久:松手键起,不补脉冲 | The key has been held long enough: on release the key goes up, no make-up pulse */ begin(&s,2,DM_TC_MAIN); dm_tc_target map=s.layout.target[DM_TC_MAP]; dm_tc_move(&s,2,map.x+map.r,map.y-map.r); CHECK(s.map_cancel_active && s.buttons==DM_BTN_A && s.rx==32767 && s.lx==32767); dm_tc_move(&s,2,map.x-map.r-1,map.y); CHECK(!s.map_cancel_active && s.buttons==DM_BTN_A && s.aim_slot==0); dm_tc_end(&s,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && s.lx==32767); drag(&s,2,DM_TC_MAIN,60,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0); dm_tc_end(&s,2); CHECK(!s.map_cancel_active); begin(&s,0,DM_TC_SKILL2); drag(&s,0,DM_TC_SKILL2,60,0); dm_tc_move(&s,0,map.x,map.y); CHECK(s.map_cancel_active && s.buttons==0 && s.rx==0 && s.ry==0 && s.lx==32767); dm_tc_end(&s,0); CHECK(!s.map_cancel_active && s.lx==32767 && s.buttons==0 && !s.pulse_button); /* 取消区松手不放 | Releasing in the cancel zone does not cast */ begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,60,0); dm_tc_set_navigation_mode(&s,1); CHECK(s.navigation_mode && s.buttons==0 && s.lx==0 && s.rx==0 && s.ry==0); begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,60,0); CHECK(s.buttons==DM_BTN_A && s.rx==0 && s.ry==0); dm_tc_move(&s,0,map.x,map.y); CHECK(!s.map_cancel_active && s.buttons==DM_BTN_A); dm_tc_set_navigation_mode(&s,1); CHECK(s.buttons==DM_BTN_A); /* identical mode does not cancel */ dm_tc_set_navigation_mode(&s,0); CHECK(!s.navigation_mode && s.buttons==0 && s.rx==0 && s.ry==0); begin(&s,0,DM_TC_SKILL3); drag(&s,0,DM_TC_SKILL3,-60,0); CHECK(s.buttons==DM_BTN_Y && s.rx==-32767 && s.ry==0); /* 按住技能钮拖动:键一直按着,朝拖动方向 | Hold an on-screen skill button and drag: the key stays down, facing the drag direction */ dm_tc_move(&s,0,NAN,0); CHECK(s.buttons==DM_BTN_Y && s.rx==-32767); dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,0); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && !s.pulse_button); /* 坏坐标不动;松手键起 | Bad coordinates do nothing; on release the key goes up */ dm_tc_cancel_all(&s); CHECK(s.buttons==0 && s.rx==0 && s.ry==0 && s.aim_slot==DM_TC_NONE && !s.map_cancel_active && !s.pulse_button); begin(&s,0,DM_TC_SKILL4); drag(&s,0,DM_TC_SKILL4,5,-5); CHECK(s.buttons==DM_BTN_R && s.rx==0 && s.ry==0); /* 拖动不过 10 点死区 = 点按:不给方向,原版自动选目标 | A drag that does not pass the 10-point dead zone = a tap: no direction given, the original game auto-selects the target */ dm_tc_tick(&s,s.last_time_s+0.1); dm_tc_end(&s,0); CHECK(s.buttons==0); begin(&s,0,DM_TC_SKILL4); drag(&s,0,DM_TC_SKILL4,0,-60); dm_tc_resize(&s,333.5f,187.5f); CHECK(s.rx==0 && s.ry==0 && s.buttons==0 && s.aim_slot==DM_TC_NONE && !s.pulse_button); begin(&s,0,DM_TC_MAIN); drag(&s,0,DM_TC_MAIN,15,-15); CHECK(s.rx==16384 && s.ry==16384); dm_tc_enable_targets(&s,0); CHECK(s.rx==0 && s.ry==0 && s.buttons==0); dm_tc_enable_targets(&s,(1u<