Jump to content

Touch controls/zh: Difference between revisions

From DDraceNetwork
Created page with "触摸控制"
 
No edit summary
 
(171 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<div lang="en" dir="ltr" class="mw-content-ltr">
触屏操控从DDNet 18.8版本客户端开始启用,这也标志着最近期的首个DDNet安卓版发布。早期的安卓版本为DDNet 9.3.1,该版本已有一个[[Special:MyLanguage/Android Tutorial for DDNet 9.3.1|单独教程]]。以下教程将只考虑18.8以后版本的触屏操控。
Touch controls are available in the DDNet client since version 18.8, which also marks the first recent release of the client for Android. The previous version for Android is DDNet 9.3.1 for which a [[Special:MyLanguage/Android Tutorial for DDNet 9.3.1|separate tutorial]] exists. In the following we will only consider the touch controls as of versions 18.8 and newer.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在用户界面可以进行的触屏操控如下:
The user interface can be used with touch controls as follows:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* 直接点击屏幕某位置:视为移动光标至该位置并用左键单击;
* Touch anywhere to move the cursor and perform a left click.
* 长按屏幕某位置至少0.5秒:视为用鼠标右键单击该位置,轻微移动手指不影响判定;
* Touch and hold for at least 0.5 seconds on roughly the same position to perform a right click.
* 用两根手指长按屏幕并上下滑动:视为在该位置滚动鼠标滚轮,可以上下滚动列表如服务器浏览器和控制台;
* Use two fingers to scroll up and down in scrollable lists like the server browser and in the console.
* 在安卓设备上触发了(虚拟)返回键:视为使用了Esc键,可关闭菜单等。
* On Android: Use the (virtual) Back button like the Escape key to close menus etc.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在游戏界面内的触屏操控可以通过配置参数<code>cl_touch_controls</code>来开启/关闭,此参数在安卓设备上默认为<code>1</code>,在其他平台则是<code>0</code>。触屏操控在其他支持触控的平台上应该也能正常使用,但此教程主要针对安卓设备进行测试。
The ingame touch controls can be enabled/disabled with the config variable <code>cl_touch_controls</code>, which defaults to <code>1</code> on Android and <code>0</code> on other platforms. Touch controls should also work on other platforms that support touch devices, but this guide has primarily been tested on Android.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
游戏内触屏操控包含许多屏幕按钮。不同按钮根据功能不同仅会在可用时显示,例如移动键仅会在进行游玩时显示。
The ingame touch controls consist of various on-screen touch buttons. The different buttons are only shown when they are usable depending on the context, e.g. buttons for movement are only shown when ingame.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Default_touch_button_configuration"></span>
== Default touch button configuration ==
== 默认触控按键配置 ==
</div>


[[File:Touch Controls Default.png|thumb|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of the default touch controls ingame.</span>]]
[[File:Touch Controls Default.png|thumb|游戏内默认触控键位的截图。]]


<div lang="en" dir="ltr" class="mw-content-ltr">
左、右移动和跳跃键的位置分布形如<code>⊥</code>,和键盘上的WASD分布类似。
Movement buttons for left, right and jump actions are arranged in a <code>⊥</code>-pattern similar to WASD controls.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
关于开火和出钩的操作,游戏内默认提供了两种操作方式:
For the fire and hook action, two modes are implemented:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
# 通过直接点击屏幕空白处,可以将准星直接移动到点击处并立即朝准星处开火或出钩,此时不松手拖动可以控制瞄准角度或不松钩;
# Direct touch input: the mouse is moved exactly where the player touches on the screen.
# 通过拖动虚拟摇杆按钮,可以将准星以玩家位置为原点朝拖动方向移动,同时开火或出钩。
# Virtual joystick: a button is used to emulate a joystick, which moves the mouse relative to the center of the screen.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
在两种操作方式下都可以点击右上角的'''“当前”'''功能按钮切换为开火或出钩模式。当按住虚拟摇杆时,“当前”按钮将变成直接触发另一功能的按钮,按钮上的文字提示也会相应改变。
In either mode, a button is used to switch between the active actions (fire and hook). While the virtual joystick is being held down, this button uses the other action directly instead of switching it.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
对于游戏或旁观时,可以分别设置直接点击屏幕的功能,通过禁用“直接触摸操作”可以避免游戏中使用摇杆的同时点击误触。
The direct touch input mode can be adjusted separately for ingame/spectating, to prevent accidental direct touch input when using a joystick.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
旁观模式下,如果将直接触屏操控设置为瞄准,则可以类似图片一样拖动地图进行观察;如果设置为禁用,则只能在摇杆范围内拖动。
When spectating, direct touch input is used to allow panning the map directly like in an image/map viewer. Virtual joysticks can also be used to pan the map while spectating.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
默认情况下左上角有两个按钮用于切换上一武器和下一武器。
Two separate buttons are shown to switch to the previous and next weapons.
</div>


[[File:Touch Controls Default All.png|thumb|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of the default touch controls ingame with all buttons being previewed.</span>]]
[[File:Touch Controls Default All.png|thumb|显示全部默认键位的预览图]]


<div lang="en" dir="ltr" class="mw-content-ltr">
左上角的<code>☰</code>字形按钮是游戏内菜单按钮,可用于显示或隐藏更多按钮,这些按钮大部分与游戏操作无关。包括显示计分板、表情轮盘、旁观列表、全局聊天、队伍内聊天的按钮,以及投票按钮和视野缩放按钮。长按菜单按钮松手时会打开类似于电脑按下 {{key press|Esc}} 后的游戏内菜单,当然安卓设备也可以使用返回键代替。
A hamburger menu button <code>☰</code> is used to toggle the visibility of lesser used touch buttons. This includes buttons for showing the scoreboard, showing the emoticon selector, showing the spectator menu, opening team and team chat, voting yes/no, and zooming. Long pressing the hamburger menu button will open the ingame menu.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
连接分身后,右上角会出现切换分身的按钮。
When the dummy is connected, a button for swapping between main and dummy is shown.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
显示更多按钮时,可以打开表情轮盘或旁观列表等菜单,点击表情发送或点击旁观对象观察,点击空白处则可以关闭菜单,安卓设备可以使用返回键关闭。但是目前还无法实现长按按钮时显示菜单、松手自动关闭的功能,并且也不适合用于旁观列表。
The emoticon selector and spectator menu are activated with the respective touch buttons and can be deactivated by touching outside of them or by using the back-button, as toggling them while the ingame touch button is pressed down is currently not feasible and also inconvenient at least for using the spectator menu.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Touch_button_configuration_format"></span>
== Touch button configuration format ==
== 自定义触控键位设置 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
默认键位保存在<code>touch_controls.json</code>文件中,安卓版本下该文件位于<code>data</code>目录,高版本安卓设备一般会禁止用户修改这一目录下的文件。因此如果您要进行键位自定义,需要通过在配置目录中创建同名为<code>touch_controls.json</code>的文件,利用更高的优先度来覆盖默认设置。
The default button layout described above is loaded from the file <code>touch_controls.json</code> in the <code>data</code> directory which should not be modified. This layout can be overridden by creating a file <code>touch_controls.json</code> in the config directory.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
键位配置文件是JSON格式的文本文件,推荐在掌握一定JSON基础的情况下阅读下方教程,在配置JSON文件时必须保证有效性。关于JSON格式的相关教程和工具可在网络上找到,下面也会涉及到许多相关术语,当然也可以将游戏配置文件当作练习对象来学习JSON,但是建议在进行实操前先做好重要文件的备份。本教程涉及的JSON配置文件的结构如下:
The touch button configuration is a text file in JSON format. It is recommended to first learn the basics of the JSON format to understand the following guide. The configuration must be a valid JSON file. Guides and validation tools for the JSON format are available on the internet. The structure of the JSON file is described in the following.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
JSON文件的根元素必须是一个对象。该对象的属性<code>&quot;touch-buttons&quot;</code>可定义一系列按钮对象。按钮对象都可调节下列属性:
The root element in the JSON file must be an object. The attribute <code>&quot;touch-buttons&quot;</code> of the root object specifies an array of touch button objects. Each touch button object has the following adjustable properties:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* 位置和大小(属性<code>&quot;x&quot;</code>, <code>&quot;y&quot;</code>, <code>&quot;w&quot;</code>, <code>&quot;h&quot;</code>):屏幕显示区域将被平均划分为1000000x1000000的网格,前面提到的四个属性为整数,大小分别表示按钮的中心点横纵坐标和宽度高度。网格的'''实际单位长度'''会根据游戏窗口大小及屏幕比例实时拉伸,因此对于不同的屏幕设备,只要屏幕纵横比差异不大,按钮布局就不会变得特别不合理。
* Position and size (attributes <code>&quot;x&quot;</code>, <code>&quot;y&quot;</code>, <code>&quot;w&quot;</code>, <code>&quot;h&quot;</code>): the X/Y position and width/height are integers on a 1,000,000² grid. These ''unit grid'' values are converted to ''screen grid'' values at runtime in relation to the size and aspect ratio of the screen. This means buttons may appear stretched if the resolution is changed, but it allows us to provide a reasonable default for slightly different aspect ratios.
* 形状 (属性<code>&quot;shape&quot;</code>):用于决定按钮形状:
* Shape (attribute <code>&quot;shape&quot;</code>): determines the shape of the button being rendered.
** <code>&quot;rect&quot;</code>:矩形;
** <code>&quot;rect&quot;</code>: rectangle shape.
** <code>&quot;circle&quot;</code>:圆形,该按钮的高度和宽度会自动调整为一致大小。
** <code>&quot;circle&quot;</code>: circle shape. The button size will automatically be adjusted so that width and height are identical.
* 可见性(属性<code>&quot;visibilities&quot;</code>):该属性为空意味着按钮总是显示在屏幕上。如果设置了某些属性,按钮将只会在满足特定条件时显示,其它情况下隐藏,目前已预设一系列可选的可见性类型如下:
* Visibility (attribute <code>&quot;visibilities&quot;</code>): an array of predefined visibility classes can be selected and the button is only shown if all conditions are satisfied. An empty array means that the button is always shown. The following visibility classes are defined:
** <code>&quot;ingame&quot;</code>:仅在游戏内显示,即在旁观模式下将会隐藏;
** <code>&quot;ingame&quot;</code>: player is ingame, i.e. not spectating.
** <code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code>, <code>&quot;extra-menu-5&quot;</code>:在打开对应序号的附加菜单时显示;
** <code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code>, <code>&quot;extra-menu-5&quot;</code>: the extra menu with the given number is activated.
** <code>&quot;zoom-allowed&quot;</code>:当前服务器允许缩放视野时显示;
** <code>&quot;zoom-allowed&quot;</code>: zoom is allowed on this server.
** <code>&quot;vote-active&quot;</code>:当投票进行时显示;
** <code>&quot;vote-active&quot;</code>: a vote is currently active.
** <code>&quot;dummy-allowed&quot;</code>:当前服务器允许分身连接时显示;
** <code>&quot;dummy-allowed&quot;</code>: dummy is allowed on this server.
** <code>&quot;dummy-connected&quot;</code>:当分身已经连接时显示;
** <code>&quot;dummy-connected&quot;</code>: dummy is currently connected.
** <code>&quot;rcon-authed&quot;</code>:成为管理员时显示;
** <code>&quot;rcon-authed&quot;</code>: player is currently authed in rcon.
** <code>&quot;demo-player&quot;</code>:当播放回放时显示;
** <code>&quot;demo-player&quot;</code>: demo player is currently active.
** 所有可见性类型都可以通过在添加<code>-</code>前缀来反转。例如:<code>&quot;-ingame&quot;</code>将在游戏内隐藏,即旁观模式中显示。
** All visibility classes can be inverted by prefixing them with <code>-</code>, e.g. <code>&quot;-ingame&quot;</code> is satisfied when the player is not ingame, i.e. spectating.
* 行为(属性<code>&quot;behavior&quot;</code>):一个用于描述此按钮激活或失效时执行的行为、标签的对象。属性<code>&quot;type&quot;</code>用于区分按钮的行为类型。行为类型有两种,分别是预设好的硬编码以及基于一般的控制台命令(例如:按键绑定)。请根据需求设置按钮的行为类型,按钮的预设行为功能较少,其余所有按钮功能来自于一般的绑定:
* Behavior (attribute <code>&quot;behavior&quot;</code>): an object which describes the behavior of this touch button when it is activated/deactivated as well as its label. The attribute <code>&quot;type&quot;</code> is used to differentiate which type of behavior is used. The behavior is either predefined (hard-coded) or based on generic console commands (like binds). Predefined behavior is only used where necessary, all other buttons are represented as generic binds.
** 预设行为(属性<code>&quot;type&quot;</code><code>&quot;predefined&quot;</code>):此行为类型的按钮只能执行预设行为。属性<code>&quot;id&quot;</code>为一个字符串,用以决定特定的预设行为。下方列出可用的预设行为:
** Predefined behavior (attribute <code>&quot;type&quot;</code> set to <code>&quot;predefined&quot;</code>): The attribute <code>&quot;id&quot;</code> is set to a fixed string value which determines the specific predefined behavior. The following predefined behaviors can be used:
*** <code>&quot;ingame-menu&quot;</code>:松开该按钮时立即打开游戏内菜单;
*** <code>&quot;ingame-menu&quot;</code>: Opens the ingame menu immediately when released.
*** <code>&quot;extra-menu&quot;</code>:附加菜单切换按钮,在可见性为<code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code><code>&quot;extra-menu-5&quot;</code>的这些按钮间循环切换,长按也可打开游戏菜单;
*** <code>&quot;extra-menu&quot;</code>: The extra menu button which toggles visibility of buttons with <code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code> and <code>&quot;extra-menu-5&quot;</code> visibilities. Also opens the ingame menu on long press.
**** 将属性<code>&quot;number&quot;</code>设置为1到5的整数分别对应下面几项的可见性<code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code>, <code>&quot;extra-menu-5&quot;</code>。若导入文件内对应的按钮没有<code>&quot;number&quot;</code>值,客户端会自动将其赋值为<code>&quot;1&quot;</code>。
**** The attribute <code>&quot;number&quot;</code> specifies an integer between 1 and 5 to associate this button with the respective visibilities <code>&quot;extra-menu&quot;</code>, <code>&quot;extra-menu-2&quot;</code>, <code>&quot;extra-menu-3&quot;</code>, <code>&quot;extra-menu-4&quot;</code>, <code>&quot;extra-menu-5&quot;</code>.
*** <code>&quot;emoticon&quot;</code>:打开表情轮盘(此功能无法通过绑定使用);
*** <code>&quot;emoticon&quot;</code>: Opens the emoticon selector (this does not work with binds).
*** <code>&quot;spectate&quot;</code>:打开旁观列表(此功能无法通过绑定使用);
*** <code>&quot;spectate&quot;</code>: Opens the spectator menu (this does not work with binds).
*** <code>&quot;swap-action&quot;</code>:切换'''当前'''直接点击屏幕和虚拟摇杆控制的动作(开火和出钩)
*** <code>&quot;swap-action&quot;</code>: Swaps the active action (fire and hook) for direct touch input and virtual joysticks.
*** <code>&quot;use-action&quot;</code>:以当前瞄准角度执行'''当前'''激活的动作;
*** <code>&quot;use-action&quot;</code>: Uses the active action with the current aiming position.
*** <code>&quot;joystick-action&quot;</code>:按下时会在调整瞄准角度的同时使用'''当前'''激活动作的虚拟摇杆;
*** <code>&quot;joystick-action&quot;</code>: Virtual joystick which uses the active action.
*** <code>&quot;joystick-aim&quot;</code>:按下时仅调整瞄准角度不执行动作的虚拟摇杆;
*** <code>&quot;joystick-aim&quot;</code>: Virtual joystick which only aims without using an action.
*** <code>&quot;joystick-fire&quot;</code>:按下时会在调整瞄准角度的同时开火的虚拟摇杆;
*** <code>&quot;joystick-fire&quot;</code>: Virtual joystick which always uses fire.
*** <code>&quot;joystick-hook&quot;</code>:按下时会在调整瞄准角度的同时出钩的虚拟摇杆。
*** <code>&quot;joystick-hook&quot;</code>: Virtual joystick which always uses hook.
** 绑定行为(属性<code>&quot;type&quot;</code>设置为<code>&quot;bind&quot;</code>)。此行为类型的按钮会执行控制台命令,和常规按键绑定类似:
** Bind behavior (attribute <code>&quot;type&quot;</code> set to <code>&quot;bind&quot;</code>). Buttons with this behavior execute console commands like regular key binds.
*** 属性<code>&quot;label&quot;</code>指定为字符串,用作定义该按钮的标签(即显示在按钮上的文字);
*** The attribute <code>&quot;label&quot;</code> specifies as a string the label of the button.
*** 属性<code>&quot;label-type&quot;</code>指定为字符串,用于决定该按键的标签种类,即属性<code>&quot;label&quot;</code>的处理方法:
*** The attribute <code>&quot;label-type&quot;</code> specifies as a string the type of the label of the button, i.e. how the attribute <code>&quot;label&quot;</code> is interpreted:
**** <code>&quot;plain&quot;</code>:标签会被直接呈现,这也是导入文件内缺少相应按钮的<code>&quot;label-type&quot;</code>值时自动赋予的默认值。;
**** <code>&quot;plain&quot;</code>: Label is used as is.
**** <code>&quot;localized&quot;</code>:标签会本地化,仅对默认按钮存在对应翻译时可用;
**** <code>&quot;localized&quot;</code>: Label is localized. Only usable for the default buttons for which there are translations available.
**** <code>&quot;icon&quot;</code>:标签使用图标。图标必须为UTF-16编码,格式为<code>\uXXXX</code>。例如<code>\uf3ce</code>为手机图标,对应的Unicode编码为<code>f3ce</code>。注意该图标必须来自于DDNet或在[https://fontawesome.com/search?o=r&m=free Font Awesome Free]上可用。
**** <code>&quot;icon&quot;</code>: Icon font is used for the label. Icons must be encoded in UTF-16 using <code>\uXXXX</code>, e.g. <code>\uf3ce</code> for the mobile phone icon which has unicode <code>f3ce</code>. Note that the icon must be available in the icon font that comes with DDNet, [https://fontawesome.com/search?o=r&m=free Font Awesome Free].
*** 属性<code>&quot;command&quot;</code>指定为可以在控制台执行的命令的字符串,与绑定类似。例如<code>&quot;+fire&quot;</code>为按钮添加开火动作。
*** The attribute <code>&quot;command&quot;</code> specifies as a string the command to execute in the console like a bind when this button is used, e.g. <code>&quot;+fire&quot;</code> for a button that uses the fire action.
** 绑定切换行为(属性<code>type</code>设置为<code>&quot;bind-toggle&quot;</code>)。此行为类型的按钮会循环触发两个或更多的命令。
** Bind toggle behavior (attribute <code>type</code> set to <code>&quot;bind-toggle&quot;</code>). Buttons with this behavior cycle between executing one of two or more specified commands.
*** 属性<code>&quot;commands&quot;</code>指定为两个及以上的指令列表,依据排列的先后顺序依次触发和显示。单个指令为一个拥有属性<code>&quot;label&quot;</code><code>&quot;label-type&quot;</code><code>&quot;command&quot;</code>的对象,与上述绑定行为的定义基本一致,但是在指令列表中必须至少有两个指令对象。
*** The attribute <code>&quot;commands&quot;</code> specifies an array of two or more commands in the order in which they are shown and executed. Each command is an object with the attributes <code>&quot;label&quot;</code>, <code>&quot;label-type&quot;</code> and <code>&quot;command&quot;</code> which are defined the same as for the bind behavior described above. At least two command objects must be specified in the array.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
除此之外,根对象还有以下属性:
The root object additionally has the following attributes:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* <code>&quot;direct-touch-ingame&quot;</code>:定义游戏内点击屏幕空白处时做出的动作。可用的值有:
* <code>&quot;direct-touch-ingame&quot;</code>: specifies the mode of direct touch input while ingame. Possible values:
** <code>&quot;disabled&quot;</code>:点击屏幕空白部分不会做出任何动作。这也意味着你需要使用虚拟摇杆。
** <code>&quot;disabled&quot;</code>: Direct touch input is not used while ingame. This means a virtual joystick is necessary.
** <code>&quot;action&quot;</code>:点击屏幕空白部分会使用当前激活的动作(见上)。
** <code>&quot;action&quot;</code>: Direct touch input uses the active action (see above).
** <code>&quot;aim&quot;</code>:点击屏幕空白部分仅会改变瞄准角度。这意味着你需要另一个按键来执行必要的动作。
** <code>&quot;aim&quot;</code>: Direct touch input only changes the aiming position without using an action. This means separate buttons for using the actions are necessary.
** <code>&quot;fire&quot;</code>:点击屏幕空白部分会改变瞄准角度并开火。
** <code>&quot;fire&quot;</code>: Direct touch input always uses fire.
** <code>&quot;hook&quot;</code>:点击屏幕空白部分会改变瞄准角度并出钩。
** <code>&quot;hook&quot;</code>: Direct touch input always uses hook.
* <code>&quot;direct-touch-spectate&quot;</code>:定义旁观时点击屏幕空白部分时做出的行为。可用的值有:
* <code>&quot;direct-touch-spectate&quot;</code>: specifies the mode of direct touch input while spectating. Possible values:
** <code>&quot;disabled&quot;</code>:点击屏幕空白部分不会做出任何动作。这也意味着你需要使用虚拟摇杆。
** <code>&quot;disabled&quot;</code>: Direct touch input is not used while spectating. This means a virtual joystick is necessary.
** <code>&quot;aim&quot;</code>:在屏幕空白部分滑动可以旁观。
** <code>&quot;aim&quot;</code>: Direct touch input is used for spectating.
* <code>&quot;background-color-inactive&quot;</code> (在DDNet 19.0加入):定义未激活按钮的背景颜色。颜色的格式相关细节见下。
</div>
* <code>&quot;background-color-active&quot;</code> (在DDNet 19.0加入):定义激活按钮的背景颜色。颜色的格式相关细节见下。


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Color_format"></span>
== Ingame menu buttons ==
=== 颜色格式 ===
</div>


[[File:Touch Controls Menu Bar.png|thumb|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of the additional buttons in the ingame menu when touch controls are enabled.</span>]]
颜色的格式是类似于<code>RRGGBBAA</code>,<code>RRGGBB</code>,<code>RGBA</code> 和 <code>RGB</code>的十六进制字符串,且没有像<code>#</code>一类的前缀,例如:<code>&quot;A526C440&quot;</code>。若没有alpha(透明度)的值,则默认为完全不透明。


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Ingame_menu_buttons"></span>
In addition to the separate on-screen touch controls, a second row is added to the main page of the ingame menu when <code>cl_touch_controls</code> is enabled for less frequently used functions which are otherwise not usable without a keyboard:
== 游戏菜单栏 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[[File:Touch Controls Menu Bar.png|thumb|触控模式下显示游戏内菜单栏时的游戏截图。]]
* Buttons to open the local and remote consoles. Opening the local console without the touch controls is useful because error messages would be shown there if the touch controls configuration could not be loaded.
* Button to close the menu, which is more convenient than using the virtual back button if it's not always shown.
* Checkbox for toggling the touch controls editor UI (see below).
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
除了菜单栏底下的触控按钮,将<code>cl_touch_controls</code>设置为 1 (推荐值)后,在菜单栏下方第二行还会出现一些不常用但重要又需要键盘才能使用的功能:
== Ingame touch controls editor ==
</div>


[[File:Touch Controls Menu Editor.png|thumb|<span lang="en" dir="ltr" class="mw-content-ltr">Screenshot of the ingame touch controls editor user interface.</span>]]
* 打开本地和远程控制台的按钮:当绑定控制台开关的触控按键失效时,仍可以快捷查看显示在控制台的错误信息;
* 菜单关闭按钮:在不方便使用返回键时更便于关闭菜单。
* 键位编辑器开关(详情见下方)。


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Ingame_touch_controls_editor"></span>
The user interface to adjust the touch controls is rendered over the main screen of the ingame menu when enabled. For now, the touch controls editor is limited to basic configuration management functions.
== 触控编辑器 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
[[File:Touch Controls Menu Editor.png|thumb|游戏菜单栏中触控编辑器的截图。]]
* Saving the configuration to the <code>touch_controls.json</code> file in the config directory.
* Discarding the current changes by reloading the <code>touch_controls.json</code> file from the config directory.
* Restoring the default configuration by reloading the <code>touch_controls.json</code> file from the data directory.
* Displaying whether there are unsaved changes.
* Importing and exporting the configuration from and to the clipboard. This is the only way to edit the configuration on newer Android versions, as editing files within apps' storage is not possible anymore.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
触控编辑器在被启用后会在游戏菜单栏的主屏幕上显示,目前只有如下有限的触控设置管理功能:
Furthermore, the global touch controls settings can be adjusted in this UI:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* 保存更改:将当前触控设置保存到配置目录下的<code>touch_controls.json</code>文件中;
* The direct touch input modes while ingame and spectating (see Touch button configuration format) can be adjusted using dropdown menus.
* 放弃更改:撤销当前对触控设置的改变,并重新加载配置目录下的<code>touch_controls.json</code>文件;
</div>
* 恢复默认设置:从数据目录中加载<code>touch_controls.json</code>文件来将键位初始化;
* 右上角留白用于提醒当前是否有设置未被保存;
* 从剪贴板导入设置,或将设置导出至剪贴板。在较新的安卓版本中应用数据无法直接修改,因此导入写好的设置文件是修改键位的唯一方法。


<div lang="en" dir="ltr" class="mw-content-ltr">
另外,对屏幕空白处进行操作的模式也可以在该界面被修改:
While the touch controls editor is active, all touch buttons are shown regardless of their visibilities, to better support arranging the buttons.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* “直接触摸操作”下拉菜单调整的正是上方提及的游戏模式参数<code>direct-touch-ingame</code>和旁观模式参数<code>direct-touch-spectate</code>(参见上方,自定义触控键位设置)。
=== Adjusting the controls ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
当触控编辑器打开时,所有按钮无视可见性属性并全部显示,从而让玩家更易观察和调整按键位置。
# Export the touch configuration to the clipboard.
# Save the clipboard to a file so you can more easily edit it. You should also do this to have a backup of your configuration!
# Edit the configuration (see above for details about the format).
# Copy the edited configuration to the clipboard and import it in the client again. If the configuration could not be loaded successfully, check the local console for error messages containing <code>touch_controls</code> and fix the configuration accordingly. Use online tools for JSON validation and formatting.
# Save the changes in the client when you are done. You can also discard your changes or revert to the default if you messed up.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Adjusting_the_controls"></span>
A more convenient user interface to edit the touch controls directly in the client is planned.
== 键位调整 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
# 导出当前键位至剪贴板。
Note: You can also edit the file <code>touch_controls.json</code> in the config directory directly instead of exporting/importing to/from the clipboard, but this is not supported on Android.
# 将剪贴板内容保存为文件便于进行修改。请记得给您的键位设置留下备份!
</div>
# 修改键位设置(相关格式细节请参见上方)。
# 复制编辑好的内容至剪贴板,然后导入到客户端。若导入失败,在本地控制台内找到包含<code>touch_controls</code>的错误消息,据此更正错误。可以用在线工具帮助更正JSON文本的错误和格式。
# 修改完成后记得在客户端中保存您的设置。如果出现问题,您也可以选择撤销更改或者初始化键位。


<div lang="en" dir="ltr" class="mw-content-ltr">
目前正计划开发一个可在客户端内直接修改键位的便捷界面。
<span id="examples"></span>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
注意:如果没有安卓系统限制,您也可以直接更改配置目录中的<code>touch_controls.json</code>文件来修改键位,而不用反复导出导入剪贴板。
== Examples ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Examples"></span>
Example for the overall structure of the touch configuration:
== 示例 ==
</div>
 
全局键位格式设置的示例:


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="json">{
<syntaxhighlight lang="json">{
     "direct-touch-ingame": "action",
     "direct-touch-ingame": "action",
     "direct-touch-spectate": "aim",
     "direct-touch-spectate": "aim",
    "background-color-inactive": "00000040",
"background-color-active": "33333340",
     "touch-buttons": [
     "touch-buttons": [
         ...
         ...
     ]
     ]
}</syntaxhighlight>
}</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
示例:带有<code>&quot;bind&quot;</code>行为的按钮,会在对话框返回一条消息:
Example button with <code>&quot;bind&quot;</code> behavior that echos a message in chat:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="json">{
<syntaxhighlight lang="json">{
     "x": 500000,
     "x": 500000,
Line 251: Line 181:
     }
     }
}</syntaxhighlight>
}</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
示例:带有<code>&quot;predefined&quot;</code>行为的按钮,表现为一个会执行当前被激活的行为的虚拟摇杆:
Example button with <code>&quot;predefined&quot;</code> behavior for a virtual joystick that uses the active action:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="json">{
<syntaxhighlight lang="json">{
     "x": 755000,
     "x": 755000,
Line 272: Line 198:
     }
     }
}</syntaxhighlight>
}</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
示例:带有<code>&quot;bind-toggle&quot;</code>行为的按钮,会在对话框循环返回三条不同的消息:
Example button with <code>&quot;bind-toggle&quot;</code> behavior that switches between echoing three different messages in chat:
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="json">{
<syntaxhighlight lang="json">{
     "x": 600000,
     "x": 600000,
Line 308: Line 230:
     }
     }
}</syntaxhighlight>
}</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Known_issues"></span>
== Known issues ==
== 一些已知的问题 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* '''安卓的问题''':同时按下三根手指会导致所有手指被立即同时松开。
* '''Problem on Android''': Pressing down 3 or more fingers at the same times causes all fingers to be released immediately.
** '''解决方法''':原因是你手机自带的全局多指手势动作(设置里面搜&quot;三指&quot;)。具体地,关闭&quot;三指下滑截屏&quot;&quot;三指长按截屏&quot;&quot;三指上滑进入菜单&quot;功能。
** '''Solution''': This is caused by features of your phone that handle global gestures with multiple fingers. Open the Settings app and disable gesture features that involve 3 or more fingers (search for &quot;3 fingers&quot;). In particular, disable the &quot;Swipe down with 3 fingers to take screenshot&quot;, &quot;Touch and hold with 3 fingers to take screenshot&quot; and &quot;Swipe up with 3 fingers to enter Split View&quot; features.
* '''安卓的问题''':有时候点击屏幕顶端15%位置会无响应或响应不连续。
* '''Problem on Android''': Rarely, touching in the top around 15% of the screen does not work at all or very inconsistently.
** '''解决方法''':目前不清楚原因。一般可以重启应用,返回手机主界面也可能可以修复该问题。
** '''Solution''': It is unclear what causes this. It should be fixed by restarting the app. Going back to the home screen may also fix it.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Implementation_details"></span>
== Implementation details ==
== 实现细则 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
下面是开发者须知的触屏操控的实现细则:
These are details about the implementation of the touch controls intended for developers.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
游戏内触屏操控由单独的客户端组件<code>CTouchControls</code>实现,该组件位于<code>src/game/client/components/touch_controls.cpp</code><code>src/game/client/components/touch_concontrol.h</code>文件中。如果一些按钮的功能可以直接通过绑定实现,尽量不要增加预设行为让代码变复杂。
The ingame touch controls are implemented in a separate client component <code>CTouchControls</code> in the files <code>src/game/client/components/touch_controls.cpp</code> and <code>src/game/client/components/touch_controls.h</code>. Whenever possible, binds are used directly as button behavior instead of using predefined behavior to reduce complexity.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
当您想在分叉客户端中添加自己的按键行为时,建议在新增的形状、可见性和行为等等之前加上您的分叉的名称。例如:用 <code>您的分叉.octagon</code> 来表示您添加的八边形按键,预防与未来的版本更新发生冲突。
When adding your own button behavior in a forked client it is recommended to prefix names of new shape, visibility, behavior etc. with the name of your fork, e.g. <code>myfork.octagon</code> if you add a new shape for octogonal buttons, to prevent conflicts in future versions.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
为其他的游戏内客户端组件例如表情轮盘和旁观菜单添加触屏操控支持时,请使用<code>CUi::UpdateTouchState</code>这一触摸状态监测函数。
To add touch support for other ingame client components like the emoticon wheel and spectator menu, use the <code>CUi::UpdateTouchState</code> function like for the emoticon wheel and spectator menu. Ensure that your component handles <code>KEY_ESCAPE</code> to close itself, which also corresponds to the Back-button on Android. Note that only one component may use the touch state in each frame, so it is not possible to hold an ingame touch button and use another component like the emoticon wheel at the same time with other fingers. Instead, the respective predefined touch button behavior (e.g. <code>CSpectateTouchButtonBehavior</code>) only activates the ingame component (e.g. the spectator menu) in its <code>OnDeactivate</code> function but does not deactivate it again. Activating the component in the <code>OnActivate</code> function already would cause the finger that activated the button to also affect the activated component.
确保您的组件能在接收到<code>KEY_ESCAPE</code>信号时立即关闭,即安卓上的返回键。
</div>
注意在每一游戏帧中,只能有一个组件可以响应触摸状态,因此在占用游戏内触控组件的同时无法使用另一个组件的内容,例如按住一个游戏内按钮就无法使用表情轮盘。
然而,按钮的预设行为(例如<code>CSpectateTouchButtonBehavior</code>)在调用<code>OnDeactivate</code>函数打开游戏内的组件(例如旁观菜单)之后不会禁用它,此时手指按下会同时影响按钮和它打开的组件。


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="References"></span>
== References ==
== 参考资料 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* 默认键位:https://github.com/ddnet/ddnet/blob/69c92a79e6bab9f9390245f518c5340222c544dc/data/touch_controls.json
* Default touch button configuration: https://github.com/ddnet/ddnet/blob/84b1c3c49c8d97a6911da34424d2023879ccdaf8/data/touch_controls.json
* 添加触摸操控至引擎和界面的拉取请求:https://github.com/ddnet/ddnet/pull/8621
* Pull Request adding Touch controls to engine and UI: https://github.com/ddnet/ddnet/pull/8621
* 添加游戏内触摸操控的拉取请求:https://github.com/ddnet/ddnet/pull/8632
* Pull Request adding Ingame touch controls: https://github.com/ddnet/ddnet/pull/8632
* 添加表情和旁观相关的拉取请求:https://github.com/ddnet/ddnet/pull/8801
* Pull Request adding Emoticon and Spectate touch controls: https://github.com/ddnet/ddnet/pull/8801
</div>

