Cleaned fonts up a little, and added a NewGame button, though not functional yet. Night!

This commit is contained in:
Rtch90 2011-12-11 23:56:01 +00:00
parent 055f3fcc50
commit 93bbd34acc
4 changed files with 81 additions and 20 deletions

View File

@ -5,28 +5,49 @@ MainMenu::MainMenu(void) {
btnNewGame.SetOverRGB(255, 255, 255); btnNewGame.SetOverRGB(255, 255, 255);
btnNewGame.SetTextRGB(0, 0, 0); btnNewGame.SetTextRGB(0, 0, 0);
btnNewGame.SetText("New Game"); btnNewGame.SetText("New Game");
btnNewGame.SetXY(100, 100); btnNewGame.SetXY(100, 150);
btnNewGameActive = false;
lblNewGame.SetXY(275, 160);
lblNewGame.SetTextBlended("This will delete your current game, are you sure?", "vsmall", 0, 0, 0);
rectNewGame.SetRGB(200, 200, 200);
rectNewGame.SetXY(250, 150);
rectNewGame.SetWidthHeight(lblNewGame.GetWidth() + 50, 90);
btnNewGameYes.SetOutRGB(20, 150, 20);
btnNewGameYes.SetOverRGB(20, 255, 20);
btnNewGameYes.SetTextRGB(0, 0, 0);
btnNewGameYes.SetText("Yes");
btnNewGameYes.SetXY(rectNewGame.GetX() + rectNewGame.GetWidth() / 2 + 40 - btnNewGameYes.GetWidth(), 190);
btnNewGameNo.SetOutRGB(150, 20, 20);
btnNewGameNo.SetOverRGB(255, 20, 20);
btnNewGameNo.SetTextRGB(0, 0, 0);
btnNewGameNo.SetText("No");
btnNewGameNo.SetXY(rectNewGame.GetX() + rectNewGame.GetWidth() / 2 + 40 - btnNewGameNo.GetWidth(), 190);
btnLoadGame.SetOutRGB(200, 200, 200); btnLoadGame.SetOutRGB(200, 200, 200);
btnLoadGame.SetOverRGB(255, 255, 255); btnLoadGame.SetOverRGB(255, 255, 255);
btnLoadGame.SetTextRGB(0, 0, 0); btnLoadGame.SetTextRGB(0, 0, 0);
btnLoadGame.SetText("Load Game"); btnLoadGame.SetText("Load Game");
btnLoadGame.SetXY(100, 150); btnLoadGame.SetXY(100, 200);
btnOptions.SetOutRGB(200, 200, 200); btnOptions.SetOutRGB(200, 200, 200);
btnOptions.SetOverRGB(255, 255, 255); btnOptions.SetOverRGB(255, 255, 255);
btnOptions.SetTextRGB(0, 0, 0); btnOptions.SetTextRGB(0, 0, 0);
btnOptions.SetText("Options"); btnOptions.SetText("Options");
btnOptions.SetXY(100, 200); btnOptions.SetXY(100, 250);
btnExit.SetOutRGB(200, 200, 200); btnExit.SetOutRGB(200, 200, 200);
btnExit.SetOverRGB(255, 255, 255); btnExit.SetOverRGB(255, 255, 255);
btnExit.SetTextRGB(0, 0, 0); btnExit.SetTextRGB(0, 0, 0);
btnExit.SetText("Exit"); btnExit.SetText("Exit");
btnExit.SetXY(100, 250); btnExit.SetXY(100, 300);
menuLabel.SetXY(100, 50); lblMenu.SetXY(100, 75);
menuLabel.SetTextBlended("MainMenu", "large", 0, 0, 0); lblMenu.SetTextBlended("Unuk", "vlarge", 0, 0, 0);
m_background = new Map; m_background = new Map;
m_background->Load("MainMenu"); m_background->Load("MainMenu");
@ -42,6 +63,11 @@ MainMenu::~MainMenu(void) {
int MainMenu::HandleInput(void) { int MainMenu::HandleInput(void) {
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {
btnNewGame.CheckMouseOver(); btnNewGame.CheckMouseOver();
if(btnNewGameActive) {
btnNewGameYes.CheckMouseOver();
btnNewGameNo.CheckMouseOver();
}
btnLoadGame.CheckMouseOver(); btnLoadGame.CheckMouseOver();
btnOptions.CheckMouseOver(); btnOptions.CheckMouseOver();
btnExit.CheckMouseOver(); btnExit.CheckMouseOver();
@ -49,13 +75,20 @@ int MainMenu::HandleInput(void) {
if(event.type == SDL_MOUSEBUTTONUP) { if(event.type == SDL_MOUSEBUTTONUP) {
if(event.button.button == SDL_BUTTON_LEFT) { if(event.button.button == SDL_BUTTON_LEFT) {
if(btnNewGame.CheckMouseOver()) if(btnNewGame.CheckMouseOver())
return MAIN_MENU_NEW_GAME; btnNewGameActive = !btnNewGameActive;
else if(btnLoadGame.CheckMouseOver()) else if(btnLoadGame.CheckMouseOver())
return MAIN_MENU_LOAD_GAME; return MAIN_MENU_LOAD_GAME;
else if(btnOptions.CheckMouseOver()) else if(btnOptions.CheckMouseOver())
return MAIN_MENU_OPTIONS; return MAIN_MENU_OPTIONS;
else if(btnExit.CheckMouseOver()) else if(btnExit.CheckMouseOver())
return MAIN_MENU_EXIT; return MAIN_MENU_EXIT;
if(btnNewGameActive) {
if(btnNewGameYes.CheckMouseOver())
return MAIN_MENU_NEW_GAME;
else if(btnNewGameNo.CheckMouseOver())
btnNewGameActive = false;
}
} }
} }
else if(event.type == SDL_QUIT) { else if(event.type == SDL_QUIT) {
@ -68,9 +101,16 @@ int MainMenu::HandleInput(void) {
void MainMenu::Render(void) { void MainMenu::Render(void) {
m_background->Render(); m_background->Render();
menuLabel.Render(); lblMenu.Render();
btnNewGame.Render(); btnNewGame.Render();
if(btnNewGameActive) {
rectNewGame.Draw();
lblNewGame.Render();
btnNewGameYes.Render();
btnNewGameNo.Render();
}
btnLoadGame.Render(); btnLoadGame.Render();
btnOptions.Render(); btnOptions.Render();
btnExit.Render(); btnExit.Render();

View File

@ -23,9 +23,16 @@ public:
private: private:
Map* m_background; Map* m_background;
Text menuLabel; Text lblMenu;
Button btnNewGame; Button btnNewGame;
bool btnNewGameActive;
Rect rectNewGame;
Text lblNewGame;
Button btnNewGameYes;
Button btnNewGameNo;
Button btnLoadGame; Button btnLoadGame;
Button btnOptions; Button btnOptions;
Button btnExit; Button btnExit;

View File

@ -1,9 +1,10 @@
#include "Text.h" #include "Text.h"
TTF_Font* Text::verySmallFont = NULL; TTF_Font* Text::vSmallFont = NULL;
TTF_Font* Text::smallFont = NULL; TTF_Font* Text::smallFont = NULL;
TTF_Font* Text::mediumFont = NULL; TTF_Font* Text::mediumFont = NULL;
TTF_Font* Text::largeFont = NULL; TTF_Font* Text::largeFont = NULL;
TTF_Font* Text::vLargeFont = NULL;
Text::Text(void) { Text::Text(void) {
m_text = NULL; m_text = NULL;
@ -16,28 +17,32 @@ Text::~Text(void) {
void Text::LoadFonts(void) { void Text::LoadFonts(void) {
// Load the fonts if they are not already in memory. // Load the fonts if they are not already in memory.
assert(verySmallFont == NULL); assert(vSmallFont == NULL);
assert(smallFont == NULL); assert(smallFont == NULL);
assert(mediumFont == NULL); assert(mediumFont == NULL);
assert(largeFont == NULL); assert(largeFont == NULL);
assert(vLargeFont == NULL);
verySmallFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 16); vSmallFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 16);
smallFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 23); smallFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 23);
mediumFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 27); mediumFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 27);
largeFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 32); largeFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 32);
vLargeFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 48);
} }
void Text::FreeFonts(void) { void Text::FreeFonts(void) {
// If the fonts are loaded, then free them. // If the fonts are loaded, then free them.
assert(verySmallFont != NULL); assert(vSmallFont != NULL);
assert(smallFont != NULL); assert(smallFont != NULL);
assert(mediumFont != NULL); assert(mediumFont != NULL);
assert(largeFont != NULL); assert(largeFont != NULL);
assert(vLargeFont != NULL);
TTF_CloseFont(verySmallFont); TTF_CloseFont(vSmallFont);
TTF_CloseFont(smallFont); TTF_CloseFont(smallFont);
TTF_CloseFont(mediumFont); TTF_CloseFont(mediumFont);
TTF_CloseFont(largeFont); TTF_CloseFont(largeFont);
TTF_CloseFont(vLargeFont);
} }
void Text::SetXY(int xArg, int yArg) { void Text::SetXY(int xArg, int yArg) {
@ -53,7 +58,7 @@ int Text::SetTextBlended(string textArg, string size, SDL_Color colour) {
} }
if(size == "vsmall") { if(size == "vsmall") {
m_text = TTF_RenderText_Blended(verySmallFont, textArg.c_str(), colour); m_text = TTF_RenderText_Blended(vSmallFont, textArg.c_str(), colour);
return 1; return 1;
} }
else if(size == "small") { else if(size == "small") {
@ -67,6 +72,10 @@ int Text::SetTextBlended(string textArg, string size, SDL_Color colour) {
else if(size == "large") { else if(size == "large") {
m_text = TTF_RenderText_Blended(largeFont, textArg.c_str(), colour); m_text = TTF_RenderText_Blended(largeFont, textArg.c_str(), colour);
return 1; return 1;
}
else if(size == "vlarge") {
m_text = TTF_RenderText_Blended(vLargeFont, textArg.c_str(), colour);
return 1;
} else { } else {
Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str()); Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str());
m_text = TTF_RenderText_Blended(smallFont, textArg.c_str(), colour); m_text = TTF_RenderText_Blended(smallFont, textArg.c_str(), colour);
@ -87,7 +96,7 @@ int Text::SetTextShaded(string textArg, string size, SDL_Color colour, SDL_Color
} }
if(size == "vsmall") { if(size == "vsmall") {
m_text = TTF_RenderText_Shaded(verySmallFont, textArg.c_str(), colour, bgColour); m_text = TTF_RenderText_Shaded(vSmallFont, textArg.c_str(), colour, bgColour);
return 1; return 1;
} }
else if(size == "small") { else if(size == "small") {
@ -101,6 +110,10 @@ int Text::SetTextShaded(string textArg, string size, SDL_Color colour, SDL_Color
else if(size == "large") { else if(size == "large") {
m_text = TTF_RenderText_Shaded(largeFont, textArg.c_str(), colour, bgColour); m_text = TTF_RenderText_Shaded(largeFont, textArg.c_str(), colour, bgColour);
return 1; return 1;
}
else if(size == "vlarge") {
m_text = TTF_RenderText_Shaded(vLargeFont, textArg.c_str(), colour, bgColour);
return 1;
} else { } else {
Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str()); Debug::logger->message("Text::SetTextBlended(): Invalid size argument %s. Defaulted to small.", size.c_str());
m_text = TTF_RenderText_Shaded(smallFont, textArg.c_str(), colour, bgColour); m_text = TTF_RenderText_Shaded(smallFont, textArg.c_str(), colour, bgColour);

View File

@ -45,10 +45,11 @@ private:
SDL_Color m_textColour; SDL_Color m_textColour;
SDL_Surface* m_text; SDL_Surface* m_text;
static TTF_Font* verySmallFont; static TTF_Font* vSmallFont;
static TTF_Font* smallFont; static TTF_Font* smallFont;
static TTF_Font* mediumFont; static TTF_Font* mediumFont;
static TTF_Font* largeFont; static TTF_Font* largeFont;
static TTF_Font* vLargeFont;
}; };
#endif #endif