Skip to content

Commit

Permalink
Fix alpha color
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Jan 19, 2025
1 parent 4ea12d6 commit 064dab0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
7 changes: 5 additions & 2 deletions UICONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"topLeftY": <y>, | Distance y from parent
"bgColor": [<r>, <g>, <b>, <a>], | Background color
"fgColor": [<r>, <g>, <b>, <a>], | Text color
"text": "<text>", |
"fgSize": <f>, | Text size
"text": "<text>", | Text
"visible": <true/false>, | Is it draw to screen
"clickable": <true/false>, | Is it clickable (it can be ...
| ... invisible but still be ...
Expand All @@ -106,6 +107,7 @@
"topLeftY": <y>, | Distance y from parent
"bgColor": [<r>, <g>, <b>, <a>], | Background color
"fgColor": [<r>, <g>, <b>, <a>], | Text color
"fgSize": <f>, | Text size
"placeholder": "<text>", | Text displayed before the ...
| ... client enter some text
"visible": <true/false>, | Is it draw to screen
Expand All @@ -122,7 +124,8 @@
"topLeftY": <y>, | Distance y from 0 (window)
"bgColor": [<r>, <g>, <b>, <a>], | Background color
"fgColor": [<r>, <g>, <b>, <a>], | Text color
"text": "<text>", |
"fgSize": <f>, | Text size
"text": "<text>", | Text
"choices": { |
"<key>": "<text>", | When the <text> is clicked ...
| ... the key will be sent
Expand Down
25 changes: 25 additions & 0 deletions client/src/uiconf/UIConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ UIConf::UIButtonText::UIButtonText(const nlohmann::json &config)
throw std::runtime_error("`fgColor` not in json or bad format (array expected)");
}
_fgColor = fgColor.value();
const auto fgSize = json_get<float>(config, "fgSize");
if (!fgSize.has_value()) {
throw std::runtime_error("`fgSize` not in json or bad format (float expected)");
}
_fgSize = fgSize.value();
const auto visible = json_get<bool>(config, "visible");
if (!visible.has_value()) {
throw std::runtime_error("`visible` not in json or bad format (bool expected)");
Expand Down Expand Up @@ -544,6 +549,8 @@ bool UIConf::UIButtonText::modify(
return false;
}
_fgColor = fgColor.value();
} else if (key == "fgSize") {
_fgSize = value.template get<float>();
} else if (key == "visible" && value.is_boolean()) {
_visible = value.template get<bool>();
} else if (key == "clickable" && value.is_boolean()) {
Expand All @@ -563,6 +570,10 @@ void UIConf::UIButtonText::update(raylib::Window &window, float parentX, float p
_textR.text = _text;
if (_fgColor != raylib::Color(_textR.GetColor()))
_textR.SetColor(_fgColor);
if (_textR.GetFontSize() != _fgSize)
_textR.SetFontSize(_fgSize);
if (_textR.GetSpacing() != _fgSpacing)
_textR.SetSpacing(_fgSpacing);
const auto textSize = _textR.MeasureEx();
if (_rectR.width != textSize.x)
_rectR.SetWidth(textSize.x);
Expand Down Expand Up @@ -644,6 +655,11 @@ UIConf::UITextEntry::UITextEntry(const nlohmann::json &config)
if (!visible.has_value()) {
throw std::runtime_error("`visible` not in json or bad format (bool expected)");
}
const auto fgSize = json_get<float>(config, "fgSize");
if (!fgSize.has_value()) {
throw std::runtime_error("`fgSize` not in json or bad format (float expected)");
}
_fgSize = fgSize.value();
_visible = visible.value();
const auto clickable = json_get<bool>(config, "clickable");
if (!clickable.has_value()) {
Expand Down Expand Up @@ -677,6 +693,8 @@ bool UIConf::UITextEntry::modify(
return false;
}
_fgColor = fgColor.value();
} else if (key == "fgSize") {
_fgSize = value.template get<float>();
} else if (key == "visible" && value.is_boolean()) {
_visible = value.template get<bool>();
} else if (key == "clickable" && value.is_boolean()) {
Expand Down Expand Up @@ -787,6 +805,11 @@ UIConf::UIPopUp::UIPopUp(const std::string &id, const nlohmann::json &config)
if (!visible.has_value()) {
throw std::runtime_error("`visible` not in json or bad format (bool expected)");
}
const auto fgSize = json_get<float>(config, "fgSize");
if (!fgSize.has_value()) {
throw std::runtime_error("`fgSize` not in json or bad format (float expected)");
}
_fgSize = fgSize.value();
_visible = visible.value();
if (!config.contains("choices") || !config.at("choices").is_object()) {
throw std::runtime_error("`choices` not in json or bad format (object expected)");
Expand Down Expand Up @@ -824,6 +847,8 @@ bool UIConf::UIPopUp::modify(
return false;
}
_fgColor = fgColor.value();
} else if (key == "fgSize") {
_fgSize = value.template get<float>();
} else if (key == "choices") {
_choices.clear();
for (const auto &[key, value] : value.items()) {
Expand Down
5 changes: 5 additions & 0 deletions client/src/uiconf/UIConf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class UIConf {
float _topLeftY;
raylib::Color _bgColor;
raylib::Color _fgColor;
float _fgSize;
float _fgSpacing = 2;
std::string _text;
bool _visible;
bool _clickable;
Expand Down Expand Up @@ -131,6 +133,8 @@ class UIConf {
float _topLeftY;
raylib::Color _bgColor;
raylib::Color _fgColor;
float _fgSize;
float _fgSpacing = 2;
std::string _placeholder;
bool _visible;
bool _clickable;
Expand Down Expand Up @@ -159,6 +163,7 @@ class UIConf {
float _topLeftY;
raylib::Color _bgColor;
raylib::Color _fgColor;
float _fgSize;
std::string _text;
std::map<std::string, std::string> _choices;
bool _visible;
Expand Down
7 changes: 4 additions & 3 deletions server/assets/uiconf/catan.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
{
"id": "title",
"type": "button_text",
"topLeftX": 10.0,
"topLeftX": 300.0,
"topLeftY": 10.0,
"bgColor": [0, 0, 0, 0],
"fgColor": [124, 252, 0, 0],
"bgColor": [0, 0, 0, 255],
"fgColor": [124, 252, 0, 255],
"fgSize": 25.0,
"text": "Catan",
"visible": true,
"clickable": false
Expand Down

0 comments on commit 064dab0

Please sign in to comment.