remove added widget definitions on lua kernel destruction.
This commit is contained in:
parent
118d18ec7a
commit
283fd32077
5 changed files with 24 additions and 1 deletions
|
@ -721,4 +721,14 @@ bool add_single_widget_definition(const std::string& widget_type, const std::str
|
|||
return true;
|
||||
}
|
||||
|
||||
void remove_single_widget_definition(const std::string& widget_type, const std::string& definition_id)
|
||||
{
|
||||
auto& gui = default_gui->second;
|
||||
auto it = gui.control_definition[widget_type].find(definition_id);
|
||||
|
||||
if ( it != gui.control_definition[widget_type].end()) {
|
||||
gui.control_definition[widget_type].erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -105,6 +105,8 @@ resolution_definition_ptr get_control(const std::string& control_type,
|
|||
|
||||
bool add_single_widget_definition(const std::string& widget_type, const std::string& definition_id, const config& cfg);
|
||||
|
||||
void remove_single_widget_definition(const std::string& widget_type, const std::string& definition_id);
|
||||
|
||||
/** Helper struct to signal that get_window_builder failed. */
|
||||
struct window_builder_invalid_id
|
||||
{
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "scripting/lua_common.hpp"
|
||||
#include "scripting/lua_kernel_base.hpp"
|
||||
#include "scripting/lua_unit.hpp"
|
||||
#include "scripting/lua_unit_type.hpp"
|
||||
#include "scripting/push_check.hpp"
|
||||
|
@ -851,8 +852,12 @@ int intf_add_dialog_tree_node(lua_State *L)
|
|||
|
||||
int intf_add_widget_definition(lua_State *L)
|
||||
{
|
||||
std::string type = luaL_checkstring(L, 1);
|
||||
std::string id = luaL_checkstring(L, 2);
|
||||
try {
|
||||
gui2::add_single_widget_definition(luaL_checkstring(L, 1), luaL_checkstring(L, 2), luaW_checkconfig(L, 3));
|
||||
if (gui2::add_single_widget_definition(type, id, luaW_checkconfig(L, 3))) {
|
||||
lua_kernel_base::get_lua_kernel<lua_kernel_base>(L).add_widget_definition(type, id);
|
||||
}
|
||||
}
|
||||
catch (const std::invalid_argument& e) {
|
||||
return luaL_argerror(L, 1, e.what());
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "exceptions.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "game_errors.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "log.hpp"
|
||||
#include "lua_jailbreak_exception.hpp" // for lua_jailbreak_exception
|
||||
#include "random_new.hpp"
|
||||
|
@ -468,6 +469,9 @@ lua_kernel_base::lua_kernel_base()
|
|||
|
||||
lua_kernel_base::~lua_kernel_base()
|
||||
{
|
||||
for (const auto& pair : this->registered_widget_definitions_) {
|
||||
gui2::remove_single_widget_definition(std::get<0>(pair), std::get<1>(pair));
|
||||
}
|
||||
lua_close(mState);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
|
||||
virtual uint32_t get_random_seed();
|
||||
lua_State * get_state() { return mState; }
|
||||
void add_widget_definition(const std::string& type, const std::string& id) { registered_widget_definitions_.emplace_back(type, id); }
|
||||
protected:
|
||||
lua_State *mState;
|
||||
|
||||
|
@ -135,6 +136,7 @@ protected:
|
|||
int intf_require(lua_State * L);
|
||||
private:
|
||||
static lua_kernel_base*& get_lua_kernel_base_ptr(lua_State *L);
|
||||
std::vector<std::tuple<std::string, std::string>> registered_widget_definitions_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue