Skip to content

Commit

Permalink
show "X" texture when opened from mainmenu
Browse files Browse the repository at this point in the history
  • Loading branch information
y5nw committed Sep 12, 2024
1 parent 8db8a69 commit 769d5b8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ inline bool Game::handleCallbacks()
}

if (g_gamecallback->keyconfig_requested) {
(new GUIKeyChangeMenu(m_rendering_engine->get_gui_env(), &input->joystick,
(new GUIKeyChangeMenu(client, m_rendering_engine->get_gui_env(), &input->joystick,
texture_src, sound_manager.get(), client->getFormspecPrepend()))->drop();
g_gamecallback->keyconfig_requested = false;
}
Expand Down
10 changes: 9 additions & 1 deletion src/gui/guiKeyChangeMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
*/

#include "guiKeyChangeMenu.h"
#include "filesys.h"
#include "gettext.h"
#include "porting.h"
#include <sstream>
#include <vector>

Expand Down Expand Up @@ -100,6 +102,11 @@ void GUIKeyChangeMenu::KeyChangeFormspecHandler::gotText(const StringMap &fields
form->updateFormSource();
}

std::string GUIKeyChangeMenu::getTexture(const std::string &name) const
{
return has_client ? name : porting::path_share + "/textures/base/pack/" + name;
}

void GUIKeyChangeMenu::updateFormSource(const std::string &message)
{
// this is more or less make_scrollbaroptions_for_scroll_container from Lua
Expand Down Expand Up @@ -163,7 +170,8 @@ void GUIKeyChangeMenu::updateFormSource(const std::string &message)
<< "button[7.5," << pos_y << ";" << btn_width << ",1;btn_set_" << setting.setting_name << ";"
<< keydesc << "]";
if (show_clear)
os << "image_button[12.5," << pos_y << ";1,1;clear.png;btn_clear_" << setting.setting_name << ";]";
os << "image_button[12.5," << pos_y << ";1,1;" << getTexture("clear.png")
<< ";btn_clear_" << setting.setting_name << ";]";
pos_y += 1.5;
}

Expand Down
10 changes: 7 additions & 3 deletions src/gui/guiKeyChangeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ class GUIKeyChangeMenu : public GUIFormSpecMenu

public:
// We can't use Client* in the mainmenu
GUIKeyChangeMenu(gui::IGUIEnvironment *guienv, JoystickController *joystick,
GUIKeyChangeMenu(Client * client, gui::IGUIEnvironment *guienv, JoystickController *joystick,
ISimpleTextureSource *tsrc, ISoundManager *sound_manager,
const std::string &formspec_prepend = "") :
super(joystick, guiroot, -1, &g_menumgr, nullptr, guienv, tsrc,
sound_manager, nullptr, nullptr, formspec_prepend)
super(joystick, guiroot, -1, &g_menumgr, client, guienv, tsrc,
sound_manager, nullptr, nullptr, formspec_prepend),
has_client(client != nullptr)
{
updateFormSource();
setFormspecHandler();
Expand Down Expand Up @@ -88,7 +89,10 @@ class GUIKeyChangeMenu : public GUIFormSpecMenu
return g_settings->getBool(name);
}

std::string getTexture(const std::string &name) const;

std::unordered_map<std::string, KeyPress> keymap;
std::unordered_map<std::string, bool> control_options;
std::string active_key;
bool has_client;
};
2 changes: 1 addition & 1 deletion src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
GUIEngine *engine = getGuiEngine(L);
sanity_check(engine != NULL);

GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(
GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(nullptr, /* no Client object here */
engine->m_rendering_engine->get_gui_env(),
engine->m_joystick, engine->m_texture_source.get(), engine->m_sound_manager.get());
kmenu->drop();
Expand Down

0 comments on commit 769d5b8

Please sign in to comment.