Latest revision as of 16:13, 18 March 2025

触屏操控从DDNet 18.8版本客户端开始启用,这也标志着最近期的首个DDNet安卓版发布。早期的安卓版本为DDNet 9.3.1,该版本已有一个单独教程。以下教程将只考虑18.8以后版本的触屏操控。

在用户界面可以进行的触屏操控如下:

  • 直接点击屏幕某位置:视为移动光标至该位置并用左键单击;
  • 长按屏幕某位置至少0.5秒:视为用鼠标右键单击该位置,轻微移动手指不影响判定;
  • 用两根手指长按屏幕并上下滑动:视为在该位置滚动鼠标滚轮,可以上下滚动列表如服务器浏览器和控制台;
  • 在安卓设备上触发了(虚拟)返回键:视为使用了Esc键,可关闭菜单等。

在游戏界面内的触屏操控可以通过配置参数cl_touch_controls来开启/关闭,此参数在安卓设备上默认为1,在其他平台则是0。触屏操控在其他支持触控的平台上应该也能正常使用,但此教程主要针对安卓设备进行测试。

游戏内触屏操控包含许多屏幕按钮。不同按钮根据功能不同仅会在可用时显示,例如移动键仅会在进行游玩时显示。

默认触控按键配置

游戏内默认触控键位的截图。

