mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Wyświetlanie (parcjalne) wyboru scenariusza, można wybierać trudność.
Sporo róznych poprawek i rzeczy, których nie pamiętam, doszukasz na Tracu ;)
This commit is contained in:
parent
de95bb0753
commit
a2998c4316
11
CMT.cpp
11
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;
|
||||
|
22
CMessage.cpp
22
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);
|
||||
|
51
CMessage.h
51
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 T=ttt> class CGroup;
|
||||
template <class T=ttt> class CPoinGroup ;
|
||||
template <class T=ttt> struct Button
|
||||
{
|
||||
int type;
|
||||
SDL_Rect pos;
|
||||
T fun;
|
||||
CSemiDefHandler* imgs;
|
||||
Button( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CGroup<T>* 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<T> * ourGroup;
|
||||
};
|
||||
//template<class T=void(CPreGame::*)(int)>
|
||||
template<class T=ttt> struct IntSelBut: public Button<T>
|
||||
{
|
||||
public:
|
||||
CPoinGroup<T> * ourGroup;
|
||||
int key;
|
||||
IntSelBut(){};
|
||||
IntSelBut( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CPoinGroup<T>* 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 T=ttt> class CPoinGroup :public CGroup<T>
|
||||
{
|
||||
public:
|
||||
int * gdzie; //where (po polsku, bo by by³o s³owo kluczowe :/)
|
||||
void setYour(IntSelBut<T> * your){*gdzie=your->key;};
|
||||
};
|
||||
template <class T=ttt> class CGroup
|
||||
{
|
||||
public:
|
||||
Button<T> * selected;
|
||||
int type; // 1=sinsel
|
||||
CGroup():selected(NULL),type(0){};
|
||||
};
|
||||
class CMessage
|
||||
{
|
||||
SDL_Color tytulowy ;
|
||||
SDL_Color tlo;
|
||||
SDL_Color zwykly ;
|
||||
public:
|
||||
std::vector<std::string> * breakText(std::string text);
|
||||
CSemiDefHandler * piecesOfBox;
|
||||
@ -15,3 +58,5 @@ public:
|
||||
SDL_Surface * drawBox1(int w, int h);
|
||||
CMessage();
|
||||
};
|
||||
|
||||
//
|
||||
|
223
CPreGame.cpp
223
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 <class T> void Button<T>::press(bool down)
|
||||
{
|
||||
if ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+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 <class T> void Button<T>::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 <class T> void Button<T>::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; i<ourScenSel->bScens.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; i<ourScenSel->bRandom.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; i<ourScenSel->bOptions.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;i<btns.size();i++)
|
||||
{
|
||||
btns[i]->pos.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;i<btns.size();i++)
|
||||
{
|
||||
if (btns[i]->ID==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;i<btns.size(); i++)
|
||||
{
|
||||
if (isItIn(&btns[i]->pos,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;i<btns.size(); i++)
|
||||
{
|
||||
if (isItIn(&btns[i]->pos,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;i<btns.size(); i++)
|
||||
{
|
||||
if (isItIn(&btns[i].pos,sEvent.motion.x,sEvent.motion.y))
|
||||
if (isItIn(&btns[i]->pos,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.size(); i++)
|
||||
{
|
||||
if (isItIn(&btns[i].pos,sEvent.motion.x,sEvent.motion.y))
|
||||
(this->*(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;
|
||||
|
33
CPreGame.h
33
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 <class T=ttt> struct Button
|
||||
class ScenSel
|
||||
{
|
||||
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(){};
|
||||
};
|
||||
public:
|
||||
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<Mapa> maps;
|
||||
void genScenList();
|
||||
int selectedDiff;
|
||||
~ScenSel(){delete difficulty;};
|
||||
} ;
|
||||
class CPreGame
|
||||
{
|
||||
public:
|
||||
std::vector<Button<> > btns;
|
||||
CSemiLodHandler * slh ;
|
||||
std::vector<Button<> *> 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<CSemiLodHandler *> 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();
|
||||
|
@ -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 && x<rect->x+rect->w) && (y>rect->y && y<rect->y+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;
|
||||
|
Loading…
Reference in New Issue
Block a user