More fixes
This commit is contained in:
parent
192df6edc4
commit
ccaefd866c
@ -28,7 +28,6 @@ namespace ui_scripting
|
||||
|
||||
scheduler::loop([]()
|
||||
{
|
||||
ShowCursor(true);
|
||||
ui_scripting::lua::engine::run_frame();
|
||||
}, scheduler::pipeline::renderer);
|
||||
|
||||
|
@ -206,18 +206,6 @@ namespace ui_scripting::lua
|
||||
element_type["settextoffset"] = &element::set_text_offset;
|
||||
element_type["setslice"] = &element::set_slice;
|
||||
|
||||
element_type["onnotify"] = [&handler](element& element, const std::string& event,
|
||||
const event_callback& callback)
|
||||
{
|
||||
event_listener listener{};
|
||||
listener.callback = callback;
|
||||
listener.element = &element;
|
||||
listener.event = event;
|
||||
listener.is_volatile = false;
|
||||
|
||||
return handler.add_event_listener(std::move(listener));
|
||||
};
|
||||
|
||||
element_type["getrect"] = [](const sol::this_state s, element& element)
|
||||
{
|
||||
auto rect = sol::table::create(s.lua_state());
|
||||
@ -371,6 +359,18 @@ namespace ui_scripting::lua
|
||||
}
|
||||
);
|
||||
|
||||
element_type["onnotify"] = [&handler](element& element, const std::string& event,
|
||||
const event_callback& callback)
|
||||
{
|
||||
event_listener listener{};
|
||||
listener.callback = callback;
|
||||
listener.element = &element;
|
||||
listener.event = event;
|
||||
listener.is_volatile = false;
|
||||
|
||||
return handler.add_event_listener(std::move(listener));
|
||||
};
|
||||
|
||||
element_type["onnotifyonce"] = [&handler](element& element, const std::string& event,
|
||||
const event_callback& callback)
|
||||
{
|
||||
@ -408,6 +408,53 @@ namespace ui_scripting::lua
|
||||
|
||||
auto menu_type = state.new_usertype<menu>("menu");
|
||||
|
||||
menu_type["onnotify"] = [&handler](menu& menu, const std::string& event,
|
||||
const event_callback& callback)
|
||||
{
|
||||
event_listener listener{};
|
||||
listener.callback = callback;
|
||||
listener.element = &menu;
|
||||
listener.event = event;
|
||||
listener.is_volatile = false;
|
||||
|
||||
return handler.add_event_listener(std::move(listener));
|
||||
};
|
||||
|
||||
menu_type["onnotifyonce"] = [&handler](menu& menu, const std::string& event,
|
||||
const event_callback& callback)
|
||||
{
|
||||
event_listener listener{};
|
||||
listener.callback = callback;
|
||||
listener.element = &menu;
|
||||
listener.event = event;
|
||||
listener.is_volatile = true;
|
||||
|
||||
return handler.add_event_listener(std::move(listener));
|
||||
};
|
||||
|
||||
menu_type["notify"] = [&handler](menu& element, const sol::this_state s, const std::string& _event,
|
||||
sol::variadic_args va)
|
||||
{
|
||||
event event;
|
||||
event.element = &element;
|
||||
event.name = _event;
|
||||
|
||||
for (auto arg : va)
|
||||
{
|
||||
if (arg.get_type() == sol::type::number)
|
||||
{
|
||||
event.arguments.push_back(arg.as<int>());
|
||||
}
|
||||
|
||||
if (arg.get_type() == sol::type::string)
|
||||
{
|
||||
event.arguments.push_back(arg.as<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
handler.dispatch(event);
|
||||
};
|
||||
|
||||
menu_type["addchild"] = [](const sol::this_state s, menu& menu, element& element)
|
||||
{
|
||||
menu.add_child(&element);
|
||||
@ -424,6 +471,31 @@ namespace ui_scripting::lua
|
||||
}
|
||||
);
|
||||
|
||||
menu_type["isopen"] = [](menu& menu)
|
||||
{
|
||||
return menu.visible || (menu.type == menu_type::overlay && game::Menu_IsMenuOpenAndVisible(0, menu.overlay_menu.data()));
|
||||
};
|
||||
|
||||
menu_type["open"] = [&handler](menu& menu)
|
||||
{
|
||||
event event;
|
||||
event.element = &menu;
|
||||
event.name = "close";
|
||||
handler.dispatch(event);
|
||||
|
||||
menu.open();
|
||||
};
|
||||
|
||||
menu_type["close"] = [&handler](menu& menu)
|
||||
{
|
||||
event event;
|
||||
event.element = &menu;
|
||||
event.name = "close";
|
||||
handler.dispatch(event);
|
||||
|
||||
menu.close();
|
||||
};
|
||||
|
||||
struct game
|
||||
{
|
||||
};
|
||||
@ -459,24 +531,38 @@ namespace ui_scripting::lua
|
||||
return pos;
|
||||
};
|
||||
|
||||
game_type["openmenu"] = [](const game&, const std::string& name)
|
||||
game_type["openmenu"] = [&handler](const game&, const std::string& name)
|
||||
{
|
||||
if (menus.find(name) == menus.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
menus[name].open();
|
||||
const auto menu = &menus[name];
|
||||
|
||||
event event;
|
||||
event.element = menu;
|
||||
event.name = "close";
|
||||
handler.dispatch(event);
|
||||
|
||||
menu->open();
|
||||
};
|
||||
|
||||
game_type["closemenu"] = [](const game&, const std::string& name)
|
||||
game_type["closemenu"] = [&handler](const game&, const std::string& name)
|
||||
{
|
||||
if (menus.find(name) == menus.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
menus[name].close();
|
||||
const auto menu = &menus[name];
|
||||
|
||||
event event;
|
||||
event.element = menu;
|
||||
event.name = "close";
|
||||
handler.dispatch(event);
|
||||
|
||||
menu->close();
|
||||
};
|
||||
|
||||
game_type["onframe"] = [&scheduler](const game&, const sol::protected_function& callback)
|
||||
@ -646,15 +732,15 @@ namespace ui_scripting::lua
|
||||
throw std::runtime_error("Not in game");
|
||||
}
|
||||
|
||||
::scheduler::once([s, name, args = std::vector<sol::object>(va.begin(), va.end())]()
|
||||
{
|
||||
std::vector<scripting::script_value> arguments{};
|
||||
|
||||
for (auto arg : va)
|
||||
for (auto arg : args)
|
||||
{
|
||||
arguments.push_back(convert({s, arg}));
|
||||
}
|
||||
|
||||
::scheduler::once([s, va, name, arguments]()
|
||||
{
|
||||
const auto player = scripting::call("getentbynum", {0}).as<scripting::entity>();
|
||||
scripting::notify(player, name, arguments);
|
||||
}, ::scheduler::pipeline::server);
|
||||
|
@ -350,7 +350,14 @@ namespace ui_scripting::lua::engine
|
||||
return;
|
||||
}
|
||||
|
||||
menus[name].open();
|
||||
const auto menu = &menus[name];
|
||||
|
||||
event event;
|
||||
event.element = menu;
|
||||
event.name = "open";
|
||||
notify(event);
|
||||
|
||||
menu->open();
|
||||
}
|
||||
|
||||
void close_menu(const std::string& name)
|
||||
@ -360,7 +367,14 @@ namespace ui_scripting::lua::engine
|
||||
return;
|
||||
}
|
||||
|
||||
menus[name].close();
|
||||
const auto menu = &menus[name];
|
||||
|
||||
event event;
|
||||
event.element = menu;
|
||||
event.name = "close";
|
||||
notify(event);
|
||||
|
||||
menu->close();
|
||||
}
|
||||
|
||||
void start()
|
||||
|
@ -7,7 +7,7 @@ namespace ui_scripting::lua
|
||||
struct event
|
||||
{
|
||||
std::string name;
|
||||
element* element{};
|
||||
const void* element{};
|
||||
std::vector<std::variant<int, std::string>> arguments;
|
||||
};
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace ui_scripting::lua
|
||||
|
||||
for (auto i = tasks.begin(); i != tasks.end();)
|
||||
{
|
||||
if (i->event != event.name || i->element->id != event.element->id)
|
||||
if (i->event != event.name || i->element != event.element)
|
||||
{
|
||||
++i;
|
||||
continue;
|
||||
@ -87,7 +87,7 @@ namespace ui_scripting::lua
|
||||
{
|
||||
if (task.id == handle.id)
|
||||
{
|
||||
task.endon_conditions.emplace_back(element->id, event);
|
||||
task.endon_conditions.emplace_back((uint64_t)element, event);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -150,7 +150,7 @@ namespace ui_scripting::lua
|
||||
{
|
||||
for (auto& condition : task.endon_conditions)
|
||||
{
|
||||
if (condition.first == event.element->id && condition.second == event.name)
|
||||
if (condition.first == (uint64_t)event.element && condition.second == event.name)
|
||||
{
|
||||
task.is_deleted = true;
|
||||
break;
|
||||
|
@ -16,7 +16,7 @@ namespace ui_scripting::lua
|
||||
{
|
||||
public:
|
||||
std::string event = {};
|
||||
element* element{};
|
||||
void* element{};
|
||||
event_callback callback = {};
|
||||
bool is_volatile = false;
|
||||
bool is_deleted = false;
|
||||
|
@ -27,7 +27,7 @@ namespace ui_scripting::lua
|
||||
{
|
||||
for (auto& condition : task.endon_conditions)
|
||||
{
|
||||
if (condition.first == event.element->id && condition.second == event.name)
|
||||
if (condition.first == (uint64_t)event.element && condition.second == event.name)
|
||||
{
|
||||
task.is_deleted = true;
|
||||
break;
|
||||
|
@ -15,38 +15,24 @@ namespace ui_scripting
|
||||
}
|
||||
|
||||
void menu::open()
|
||||
{
|
||||
if (this->visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->cursor_was_enabled = *game::keyCatchers & 0x40;
|
||||
if (!this->cursor_was_enabled && this->cursor)
|
||||
{
|
||||
*game::keyCatchers |= 0x40;
|
||||
}
|
||||
|
||||
this->visible = true;
|
||||
}
|
||||
|
||||
void menu::close()
|
||||
{
|
||||
if (!this->visible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->cursor_was_enabled && this->cursor)
|
||||
{
|
||||
*game::keyCatchers &= ~0x40;
|
||||
}
|
||||
|
||||
this->visible = false;
|
||||
}
|
||||
|
||||
void menu::render() const
|
||||
{
|
||||
if (this->cursor)
|
||||
{
|
||||
*game::keyCatchers |= 0x40;
|
||||
}
|
||||
|
||||
for (auto& element : this->children)
|
||||
{
|
||||
element->render();
|
||||
|
@ -17,7 +17,6 @@ namespace ui_scripting
|
||||
|
||||
bool visible = false;
|
||||
bool cursor = false;
|
||||
bool cursor_was_enabled = false;
|
||||
|
||||
void open();
|
||||
void close();
|
||||
|
Loading…
Reference in New Issue
Block a user