Some fixes

This commit is contained in:
Federico Cecchetto 2021-09-20 21:43:01 +02:00
parent 1c9069b5ce
commit 8e4b8fc37a
3 changed files with 16 additions and 6 deletions

View File

@ -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]);
}
}

View File

@ -624,6 +624,16 @@ namespace ui_scripting::lua
auto game_type = state.new_usertype<game>("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();

View File

@ -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)