Select Git revision
AddSolutionForm.js
Forked from
KSZK / DevTeam / kszkepzes / old / kszkepzes-frontend
Source project has a limited visibility.
menu.c 3.93 KiB
/* Copyright (C) 2013 Barnabás Czémán <trabarni@gmail.com>
This file is part of Minesweeper2D.
Minesweeper2D is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Minesweeper2D is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Minesweeper2D. If not, see <http://www.gnu.org/licenses/>.*/
#include "menu.h"
#include "button.h"
#include "SDL_image.h"
#include "enums.h"
#include "label.h"
#include "colors.h"
/*Létezik-e file*/
/** Ez a függvény egy fájl létezését vizsgálja a játékmappájától viszonyítva.
*
* \param filename fájlneve
* \return létezik-e
*
*/
int fileIsAviable(char const* filename)
{
FILE* fp;
fp=fopen(filename,"r");
if(fp==NULL)
{
return 0;
}
else
{
fclose(fp);
return 1;
}
}
/** Ez a függvény kirajzolja a főmenüt.
*
* \param screen amire kirajzolja
* \param evt esemény változó
* \param bgButton gombok háttere
*
*
*/
MainMenu drawMenu(SDL_Surface* screen,SDL_Event* evt,TTF_Font* font,SDL_Surface* bg,SDL_Surface* bgButton)
{
/*Menüpontok poziciója*/
Uint16 cache[10];
SDL_Rect rectContinue= {200,120,200,50},
rectNew= {200,190,200,50},
rectHighScore= {200,260,200,50},
rectExit= {200,410,200,50},
rectLMain={250,50,200,50};
Button btnContinue,btnNew,btnHighScore,btnExit;
Label labelMain;
/*Menüpontok inicializációja*/
setButton(&btnContinue,rectContinue,bgButton,font,"Continue");
setButton(&btnNew,rectNew,bgButton,font,"NewGame");
setButton(&btnHighScore,rectHighScore,bgButton,font,"HighScore");
setButton(&btnExit,rectExit,bgButton,font,"Exit");
/*Folytatás gomb inaktiv*/
if(!fileIsAviable("game.sav"))
setActive(&btnContinue,0);
if(!fileIsAviable("highscore.rst")){
setActive(&btnHighScore,0);
}
utf8_2_unicode("Main Menu",cache);
setLabel(&labelMain,font,&rectLMain,cache,&white);
while(SDL_WaitEvent(evt)/*eseményre vár*/&&1/*Forever*/)/*Fömenü esemény kezelő hurokja*/
{
/*háttér kirajzolása*/
SDL_BlitSurface(bg,NULL,screen,NULL);
/*menüpontok kirajzolása*/
drawButton(screen,evt,&btnContinue);
drawButton(screen,evt,&btnNew);
drawButton(screen,evt,&btnHighScore);
drawButton(screen,evt,&btnExit);
/*menüpontok eseményeinek beállítása*/
setButtonEvents(&btnContinue,evt);
setButtonEvents(&btnNew,evt);
setButtonEvents(&btnHighScore,evt);
setButtonEvents(&btnExit,evt);
drawLabel(screen,&labelMain);
if(btnContinue.leftButtonClicked==1)
{
return CONTINUE;/*folytatás menüpontra katintáskor vissza tér az állapottal*/
}
if(btnNew.leftButtonClicked==1)
{
return NEW_GAME;/*új játék menüpontra katintáskor vissza tér az állapottal*/
}
if(btnHighScore.leftButtonClicked==1)
{
return HIGH_SCORE;/*dicsőségtábla menüpontra katintáskor vissza tér az állapottal*/
}
if(btnExit.leftButtonClicked==1)
{
/*Gombok felszabadítása*/
destroyButton(&btnContinue);
destroyButton(&btnExit);
destroyButton(&btnHighScore);
destroyButton(&btnNew);
destroyLabel(&labelMain);
return QUIT_TO_OS;/*kilépés menüpontra katintáskor vissza tér az állapottal*/
}
SDL_Flip(screen);/*kirajzol*/
}
return 1;
}