Some fixes
This commit is contained in:
parent
c981bb2b47
commit
5c345fc275
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "game/game.hpp"
|
||||
#include "value.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
@ -75,7 +76,7 @@ namespace ui_scripting
|
||||
alignment horzalign = alignment::start;
|
||||
alignment vertalign = alignment::start;
|
||||
|
||||
std::unordered_map<std::string, std::string> attributes = {};
|
||||
std::unordered_map<std::string, value> attributes = {};
|
||||
std::string font = "default";
|
||||
std::string material = "white";
|
||||
std::string border_material = "white";
|
||||
|
12
src/client/game/ui_scripting/event.hpp
Normal file
12
src/client/game/ui_scripting/event.hpp
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "value.hpp"
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
struct event
|
||||
{
|
||||
std::string name;
|
||||
const void* element{};
|
||||
arguments arguments;
|
||||
};
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#include <std_include.hpp>
|
||||
#include "value.hpp"
|
||||
#include "execution.hpp"
|
||||
|
||||
#include "component/ui_scripting.hpp"
|
||||
|
@ -3,7 +3,5 @@
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
using value = std::variant<std::monostate, bool, int, float, std::string>;
|
||||
using arguments = std::vector<value>;
|
||||
value call(const std::string& name, const arguments& arguments);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "context.hpp"
|
||||
#include "error.hpp"
|
||||
#include "../../scripting/execution.hpp"
|
||||
#include "../value.hpp"
|
||||
#include "../execution.hpp"
|
||||
|
||||
#include "../../../component/ui_scripting.hpp"
|
||||
@ -504,18 +505,17 @@ namespace ui_scripting::lua
|
||||
|
||||
for (auto arg : va)
|
||||
{
|
||||
if (arg.get_type() == sol::type::number)
|
||||
if (arg.is<value>())
|
||||
{
|
||||
event.arguments.push_back(arg.as<int>());
|
||||
event.arguments.push_back(arg.as<value>());
|
||||
}
|
||||
|
||||
if (arg.get_type() == sol::type::string)
|
||||
else
|
||||
{
|
||||
event.arguments.push_back(arg.as<std::string>());
|
||||
event.arguments.push_back({});
|
||||
}
|
||||
}
|
||||
|
||||
handler.dispatch(event);
|
||||
lua::engine::notify(event);
|
||||
};
|
||||
|
||||
element_type["hidden"] = sol::property(
|
||||
@ -529,7 +529,7 @@ namespace ui_scripting::lua
|
||||
}
|
||||
);
|
||||
|
||||
element_type[sol::meta_function::new_index] = [](element& element, const std::string& attribute, const std::string& value)
|
||||
element_type[sol::meta_function::new_index] = [](element& element, const std::string& attribute, const value& value)
|
||||
{
|
||||
element.attributes[attribute] = value;
|
||||
};
|
||||
@ -579,18 +579,17 @@ namespace ui_scripting::lua
|
||||
|
||||
for (auto arg : va)
|
||||
{
|
||||
if (arg.get_type() == sol::type::number)
|
||||
if (arg.is<value>())
|
||||
{
|
||||
event.arguments.push_back(arg.as<int>());
|
||||
event.arguments.push_back(arg.as<value>());
|
||||
}
|
||||
|
||||
if (arg.get_type() == sol::type::string)
|
||||
else
|
||||
{
|
||||
event.arguments.push_back(arg.as<std::string>());
|
||||
event.arguments.push_back({});
|
||||
}
|
||||
}
|
||||
|
||||
handler.dispatch(event);
|
||||
lua::engine::notify(event);
|
||||
};
|
||||
|
||||
menu_type["addchild"] = [](const sol::this_state s, menu& menu, element& element)
|
||||
@ -656,7 +655,7 @@ namespace ui_scripting::lua
|
||||
menu.close();
|
||||
};
|
||||
|
||||
menu_type["getelement"] = [](menu& menu, const sol::this_state s, const std::string& value, const std::string& attribute)
|
||||
menu_type["getelement"] = [](menu& menu, const sol::this_state s, const value& value, const std::string& attribute)
|
||||
{
|
||||
for (const auto& element : menu.children)
|
||||
{
|
||||
@ -671,7 +670,7 @@ namespace ui_scripting::lua
|
||||
|
||||
menu_type["getelements"] = sol::overload
|
||||
(
|
||||
[](menu& menu, const sol::this_state s, const std::string& value, const std::string& attribute)
|
||||
[](menu& menu, const sol::this_state s, const value& value, const std::string& attribute)
|
||||
{
|
||||
auto result = sol::table::create(s.lua_state());
|
||||
|
||||
@ -714,7 +713,7 @@ namespace ui_scripting::lua
|
||||
return sol::lua_value{s, &menus[name]};
|
||||
};
|
||||
|
||||
game_type["getelement"] = [](const game&, const sol::this_state s, const std::string& value, const std::string& attribute)
|
||||
game_type["getelement"] = [](const game&, const sol::this_state s, const value& value, const std::string& attribute)
|
||||
{
|
||||
for (const auto& element : elements)
|
||||
{
|
||||
@ -729,7 +728,7 @@ namespace ui_scripting::lua
|
||||
|
||||
game_type["getelements"] = sol::overload
|
||||
(
|
||||
[](const game&, const sol::this_state s, const std::string& value, const std::string& attribute)
|
||||
[](const game&, const sol::this_state s, const value& value, const std::string& attribute)
|
||||
{
|
||||
auto result = sol::table::create(s.lua_state());
|
||||
|
||||
@ -954,6 +953,11 @@ namespace ui_scripting::lua
|
||||
::game::Dvar_SetCommand(hash, "", string_value.data());
|
||||
};
|
||||
|
||||
game_type["playsound"] = [](const game&, const std::string& sound)
|
||||
{
|
||||
::game::UI_PlayLocalSoundAlias(0, sound.data());
|
||||
};
|
||||
|
||||
game_type["getwindowsize"] = [](const game&, const sol::this_state s)
|
||||
{
|
||||
const auto size = ::game::ScrPlace_GetViewPlacement()->realViewportSize;
|
||||
|
@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../event.hpp"
|
||||
#include "../menu.hpp"
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4702)
|
||||
|
||||
@ -7,8 +10,7 @@
|
||||
#define SOL_PRINT_ERRORS 0
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include "../menu.hpp"
|
||||
#include "event.hpp"
|
||||
#include "engine.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "event_handler.hpp"
|
||||
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
namespace ui_scripting::lua::engine
|
||||
{
|
||||
void notify(const event& e);
|
||||
|
||||
namespace
|
||||
{
|
||||
float screen_max[2];
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../event.hpp"
|
||||
|
||||
namespace ui_scripting::lua::engine
|
||||
{
|
||||
void start();
|
||||
@ -9,5 +11,6 @@ namespace ui_scripting::lua::engine
|
||||
void open_menu(const std::string& name);
|
||||
|
||||
void ui_event(const std::string&, const std::vector<int>&);
|
||||
void notify(const event& e);
|
||||
void run_frame();
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
namespace ui_scripting::lua
|
||||
{
|
||||
struct event
|
||||
{
|
||||
std::string name;
|
||||
const void* element{};
|
||||
std::vector<std::variant<int, std::string>> arguments;
|
||||
};
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
#include "std_include.hpp"
|
||||
#include "context.hpp"
|
||||
#include "error.hpp"
|
||||
#include "../../scripting/lua/value_conversion.hpp"
|
||||
|
||||
#include "event_handler.hpp"
|
||||
|
||||
@ -168,20 +167,14 @@ namespace ui_scripting::lua
|
||||
|
||||
for (const auto& argument : event.arguments)
|
||||
{
|
||||
const auto index = argument.index();
|
||||
|
||||
if (index == 0)
|
||||
if (argument.index() > 0)
|
||||
{
|
||||
const sol::lua_value value = {this->state_, std::get<int>(argument)};
|
||||
arguments.emplace_back(value);
|
||||
arguments.emplace_back(argument);
|
||||
}
|
||||
|
||||
if (index == 1)
|
||||
else
|
||||
{
|
||||
const sol::lua_value value = {this->state_, std::get<std::string>(argument)};
|
||||
arguments.emplace_back(value);
|
||||
arguments.emplace_back(sol::lua_value{this->state_, sol::lua_nil});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return arguments;
|
||||
|
7
src/client/game/ui_scripting/value.hpp
Normal file
7
src/client/game/ui_scripting/value.hpp
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace ui_scripting
|
||||
{
|
||||
using value = std::variant<std::monostate, bool, int, float, std::string>;
|
||||
using arguments = std::vector<value>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user