mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
feat(lua): much more complete imgui bindings, allow lua imgui callbacks from outside yimmenu classic tabs through gui.add_imgui(func)
but also inside yimmenu classic tabs through tab:add_imgui(func)
(#1736)
This commit is contained in:
parent
0417fbf0f9
commit
664b5c6c40
6
docs/lua/classes/raw_imgui_callback.md
Normal file
6
docs/lua/classes/raw_imgui_callback.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Class: raw_imgui_callback
|
||||||
|
|
||||||
|
## Inherit from 1 class: gui_element
|
||||||
|
|
||||||
|
Class for representing a raw imgui callback.
|
||||||
|
|
@ -8,7 +8,7 @@ Class for gta script utils, the instance is usually given to you.
|
|||||||
|
|
||||||
Yield execution.
|
Yield execution.
|
||||||
|
|
||||||
**Exemple Usage:**
|
**Example Usage:**
|
||||||
```lua
|
```lua
|
||||||
script_util:yield()
|
script_util:yield()
|
||||||
```
|
```
|
||||||
@ -20,7 +20,7 @@ Sleep for the given amount of time, time is in milliseconds.
|
|||||||
- **Parameters:**
|
- **Parameters:**
|
||||||
- `ms` (integer): The amount of time in milliseconds that we will sleep for.
|
- `ms` (integer): The amount of time in milliseconds that we will sleep for.
|
||||||
|
|
||||||
**Exemple Usage:**
|
**Example Usage:**
|
||||||
```lua
|
```lua
|
||||||
script_util:sleep(ms)
|
script_util:sleep(ms)
|
||||||
```
|
```
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Class for representing a tab within the GUI.
|
Class for representing a tab within the GUI.
|
||||||
|
|
||||||
## Functions (10)
|
## Functions (11)
|
||||||
|
|
||||||
### `clear()`
|
### `clear()`
|
||||||
|
|
||||||
@ -134,4 +134,30 @@ Add a ImGui::InputText.
|
|||||||
input_string = tab:add_input_string(name)
|
input_string = tab:add_input_string(name)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `add_imgui(imgui_rendering)`
|
||||||
|
|
||||||
|
Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
**Example Usage:**
|
||||||
|
```lua
|
||||||
|
tab:add_imgui(function()
|
||||||
|
if ImGui.Begin("My Custom Window") then
|
||||||
|
if ImGui.Button("Label") then
|
||||||
|
script.run_in_fiber(function(script)
|
||||||
|
-- call natives in there
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
ImGui.End()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `imgui_rendering` (function): Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
|
||||||
|
**Example Usage:**
|
||||||
|
```lua
|
||||||
|
tab:add_imgui(imgui_rendering)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -766,7 +766,7 @@ Arg Count: 0
|
|||||||
Arg Count: 0
|
Arg Count: 0
|
||||||
|
|
||||||
### alwaysfullammo
|
### alwaysfullammo
|
||||||
Refills your ammo every tick
|
Refills your ammo every tick
|
||||||
Arg Count: 0
|
Arg Count: 0
|
||||||
|
|
||||||
### incrdamage
|
### incrdamage
|
||||||
|
1464
docs/lua/tables/ImGui.md
Normal file
1464
docs/lua/tables/ImGui.md
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Table containing functions for modifying the menu GUI.
|
Table containing functions for modifying the menu GUI.
|
||||||
|
|
||||||
## Functions (6)
|
## Functions (7)
|
||||||
|
|
||||||
### `get_tab(tab_name)`
|
### `get_tab(tab_name)`
|
||||||
|
|
||||||
@ -79,4 +79,30 @@ gui.show_error(title, message)
|
|||||||
bool = gui.is_open()
|
bool = gui.is_open()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `add_imgui(imgui_rendering)`
|
||||||
|
|
||||||
|
Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
**Example Usage:**
|
||||||
|
```lua
|
||||||
|
gui.add_imgui(function()
|
||||||
|
if ImGui.Begin("My Custom Window") then
|
||||||
|
if ImGui.Button("Label") then
|
||||||
|
script.run_in_fiber(function(script)
|
||||||
|
-- call natives in there
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
ImGui.End()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters:**
|
||||||
|
- `imgui_rendering` (function): Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
|
||||||
|
**Example Usage:**
|
||||||
|
```lua
|
||||||
|
gui.add_imgui(imgui_rendering)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,3 +75,4 @@ end)
|
|||||||
script.run_in_fiber(func)
|
script.run_in_fiber(func)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,11 +13,12 @@ end)
|
|||||||
|
|
||||||
For a complete list of available gui functions, please refer to the tab class documentation and the gui table documentation.
|
For a complete list of available gui functions, please refer to the tab class documentation and the gui table documentation.
|
||||||
|
|
||||||
## Tab Count: 42
|
## Tab Count: 43
|
||||||
|
|
||||||
### `GUI_TAB_SELF`
|
### `GUI_TAB_SELF`
|
||||||
### `GUI_TAB_WEAPONS`
|
### `GUI_TAB_WEAPONS`
|
||||||
### `GUI_TAB_TELEPORT`
|
### `GUI_TAB_TELEPORT`
|
||||||
|
### `GUI_TAB_CUSTOM_TELEPORT`
|
||||||
### `GUI_TAB_MOBILE`
|
### `GUI_TAB_MOBILE`
|
||||||
### `GUI_TAB_OUTFIT_EDITOR`
|
### `GUI_TAB_OUTFIT_EDITOR`
|
||||||
### `GUI_TAB_OUTFIT_SLOTS`
|
### `GUI_TAB_OUTFIT_SLOTS`
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "gui/input_float.hpp"
|
#include "gui/input_float.hpp"
|
||||||
#include "gui/input_int.hpp"
|
#include "gui/input_int.hpp"
|
||||||
#include "gui/input_string.hpp"
|
#include "gui/input_string.hpp"
|
||||||
|
#include "gui/raw_imgui_callback.hpp"
|
||||||
#include "gui/sameline.hpp"
|
#include "gui/sameline.hpp"
|
||||||
#include "gui/separator.hpp"
|
#include "gui/separator.hpp"
|
||||||
#include "gui/text.hpp"
|
#include "gui/text.hpp"
|
||||||
@ -13,6 +14,13 @@
|
|||||||
|
|
||||||
namespace lua::gui
|
namespace lua::gui
|
||||||
{
|
{
|
||||||
|
static void add_independent_element(lua_State* state, std::shared_ptr<lua::gui::gui_element> element)
|
||||||
|
{
|
||||||
|
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
|
||||||
|
|
||||||
|
module->m_independent_gui.push_back(std::move(element));
|
||||||
|
}
|
||||||
|
|
||||||
static void add_element(lua_State* state, std::uint32_t hash, std::shared_ptr<lua::gui::gui_element> element)
|
static void add_element(lua_State* state, std::uint32_t hash, std::shared_ptr<lua::gui::gui_element> element)
|
||||||
{
|
{
|
||||||
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
|
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
|
||||||
@ -51,7 +59,7 @@ namespace lua::gui
|
|||||||
m_id = nav_item.first;
|
m_id = nav_item.first;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_if_existing_tab_and_fill_id(nav_item.second.sub_nav))
|
if (check_if_existing_tab_and_fill_id(nav_item.second.sub_nav))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@ -81,7 +89,7 @@ namespace lua::gui
|
|||||||
std::pair<big::tabs, big::navigation_struct> make_tab_nav(const std::string& name, const rage::joaat_t tab_hash, const sol::this_state& state)
|
std::pair<big::tabs, big::navigation_struct> make_tab_nav(const std::string& name, const rage::joaat_t tab_hash, const sol::this_state& state)
|
||||||
{
|
{
|
||||||
static size_t custom_tab_count = size_t(big::tabs::RUNTIME_CUSTOM);
|
static size_t custom_tab_count = size_t(big::tabs::RUNTIME_CUSTOM);
|
||||||
m_id = big::tabs(custom_tab_count);
|
m_id = big::tabs(custom_tab_count);
|
||||||
|
|
||||||
custom_tab_count++;
|
custom_tab_count++;
|
||||||
|
|
||||||
@ -261,6 +269,32 @@ namespace lua::gui
|
|||||||
add_element(state, m_tab_hash, element);
|
add_element(state, m_tab_hash, element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lua API: Function
|
||||||
|
// Class: tab
|
||||||
|
// Name: add_imgui
|
||||||
|
// Param: imgui_rendering: function: Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
// Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
// **Example Usage:**
|
||||||
|
// ```lua
|
||||||
|
// tab:add_imgui(function()
|
||||||
|
// if ImGui.Begin("My Custom Window") then
|
||||||
|
// if ImGui.Button("Label") then
|
||||||
|
// script.run_in_fiber(function(script)
|
||||||
|
// -- call natives in there
|
||||||
|
// end)
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// ImGui.End()
|
||||||
|
// end
|
||||||
|
// end)
|
||||||
|
// ```
|
||||||
|
std::shared_ptr<lua::gui::raw_imgui_callback> add_imgui(sol::protected_function imgui_rendering, sol::this_state state)
|
||||||
|
{
|
||||||
|
auto element = std::make_shared<lua::gui::raw_imgui_callback>(imgui_rendering);
|
||||||
|
add_element(state, m_tab_hash, element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Lua API: Table
|
// Lua API: Table
|
||||||
@ -328,6 +362,32 @@ namespace lua::gui
|
|||||||
// Returns: bool: Returns true if the GUI is open.
|
// Returns: bool: Returns true if the GUI is open.
|
||||||
bool is_open();
|
bool is_open();
|
||||||
|
|
||||||
|
// Lua API: Function
|
||||||
|
// Table: gui
|
||||||
|
// Name: add_imgui
|
||||||
|
// Param: imgui_rendering: function: Function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
// Registers a function that will be called every rendering frame, you can call ImGui functions in it, please check the ImGui.md documentation file for more info.
|
||||||
|
// **Example Usage:**
|
||||||
|
// ```lua
|
||||||
|
// gui.add_imgui(function()
|
||||||
|
// if ImGui.Begin("My Custom Window") then
|
||||||
|
// if ImGui.Button("Label") then
|
||||||
|
// script.run_in_fiber(function(script)
|
||||||
|
// -- call natives in there
|
||||||
|
// end)
|
||||||
|
// end
|
||||||
|
//
|
||||||
|
// ImGui.End()
|
||||||
|
// end
|
||||||
|
// end)
|
||||||
|
// ```
|
||||||
|
static std::shared_ptr<lua::gui::raw_imgui_callback> add_imgui(sol::protected_function imgui_rendering, sol::this_state state)
|
||||||
|
{
|
||||||
|
auto element = std::make_shared<lua::gui::raw_imgui_callback>(imgui_rendering);
|
||||||
|
add_independent_element(state, element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
static void bind(sol::state& state)
|
static void bind(sol::state& state)
|
||||||
{
|
{
|
||||||
auto ns = state["gui"].get_or_create<sol::table>();
|
auto ns = state["gui"].get_or_create<sol::table>();
|
||||||
@ -337,6 +397,7 @@ namespace lua::gui
|
|||||||
ns["show_warning"] = show_warning;
|
ns["show_warning"] = show_warning;
|
||||||
ns["show_error"] = show_error;
|
ns["show_error"] = show_error;
|
||||||
ns["is_open"] = is_open;
|
ns["is_open"] = is_open;
|
||||||
|
ns["add_imgui"] = add_imgui;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
ns.new_usertype<lua::gui::button>("button",
|
ns.new_usertype<lua::gui::button>("button",
|
||||||
@ -391,7 +452,8 @@ namespace lua::gui
|
|||||||
"add_separator", &tab::add_separator,
|
"add_separator", &tab::add_separator,
|
||||||
"add_input_int", &tab::add_input_int,
|
"add_input_int", &tab::add_input_int,
|
||||||
"add_input_float", &tab::add_input_float,
|
"add_input_float", &tab::add_input_float,
|
||||||
"add_input_string", &tab::add_input_string
|
"add_input_string", &tab::add_input_string,
|
||||||
|
"add_imgui", &tab::add_imgui
|
||||||
);
|
);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
15
src/lua/bindings/gui/raw_imgui_callback.cpp
Normal file
15
src/lua/bindings/gui/raw_imgui_callback.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "raw_imgui_callback.hpp"
|
||||||
|
|
||||||
|
namespace lua::gui
|
||||||
|
{
|
||||||
|
raw_imgui_callback::raw_imgui_callback(sol::protected_function callback) :
|
||||||
|
m_callback(callback)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void raw_imgui_callback::draw()
|
||||||
|
{
|
||||||
|
m_callback();
|
||||||
|
}
|
||||||
|
}
|
20
src/lua/bindings/gui/raw_imgui_callback.hpp
Normal file
20
src/lua/bindings/gui/raw_imgui_callback.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gui_element.hpp"
|
||||||
|
#include "lua/sol.hpp"
|
||||||
|
|
||||||
|
namespace lua::gui
|
||||||
|
{
|
||||||
|
// Lua API: Class
|
||||||
|
// Name: raw_imgui_callback
|
||||||
|
// Inherit: gui_element
|
||||||
|
// Class for representing a raw imgui callback.
|
||||||
|
class raw_imgui_callback : public gui_element
|
||||||
|
{
|
||||||
|
sol::protected_function m_callback;
|
||||||
|
|
||||||
|
public:
|
||||||
|
raw_imgui_callback(sol::protected_function callback);
|
||||||
|
|
||||||
|
void draw() override;
|
||||||
|
};
|
||||||
|
}
|
3641
src/lua/bindings/imgui.hpp
Normal file
3641
src/lua/bindings/imgui.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -47,7 +47,7 @@ namespace lua::script
|
|||||||
// Param: name: string: name of your new looped script
|
// Param: name: string: name of your new looped script
|
||||||
// Param: func: function: function that will be executed in a forever loop.
|
// Param: func: function: function that will be executed in a forever loop.
|
||||||
// Registers a function that will be looped as a gta script.
|
// Registers a function that will be looped as a gta script.
|
||||||
// **Exemple Usage:**
|
// **Example Usage:**
|
||||||
// ```lua
|
// ```lua
|
||||||
// script.register_looped("nameOfMyLoopedScript", function (script)
|
// script.register_looped("nameOfMyLoopedScript", function (script)
|
||||||
// -- sleep until next game frame
|
// -- sleep until next game frame
|
||||||
@ -108,7 +108,7 @@ namespace lua::script
|
|||||||
// Name: run_in_fiber
|
// Name: run_in_fiber
|
||||||
// Param: func: function: function that will be executed once in the fiber pool.
|
// Param: func: function: function that will be executed once in the fiber pool.
|
||||||
// Executes a function once inside the fiber pool, you can call natives inside it and yield or sleep.
|
// Executes a function once inside the fiber pool, you can call natives inside it and yield or sleep.
|
||||||
// **Exemple Usage:**
|
// **Example Usage:**
|
||||||
// ```lua
|
// ```lua
|
||||||
// script.run_in_fiber(function (script)
|
// script.run_in_fiber(function (script)
|
||||||
// -- sleep until next game frame
|
// -- sleep until next game frame
|
||||||
|
@ -42,6 +42,19 @@ namespace big
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lua_manager::draw_independent_gui()
|
||||||
|
{
|
||||||
|
std::lock_guard guard(m_module_lock);
|
||||||
|
|
||||||
|
for (const auto& module : m_modules)
|
||||||
|
{
|
||||||
|
for (const auto& element : module->m_independent_gui)
|
||||||
|
{
|
||||||
|
element->draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void lua_manager::draw_gui(rage::joaat_t tab_hash)
|
void lua_manager::draw_gui(rage::joaat_t tab_hash)
|
||||||
{
|
{
|
||||||
std::lock_guard guard(m_module_lock);
|
std::lock_guard guard(m_module_lock);
|
||||||
|
@ -46,6 +46,7 @@ namespace big
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_independent_gui();
|
||||||
void draw_gui(rage::joaat_t tab_hash);
|
void draw_gui(rage::joaat_t tab_hash);
|
||||||
|
|
||||||
void unload_module(rage::joaat_t module_id);
|
void unload_module(rage::joaat_t module_id);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "bindings/script.hpp"
|
#include "bindings/script.hpp"
|
||||||
#include "bindings/tunables.hpp"
|
#include "bindings/tunables.hpp"
|
||||||
#include "bindings/vector.hpp"
|
#include "bindings/vector.hpp"
|
||||||
|
#include "bindings/imgui.hpp"
|
||||||
#include "file_manager.hpp"
|
#include "file_manager.hpp"
|
||||||
#include "script_mgr.hpp"
|
#include "script_mgr.hpp"
|
||||||
|
|
||||||
@ -215,5 +216,6 @@ namespace big
|
|||||||
lua::event::bind(state);
|
lua::event::bind(state);
|
||||||
lua::vector::bind(state);
|
lua::vector::bind(state);
|
||||||
lua::global_table::bind(state);
|
lua::global_table::bind(state);
|
||||||
|
lua::imgui::bind(state, state.globals());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,6 +26,7 @@ namespace big
|
|||||||
|
|
||||||
std::unordered_map<big::tabs, std::vector<big::tabs>> m_tab_to_sub_tabs;
|
std::unordered_map<big::tabs, std::vector<big::tabs>> m_tab_to_sub_tabs;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<lua::gui::gui_element>> m_independent_gui;
|
||||||
std::unordered_map<rage::joaat_t, std::vector<std::shared_ptr<lua::gui::gui_element>>> m_gui;
|
std::unordered_map<rage::joaat_t, std::vector<std::shared_ptr<lua::gui::gui_element>>> m_gui;
|
||||||
std::unordered_map<menu_event, std::vector<sol::protected_function>> m_event_callbacks;
|
std::unordered_map<menu_event, std::vector<sol::protected_function>> m_event_callbacks;
|
||||||
std::vector<void*> m_allocated_memory;
|
std::vector<void*> m_allocated_memory;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "views/view.hpp"
|
#include "views/view.hpp"
|
||||||
|
#include "lua/lua_manager.hpp"
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
@ -11,6 +12,9 @@ namespace big
|
|||||||
|
|
||||||
debug::main();
|
debug::main();
|
||||||
|
|
||||||
|
if (g_lua_manager)
|
||||||
|
g_lua_manager->draw_independent_gui();
|
||||||
|
|
||||||
if (g.window.demo) // It is not the YimMenu way.
|
if (g.window.demo) // It is not the YimMenu way.
|
||||||
ImGui::ShowDemoWindow(&g.window.demo);
|
ImGui::ShowDemoWindow(&g.window.demo);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user