1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

- partial implementation of kingdom overview:

-- moved some kingdom overview values to config
-- small fix to garrison window
-- small fix to button class
This commit is contained in:
Ivan Savenko 2010-01-30 19:08:26 +00:00
parent 83e91430a7
commit 6f0f6564d7
7 changed files with 483 additions and 133 deletions

View File

@ -55,8 +55,8 @@ void CButtonBase::show(SDL_Surface * to)
{ {
blitAt(imgs[curimg][img],pos.x,pos.y,to); blitAt(imgs[curimg][img],pos.x,pos.y,to);
if(text) if(text)
{ {//using "state" instead of "state == 1" screwed up hoverable buttons with text
CSDL_Ext::printAt(text->text, text->x + pos.x + state, text->y + pos.y + state, text->font, zwykly, to); CSDL_Ext::printAt(text->text, text->x + pos.x + (state == 1), text->y + pos.y + (state == 1), text->font, text->color, to);
} }
} }
else else
@ -70,7 +70,7 @@ void CButtonBase::showAll( SDL_Surface * to )
show(to); show(to);
} }
void CButtonBase::addTextOverlay( const std::string Text, EFonts font ) void CButtonBase::addTextOverlay( const std::string Text, EFonts font, SDL_Color color)
{ {
text = new TextOverlay; text = new TextOverlay;
text->text = Text; text->text = Text;
@ -79,6 +79,7 @@ void CButtonBase::addTextOverlay( const std::string Text, EFonts font )
text->x = pos.w/2 - f->getWidth(Text.c_str())/2; text->x = pos.w/2 - f->getWidth(Text.c_str())/2;
text->y = pos.h/2 - f->height/2; text->y = pos.h/2 - f->height/2;
text->font = font; text->font = font;
text->color = color;
} }

View File

@ -15,6 +15,8 @@
* *
*/ */
extern SDL_Color tytulowy, tlo, zwykly ;
class CDefEssential; class CDefEssential;
namespace config{struct ButtonInfo;} namespace config{struct ButtonInfo;}
@ -27,9 +29,10 @@ public:
{ {
EFonts font; EFonts font;
std::string text; std::string text;
SDL_Color color;
int x, y; int x, y;
} *text; } *text;
void addTextOverlay(const std::string Text, EFonts font); void addTextOverlay(const std::string Text, EFonts font, SDL_Color color = zwykly);
int bitmapOffset; //TODO: comment me int bitmapOffset; //TODO: comment me
int type; //advmapbutton=2 //TODO: comment me int type; //advmapbutton=2 //TODO: comment me

View File

@ -294,6 +294,13 @@ struct SettingsGrammar : public grammar<SettingsGrammar>
| "maxOutputPerLine=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::outputLineLength)] | "maxOutputPerLine=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::outputLineLength)]
) )
) )
| str_p("Overview:") >>
*(
( "pics=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::overviewPics)]
| "size=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::overviewSize)]
| "graphic=" >> fname[SetAdventureStr(&AdventureMapConfig::overviewBg)]
)
)
; ;
AdvMapOptionsSequence = *(AdvMapOption >> (';' | eps_p[lerror("Semicolon lacking in advmapopt!")])); AdvMapOptionsSequence = *(AdvMapOption >> (';' | eps_p[lerror("Semicolon lacking in advmapopt!")]));
GUIResolution = (uint_p[assign_a(curRes.first)] >> 'x' >> uint_p[assign_a(curRes.second)]) GUIResolution = (uint_p[assign_a(curRes.first)] >> 'x' >> uint_p[assign_a(curRes.second)])

View File

