main_menu.*pp is building

Scene list:
    > disconnected_screen.*pp
    * lobby_menu.*pp
    > main_menu.*pp
    > options_menu.*pp
    > splash_screen.*pp
    * world*.*pp

    * unfinished
    > building
This commit is contained in:
2015-08-14 18:49:37 +10:00
parent a4d3a356c3
commit a7ce7a0e9b
3 changed files with 47 additions and 47 deletions
+39 -43
View File
@@ -31,37 +31,36 @@ MainMenu::MainMenu() {
ConfigUtility& config = ConfigUtility::GetSingleton();
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
buttonImage.Load(GetRenderer(), config["dir.interface"] + "button.png");
font = TTF_OpenFont(config["client.font"].c_str(), 12);
//pass the utility objects
startButton.SetImage(&image);
startButton.SetFont(&font);
optionsButton.SetImage(&image);
optionsButton.SetFont(&font);
quitButton.SetImage(&image);
quitButton.SetFont(&font);
//setup the buttons
startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
startButton.SetText(GetRenderer(), font, "Start", {255, 255, 255, 255});
optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
optionsButton.SetText(GetRenderer(), font, "Options", {255, 255, 255, 255});
quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
quitButton.SetText(GetRenderer(), font, "Quit", {255, 255, 255, 255});
//set the button positions
startButton.SetX(50);
startButton.SetY(50 + image.GetClipH() * 0);
startButton.SetY(50 + 20 * 0);
optionsButton.SetX(50);
optionsButton.SetY(50 + image.GetClipH() * 1);
optionsButton.SetY(50 + 20 * 1);
quitButton.SetX(50);
quitButton.SetY(50 + image.GetClipH() * 2);
quitButton.SetY(50 + 20 * 2);
//set the button texts
startButton.SetText("Start");
optionsButton.SetText("Options");
quitButton.SetText("Quit");
//text box
textBox.PushLine(GetRenderer(), font, "Thanks for playing!", {255, 255, 255, 255});
textBox.PushLine(GetRenderer(), font, "You can get the latest version at: ", {255, 255, 255, 255});
textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255});
//debug
//
}
MainMenu::~MainMenu() {
//
TTF_CloseFont(font);
}
//-------------------------
@@ -80,52 +79,49 @@ void MainMenu::FrameEnd() {
//
}
void MainMenu::Render(SDL_Surface* const screen) {
startButton.DrawTo(screen);
optionsButton.DrawTo(screen);
quitButton.DrawTo(screen);
void MainMenu::RenderFrame(SDL_Renderer* renderer) {
startButton.DrawTo(renderer);
optionsButton.DrawTo(renderer);
quitButton.DrawTo(renderer);
//text
font.DrawStringTo("Thanks for playing!", screen, 50, screen->h - 50 - image.GetClipH() * 2);
font.DrawStringTo("You can get the latest version at: ", screen, 50, screen->h - 50 - image.GetClipH() * 1);
font.DrawStringTo("krgamestudios.com", screen, 50, screen->h - 50 - image.GetClipH() * 0);
textBox.DrawTo(renderer, 50, 50, 12);
}
//-------------------------
//Event handlers
//-------------------------
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
startButton.MouseMotion(motion);
optionsButton.MouseMotion(motion);
quitButton.MouseMotion(motion);
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& event) {
startButton.MouseMotion(event);
optionsButton.MouseMotion(event);
quitButton.MouseMotion(event);
}
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
startButton.MouseButtonDown(button);
optionsButton.MouseButtonDown(button);
quitButton.MouseButtonDown(button);
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
startButton.MouseButtonDown(event);
optionsButton.MouseButtonDown(event);
quitButton.MouseButtonDown(event);
}
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
//TODO: (2) Buttons should only register as "selected" when the left button is used
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU);
if (startButton.MouseButtonUp(event) == Button::State::RELEASED) {
SetSceneSignal(SceneSignal::LOBBYMENU);
}
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::OPTIONSMENU);
if (optionsButton.MouseButtonUp(event) == Button::State::RELEASED) {
SetSceneSignal(SceneSignal::OPTIONSMENU);
}
if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
if (quitButton.MouseButtonUp(event) == Button::State::RELEASED) {
QuitEvent();
}
}
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
void MainMenu::KeyDown(SDL_KeyboardEvent const& event) {
//
}
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
void MainMenu::KeyUp(SDL_KeyboardEvent const& event) {
switch(event.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
+7 -3
View File
@@ -22,9 +22,11 @@
#pragma once
#include "base_scene.hpp"
#include "image.hpp"
#include "button.hpp"
#include "image.hpp"
#include "text_box.hpp"
#include "SDL2/SDL_ttf.h"
class MainMenu : public BaseScene {
public:
@@ -49,8 +51,10 @@ protected:
void KeyUp(SDL_KeyboardEvent const& event) override;
//members
Image image;
Image buttonImage;
TTF_Font* font = nullptr;
Button startButton;
Button optionsButton;
Button quitButton;
TextBox textBox;
};
+1 -1
View File
@@ -7,7 +7,7 @@ CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
CXXSRC=$(wildcard *.cpp)
#DEBUG: override the wildcard
CXXSRC=disconnected_screen.cpp options_menu.cpp splash_screen.cpp
CXXSRC=disconnected_screen.cpp main_menu.cpp options_menu.cpp splash_screen.cpp
#objects
OBJDIR=obj