左、右移动和跳跃键的位置分布形如,和键盘上的WASD分布类似。

关于开火和出钩的操作,游戏内默认提供了两种操作方式:

  1. 通过直接点击屏幕空白处,可以将准星直接移动到点击处并立即朝准星处开火或出钩,此时不松手拖动可以控制瞄准角度或不松钩;
  2. 通过拖动虚拟摇杆按钮,可以将准星以玩家位置为原点朝拖动方向移动,同时开火或出钩。

在两种操作方式下都可以点击右上角的“当前”功能按钮切换为开火或出钩模式。当按住虚拟摇杆时,“当前”按钮将变成直接触发另一功能的按钮,按钮上的文字提示也会相应改变。

对于游戏或旁观时,可以分别设置直接点击屏幕的功能,通过禁用“直接触摸操作”可以避免游戏中使用摇杆的同时点击误触。

旁观模式下,如果将直接触屏操控设置为瞄准,则可以类似图片一样拖动地图进行观察;如果设置为禁用,则只能在摇杆范围内拖动。

默认情况下左上角有两个按钮用于切换上一武器和下一武器。

显示全部默认键位的预览图

左上角的字形按钮是游戏内菜单按钮,可用于显示或隐藏更多按钮,这些按钮大部分与游戏操作无关。包括显示计分板、表情轮盘、旁观列表、全局聊天、队伍内聊天的按钮,以及投票按钮和视野缩放按钮。长按菜单按钮松手时会打开类似于电脑按下 Esc 后的游戏内菜单,当然安卓设备也可以使用返回键代替。

