forked from Mirrorlandia_minetest/minetest
Android: Modify touch screen GUI's buttons (#7240)
* Android: Add zoom, minimap, and toggle chat button Zoom button is put above jump button. Minimap and toggle chat button are put in settings bar. * Jump button is rotated down button * Move three buttons on the right screen higher
This commit is contained in:
parent
cca925377b
commit
b1e58c9c35
@ -31,6 +31,14 @@ erlehmann:
|
||||
JRottm
|
||||
textures/base/pack/player_marker.png
|
||||
|
||||
srifqi
|
||||
textures/base/pack/chat_hide_btn.png
|
||||
textures/base/pack/chat_show_btn.png
|
||||
textures/base/pack/joystick_bg.png
|
||||
textures/base/pack/joystick_center.png
|
||||
textures/base/pack/joystick_off.png
|
||||
textures/base/pack/minimap_btn.png
|
||||
|
||||
License of Minetest source code
|
||||
-------------------------------
|
||||
|
||||
|
@ -41,7 +41,8 @@ using namespace irr::core;
|
||||
|
||||
const char **touchgui_button_imagenames = (const char *[]) {
|
||||
"jump_btn.png",
|
||||
"down.png"
|
||||
"down.png",
|
||||
"zoom.png"
|
||||
};
|
||||
|
||||
const char **touchgui_joystick_imagenames = (const char *[]) {
|
||||
@ -78,6 +79,9 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
||||
case crunch_id:
|
||||
key = "sneak";
|
||||
break;
|
||||
case zoom_id:
|
||||
key = "zoom";
|
||||
break;
|
||||
case fly_id:
|
||||
key = "freemove";
|
||||
break;
|
||||
@ -90,6 +94,12 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
||||
case debug_id:
|
||||
key = "toggle_debug";
|
||||
break;
|
||||
case toggle_chat_id:
|
||||
key = "toggle_chat";
|
||||
break;
|
||||
case minimap_id:
|
||||
key = "minimap";
|
||||
break;
|
||||
case chat_id:
|
||||
key = "chat";
|
||||
break;
|
||||
@ -246,6 +256,17 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
||||
m_buttons.push_back(btn);
|
||||
}
|
||||
|
||||
void AutoHideButtonBar::addToggleButton(touch_gui_button_id button_id,
|
||||
const wchar_t *caption, const char *btn_image_1,
|
||||
const char *btn_image_2)
|
||||
{
|
||||
addButton(button_id, caption, btn_image_1);
|
||||
button_info *btn = m_buttons.back();
|
||||
btn->togglable = 1;
|
||||
btn->textures.push_back(btn_image_1);
|
||||
btn->textures.push_back(btn_image_2);
|
||||
}
|
||||
|
||||
bool AutoHideButtonBar::isButton(const SEvent &event)
|
||||
{
|
||||
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
||||
@ -291,6 +312,18 @@ bool AutoHideButtonBar::isButton(const SEvent &event)
|
||||
|
||||
m_timeout = 0;
|
||||
|
||||
if ((*iter)->togglable == 1) {
|
||||
(*iter)->togglable = 2;
|
||||
load_button_texture(*iter, (*iter)->textures[1],
|
||||
(*iter)->guibutton->getRelativePosition(),
|
||||
m_texturesource, m_driver);
|
||||
} else if ((*iter)->togglable == 2) {
|
||||
(*iter)->togglable = 1;
|
||||
load_button_texture(*iter, (*iter)->textures[0],
|
||||
(*iter)->guibutton->getRelativePosition(),
|
||||
m_texturesource, m_driver);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
++iter;
|
||||
@ -506,19 +539,27 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
||||
// init jump button
|
||||
initButton(jump_id,
|
||||
rect<s32>(m_screensize.X - (1.75 * button_size),
|
||||
m_screensize.Y - (0.5*button_size),
|
||||
m_screensize.Y - button_size,
|
||||
m_screensize.X - (0.25 * button_size),
|
||||
m_screensize.Y),
|
||||
m_screensize.Y - (0.5 * button_size)),
|
||||
L"x", false);
|
||||
|
||||
// init crunch button
|
||||
initButton(crunch_id,
|
||||
rect<s32>(m_screensize.X - (3.25 * button_size),
|
||||
m_screensize.Y - (0.5*button_size),
|
||||
m_screensize.Y - button_size,
|
||||
m_screensize.X - (1.75 * button_size),
|
||||
m_screensize.Y),
|
||||
m_screensize.Y - (0.5 * button_size)),
|
||||
L"H", false);
|
||||
|
||||
// init zoom button
|
||||
initButton(zoom_id,
|
||||
rect<s32>(m_screensize.X - (1.25 * button_size),
|
||||
m_screensize.Y - (3 * button_size),
|
||||
m_screensize.X - (0.25 * button_size),
|
||||
m_screensize.Y - (2 * button_size)),
|
||||
L"z", 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)
|
||||
@ -534,6 +575,11 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
||||
m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
|
||||
m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
|
||||
m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
|
||||
m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png");
|
||||
|
||||
// Chat is shown by default, so chat_hide_btn.png is shown first.
|
||||
m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat",
|
||||
"chat_hide_btn.png", "chat_show_btn.png");
|
||||
|
||||
m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
|
||||
rare_controls_starter_id,
|
||||
|
@ -36,6 +36,7 @@ using namespace irr::gui;
|
||||
typedef enum {
|
||||
jump_id = 0,
|
||||
crunch_id,
|
||||
zoom_id,
|
||||
after_last_element_id,
|
||||
settings_starter_id,
|
||||
rare_controls_starter_id,
|
||||
@ -45,6 +46,8 @@ typedef enum {
|
||||
debug_id,
|
||||
camera_id,
|
||||
range_id,
|
||||
minimap_id,
|
||||
toggle_chat_id,
|
||||
chat_id,
|
||||
inventory_id,
|
||||
drop_id,
|
||||
@ -70,7 +73,7 @@ typedef enum {
|
||||
#define MAX_TOUCH_COUNT 64
|
||||
#define BUTTON_REPEAT_DELAY 0.2f
|
||||
|
||||
#define SETTINGS_BAR_Y_OFFSET 6.5
|
||||
#define SETTINGS_BAR_Y_OFFSET 5
|
||||
#define RARE_CONTROLS_BAR_Y_OFFSET 4
|
||||
|
||||
extern const char **touchgui_button_imagenames;
|
||||
@ -84,6 +87,10 @@ struct button_info
|
||||
std::vector<int> ids;
|
||||
IGUIButton *guibutton = nullptr;
|
||||
bool immediate_release;
|
||||
|
||||
// 0: false, 1: (true) first texture, 2: (true) second texture
|
||||
int togglable = 0;
|
||||
std::vector<const char *> textures;
|
||||
};
|
||||
|
||||
class AutoHideButtonBar
|
||||
@ -101,6 +108,10 @@ public:
|
||||
void addButton(touch_gui_button_id id, const wchar_t *caption,
|
||||
const char *btn_image);
|
||||
|
||||
// add toggle button to be shown
|
||||
void addToggleButton(touch_gui_button_id id, const wchar_t *caption,
|
||||
const char *btn_image_1, const char *btn_image_2);
|
||||
|
||||
// detect settings bar button events
|
||||
bool isButton(const SEvent &event);
|
||||
|
||||
|
BIN
textures/base/pack/chat_hide_btn.png
Executable file
BIN
textures/base/pack/chat_hide_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 289 B |
BIN
textures/base/pack/chat_show_btn.png
Executable file
BIN
textures/base/pack/chat_show_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 188 B |
BIN
textures/base/pack/jump_btn.png
Normal file → Executable file
BIN
textures/base/pack/jump_btn.png
Normal file → Executable file
Binary file not shown.
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 396 B |
BIN
textures/base/pack/minimap_btn.png
Executable file
BIN
textures/base/pack/minimap_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 218 B |
BIN
textures/base/pack/zoom.png
Executable file
BIN
textures/base/pack/zoom.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user