Android: Add 'aux' button (#7477)

Add 'aux' button.
Use joystick to trigger 'aux' button when forward and out of main circle, by enabling
'virtual_joystick_triggers_aux' setting.
This commit is contained in:
Muhammad Rifqi Priyo Susanto 2018-07-11 05:33:40 +07:00 committed by Paramat
parent f7a8e75765
commit 7ebc229b0d
5 changed files with 41 additions and 10 deletions

@ -126,6 +126,10 @@ touchscreen_threshold (Touch screen threshold) int 20 0 100
# If disabled, virtual joystick will center to first-touch's position.
fixed_virtual_joystick (Fixed virtual joystick) bool false
# (Android) Use virtual joystick to trigger "aux" button.
# If enabled, virtual joystick will also tap "aux" button when out of main circle.
virtual_joystick_triggers_aux (Virtual joystick triggers aux button) bool false
# Enable joysticks
enable_joysticks (Enable joysticks) bool false

@ -409,6 +409,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("TMPFolder","/sdcard/" PROJECT_NAME_C "/tmp/");
settings->setDefault("touchscreen_threshold","20");
settings->setDefault("fixed_virtual_joystick", "false");
settings->setDefault("virtual_joystick_triggers_aux", "false");
settings->setDefault("smooth_lighting", "false");
settings->setDefault("max_simultaneous_block_sends_per_client", "3");
settings->setDefault("emergequeue_limit_diskonly", "8");

@ -42,7 +42,8 @@ using namespace irr::core;
const char **touchgui_button_imagenames = (const char *[]) {
"jump_btn.png",
"down.png",
"zoom.png"
"zoom.png",
"aux_btn.png"
};
const char **touchgui_joystick_imagenames = (const char *[]) {
@ -82,6 +83,9 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
case zoom_id:
key = "zoom";
break;
case special1_id:
key = "special1";
break;
case fly_id:
key = "freemove";
break;
@ -454,6 +458,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver)
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick");
m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux");
m_screensize = m_device->getVideoDriver()->getScreenSize();
}
@ -555,11 +560,20 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
// init zoom button
initButton(zoom_id,
rect<s32>(m_screensize.X - (1.25 * button_size),
m_screensize.Y - (3 * button_size),
m_screensize.Y - (4 * button_size),
m_screensize.X - (0.25 * button_size),
m_screensize.Y - (2 * button_size)),
m_screensize.Y - (3 * button_size)),
L"z", false);
// init special1 button
if (!m_joystick_triggers_special1)
initButton(special1_id,
rect<s32>(m_screensize.X - (1.25 * button_size),
m_screensize.Y - (2.5 * button_size),
m_screensize.X - (0.25 * button_size),
m_screensize.Y - (1.5 * button_size)),
L"spc1", false);
m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
v2s32(m_screensize.X - (button_size / 2),
m_screensize.Y - ((SETTINGS_BAR_Y_OFFSET + 1) * button_size)
@ -973,7 +987,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
angle = fmod(angle + 180 + 22.5, 360);
// reset state before applying
for (unsigned int i = 0; i < 4; i ++)
for (unsigned int i = 0; i < 5; i ++)
m_joystick_status[i] = false;
if (distance <= m_touchscreen_threshold) {
@ -1000,8 +1014,9 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_joystick_status[j_left] = true;
}
// move joystick "button"
if (distance > button_size) {
m_joystick_status[j_special1] = true;
// move joystick "button"
s32 ndx = (s32) button_size * dx / distance - (s32) button_size / 2;
s32 ndy = (s32) button_size * dy / distance - (s32) button_size / 2;
if (m_fixed_joystick) {
@ -1125,7 +1140,10 @@ bool TouchScreenGUI::doubleTapDetection()
void TouchScreenGUI::applyJoystickStatus()
{
for (unsigned int i = 0; i < 4; i ++) {
for (unsigned int i = 0; i < 5; i ++) {
if (i == 4 && !m_joystick_triggers_special1)
continue;
SEvent translated{};
translated.EventType = irr::EET_KEY_INPUT_EVENT;
translated.KeyInput.Key = id2keycode(m_joystick_names[i]);

@ -37,6 +37,7 @@ typedef enum {
jump_id = 0,
crunch_id,
zoom_id,
special1_id,
after_last_element_id,
settings_starter_id,
rare_controls_starter_id,
@ -60,7 +61,13 @@ typedef enum {
joystick_center_id
} touch_gui_button_id;
typedef enum { j_forward = 0, j_backward, j_left, j_right } touch_gui_joystick_move_id;
typedef enum {
j_forward = 0,
j_backward,
j_left,
j_right,
j_special1
} touch_gui_joystick_move_id;
typedef enum {
AHBB_Dir_Top_Bottom,
@ -206,9 +213,9 @@ private:
double m_camera_pitch = 0.0;
// forward, backward, left, right
touch_gui_button_id m_joystick_names[4] = {
forward_id, backward_id, left_id, right_id};
bool m_joystick_status[4] = {false, false, false, false};
touch_gui_button_id m_joystick_names[5] = {
forward_id, backward_id, left_id, right_id, special1_id};
bool m_joystick_status[5] = {false, false, false, false, false};
/*!
* A line starting at the camera and pointing towards the
@ -227,6 +234,7 @@ private:
int m_joystick_id = -1;
bool m_joystick_has_really_moved = false;
bool m_fixed_joystick = false;
bool m_joystick_triggers_special1 = false;
button_info *m_joystick_btn_off = nullptr;
button_info *m_joystick_btn_bg = nullptr;
button_info *m_joystick_btn_center = nullptr;

BIN
textures/base/pack/aux_btn.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB