walk.tin 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. ///// 键位做细微的调整。
  15. ///// 举例来说,如果东方只有一个 eastup 出口,那么 east/eastup/eastdown 三个键位
  16. ///// 的作用就都是 eastup,如果只有一个 eastdown 也一样。南、北、西三个方向同理。
  17. /////
  18. ///// 本模块加载后立即生效,如果你需要暂时禁用,可以用 ui.walk.Disable 别名。
  19. ///// 稍后可以通过 ui.walk.Enable 重新启用。
  20. // };
  21. #var lib_ui_walk[META] {
  22. {NAME} {触屏走路}
  23. {DESC} {支持鼠标和触摸屏操作,点击屏幕不同区域,可以进入不同出口}
  24. {AUTHOR} {担子炮}
  25. };
  26. option.Define {KeypadWalk} {Bool} {是否开启小键盘走路} {false};
  27. #func {lib_ui_walk.Init} {
  28. ui.walk.Enable;
  29. event.Handle {option/changed} {option/changed/KeypadWalk} {lib/ui/walk} {ui.walk.keypad.Toggle};
  30. option.Disable KeypadWalk;
  31. #return {true};
  32. };
  33. #alias {ui.walk.setup} {
  34. #class ui.walk.mouse open;
  35. #event {SHORT-CLICKED MOUSE BUTTON ONE} {
  36. ui.walk.go @ui.walk.locate{%%0;%%1;left;short};
  37. };
  38. #event {SHORT-CLICKED MOUSE BUTTON THREE} {
  39. okLog 鼠标右击 @ui.walk.locate{%%0;%%1;right;short};
  40. };
  41. #event {LONG-CLICKED MOUSE BUTTON ONE} {
  42. okLog 鼠标长按 @ui.walk.locate{%%0;%%1;left;long};
  43. };
  44. #event {LONG-CLICKED MOUSE BUTTON THREE} {
  45. okLog 鼠标长右 @ui.walk.locate{%%0;%%1;right;long};
  46. };
  47. #class ui.walk.mouse close;
  48. };
  49. ///=== {
  50. // ## ui.walk.Enable
  51. // 开启触屏走路。
  52. // 本别名没有参数。
  53. // };
  54. #alias {ui.walk.Enable} {
  55. ui.walk.setup;
  56. };
  57. ///=== {
  58. // ## ui.walk.Disable
  59. // 禁用触屏走路。
  60. // 本别名没有参数。
  61. // };
  62. #alias {ui.walk.Disable} {
  63. #class ui.walk.mouse kill;
  64. };
  65. ///=== {
  66. // ## ui.walk.Guide
  67. // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
  68. // 本别名没有参数。
  69. // };
  70. #alias {ui.walk.Guide} {
  71. #local height {};
  72. #local width {};
  73. #screen get rows height;
  74. #screen get cols width;
  75. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
  76. #screen clear scroll;
  77. #local top {@math.Eval{$height / 4}};
  78. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  79. #local left {@math.Eval{$width / 4}};
  80. #local right {@math.Eval{$width * 3 / 4 + 1}};
  81. #local vmid {@math.Eval{$width / 2}};
  82. #local hmid {@math.Eval{$height / 2}};
  83. #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
  84. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
  85. #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
  86. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
  87. #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
  88. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
  89. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
  90. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
  91. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
  92. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
  93. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
  94. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
  95. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
  96. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
  97. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
  98. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
  99. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
  100. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
  101. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
  102. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
  103. #buffer lock on;
  104. #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
  105. };
  106. #func {ui.walk.locate} {
  107. #local row {%1};
  108. #local col {%2};
  109. #local button {%3};
  110. #local long {%4};
  111. #local height {};
  112. #local width {};
  113. #screen get rows height;
  114. #screen get cols width;
  115. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
  116. #local top {@math.Eval{$height / 4}};
  117. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  118. #local left {@math.Eval{$width / 4}};
  119. #local right {@math.Eval{$width * 3 / 4 + 1}};
  120. #local vmid {@math.Eval{$width / 2}};
  121. #local hmid {@math.Eval{$height / 2}};
  122. #local dir {};
  123. #if { $row <= $top } {
  124. #cat dir {north};
  125. };
  126. #elseif { $row >= $bot } {
  127. #cat dir {south};
  128. };
  129. #if { $col <= $left } {
  130. #cat dir {west};
  131. };
  132. #elseif { $col >= $right } {
  133. #cat dir {east};
  134. };
  135. #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
  136. #if { "$dir" == "{north|south}" } {
  137. #if { @sset.Size{$real} == 1 } {
  138. #local dir {$real};
  139. };
  140. #else {
  141. #if { $col <= $left * 5 / 3 } {
  142. #cat dir {up};
  143. };
  144. #elseif { $col > $left * 7 / 3 } {
  145. #cat dir {down};
  146. };
  147. };
  148. };
  149. #elseif { "$dir" == "{east|west}" } {
  150. #if { @sset.Size{$real} == 1 } {
  151. #local dir {$real};
  152. };
  153. #else {
  154. #if { $row <= $top * 5 / 3 } {
  155. #cat dir {up};
  156. };
  157. #elseif { $row > $top * 7 / 3 } {
  158. #cat dir {down};
  159. };
  160. };
  161. };
  162. #if { "$dir" == "" } {
  163. #if { $col <= $vmid } {
  164. #local dir {@if{$row <= $hmid; enter; out}};
  165. };
  166. #else {
  167. #local dir {@if{$row <= $hmid; up; down}};
  168. };
  169. };
  170. #return {$dir};
  171. };
  172. VAR {触屏走路插件的走路命令,默认为 go} ui.walk.cmd {go};
  173. ///=== {
  174. // ## ui.walk.SetCmd <触屏走路命令>
  175. // 设置触屏走路时所用的命令,默认为 go。
  176. // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
  177. // };
  178. #alias {ui.walk.SetCmd} {
  179. #var ui.walk.cmd {%1};
  180. };
  181. #alias {ui.walk.go} {
  182. #local dir {%1};
  183. $ui.walk.cmd $dir;
  184. };
  185. #alias {ui.walk.keypad.Toggle} {
  186. #if { @option.IsDisable{KeypadWalk} } {
  187. okLog 小键盘走路已关闭。;
  188. #class ui.walk.Keypad kill;
  189. };
  190. #else {
  191. okLog 小键盘走路已开启。;
  192. #class ui.walk.Keypad open;
  193. #local dir {};
  194. #foreach {*global-keypad-walking[]} {dir} {
  195. #local code {$global-keypad-walking[$dir]};
  196. #line sub var #macro {$code} {ui.walk.go $dir};
  197. };
  198. #class ui.walk.Keypad close;
  199. };
  200. };