Skip to content

Conversation

Thomas--S
Copy link
Contributor

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!

video::SColor tmp_color;

bool use_color_alpha = false;
if (parts.size() == 4 && parts[3] == "true") {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

rubenwardy
rubenwardy previously approved these changes Mar 9, 2018
@SmallJoker
Copy link
Member

Are you sure this is backwards compatible? FORMSPEC_API_VERSION was not increased, so older clients will not draw the box and throw an error instead:
https://github.com/Thomas--S/minetest/blob/49ca8474389b315ff707270e4370406cccfcba82/src/gui/guiFormSpecMenu.cpp#L1602

Also the "close on enter" feature (#4417) had to be changed to a new formspec element (#4566) due this strange version management system.

@Thomas--S
Copy link
Contributor Author

Thomas--S commented Mar 10, 2018

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:

old client – new server new client – old server new client – new server old client – old server
boxes with three params ✔️ ✔️ ✔️ ✔️
boxes with four params 🚫 not drawn ✔️ ✔️ 🚫 not drawn

Backwards compatible (only boxes with the new, fourth parameter are not drawn in old clients).

So, the statement from my first post is correct. (I tested it.)
Backwards compatiblity is ensured for three-param boxes, four-param boxes are not drawn in old clients. (A new introduced element wouldn't be drawn in old clients either, I think.)

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.


video::SColor tmp_color;

bool use_color_alpha = false;
Copy link
Member

@SmallJoker SmallJoker Mar 24, 2018

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

Copy link
Contributor

@rubenwardy rubenwardy left a 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

@Thomas--S
Copy link
Contributor Author

PR updated according to @rubenwardy's comment. Tested and seems to work.

#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);
Copy link
Member

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,

}

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too long

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);
Copy link
Member

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
@Thomas--S Thomas--S changed the title Formspecs: Add a <use_color_alpha> parameter to the box[] element Formspecs: Allow specifying a certain alpha value for the box[] element Apr 8, 2018
@Thomas--S
Copy link
Contributor Author

@rubenwardy, @SmallJoker could you please review this again? The changes you requested are all done, as far as I can see.

Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rubenwardy rubenwardy merged commit 9577a43 into luanti-org:master Apr 23, 2018
@Thomas--S Thomas--S deleted the box_alpha branch April 23, 2018 20:26
@Thomas--S
Copy link
Contributor Author

Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants