[ServerLoadingState] Added.

This commit is contained in:
Quentin Bazin 2019-01-12 22:42:24 +01:00
parent f374c7ba80
commit d89283ddab
6 changed files with 104 additions and 4 deletions

View File

@ -16,6 +16,7 @@
#include <gk/core/CoreApplication.hpp>
#include "Client.hpp"
#include "KeyboardHandler.hpp"
#include "Registry.hpp"
#include "ScriptEngine.hpp"
@ -34,6 +35,8 @@ class ClientApplication : public gk::CoreApplication {
ScriptEngine m_scriptEngine;
Registry m_registry;
Client m_client;
};
#endif // CLIENTAPPLICATION_HPP_

View File

@ -30,7 +30,7 @@
class GameState : public gk::ApplicationState {
public:
GameState();
GameState(Client &client);
void testLuaAPI();
@ -55,7 +55,7 @@ class GameState : public gk::ApplicationState {
LuaCore m_luaCore;
Client m_client;
Client &m_client;
bool m_hasGameStarted = false;
};

View File

@ -0,0 +1,42 @@
/*
* =====================================================================================
*
* Filename: ServerLoadingState.hpp
*
* Description:
*
* Created: 12/01/2019 21:57:24
*
* Author: Quentin Bazin, <quent42340@gmail.com>
*
* =====================================================================================
*/
#ifndef SERVERLOADINGSTATE_HPP_
#define SERVERLOADINGSTATE_HPP_
#include <gk/core/ApplicationState.hpp>
#include <gk/gl/Shader.hpp>
#include <gk/graphics/Text.hpp>
class Client;
class ServerLoadingState : public gk::ApplicationState {
public:
ServerLoadingState(Client &client);
void update() override;
private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
gk::Shader m_shader;
Client &m_client;
gk::Text m_text;
gk::Text m_textShadow;
mutable bool m_hasBeenDrawn = false;
};
#endif // SERVERLOADINGSTATE_HPP_

View File

@ -19,6 +19,7 @@
#include "Config.hpp"
#include "GameState.hpp"
#include "TextureLoader.hpp"
#include "ServerLoadingState.hpp"
void ClientApplication::init() {
gk::CoreApplication::init();
@ -41,7 +42,8 @@ void ClientApplication::init() {
m_scriptEngine.init();
m_stateStack.push<GameState>();
// m_stateStack.push<GameState>(m_client);
m_stateStack.push<ServerLoadingState>(m_client);
}
void ClientApplication::initOpenGL() {

View File

@ -30,7 +30,7 @@
#include "PlayerInventoryWidget.hpp"
#include "ScriptEngine.hpp"
GameState::GameState() {
GameState::GameState(Client &client) : m_client(client) {
try {
m_client.connect("localhost", 4242);
}

View File

@ -0,0 +1,53 @@
/*
* =====================================================================================
*
* Filename: ServerLoadingState.cpp
*
* Description:
*
* Created: 12/01/2019 21:58:21
*
* Author: Quentin Bazin, <quent42340@gmail.com>
*
* =====================================================================================
*/
#include <gk/core/ApplicationStateStack.hpp>
#include <gk/resource/ResourceHandler.hpp>
#include "Config.hpp"
#include "GameState.hpp"
#include "ServerLoadingState.hpp"
ServerLoadingState::ServerLoadingState(Client &client) : m_client(client) {
m_shader.createProgram();
m_shader.addShader(GL_VERTEX_SHADER, "resources/shaders/basic.v.glsl");
m_shader.addShader(GL_FRAGMENT_SHADER, "resources/shaders/basic.f.glsl");
m_shader.linkProgram();
m_text.setFont(gk::ResourceHandler::getInstance().get<gk::Font>("font-default"));
m_text.setCharacterSize(8 * 6);
m_text.setText("Loading world...");
m_text.setColor(gk::Color::White);
m_text.setPosition(SCREEN_WIDTH / 2.0 - m_text.getLocalBounds().width / 2.0, 200);
m_textShadow.setFont(gk::ResourceHandler::getInstance().get<gk::Font>("font-default"));
m_textShadow.setCharacterSize(8 * 6);
m_textShadow.setText(m_text.text());
m_textShadow.setColor(gk::Color{70, 70, 70, 255});
m_textShadow.setPosition(m_text.getPosition().x + 6, m_text.getPosition().y + 6);
}
void ServerLoadingState::update() {
if (m_hasBeenDrawn)
m_stateStack->push<GameState>(m_client);
}
void ServerLoadingState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.shader = &m_shader;
target.setView(target.getDefaultView());
target.draw(m_textShadow, states);
target.draw(m_text, states);
m_hasBeenDrawn = true;
}