From 8e4b8fc37a29d5f51aca24b5a4db150724720c6b Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 20 Sep 2021 21:43:01 +0200 Subject: [PATCH] Some fixes --- src/client/game/ui_scripting/element.cpp | 4 ++-- src/client/game/ui_scripting/lua/context.cpp | 12 +++++++++++- src/client/game/ui_scripting/lua/engine.cpp | 6 +++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/client/game/ui_scripting/element.cpp b/src/client/game/ui_scripting/element.cpp index 0890f6ad..1ca2e5e9 100644 --- a/src/client/game/ui_scripting/element.cpp +++ b/src/client/game/ui_scripting/element.cpp @@ -97,12 +97,12 @@ namespace ui_scripting float relative(float value) { - return (value / 1920.f) * screen_max[0]; + return ceil((value / 1920.f) * screen_max[0]); } int relative(int value) { - return (int)(((float)value / 1920.f) * screen_max[0]); + return (int)ceil(((float)value / 1920.f) * screen_max[0]); } } diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 0550ec42..1840135c 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -624,6 +624,16 @@ namespace ui_scripting::lua auto game_type = state.new_usertype("game_"); state["game"] = game(); + game_type["getmenu"] = [](const game&, const sol::this_state s, const std::string& name) + { + if (menus.find(name) == menus.end()) + { + return sol::lua_value{s, sol::lua_nil}; + } + + 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) { for (const auto& element : elements) @@ -716,7 +726,7 @@ namespace ui_scripting::lua event event; event.element = menu; - event.name = "close"; + event.name = "open"; handler.dispatch(event); menu->open(); diff --git a/src/client/game/ui_scripting/lua/engine.cpp b/src/client/game/ui_scripting/lua/engine.cpp index d5ac70d3..4863c1c0 100644 --- a/src/client/game/ui_scripting/lua/engine.cpp +++ b/src/client/game/ui_scripting/lua/engine.cpp @@ -23,17 +23,17 @@ namespace ui_scripting::lua::engine int relative_mouse(int value) { - return (int)(((float)value / screen_max[0]) * 1920.f); + return (int)ceil(((float)value / screen_max[0]) * 1920.f); } int relative(int value) { - return (int)(((float)value / 1920.f) * screen_max[0]); + return (int)ceil(((float)value / 1920.f) * screen_max[0]); } float relative(float value) { - return (value / 1920.f) * screen_max[0]; + return ceil((value / 1920.f) * screen_max[0]); } bool point_in_rect(int px, int py, int x, int y, int w, int h)