连接分身后,右上角会出现切换分身的按钮。

显示更多按钮时,可以打开表情轮盘或旁观列表等菜单,点击表情发送或点击旁观对象观察,点击空白处则可以关闭菜单,安卓设备可以使用返回键关闭。但是目前还无法实现长按按钮时显示菜单、松手自动关闭的功能,并且也不适合用于旁观列表。

自定义触控键位设置

默认键位保存在touch_controls.json文件中,安卓版本下该文件位于data目录,高版本安卓设备一般会禁止用户修改这一目录下的文件。因此如果您要进行键位自定义,需要通过在配置目录中创建同名为touch_controls.json的文件,利用更高的优先度来覆盖默认设置。

键位配置文件是JSON格式的文本文件,推荐在掌握一定JSON基础的情况下阅读下方教程,在配置JSON文件时必须保证有效性。关于JSON格式的相关教程和工具可在网络上找到,下面也会涉及到许多相关术语,当然也可以将游戏配置文件当作练习对象来学习JSON,但是建议在进行实操前先做好重要文件的备份。本教程涉及的JSON配置文件的结构如下:

JSON文件的根元素必须是一个对象。该对象的属性"touch-buttons"可定义一系列按钮对象。按钮对象都可调节下列属性:

  • 位置和大小(属性"x", "y", "w", "h"):屏幕显示区域将被平均划分为1000000x1000000的网格,前面提到的四个属性为整数,大小分别表示按钮的中心点横纵坐标和宽度高度。网格的实际单位长度会根据游戏窗口大小及屏幕比例实时拉伸,因此对于不同的屏幕设备,只要屏幕纵横比差异不大,按钮布局就不会变得特别不合理。
  • 形状 (属性"shape"):用于决定按钮形状:
    • "rect":矩形;
    • "circle":圆形,该按钮的高度和宽度会自动调整为一致大小。
  • 可见性(属性"visibilities"):该属性为空意味着按钮总是显示在屏幕上。如果设置了某些属性,按钮将只会在满足特定条件时显示,其它情况下隐藏,目前已预设一系列可选的可见性类型如下:
    • "ingame":仅在游戏内显示,即在旁观模式下将会隐藏;
    • "extra-menu", "extra-menu-2", "extra-menu-3", "extra-menu-4", "extra-menu-5":在打开对应序号的附加菜单时显示;
    • "zoom-allowed":当前服务器允许缩放视野时显示;
    • "vote-active":当投票进行时显示;
    • "dummy-allowed":当前服务器允许分身连接时显示;
    • "dummy-connected":当分身已经连接时显示;
    • "rcon-authed":成为管理员时显示;
    • "demo-player":当播放回放时显示;
    • 所有可见性类型都可以通过在添加-前缀来反转。例如:"-ingame"将在游戏内隐藏,即旁观模式中显示。
  • 行为(属性"behavior"):一个用于描述此按钮激活或失效时执行的行为、标签的对象。属性"type"用于区分按钮的行为类型。行为类型有两种,分别是预设好的硬编码以及基于一般的控制台命令(例如:按键绑定)。请根据需求设置按钮的行为类型,按钮的预设行为功能较少,其余所有按钮功能来自于一般的绑定:
    • 预设行为(属性"type""predefined"):此行为类型的按钮只能执行预设行为。属性"id"为一个字符串,用以决定特定的预设行为。下方列出可用的预设行为:
      • "ingame-menu":松开该按钮时立即打开游戏内菜单;
      • "extra-menu":附加菜单切换按钮,在可见性为"extra-menu", "extra-menu-2", "extra-menu-3", "extra-menu-4""extra-menu-5"的这些按钮间循环切换,长按也可打开游戏菜单;
        • 将属性"number"设置为1到5的整数分别对应下面几项的可见性"extra-menu", "extra-menu-2", "extra-menu-3", "extra-menu-4", "extra-menu-5"。若导入文件内对应的按钮没有"number"值,客户端会自动将其赋值为"1"
      • "emoticon":打开表情轮盘(此功能无法通过绑定使用);
      • "spectate":打开旁观列表(此功能无法通过绑定使用);
      • "swap-action":切换当前直接点击屏幕和虚拟摇杆控制的动作(开火和出钩);
      • "use-action":以当前瞄准角度执行当前激活的动作;
      • "joystick-action":按下时会在调整瞄准角度的同时使用当前激活动作的虚拟摇杆;
      • "joystick-aim":按下时仅调整瞄准角度不执行动作的虚拟摇杆;
      • "joystick-fire":按下时会在调整瞄准角度的同时开火的虚拟摇杆;
      • "joystick-hook":按下时会在调整瞄准角度的同时出钩的虚拟摇杆。
    • 绑定行为(属性"type"设置为"bind")。此行为类型的按钮会执行控制台命令,和常规按键绑定类似:
      • 属性"label"指定为字符串,用作定义该按钮的标签(即显示在按钮上的文字);
      • 属性"label-type"指定为字符串,用于决定该按键的标签种类,即属性"label"的处理方法:
        • "plain":标签会被直接呈现,这也是导入文件内缺少相应按钮的"label-type"值时自动赋予的默认值。;
        • "localized":标签会本地化,仅对默认按钮存在对应翻译时可用;
        • "icon":标签使用图标。图标必须为UTF-16编码,格式为\uXXXX。例如\uf3ce为手机图标,对应的Unicode编码为f3ce。注意该图标必须来自于DDNet或在Font Awesome Free上可用。
      • 属性"command"指定为可以在控制台执行的命令的字符串,与绑定类似。例如"+fire"为按钮添加开火动作。
    • 绑定切换行为(属性type设置为"bind-toggle")。此行为类型的按钮会循环触发两个或更多的命令。
      • 属性"commands"指定为两个及以上的指令列表,依据排列的先后顺序依次触发和显示。单个指令为一个拥有属性"label""label-type""command"的对象,与上述绑定行为的定义基本一致,但是在指令列表中必须至少有两个指令对象。

