mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
feat(lua): expose the self class and add new menu events (#2656)
This commit is contained in:
parent
49d31f8799
commit
2e63940b77
@ -2,7 +2,7 @@
|
||||
|
||||
Table containing all possible events to which you can respond.
|
||||
|
||||
## Fields (6)
|
||||
## Fields (8)
|
||||
|
||||
### `PlayerLeave`
|
||||
|
||||
@ -79,3 +79,27 @@ end)
|
||||
|
||||
- Type: `integer`
|
||||
|
||||
### `MenuUnloaded`
|
||||
|
||||
Event that is triggered when we unload YimMenu.
|
||||
**Example Usage:**
|
||||
```lua
|
||||
event.register_handler(menu_event.MenuUnloaded, function ()
|
||||
log.info("Menu unloaded.")
|
||||
end)
|
||||
```
|
||||
|
||||
- Type: `integer`
|
||||
|
||||
### `ScriptsReloaded`
|
||||
|
||||
Event that is triggered when we reload the Lua scripts.
|
||||
**Example Usage:**
|
||||
```lua
|
||||
event.register_handler(menu_event.ScriptsReloaded, function ()
|
||||
log.info("Scripts reloaded.")
|
||||
end)
|
||||
```
|
||||
|
||||
- Type: `integer`
|
||||
|
||||
|
@ -8,4 +8,6 @@ enum class menu_event
|
||||
PlayerMgrShutdown,
|
||||
ChatMessageReceived,
|
||||
ScriptedGameEventReceived,
|
||||
MenuUnloaded,
|
||||
ScriptsReloaded,
|
||||
};
|
@ -80,6 +80,28 @@ namespace lua::event
|
||||
// end)
|
||||
// ```
|
||||
|
||||
// Lua API: Field
|
||||
// Table: menu_event
|
||||
// Field: MenuUnloaded: integer
|
||||
// Event that is triggered when we unload YimMenu.
|
||||
// **Example Usage:**
|
||||
// ```lua
|
||||
// event.register_handler(menu_event.MenuUnloaded, function ()
|
||||
// log.info("Menu unloaded.")
|
||||
// end)
|
||||
// ```
|
||||
|
||||
// Lua API: Field
|
||||
// Table: menu_event
|
||||
// Field: ScriptsReloaded: integer
|
||||
// Event that is triggered when we reload the Lua scripts.
|
||||
// **Example Usage:**
|
||||
// ```lua
|
||||
// event.register_handler(menu_event.ScriptsReloaded, function ()
|
||||
// log.info("Scripts reloaded.")
|
||||
// end)
|
||||
// ```
|
||||
|
||||
// Lua API: Table
|
||||
// Name: event
|
||||
// Table for responding to various events. The list of events is available in the menu_event table.
|
||||
@ -107,6 +129,8 @@ namespace lua::event
|
||||
{"PlayerMgrShutdown", menu_event::PlayerMgrShutdown},
|
||||
{"ChatMessageReceived", menu_event::ChatMessageReceived},
|
||||
{"ScriptedGameEventReceived", menu_event::ScriptedGameEventReceived},
|
||||
{"MenuUnloaded", menu_event::MenuUnloaded},
|
||||
{"ScriptsReloaded", menu_event::ScriptsReloaded},
|
||||
});
|
||||
|
||||
|
||||
|
43
src/lua/bindings/self.cpp
Normal file
43
src/lua/bindings/self.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include "self.hpp"
|
||||
|
||||
namespace lua_self = self;
|
||||
|
||||
namespace lua::self
|
||||
{
|
||||
static Ped get_ped()
|
||||
{
|
||||
return lua_self::ped;
|
||||
}
|
||||
|
||||
static Player get_id()
|
||||
{
|
||||
return lua_self::id;
|
||||
}
|
||||
|
||||
static Vector3 get_pos()
|
||||
{
|
||||
return lua_self::pos;
|
||||
}
|
||||
|
||||
static Vector3 get_rot()
|
||||
{
|
||||
return lua_self::rot;
|
||||
}
|
||||
|
||||
static Vehicle get_veh()
|
||||
{
|
||||
return lua_self::veh;
|
||||
}
|
||||
|
||||
void bind(sol::state& state)
|
||||
{
|
||||
auto ns = state["self"].get_or_create<sol::table>();
|
||||
|
||||
ns["get_ped"] = get_ped;
|
||||
ns["get_id"] = get_id;
|
||||
ns["get_pos"] = get_pos;
|
||||
ns["get_rot"] = get_rot;
|
||||
ns["get_veh"] = get_veh;
|
||||
}
|
||||
}
|
6
src/lua/bindings/self.hpp
Normal file
6
src/lua/bindings/self.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace lua::self
|
||||
{
|
||||
void bind(sol::state& state);
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
#include "bindings/native.hpp"
|
||||
#include "bindings/network.hpp"
|
||||
#include "bindings/script.hpp"
|
||||
#include "bindings/self.hpp"
|
||||
#include "bindings/stats.hpp"
|
||||
#include "bindings/tunables.hpp"
|
||||
#include "bindings/vector.hpp"
|
||||
@ -283,6 +284,7 @@ namespace big
|
||||
lua::global_table::bind(m_state);
|
||||
lua::imgui::bind(m_state, m_state.globals());
|
||||
lua::entities::bind(m_state);
|
||||
lua::self::bind(m_state);
|
||||
lua::stats::bind(m_state);
|
||||
lua::weapons::bind(m_state);
|
||||
lua::vehicles::bind(m_state);
|
||||
|
@ -31,6 +31,7 @@ namespace big
|
||||
// empty the pool, we want the that job below run no matter what for clean up purposes.
|
||||
g_fiber_pool->reset();
|
||||
g_fiber_pool->queue_job([] {
|
||||
g_lua_manager->trigger_event<menu_event::MenuUnloaded>();
|
||||
for (auto& command : g_looped_commands)
|
||||
if (command->is_enabled())
|
||||
command->on_disable();
|
||||
@ -40,6 +41,7 @@ namespace big
|
||||
}
|
||||
else
|
||||
{
|
||||
g_lua_manager->trigger_event<menu_event::MenuUnloaded>();
|
||||
g_running = false;
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,11 @@ namespace big
|
||||
|
||||
if (components::button("VIEW_LUA_SCRIPTS_RELOAD_ALL"_T))
|
||||
{
|
||||
g_lua_manager->unload_all_modules();
|
||||
g_lua_manager->load_all_modules();
|
||||
g_fiber_pool->queue_job([] {
|
||||
g_lua_manager->trigger_event<menu_event::ScriptsReloaded>();
|
||||
g_lua_manager->unload_all_modules();
|
||||
g_lua_manager->load_all_modules();
|
||||
});
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("VIEW_LUA_SCRIPTS_AUTO_RELOAD_CHANGED_SCRIPTS"_T.data(), &g.lua.enable_auto_reload_changed_scripts);
|
||||
|
Loading…
Reference in New Issue
Block a user