From 93bbd34acc799076e4db3f560c64a944fa374efa Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Sun, 11 Dec 2011 23:56:01 +0000 Subject: [PATCH] Cleaned fonts up a little, and added a NewGame button, though not functional yet. Night! --- src/libUnuk/MainMenu.cpp | 56 ++++++++++++++++++++++++++++++++++------ src/libUnuk/MainMenu.h | 9 ++++++- src/libUnuk/Text.cpp | 33 ++++++++++++++++------- src/libUnuk/Text.h | 3 ++- 4 files changed, 81 insertions(+), 20 deletions(-) diff --git a/src/libUnuk/MainMenu.cpp b/src/libUnuk/MainMenu.cpp index e141e51..71b9f17 100644 --- a/src/libUnuk/MainMenu.cpp +++ b/src/libUnuk/MainMenu.cpp @@ -5,28 +5,49 @@ MainMenu::MainMenu(void) { btnNewGame.SetOverRGB(255, 255, 255); btnNewGame.SetTextRGB(0, 0, 0); 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.SetOverRGB(255, 255, 255); btnLoadGame.SetTextRGB(0, 0, 0); btnLoadGame.SetText("Load Game"); - btnLoadGame.SetXY(100, 150); + btnLoadGame.SetXY(100, 200); btnOptions.SetOutRGB(200, 200, 200); btnOptions.SetOverRGB(255, 255, 255); btnOptions.SetTextRGB(0, 0, 0); btnOptions.SetText("Options"); - btnOptions.SetXY(100, 200); + btnOptions.SetXY(100, 250); btnExit.SetOutRGB(200, 200, 200); btnExit.SetOverRGB(255, 255, 255); btnExit.SetTextRGB(0, 0, 0); btnExit.SetText("Exit"); - btnExit.SetXY(100, 250); + btnExit.SetXY(100, 300); - menuLabel.SetXY(100, 50); - menuLabel.SetTextBlended("MainMenu", "large", 0, 0, 0); + lblMenu.SetXY(100, 75); + lblMenu.SetTextBlended("Unuk", "vlarge", 0, 0, 0); m_background = new Map; m_background->Load("MainMenu"); @@ -42,6 +63,11 @@ MainMenu::~MainMenu(void) { int MainMenu::HandleInput(void) { while(SDL_PollEvent(&event)) { btnNewGame.CheckMouseOver(); + if(btnNewGameActive) { + btnNewGameYes.CheckMouseOver(); + btnNewGameNo.CheckMouseOver(); + } + btnLoadGame.CheckMouseOver(); btnOptions.CheckMouseOver(); btnExit.CheckMouseOver(); @@ -49,13 +75,20 @@ int MainMenu::HandleInput(void) { if(event.type == SDL_MOUSEBUTTONUP) { if(event.button.button == SDL_BUTTON_LEFT) { if(btnNewGame.CheckMouseOver()) - return MAIN_MENU_NEW_GAME; + btnNewGameActive = !btnNewGameActive; else if(btnLoadGame.CheckMouseOver()) return MAIN_MENU_LOAD_GAME; else if(btnOptions.CheckMouseOver()) return MAIN_MENU_OPTIONS; else if(btnExit.CheckMouseOver()) 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) { @@ -68,9 +101,16 @@ int MainMenu::HandleInput(void) { void MainMenu::Render(void) { m_background->Render(); - menuLabel.Render(); + lblMenu.Render(); btnNewGame.Render(); + if(btnNewGameActive) { + rectNewGame.Draw(); + lblNewGame.Render(); + btnNewGameYes.Render(); + btnNewGameNo.Render(); + } + btnLoadGame.Render(); btnOptions.Render(); btnExit.Render(); diff --git a/src/libUnuk/MainMenu.h b/src/libUnuk/MainMenu.h index 328ebb0..a1185cb 100644 --- a/src/libUnuk/MainMenu.h +++ b/src/libUnuk/MainMenu.h @@ -23,9 +23,16 @@ public: private: Map* m_background; - Text menuLabel; + Text lblMenu; Button btnNewGame; + + bool btnNewGameActive; + Rect rectNewGame; + Text lblNewGame; + Button btnNewGameYes; + Button btnNewGameNo; + Button btnLoadGame; Button btnOptions; Button btnExit; diff --git a/src/libUnuk/Text.cpp b/src/libUnuk/Text.cpp index 2b02561..e64d9d4 100644 --- a/src/libUnuk/Text.cpp +++ b/src/libUnuk/Text.cpp @@ -1,9 +1,10 @@ #include "Text.h" -TTF_Font* Text::verySmallFont = NULL; -TTF_Font* Text::smallFont = NULL; -TTF_Font* Text::mediumFont = NULL; -TTF_Font* Text::largeFont = NULL; +TTF_Font* Text::vSmallFont = NULL; +TTF_Font* Text::smallFont = NULL; +TTF_Font* Text::mediumFont = NULL; +TTF_Font* Text::largeFont = NULL; +TTF_Font* Text::vLargeFont = NULL; Text::Text(void) { m_text = NULL; @@ -16,28 +17,32 @@ Text::~Text(void) { void Text::LoadFonts(void) { // Load the fonts if they are not already in memory. - assert(verySmallFont == NULL); + assert(vSmallFont == NULL); assert(smallFont == NULL); assert(mediumFont == 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); mediumFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 27); largeFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 32); + vLargeFont = Font("../Data/Media/Fonts/Enigma_2.ttf", 48); } void Text::FreeFonts(void) { // If the fonts are loaded, then free them. - assert(verySmallFont != NULL); + assert(vSmallFont != NULL); assert(smallFont != NULL); assert(mediumFont != NULL); assert(largeFont != NULL); + assert(vLargeFont != NULL); - TTF_CloseFont(verySmallFont); + TTF_CloseFont(vSmallFont); TTF_CloseFont(smallFont); TTF_CloseFont(mediumFont); TTF_CloseFont(largeFont); + TTF_CloseFont(vLargeFont); } void Text::SetXY(int xArg, int yArg) { @@ -53,7 +58,7 @@ int Text::SetTextBlended(string textArg, string size, SDL_Color colour) { } 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; } else if(size == "small") { @@ -67,6 +72,10 @@ int Text::SetTextBlended(string textArg, string size, SDL_Color colour) { else if(size == "large") { m_text = TTF_RenderText_Blended(largeFont, textArg.c_str(), colour); return 1; + } + else if(size == "vlarge") { + m_text = TTF_RenderText_Blended(vLargeFont, textArg.c_str(), colour); + return 1; } else { 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); @@ -87,7 +96,7 @@ int Text::SetTextShaded(string textArg, string size, SDL_Color colour, SDL_Color } 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; } else if(size == "small") { @@ -101,6 +110,10 @@ int Text::SetTextShaded(string textArg, string size, SDL_Color colour, SDL_Color else if(size == "large") { m_text = TTF_RenderText_Shaded(largeFont, textArg.c_str(), colour, bgColour); return 1; + } + else if(size == "vlarge") { + m_text = TTF_RenderText_Shaded(vLargeFont, textArg.c_str(), colour, bgColour); + return 1; } else { 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); diff --git a/src/libUnuk/Text.h b/src/libUnuk/Text.h index a74cc08..529e275 100644 --- a/src/libUnuk/Text.h +++ b/src/libUnuk/Text.h @@ -45,10 +45,11 @@ private: SDL_Color m_textColour; SDL_Surface* m_text; - static TTF_Font* verySmallFont; + static TTF_Font* vSmallFont; static TTF_Font* smallFont; static TTF_Font* mediumFont; static TTF_Font* largeFont; + static TTF_Font* vLargeFont; }; #endif