除此之外,根对象还有以下属性:

  • "direct-touch-ingame":定义游戏内点击屏幕空白处时做出的动作。可用的值有:
    • "disabled":点击屏幕空白部分不会做出任何动作。这也意味着你需要使用虚拟摇杆。
    • "action":点击屏幕空白部分会使用当前激活的动作(见上)。
    • "aim":点击屏幕空白部分仅会改变瞄准角度。这意味着你需要另一个按键来执行必要的动作。
    • "fire":点击屏幕空白部分会改变瞄准角度并开火。
    • "hook":点击屏幕空白部分会改变瞄准角度并出钩。
  • "direct-touch-spectate":定义旁观时点击屏幕空白部分时做出的行为。可用的值有:
    • "disabled":点击屏幕空白部分不会做出任何动作。这也意味着你需要使用虚拟摇杆。
    • "aim":在屏幕空白部分滑动可以旁观。
  • "background-color-inactive" (在DDNet 19.0加入):定义未激活按钮的背景颜色。颜色的格式相关细节见下。
  • "background-color-active" (在DDNet 19.0加入):定义激活按钮的背景颜色。颜色的格式相关细节见下。

颜色格式

颜色的格式是类似于RRGGBBAARRGGBBRGBARGB的十六进制字符串,且没有像#一类的前缀,例如:"A526C440"。若没有alpha(透明度)的值,则默认为完全不透明。