@ -61,6 +61,9 @@ namespace config
std::vector<std::string> gemG; std::vector<std::string> gemG;
//in-game console //in-game console
int inputLineLength, outputLineLength; int inputLineLength, outputLineLength;
//kingdom overview
int overviewPics, overviewSize; //pic count in def and count of visible slots
std::string overviewBg; //background name
}; };
struct GUIOptions struct GUIOptions
{ {

View File

@ -2,8 +2,10 @@
#include "AdventureMapButton.h" #include "AdventureMapButton.h"
#include "CAdvmapInterface.h" #include "CAdvmapInterface.h"
#include "../CCallback.h" #include "../CCallback.h"
#include "CConfigHandler.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "CHeroWindow.h" #include "CHeroWindow.h"
#include "CSpellWindow.h"
#include "CMessage.h" #include "CMessage.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "Graphics.h" #include "Graphics.h"
@ -15,6 +17,8 @@
#include "../lib/map.h" #include "../lib/map.h"
#include "../lib/NetPacks.h" #include "../lib/NetPacks.h"
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <sstream> #include <sstream>
using namespace boost::assign; using namespace boost::assign;
using namespace CSDL_Ext; using namespace CSDL_Ext;
@ -29,9 +33,7 @@ using namespace CSDL_Ext;
* *
*/ */
int PicCount = 4;//how many pictures for background present in .def TODO - move to config #define ADVOPT (conf.go()->ac)
int size = 4;//we have 4 visible items in the list, would be nice to move this value to configs later
CDefEssential* CKingdomInterface::slots; CDefEssential* CKingdomInterface::slots;
CDefEssential* CKingdomInterface::fort; CDefEssential* CKingdomInterface::fort;
CDefEssential* CKingdomInterface::hall; CDefEssential* CKingdomInterface::hall;
@ -39,21 +41,23 @@ CDefEssential* CKingdomInterface::hall;
CKingdomInterface::CKingdomInterface() CKingdomInterface::CKingdomInterface()
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
defActions = /*ACTIVATE | DEACTIVATE |*/ SHARE_POS | DISPOSE;//??? why buttons dont receive activate/deactivate??? defActions =/* ACTIVATE | DEACTIVATE | */SHARE_POS | DISPOSE;
PicCount = ADVOPT.overviewPics;
size = ADVOPT.overviewSize;
pos.x = screen->w/2 - 400; pos.x = screen->w/2 - 400;
pos.y = screen->h/2 - (68+58*size); pos.y = screen->h/2 - (68+58*size);
heroPos = townPos = objPos = 0; heroPos = townPos = objPos = 0;
state = 2; state = 0;
showHarrisoned = false; showHarrisoned = false;//set to true if you want to see garrisoned heroes
bg = BitmapHandler::loadBitmap("OVCAST.bmp"); bg = BitmapHandler::loadBitmap(ADVOPT.overviewBg);
graphics->blueToPlayersAdv(bg, LOCPLINT->playerID); graphics->blueToPlayersAdv(bg, LOCPLINT->playerID);
mines = CDefHandler::giveDefEss("OVMINES.DEF"); mines = CDefHandler::giveDefEss("OVMINES.DEF");
slots = CDefHandler::giveDefEss("OVSLOT.DEF");
title = CDefHandler::giveDefEss("OVTITLE.DEF"); title = CDefHandler::giveDefEss("OVTITLE.DEF");
hall = CDefHandler::giveDefEss("ITMTL.DEF"); hall = CDefHandler::giveDefEss("ITMTL.DEF");
fort = CDefHandler::giveDefEss("ITMCL.DEF"); fort = CDefHandler::giveDefEss("ITMCL.DEF");
objPics = CDefHandler::giveDefEss("FLAGPORT.DEF"); objPics = CDefHandler::giveDefEss("FLAGPORT.DEF");
slots = CDefHandler::giveDefEss("OVSLOT.DEF");
toHeroes = new AdventureMapButton (CGI->generaltexth->overview[11],"", toHeroes = new AdventureMapButton (CGI->generaltexth->overview[11],"",
boost::bind(&CKingdomInterface::listToHeroes,this),748,28+size*116,"OVBUTN1.DEF"); boost::bind(&CKingdomInterface::listToHeroes,this),748,28+size*116,"OVBUTN1.DEF");
@ -70,15 +74,18 @@ CKingdomInterface::CKingdomInterface()
statusbar = new CStatusBar(pos.x+7,pos.y+91+size*116,"TSTATBAR.bmp",732); statusbar = new CStatusBar(pos.x+7,pos.y+91+size*116,"TSTATBAR.bmp",732);
resdatabar = new CResDataBar("KRESBAR.bmp",pos.x+3,pos.y+111+size*116,32,2,76,76); resdatabar = new CResDataBar("KRESBAR.bmp",pos.x+3,pos.y+111+size*116,32,2,76,76);
for (int i=0; i<RESOURCE_QUANTITY; i++) for (int i = 0; i<size; i++)
incomes.push_back(new CResIncomePic(i,mines)); blitAt(slots->ourImages[PicCount].bitmap,23,26+i*116,bg);
for (size_t i=0; i<RESOURCE_QUANTITY; i++)
incomes.push_back(new CResIncomePic(i,mines,this));//bottom panel with mines
heroes.resize(size); heroes.resize(size);
for(size_t i=0;i<size;i++)//preparing lists for input for(size_t i=0;i<size;i++)//creating empty hero/town lists for input
heroes[i] = new CHeroItem(i); heroes[i] = new CHeroItem(i,this);
towns.resize(size); towns.resize(size);
for(size_t i=0;i<size;i++) for(size_t i=0;i<size;i++)
towns[i] = new CTownItem(i); towns[i] = new CTownItem(i,this);
slider = new CSlider(4, 4, size*116+19, boost::bind (&CKingdomInterface::sliderMoved, this, _1), slider = new CSlider(4, 4, size*116+19, boost::bind (&CKingdomInterface::sliderMoved, this, _1),
size, LOCPLINT->cb->howManyHeroes(showHarrisoned), 0, false, 0); size, LOCPLINT->cb->howManyHeroes(showHarrisoned), 0, false, 0);
@ -115,20 +122,20 @@ CKingdomInterface::CKingdomInterface()
#undef INSERT_MAP #undef INSERT_MAP
for(size_t i = 0; i<CGI->state->map->objects.size(); i++) for(size_t i = 0; i<CGI->state->map->objects.size(); i++)
{ {
CGObjectInstance* obj = CGI->state->map->objects[i]; CGObjectInstance* obj = CGI->state->map->objects[i];//current object
if (obj) if (obj)
{ {
std::pair<int,int > curElm = std::pair<int,int >(obj->ID, obj->subID); std::pair<int,int > curElm = std::pair<int,int >(obj->ID, obj->subID);
if (obj->tempOwner == CGI->state->currentPlayer) if (obj->tempOwner == CGI->state->currentPlayer)//if object is our
{ {
if ( obj->ID == 17 ) if ( obj->ID == 17 )//dwelling, text is a plural name of a creature
{ {
objList[obj->subID].first += 1; objList[obj->subID].first += 1;
objList[obj->subID].second = & CGI->creh->creatures[CGI->objh->cregens[obj->subID]].namePl; objList[obj->subID].second = & CGI->creh->creatures[CGI->objh->cregens[obj->subID]].namePl;
} }
else if (addObjects.find(curElm) != addObjects.end()) else if (addObjects.find(curElm) != addObjects.end())
{ {//object from addObjects map, text is name of the object
objList[addObjects[curElm]].first += 1; objList[addObjects[curElm]].first += 1;
objList[addObjects[curElm]].second = & obj->hoverName; objList[addObjects[curElm]].second = & obj->hoverName;
} }
@ -151,13 +158,13 @@ void CKingdomInterface::moveObjectList(int newPos)
int bottom = objList.size() > objSize ? objList.size() - objSize : 0 ; int bottom = objList.size() > objSize ? objList.size() - objSize : 0 ;
switch (newPos)//checking what button was pressed switch (newPos)//checking what button was pressed
{ {
case 0: objPos = top; /* Top */ case 0: objPos = top;
break; break;
case 1: objPos = objPos==top?top:(objPos-1); /* Up */ case 1: objPos = objPos==top?top:(objPos-1);
break; break;
case 2: objPos = objPos==bottom?bottom:(objPos+1); /* Down */ case 2: objPos = objPos==bottom?bottom:(objPos+1);
break; break;
case 3: objPos = bottom; /*Bottom*/ case 3: objPos = bottom;
break; break;
} }
GH.totalRedraw(); GH.totalRedraw();
@ -167,13 +174,14 @@ CKingdomInterface::~CKingdomInterface()
{ {
SDL_FreeSurface(bg); SDL_FreeSurface(bg);
delete title; delete title;//deleting .def
delete slots; delete slots;
delete fort; delete fort;
delete hall; delete hall;
delete mines; delete mines;
delete objPics;
towns.clear(); towns.clear();//deleting lists
heroes.clear(); heroes.clear();
incomes.clear(); incomes.clear();
ObjList.clear(); ObjList.clear();
@ -205,14 +213,14 @@ void CKingdomInterface::showAll( SDL_Surface * to/*=NULL*/)
int skipCount=0, curPos=objPos<0?(-objPos):0; int skipCount=0, curPos=objPos<0?(-objPos):0;
for (std::map<int,std::pair<int, std::string*> >::iterator it=objList.begin(); it!= objList.end(); it++) for (std::map<int,std::pair<int, std::string*> >::iterator it=objList.begin(); it!= objList.end(); it++)
{ {
if (skipCount<objPos) if (skipCount<objPos)//we will show only objects from objPos
{ {
skipCount++; skipCount++;
continue; continue;
} }
blitAt(objPics->ourImages[(*it).first].bitmap,pos.x+740,pos.y+44+curPos*57,to); blitAt(objPics->ourImages[(*it).first].bitmap,pos.x+740,pos.y+44+curPos*57,to);
std::ostringstream ostrs; std::ostringstream ostrs;//objects count
ostrs << (*it).second.first; ostrs << (*it).second.first;
CSDL_Ext::printTo(ostrs.str(),pos.x+790,pos.y+94+curPos*57,GEOR13,zwykly,to); CSDL_Ext::printTo(ostrs.str(),pos.x+790,pos.y+94+curPos*57,GEOR13,zwykly,to);
@ -228,14 +236,14 @@ void CKingdomInterface::showAll( SDL_Surface * to/*=NULL*/)
CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[4],pos.x+370,pos.y+12,TNRB16,zwykly,to); CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[4],pos.x+370,pos.y+12,TNRB16,zwykly,to);
CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[5],pos.x+600,pos.y+12,TNRB16,zwykly,to); CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[5],pos.x+600,pos.y+12,TNRB16,zwykly,to);
for (size_t i=0; i<size; i++) for (size_t i=0; i<size; i++)
towns[i]->show(to);//show town list towns[i]->showAll(to);//show town list
} }
else else
{//text "Hero/stats" and "Skills" {//text "Hero/stats" and "Skills"
CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[0],pos.x+150,pos.y+12,TNRB16,zwykly,to); CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[0],pos.x+150,pos.y+12,TNRB16,zwykly,to);
CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[1],pos.x+500,pos.y+12,TNRB16,zwykly,to); CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[1],pos.x+500,pos.y+12,TNRB16,zwykly,to);
for (size_t i=0; i<size; i++) for (size_t i=0; i<size; i++)
heroes[i]->show(to);//show hero list heroes[i]->showAll(to);//show hero list
} }
for(size_t i=0;i<incomes.size();i++) for(size_t i=0;i<incomes.size();i++)
@ -269,12 +277,11 @@ void CKingdomInterface::activate()
for (size_t i=0; i<incomes.size(); i++) for (size_t i=0; i<incomes.size(); i++)
incomes[i]->activate(); incomes[i]->activate();
if (state == 1) if (state == 1)
for (int i=0; i<size; i++) for (size_t i=0; i<size; i++)
towns[i]->activate(); towns[i]->activate();
else else
for (int i=0; i<size; i++) for (size_t i=0; i<size; i++)
heroes[i]->activate(); heroes[i]->activate();
slider->activate(); slider->activate();
@ -298,10 +305,10 @@ void CKingdomInterface::deactivate()
incomes[i]->deactivate(); incomes[i]->deactivate();
if (state == 1) if (state == 1)
for (int i=0; i<size; i++) for (size_t i=0; i<size; i++)
towns[i]->deactivate(); towns[i]->deactivate();
else else
for (int i=0; i<size; i++) for (size_t i=0; i<size; i++)
heroes[i]->deactivate(); heroes[i]->deactivate();
slider->deactivate(); slider->deactivate();
} }
@ -314,34 +321,32 @@ void CKingdomInterface::recreateHeroList(int pos)
{ {
std::vector<const CGHeroInstance*> Heroes = LOCPLINT->cb->getHeroesInfo(true); std::vector<const CGHeroInstance*> Heroes = LOCPLINT->cb->getHeroesInfo(true);
int i=0, cnt=0; int i=0, cnt=0;
for (int j = 0; ((j<Heroes.size()) && (i<size));j++) for (size_t j = 0; ((j<Heroes.size()) && (i<size));j++)
{ {
if (Heroes[j]->inTownGarrison && (!showHarrisoned))//if hero in garrison and we don't show them if (Heroes[j]->inTownGarrison && (!showHarrisoned))//if hero in garrison and we don't show them
{
continue; continue;
}
if (cnt<pos)//skipping heroes if (cnt<pos)//skipping heroes
{ {
cnt++; cnt++;
continue; continue;
}//this hero will be added }//this hero will be added
heroes[i]->hero = Heroes[j]; heroes[i]->setHero(Heroes[j]);
i++; i++;
} }
for (i;i<size;i++)//if we still have empty pieces for (i;i<size;i++)//if we still have empty pieces
heroes[i]->hero = NULL;//empty pic heroes[i]->setHero(NULL);//empty pic
GH.totalRedraw(); GH.totalRedraw();
} }
void CKingdomInterface::recreateTownList(int pos) void CKingdomInterface::recreateTownList(int pos)
{ {
std::vector<const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true); std::vector<const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true);
for(int i=0;i<size;i++) for(size_t i=0;i<size;i++)
{ {
if (i+pos<Towns.size()) if (i+pos<Towns.size())
towns[i]->town = Towns[i+pos];//replace town towns[i]->setTown(Towns[i+pos]);//replace town
else else
towns[i]->town = NULL;//only empty pic towns[i]->setTown(NULL);//only empty pic
} }
GH.totalRedraw(); GH.totalRedraw();
} }
@ -355,10 +360,10 @@ void CKingdomInterface::listToTowns()
slider->setAmount(LOCPLINT->cb->howManyTowns()); slider->setAmount(LOCPLINT->cb->howManyTowns());
slider->value=townPos;//moving slider slider->value=townPos;//moving slider
recreateTownList(townPos); recreateTownList(townPos);
for (size_t i=0;i<size;i++)//TODO:is this loop needed? for (size_t i=0;i<size;i++)
{ {
towns[i]->deactivate(); heroes[i]->deactivate();
heroes[i]->activate(); towns[i]->activate();
} }
} }
@ -371,7 +376,7 @@ void CKingdomInterface::listToHeroes()
slider->setAmount(LOCPLINT->cb->howManyHeroes(showHarrisoned)); slider->setAmount(LOCPLINT->cb->howManyHeroes(showHarrisoned));
slider->value=heroPos;//moving slider slider->value=heroPos;//moving slider
recreateHeroList(heroPos); recreateHeroList(heroPos);
for (size_t i=0;i<size;i++)//TODO:is this loop needed? for (size_t i=0;i<size;i++)
{ {
towns[i]->deactivate(); towns[i]->deactivate();
heroes[i]->activate(); heroes[i]->activate();
@ -380,25 +385,39 @@ void CKingdomInterface::listToHeroes()
void CKingdomInterface::sliderMoved(int newpos) void CKingdomInterface::sliderMoved(int newpos)
{ {
if ( state == 1 )//towns if (state == 0)
{ {
townPos = newpos; townPos = newpos;
recreateHeroList(newpos);
state = 2;
}
else if ( state == 1 )//towns
{
for (size_t i=0; i<size; i++)
towns[i]->deactivate();
townPos = newpos;
recreateTownList(newpos); recreateTownList(newpos);
for (size_t i=0; i<size; i++)
towns[i]->activate();
} }
else//heroes else//heroes
{ {
for (size_t i=0; i<size; i++)
heroes[i]->deactivate();
heroPos = newpos; heroPos = newpos;
recreateHeroList(newpos); recreateHeroList(newpos);
for (size_t i=0; i<size; i++)
heroes[i]->activate();
} }
} }
CKingdomInterface::CResIncomePic::CResIncomePic(int RID, CDefEssential * Mines) CKingdomInterface::CResIncomePic::CResIncomePic(int RID, CDefEssential * Mines, CKingdomInterface * Owner)
{ {
used = HOVER; used = HOVER;
recActions = DISPOSE | SHARE_POS; recActions =/* ACTIVATE | DEACTIVATE | SHOWALL |*/ DISPOSE | SHARE_POS;
resID = RID; resID = RID;
pos.x += 20 + RID*80; pos.x += 20 + RID*80;
pos.y += 31+size*116; pos.y += 31+Owner->size*116;
pos.h = 54; pos.h = 54;
pos.w = (resID!=7)?68:136;//gold pile is bigger pos.w = (resID!=7)?68:136;//gold pile is bigger
mines = Mines; mines = Mines;
@ -411,7 +430,6 @@ CKingdomInterface::CResIncomePic::CResIncomePic(int RID, CDefEssential * Mines)
} }
else else
hoverText = CGI->generaltexth->allTexts[255]; hoverText = CGI->generaltexth->allTexts[255];
tlog1<<hoverText<<"\n";
value = 0; value = 0;
int resource = resID==7?6:resID; int resource = resID==7?6:resID;
@ -472,9 +490,10 @@ void CKingdomInterface::CResIncomePic::show(SDL_Surface * to)
} }
CKingdomInterface::CTownItem::CTownItem(int num) CKingdomInterface::CTownItem::CTownItem(int num, CKingdomInterface * Owner)
{ {
recActions = DISPOSE | SHARE_POS; recActions = DISPOSE | SHARE_POS;
owner = Owner;
numb = num; numb = num;
pos.x += 23; pos.x += 23;
pos.y += 26+num*116; pos.y += 26+num*116;
@ -487,6 +506,11 @@ CKingdomInterface::CTownItem::~CTownItem()
{ {
} }
void CKingdomInterface::CTownItem::setTown(const CGTownInstance * newTown)
{
town = newTown;
}
void CKingdomInterface::CTownItem::activate() void CKingdomInterface::CTownItem::activate()
{ {
} }
@ -495,14 +519,14 @@ void CKingdomInterface::CTownItem::deactivate()
{ {
} }
void CKingdomInterface::CTownItem::show(SDL_Surface * to) void CKingdomInterface::CTownItem::showAll(SDL_Surface * to)
{ {
if (!town) if (!town)
{//if NULL - print background & exit {//if NULL - print background & exit
blitAt(slots->ourImages[numb % PicCount].bitmap,pos.x,pos.y,to); blitAt(slots->ourImages[numb % owner->PicCount].bitmap,pos.x,pos.y,to);
return; return;
}//background }//background
blitAt(slots->ourImages[PicCount+2].bitmap,pos.x,pos.y,to); blitAt(slots->ourImages[owner->PicCount+2].bitmap,pos.x,pos.y,to);
//town pic/name //town pic/name
int townPic = town->subID*2; int townPic = town->subID*2;
if (!town->hasFort()) if (!town->hasFort())
@ -522,7 +546,7 @@ void CKingdomInterface::CTownItem::show(SDL_Surface * to)
std::ostringstream oss; std::ostringstream oss;
oss << town->dailyIncome(); oss << town->dailyIncome();
CSDL_Ext::printAtMiddle(oss.str(),pos.x+188,pos.y+60,GEOR13,zwykly,to); CSDL_Ext::printAtMiddle(oss.str(),pos.x+188,pos.y+60,GEOR13,zwykly,to);
// Creature bonuses/ Creature available texts - need to find text wrapper thingy // Creature bonuses/ Creature available texts - need to find text wrapper thingy (have "\n" inside text)
// CSDL_Ext::printAtWR(CGI->generaltexth->allTexts[265],pos.x,pos.y+80,GEOR13,zwykly,to); // CSDL_Ext::printAtWR(CGI->generaltexth->allTexts[265],pos.x,pos.y+80,GEOR13,zwykly,to);
// CSDL_Ext::printTo(CGI->generaltexth->allTexts[266],pos.x+350,pos.y+80,GEOR13,zwykly,to); // CSDL_Ext::printTo(CGI->generaltexth->allTexts[266],pos.x+350,pos.y+80,GEOR13,zwykly,to);
for (int i=0; i<CREATURES_PER_TOWN;i++) for (int i=0; i<CREATURES_PER_TOWN;i++)
@ -575,43 +599,218 @@ void CKingdomInterface::CTownItem::show(SDL_Surface * to)
} }
} }
CKingdomInterface::CHeroItem::CHeroItem(int num) CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL;
recActions = DISPOSE | SHARE_POS; recActions = DISPOSE | SHARE_POS;
defActions = SHARE_POS;
owner = Owner;
numb = num; numb = num;
pos.x += 23; pos.x += 23;
pos.y += 26+num*116; pos.y += 26+num*116;
pos.w = 702; pos.w = 702;
pos.h = 114; pos.h = 114;
hero = NULL; hero = NULL;
garr = NULL;
artGroup = 0; artGroup = 0;
backpackPos = 0;
artButtons = new CHighlightableButtonsGroup(0);
for (size_t it = 0; it<3; it++)
{
artButtons->addButton(boost::assign::map_list_of(0,CGI->generaltexth->overview[13+it]),
CGI->generaltexth->overview[8+it], "OVBUTN3.DEF",364+it*112, 46, it);
std::string str = CGI->generaltexth->overview[8+it];//TODO:find function for this if any
str = str.substr(str.find_first_of("{"), str.find_first_of("}")-str.find_first_of("{"));
artButtons->buttons[it]->addTextOverlay(str, FONT_SMALL, tytulowy);
}
artButtons->onChange = boost::bind(&CKingdomInterface::CHeroItem::onArtChange, this, _1);
artButtons->select(0,0);
artLeft = new AdventureMapButton("", "", boost::bind
(&CKingdomInterface::CHeroItem::scrollArts,this,-1), 269, 66, "hsbtns3.def", SDLK_LEFT);
artRight = new AdventureMapButton("", "", boost::bind
(&CKingdomInterface::CHeroItem::scrollArts,this,+1), 675, 66, "hsbtns5.def", SDLK_RIGHT);
portrait = new LRClickableAreaWText();
portrait->pos = genRect(64, 58, pos.x+5, pos.y + 5);
char bufor[400];
for(int i=0; i<4; i++)
{
primarySkills.push_back(new LRClickableAreaWTextComp());
primarySkills[i]->pos = genRect(45, 32, pos.x+77 + 36*i, pos.y+26);
primarySkills[i]->text = CGI->generaltexth->arraytxt[2+i];
primarySkills[i]->type = i;
primarySkills[i]->baseType = 0;
sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), CGI->generaltexth->primarySkillNames[i].c_str());
primarySkills[i]->hoverText = std::string(bufor);
};
experience = new LRClickableAreaWText();
experience->pos = genRect(33, 49, pos.x+322, pos.y+4);
experience->hoverText = CGI->generaltexth->heroscrn[9];
morale = new LRClickableAreaWTextComp();
morale->pos = genRect(20,32,pos.x+221,pos.y+52);
luck = new LRClickableAreaWTextComp();
luck->pos = genRect(20,32,pos.x+221,pos.y+28);
spellPoints = new LRClickableAreaWText();
spellPoints->pos = genRect(32, 48, pos.x+271, pos.y+4); spellPoints->hoverText = CGI->generaltexth->heroscrn[22];
speciality = new LRClickableAreaWText();
speciality->pos = genRect(32, 48, pos.x+271, pos.y+4); speciality->hoverText = CGI->generaltexth->heroscrn[27];
for(int i=0; i<8; ++i)
{
secondarySkills.push_back(new LRClickableAreaWTextComp()); secondarySkills[i]->pos = genRect(32, 32, pos.x+410+i*37, pos.y+4);
secondarySkills[i]->baseType = 1;
};
for (int i=0; i<18;i++)
{
artifacts.push_back(new CArtPlace(this)); artifacts[i]->pos = genRect(44, 44, pos.x+268+(i%9)*48, pos.y+66);
artifacts[i]->baseType = SComponent::artifact;
};
for (int i=0; i<8;i++)
{
backpack.push_back(new CArtPlace(this)); backpack[i]->pos = genRect(44, 44, pos.x+293+(i%9)*48, pos.y+66);
backpack[i]->baseType = SComponent::artifact;
};
} }
CKingdomInterface::CHeroItem::~CHeroItem() CKingdomInterface::CHeroItem::~CHeroItem()
{ {
delete artButtons;
} }
void CKingdomInterface::CHeroItem::show(SDL_Surface * to) void CKingdomInterface::CHeroItem::setHero(const CGHeroInstance * newHero)
{
BLOCK_CAPTURING;
delete garr;
hero = newHero;
if (!hero)
{
return;
garr = NULL;
}
char bufor[400];
artLeft->block(hero->artifacts.size() <= 8);
artRight->block(hero->artifacts.size() <= 8);
garr = new CGarrisonInt(pos.x+6, pos.y+78, 4, Point(), owner->bg, Point(29,104), hero, NULL, false, true);
garr->update = false;
for (int i=0; i<artifacts.size(); i++)
{
artifacts[i]->type = hero->getArtAtPos(i);
if (artifacts[i]->type<0)
artifacts[i]->hoverText = CGI->generaltexth->heroscrn[11];
else
{
artifacts[i]->text = CGI->generaltexth->artifDescriptions[artifacts[i]->type];
artifacts[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[artifacts[i]->type].Name());
}
}
for (int i=0; i<backpack.size(); i++)
{
backpack[i]->type = hero->getArtAtPos(19+i);
if (backpack[i]->type<0)
backpack[i]->hoverText ="";
else
{
backpack[i]->text = CGI->generaltexth->artifDescriptions[backpack[i]->type];
backpack[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[backpack[i]->type].Name());
}
}
sprintf(bufor, CGI->generaltexth->allTexts[15].c_str(), hero->name.c_str(), hero->type->heroClass->name.c_str());
portrait->hoverText = std::string(bufor);
portrait->text = hero->getBiography();
//primary skills
for(size_t g=0; g<primarySkills.size(); ++g)
primarySkills[g]->bonus = hero->getPrimSkillLevel(g);
//secondary skills
for(size_t g=0; g<std::min(secondarySkills.size(),hero->secSkills.size()); ++g)
{
int skill = hero->secSkills[g].first,
level = hero->secSkills[g].second;
secondarySkills[g]->type = skill;
secondarySkills[g]->bonus = level;
secondarySkills[g]->text = CGI->generaltexth->skillInfoTexts[skill][level-1];
sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[level-1].c_str(), CGI->generaltexth->skillName[skill].c_str());
secondarySkills[g]->hoverText = std::string(bufor);
}
//experience
experience->text = CGI->generaltexth->allTexts[2].c_str();
boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(hero->level));
boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(CGI->heroh->reqExp(hero->level+1)));
boost::replace_first(experience->text, "%d", boost::lexical_cast<std::string>(hero->exp));
//spell points
sprintf(bufor, CGI->generaltexth->allTexts[205].c_str(), hero->name.c_str(), hero->mana, hero->manaLimit());
spellPoints->text = std::string(bufor);
//setting morale
std::vector<std::pair<int,std::string> > mrl = hero->getCurrentMoraleModifiers();
int mrlv = hero->getCurrentMorale();
int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale, 0 - neutral, 1 - good
morale->hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
morale->baseType = SComponent::morale;
morale->bonus = mrlv;
morale->text = CGI->generaltexth->arraytxt[88];
boost::algorithm::replace_first(morale->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
for(int it=0; it < mrl.size(); it++)
morale->text += mrl[it].second;
//setting luck
mrl = hero->getCurrentLuckModifiers();
mrlv = hero->getCurrentLuck();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck, 0 - neutral, 1 - good
luck->hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
luck->baseType = SComponent::luck;
luck->bonus = mrlv;
luck->text = CGI->generaltexth->arraytxt[62];
boost::algorithm::replace_first(luck->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
for(int it=0; it < mrl.size(); it++)
luck->text += mrl[it].second;
// redrawCurBack();
}
void CKingdomInterface::CHeroItem::scrollArts(int move)
{
backpackPos = ( backpackPos + move + hero->artifacts.size()) % hero->artifacts.size();
for (int i=0; i<backpack.size(); i++)
{
backpack[i]->type = hero->getArtAtPos(19+(backpackPos + i)%hero->artifacts.size());
if (backpack[i]->type<0)
backpack[i]->hoverText ="";
else
{
backpack[i]->text = CGI->generaltexth->artifDescriptions[backpack[i]->type];
backpack[i]->hoverText = boost::str(boost::format(CGI->generaltexth->heroscrn[1].c_str()) % CGI->arth->artifacts[backpack[i]->type].Name());
}
}
GH.totalRedraw();
}
void CKingdomInterface::CHeroItem::showAll(SDL_Surface * to)
{ {
if (!hero) if (!hero)
{//if we have no hero for this slot - print background & exit {//if we have no hero for this slot - print background & exit
blitAt(slots->ourImages[numb % PicCount].bitmap,pos.x,pos.y,to); blitAt(slots->ourImages[numb % owner->PicCount].bitmap,pos.x,pos.y,to);
return; return;
}//print background, different for arts view/backpack mode }//print background, different for arts view/backpack mode
blitAt(slots->ourImages[(artGroup=2)?PicCount:(PicCount+1)].bitmap,pos.x,pos.y,to); blitAt(slots->ourImages[(artGroup!=2)?owner->PicCount:(owner->PicCount+1)].bitmap,pos.x,pos.y,to);
//text "Artifacts" //text "Artifacts"
CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[2],pos.x+320,pos.y+55,GEOR13,zwykly,to); CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[2],pos.x+320,pos.y+55,GEOR13,zwykly,to);
int X = pos.x+6;//portrait
blitAt(graphics->portraitLarge[hero->portrait],pos.x+5,pos.y+6,to); blitAt(graphics->portraitLarge[hero->portrait],pos.x+5,pos.y+6,to);
for(std::map<si32,std::pair<ui32,si32> >::const_iterator
j=hero->army.slots.begin(); j!=hero->army.slots.end(); j++) garr->show(to);
{//army //hero name
blitAt(graphics->smallImgs[j->second.first],X,pos.y+78,to);
std::ostringstream creanum;
creanum << (j->second.second);
CSDL_Ext::printTo(creanum.str(),X+30,pos.y+110,GEOR13,zwykly,to);
X+=36;
}//hero name
CSDL_Ext::printAt(hero->name,pos.x+73,pos.y+7,GEOR13,zwykly,to); CSDL_Ext::printAt(hero->name,pos.x+73,pos.y+7,GEOR13,zwykly,to);
for (int i = 0; i<6; i++) for (int i = 0; i<6; i++)
{//primary skills, mana and exp. pics {//primary skills, mana and exp. pics
@ -642,6 +841,8 @@ void CKingdomInterface::CHeroItem::show(SDL_Surface * to)
blitAt(graphics->abils32->ourImages[skill*3+level+2].bitmap,pos.x+411+i*36,pos.y+6,to); blitAt(graphics->abils32->ourImages[skill*3+level+2].bitmap,pos.x+411+i*36,pos.y+6,to);
} }
artButtons->show(to);
int iter=0; int iter=0;
switch (artGroup) switch (artGroup)
{//arts {//arts
@ -654,21 +855,124 @@ void CKingdomInterface::CHeroItem::show(SDL_Surface * to)
blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to); blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to);
} }
break; break;
case 2://TODO:backpack case 2:
artLeft->show(to);
artRight->show(to);
int max = hero->artifacts.size();
iter = std::min(8, max);
for (size_t it = 0 ; it<iter;it++)
blitAt(graphics->artDefs->ourImages[hero->artifacts[(it+backpackPos)%max]].bitmap,pos.x+293+48*it,pos.y+66,to);
break; break;
default: tlog1<<"Unknown artifact group: "<<artGroup<<"\n";
} }
show(to);
} }
void CKingdomInterface::CHeroItem::onArtChange(int newstate) void CKingdomInterface::CHeroItem::onArtChange(int newstate)
{ {
if (!hero)
return;
deactivate();
artGroup = newstate; artGroup = newstate;
activate();
GH.totalRedraw();
} }
void CKingdomInterface::CHeroItem::activate() void CKingdomInterface::CHeroItem::activate()
{ {
if (!hero)
return;
artButtons->activate();
garr->activate();
if ( artGroup == 2 )
{
artLeft->activate();
artRight->activate();
for (size_t i=0; i<8;i++)
backpack[i]->activate();
}
else
{
for (size_t i=artGroup*9; i<9+artGroup*9;i++)
artifacts[i]->activate();
}
portrait->activate();
experience->activate();
morale->activate();
luck->activate();
spellPoints->activate();
speciality->activate();
for (size_t i=0; i<primarySkills.size();i++)
primarySkills[i]->activate();
for (size_t i=0; i<std::min(secondarySkills.size(),hero->secSkills.size());i++)
secondarySkills[i]->activate();
} }
void CKingdomInterface::CHeroItem::deactivate() void CKingdomInterface::CHeroItem::deactivate()
{ {
if (!hero)
return;
artButtons->deactivate();
garr->deactivate();
if ( artGroup == 2 )
{
artLeft->deactivate();
artRight->deactivate();
for (size_t i=0; i<8;i++)
backpack[i]->deactivate();
}
else
{
for (size_t i=artGroup*9; i<9+artGroup*9;i++)
artifacts[i]->deactivate();
}
portrait->deactivate();
experience->deactivate();
morale->deactivate();
luck->deactivate();
spellPoints->deactivate();
speciality->deactivate();
for (size_t i=0; i<primarySkills.size();i++)
primarySkills[i]->deactivate();
for (size_t i=0; i<std::min(secondarySkills.size(),hero->secSkills.size());i++)
secondarySkills[i]->deactivate();
}
CKingdomInterface::CHeroItem::CArtPlace::CArtPlace(CHeroItem * owner)
{
hero = owner;
used = LCLICK | RCLICK | HOVER;
}
void CKingdomInterface::CHeroItem::CArtPlace::activate()
{
LRClickableAreaWTextComp::activate();
}
void CKingdomInterface::CHeroItem::CArtPlace::clickLeft(tribool down, bool previousState)
{tlog1<<pos.x<<" "<<type<<"\n";
if (!down && previousState && type>=0)
{
if(type == 0)
{
CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (screen->w - 620)/2, (screen->h - 595)/2), hero->hero);
GH.pushInt(spellWindow);
}
else
LRClickableAreaWTextComp::clickLeft(down,previousState);
}
}
void CKingdomInterface::CHeroItem::CArtPlace::clickRight(tribool down, bool previousState)
{
if (type>=0)
LRClickableAreaWTextComp::clickRight(down, previousState);
}
void CKingdomInterface::CHeroItem::CArtPlace::deactivate()
{
LRClickableAreaWTextComp::deactivate();
} }

