diff --git a/src/include/unittype.h b/src/include/unittype.h index 4b197b520..8330f66fa 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -280,6 +280,16 @@ public: IntColor BColor; /// Color of background. }; +class CDecoVarFrame : public CDecoVar +{ +public: + CDecoVarFrame() : Thickness(0), ColorIndex(-1) {}; + virtual void Draw(int x, int y, const CUnitType &type, const CVariable &var) const; + + int Thickness; + int ColorIndex; +}; + class CDecoVarText : public CDecoVar { public: diff --git a/src/spell/spell_summon.cpp b/src/spell/spell_summon.cpp index faa112995..a85e73646 100644 --- a/src/spell/spell_summon.cpp +++ b/src/spell/spell_summon.cpp @@ -133,7 +133,7 @@ public: // To avoid defending summoned unit for AI // we also use this value to store when this // unit was summoned - target->Summoned = GameCycle; + target->Summoned = GameCycle + 1; // // set life span. ttl=0 results in a permanent unit. // diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index a788a46e5..e282f40ed 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -1750,6 +1750,23 @@ static int CclDefineDecorations(lua_State *l) lua_pop(l, 1); // Pop value } decovar = decovarbar; + } else if (!strcmp(key, "frame")) { + CDecoVarFrame *frame = new CDecoVarFrame; + if (!lua_istable(l, -1)) { + LuaError(l, "incorrect argument, need table with Thickness= and Color="); + } + for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) { + const char* innerkey = LuaToString(l, -2); + if (!strcmp(innerkey, "Thickness")) { + frame->Thickness = LuaToNumber(l, -1); + } else if (!strcmp(innerkey, "ColorName")) { + const char *const colorName = LuaToString(l, -1); + frame->ColorIndex = GetColorIndexByName(colorName); + } else { + LuaError(l, "'%s' invalid for Method frame" _C_ innerkey); + } + } + decovar = frame; } else if (!strcmp(key, "text")) { CDecoVarText *decovartext = new CDecoVarText; diff --git a/src/unit/unit_draw.cpp b/src/unit/unit_draw.cpp index 5f8e9ea0c..fbcc55886 100644 --- a/src/unit/unit_draw.cpp +++ b/src/unit/unit_draw.cpp @@ -426,6 +426,33 @@ void CDecoVarBar::Draw(int x, int y, } } +/** +** Draw bar for variables. +** +** @param x X screen pixel position +** @param y Y screen pixel position +** @param unit Unit pointer +** @todo fix color configuration. +*/ +void CDecoVarFrame::Draw(int x, int y, + const CUnitType &type, const CVariable &var) const +{ + Assert(var.Max); + + int height = type.BoxHeight - 2; + int width = type.BoxWidth - 2; + int thickness = this->Thickness; + + Uint32 color = IndexToColor(this->ColorIndex); + // always keep it between a 2/5 and 4/5 visible + unsigned char alpha = (var.Value * 51 / var.Max + 51) * 2; + + Video.FillTransRectangleClip(color, x + 1, y + 1, width, thickness, alpha); + Video.FillTransRectangleClip(color, x + 1, y + 1 + thickness, thickness, height - thickness, alpha); + Video.FillTransRectangleClip(color, x + 1 + width - thickness, y + 1 + thickness, thickness, height - thickness, alpha); + Video.FillTransRectangleClip(color, x + 1 + thickness, y + 1 + height - thickness, width - 2 * thickness, thickness, alpha); +} + /** ** Print variable values (and max....). **