游戏菜单栏

触控模式下显示游戏内菜单栏时的游戏截图。

除了菜单栏底下的触控按钮,将cl_touch_controls设置为 1 (推荐值)后,在菜单栏下方第二行还会出现一些不常用但重要又需要键盘才能使用的功能:

  • 打开本地和远程控制台的按钮:当绑定控制台开关的触控按键失效时,仍可以快捷查看显示在控制台的错误信息;
  • 菜单关闭按钮:在不方便使用返回键时更便于关闭菜单。
  • 键位编辑器开关(详情见下方)。

触控编辑器

游戏菜单栏中触控编辑器的截图。

触控编辑器在被启用后会在游戏菜单栏的主屏幕上显示,目前只有如下有限的触控设置管理功能:

  • 保存更改:将当前触控设置保存到配置目录下的touch_controls.json文件中;
  • 放弃更改:撤销当前对触控设置的改变,并重新加载配置目录下的touch_controls.json文件;
  • 恢复默认设置:从数据目录中加载touch_controls.json文件来将键位初始化;
  • 右上角留白用于提醒当前是否有设置未被保存;
  • 从剪贴板导入设置,或将设置导出至剪贴板。在较新的安卓版本中应用数据无法直接修改,因此导入写好的设置文件是修改键位的唯一方法。

