walk.tin 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  5. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  6. */
  7. ///=== {
  8. ///// 小键盘和触屏走路模块允许玩家通过小键盘,或者点击屏幕上的不同区域来控制角色向不同方向移动。
  9. ///// 本模块对手机用户可能有一些帮助,也可满足喜欢小键盘的玩家诉求。
  10. /////
  11. ///// 对于手机用户来说,建议先通过 ui.walk.Guide 别名来学习虚拟按键的方位布局。
  12. /////
  13. ///// 需要特别说明的是,本模块会自动和地图系统进行集成。通过监测房间出口,会对键位做细微的调整。
  14. ///// 举例来说,如果东方只有一个 eastup 出口,那么 east/eastup/eastdown 三个键位
  15. ///// 的作用就都是 eastup,如果只有一个 eastdown 也一样。南、北、西三个方向同理。
  16. /////
  17. ///// 本模块加载后默认并不启用,你需要通过开启 PaoTin++ 全局选项来开启对应功能。
  18. ///// 目前有两个功能:
  19. ///// - KeypadWalk: 小键盘走路,默认已绑定到快捷键 <ctrl+o> <k>
  20. ///// - ScreenKeypad: 屏幕虚拟键盘走路,默认已绑定到快捷键 <ctrl+o> <K>
  21. /////
  22. ///// 你也可以在脚本中通过 option 标准方法 option.Toggle/Enable/Disable 来开启或关闭它们。
  23. ///// 请查阅 HELP option
  24. // };
  25. #var lib_ui_walk[META] {
  26. {NAME} {触屏和小键盘走路}
  27. {DESC} {支持鼠标和触摸屏操作,点击屏幕不同区域,可以进入不同出口}
  28. {AUTHOR} {担子炮}
  29. };
  30. option.Define {KeypadWalk} {Bool} {是否开启小键盘走路} {false};
  31. option.Define {ScreenKeypad} {Bool} {是否开启屏幕虚拟键盘} {false};
  32. #func {lib_ui_walk.Init} {
  33. event.Handle {option/changed} {option/changed/KeypadWalk} {lib/ui/walk} {ui.walk.Keypad.Setup};
  34. event.Handle {option/changed} {option/changed/ScreenKeypad} {lib/ui/walk} {ui.walk.ScreenKeypad.Setup};
  35. event.HandleOnce {user-online} {ui/walk/setup} {pkuxkx/online} {
  36. ui.walk.Keypad.Setup;
  37. ui.walk.ScreenKeypad.Setup;
  38. };
  39. #return {true};
  40. };
  41. #alias {ui.walk.setup} {
  42. #class ui.walk.mouse open;
  43. #event {SHORT-CLICKED MOUSE BUTTON ONE} {
  44. ui.walk.go @ui.walk.locate{%%0;%%1;left;short};
  45. };
  46. #event {SHORT-CLICKED MOUSE BUTTON THREE} {
  47. okLog 鼠标右击 @ui.walk.locate{%%0;%%1;right;short};
  48. };
  49. #event {LONG-CLICKED MOUSE BUTTON ONE} {
  50. okLog 鼠标长按 @ui.walk.locate{%%0;%%1;left;long};
  51. };
  52. #event {LONG-CLICKED MOUSE BUTTON THREE} {
  53. okLog 鼠标长右 @ui.walk.locate{%%0;%%1;right;long};
  54. };
  55. #class ui.walk.mouse close;
  56. };
  57. ///=== {
  58. // ## ui.walk.ScreenKeypad.Setup
  59. // 开启/关闭屏幕虚拟键盘走路。
  60. // 本别名没有参数。
  61. // };
  62. #alias {ui.walk.ScreenKeypad.Setup} {
  63. #if { @option.IsDisable{ScreenKeypad} } {
  64. #class ui.walk.mouse kill;
  65. errLog 屏幕虚拟键盘走路已关闭。;
  66. };
  67. #else {
  68. ui.walk.setup;
  69. okLog 屏幕虚拟键盘走路已开启。;
  70. };
  71. };
  72. ///=== {
  73. // ## ui.walk.Guide
  74. // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
  75. // 本别名没有参数。
  76. // };
  77. #alias {ui.walk.Guide} {
  78. #local height {};
  79. #local width {};
  80. #screen get rows height;
  81. #screen get cols width;
  82. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
  83. #screen clear scroll;
  84. #local top {@math.Eval{$height / 4}};
  85. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  86. #local left {@math.Eval{$width / 4}};
  87. #local right {@math.Eval{$width * 3 / 4 + 1}};
  88. #local vmid {@math.Eval{$width / 2}};
  89. #local hmid {@math.Eval{$height / 2}};
  90. #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
  91. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
  92. #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
  93. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
  94. #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
  95. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
  96. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
  97. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
  98. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
  99. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
  100. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
  101. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
  102. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
  103. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
  104. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
  105. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
  106. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
  107. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
  108. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
  109. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
  110. #buffer lock on;
  111. #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
  112. };
  113. #func {ui.walk.locate} {
  114. #local row {%1};
  115. #local col {%2};
  116. #local button {%3};
  117. #local long {%4};
  118. #local height {};
  119. #local width {};
  120. #screen get rows height;
  121. #screen get cols width;
  122. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
  123. #local top {@math.Eval{$height / 4}};
  124. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  125. #local left {@math.Eval{$width / 4}};
  126. #local right {@math.Eval{$width * 3 / 4 + 1}};
  127. #local vmid {@math.Eval{$width / 2}};
  128. #local hmid {@math.Eval{$height / 2}};
  129. #local dir {};
  130. #if { $row <= $top } {
  131. #cat dir {north};
  132. };
  133. #elseif { $row >= $bot } {
  134. #cat dir {south};
  135. };
  136. #if { $col <= $left } {
  137. #cat dir {west};
  138. };
  139. #elseif { $col >= $right } {
  140. #cat dir {east};
  141. };
  142. #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
  143. #if { "$dir" == "{north|south}" } {
  144. #if { @sset.Size{$real} == 1 } {
  145. #local dir {$real};
  146. };
  147. #else {
  148. #if { $col <= $left * 5 / 3 } {
  149. #cat dir {up};
  150. };
  151. #elseif { $col > $left * 7 / 3 } {
  152. #cat dir {down};
  153. };
  154. };
  155. };
  156. #elseif { "$dir" == "{east|west}" } {
  157. #if { @sset.Size{$real} == 1 } {
  158. #local dir {$real};
  159. };
  160. #else {
  161. #if { $row <= $top * 5 / 3 } {
  162. #cat dir {up};
  163. };
  164. #elseif { $row > $top * 7 / 3 } {
  165. #cat dir {down};
  166. };
  167. };
  168. };
  169. #if { "$dir" == "" } {
  170. #if { $col <= $vmid } {
  171. #local dir {@if{$row <= $hmid; enter; out}};
  172. };
  173. #else {
  174. #local dir {@if{$row <= $hmid; up; down}};
  175. };
  176. };
  177. #return {$dir};
  178. };
  179. VAR {触屏走路插件的走路命令,默认为 go} ui.walk.cmd {go};
  180. ///=== {
  181. // ## ui.walk.SetCmd <触屏走路命令>
  182. // 设置触屏走路时所用的命令,默认为 go。
  183. // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
  184. // };
  185. #alias {ui.walk.SetCmd} {
  186. #var ui.walk.cmd {%1};
  187. };
  188. #alias {ui.walk.go} {
  189. #local dir {%1};
  190. $ui.walk.cmd $dir;
  191. };
  192. #alias {ui.walk.Keypad.Setup} {
  193. #if { @option.IsDisable{KeypadWalk} } {
  194. #class ui.walk.Keypad kill;
  195. errLog 小键盘走路已关闭。;
  196. };
  197. #else {
  198. #class ui.walk.Keypad open;
  199. #local idx {};
  200. #foreach {*global-keypad-walking[]} {idx} {
  201. #local entry {$global-keypad-walking[$idx]};
  202. #local name {$entry[key]};
  203. #local type {$entry[type]};
  204. #local args {$entry[args]};
  205. #if { &global-keypad-code[$name] == 0 } {
  206. #continue;
  207. };
  208. #local code {$global-keypad-code[$name]};
  209. #line sub var #macro {$code} {ui.walk.keypad.do $name $type {$args}};
  210. };
  211. #class ui.walk.Keypad close;
  212. okLog 小键盘走路已开启。;
  213. };
  214. };
  215. ///=== {
  216. // ## ui.walk.Keypad.Bind <键名> <功能类型> <参数>
  217. // 为快捷键绑定功能。
  218. // 参数说明:
  219. // 键名:注意这里用的是键名,完整的键名列表可以通过 #var global-keypad-code 查看。
  220. // 功能类型目前就两种:
  221. // - dir: 方向指令。方向指令会根据当前行走模式转换成不同的命令。默认模式是 go,
  222. // 护镖或其它任务需要自行设置,请参考 HELP ui.walk.SetCmd
  223. // - cmd: 普通命令。可以是本地别名,或者服务器指令。
  224. // 参数:如果是方向指令,则应该是英文的方向全称。允许指定多个候选,以分号分隔。
  225. // 如果是普通命令,则只允许一条命令,如果功能复杂建议单独设置一个别名,在这里写别名名称。
  226. // };
  227. #alias {ui.walk.Keypad.Bind} {
  228. #local name {%1};
  229. #local type {%2};
  230. #local args {%3};
  231. #if { "$name" == "" || "$type" != "{dir|cmd}" || "$args" == "" } {
  232. xtt.Usage %90;
  233. #return;
  234. };
  235. #if { &global-keypad-code[$name] == 0 } {
  236. xtt.Usage %90;
  237. #return;
  238. };
  239. #list global-keypad-walking {indexate} key;
  240. #local idx {};
  241. #list global-keypad-walking {find} {$name} idx;
  242. #if { $idx == 0 } {
  243. #list global-keypad-walking {add} {{
  244. {key} {$name}
  245. {type} {$type}
  246. {args} {$args}
  247. }};
  248. };
  249. #else {
  250. #var {global-keypad-walking[$idx]} {
  251. {key} {$name}
  252. {type} {$type}
  253. {args} {$args}
  254. };
  255. };
  256. okLog 已绑定快捷键 $name 为 {$type} {$args};
  257. };
  258. ///=== {
  259. // ## ui.walk.Keypad.UnBind <键名>
  260. // 删除快捷键绑定的功能。
  261. // };
  262. #alias {ui.walk.Keypad.UnBind} {
  263. #local name {%1};
  264. #if { "$name" == "" } {
  265. xtt.Usage %90;
  266. #return;
  267. };
  268. #if { &global-keypad-code[$name] == 0 } {
  269. xtt.Usage %90;
  270. #return;
  271. };
  272. #list global-keypad-walking {indexate} key;
  273. #local idx {};
  274. #list global-keypad-walking {find} {$name} idx;
  275. #if { $idx > 0 } {
  276. #list global-keypad-walking {delete} {$idx};
  277. okLog 快捷键 $name 功能已删除。;
  278. };
  279. };
  280. #alias {ui.walk.keypad.do} {
  281. #local key {%1};
  282. #local type {%2};
  283. #local args {%3};
  284. #if { "$key" == "Enter" } {
  285. #local input {};
  286. #cursor get input;
  287. #if { {$input} !== {} } {
  288. #cursor clear;
  289. $input;
  290. #return;
  291. };
  292. #elseif { "$gMapRoom[dock]" == "dock" } {
  293. map.YellBoat;
  294. #return;
  295. };
  296. #elseif { "$gMapRoom[dock]" == "ride" } {
  297. map.Ride;
  298. #return;
  299. };
  300. };
  301. #if { "$type" == "cmd" } {
  302. $args;
  303. #return;
  304. };
  305. #local dir {};
  306. #foreach {$args} {dir} {
  307. #if { @sset.Contains{{$gMapRoom[exits]};$dir} } {
  308. ui.walk.go $dir;
  309. #return;
  310. };
  311. };
  312. };