Some menu scenes compiling; replaced KR Studios logo file

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:18:21 +10:00
parent fedc420c19
commit a4d3a356c3
9 changed files with 52 additions and 52 deletions
+14 -20
View File
@@ -23,7 +23,6 @@
#include "channels.hpp" #include "channels.hpp"
#include "config_utility.hpp" #include "config_utility.hpp"
#include "text_util.hpp"
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include <stdexcept> #include <stdexcept>
@@ -42,12 +41,15 @@ DisconnectedScreen::DisconnectedScreen() {
//setup the button //setup the button
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture()); backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE); backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255});
//set the button positions //set the button positions
backButton.SetX(50); backButton.SetX(50);
backButton.SetY(50); backButton.SetY(50);
//set the disconnection message text
textLine.SetText(GetRenderer(), font, config["client.disconnectMessage"], {255, 255, 255, 255});
//full reset //full reset
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER); UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
@@ -81,44 +83,36 @@ void DisconnectedScreen::FrameEnd() {
} }
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) { void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
ConfigUtility& config = ConfigUtility::GetSingleton();
backButton.DrawTo(renderer); backButton.DrawTo(renderer);
//render output message textLine.DrawTo(renderer, 50, 50);
SDL_Texture* tex = renderPlainText(renderer, font, config["client.disconnectMessage"], COLOR_WHITE);
int w = 0, h = 0;
SDL_QueryTexture(tex, nullptr, nullptr, &w, &h);
SDL_Rect d = {50, 30, w, h};
SDL_RenderCopy(renderer, tex, nullptr, &d);
SDL_DestroyTexture(tex);
} }
//------------------------- //-------------------------
//Event handlers //Event handlers
//------------------------- //-------------------------
void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& motion) { void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& event) {
backButton.MouseMotion(motion); backButton.MouseMotion(event);
} }
void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) { void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& event) {
backButton.MouseButtonDown(button); backButton.MouseButtonDown(event);
} }
void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) { void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& event) {
if (backButton.MouseButtonUp(button) == Button::State::RELEASED) { if (backButton.MouseButtonUp(event) == Button::State::RELEASED) {
SetSceneSignal(SceneSignal::MAINMENU); SetSceneSignal(SceneSignal::MAINMENU);
} }
} }
void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& key) { void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& event) {
switch(key.keysym.sym) { switch(event.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
SetSceneSignal(SceneSignal::MAINMENU); SetSceneSignal(SceneSignal::MAINMENU);
break; break;
} }
} }
void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& key) { void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& event) {
// //
} }
@@ -24,6 +24,8 @@
#include "base_scene.hpp" #include "base_scene.hpp"
#include "button.hpp" #include "button.hpp"
#include "image.hpp" #include "image.hpp"
#include "text_line.hpp"
#include "SDL2/SDL_ttf.h" #include "SDL2/SDL_ttf.h"
#include <chrono> #include <chrono>
@@ -54,6 +56,7 @@ protected:
Image image; Image image;
TTF_Font* font = nullptr; TTF_Font* font = nullptr;
Button backButton; Button backButton;
TextLine textLine;
//auto return //auto return
std::chrono::steady_clock::time_point startTick; std::chrono::steady_clock::time_point startTick;
+3
View File
@@ -6,6 +6,9 @@ CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source #source
CXXSRC=$(wildcard *.cpp) CXXSRC=$(wildcard *.cpp)
#DEBUG: override the wildcard
CXXSRC=disconnected_screen.cpp options_menu.cpp splash_screen.cpp
#objects #objects
OBJDIR=obj OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
+23 -25
View File
@@ -31,24 +31,23 @@ OptionsMenu::OptionsMenu() {
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 button
backButton.SetImage(&image); backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
backButton.SetFont(&font); backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255});
//set the button positions //set the button positions
backButton.SetX(50); backButton.SetX(50);
backButton.SetY(50 + image.GetClipH() * 0); backButton.SetY(50);
//set the button texts //text line
backButton.SetText("Back"); textLine.SetText(GetRenderer(), font, "This code is fucking hard to refactor.", {255, 255, 255, 255});
} }
OptionsMenu::~OptionsMenu() { OptionsMenu::~OptionsMenu() {
// TTF_CloseFont(font);
} }
//------------------------- //-------------------------
@@ -67,38 +66,37 @@ void OptionsMenu::FrameEnd() {
// //
} }
void OptionsMenu::Render(SDL_Surface* const screen) { void OptionsMenu::RenderFrame(SDL_Renderer* renderer) {
backButton.DrawTo(screen); backButton.DrawTo(renderer);
textLine.DrawTo(renderer, 50, 30);
font.DrawStringTo("Oh, were you looking for the options screen?", screen, 50, 30);
} }
//------------------------- //-------------------------
//Event handlers //Event handlers
//------------------------- //-------------------------
void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& motion) { void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& event) {
backButton.MouseMotion(motion); backButton.MouseMotion(event);
} }
void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) { void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
backButton.MouseButtonDown(button); backButton.MouseButtonDown(event);
} }
void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER) { if (backButton.MouseButtonUp(event) == Button::State::RELEASED) {
SetNextScene(SceneList::MAINMENU); SetSceneSignal(SceneSignal::MAINMENU);
} }
} }
void OptionsMenu::KeyDown(SDL_KeyboardEvent const& key) { void OptionsMenu::KeyDown(SDL_KeyboardEvent const& event) {
switch(key.keysym.sym) { switch(event.keysym.sym) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU); SetSceneSignal(SceneSignal::MAINMENU);
break; break;
} }
} }
void OptionsMenu::KeyUp(SDL_KeyboardEvent const& key) { void OptionsMenu::KeyUp(SDL_KeyboardEvent const& event) {
// //
} }
+7 -4
View File
@@ -21,10 +21,11 @@
*/ */
#pragma once #pragma once
#include "base_scene.hpp"
#include "image.hpp"
#include "button.hpp" #include "button.hpp"
#include "image.hpp"
#include "text_line.hpp"
#include "base_scene.hpp"
//NOTE: The options screen needs to be USED //NOTE: The options screen needs to be USED
class OptionsMenu : public BaseScene { class OptionsMenu : public BaseScene {
@@ -50,6 +51,8 @@ private:
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 backButton; Button backButton;
TextLine textLine;
}; };
+2 -2
View File
@@ -28,7 +28,7 @@
//------------------------- //-------------------------
SplashScreen::SplashScreen() { SplashScreen::SplashScreen() {
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp"); logo.Load(GetRenderer(), ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.png");
startTick = std::chrono::steady_clock::now(); startTick = std::chrono::steady_clock::now();
} }
@@ -48,6 +48,6 @@ void SplashScreen::FrameStart() {
void SplashScreen::RenderFrame(SDL_Renderer* renderer) { void SplashScreen::RenderFrame(SDL_Renderer* renderer) {
int w = 0, h = 0; int w = 0, h = 0;
SDL_GetLogicalSize(renderer, &w, &h); SDL_RenderGetLogicalSize(renderer, &w, &h);
logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2); logo.DrawTo(renderer, (w - logo.GetClipW()) / 2, (h - logo.GetClipH()) / 2);
} }
-1
View File
@@ -22,7 +22,6 @@
#pragma once #pragma once
#include "base_scene.hpp" #include "base_scene.hpp"
#include "image.hpp" #include "image.hpp"
#include <chrono> #include <chrono>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB