1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Naprawa dziur w głównym menu, uprzejrzystnienie kodu, Button szablonem.

This commit is contained in:
Michał W. Urbańczyk 2007-06-14 10:14:26 +00:00
parent df7ef8115b
commit 4b67e80055
2 changed files with 18 additions and 12 deletions

View File

@ -35,8 +35,8 @@ void CPreGame::initMainMenu()
ourMainMenu->highScores = slh->giveDef("ZMENUHS.DEF"); ourMainMenu->highScores = slh->giveDef("ZMENUHS.DEF");
ourMainMenu->credits = slh->giveDef("ZMENUCR.DEF"); ourMainMenu->credits = slh->giveDef("ZMENUCR.DEF");
ourMainMenu->quit = slh->giveDef("ZMENUQT.DEF"); ourMainMenu->quit = slh->giveDef("ZMENUQT.DEF");
ourMainMenu->ok = slh->giveDef("IOKAY.DEF"); ok = slh->giveDef("IOKAY.DEF");
ourMainMenu->cancel = slh->giveDef("ICANCEL.DEF"); cancel = slh->giveDef("ICANCEL.DEF");
// new game button location // new game button location
ourMainMenu->lNewGame.h=ourMainMenu->newGame->ourImages[0].bitmap->h; ourMainMenu->lNewGame.h=ourMainMenu->newGame->ourImages[0].bitmap->h;
ourMainMenu->lNewGame.w=ourMainMenu->newGame->ourImages[0].bitmap->w; ourMainMenu->lNewGame.w=ourMainMenu->newGame->ourImages[0].bitmap->w;
@ -128,8 +128,8 @@ void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)())
CMessage * cmh = new CMessage(); CMessage * cmh = new CMessage();
std::vector<CSemiDefHandler*> * przyciski = new std::vector<CSemiDefHandler*>(0); std::vector<CSemiDefHandler*> * przyciski = new std::vector<CSemiDefHandler*>(0);
std::vector<SDL_Rect> * btnspos= new std::vector<SDL_Rect>(0); std::vector<SDL_Rect> * btnspos= new std::vector<SDL_Rect>(0);
przyciski->push_back(ourMainMenu->ok); przyciski->push_back(ok);
przyciski->push_back(ourMainMenu->cancel); przyciski->push_back(cancel);
SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data), EWindowType::yesOrNO, przyciski, btnspos); SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data), EWindowType::yesOrNO, przyciski, btnspos);
behindCurMes = SDL_CreateRGBSurface(ekran->flags,infoBox->w,infoBox->h,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask); behindCurMes = SDL_CreateRGBSurface(ekran->flags,infoBox->w,infoBox->h,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
SDL_Rect pos = genRect(infoBox->h,infoBox->w, SDL_Rect pos = genRect(infoBox->h,infoBox->w,
@ -143,8 +143,8 @@ void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)())
(*btnspos)[0].y+=pos.y; (*btnspos)[0].y+=pos.y;
(*btnspos)[1].x+=pos.x; (*btnspos)[1].x+=pos.x;
(*btnspos)[1].y+=pos.y; (*btnspos)[1].y+=pos.y;
btns.push_back(Button(1,(*btnspos)[0],&CPreGame::quit,ourMainMenu->ok)); btns.push_back(Button<>(1,(*btnspos)[0],&CPreGame::quit,ok));
btns.push_back(Button(2,(*btnspos)[1],(&CPreGame::hideBox),ourMainMenu->cancel)); btns.push_back(Button<>(2,(*btnspos)[1],(&CPreGame::hideBox),cancel));
delete cmh; delete cmh;
delete przyciski; delete przyciski;
delete btnspos; delete btnspos;
@ -173,6 +173,7 @@ void CPreGame::runLoop()
return ; return ;
else if (sEvent.type==SDL_MOUSEMOTION) else if (sEvent.type==SDL_MOUSEMOTION)
{ {
if (currentMessage) continue;
if (ourMainMenu->highlighted) if (ourMainMenu->highlighted)
{ {
switch (ourMainMenu->highlighted) switch (ourMainMenu->highlighted)
@ -270,6 +271,7 @@ void CPreGame::runLoop()
updateRect(&btns[i].pos); updateRect(&btns[i].pos);
} }
} }
if (currentMessage) continue;
if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y)) if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y))
{ {
highlightButton(1,1); highlightButton(1,1);
@ -308,6 +310,7 @@ void CPreGame::runLoop()
updateRect(&btns[i].pos); updateRect(&btns[i].pos);
} }
} }
if (currentMessage) continue;
if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y)) if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y))
{ {
highlightButton(1,2); highlightButton(1,2);
@ -337,6 +340,7 @@ void CPreGame::runLoop()
} }
else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_RIGHT)) else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_RIGHT))
{ {
if (currentMessage) continue;
if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y)) if (isItIn(&ourMainMenu->lNewGame,sEvent.motion.x,sEvent.motion.y))
{ {
showCenBox(preth->mainNewGame); showCenBox(preth->mainNewGame);

View File

@ -4,28 +4,30 @@
#include "CPreGameTextHandler.h" #include "CPreGameTextHandler.h"
class CPreGame; class CPreGame;
extern CPreGame * CPG; extern CPreGame * CPG;
struct Button typedef void(CPreGame::*ttt)();
template <class T=ttt> struct Button
{ {
int type; // 1=yes; 2=no int type; // 1=yes; 2=no
SDL_Rect pos; SDL_Rect pos;
(void)(CPreGame::*fun)(); T fun;
CSemiDefHandler* imgs; CSemiDefHandler* imgs;
Button(int Type, SDL_Rect Pos, void(CPreGame::*Fun)(),CSemiDefHandler* Imgs):imgs(Imgs),type(Type),pos(Pos),fun(Fun){}; Button(int Type, SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs):imgs(Imgs),type(Type),pos(Pos),fun(Fun){};
Button(){}; Button(){};
}; };
class CPreGame class CPreGame
{ {
public: public:
std::vector<Button> btns; std::vector<Button<> > btns;
CPreGameTextHandler * preth ; CPreGameTextHandler * preth ;
SDL_Rect * currentMessage; SDL_Rect * currentMessage;
SDL_Surface * behindCurMes; SDL_Surface * behindCurMes;
CSemiDefHandler *ok, *cancel;
enum EState { //where are we? enum EState { //where are we?
mainMenu, ScenarioList mainMenu, newGame, loadGame, ScenarioList
} state; } state;
struct menuItems { struct menuItems {
SDL_Surface * background; SDL_Surface * background;
CSemiDefHandler *newGame, *loadGame, *highScores,*credits, *quit, *ok, *cancel; CSemiDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit; SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
} * ourMainMenu, * newGameManu; } * ourMainMenu, * newGameManu;