| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- #nop vim: set filetype=tt:;
- /*
- 本文件属于 PaoTin++ 的一部分。
- PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
- 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
- */
- ///=== {
- ///// 小键盘和触屏走路模块允许玩家通过小键盘,或者点击屏幕上的不同区域来控制角色向不同方向移动。
- ///// 本模块对手机用户可能有一些帮助,也可满足喜欢小键盘的玩家诉求。
- /////
- ///// 对于手机用户来说,建议先通过 ui.walk.Guide 别名来学习虚拟按键的方位布局。
- /////
- ///// 需要特别说明的是,本模块会自动和地图系统进行集成。通过监测房间出口,会对键位做细微的调整。
- ///// 举例来说,如果东方只有一个 eastup 出口,那么 east/eastup/eastdown 三个键位
- ///// 的作用就都是 eastup,如果只有一个 eastdown 也一样。南、北、西三个方向同理。
- /////
- ///// 本模块加载后默认并不启用,你需要通过开启 PaoTin++ 全局选项来开启对应功能。
- ///// 目前有两个功能:
- ///// - KeypadWalk: 小键盘走路,默认已绑定到快捷键 <ctrl+o> <k>
- ///// - ScreenKeypad: 屏幕虚拟键盘走路,默认已绑定到快捷键 <ctrl+o> <K>
- /////
- ///// 你也可以在脚本中通过 option 标准方法 option.Toggle/Enable/Disable 来开启或关闭它们。
- ///// 请查阅 HELP option
- // };
- #var lib_ui_walk[META] {
- {NAME} {触屏和小键盘走路}
- {DESC} {支持鼠标和触摸屏操作,点击屏幕不同区域,可以进入不同出口}
- {AUTHOR} {担子炮}
- };
- option.Define {KeypadWalk} {Bool} {是否开启小键盘走路} {false};
- option.Define {ScreenKeypad} {Bool} {是否开启屏幕虚拟键盘} {false};
- #func {lib_ui_walk.Init} {
- event.Handle {option/changed} {opt/KeypadWalk/main} {lib/ui/walk} {ui.walk.Keypad.Setup};
- event.Handle {option/changed} {opt/ScreenKeypad/main} {lib/ui/walk} {ui.walk.ScreenKeypad.Setup};
- event.HandleOnce {user-online} {ui/walk/setup} {online} {
- ui.walk.Keypad.Setup;
- ui.walk.ScreenKeypad.Setup;
- };
- #return {true};
- };
- #alias {ui.walk.setup} {
- #class ui.walk.mouse open;
- #event {SHORT-CLICKED MOUSE BUTTON ONE} {
- ui.walk.go @ui.walk.locate{%%0;%%1;left;short};
- };
- #event {SHORT-CLICKED MOUSE BUTTON THREE} {
- okLog 鼠标右击 @ui.walk.locate{%%0;%%1;right;short};
- };
- #event {LONG-CLICKED MOUSE BUTTON ONE} {
- okLog 鼠标长按 @ui.walk.locate{%%0;%%1;left;long};
- };
- #event {LONG-CLICKED MOUSE BUTTON THREE} {
- okLog 鼠标长右 @ui.walk.locate{%%0;%%1;right;long};
- };
- #class ui.walk.mouse close;
- };
- ///=== {
- // ## ui.walk.ScreenKeypad.Setup
- // 开启/关闭屏幕虚拟键盘走路。
- // 本别名没有参数。
- // };
- #alias {ui.walk.ScreenKeypad.Setup} {
- #if { @option.IsDisable{ScreenKeypad} } {
- #class ui.walk.mouse kill;
- prompt.Set {{screenKeypad}{}};
- errLog 屏幕虚拟键盘走路已关闭。;
- };
- #else {
- prompt.Set {{screenKeypad}{<129>已开启<299>}};
- ui.walk.setup;
- okLog 屏幕虚拟键盘走路已开启。;
- };
- };
- ///=== {
- // ## ui.walk.Guide
- // 在屏幕上展示一个虚拟键盘,展示每个按键的方位。
- // 本别名没有参数。
- // };
- #alias {ui.walk.Guide} {
- #local height {};
- #local width {};
- #screen get rows height;
- #screen get cols width;
- #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line - 1}};
- #screen clear scroll;
- #local top {@math.Eval{$height / 4}};
- #local bot {@math.Eval{$height * 3 / 4 + 1}};
- #local left {@math.Eval{$width / 4}};
- #local right {@math.Eval{$width * 3 / 4 + 1}};
- #local vmid {@math.Eval{$width / 2}};
- #local hmid {@math.Eval{$height / 2}};
- #draw TALIGN BALIGN CALIGN box 1 1 $top @math.Eval{$left - 1} 西北;
- #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$right + 1} $top $width 东北;
- #draw TALIGN BALIGN CALIGN box $bot 1 $height @math.Eval{$left - 1} 西南;
- #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$right + 1} $height $width 东南;
- #draw TALIGN BALIGN CALIGN box 1 $left $top @math.Eval{$left * 5 / 3} 北上;
- #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 5 / 3 + 1} $top @math.Eval{$left * 7 / 3} 北;
- #draw TALIGN BALIGN CALIGN box 1 @math.Eval{$left * 7 / 3 + 1} $top $right 北下;
- #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left + 1} $height @math.Eval{$left * 5 / 3} 南上;
- #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 5 / 3 + 1} $height @math.Eval{$left * 7 / 3} 南;
- #draw TALIGN BALIGN CALIGN box $bot @math.Eval{$left * 7 / 3 + 1} $height $right 南下;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} 1 @math.Eval{$top * 5 / 3} @math.Eval{$left - 1} 西上;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} 1 @math.Eval{$top * 7 / 3} @math.Eval{$left - 1} 西;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} 1 @math.Eval{$bot - 1} @math.Eval{$left - 1} 西下;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$right + 1} @math.Eval{$top * 5 / 3} $width 东上;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 5 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$top * 7 / 3} $width 东;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top * 7 / 3 + 1} @math.Eval{$right + 1} @math.Eval{$bot - 1} $width 东下;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$left + 1} $hmid $vmid 进;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$left + 1} @math.Eval{$bot - 1} $vmid 出;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$top + 1} @math.Eval{$vmid + 1} $hmid $right 上;
- #draw TALIGN BALIGN CALIGN box @math.Eval{$hmid + 1} @math.Eval{$vmid + 1} @math.Eval{$bot - 1} $right 下;
- #buffer lock on;
- #line oneshot #macro {\cc} {#buffer lock off; #buffer end};
- };
- #func {ui.walk.locate} {
- #local row {%1};
- #local col {%2};
- #local button {%3};
- #local long {%4};
- #local height {};
- #local width {};
- #screen get rows height;
- #screen get cols width;
- #local height {@math.Eval{$height - $prompt-top-max-line - $prompt-bot-max-line}};
- #local top {@math.Eval{$height / 4}};
- #local bot {@math.Eval{$height * 3 / 4 + 1}};
- #local left {@math.Eval{$width / 4}};
- #local right {@math.Eval{$width * 3 / 4 + 1}};
- #local vmid {@math.Eval{$width / 2}};
- #local hmid {@math.Eval{$height / 2}};
- #local dir {};
- #if { $row <= $top } {
- #cat dir {north};
- };
- #elseif { $row >= $bot } {
- #cat dir {south};
- };
- #if { $col <= $left } {
- #cat dir {west};
- };
- #elseif { $col >= $right } {
- #cat dir {east};
- };
- #local real {@sset.Intersection{{$gMapRoom[exits]};{${dir}up;$dir;${dir}down}}};
- #if { "$dir" == "{north|south}" } {
- #if { @sset.Size{$real} == 1 } {
- #local dir {$real};
- };
- #else {
- #if { $col <= $left * 5 / 3 } {
- #cat dir {up};
- };
- #elseif { $col > $left * 7 / 3 } {
- #cat dir {down};
- };
- };
- };
- #elseif { "$dir" == "{east|west}" } {
- #if { @sset.Size{$real} == 1 } {
- #local dir {$real};
- };
- #else {
- #if { $row <= $top * 5 / 3 } {
- #cat dir {up};
- };
- #elseif { $row > $top * 7 / 3 } {
- #cat dir {down};
- };
- };
- };
- #if { "$dir" == "" } {
- #if { $col <= $vmid } {
- #local dir {@if{$row <= $hmid; enter; out}};
- };
- #else {
- #local dir {@if{$row <= $hmid; up; down}};
- };
- };
- #return {$dir};
- };
- VAR {触屏和小键盘走路插件的走路命令,默认为 go} ui.walk.cmd {go};
- ///=== {
- // ## ui.walk.SetCmd <触屏走路命令>
- // 设置触屏走路和小键盘走路时所用的命令,默认为 go。
- // 例如,推车任务时你可以设置为: ui.walk.SetCmd {gan che to} 来表示推车所用的命令。
- // };
- #alias {ui.walk.SetCmd} {
- #var ui.walk.cmd {%1};
- };
- #alias {ui.walk.go} {
- #local dir {%1};
- $ui.walk.cmd $dir;
- };
- #alias {ui.walk.Keypad.Setup} {
- #if { @option.IsDisable{KeypadWalk} } {
- #class ui.walk.Keypad kill;
- prompt.Set {{keypad}{}};
- errLog 小键盘走路已关闭。;
- };
- #else {
- #class ui.walk.Keypad open;
- #local idx {};
- #foreach {*global-keypad-walking[]} {idx} {
- #local entry {$global-keypad-walking[$idx]};
- #local name {$entry[key]};
- #local type {$entry[type]};
- #local args {$entry[args]};
- #if { &global-keypad-code[$name] == 0 } {
- #continue;
- };
- #local code {$global-keypad-code[$name]};
- #line sub var #macro {$code} {ui.walk.keypad.do $name $type {$args}};
- };
- #class ui.walk.Keypad close;
- okLog 小键盘走路已开启。;
- prompt.Set {{keypad}{<129>已开启<299>}};
- };
- };
- ///=== {
- // ## ui.walk.Keypad.Bind <键名> <功能类型> <参数>
- // 为快捷键绑定功能。
- // 参数说明:
- // 键名:注意这里用的是键名,完整的键名列表可以通过 #var global-keypad-code 查看。
- // 功能类型目前就两种:
- // - dir: 方向指令。方向指令会根据当前行走模式转换成不同的命令。默认模式是 go,
- // 护镖或其它任务需要自行设置,请参考 HELP ui.walk.SetCmd
- // - cmd: 普通命令。可以是本地别名,或者服务器指令。
- // 参数:如果是方向指令,则应该是英文的方向全称。允许指定多个候选,以分号分隔。
- // 如果是普通命令,则只允许一条命令,如果功能复杂建议单独设置一个别名,在这里写别名名称。
- // };
- #alias {ui.walk.Keypad.Bind} {
- #local name {%1};
- #local type {%2};
- #local args {%3};
- #if { "$name" == "" || "$type" != "{dir|cmd}" || "$args" == "" } {
- xtt.Usage %90;
- #return;
- };
- #if { &global-keypad-code[$name] == 0 } {
- xtt.Usage %90;
- #return;
- };
- #list global-keypad-walking {indexate} key;
- #local idx {};
- #list global-keypad-walking {find} {$name} idx;
- #if { $idx == 0 } {
- #list global-keypad-walking {add} {{
- {key} {$name}
- {type} {$type}
- {args} {$args}
- }};
- };
- #else {
- #var {global-keypad-walking[$idx]} {
- {key} {$name}
- {type} {$type}
- {args} {$args}
- };
- };
- okLog 已绑定快捷键 $name 为 {$type} {$args};
- };
- ///=== {
- // ## ui.walk.Keypad.UnBind <键名>
- // 删除快捷键绑定的功能。
- // };
- #alias {ui.walk.Keypad.UnBind} {
- #local name {%1};
- #if { "$name" == "" } {
- xtt.Usage %90;
- #return;
- };
- #if { &global-keypad-code[$name] == 0 } {
- xtt.Usage %90;
- #return;
- };
- #list global-keypad-walking {indexate} key;
- #local idx {};
- #list global-keypad-walking {find} {$name} idx;
- #if { $idx > 0 } {
- #list global-keypad-walking {delete} {$idx};
- okLog 快捷键 $name 功能已删除。;
- };
- };
- #alias {ui.walk.keypad.do} {
- #local key {%1};
- #local type {%2};
- #local args {%3};
- #if { "$key" == "Enter" } {
- #local input {};
- #cursor get input;
- #if { {$input} !== {} } {
- #cursor clear;
- $input;
- #line sub var #history insert {$input};
- #return;
- };
- #elseif { "$gMapRoom[dock]" == "dock" } {
- map.YellBoat;
- #return;
- };
- #elseif { "$gMapRoom[dock]" == "ride" } {
- map.Ride;
- #return;
- };
- };
- #if { "$type" == "cmd" } {
- $args;
- #return;
- };
- #local dir {};
- #foreach {$args} {dir} {
- #if { @sset.Contains{{$gMapRoom[exits]};$dir} } {
- ui.walk.go $dir;
- #return;
- };
- };
- };
|