另外,对屏幕空白处进行操作的模式也可以在该界面被修改:

  • “直接触摸操作”下拉菜单调整的正是上方提及的游戏模式参数direct-touch-ingame和旁观模式参数direct-touch-spectate(参见上方,自定义触控键位设置)。

当触控编辑器打开时,所有按钮无视可见性属性并全部显示,从而让玩家更易观察和调整按键位置。

键位调整

  1. 导出当前键位至剪贴板。
  2. 将剪贴板内容保存为文件便于进行修改。请记得给您的键位设置留下备份!
  3. 修改键位设置(相关格式细节请参见上方)。
  4. 复制编辑好的内容至剪贴板,然后导入到客户端。若导入失败,在本地控制台内找到包含touch_controls的错误消息,据此更正错误。可以用在线工具帮助更正JSON文本的错误和格式。
  5. 修改完成后记得在客户端中保存您的设置。如果出现问题,您也可以选择撤销更改或者初始化键位。

目前正计划开发一个可在客户端内直接修改键位的便捷界面。

注意:如果没有安卓系统限制,您也可以直接更改配置目录中的touch_controls.json文件来修改键位,而不用反复导出导入剪贴板。

示例

全局键位格式设置的示例:

{
    "direct-touch-ingame": "action",
    "direct-touch-spectate": "aim",
    "background-color-inactive": "00000040",
	"background-color-active": "33333340",
    "touch-buttons": [
        ...
    ]
}

