walk.tin 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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.Toggle};
  34. event.Handle {option/changed} {option/changed/ScreenKeypad} {lib/ui/walk} {ui.walk.ScreenKeypad.Toggle};
  35. #return {true};
  36. };
  37. #alias {ui.walk.setup} {
  38. #class ui.walk.mouse open;
  39. #event {SHORT-CLICKED MOUSE BUTTON ONE} {
  40. ui.walk.go @ui.walk.locate{%%0;%%1;left;short};
  41. };
  42. #event {SHORT-CLICKED MOUSE BUTTON THREE} {
  43. okLog 鼠标右击 @ui.walk.locate{%%0;%%1;right;short};
  44. };
  45. #event {LONG-CLICKED MOUSE BUTTON ONE} {
  46. okLog 鼠标长按 @ui.walk.locate{%%0;%%1;left;long};
  47. };
  48. #event {LONG-CLICKED MOUSE BUTTON THREE} {
  49. okLog 鼠标长右 @ui.walk.locate{%%0;%%1;right;long};
  50. };
  51. #class ui.walk.mouse close;
  52. };
  53. ///=== {
  54. // ## ui.walk.ScreenKeypad.Toggle
  55. // 开启/关闭屏幕虚拟键盘走路。
  56. // 本别名没有参数。
  57. // };
  58. #alias {ui.walk.ScreenKeypad.Toggle} {
  59. #if { @option.IsDisable{ScreenKeypad} } {
  60. #class ui.walk.mouse kill;
  61. errLog 屏幕虚拟键盘走路已关闭。;
  62. };
  63. #else {
  64. ui.walk.setup;
  65. okLog 屏幕虚拟键盘走路已开启。;
  66. };
  67. };
  68. ///=== {
  69. // ## ui.walk.Guide
  70. // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
  71. // 本别名没有参数。
  72. // };
  73. #alias {ui.walk.Guide} {
  74. #local height {};
  75. #local width {};
  76. #screen get rows height;
  77. #screen get cols width;
  78. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
  79. #screen clear scroll;
  80. #local top {@math.Eval{$height / 4}};
  81. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  82. #local left {@math.Eval{$width / 4}};
  83. #local right {@math.Eval{$width * 3 / 4 + 1}};
  84. #local vmid {@math.Eval{$width / 2}};
  85. #local hmid {@math.Eval{$height / 2}};
  86. #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
  87. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
  88. #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
  89. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
  90. #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
  91. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
  92. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
  93. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
  94. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
  95. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
  96. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
  97. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
  98. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
  99. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
  100. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
  101. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
  102. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
  103. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
  104. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
  105. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
  106. #buffer lock on;
  107. #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
  108. };
  109. #func {ui.walk.locate} {
  110. #local row {%1};
  111. #local col {%2};
  112. #local button {%3};
  113. #local long {%4};
  114. #local height {};
  115. #local width {};
  116. #screen get rows height;
  117. #screen get cols width;
  118. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
  119. #local top {@math.Eval{$height / 4}};
  120. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  121. #local left {@math.Eval{$width / 4}};
  122. #local right {@math.Eval{$width * 3 / 4 + 1}};
  123. #local vmid {@math.Eval{$width / 2}};
  124. #local hmid {@math.Eval{$height / 2}};
  125. #local dir {};
  126. #if { $row <= $top } {
  127. #cat dir {north};
  128. };
  129. #elseif { $row >= $bot } {
  130. #cat dir {south};
  131. };
  132. #if { $col <= $left } {
  133. #cat dir {west};
  134. };
  135. #elseif { $col >= $right } {
  136. #cat dir {east};
  137. };
  138. #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
  139. #if { "$dir" == "{north|south}" } {
  140. #if { @sset.Size{$real} == 1 } {
  141. #local dir {$real};
  142. };
  143. #else {
  144. #if { $col <= $left * 5 / 3 } {
  145. #cat dir {up};
  146. };
  147. #elseif { $col > $left * 7 / 3 } {
  148. #cat dir {down};
  149. };
  150. };
  151. };
  152. #elseif { "$dir" == "{east|west}" } {
  153. #if { @sset.Size{$real} == 1 } {
  154. #local dir {$real};
  155. };
  156. #else {
  157. #if { $row <= $top * 5 / 3 } {
  158. #cat dir {up};
  159. };
  160. #elseif { $row > $top * 7 / 3 } {
  161. #cat dir {down};
  162. };
  163. };
  164. };
  165. #if { "$dir" == "" } {
  166. #if { $col <= $vmid } {
  167. #local dir {@if{$row <= $hmid; enter; out}};
  168. };
  169. #else {
  170. #local dir {@if{$row <= $hmid; up; down}};
  171. };
  172. };
  173. #return {$dir};
  174. };
  175. VAR {触屏走路插件的走路命令,默认为 go} ui.walk.cmd {go};
  176. ///=== {
  177. // ## ui.walk.SetCmd <触屏走路命令>
  178. // 设置触屏走路时所用的命令,默认为 go。
  179. // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
  180. // };
  181. #alias {ui.walk.SetCmd} {
  182. #var ui.walk.cmd {%1};
  183. };
  184. #alias {ui.walk.go} {
  185. #local dir {%1};
  186. $ui.walk.cmd $dir;
  187. };
  188. #alias {ui.walk.Keypad.Toggle} {
  189. #if { @option.IsDisable{KeypadWalk} } {
  190. #class ui.walk.Keypad kill;
  191. errLog 小键盘走路已关闭。;
  192. };
  193. #else {
  194. #class ui.walk.Keypad open;
  195. #local idx {};
  196. #foreach {*global-keypad-walking[]} {idx} {
  197. #local entry {$global-keypad-walking[$idx]};
  198. #local name {$entry[key]};
  199. #local type {$entry[type]};
  200. #local args {$entry[args]};
  201. #if { &global-keypad-code[$name] == 0 } {
  202. #continue;
  203. };
  204. #local code {$global-keypad-code[$name]};
  205. #line sub var #macro {$code} {ui.walk.keypad.do $name $type {$args}};
  206. };
  207. #class ui.walk.Keypad close;
  208. okLog 小键盘走路已开启。;
  209. };
  210. };
  211. #alias {ui.walk.keypad.do} {
  212. #local key {%1};
  213. #local type {%2};
  214. #local args {%3};
  215. #if { "$key" == "Enter" } {
  216. #local input {};
  217. #cursor get input;
  218. #if { {$input} !== {} } {
  219. #cursor clear;
  220. $input;
  221. #return;
  222. };
  223. };
  224. #if { "$type" == "cmd" } {
  225. $args;
  226. #return;
  227. };
  228. #local dir {};
  229. #foreach {$args} {dir} {
  230. #if { @sset.Contains{{$gMapRoom[exits]};$dir} } {
  231. ui.walk.go $dir;
  232. #return;
  233. };
  234. };
  235. };