diff --git a/client/menu_scenes/disconnected_screen.cpp b/client/menu_scenes/disconnected_screen.cpp index 6c1240a..0a5e655 100644 --- a/client/menu_scenes/disconnected_screen.cpp +++ b/client/menu_scenes/disconnected_screen.cpp @@ -23,7 +23,6 @@ #include "channels.hpp" #include "config_utility.hpp" -#include "text_util.hpp" #include "udp_network_utility.hpp" #include @@ -42,12 +41,15 @@ DisconnectedScreen::DisconnectedScreen() { //setup the button 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 backButton.SetX(50); backButton.SetY(50); + //set the disconnection message text + textLine.SetText(GetRenderer(), font, config["client.disconnectMessage"], {255, 255, 255, 255}); + //full reset UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER); @@ -81,44 +83,36 @@ void DisconnectedScreen::FrameEnd() { } void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) { - ConfigUtility& config = ConfigUtility::GetSingleton(); - backButton.DrawTo(renderer); - //render output message - 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); + textLine.DrawTo(renderer, 50, 50); } //------------------------- //Event handlers //------------------------- -void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& motion) { - backButton.MouseMotion(motion); +void DisconnectedScreen::MouseMotion(SDL_MouseMotionEvent const& event) { + backButton.MouseMotion(event); } -void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) { - backButton.MouseButtonDown(button); +void DisconnectedScreen::MouseButtonDown(SDL_MouseButtonEvent const& event) { + backButton.MouseButtonDown(event); } -void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) { - if (backButton.MouseButtonUp(button) == Button::State::RELEASED) { +void DisconnectedScreen::MouseButtonUp(SDL_MouseButtonEvent const& event) { + if (backButton.MouseButtonUp(event) == Button::State::RELEASED) { SetSceneSignal(SceneSignal::MAINMENU); } } -void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { +void DisconnectedScreen::KeyDown(SDL_KeyboardEvent const& event) { + switch(event.keysym.sym) { case SDLK_ESCAPE: SetSceneSignal(SceneSignal::MAINMENU); break; } } -void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& key) { +void DisconnectedScreen::KeyUp(SDL_KeyboardEvent const& event) { // } diff --git a/client/menu_scenes/disconnected_screen.hpp b/client/menu_scenes/disconnected_screen.hpp index a82444b..5edf340 100644 --- a/client/menu_scenes/disconnected_screen.hpp +++ b/client/menu_scenes/disconnected_screen.hpp @@ -24,6 +24,8 @@ #include "base_scene.hpp" #include "button.hpp" #include "image.hpp" +#include "text_line.hpp" + #include "SDL2/SDL_ttf.h" #include @@ -54,6 +56,7 @@ protected: Image image; TTF_Font* font = nullptr; Button backButton; + TextLine textLine; //auto return std::chrono::steady_clock::time_point startTick; diff --git a/client/menu_scenes/makefile b/client/menu_scenes/makefile index f03de53..79e4aa1 100644 --- a/client/menu_scenes/makefile +++ b/client/menu_scenes/makefile @@ -6,6 +6,9 @@ CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) #source CXXSRC=$(wildcard *.cpp) +#DEBUG: override the wildcard +CXXSRC=disconnected_screen.cpp options_menu.cpp splash_screen.cpp + #objects OBJDIR=obj OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) diff --git a/client/menu_scenes/options_menu.cpp b/client/menu_scenes/options_menu.cpp index f06b798..96863b3 100644 --- a/client/menu_scenes/options_menu.cpp +++ b/client/menu_scenes/options_menu.cpp @@ -31,24 +31,23 @@ OptionsMenu::OptionsMenu() { 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 - backButton.SetImage(&image); - backButton.SetFont(&font); + //setup the button + backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture()); + backButton.SetText(GetRenderer(), font, "Back", {255, 255, 255, 255}); //set the button positions backButton.SetX(50); - backButton.SetY(50 + image.GetClipH() * 0); + backButton.SetY(50); - //set the button texts - backButton.SetText("Back"); + //text line + textLine.SetText(GetRenderer(), font, "This code is fucking hard to refactor.", {255, 255, 255, 255}); } OptionsMenu::~OptionsMenu() { - // + TTF_CloseFont(font); } //------------------------- @@ -67,38 +66,37 @@ void OptionsMenu::FrameEnd() { // } -void OptionsMenu::Render(SDL_Surface* const screen) { - backButton.DrawTo(screen); - - font.DrawStringTo("Oh, were you looking for the options screen?", screen, 50, 30); +void OptionsMenu::RenderFrame(SDL_Renderer* renderer) { + backButton.DrawTo(renderer); + textLine.DrawTo(renderer, 50, 30); } //------------------------- //Event handlers //------------------------- -void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& motion) { - backButton.MouseMotion(motion); +void OptionsMenu::MouseMotion(SDL_MouseMotionEvent const& event) { + backButton.MouseMotion(event); } -void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) { - backButton.MouseButtonDown(button); +void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) { + backButton.MouseButtonDown(event); } -void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { - if (backButton.MouseButtonUp(button) == Button::State::HOVER) { - SetNextScene(SceneList::MAINMENU); +void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) { + if (backButton.MouseButtonUp(event) == Button::State::RELEASED) { + SetSceneSignal(SceneSignal::MAINMENU); } } -void OptionsMenu::KeyDown(SDL_KeyboardEvent const& key) { - switch(key.keysym.sym) { +void OptionsMenu::KeyDown(SDL_KeyboardEvent const& event) { + switch(event.keysym.sym) { case SDLK_ESCAPE: - SetNextScene(SceneList::MAINMENU); + SetSceneSignal(SceneSignal::MAINMENU); break; } } -void OptionsMenu::KeyUp(SDL_KeyboardEvent const& key) { +void OptionsMenu::KeyUp(SDL_KeyboardEvent const& event) { // } diff --git a/client/menu_scenes/options_menu.hpp b/client/menu_scenes/options_menu.hpp index 509ce92..31507f6 100644 --- a/client/menu_scenes/options_menu.hpp +++ b/client/menu_scenes/options_menu.hpp @@ -21,10 +21,11 @@ */ #pragma once -#include "base_scene.hpp" - -#include "image.hpp" #include "button.hpp" +#include "image.hpp" +#include "text_line.hpp" + +#include "base_scene.hpp" //NOTE: The options screen needs to be USED class OptionsMenu : public BaseScene { @@ -50,6 +51,8 @@ private: void KeyUp(SDL_KeyboardEvent const& event) override; //members - Image image; + Image buttonImage; + TTF_Font* font = nullptr; Button backButton; + TextLine textLine; }; diff --git a/client/menu_scenes/splash_screen.cpp b/client/menu_scenes/splash_screen.cpp index 7d97546..9fefd4a 100644 --- a/client/menu_scenes/splash_screen.cpp +++ b/client/menu_scenes/splash_screen.cpp @@ -28,7 +28,7 @@ //------------------------- 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(); } @@ -48,6 +48,6 @@ void SplashScreen::FrameStart() { void SplashScreen::RenderFrame(SDL_Renderer* renderer) { 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); } diff --git a/client/menu_scenes/splash_screen.hpp b/client/menu_scenes/splash_screen.hpp index abc2907..469c647 100644 --- a/client/menu_scenes/splash_screen.hpp +++ b/client/menu_scenes/splash_screen.hpp @@ -22,7 +22,6 @@ #pragma once #include "base_scene.hpp" - #include "image.hpp" #include diff --git a/rsc/graphics/logos/krstudios.bmp b/rsc/graphics/logos/krstudios.bmp deleted file mode 100644 index ca07226..0000000 Binary files a/rsc/graphics/logos/krstudios.bmp and /dev/null differ diff --git a/rsc/graphics/logos/krstudios.png b/rsc/graphics/logos/krstudios.png new file mode 100644 index 0000000..9a411c1 Binary files /dev/null and b/rsc/graphics/logos/krstudios.png differ