示例:带有"bind"行为的按钮,会在对话框返回一条消息:

{
    "x": 500000,
    "y": 500000,
    "w": 100000,
    "h": 100000,
    "shape": "rect",
    "visibilities": [
    ],
    "behavior": {
        "type": "bind",
        "label": "Example",
        "label-type": "plain",
        "command": "echo Hello world!"
    }
}

示例:带有"predefined"行为的按钮,表现为一个会执行当前被激活的行为的虚拟摇杆:

{
    "x": 755000,
    "y": 580000,
    "w": 225000,
    "h": 400000,
    "shape": "circle",
    "visibilities": [
        "ingame"
    ],
    "behavior": {
        "type": "predefined",
        "id": "joystick-action"
    }
}

示例:带有"bind-toggle"行为的按钮,会在对话框循环返回三条不同的消息:

{
    "x": 600000,
    "y": 200000,
    "w": 100000,
    "h": 100000,
    "shape": "rect",
    "visibilities": [
    ],
    "behavior": {
        "type": "bind-toggle",
        "commands": [
            {
                "label": "Echo 1",
                "label-type": "plain",
                "command": "echo 1"
            },
            {
                "label": "Echo 2",
                "label-type": "plain",
                "command": "echo 2"
            },
            {
                "label": "Echo 3",
                "label-type": "plain",
                "command": "echo 3"
            }
        ]
    }
}

一些已知的问题

  • 安卓的问题:同时按下三根手指会导致所有手指被立即同时松开。
    • 解决方法:原因是你手机自带的全局多指手势动作(设置里面搜"三指")。具体地,关闭"三指下滑截屏","三指长按截屏","三指上滑进入菜单"功能。
  • 安卓的问题:有时候点击屏幕顶端15%位置会无响应或响应不连续。
    • 解决方法:目前不清楚原因。一般可以重启应用,返回手机主界面也可能可以修复该问题。

实现细则

下面是开发者须知的触屏操控的实现细则:

游戏内触屏操控由单独的客户端组件CTouchControls实现,该组件位于src/game/client/components/touch_controls.cppsrc/game/client/components/touch_concontrol.h文件中。如果一些按钮的功能可以直接通过绑定实现,尽量不要增加预设行为让代码变复杂。

当您想在分叉客户端中添加自己的按键行为时,建议在新增的形状、可见性和行为等等之前加上您的分叉的名称。例如:用 您的分叉.octagon 来表示您添加的八边形按键,预防与未来的版本更新发生冲突。

为其他的游戏内客户端组件例如表情轮盘和旁观菜单添加触屏操控支持时,请使用CUi::UpdateTouchState这一触摸状态监测函数。 确保您的组件能在接收到KEY_ESCAPE信号时立即关闭,即安卓上的返回键。 注意在每一游戏帧中,只能有一个组件可以响应触摸状态,因此在占用游戏内触控组件的同时无法使用另一个组件的内容,例如按住一个游戏内按钮就无法使用表情轮盘。 然而,按钮的预设行为(例如CSpectateTouchButtonBehavior)在调用OnDeactivate函数打开游戏内的组件(例如旁观菜单)之后不会禁用它,此时手指按下会同时影响按钮和它打开的组件。

参考资料