Text glow color

This commit is contained in:
Federico Cecchetto 2021-09-14 22:42:44 +02:00
parent a679544531
commit 83ccb92c54
5 changed files with 52 additions and 6 deletions

View File

@ -48,6 +48,9 @@ namespace game
WEAK symbol<int(const char* fname)> generateHashValue{0x343D20}; WEAK symbol<int(const char* fname)> generateHashValue{0x343D20};
WEAK symbol<bool()> CL_IsCgameInitialized{0x3CA0C0}; WEAK symbol<bool()> CL_IsCgameInitialized{0x3CA0C0};
WEAK symbol<void(const char* text, int maxChars, Font_s* font, float x, float y, float xScale, float yScale,
const float* color, int style, const float* glowColor, Material* fxMaterial, Material* fxMaterialGlow,
int fxBirthTime, int fxLetterTime, int fxDecayStartTime, int fxDecayDuration, int a17)> CL_DrawTextPhysicalWithEffects{0x3D4990};
WEAK symbol<unsigned int (unsigned int parentId, unsigned int name)> FindVariable{0x5C1D50}; WEAK symbol<unsigned int (unsigned int parentId, unsigned int name)> FindVariable{0x5C1D50};
WEAK symbol<unsigned int(int entnum, unsigned int classnum)> FindEntityId{0x5C1C50}; WEAK symbol<unsigned int(int entnum, unsigned int classnum)> FindEntityId{0x5C1C50};

View File

@ -192,6 +192,14 @@ namespace ui_scripting
this->color[3] = a; this->color[3] = a;
} }
void element::set_glow_color(float r, float g, float b, float a)
{
this->glow_color[0] = r;
this->glow_color[1] = g;
this->glow_color[2] = b;
this->glow_color[3] = a;
}
void element::set_border_material(const std::string& _material) void element::set_border_material(const std::string& _material)
{ {
this->border_material = _material; this->border_material = _material;
@ -331,11 +339,16 @@ namespace ui_scripting
auto _horzalign = get_align_value(this->horzalign, (float)text_width, relative(this->w)); auto _horzalign = get_align_value(this->horzalign, (float)text_width, relative(this->w));
auto _vertalign = get_align_value(this->vertalign, (float)relative(this->fontsize), relative(this->h)); auto _vertalign = get_align_value(this->vertalign, (float)relative(this->fontsize), relative(this->h));
game::R_AddCmdDrawText(this->text.data(), 0x7FFFFFFF, _font, game::CL_DrawTextPhysicalWithEffects(
this->text.data(),
0x7FFFFFFF,
_font,
relative(this->x) + relative(this->text_offset[0]) + _horzalign + relative(this->border_width[3]), relative(this->x) + relative(this->text_offset[0]) + _horzalign + relative(this->border_width[3]),
relative(this->y) + relative(this->text_offset[1]) + _vertalign + relative(this->fontsize) + relative(this->border_width[0]), relative(this->y) + relative(this->text_offset[1]) + _vertalign + relative(this->fontsize) + relative(this->border_width[0]),
1.0f, 1.0f, 0.0f, 1.f, 1.f,
(float*)this->color, 0 (float*)this->color, 0,
(float*)this->glow_color,
0, 0, 0, 0, 0, 0, 0
); );
} }
} }

View File

@ -22,6 +22,7 @@ namespace ui_scripting
void set_font(const std::string& _font); void set_font(const std::string& _font);
void set_font(const std::string& _font, const int _fontsize); void set_font(const std::string& _font, const int _fontsize);
void set_color(float r, float g, float b, float a); void set_color(float r, float g, float b, float a);
void set_glow_color(float r, float g, float b, float a);
void set_text_offset(float x, float y); void set_text_offset(float x, float y);
void set_background_color(float r, float g, float b, float a); void set_background_color(float r, float g, float b, float a);
@ -51,6 +52,7 @@ namespace ui_scripting
float text_offset[2] = {0.f, 0.f}; float text_offset[2] = {0.f, 0.f};
float color[4] = {1.f, 1.f, 1.f, 1.f}; float color[4] = {1.f, 1.f, 1.f, 1.f};
float glow_color[4] = {0.f, 0.f, 0.f, 0.f};
float background_color[4] = {0.f, 0.f, 0.f, 0.f}; float background_color[4] = {0.f, 0.f, 0.f, 0.f};
float border_color[4] = {0.f, 0.f, 0.f, 0.f}; float border_color[4] = {0.f, 0.f, 0.f, 0.f};
float border_width[4] = {0.f, 0.f, 0.f, 0.f}; float border_width[4] = {0.f, 0.f, 0.f, 0.f};
@ -59,7 +61,7 @@ namespace ui_scripting
alignment horzalign = alignment::start; alignment horzalign = alignment::start;
alignment vertalign = alignment::start; alignment vertalign = alignment::start;
std::string font = "fonts/fira_mono_regular.ttf"; std::string font = "default";
std::string material = "white"; std::string material = "white";
std::string border_material = "white"; std::string border_material = "white";
std::string text{}; std::string text{};

View File

@ -195,6 +195,7 @@ namespace ui_scripting::lua
element_type["settext"] = &element::set_text; element_type["settext"] = &element::set_text;
element_type["setmaterial"] = &element::set_material; element_type["setmaterial"] = &element::set_material;
element_type["setcolor"] = &element::set_color; element_type["setcolor"] = &element::set_color;
element_type["setglowcolor"] = &element::set_glow_color;
element_type["setbackcolor"] = &element::set_background_color; element_type["setbackcolor"] = &element::set_background_color;
element_type["setbordercolor"] = &element::set_border_color; element_type["setbordercolor"] = &element::set_border_color;
element_type["setborderwidth"] = sol::overload( element_type["setborderwidth"] = sol::overload(
@ -280,6 +281,25 @@ namespace ui_scripting::lua
} }
); );
element_type["glowcolor"] = sol::property(
[](element& element, const sol::this_state s)
{
auto color = sol::table::create(s.lua_state());
color["r"] = element.glow_color[0];
color["g"] = element.glow_color[1];
color["b"] = element.glow_color[2];
color["a"] = element.glow_color[3];
return color;
},
[](element& element, const sol::lua_table color)
{
element.glow_color[0] = color["r"].get_type() == sol::type::number ? color["r"].get<float>() : 0.f;
element.glow_color[1] = color["g"].get_type() == sol::type::number ? color["g"].get<float>() : 0.f;
element.glow_color[2] = color["b"].get_type() == sol::type::number ? color["b"].get<float>() : 0.f;
element.glow_color[3] = color["a"].get_type() == sol::type::number ? color["a"].get<float>() : 0.f;
}
);
element_type["backcolor"] = sol::property( element_type["backcolor"] = sol::property(
[](element& element, const sol::this_state s) [](element& element, const sol::this_state s)
{ {

View File

@ -15,14 +15,22 @@ namespace ui_scripting
} }
void menu::open() void menu::open()
{
if (this->cursor)
{ {
*game::keyCatchers |= 0x40; *game::keyCatchers |= 0x40;
}
this->visible = true; this->visible = true;
} }
void menu::close() void menu::close()
{
if (this->cursor)
{ {
*game::keyCatchers &= ~0x40; *game::keyCatchers &= ~0x40;
}
this->visible = false; this->visible = false;
} }