allow full frames as decorations for units (like WC1 when spell is active)
This commit is contained in:
parent
a62faf21d3
commit
28cc778153
4 changed files with 55 additions and 1 deletions
src
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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....).
|
||||
**
|
||||
|
|
Loading…
Add table
Reference in a new issue