Use PixelPos in ContentType.

Fix some error message.
Commit missing CMakeLists.txt modifications for the new files from last commit
This commit is contained in:
joris 2012-12-31 12:02:34 +01:00
parent 28baa19704
commit c01bef9426
7 changed files with 51 additions and 81 deletions

View file

@ -277,6 +277,7 @@ source_group(stratagusmain FILES ${stratagus_SRCS})
set(ui_SRCS
src/ui/botpanel.cpp
src/ui/button_checks.cpp
src/ui/contenttype.cpp
src/ui/icons.cpp
src/ui/interface.cpp
src/ui/mainscr.cpp
@ -523,6 +524,7 @@ set(stratagus_generic_HDRS
src/include/title.h
src/include/translate.h
src/include/trigger.h
src/include/ui/contenttype.h
src/include/ui.h
src/include/unit.h
src/include/unit_cache.h

View file

@ -53,7 +53,6 @@
#endif
#include "color.h"
#include "ui/contenttype.h"
#include "viewport.h"
#include <vector>
@ -64,6 +63,7 @@
-- Declarations
----------------------------------------------------------------------------*/
class CContentType;
class CUnit;
class CFile;
class CFont;
@ -204,15 +204,9 @@ class CUnitInfoPanel
public:
CUnitInfoPanel() : PosX(0), PosY(0), DefaultFont(0),
Contents(), Condition(NULL) {}
~CUnitInfoPanel() {
for (std::vector<CContentType *>::iterator content = Contents.begin();
content != Contents.end(); ++content) {
delete *content;
}
delete Condition;
}
~CUnitInfoPanel();
public:
std::string Name; /// Ident of the panel.
int PosX; /// X coordinate of the panel.
int PosY; /// Y coordinate of the panel.

View file

@ -33,13 +33,12 @@
//@{
#include "script.h"
#include "vec2i.h"
#include <vector>
class CUnit;
class CFont;
class ConditionPanel;
//class StringDesc;
//struct lua_State;
/**
** Infos to display the contents of panel.
@ -47,7 +46,7 @@ class ConditionPanel;
class CContentType
{
public:
CContentType() : PosX(0), PosY(0), Condition(NULL) {}
CContentType() : Pos(0, 0), Condition(NULL) {}
virtual ~CContentType();
/// Tell how show the variable Index.
@ -55,9 +54,8 @@ public:
virtual void Parse(lua_State *l) = 0;
int PosX; /// X coordinate where to display.
int PosY; /// Y coordinate where to display.
public:
PixelPos Pos; /// Coordinate where to display.
ConditionPanel *Condition; /// Condition to show the content; if NULL, no condition.
};

View file

@ -70,8 +70,8 @@ CContentType::~CContentType()
void CContentTypeText::Draw(const CUnit &unit, CFont *defaultfont) const
{
std::string text; // Optional text to display.
int x = this->PosX;
int y = this->PosY;
int x = this->Pos.x;
int y = this->Pos.y;
CFont &font = this->Font ? *this->Font : *defaultfont;
Assert(&font);
@ -154,9 +154,9 @@ void CContentTypeFormattedText::Draw(const CUnit &unit, CFont *defaultfont) cons
}
if (this->Centered) {
label.DrawCentered(this->PosX, this->PosY, buf);
label.DrawCentered(this->Pos.x, this->Pos.y, buf);
} else {
label.Draw(this->PosX, this->PosY, buf);
label.Draw(this->Pos.x, this->Pos.y, buf);
}
}
@ -195,9 +195,9 @@ void CContentTypeFormattedText2::Draw(const CUnit &unit, CFont *defaultfont) con
}
}
if (this->Centered) {
label.DrawCentered(this->PosX, this->PosY, buf);
label.DrawCentered(this->Pos.x, this->Pos.y, buf);
} else {
label.Draw(this->PosX, this->PosY, buf);
label.Draw(this->Pos.x, this->Pos.y, buf);
}
}
@ -246,8 +246,7 @@ void CContentTypeIcon::Draw(const CUnit &unit, CFont *) const
const CUnit *unitToDraw = GetUnitRef(unit, this->UnitRef);
if (unitToDraw && unitToDraw->Type->Icon.Icon) {
const PixelPos pos(this->PosX, this->PosY);
unitToDraw->Type->Icon.Icon->DrawIcon(*unitToDraw->Player, pos);
unitToDraw->Type->Icon.Icon->DrawIcon(*unitToDraw->Player, this->Pos);
}
}
@ -281,10 +280,10 @@ void CContentTypeLifeBar::Draw(const CUnit &unit, CFont *) const
}
// Border
Video.FillRectangleClip(ColorBlack, this->PosX - 1, this->PosY - 1,
Video.FillRectangleClip(ColorBlack, this->Pos.x - 1, this->Pos.y - 1,
this->Width + 2, this->Height + 2);
Video.FillRectangleClip(color, this->PosX, this->PosY,
Video.FillRectangleClip(color, this->Pos.x, this->Pos.y,
(f * this->Width) / 100, this->Height);
}
@ -299,53 +298,24 @@ void CContentTypeLifeBar::Draw(const CUnit &unit, CFont *) const
*/
void CContentTypeCompleteBar::Draw(const CUnit &unit, CFont *) const
{
Uint32 color;
Assert((unsigned int) this->Index < UnitTypeVar.GetNumberVariable());
if (!unit.Variable[this->Index].Max) {
return;
}
int x = this->PosX;
int y = this->PosY;
int x = this->Pos.x;
int y = this->Pos.y;
int w = this->Width;
int h = this->Height;
Assert(w > 0);
Assert(h > 4);
//FIXME: ugly
switch (this->Color) {
case 1:
color = ColorRed;
break;
case 2:
color = ColorYellow;
break;
case 3:
color = ColorGreen;
break;
case 4:
color = ColorGray;
break;
case 5:
color = ColorWhite;
break;
case 6:
color = ColorOrange;
break;
case 7:
color = ColorBlue;
break;
case 8:
color = ColorDarkGreen;
break;
case 9:
color = ColorBlack;
break;
default:
color = UI.CompletedBarColor;
break;
}
const Uint32 colors[] = {ColorRed, ColorYellow, ColorGreen,
ColorGray, ColorWhite, ColorOrange,
ColorBlue, ColorDarkGreen, ColorBlack};
const Uint32 color = (1 <= Color && Color <= 9) ?
colors[this->Color - 1] : UI.CompletedBarColor;
int f = (100 * unit.Variable[this->Index].Value) / unit.Variable[this->Index].Max;
if (!this->Border) {
@ -398,7 +368,7 @@ void CContentTypeCompleteBar::Draw(const CUnit &unit, CFont *) const
} else if (!strcmp(key, "ShowName")) {
this->ShowName = LuaToBoolean(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'Text' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'Text' in DefinePanelContents" _C_ key);
}
}
}
@ -425,7 +395,7 @@ void CContentTypeCompleteBar::Draw(const CUnit &unit, CFont *) const
} else if (!strcmp(key, "Centered")) {
this->Centered = LuaToBoolean(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'FormattedText' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'FormattedText' in DefinePanelContents" _C_ key);
}
}
}
@ -468,7 +438,7 @@ void CContentTypeCompleteBar::Draw(const CUnit &unit, CFont *) const
} else if (!strcmp(key, "Centered")) {
this->Centered = LuaToBoolean(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'FormattedText2' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'FormattedText2' in DefinePanelContents" _C_ key);
}
}
}
@ -512,7 +482,7 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s)
if (!strcmp(key, "Unit")) {
this->UnitRef = Str2EnumUnit(l, LuaToString(l, -1));
} else {
LuaError(l, "'%s' invalid for method 'Icon' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'Icon' in DefinePanelContents" _C_ key);
}
}
}
@ -532,7 +502,7 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s)
} else if (!strcmp(key, "Width")) {
this->Width = LuaToNumber(l, -1);
} else {
LuaError(l, "'%s' invalid for method 'LifeBar' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'LifeBar' in DefinePanelContents" _C_ key);
}
}
// Default value and checking errors.
@ -589,7 +559,7 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s)
LuaError(l, "incorrect color: '%s' " _C_ color);
}
} else {
LuaError(l, "'%s' invalid for method 'CompleteBar' in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for method 'CompleteBar' in DefinePanelContents" _C_ key);
}
}
// Default value and checking errors.
@ -604,7 +574,4 @@ static EnumUnit Str2EnumUnit(lua_State *l, const char *s)
}
}
//@}

