One menu scene works, but I need some more UI widgets
Namely, I need a text box widget, which can display text without having to re-create and destroy the texture every frame.
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#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>
|
||||||
@@ -35,20 +36,17 @@ DisconnectedScreen::DisconnectedScreen() {
|
|||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
//TODO: (1) resource tool, to prevent reloading like this
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.Load(GetRenderer(), config["dir.interface"] + "button.png");
|
||||||
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
|
font = TTF_OpenFont(config["client.font"].c_str(), 12);
|
||||||
|
|
||||||
//pass the utility objects
|
//setup the button
|
||||||
backButton.SetImage(&image);
|
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
|
||||||
backButton.SetFont(&font);
|
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
|
||||||
|
|
||||||
//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
|
|
||||||
backButton.SetText("Back");
|
|
||||||
|
|
||||||
//full reset
|
//full reset
|
||||||
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
|
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
|
||||||
@@ -71,7 +69,7 @@ void DisconnectedScreen::FrameStart() {
|
|||||||
|
|
||||||
void DisconnectedScreen::Update() {
|
void DisconnectedScreen::Update() {
|
||||||
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
||||||
SetNextScene(SceneList::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Eat incoming packets
|
//Eat incoming packets
|
||||||
@@ -86,7 +84,13 @@ void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
backButton.DrawTo(renderer);
|
backButton.DrawTo(renderer);
|
||||||
font.DrawStringTo(config["client.disconnectMessage"], screen, 50, 30);
|
//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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -21,14 +21,11 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//graphics
|
|
||||||
#include "image.hpp"
|
|
||||||
#include "button.hpp"
|
|
||||||
|
|
||||||
//client
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
#include "button.hpp"
|
||||||
|
#include "image.hpp"
|
||||||
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
//std namespace
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
class DisconnectedScreen : public BaseScene {
|
class DisconnectedScreen : public BaseScene {
|
||||||
@@ -55,6 +52,7 @@ protected:
|
|||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image image;
|
Image image;
|
||||||
|
TTF_Font* font = nullptr;
|
||||||
Button backButton;
|
Button backButton;
|
||||||
|
|
||||||
//auto return
|
//auto return
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
INCLUDES+=. .. ../client_utilities ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -12,12 +12,14 @@ server.dbname = database.db
|
|||||||
#client.screen.h = 600
|
#client.screen.h = 600
|
||||||
client.screen.f = false
|
client.screen.f = false
|
||||||
|
|
||||||
|
#TODO: change this based on platform?
|
||||||
|
client.font = /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf
|
||||||
|
|
||||||
client.username = username
|
client.username = username
|
||||||
client.handle = handle
|
client.handle = handle
|
||||||
client.avatar = elliot2.bmp
|
client.avatar = elliot2.bmp
|
||||||
|
|
||||||
#directories
|
#directories
|
||||||
dir.fonts = rsc/graphics/fonts/
|
|
||||||
dir.logos = rsc/graphics/logos/
|
dir.logos = rsc/graphics/logos/
|
||||||
dir.sprites = rsc/graphics/sprites/
|
dir.sprites = rsc/graphics/sprites/
|
||||||
dir.tilesets = rsc/graphics/tilesets/
|
dir.tilesets = rsc/graphics/tilesets/
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 65 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 321 B |
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user