mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add wear bar color API (#13328)
--------- Co-authored-by: Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> Co-authored-by: grorp <gregor.parzefall@posteo.de>
This commit is contained in:
parent
e10d8080ba
commit
176e674a51
19 changed files with 598 additions and 26 deletions
|
@ -1179,17 +1179,26 @@ void drawItemStack(
|
|||
(1 - wear) * progressrect.LowerRightCorner.X;
|
||||
|
||||
// Compute progressbar color
|
||||
// default scheme:
|
||||
// wear = 0.0: green
|
||||
// wear = 0.5: yellow
|
||||
// wear = 1.0: red
|
||||
video::SColor color(255, 255, 255, 255);
|
||||
int wear_i = MYMIN(std::floor(wear * 600), 511);
|
||||
wear_i = MYMIN(wear_i + 10, 511);
|
||||
|
||||
if (wear_i <= 255)
|
||||
color.set(255, wear_i, 255, 0);
|
||||
else
|
||||
color.set(255, 255, 511 - wear_i, 0);
|
||||
video::SColor color;
|
||||
auto barParams = item.getWearBarParams(client->idef());
|
||||
if (barParams.has_value()) {
|
||||
f32 durabilityPercent = 1.0 - wear;
|
||||
color = barParams->getWearBarColor(durabilityPercent);
|
||||
} else {
|
||||
color = video::SColor(255, 255, 255, 255);
|
||||
int wear_i = MYMIN(std::floor(wear * 600), 511);
|
||||
wear_i = MYMIN(wear_i + 10, 511);
|
||||
|
||||
if (wear_i <= 255)
|
||||
color.set(255, wear_i, 255, 0);
|
||||
else
|
||||
color.set(255, 255, 511 - wear_i, 0);
|
||||
}
|
||||
|
||||
core::rect<s32> progressrect2 = progressrect;
|
||||
progressrect2.LowerRightCorner.X = progressmid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue