-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Formspecs: Allow specifying a certain alpha value for the box[] element #7116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/gui/guiFormSpecMenu.cpp
Outdated
video::SColor tmp_color; | ||
|
||
bool use_color_alpha = false; | ||
if (parts.size() == 4 && parts[3] == "true") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's an is_yes function somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Are you sure this is backwards compatible? Also the "close on enter" feature (#4417) had to be changed to a new formspec element (#4566) due this strange version management system. |
Thanks for your comment, SmallJoker! Only the boxes that use the new fourth parameter will not be drawn in old clients. The "normal" old boxes with three parameters will work in all combinations. Here's a little table:
So, the statement from my first post is correct. (I tested it.) Thanks for your efforts! Edit (2018-03-10 14:17 UTC): I looked at the two PRs mentioned above again. I think this PR has technically the same problem, but a box, which is not drawn, usually doesn't cause problems, only the design might not look so good anymore. Another good thing is that with 0.5.0, both clients and server both must have the new system, so the "problem" mentioned above only occurs with -dev versions. |
src/gui/guiFormSpecMenu.cpp
Outdated
|
||
video::SColor tmp_color; | ||
|
||
bool use_color_alpha = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorter: bool use_color_alpha = parts.size() >= 4 && is_yes(parts[3]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a new argument added to the color parsing function which is the alpha if not specified. This can default to 1
PR updated according to @rubenwardy's comment. Tested and seems to work. |
src/util/string.cpp
Outdated
#endif | ||
|
||
static bool parseHexColorString(const std::string &value, video::SColor &color); | ||
static bool parseHexColorString(const std::string &value, video::SColor &color, unsigned char default_alpha = 0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long. Split after color,
src/util/string.cpp
Outdated
} | ||
|
||
bool parseColorString(const std::string &value, video::SColor &color, bool quiet) | ||
bool parseColorString(const std::string &value, video::SColor &color, bool quiet, unsigned char default_alpha) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long
src/util/string.h
Outdated
char *mystrtok_r(char *s, const char *sep, char **lasts); | ||
u64 read_seed(const char *str); | ||
bool parseColorString(const std::string &value, video::SColor &color, bool quiet); | ||
bool parseColorString(const std::string &value, video::SColor &color, bool quiet, unsigned char default_alpha = 0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Done by adding a `default_alpha` parameter to the `parseColorString()` function
@rubenwardy, @SmallJoker could you please review this again? The changes you requested are all done, as far as I can see. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for merging! |
This allows using the alpha component of the ColorString.
The default behaviour is unchanged.
Backwards compatible (only boxes with the new, fourth parameter are not drawn in old clients).
I'm looking forward to your comments! Thanks in advance for your efforts!