Menu overlay type

This commit is contained in:
Federico Cecchetto 2021-09-12 02:39:43 +02:00
parent 15474f18d0
commit 0184920bb5
2 changed files with 24 additions and 2 deletions

View File

@ -84,13 +84,18 @@ namespace ui_scripting::lua
return (px > x && px < x + w && py > y && py < y + h); return (px > x && px < x + w && py > y && py < y + h);
} }
bool is_menu_visible(const menu& menu)
{
return menu.visible || (menu.type == menu_type::overlay && game::Menu_IsMenuOpenAndVisible(0, menu.overlay_menu.data()));
}
void render_menus() void render_menus()
{ {
check_resize(); check_resize();
for (const auto& menu : menus) for (const auto& menu : menus)
{ {
if (menu.second.visible) if (is_menu_visible(menu.second))
{ {
menu.second.render(); menu.second.render();
} }
@ -103,7 +108,7 @@ namespace ui_scripting::lua
for (const auto& menu : menus) for (const auto& menu : menus)
{ {
if (!menu.second.visible) if (!is_menu_visible(menu.second))
{ {
continue; continue;
} }
@ -574,6 +579,14 @@ namespace ui_scripting::lua
return &menus[name]; return &menus[name];
}; };
game_type["newmenuoverlay"] = [](const sol::lua_value&, const std::string& name, const std::string& menu_name)
{
menus[name] = {};
menus[name].type = menu_type::overlay;
menus[name].overlay_menu = menu_name;
return &menus[name];
};
game_type["getmouseposition"] = [](const sol::this_state s, const game&) game_type["getmouseposition"] = [](const sol::this_state s, const game&)
{ {
auto pos = sol::table::create(s.lua_state()); auto pos = sol::table::create(s.lua_state());

View File

@ -4,6 +4,12 @@
namespace ui_scripting namespace ui_scripting
{ {
enum menu_type
{
normal,
overlay
};
class menu final class menu final
{ {
public: public:
@ -19,6 +25,9 @@ namespace ui_scripting
void add_child(element* el); void add_child(element* el);
void render() const; void render() const;
menu_type type = normal;
std::string overlay_menu;
std::vector<element*> children{}; std::vector<element*> children{};
}; };
} }