View file

@ -52,6 +52,7 @@
#include "tileset.h"
#include "translate.h"
#include "trigger.h"
#include "ui/contenttype.h"
#include "ui.h"
#include "unit.h"
#include "unitsound.h"

View file

@ -45,6 +45,7 @@
#include "spells.h"
#include "title.h"
#include "util.h"
#include "ui/contenttype.h"
#include "unit.h"
#include "unit_manager.h"
#include "unittype.h"
@ -423,7 +424,7 @@ static ConditionPanel *ParseConditionPanel(lua_State *l)
condition->Variables[index] = Ccl2Condition(l, LuaToString(l, -1));
continue;
}
LuaError(l, "'%s' invalid for Condition in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for Condition in DefinePanelContents" _C_ key);
}
}
return condition;
@ -435,13 +436,12 @@ static CContentType *CclParseContent(lua_State *l)
CContentType *content = NULL;
ConditionPanel *condition = NULL;
int posX = 0;
int posY = 0;
PixelPos pos(0, 0);
for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
const char *key = LuaToString(l, -2);
if (!strcmp(key, "Pos")) {
CclGetPos(l, &posX, &posY);
CclGetPos(l, &pos.x, &pos.y);
} else if (!strcmp(key, "More")) {
Assert(lua_istable(l, -1));
lua_rawgeti(l, -1, 1); // Method name
@ -460,18 +460,17 @@ static CContentType *CclParseContent(lua_State *l)
} else if (!strcmp(key, "CompleteBar")) {
content = new CContentTypeCompleteBar;
} else {
LuaError(l, "Invalid drawing method '%s' in DefinePanels" _C_ key);
LuaError(l, "Invalid drawing method '%s' in DefinePanelContents" _C_ key);
}
content->Parse(l);
lua_pop(l, 2); // Pop Variable Name and Method
} else if (!strcmp(key, "Condition")) {
condition = ParseConditionPanel(l);
} else {
LuaError(l, "'%s' invalid for Contents in DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for Contents in DefinePanelContents" _C_ key);
}
}
content->PosX = posX;
content->PosY = posY;
content->Pos = pos;
content->Condition = condition;
return content;
}
@ -510,13 +509,13 @@ static int CclDefinePanelContents(lua_State *l)
infopanel->Contents.push_back(CclParseContent(l));
}
} else {
LuaError(l, "'%s' invalid for DefinePanels" _C_ key);
LuaError(l, "'%s' invalid for DefinePanelContents" _C_ key);
}
}
for (std::vector<CContentType *>::iterator content = infopanel->Contents.begin();
content != infopanel->Contents.end(); ++content) { // Default value for invalid value.
(*content)->PosX += infopanel->PosX;
(*content)->PosY += infopanel->PosY;
(*content)->Pos.x += infopanel->PosX;
(*content)->Pos.y += infopanel->PosY;
}
size_t j;
for (j = 0; j < UI.InfoPanelContents.size(); ++j) {

View file

@ -45,6 +45,7 @@
#include "menus.h"
#include "tileset.h"
#include "title.h"
#include "ui/contenttype.h"
#include "unit.h"
#include "video.h"
@ -100,6 +101,14 @@ void ShowLoadProgress(const char *fmt, ...)
}
}
CUnitInfoPanel::~CUnitInfoPanel() {
for (std::vector<CContentType *>::iterator content = Contents.begin();
content != Contents.end(); ++content) {
delete *content;
}
delete Condition;
}
CUserInterface::CUserInterface() :
MouseScroll(false), KeyScroll(false), MouseScrollSpeed(1),