walk.tin 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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} {opt/KeypadWalk/main} {lib/ui/walk} {ui.walk.Keypad.Setup};
  34. event.Handle {option/changed} {opt/ScreenKeypad/main} {lib/ui/walk} {ui.walk.ScreenKeypad.Setup};
  35. event.HandleOnce {user-online} {ui/walk/setup} {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. prompt.Set {{screenKeypad}{}};
  66. errLog 屏幕虚拟键盘走路已关闭。;
  67. };
  68. #else {
  69. prompt.Set {{screenKeypad}{<129>已开启<299>}};
  70. ui.walk.setup;
  71. okLog 屏幕虚拟键盘走路已开启。;
  72. };
  73. };
  74. ///=== {
  75. // ## ui.walk.Guide
  76. // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
  77. // 本别名没有参数。
  78. // };
  79. #alias {ui.walk.Guide} {
  80. #local height {};
  81. #local width {};
  82. #screen get rows height;
  83. #screen get cols width;
  84. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
  85. #screen clear scroll;
  86. #local top {@math.Eval{$height / 4}};
  87. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  88. #local left {@math.Eval{$width / 4}};
  89. #local right {@math.Eval{$width * 3 / 4 + 1}};
  90. #local vmid {@math.Eval{$width / 2}};
  91. #local hmid {@math.Eval{$height / 2}};
  92. #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
  93. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
  94. #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
  95. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
  96. #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
  97. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
  98. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
  99. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
  100. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
  101. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
  102. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
  103. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
  104. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
  105. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
  106. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
  107. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
  108. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
  109. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
  110. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
  111. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
  112. #buffer lock on;
  113. #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
  114. };
  115. #func {ui.walk.locate} {
  116. #local row {%1};
  117. #local col {%2};
  118. #local button {%3};
  119. #local long {%4};
  120. #local height {};
  121. #local width {};
  122. #screen get rows height;
  123. #screen get cols width;
  124. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
  125. #local top {@math.Eval{$height / 4}};
  126. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  127. #local left {@math.Eval{$width / 4}};
  128. #local right {@math.Eval{$width * 3 / 4 + 1}};
  129. #local vmid {@math.Eval{$width / 2}};
  130. #local hmid {@math.Eval{$height / 2}};
  131. #local dir {};
  132. #if { $row <= $top } {
  133. #cat dir {north};
  134. };
  135. #elseif { $row >= $bot } {
  136. #cat dir {south};
  137. };
  138. #if { $col <= $left } {
  139. #cat dir {west};
  140. };
  141. #elseif { $col >= $right } {
  142. #cat dir {east};
  143. };
  144. #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
  145. #if { "$dir" == "{north|south}" } {
  146. #if { @sset.Size{$real} == 1 } {
  147. #local dir {$real};
  148. };
  149. #else {
  150. #if { $col <= $left * 5 / 3 } {
  151. #cat dir {up};
  152. };
  153. #elseif { $col > $left * 7 / 3 } {
  154. #cat dir {down};
  155. };
  156. };
  157. };
  158. #elseif { "$dir" == "{east|west}" } {
  159. #if { @sset.Size{$real} == 1 } {
  160. #local dir {$real};
  161. };
  162. #else {
  163. #if { $row <= $top * 5 / 3 } {
  164. #cat dir {up};
  165. };
  166. #elseif { $row > $top * 7 / 3 } {
  167. #cat dir {down};
  168. };
  169. };
  170. };
  171. #if { "$dir" == "" } {
  172. #if { $col <= $vmid } {
  173. #local dir {@if{$row <= $hmid; enter; out}};
  174. };
  175. #else {
  176. #local dir {@if{$row <= $hmid; up; down}};
  177. };
  178. };
  179. #return {$dir};
  180. };
  181. VAR {触屏和小键盘走路插件的走路命令,默认为 go} ui.walk.cmd {go};
  182. ///=== {
  183. // ## ui.walk.SetCmd <触屏走路命令>
  184. // 设置触屏走路和小键盘走路时所用的命令,默认为 go。
  185. // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
  186. // };
  187. #alias {ui.walk.SetCmd} {
  188. #var ui.walk.cmd {%1};
  189. };
  190. #alias {ui.walk.go} {
  191. #local dir {%1};
  192. $ui.walk.cmd $dir;
  193. };
  194. #alias {ui.walk.Keypad.Setup} {
  195. #if { @option.IsDisable{KeypadWalk} } {
  196. #class ui.walk.Keypad kill;
  197. prompt.Set {{keypad}{}};
  198. errLog 小键盘走路已关闭。;
  199. };
  200. #else {
  201. #class ui.walk.Keypad open;
  202. #local idx {};
  203. #foreach {*global-keypad-walking[]} {idx} {
  204. #local entry {$global-keypad-walking[$idx]};
  205. #local name {$entry[key]};
  206. #local type {$entry[type]};
  207. #local args {$entry[args]};
  208. #if { &global-keypad-code[$name] == 0 } {
  209. #continue;
  210. };
  211. #local code {$global-keypad-code[$name]};
  212. #line sub var #macro {^$code} {ui.walk.keypad.do $name $type {$args}};
  213. };
  214. #class ui.walk.Keypad close;
  215. okLog 小键盘走路已开启。;
  216. prompt.Set {{keypad}{<129>已开启<299>}};
  217. };
  218. };
  219. ///=== {
  220. // ## ui.walk.Keypad.Bind <键名> <功能类型> <参数>
  221. // 为快捷键绑定功能。
  222. // 参数说明:
  223. // 键名:注意这里用的是键名,完整的键名列表可以通过 #var global-keypad-code 查看。
  224. // 功能类型目前就两种:
  225. // - dir: 方向指令。方向指令会根据当前行走模式转换成不同的命令。默认模式是 go,
  226. // 护镖或其它任务需要自行设置,请参考 HELP ui.walk.SetCmd
  227. // - cmd: 普通命令。可以是本地别名,或者服务器指令。
  228. // 参数:如果是方向指令,则应该是英文的方向全称。允许指定多个候选,以分号分隔。
  229. // 如果是普通命令,则只允许一条命令,如果功能复杂建议单独设置一个别名,在这里写别名名称。
  230. // };
  231. #alias {ui.walk.Keypad.Bind} {
  232. #local name {%1};
  233. #local type {%2};
  234. #local args {%3};
  235. #if { "$name" == "" || "$type" != "{dir|cmd}" || "$args" == "" } {
  236. xtt.Usage %90;
  237. #return;
  238. };
  239. #if { &global-keypad-code[$name] == 0 } {
  240. xtt.Usage %90;
  241. #return;
  242. };
  243. #list global-keypad-walking {indexate} key;
  244. #local idx {};
  245. #list global-keypad-walking {find} {$name} idx;
  246. #if { $idx == 0 } {
  247. #list global-keypad-walking {add} {{
  248. {key} {$name}
  249. {type} {$type}
  250. {args} {$args}
  251. }};
  252. };
  253. #else {
  254. #var {global-keypad-walking[$idx]} {
  255. {key} {$name}
  256. {type} {$type}
  257. {args} {$args}
  258. };
  259. };
  260. okLog 已绑定快捷键 $name 为 {$type} {$args};
  261. };
  262. ///=== {
  263. // ## ui.walk.Keypad.UnBind <键名>
  264. // 删除快捷键绑定的功能。
  265. // };
  266. #alias {ui.walk.Keypad.UnBind} {
  267. #local name {%1};
  268. #if { "$name" == "" } {
  269. xtt.Usage %90;
  270. #return;
  271. };
  272. #if { &global-keypad-code[$name] == 0 } {
  273. xtt.Usage %90;
  274. #return;
  275. };
  276. #list global-keypad-walking {indexate} key;
  277. #local idx {};
  278. #list global-keypad-walking {find} {$name} idx;
  279. #if { $idx > 0 } {
  280. #list global-keypad-walking {delete} {$idx};
  281. okLog 快捷键 $name 功能已删除。;
  282. };
  283. };
  284. #alias {ui.walk.keypad.do} {
  285. #local key {%1};
  286. #local type {%2};
  287. #local args {%3};
  288. #if { "$type" == "cmd" } {
  289. $args;
  290. #return;
  291. };
  292. #local dir {};
  293. #foreach {$args} {dir} {
  294. #if { @sset.Contains{{$gMapRoom[exits]};$dir} } {
  295. ui.walk.go $dir;
  296. #return;
  297. };
  298. };
  299. };