|
|
@@ -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)
|
|
|
+{
|
|
|
+ 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 ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+rect->h))
|
|
|
- return true;
|
|
|
- else return false;
|
|
|
+ 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;
|