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