From 4918f6a50fd28834b78f1a758f06b84d474ba460 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Thu, 8 Sep 2022 21:52:31 +1200 Subject: [PATCH] Improve change keys, change volume and change password menus (#94) Co-authored-by: Maksym H --- po/ca/minetest.po | 2 +- po/da/minetest.po | 2 +- po/de/minetest.po | 2 +- po/es/minetest.po | 2 +- po/et/minetest.po | 2 +- po/gd/minetest.po | 2 +- po/gl/minetest.po | 2 +- po/he/minetest.po | 2 +- po/ms_Arab/minetest.po | 4 +- po/nb/minetest.po | 2 +- po/nn/minetest.po | 2 +- po/pt_BR/minetest.po | 2 +- po/ru/minetest.po | 2 +- po/sk/minetest.po | 4 +- po/sl/minetest.po | 2 +- po/sv/minetest.po | 2 +- po/uk/minetest.po | 2 +- src/client/game.cpp | 25 +++++---- src/gui/StyleSpec.h | 24 ++++++++ src/gui/guiKeyChangeMenu.cpp | 92 +++++++++++++++++++++++-------- src/gui/guiKeyChangeMenu.h | 6 +- src/gui/guiVolumeChange.cpp | 74 +++++++++++++++++-------- src/gui/guiVolumeChange.h | 1 + src/script/lua_api/l_mainmenu.cpp | 3 +- 24 files changed, 187 insertions(+), 76 deletions(-) diff --git a/po/ca/minetest.po b/po/ca/minetest.po index dd8c35231..6bf200bda 100644 --- a/po/ca/minetest.po +++ b/po/ca/minetest.po @@ -1957,7 +1957,7 @@ msgstr "La tecla s'està utilitzant" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Combinacions de tecles. (Si aquest menú espatlla, esborrar coses de minetest." +"Combinacions de tecles. (Si aquest menú espatlla, esborrar coses de multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/da/minetest.po b/po/da/minetest.po index 3a3ea6492..7b711b0f0 100644 --- a/po/da/minetest.po +++ b/po/da/minetest.po @@ -1919,7 +1919,7 @@ msgstr "Tast allerede i brug" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Tastebindinger. (Hvis denne menu fucker op, fjern elementer fra minetest." +"Tastebindinger. (Hvis denne menu fucker op, fjern elementer fra multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/de/minetest.po b/po/de/minetest.po index 867086510..586b50a88 100644 --- a/po/de/minetest.po +++ b/po/de/minetest.po @@ -1869,7 +1869,7 @@ msgstr "Taste bereits in Benutzung" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Steuerung (Falls dieses Menü defekt ist, entfernen Sie Zeugs aus minetest." +"Steuerung (Falls dieses Menü defekt ist, entfernen Sie Zeugs aus multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/es/minetest.po b/po/es/minetest.po index a4301cdc5..01ad5492d 100644 --- a/po/es/minetest.po +++ b/po/es/minetest.po @@ -1868,7 +1868,7 @@ msgstr "La tecla ya se está utilizando" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Combinaciones de teclas. (Si este menú da error, elimina líneas en minetest." +"Combinaciones de teclas. (Si este menú da error, elimina líneas en multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/et/minetest.po b/po/et/minetest.po index 7a80a19fd..e043e072d 100644 --- a/po/et/minetest.po +++ b/po/et/minetest.po @@ -1859,7 +1859,7 @@ msgstr "Nupp juba kasutuses" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Nupusätted. (Kui see menüü sassi läheb, siis kustuta asju failist minetest." +"Nupusätted. (Kui see menüü sassi läheb, siis kustuta asju failist multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/gd/minetest.po b/po/gd/minetest.po index e7147d3b5..449a58bb9 100644 --- a/po/gd/minetest.po +++ b/po/gd/minetest.po @@ -1848,7 +1848,7 @@ msgid "Key already in use" msgstr "" #: src/gui/guiKeyChangeMenu.cpp -msgid "Keybindings. (If this menu screws up, remove stuff from minetest.conf)" +msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/gl/minetest.po b/po/gl/minetest.po index 6f5b479bc..d1834871b 100644 --- a/po/gl/minetest.po +++ b/po/gl/minetest.po @@ -1818,7 +1818,7 @@ msgid "Key already in use" msgstr "" #: src/gui/guiKeyChangeMenu.cpp -msgid "Keybindings. (If this menu screws up, remove stuff from minetest.conf)" +msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/he/minetest.po b/po/he/minetest.po index d04e63c72..477e69074 100644 --- a/po/he/minetest.po +++ b/po/he/minetest.po @@ -1857,7 +1857,7 @@ msgstr "מקש כבר בשימוש" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" -msgstr "קישור מקשים (אם התפריט מתקלקל, הסר דברים מminetest.conf)" +msgstr "קישור מקשים (אם התפריט מתקלקל, הסר דברים מmulticraft.conf)" #: src/gui/guiKeyChangeMenu.cpp msgid "Local command" diff --git a/po/ms_Arab/minetest.po b/po/ms_Arab/minetest.po index 42d758b7d..557733d9a 100644 --- a/po/ms_Arab/minetest.po +++ b/po/ms_Arab/minetest.po @@ -1870,9 +1870,9 @@ msgid "Key already in use" msgstr "ککونچي تله دݢوناکن اونتوق فوڠسي لاٴين" #: src/gui/guiKeyChangeMenu.cpp -msgid "Keybindings. (If this menu screws up, remove stuff from minetest.conf)" +msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"ايکتن ککونچي. (جيک مينو اين برسليرق⹁ ڤادم سستڠه بندا دري فايل minetest.conf)" +"ايکتن ککونچي. (جيک مينو اين برسليرق⹁ ڤادم سستڠه بندا دري فايل multicraft.conf)" #: src/gui/guiKeyChangeMenu.cpp msgid "Local command" diff --git a/po/nb/minetest.po b/po/nb/minetest.po index 016a48d90..c431a6897 100644 --- a/po/nb/minetest.po +++ b/po/nb/minetest.po @@ -1867,7 +1867,7 @@ msgstr "Tast allerede i bruk" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Tastaturtilknytninger. (Hvis dette byr på problemer, fjern ting fra minetest." +"Tastaturtilknytninger. (Hvis dette byr på problemer, fjern ting fra multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/nn/minetest.po b/po/nn/minetest.po index cd12bc0dc..eeb4f1e0f 100644 --- a/po/nn/minetest.po +++ b/po/nn/minetest.po @@ -1886,7 +1886,7 @@ msgstr "Knapp er allereie i bruk" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Knappebindinger. (Om denne menyen går galen, ta bort tinga fra \"minetest." +"Knappebindinger. (Om denne menyen går galen, ta bort tinga fra \"multicraft." "conf\")" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/pt_BR/minetest.po b/po/pt_BR/minetest.po index f5dfe6936..c59ddb111 100644 --- a/po/pt_BR/minetest.po +++ b/po/pt_BR/minetest.po @@ -1866,7 +1866,7 @@ msgstr "Essa tecla já está em uso" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Teclas (se este menu estiver com problema, remova itens do arquivo minetest." +"Teclas (se este menu estiver com problema, remova itens do arquivo multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/ru/minetest.po b/po/ru/minetest.po index 277dfb041..cb9af58f9 100644 --- a/po/ru/minetest.po +++ b/po/ru/minetest.po @@ -1866,7 +1866,7 @@ msgstr "Клавиша уже используется" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Привязки клавиш. (Если это меню сломается, удалите настройки из minetest." +"Привязки клавиш. (Если это меню сломается, удалите настройки из multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/sk/minetest.po b/po/sk/minetest.po index f3c6f4445..ced46b1af 100644 --- a/po/sk/minetest.po +++ b/po/sk/minetest.po @@ -1869,9 +1869,9 @@ msgid "Key already in use" msgstr "Klávesa sa už používa" #: src/gui/guiKeyChangeMenu.cpp -msgid "Keybindings. (If this menu screws up, remove stuff from minetest.conf)" +msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Priradenie kláves. (ak je toto menu rozbité, zmaž zbytočnosti z minetest." +"Priradenie kláves. (ak je toto menu rozbité, zmaž zbytočnosti z multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/sl/minetest.po b/po/sl/minetest.po index 7377d1fd0..39886d51d 100644 --- a/po/sl/minetest.po +++ b/po/sl/minetest.po @@ -1908,7 +1908,7 @@ msgstr "Tipka je že v uporabi" msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" "Vloge tipk (če ta meni preneha delovati, odstranite nastavitve tipk iz " -"datoteke minetest.conf)" +"datoteke multicraft.conf)" #: src/gui/guiKeyChangeMenu.cpp msgid "Local command" diff --git a/po/sv/minetest.po b/po/sv/minetest.po index b76062e5b..e131b1fe5 100644 --- a/po/sv/minetest.po +++ b/po/sv/minetest.po @@ -1926,7 +1926,7 @@ msgstr "Tangent används redan" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Tangentbindningar. (Om den här menyn strular, radera saker från minetest." +"Tangentbindningar. (Om den här menyn strular, radera saker från multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/po/uk/minetest.po b/po/uk/minetest.po index 14ddfbc25..a9dbb0027 100644 --- a/po/uk/minetest.po +++ b/po/uk/minetest.po @@ -1872,7 +1872,7 @@ msgstr "Клавіша вже використовується" #: src/gui/guiKeyChangeMenu.cpp msgid "Keybindings. (If this menu screws up, remove stuff from multicraft.conf)" msgstr "" -"Комбінації клавіш. (Якщо це меню зламалося, видаліть налаштування з minetest." +"Комбінації клавіш. (Якщо це меню зламалося, видаліть налаштування з multicraft." "conf)" #: src/gui/guiKeyChangeMenu.cpp diff --git a/src/client/game.cpp b/src/client/game.cpp index cd94410ab..aa89d1727 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -4363,9 +4363,9 @@ void Game::showPauseMenu() << "no_prepend[]" << "bgcolor[#00000060;true]" - << "style_type[image_button_exit,image_button;bgimg=gui_button.png;bgimg_middle=20;padding=-5]" - << "style_type[image_button_exit,image_button:hovered;bgimg=gui_button_hovered.png;bgimg_middle=20]" - << "style_type[image_button_exit,image_button:pressed;bgimg=gui_button_pressed.png;bgimg_middle=20]" + << "style_type[image_button_exit,image_button;bgimg=gui_button.png;bgimg_middle=20;padding=-10]" + << "style_type[image_button_exit,image_button:hovered;bgimg=gui_button_hovered.png]" + << "style_type[image_button_exit,image_button:pressed;bgimg=gui_button_pressed.png]" << "image_button_exit[3.5," << (ypos++) << ";4,0.9;;btn_continue;" << strgettext("Continue") << ";;false]"; @@ -4375,13 +4375,13 @@ void Game::showPauseMenu() << strgettext("Change Password") << ";;false]"; } -#if !defined(__ANDROID__) && !defined(__IOS__) #if USE_SOUND if (g_settings->getBool("enable_sound")) { os << "image_button_exit[3.5," << (ypos++) << ";4,0.9;;btn_sound;" << strgettext("Sound Volume") << ";;false]"; } #endif +#if !defined(__ANDROID__) && !defined(__IOS__) os << "image_button_exit[3.5," << (ypos++) << ";4,0.9;;btn_key_config;" << strgettext("Change Keys") << ";;false]"; #endif @@ -4457,18 +4457,21 @@ void Game::showChangePasswordDialog(std::string old_pw, std::string new_pw, std::ostringstream os; os << "formspec_version[5]" - << "size[10.5,7.9]" + << "size[10.5,7.5]" << "no_prepend[]" << "bgcolor[#320000b4;true]" << "background9[0,0;0,0;bg_common.png;true;40]" - << "pwdfield[1,1.4;8.5,0.8;old_pw;" << strgettext("Old Password") << ":;" << old_pw << "]" - << "pwdfield[1,3;8.5,0.8;new_pw;" << strgettext("New Password") << ":;" << new_pw << "]" - << "pwdfield[1,4.6;8.5,0.8;confirm_pw;" << strgettext("Confirm Password") << ":;" << confirm_pw << "]" - << "button[1,5.9;4.1,0.8;btn_change_pw;" << strgettext("Change") << "]" - << "button_exit[5.4,5.9;4.1,0.8;btn_cancel;" << strgettext("Cancel") << "]"; + << "pwdfield[1,1.2;8.5,0.8;old_pw;" << strgettext("Old Password") << ":;" << old_pw << "]" + << "pwdfield[1,2.8;8.5,0.8;new_pw;" << strgettext("New Password") << ":;" << new_pw << "]" + << "pwdfield[1,4.4;8.5,0.8;confirm_pw;" << strgettext("Confirm Password") << ":;" << confirm_pw << "]" + << "style_type[image_button_exit,image_button;bgimg=gui_button.png;bgimg_middle=20;padding=-10]" + << "style_type[image_button_exit,image_button:hovered;bgimg=gui_button_hovered.png]" + << "style_type[image_button_exit,image_button:pressed;bgimg=gui_button_pressed.png]" + << "image_button[1,5.9;4.1,0.8;;btn_change_pw;" << strgettext("Change") << ";;false]" + << "image_button_exit[5.4,5.9;4.1,0.8;;btn_cancel;" << strgettext("Cancel") << ";;false]"; if (new_pw != confirm_pw) - os << "label[1,7.2;\x1b(c@red)" << strgettext("Passwords do not match!") << "]"; + os << "label[1,7.1;\x1b(c@red)" << strgettext("Passwords do not match!") << "]"; /* Create menu */ /* Note: FormspecFormSource and LocalFormspecHandler * diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h index 266b406e1..795c2a994 100644 --- a/src/gui/StyleSpec.h +++ b/src/gui/StyleSpec.h @@ -70,6 +70,30 @@ public: STATE_INVALID = 1 << 3, }; + // Used in guiKeyChangeMenu.cpp and guiVolumeChange.h + // Is this the best place to put this function? + static std::array getButtonStyle(const std::string texture_path = "") { + std::array ret; + + StyleSpec btn_spec; + btn_spec.set(BGIMG, texture_path + "gui_button.png"); + btn_spec.set(BGIMG_MIDDLE, "20"); + btn_spec.set(BORDER, "false"); + btn_spec.set(PADDING, "-10"); + + ret[STATE_DEFAULT] = btn_spec; + + StyleSpec hovered_spec; + hovered_spec.set(BGIMG, texture_path + "gui_button_hovered.png"); + ret[STATE_HOVERED] = hovered_spec; + + StyleSpec pressed_spec; + pressed_spec.set(BGIMG, texture_path + "gui_button_pressed.png"); + ret[STATE_PRESSED] = pressed_spec; + + return ret; + } + private: std::array property_set{}; std::array properties; diff --git a/src/gui/guiKeyChangeMenu.cpp b/src/gui/guiKeyChangeMenu.cpp index a4038950d..5d6aef48a 100644 --- a/src/gui/guiKeyChangeMenu.cpp +++ b/src/gui/guiKeyChangeMenu.cpp @@ -21,6 +21,7 @@ #include "guiKeyChangeMenu.h" #include "debug.h" +#include "guiBackgroundImage.h" #include "guiButton.h" #include "serialization.h" #include @@ -29,7 +30,10 @@ #include #include #include +#include "filesys.h" +#include "porting.h" #include "settings.h" +#include "StyleSpec.h" #include #include "mainmenumanager.h" // for g_gamecallback @@ -42,6 +46,7 @@ extern MainGameCallback *g_gamecallback; enum { GUI_ID_BACK_BUTTON = 101, GUI_ID_ABORT_BUTTON, GUI_ID_SCROLL_BAR, + GUI_ID_BACKGROUND_IMG, // buttons GUI_ID_KEY_FORWARD_BUTTON, GUI_ID_KEY_BACKWARD_BUTTON, @@ -84,11 +89,21 @@ enum GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, - ISimpleTextureSource *tsrc) : + ISimpleTextureSource *tsrc, bool main_menu) : GUIModalMenu(env, parent, id, menumgr), - m_tsrc(tsrc) + m_tsrc(tsrc), + m_main_menu(main_menu) { init_keys(); + + if (m_main_menu) return; + v3f formspec_bgcolor = g_settings->getV3F("formspec_fullscreen_bg_color"); + m_fullscreen_bgcolor = video::SColor( + (u8) MYMIN(MYMAX(g_settings->getS32("formspec_fullscreen_bg_opacity"), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.X), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.Y), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.Z), 0), 255) + ); } GUIKeyChangeMenu::~GUIKeyChangeMenu() @@ -120,13 +135,20 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { removeChildren(); -#ifdef HAVE_TOUCHSCREENGUI - const float s = m_gui_scale * RenderingEngine::getDisplayDensity() / 1.5; -#elif defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) - const float s = m_gui_scale * RenderingEngine::getDisplayDensity() * 1.5; + float s = MYMIN(screensize.X / 835.f, screensize.Y / 430.f); +#if HAVE_TOUCHSCREENGUI + s *= g_settings->getBool("device_is_tablet") ? 0.8f : 0.9f; #else - const float s = m_gui_scale; + s *= 0.75f; #endif + + // Make sure the GUI will fit on the screen + // The change keys GUI is 835x430 pixels (with a scaling of 1) + if (835 * s > screensize.X) + s = screensize.X / 835.f; + if (430 * s > screensize.Y) + s = screensize.Y / 430.f; + DesiredRect = core::rect( screensize.X / 2 - 835 * s / 2, screensize.Y / 2 - 430 * s / 2, @@ -138,11 +160,29 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) v2s32 size = DesiredRect.getSize(); v2s32 topleft(0, 0); + std::string texture_path = ""; + if (m_main_menu) + texture_path = porting::path_share + DIR_DELIM "textures" DIR_DELIM + "base" DIR_DELIM "pack" DIR_DELIM; + + // Background image { - core::rect rect(0, 0, 600 * s, 40 * s); - rect += topleft + v2s32(25 * s, 3 * s); + const std::string texture = texture_path + "bg_common.png"; + const core::rect rect(0, 0, 0, 0); + const core::rect middle(40, 40, -40, -40); + new GUIBackgroundImage(Environment, this, GUI_ID_BACKGROUND_IMG, rect, + texture, middle, m_tsrc, true); + } + + { + core::rect rect(0, 0, 795 * s, 50 * s); + rect += topleft + v2s32(25 * s, 10 * s); //gui::IGUIStaticText *t = +#if !defined(__ANDROID__) && !defined(__IOS__) const wchar_t *text = wgettext("Keybindings. (If this menu screws up, remove stuff from multicraft.conf)"); +#else + const wchar_t *text = wgettext("Change Keys"); +#endif Environment->addStaticText(text, rect, false, true, this, -1); delete[] text; @@ -180,7 +220,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { s32 option_x = offset.X; s32 option_y = offset.Y + 5 * s; - u32 option_w = 180 * s; + u32 option_w = 300 * s; { core::rect rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); @@ -195,7 +235,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { s32 option_x = offset.X; s32 option_y = offset.Y + 5 * s; - u32 option_w = 280 * s; + u32 option_w = 300 * s; { core::rect rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); @@ -210,7 +250,7 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) { s32 option_x = offset.X; s32 option_y = offset.Y + 5 * s; - u32 option_w = 280; + u32 option_w = 300 * s; { core::rect rect(0, 0, option_w, 30 * s); rect += topleft + v2s32(option_x, option_y); @@ -222,18 +262,23 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) offset += v2s32(0, 25); } + const std::array styles = + StyleSpec::getButtonStyle(texture_path); + { - core::rect rect(0, 0, 100 * s, 30 * s); - rect += topleft + v2s32(size.X / 2 - 105 * s, size.Y - 40 * s); - const wchar_t *text = wgettext("Save"); - GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, text); + core::rect rect(0, 0, 150 * s, 35 * s); + rect += topleft + v2s32(size.X / 2 - 165 * s, size.Y - 50 * s); + const wchar_t *text = wgettext("Save"); + GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_BACK_BUTTON, text); + e->setStyles(styles); delete[] text; } { - core::rect rect(0, 0, 100 * s, 30 * s); - rect += topleft + v2s32(size.X / 2 + 5 * s, size.Y - 40 * s); + core::rect rect(0, 0, 150 * s, 35 * s); + rect += topleft + v2s32(size.X / 2 + 15 * s, size.Y - 50 * s); const wchar_t *text = wgettext("Cancel"); - GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, text); + GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, this, GUI_ID_ABORT_BUTTON, text); + e->setStyles(styles); delete[] text; } } @@ -243,10 +288,13 @@ void GUIKeyChangeMenu::drawMenu() gui::IGUISkin* skin = Environment->getSkin(); if (!skin) return; - video::IVideoDriver* driver = Environment->getVideoDriver(); - video::SColor bgcolor(140, 0, 0, 0); - driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); + if (!m_main_menu) { + video::IVideoDriver* driver = Environment->getVideoDriver(); + v2u32 screenSize = driver->getScreenSize(); + core::rect allbg(0, 0, screenSize.X, screenSize.Y); + driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg); + } gui::IGUIElement::draw(); } diff --git a/src/gui/guiKeyChangeMenu.h b/src/gui/guiKeyChangeMenu.h index 8c6bc5e8b..5ca99c63c 100644 --- a/src/gui/guiKeyChangeMenu.h +++ b/src/gui/guiKeyChangeMenu.h @@ -43,7 +43,8 @@ class GUIKeyChangeMenu : public GUIModalMenu { public: GUIKeyChangeMenu(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, - IMenuManager *menumgr, ISimpleTextureSource *tsrc); + IMenuManager *menumgr, ISimpleTextureSource *tsrc, + bool main_menu = false); ~GUIKeyChangeMenu(); void removeChildren(); @@ -77,4 +78,7 @@ private: gui::IGUIStaticText *key_used_text = nullptr; std::vector key_settings; ISimpleTextureSource *m_tsrc; + bool m_main_menu = false; + + video::SColor m_fullscreen_bgcolor; }; diff --git a/src/gui/guiVolumeChange.cpp b/src/gui/guiVolumeChange.cpp index d8109f546..dc34d5269 100644 --- a/src/gui/guiVolumeChange.cpp +++ b/src/gui/guiVolumeChange.cpp @@ -19,6 +19,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "guiVolumeChange.h" #include "debug.h" +#include "guiBackgroundImage.h" #include "guiButton.h" #include "serialization.h" #include @@ -28,10 +29,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include "settings.h" +#include "StyleSpec.h" #include "gettext.h" #include "client/renderingengine.h" +const int ID_backgroundImage = 262; const int ID_soundText = 263; const int ID_soundExitButton = 264; const int ID_soundSlider = 265; @@ -44,6 +47,13 @@ GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env, GUIModalMenu(env, parent, id, menumgr), m_tsrc(tsrc) { + v3f formspec_bgcolor = g_settings->getV3F("formspec_fullscreen_bg_color"); + m_fullscreen_bgcolor = video::SColor( + (u8) MYMIN(MYMAX(g_settings->getS32("formspec_fullscreen_bg_opacity"), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.X), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.Y), 0), 255), + MYMIN(MYMAX(myround(formspec_bgcolor.Z), 0), 255) + ); } GUIVolumeChange::~GUIVolumeChange() @@ -53,6 +63,9 @@ GUIVolumeChange::~GUIVolumeChange() void GUIVolumeChange::removeChildren() { + if (gui::IGUIElement *e = getElementFromId(ID_backgroundImage)) + e->remove(); + if (gui::IGUIElement *e = getElementFromId(ID_soundText)) e->remove(); @@ -75,18 +88,18 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) /* Calculate new sizes and positions */ -#ifdef HAVE_TOUCHSCREENGUI - const float s = m_gui_scale * RenderingEngine::getDisplayDensity() / 1.5; -#elif defined(__MACH__) && defined(__APPLE__) && !defined(__IOS__) - const float s = m_gui_scale * RenderingEngine::getDisplayDensity() * 1.5; + float s = MYMIN(screensize.X / 380.f, screensize.Y / 180.f); +#if HAVE_TOUCHSCREENGUI + s *= g_settings->getBool("device_is_tablet") ? 0.4f : 0.5f; #else - const float s = m_gui_scale; + s *= 0.35f; #endif + DesiredRect = core::rect( screensize.X / 2 - 380 * s / 2, - screensize.Y / 2 - 200 * s / 2, + screensize.Y / 2 - 180 * s / 2, screensize.X / 2 + 380 * s / 2, - screensize.Y / 2 + 200 * s / 2 + screensize.Y / 2 + 180 * s / 2 // 200 ); recalculateAbsolutePosition(false); @@ -97,8 +110,15 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) Add stuff */ { - core::rect rect(0, 0, 160 * s, 20 * s); - rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 70 * s); + const std::string texture = "bg_common.png"; + const core::rect rect(0, 0, 0, 0); + const core::rect middle(40, 40, -40, -40); + new GUIBackgroundImage(Environment, this, ID_backgroundImage, rect, + texture, middle, m_tsrc, true); + } + { + core::rect rect(0, 0, 320 * s, 25 * s); + rect = rect + v2s32(30 * s, size.Y / 2 - 35 * s); // 55 const wchar_t *text = wgettext("Sound Volume: "); core::stringw volume_text = text; @@ -109,28 +129,31 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize) true, this, ID_soundText); } { - core::rect rect(0, 0, 80 * s, 30 * s); - rect = rect + v2s32(size.X / 2 - 80 * s / 2, size.Y / 2 + 55 * s); + core::rect rect(0, 0, 80 * s, 35 * s); + rect = rect + v2s32(size.X / 2 - 40 * s, size.Y / 2 + 35 * s); // 45 const wchar_t *text = wgettext("Exit"); - GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton, text); + GUIButton *e = GUIButton::addButton(Environment, rect, m_tsrc, this, + ID_soundExitButton, text); delete[] text; + + e->setStyles(StyleSpec::getButtonStyle()); } { - core::rect rect(0, 0, 300 * s, 20 * s); - rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2); + core::rect rect(0, 0, 320 * s, 25 * s); + rect = rect + v2s32(size.X / 2 - 160 * s, size.Y / 2 - 12 * s); // 30 gui::IGUIScrollBar *e = Environment->addScrollBar(true, rect, this, ID_soundSlider); e->setMax(100); e->setPos(volume); } - { - core::rect rect(0, 0, 160 * s, 20 * s); - rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 35 * s); + /*{ + core::rect rect(0, 0, 150 * s, 25 * s); + rect = rect + v2s32(30 * s, size.Y / 2 + 5 * s); const wchar_t *text = wgettext("Muted"); Environment->addCheckBox(g_settings->getBool("mute_sound"), rect, this, ID_soundMuteButton, text); delete[] text; - } + }*/ } void GUIVolumeChange::drawMenu() @@ -139,8 +162,11 @@ void GUIVolumeChange::drawMenu() if (!skin) return; video::IVideoDriver* driver = Environment->getVideoDriver(); - video::SColor bgcolor(140, 0, 0, 0); - driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); + + v2u32 screenSize = driver->getScreenSize(); + core::rect allbg(0, 0, screenSize.X, screenSize.Y); + driver->draw2DRectangle(m_fullscreen_bgcolor, allbg, &allbg); + gui::IGUIElement::draw(); } @@ -157,7 +183,7 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) return true; } } else if (event.EventType == EET_GUI_EVENT) { - if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) { + /*if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) { gui::IGUIElement *e = getElementFromId(ID_soundMuteButton); if (e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) { g_settings->setBool("mute_sound", ((gui::IGUICheckBox*)e)->isChecked()); @@ -165,7 +191,7 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) Environment->setFocus(this); return true; - } + }*/ if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) { if (event.GUIEvent.Caller->getID() == ID_soundExitButton) { @@ -189,6 +215,10 @@ bool GUIVolumeChange::OnEvent(const SEvent& event) s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); g_settings->setFloat("sound_volume", (float) pos / 100); + // unmute sound when changing the volume + if (g_settings->getBool("mute_sound")) + g_settings->setBool("mute_sound", false); + gui::IGUIElement *e = getElementFromId(ID_soundText); const wchar_t *text = wgettext("Sound Volume: "); core::stringw volume_text = text; diff --git a/src/gui/guiVolumeChange.h b/src/gui/guiVolumeChange.h index 466e17f9d..54f1ea1e7 100644 --- a/src/gui/guiVolumeChange.h +++ b/src/gui/guiVolumeChange.h @@ -51,4 +51,5 @@ protected: private: ISimpleTextureSource *m_tsrc; + video::SColor m_fullscreen_bgcolor; }; diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index f73cd6c5e..c5f6eddaa 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -409,7 +409,8 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L) engine->m_parent, -1, engine->m_menumanager, - engine->m_texture_source); + engine->m_texture_source, + true); kmenu->drop(); return 0; }