From 8fea2b87b83492ae3fcca7338c724c620c4b7dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sun, 20 Jan 2008 16:24:03 +0000 Subject: [PATCH] Nearly working borders of buildings. --- CCallback.cpp | 4 +++- CCastleInterface.cpp | 37 ++++++++++++++++++++++++++++++------- CCastleInterface.h | 4 ++-- CMT.cpp | 1 + CPlayerInterface.cpp | 4 ++++ config/buildings3.txt | 37 +++++++++++++++++++++++++++++++++++++ hch/CLodHandler.cpp | 3 +++ hch/CTownHandler.cpp | 31 ++++++++++++++++++++++++++++--- hch/CTownHandler.h | 2 +- 9 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 config/buildings3.txt diff --git a/CCallback.cpp b/CCallback.cpp index 69687c0e6..a3767bd30 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -242,7 +242,9 @@ const CGHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) // if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info return NULL; if (!mode) - return gs->players[player].heroes[val]; + if(valplayers[player].heroes.size()) + return gs->players[player].heroes[val]; + else return NULL; else { for (int i=0; iplayers[player].heroes.size();i++) diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index c49115ec2..cbca89370 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -13,7 +13,14 @@ CBuildingRect::CBuildingRect(Structure *Str) :str(Str) { def = CGI->spriteh->giveDef(Str->defName); - border = area = NULL; + if (border = CGI->bitmaph->loadBitmap(str->borderName)) + SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255)); + else + std::cout << "Warning: no border for "<ID<bitmaph->loadBitmap(str->areaName)) + ;//SDL_SetColorKey(area,SDL_SRCCOLORKEY,SDL_MapRGB(area->format,0,255,255)); + else + std::cout << "Warning: no area for "<ID<pos.x; pos.y = str->pos.y; pos.w = def->ourImages[0].bitmap->w; @@ -30,13 +37,13 @@ CBuildingRect::~CBuildingRect() } void CBuildingRect::activate() { - MotionInterested::activate(); + Hoverable::activate(); ClickableL::activate(); ClickableR::activate(); } void CBuildingRect::deactivate() { - MotionInterested::deactivate(); + Hoverable::deactivate(); ClickableL::deactivate(); ClickableR::deactivate(); } @@ -47,9 +54,19 @@ bool CBuildingRect::operator<(const CBuildingRect & p2) const else return (str->ID) < (p2.str->ID); } -void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent) +void CBuildingRect::hover(bool on) { - //todo - handle + if(area) + { + if(CSDL_Ext::SDL_GetPixel(area,LOCPLINT->current->motion.x-pos.x,LOCPLINT->current->motion.y-pos.y) == 0) + { + Hoverable::hover(false); + return; + } + } + Hoverable::hover(on); + if(border) + blitAt(border,pos.x,pos.y); } void CBuildingRect::clickLeft (tribool down) { @@ -264,6 +281,8 @@ void CCastleInterface::show(SDL_Surface * to) animval++; } + blitAt(cityBg,0,0,to); + //blit buildings for(int i=0;idef->ourImages[(animval)%(buildings[i]->def->ourImages.size())].bitmap,buildings[i]->pos.x,buildings[i]->pos.y,to); + if(buildings[i]->hovered && buildings[i]->border) + blitAt(buildings[i]->border,buildings[i]->pos.x,buildings[i]->pos.y); } //for(int i=0;icurint = this; - //for(int i=0;iactivate(); + for(int i=0;iactivate(); } void CCastleInterface::deactivate() { exit->deactivate(); + for(int i=0;ideactivate(); } \ No newline at end of file diff --git a/CCastleInterface.h b/CCastleInterface.h index 30b571d08..050619525 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -7,7 +7,7 @@ class CGTownInstance; class CTownHandler; struct Structure; template class AdventureMapButton; -class CBuildingRect : public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested +class CBuildingRect : public Hoverable, public ClickableL, public ClickableR//, public TimeInterested { public: Structure* str; @@ -19,7 +19,7 @@ public: void activate(); void deactivate(); bool operator<(const CBuildingRect & p2) const; - void mouseMoved (SDL_MouseMotionEvent & sEvent); + void hover(bool on); void clickLeft (tribool down); void clickRight (tribool down); }; diff --git a/CMT.cpp b/CMT.cpp index 92dc68478..3ceeb311e 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -276,6 +276,7 @@ void initGameState(CGameInfo * cgi) int _tmain(int argc, _TCHAR* argv[]) { + //std::ios_base::sync_with_stdio(0); //CLuaHandler luatest; //luatest.test(); diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index efd76e7f6..25dc35009 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -17,6 +17,7 @@ #include "hch/CGeneralTextHandler.h" #include "CCastleInterface.h" #include "CHeroWindow.h" +#include "timeHandler.h" using namespace CSDL_Ext; class OCM_HLP_CGIN @@ -1235,7 +1236,10 @@ SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh) void CPlayerInterface::openTownWindow(const CGTownInstance * town) { adventureInt->hide(); + timeHandler t; + t.getDif(); castleInt = new CCastleInterface(town,true); + std::cout << "Loading town screen: " << t.getDif() < draws info about selected town/hero diff --git a/config/buildings3.txt b/config/buildings3.txt new file mode 100644 index 000000000..f9c5043f6 --- /dev/null +++ b/config/buildings3.txt @@ -0,0 +1,37 @@ +0 16 TBCSBLAK.def TOCSBLAK.bmp TZCSBLAK.bmp +0 20 TBCSBOAT.def TOCSDKMN.bmp TZCSDKMN.bmp +0 8 TBCSCAS2.def TOCSCAS2.bmp TZCSCAS2.bmp +0 9 TBCSCAS3.def TOCSCAS3.bmp TZCSCAS3.bmp +0 7 TBCSCSTL.def TOCSCAS1.bmp TZCSCAS1.bmp +0 6 TBCSDOCK.def TOCSDKMS.bmp TZCSDKMS.bmp +0 30 TBCSDW0_.def TOCSPIK1.bmp TZCSPIK1.bmp +0 31 TBCSDW_1.def TOCSCRS1.bmp TZCSCRS1.bmp +0 32 TBCSDW_2.def TOCSGR1N.bmp TZCSGR1N.bmp +0 33 TBCSDW_3.def TOCSSWD1.bmp TZCSSWD1.bmp +0 34 TBCSDW_4.def TOCSMON1.bmp TZCSMON1.bmp +0 35 TBCSDW_5.def TOCSC101.bmp TZCSCAV1.bmp +0 36 TBCSDW_6.def TOCSANG1.bmp TZCSANG1.bmp +0 21 TBCSEXT0.def TOCSCAVM.bmp TZCSCAVM.bmp +0 22 TBCSEXT1.def TOCSTAV2.bmp TZCSTAV2.bmp +0 11 TBCSHAL2.def TOCSH201.bmp TZCSH201.bmp +0 12 TBCSHAL3.def TOCSH301.bmp TZCSH301.bmp +0 13 TBCSHAL4.def TOCSH401.bmp TZCSH401.bmp +0 10 TBCSHALL.def TOCSH101.bmp TZCSH101.bmp +0 26 TBCSHOLY.def TOCSHOLY.bmp TZCSHOLY.bmp +0 18 TBCSHRD1.def TOCSGR1H.bmp TZCSGR1H.bmp +0 19 TBCSHRD2.def TOCSGR2H.bmp TZCSGR2H.bmp +0 1 TBCSMAG2.def TOCSMAG2.bmp TZCSMAG2.bmp +0 2 TBCSMAG3.def TOCSM301.bmp TZCSM301.bmp +0 3 TBCSMAG4.def TOCSM401.bmp TZCSM401.bmp +0 0 TBCSMAGE.def TOCSMAG1.bmp TZCSMAG1.bmp +0 14 TBCSMARK.def TOCSMRK1.bmp TZCSMRK1.bmp +0 15 TBCSSILO.def TOCSMRK2.bmp TZCSMRK2.bmp +0 17 TBCSSPEC.def TOCSLT01.bmp TZCSLT01.bmp +0 5 TBCSTVRN.def TOCSTAV1.bmp TZCSTAV1.bmp +0 37 TBCSUP0_.def TOCSPIK2.bmp TZCSPIK2.bmp +0 38 TBCSUP_1.def TOCSCRS2.bmp TZCSCRS2.bmp +0 39 TBCSUP_2.def TOCSGR2N.bmp TZCSGR2N.bmp +0 40 TBCSUP_3.def TOCSSWD2.bmp TZCSSWD2.bmp +0 41 TBCSUP_4.def TOCSMON2.bmp TZCSMON2.bmp +0 42 TBCSUP_5.def TOCSCAV2.bmp TZCSCAV2.bmp +0 43 TBCSUP_6.def TOCSANG2.bmp TZCSANG2.bmp \ No newline at end of file diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 77ced1230..bae6d564b 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -254,6 +254,8 @@ SDL_Surface * CPCXConv::getSurface() } SDL_Surface * CLodHandler::loadBitmap(std::string fname) { + if(!fname.size()) + return NULL; unsigned char * pcx; std::transform(fname.begin(),fname.end(),fname.begin(),toupper); fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX"); @@ -270,6 +272,7 @@ SDL_Surface * CLodHandler::loadBitmap(std::string fname) if(index==-1) { std::cout<<"File "<second.find(buildingID=atoi(s.c_str()))))!=(i->second.end())) i2->second->pos.z=itr++; else - std::cout << "Warning: No building "< >::iterator i; + std::map::iterator i2; + int town, id; + std::string border, area; + of >> town >> id >> border >> border >> area; + + if((i=structures.find(town))!=structures.end()) + if((i2=(i->second.find(id)))!=(i->second.end())) + { + i2->second->borderName = border; + i2->second->areaName = area; + } + else + std::cout << "Warning2: No building "<