From a2998c43166a08507ab0575e3100ae5a339d1769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 19 Jun 2007 15:25:42 +0000 Subject: [PATCH] =?UTF-8?q?Wy=C5=9Bwietlanie=20(parcjalne)=20wyboru=20scen?= =?UTF-8?q?ariusza,=20mo=C5=BCna=20wybiera=C4=87=20trudno=C5=9B=C4=87.=20S?= =?UTF-8?q?poro=20r=C3=B3znych=20poprawek=20i=20rzeczy,=20kt=C3=B3rych=20n?= =?UTF-8?q?ie=20pami=C4=99tam,=20doszukasz=20na=20Tracu=20;)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMT.cpp | 11 ++- CMessage.cpp | 22 +++-- CMessage.h | 53 ++++++++++- CPreGame.cpp | 223 +++++++++++++++++++++++++++++++++++++++++---- CPreGame.h | 37 +++++--- SDL_Extensions.cpp | 19 ++++ 6 files changed, 320 insertions(+), 45 deletions(-) diff --git a/CMT.cpp b/CMT.cpp index 23799a1e1..408575575 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -43,7 +43,7 @@ const char * NAME = "VCMI 0.2"; version of the library linked do not match, or Z_ERRNO if there is an error reading or writing the files. */ SDL_Surface * ekran; -TTF_Font * TNRB; +TTF_Font * TNRB16, *TNR, *GEOR13; int def(FILE *source, FILE *dest, int level, int winBits=15, int memLevel =8) { int ret, flush; @@ -215,7 +215,10 @@ int _tmain(int argc, _TCHAR* argv[]) TTF_Init(); atexit(TTF_Quit); atexit(SDL_Quit); - TNRB = TTF_OpenFont("Fonts\\tnrb.ttf",16); + //TNRB = TTF_OpenFont("Fonts\\tnrb.ttf",16); + TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16); + //TNR = TTF_OpenFont("Fonts\\tnr.ttf",10); + GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13); //initializing audio if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048)==-1) @@ -234,11 +237,11 @@ int _tmain(int argc, _TCHAR* argv[]) // this might be a critical error... } - /*if(Mix_PlayMusic(music, -1)==-1) //uncomment this fragment to have music + if(Mix_PlayMusic(music, -1)==-1) //uncomment this fragment to have music { printf("Mix_PlayMusic: %s\n", Mix_GetError()); // well, there's no music, but most games don't break without music... - }*/ + } screen = SDL_SetVideoMode(800,600,24,SDL_HWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); ekran = screen; diff --git a/CMessage.cpp b/CMessage.cpp index a64467b53..a08e9a8a7 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -2,19 +2,24 @@ #include "CMessage.h" #include "SDL_TTF.h" #include "CSemiDefHandler.h" -extern TTF_Font * TNRB; -extern SDL_Surface * ekran; +SDL_Color tytulowy, tlo, zwykly ; SDL_Rect genRect(int hh, int ww, int xx, int yy); + +extern SDL_Surface * ekran; +extern TTF_Font * TNRB16, *TNR, *GEOR13; +SDL_Color genRGB(int r, int g, int b, int a=0); +void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran); +void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran); +extern CPreGame * CPG; +void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran); +bool isItIn(const SDL_Rect * rect, int x, int y); CMessage::CMessage() { piecesOfBox = new CSemiDefHandler(); piecesOfBox->openDef("DIALGBOX.DEF","H3sprite.lod"); background = SDL_LoadBMP("H3bitmap.lod\\DIBOXBCK.BMP"); SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255)); - tytulowy.r=229;tytulowy.g=215;tytulowy.b=123;tytulowy.unused=0; - zwykly.r=255;zwykly.g=255;zwykly.b=255;zwykly.unused=0; //gbr - tlo.r=66;tlo.g=44;tlo.b=24;tlo.unused=0; } SDL_Surface * CMessage::drawBox1(int w, int h) { @@ -113,7 +118,9 @@ SDL_Surface * CMessage::genMessage if (title.length()) { - SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB,title.c_str(),tytulowy,tlo); + //SDL_Surface * titleText = TTF_RenderText_Shaded(TNRB16,title.c_str(),tytulowy,tlo); + SDL_Surface * titleText = TTF_RenderText_Blended(TNRB16,title.c_str(),tytulowy); + //draw title SDL_Rect tytul = genRect(titleText->h,titleText->w,((ret->w/2)-(titleText->w/2)),37); SDL_BlitSurface(titleText,NULL,ret,&tytul); @@ -124,7 +131,8 @@ SDL_Surface * CMessage::genMessage { int by = 37+i*21; if (title.length()) by+=40; - SDL_Surface * tresc = TTF_RenderText_Shaded(TNRB,(*tekst)[i].c_str(),zwykly,tlo); + //SDL_Surface * tresc = TTF_RenderText_Shaded(TNRB16,(*tekst)[i].c_str(),zwykly,tlo); + SDL_Surface * tresc = TTF_RenderText_Blended(TNRB16,(*tekst)[i].c_str(),zwykly); SDL_Rect trescRect = genRect(tresc->h,tresc->w,((ret->w/2)-(tresc->w/2)),by); SDL_BlitSurface(tresc,NULL,ret,&trescRect); SDL_FreeSurface(tresc); diff --git a/CMessage.h b/CMessage.h index 55a96e398..cb0753abb 100644 --- a/CMessage.h +++ b/CMessage.h @@ -1,11 +1,54 @@ #include "SDL_TTF.h" #include "CSemiDefHandler.h" enum EWindowType {infoOnly, infoOK, yesOrNO}; +class CPreGame; +typedef void(CPreGame::*ttt)(); +template class CGroup; +template class CPoinGroup ; +template struct Button +{ + int type; + SDL_Rect pos; + T fun; + CSemiDefHandler* imgs; + Button( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1) + :state(0),selectable(Sel),selected(false),imgs(Imgs),pos(Pos),fun(Fun),ourGroup(gr), type(0), ID(id){}; + Button(){}; + bool selectable, selected; + bool highlightable, highlighted; + int state; + int ID; + virtual void hover(bool on=true); + virtual void press(bool down=true); + virtual void select(bool on=true); + CGroup * ourGroup; +}; +//template +template struct IntSelBut: public Button +{ +public: + CPoinGroup * ourGroup; + int key; + IntSelBut(){}; + IntSelBut( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1) + : Button(Pos,Fun,Imgs,Sel,gr),key(My){ourGroup=gr;}; + void select(bool on=true) {(*this).Button::select(on);ourGroup->setYour(this);} +}; +template class CPoinGroup :public CGroup +{ +public: + int * gdzie; //where (po polsku, bo by było słowo kluczowe :/) + void setYour(IntSelBut * your){*gdzie=your->key;}; +}; +template class CGroup +{ +public: + Button * selected; + int type; // 1=sinsel + CGroup():selected(NULL),type(0){}; +}; class CMessage { - SDL_Color tytulowy ; - SDL_Color tlo; - SDL_Color zwykly ; public: std::vector * breakText(std::string text); CSemiDefHandler * piecesOfBox; @@ -14,4 +57,6 @@ public: std::vector *addPics=NULL, void * cb=NULL); SDL_Surface * drawBox1(int w, int h); CMessage(); -}; \ No newline at end of file +}; + +// diff --git a/CPreGame.cpp b/CPreGame.cpp index d8a7e600a..deb441578 100644 --- a/CPreGame.cpp +++ b/CPreGame.cpp @@ -1,34 +1,172 @@ #include "stdafx.h" #include "CPreGame.h" #include "SDL.h" -#include "CMessage.h" extern SDL_Surface * ekran; +extern SDL_Color tytulowy, tlo, zwykly ; +extern TTF_Font * TNRB16, *TNR, *GEOR13; SDL_Rect genRect(int hh, int ww, int xx, int yy); SDL_Color genRGB(int r, int g, int b, int a=0); +void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran); +void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran); CPreGame * CPG; void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran); -bool isItIn(const SDL_Rect * rect, int x, int y) +bool isItIn(const SDL_Rect * rect, int x, int y); + +template void Button::press(bool down) { - if ((x>rect->x && xx+rect->w) && (y>rect->y && yy+rect->h)) - return true; - else return false; + int i; + if (down) state=i=1; + else state=i=0; + SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos); + updateRect(&pos); +} +template void Button::hover(bool on=true) +{ + if (!highlightable) return; + int i; + if (on) state=i=2; + else state=i=0; + SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos); + updateRect(&pos); +} +template void Button::select(bool on) +{ + int i; + if (on) state=i=3; + else state=i=0; + SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,ekran,&pos); + updateRect(&pos); + if (ourGroup && on && ourGroup->type==1) + { + if (ourGroup->selected && ourGroup->selected!=this) + ourGroup->selected->select(false); + ourGroup->selected =this; + } } CPreGame::CPreGame() { + + tytulowy.r=229;tytulowy.g=215;tytulowy.b=123;tytulowy.unused=0; + zwykly.r=255;zwykly.g=255;zwykly.b=255;zwykly.unused=0; //gbr + tlo.r=66;tlo.g=44;tlo.b=24;tlo.unused=0; preth = new CPreGameTextHandler; preth->loadTexts(); currentMessage=NULL; behindCurMes=NULL; initMainMenu(); initNewMenu(); + initScenSel(); showMainMenu(); CPG=this; } +void CPreGame::initScenSel() +{ + ourScenSel = new ScenSel(); + if (rand()%2) ourScenSel->background=SDL_LoadBMP("h3bitmap.lod\\ZPIC1000.bmp"); + else ourScenSel->background=SDL_LoadBMP("h3bitmap.lod\\ZPIC1001.bmp"); + + ourScenSel->pressed=NULL; + + ourScenSel->scenInf=SDL_LoadBMP("h3bitmap.lod\\GSELPOP1.bmp"); + ourScenSel->scenList=SDL_LoadBMP("h3bitmap.lod\\SCSELBCK.bmp"); + ourScenSel->randMap=SDL_LoadBMP("h3bitmap.lod\\RANMAPBK.bmp"); + ourScenSel->options=SDL_LoadBMP("h3bitmap.lod\\ADVOPTBK.bmp"); + SDL_SetColorKey(ourScenSel->scenInf,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenInf->format,0,255,255)); + SDL_SetColorKey(ourScenSel->scenList,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenList->format,0,255,255)); + SDL_SetColorKey(ourScenSel->randMap,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->randMap->format,0,255,255)); + SDL_SetColorKey(ourScenSel->options,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->options->format,0,255,255)); + + ourScenSel->difficulty = new CPoinGroup<>(); + ourScenSel->difficulty->type=1; + ourScenSel->selectedDiff=-77; + ourScenSel->difficulty->gdzie = &ourScenSel->selectedDiff; + ourScenSel->bEasy = IntSelBut<>(genRect(0,0,506,456),NULL,slh->giveDef("GSPBUT3.DEF"),true,ourScenSel->difficulty,1); + ourScenSel->bNormal = IntSelBut<>(genRect(0,0,538,456),NULL,slh->giveDef("GSPBUT4.DEF"),true,ourScenSel->difficulty,2); + ourScenSel->bHard = IntSelBut<>(genRect(0,0,570,456),NULL,slh->giveDef("GSPBUT5.DEF"),true,ourScenSel->difficulty,3); + ourScenSel->bExpert = IntSelBut<>(genRect(0,0,602,456),NULL,slh->giveDef("GSPBUT6.DEF"),true,ourScenSel->difficulty,4); + ourScenSel->bImpossible = IntSelBut<>(genRect(0,0,634,456),NULL,slh->giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,5); + + ourScenSel->bBack = Button<>(genRect(0,0,584,535),&CPreGame::showNewMenu,slh->giveDef("SCNRBACK.DEF")); + ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::showScenList,slh->giveDef("SCNRBEG.DEF")); + + ourScenSel->bScens = Button<>(genRect(0,0,414,81),&CPreGame::showScenList,slh->giveDef("GSPBUTT.DEF")); + for (int i=0; ibScens.imgs->ourImages.size(); i++) + printAt("Show Available Scenarios",25+i,2+i,GEOR13,zwykly,ourScenSel->bScens.imgs->ourImages[i].bitmap); + ourScenSel->bRandom = Button<>(genRect(0,0,414,105),&CPreGame::showScenList,slh->giveDef("GSPBUTT.DEF")); + for (int i=0; ibRandom.imgs->ourImages.size(); i++) + printAt("Random Map",25+i,2+i,GEOR13,zwykly,ourScenSel->bRandom.imgs->ourImages[i].bitmap); + ourScenSel->bOptions = Button<>(genRect(0,0,414,509),&CPreGame::showScenList,slh->giveDef("GSPBUTT.DEF")); + for (int i=0; ibOptions.imgs->ourImages.size(); i++) + printAt("Show Advanced Options",25+i,2+i,GEOR13,zwykly,ourScenSel->bOptions.imgs->ourImages[i].bitmap); + + +} + +void CPreGame::showScenSel() +{ + state=EState::ScenarioList; + SDL_BlitSurface(ourScenSel->background,NULL,ekran,NULL); + SDL_BlitSurface(ourScenSel->scenInf,NULL,ekran,&genRect(ourScenSel->scenInf->h,ourScenSel->scenInf->w,395,6)); + //blit texts + printAt(preth->singleScenarioName,420,25,GEOR13); + printAt("Scenario Description:",420,135,GEOR13); + printAt("Victory Condition:",420,285,GEOR13); + printAt("Loss Condition:",420,340,GEOR13); + printAt("Allies:",420,406,GEOR13,zwykly); + printAt("Enemies:",585,406,GEOR13,zwykly); + printAt("Map Diff:",427,438,GEOR13); + printAt("Player Difficulty:",527,438,GEOR13); + printAt("Rating:",685,438,GEOR13); + //blit buttons + SDL_BlitSurface(ourScenSel->bEasy.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bEasy.pos); + SDL_BlitSurface(ourScenSel->bNormal.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bNormal.pos); + SDL_BlitSurface(ourScenSel->bHard.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bHard.pos); + SDL_BlitSurface(ourScenSel->bExpert.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bExpert.pos); + SDL_BlitSurface(ourScenSel->bImpossible.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bImpossible.pos); + SDL_BlitSurface(ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bScens.pos); + SDL_BlitSurface(ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bOptions.pos); + SDL_BlitSurface(ourScenSel->bBegin.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBegin.pos); + SDL_BlitSurface(ourScenSel->bBack.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBack.pos); + SDL_BlitSurface(ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bRandom.pos); + //blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y); + //blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105); + //blitAt(ourScenSel->bOptions.imgs->ourImages[0].bitmap,414,509); + //blitAt(ourScenSel->bBegin.imgs->ourImages[0].bitmap,414,535); + //blitAt(ourScenSel->bBack.imgs->ourImages[0].bitmap,584,535); + //add buttons info + btns.push_back(&ourScenSel->bEasy); + btns.push_back(&ourScenSel->bNormal); + btns.push_back(&ourScenSel->bHard); + btns.push_back(&ourScenSel->bExpert); + btns.push_back(&ourScenSel->bImpossible); + btns.push_back(&ourScenSel->bScens); + btns.push_back(&ourScenSel->bRandom); + btns.push_back(&ourScenSel->bOptions); + btns.push_back(&ourScenSel->bBegin); + btns.push_back(&ourScenSel->bBack); + + ourScenSel->selectedDiff=1; + ourScenSel->bNormal.select(true); + + for (int i=0;ipos.w=btns[i]->imgs->ourImages[0].bitmap->w; + btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h; + } + + handleOther = &CPreGame::scenHandleEv; + SDL_Flip(ekran); + +} +void CPreGame::showScenList() +{} +void CPreGame::showOptions() +{} void CPreGame::initNewMenu() { ourNewMenu = new menuItems(); ourNewMenu->background = SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp"); - CSemiLodHandler * slh = new CSemiLodHandler(); + slh = new CSemiLodHandler(); slh->openLod("H3sprite.lod"); //loading menu buttons ourNewMenu->newGame = slh->giveDef("ZTSINGL.DEF"); @@ -43,6 +181,7 @@ void CPreGame::initNewMenu() ourNewMenu->lNewGame.w=ourNewMenu->newGame->ourImages[0].bitmap->w; ourNewMenu->lNewGame.x=545; ourNewMenu->lNewGame.y=4; + ourNewMenu->fNewGame=&CPreGame::showScenSel; //multiplayer ourNewMenu->lLoadGame.h=ourNewMenu->loadGame->ourImages[0].bitmap->h; ourNewMenu->lLoadGame.w=ourNewMenu->loadGame->ourImages[0].bitmap->w; @@ -66,11 +205,10 @@ void CPreGame::initNewMenu() ourNewMenu->fQuit=&CPreGame::showMainMenu; ourNewMenu->highlighted=0; - handledLods.push_back(slh); - delete slh; } void CPreGame::showNewMenu() { + btns.clear(); state = EState::newGame; SDL_BlitSurface(ourNewMenu->background,NULL,ekran,NULL); SDL_BlitSurface(ourNewMenu->newGame->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lNewGame); @@ -205,8 +343,8 @@ void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)()) (*btnspos)[0].y+=pos.y; (*btnspos)[1].x+=pos.x; (*btnspos)[1].y+=pos.y; - btns.push_back(Button<>(1,(*btnspos)[0],&CPreGame::quit,ok)); - btns.push_back(Button<>(2,(*btnspos)[1],(&CPreGame::hideBox),cancel)); + btns.push_back(new Button<>((*btnspos)[0],&CPreGame::quit,ok,false, NULL,2)); + btns.push_back(new Button<>((*btnspos)[1],(&CPreGame::hideBox),cancel,false, NULL,2)); delete cmh; delete przyciski; delete btnspos; @@ -216,7 +354,14 @@ void CPreGame::hideBox () SDL_BlitSurface(behindCurMes,NULL,ekran,currentMessage); SDL_UpdateRect (ekran,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h); - btns.clear(); + for (int i=0;iID==2) + { + delete btns[i]; + btns.erase(btns.begin()+i); + } + } SDL_FreeSurface(behindCurMes); delete currentMessage; currentMessage = NULL; @@ -230,6 +375,42 @@ CPreGame::menuItems * CPreGame::currentItems() return ourMainMenu; case EState::newGame: return ourNewMenu; + default: + return NULL; + } +} + +void CPreGame::scenHandleEv(SDL_Event& sEvent) +{ + if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT)) + { + for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) + { + btns[i]->press(true); + ourScenSel->pressed=btns[i]; + } + } + } + else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT)) + { + if (ourScenSel->pressed) + { + ourScenSel->pressed->press(false); + ourScenSel->pressed=NULL; + } + for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) + { + if (btns[i]->selectable) + btns[i]->select(true); + if (btns[i]->fun) + (this->*(btns[i]->fun))(); + return; + } + } } } void CPreGame::runLoop() @@ -244,6 +425,10 @@ void CPreGame::runLoop() menuItems * current = currentItems(); if(sEvent.type==SDL_QUIT) return ; + if (!current) + { + (this->*handleOther)(sEvent); + } else if (sEvent.type==SDL_KEYDOWN) { if (sEvent.key.keysym.sym==SDLK_q) @@ -375,10 +560,11 @@ void CPreGame::runLoop() { for (int i=0;ipos,sEvent.motion.x,sEvent.motion.y)) { - SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,ekran,&btns[i].pos); - updateRect(&btns[i].pos); + btns[i]->press(true); + //SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,ekran,&btns[i].pos); + //updateRect(&btns[i].pos); } } if (currentMessage) continue; @@ -412,12 +598,13 @@ void CPreGame::runLoop() { for (int i=0;i*(btns[i].fun))(); + if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y)) + (this->*(btns[i]->fun))(); else { - SDL_BlitSurface((btns[i].imgs)->ourImages[0].bitmap,NULL,ekran,&btns[i].pos); - updateRect(&btns[i].pos); + btns[i]->press(false); + //SDL_BlitSurface((btns[i].imgs)->ourImages[0].bitmap,NULL,ekran,&btns[i].pos); + //updateRect(&btns[i].pos); } } if (currentMessage) continue; diff --git a/CPreGame.h b/CPreGame.h index ea1d6f753..504f17ba5 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -2,22 +2,28 @@ #include "CSemiDefHandler.h" #include "CSemiLodHandler.h" #include "CPreGameTextHandler.h" +#include "CMessage.h" +#include "map.h" class CPreGame; extern CPreGame * CPG; -typedef void(CPreGame::*ttt)(); -template struct Button -{ - int type; // 1=yes; 2=no - SDL_Rect pos; - T fun; - CSemiDefHandler* imgs; - Button(int Type, SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs):imgs(Imgs),type(Type),pos(Pos),fun(Fun){}; - Button(){}; -}; -class CPreGame +class ScenSel { public: - std::vector > btns; + SDL_Surface * background, *scenInf, *scenList, *randMap, *options ; + Button<> bScens, bOptions, bRandom, bBegin, bBack; + IntSelBut<> bEasy, bNormal, bHard, bExpert, bImpossible; + Button<> * pressed; + CPoinGroup<> * difficulty; + std::vector maps; + void genScenList(); + int selectedDiff; + ~ScenSel(){delete difficulty;}; +} ; +class CPreGame +{ +public: + CSemiLodHandler * slh ; + std::vector *> btns; CPreGameTextHandler * preth ; SDL_Rect * currentMessage; SDL_Surface * behindCurMes; @@ -32,13 +38,20 @@ public: ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit; int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit } * ourMainMenu, * ourNewMenu; + ScenSel * ourScenSel; std::string map; //selected map std::vector handledLods; CPreGame(); //c-tor std::string buttonText(int which); menuItems * currentItems(); + void(CPreGame::*handleOther)(SDL_Event&); + void scenHandleEv(SDL_Event& sEvent); void quitAskBox(); void quit(){exit(0);}; + void initScenSel(); + void showScenSel(); + void showScenList(); + void showOptions(); void initNewMenu(); void showNewMenu(); void showMainMenu(); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 7ee478e40..53d803b98 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -1,6 +1,14 @@ #include "stdafx.h" #include "SDL_Extensions.h" +#include "SDL_TTF.h" extern SDL_Surface * ekran; +extern SDL_Color tytulowy, tlo, zwykly ; +bool isItIn(const SDL_Rect * rect, int x, int y) +{ + if ((x>rect->x && xx+rect->w) && (y>rect->y && yy+rect->h)) + return true; + else return false; +} SDL_Rect genRect(int hh, int ww, int xx, int yy) { SDL_Rect ret; @@ -10,6 +18,10 @@ SDL_Rect genRect(int hh, int ww, int xx, int yy) ret.y=yy; return ret; } +void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran) +{ + SDL_BlitSurface(src,NULL,dst,&genRect(src->h,src->w,x,y)); +} SDL_Color genRGB(int r, int g, int b, int a=0) { SDL_Color ret; @@ -23,6 +35,13 @@ void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran) { SDL_UpdateRect(scr,rect->x,rect->y,rect->w,rect->h); } +void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran) +{ + SDL_Surface * temp = TTF_RenderText_Blended(font,text.c_str(),kolor); + SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y)); + SDL_UpdateRect(dst,x,y,temp->w,temp->h); + SDL_FreeSurface(temp); +} void CSDL_Ext::SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B, int myC) { Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel-myC;