Lua Scripting (#1334)
Closes #83 Fixes #1309 Fixes #1287 Fixes #1129 (actually fixed now)
This commit is contained in:
19
src/lua/bindings/gui/base_text_element.cpp
Normal file
19
src/lua/bindings/gui/base_text_element.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "base_text_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
base_text_element::base_text_element(std::string text) :
|
||||
m_text(text)
|
||||
{
|
||||
}
|
||||
|
||||
void base_text_element::set_text(std::string new_text)
|
||||
{
|
||||
m_text = new_text;
|
||||
}
|
||||
|
||||
std::string base_text_element::get_text()
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
}
|
17
src/lua/bindings/gui/base_text_element.hpp
Normal file
17
src/lua/bindings/gui/base_text_element.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "gui_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class base_text_element : public gui_element
|
||||
{
|
||||
protected:
|
||||
std::string m_text;
|
||||
|
||||
public:
|
||||
base_text_element(std::string text);
|
||||
|
||||
void set_text(std::string new_text);
|
||||
std::string get_text();
|
||||
};
|
||||
}
|
34
src/lua/bindings/gui/button.cpp
Normal file
34
src/lua/bindings/gui/button.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "button.hpp"
|
||||
|
||||
#include "fiber_pool.hpp"
|
||||
#include "lua/lua_manager.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
button::button(std::string text, sol::function callback) :
|
||||
base_text_element(text),
|
||||
m_callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
void button::draw()
|
||||
{
|
||||
if (ImGui::Button(m_text.data()))
|
||||
{
|
||||
if (m_execute_in_fiber_pool)
|
||||
{
|
||||
big::g_fiber_pool->queue_job([this] {
|
||||
auto res = m_callback();
|
||||
if (!res.valid())
|
||||
big::g_lua_manager->handle_error(res, res.lua_state());
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
auto res = m_callback();
|
||||
if (!res.valid())
|
||||
big::g_lua_manager->handle_error(res, res.lua_state());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
src/lua/bindings/gui/button.hpp
Normal file
17
src/lua/bindings/gui/button.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
#include "lua/sol.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class button : public base_text_element
|
||||
{
|
||||
sol::function m_callback;
|
||||
bool m_execute_in_fiber_pool = true;
|
||||
|
||||
public:
|
||||
button(std::string text, sol::function callback);
|
||||
|
||||
void draw() override;
|
||||
};
|
||||
}
|
24
src/lua/bindings/gui/checkbox.cpp
Normal file
24
src/lua/bindings/gui/checkbox.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "checkbox.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
checkbox::checkbox(std::string text) :
|
||||
base_text_element(text)
|
||||
{
|
||||
}
|
||||
|
||||
void checkbox::draw()
|
||||
{
|
||||
ImGui::Checkbox(m_text.data(), &m_enabled);
|
||||
}
|
||||
|
||||
bool checkbox::is_enabled()
|
||||
{
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
void checkbox::set_enabled(bool enabled)
|
||||
{
|
||||
m_enabled = enabled;
|
||||
}
|
||||
}
|
18
src/lua/bindings/gui/checkbox.hpp
Normal file
18
src/lua/bindings/gui/checkbox.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class checkbox : public base_text_element
|
||||
{
|
||||
bool m_enabled = false;
|
||||
|
||||
public:
|
||||
checkbox(std::string text);
|
||||
|
||||
void draw() override;
|
||||
|
||||
bool is_enabled();
|
||||
void set_enabled(bool enabled);
|
||||
};
|
||||
}
|
10
src/lua/bindings/gui/gui_element.hpp
Normal file
10
src/lua/bindings/gui/gui_element.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class gui_element
|
||||
{
|
||||
public:
|
||||
virtual void draw() = 0;
|
||||
};
|
||||
}
|
24
src/lua/bindings/gui/input_float.cpp
Normal file
24
src/lua/bindings/gui/input_float.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "input_float.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
input_float::input_float(std::string text) :
|
||||
base_text_element(text)
|
||||
{
|
||||
}
|
||||
|
||||
void input_float::draw()
|
||||
{
|
||||
ImGui::InputFloat(m_text.c_str(), &m_value);
|
||||
}
|
||||
|
||||
int input_float::get_value()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void input_float::set_value(float val)
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
}
|
19
src/lua/bindings/gui/input_float.hpp
Normal file
19
src/lua/bindings/gui/input_float.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class input_float : public base_text_element
|
||||
{
|
||||
bool m_enabled = false;
|
||||
float m_value = 0;
|
||||
|
||||
public:
|
||||
input_float(std::string text);
|
||||
|
||||
void draw() override;
|
||||
|
||||
int get_value();
|
||||
void set_value(float val);
|
||||
};
|
||||
}
|
24
src/lua/bindings/gui/input_int.cpp
Normal file
24
src/lua/bindings/gui/input_int.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "input_int.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
input_int::input_int(std::string text) :
|
||||
base_text_element(text)
|
||||
{
|
||||
}
|
||||
|
||||
void input_int::draw()
|
||||
{
|
||||
ImGui::InputInt(m_text.c_str(), &m_value);
|
||||
}
|
||||
|
||||
int input_int::get_value()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void input_int::set_value(int val)
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
}
|
19
src/lua/bindings/gui/input_int.hpp
Normal file
19
src/lua/bindings/gui/input_int.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class input_int : public base_text_element
|
||||
{
|
||||
bool m_enabled = false;
|
||||
int m_value = 0;
|
||||
|
||||
public:
|
||||
input_int(std::string text);
|
||||
|
||||
void draw() override;
|
||||
|
||||
int get_value();
|
||||
void set_value(int val);
|
||||
};
|
||||
}
|
24
src/lua/bindings/gui/input_string.cpp
Normal file
24
src/lua/bindings/gui/input_string.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "input_string.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
input_string::input_string(std::string text) :
|
||||
base_text_element(text)
|
||||
{
|
||||
}
|
||||
|
||||
void input_string::draw()
|
||||
{
|
||||
ImGui::InputText(m_text.c_str(), m_value, sizeof(m_value));
|
||||
}
|
||||
|
||||
std::string input_string::get_value()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void input_string::set_value(std::string val)
|
||||
{
|
||||
strncpy(m_value, val.c_str(), sizeof(m_value));
|
||||
}
|
||||
}
|
19
src/lua/bindings/gui/input_string.hpp
Normal file
19
src/lua/bindings/gui/input_string.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class input_string : public base_text_element
|
||||
{
|
||||
bool m_enabled = false;
|
||||
char m_value[255] = {};
|
||||
|
||||
public:
|
||||
input_string(std::string text);
|
||||
|
||||
void draw() override;
|
||||
|
||||
std::string get_value();
|
||||
void set_value(std::string val);
|
||||
};
|
||||
}
|
9
src/lua/bindings/gui/sameline.cpp
Normal file
9
src/lua/bindings/gui/sameline.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "sameline.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
void sameline::draw()
|
||||
{
|
||||
ImGui::SameLine();
|
||||
}
|
||||
}
|
13
src/lua/bindings/gui/sameline.hpp
Normal file
13
src/lua/bindings/gui/sameline.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "gui_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class sameline : public gui_element
|
||||
{
|
||||
public:
|
||||
sameline(){};
|
||||
|
||||
void draw() override;
|
||||
};
|
||||
}
|
9
src/lua/bindings/gui/separator.cpp
Normal file
9
src/lua/bindings/gui/separator.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "separator.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
void separator::draw()
|
||||
{
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
13
src/lua/bindings/gui/separator.hpp
Normal file
13
src/lua/bindings/gui/separator.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "gui_element.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class separator : public gui_element
|
||||
{
|
||||
public:
|
||||
separator(){};
|
||||
|
||||
void draw() override;
|
||||
};
|
||||
}
|
32
src/lua/bindings/gui/text.cpp
Normal file
32
src/lua/bindings/gui/text.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "text.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
text::text(std::string text) :
|
||||
base_text_element(text)
|
||||
{
|
||||
}
|
||||
|
||||
void text::draw()
|
||||
{
|
||||
if (m_font)
|
||||
ImGui::PushFont(m_font);
|
||||
ImGui::Text(m_text.data());
|
||||
if (m_font)
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
void text::set_font(std::string font)
|
||||
{
|
||||
auto hash = rage::joaat(font);
|
||||
|
||||
switch (hash)
|
||||
{
|
||||
case RAGE_JOAAT("title"): m_font = big::g.window.font_title; break;
|
||||
case RAGE_JOAAT("subtitle"): m_font = big::g.window.font_sub_title; break;
|
||||
case RAGE_JOAAT("small"): m_font = big::g.window.font_small; break;
|
||||
case RAGE_JOAAT("icon"): m_font = big::g.window.font_icon; break;
|
||||
default: m_font = nullptr; break;
|
||||
}
|
||||
}
|
||||
}
|
17
src/lua/bindings/gui/text.hpp
Normal file
17
src/lua/bindings/gui/text.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "base_text_element.hpp"
|
||||
#include "lua/sol.hpp"
|
||||
|
||||
namespace lua::gui
|
||||
{
|
||||
class text : public base_text_element
|
||||
{
|
||||
ImFont* m_font = nullptr;
|
||||
|
||||
public:
|
||||
text(std::string text);
|
||||
|
||||
void draw() override;
|
||||
void set_font(std::string font);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user