walk.tin 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #func {lib_ui_walk.Init} {
  27. ui.walk.Enable;
  28. #return {true};
  29. };
  30. #alias {ui.walk.setup} {
  31. #class ui.walk.mouse open;
  32. #event {SHORT-CLICKED MOUSE BUTTON ONE} {
  33. ui.walk.go @ui.walk.locate{%%0;%%1;left;short};
  34. };
  35. #event {SHORT-CLICKED MOUSE BUTTON THREE} {
  36. okLog 鼠标右击 @ui.walk.locate{%%0;%%1;right;short};
  37. };
  38. #event {LONG-CLICKED MOUSE BUTTON ONE} {
  39. okLog 鼠标长按 @ui.walk.locate{%%0;%%1;left;long};
  40. };
  41. #event {LONG-CLICKED MOUSE BUTTON THREE} {
  42. okLog 鼠标长右 @ui.walk.locate{%%0;%%1;right;long};
  43. };
  44. #class ui.walk.mouse close;
  45. };
  46. ///=== {
  47. // ## ui.walk.Enable
  48. // 开启触屏走路。
  49. // 本别名没有参数。
  50. // };
  51. #alias {ui.walk.Enable} {
  52. ui.walk.setup;
  53. };
  54. ///=== {
  55. // ## ui.walk.Disable
  56. // 禁用触屏走路。
  57. // 本别名没有参数。
  58. // };
  59. #alias {ui.walk.Disable} {
  60. #class ui.walk.mouse kill;
  61. };
  62. ///=== {
  63. // ## ui.walk.Guide
  64. // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
  65. // 本别名没有参数。
  66. // };
  67. #alias {ui.walk.Guide} {
  68. #local height {};
  69. #local width {};
  70. #screen get rows height;
  71. #screen get cols width;
  72. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
  73. #screen clear scroll;
  74. #local top {@math.Eval{$height / 4}};
  75. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  76. #local left {@math.Eval{$width / 4}};
  77. #local right {@math.Eval{$width * 3 / 4 + 1}};
  78. #local vmid {@math.Eval{$width / 2}};
  79. #local hmid {@math.Eval{$height / 2}};
  80. #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
  81. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
  82. #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
  83. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
  84. #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
  85. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
  86. #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
  87. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
  88. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
  89. #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
  90. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
  91. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
  92. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
  93. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
  94. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
  95. #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
  96. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
  97. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
  98. #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
  99. #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
  100. #buffer lock on;
  101. #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
  102. };
  103. #func {ui.walk.locate} {
  104. #local row {%1};
  105. #local col {%2};
  106. #local button {%3};
  107. #local long {%4};
  108. #local height {};
  109. #local width {};
  110. #screen get rows height;
  111. #screen get cols width;
  112. #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
  113. #local top {@math.Eval{$height / 4}};
  114. #local bot {@math.Eval{$height * 3 / 4 + 1}};
  115. #local left {@math.Eval{$width / 4}};
  116. #local right {@math.Eval{$width * 3 / 4 + 1}};
  117. #local vmid {@math.Eval{$width / 2}};
  118. #local hmid {@math.Eval{$height / 2}};
  119. #local dir {};
  120. #if { $row <= $top } {
  121. #cat dir {north};
  122. };
  123. #elseif { $row >= $bot } {
  124. #cat dir {south};
  125. };
  126. #if { $col <= $left } {
  127. #cat dir {west};
  128. };
  129. #elseif { $col >= $right } {
  130. #cat dir {east};
  131. };
  132. #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
  133. #if { "$dir" == "{north|south}" } {
  134. #if { @sset.Size{$real} == 1 } {
  135. #local dir {$real};
  136. };
  137. #else {
  138. #if { $col <= $left * 5 / 3 } {
  139. #cat dir {up};
  140. };
  141. #elseif { $col > $left * 7 / 3 } {
  142. #cat dir {down};
  143. };
  144. };
  145. };
  146. #elseif { "$dir" == "{east|west}" } {
  147. #if { @sset.Size{$real} == 1 } {
  148. #local dir {$real};
  149. };
  150. #else {
  151. #if { $row <= $top * 5 / 3 } {
  152. #cat dir {up};
  153. };
  154. #elseif { $row > $top * 7 / 3 } {
  155. #cat dir {down};
  156. };
  157. };
  158. };
  159. #if { "$dir" == "" } {
  160. #if { $col <= $vmid } {
  161. #local dir {@if{$row <= $hmid; enter; out}};
  162. };
  163. #else {
  164. #local dir {@if{$row <= $hmid; up; down}};
  165. };
  166. };
  167. #return {$dir};
  168. };
  169. VAR {触屏走路插件的走路命令,默认为 go} ui.walk.cmd {go};
  170. ///=== {
  171. // ## ui.walk.SetCmd <触屏走路命令>
  172. // 设置触屏走路时所用的命令,默认为 go。
  173. // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
  174. // };
  175. #alias {ui.walk.SetCmd} {
  176. #var ui.walk.cmd {%1};
  177. };
  178. #alias {ui.walk.go} {
  179. #local dir {%1};
  180. $ui.walk.cmd $dir;
  181. };