View File

@ -6,6 +6,7 @@
#include "../global.h" #include "../global.h"
#include <SDL.h> #include <SDL.h>
#include "GUIBase.h" #include "GUIBase.h"
#include "GUIClasses.h"
#include "../hch/CMusicBase.h" #include "../hch/CMusicBase.h"
class AdventureMapButton; class AdventureMapButton;
class CHighlightableButtonsGroup; class CHighlightableButtonsGroup;
@ -14,6 +15,8 @@ class CStatusBar;
class CSlider; class CSlider;
class CMinorResDataBar; class CMinorResDataBar;
class HoverableArea; class HoverableArea;
/*class LRClickableAreaWText
class LRClickableAreaWTextComp*/
/* /*
* CKingdomInterface.h, part of VCMI engine * CKingdomInterface.h, part of VCMI engine
@ -32,7 +35,7 @@ class CKingdomInterface : public CIntObject
public: public:
int resID,value;//resource ID int resID,value;//resource ID
std::string hoverText; std::string hoverText;
CResIncomePic(int RID, CDefEssential * Mines);//c-tor CResIncomePic(int RID, CDefEssential * Mines, CKingdomInterface * Owner);//c-tor
~CResIncomePic();//d-tor ~CResIncomePic();//d-tor
void hover(bool on); void hover(bool on);
void show(SDL_Surface * to); void show(SDL_Surface * to);
@ -40,25 +43,53 @@ class CKingdomInterface : public CIntObject
}; };
class CTownItem : public CIntObject class CTownItem : public CIntObject
{ {
public: private:
int numb;//position on screen (1..size)
const CGTownInstance * town; const CGTownInstance * town;
void show(SDL_Surface * to); public:
CKingdomInterface * owner;
int numb;//position on screen (1..size)
void setTown(const CGTownInstance * newTown);//change town and update info
void showAll(SDL_Surface * to);
void activate(); void activate();
void deactivate(); void deactivate();
CTownItem (int num);//c-tor CTownItem (int num, CKingdomInterface * Owner);//c-tor
~CTownItem();//d-tor ~CTownItem();//d-tor
}; };
class CHeroItem : public CIntObject class CHeroItem : public CWindowWithGarrison
{
class CArtPlace: public LRClickableAreaWTextComp
{ {
public: public:
const CGHeroInstance * hero; CHeroItem * hero;
int artGroup,numb;//current art group (0 = equiped, 1 = misc, 2 = backpack) CArtPlace(CHeroItem * owner); //c-tor
void onArtChange(int newstate);//changes artgroup void clickLeft(tribool down, bool previousState);
void show(SDL_Surface * to); void clickRight(tribool down, bool previousState);
void activate(); void activate();
void deactivate(); void deactivate();
CHeroItem (int num);//c-tor };
public:
const CGHeroInstance * hero;
CKingdomInterface * owner;
int artGroup,numb;//current art group (0 = equiped, 1 = misc, 2 = backpack)
int backpackPos;//first visible artifact in backpack
AdventureMapButton * artLeft, * artRight;//buttons for backpack
LRClickableAreaWText * portrait;
LRClickableAreaWText * experience;
LRClickableAreaWTextComp * morale, * luck;
LRClickableAreaWText * spellPoints;
LRClickableAreaWText * speciality;
std::vector<LRClickableAreaWTextComp *> primarySkills;
std::vector<LRClickableAreaWTextComp *> secondarySkills;
std::vector<LRClickableAreaWTextComp *> artifacts;
std::vector<LRClickableAreaWTextComp *> backpack;
CHighlightableButtonsGroup * artButtons;
void setHero(const CGHeroInstance * newHero);//change hero and update info
void scrollArts(int move);//moving backpack, receiving distance
void onArtChange(int newstate);//changes artgroup
void showAll(SDL_Surface * to);
void activate();
void deactivate();
CHeroItem (int num, CKingdomInterface * Owner);//c-tor
~CHeroItem();//d-tor ~CHeroItem();//d-tor
}; };
public: public:
@ -67,6 +98,7 @@ public:
SDL_Surface * bg;//background SDL_Surface * bg;//background
CStatusBar * statusbar;//statusbar CStatusBar * statusbar;//statusbar
CResDataBar *resdatabar;//resources CResDataBar *resdatabar;//resources
int size,PicCount;
//buttons //buttons
AdventureMapButton *exit;//exit button AdventureMapButton *exit;//exit button

View File

@ -365,8 +365,8 @@ void CGarrisonSlot::show(SDL_Surface * to)
else//empty slot else//empty slot
{ {
Rect pos1 = pos, pos2 = pos; //positions on the garr bg sur and scren Rect pos1 = pos, pos2 = pos; //positions on the garr bg sur and scren
pos1.x = owner->surOffset.x; pos1.x = owner->surOffset.x+ pos.x-owner->pos.x;
pos1.y = owner->surOffset.y; pos1.y = owner->surOffset.y+ pos.y-owner->pos.y;
SDL_BlitSurface(owner->sur,&pos1,to,&pos2); SDL_BlitSurface(owner->sur,&pos1,to,&pos2);
if(owner->splitting) if(owner->splitting)