[HUD] All the widgets works now.
This commit is contained in:
parent
1f277f38a1
commit
f374c7ba80
@ -16,15 +16,15 @@
|
||||
|
||||
#include <gk/core/SDLHeaders.hpp>
|
||||
|
||||
#include "ClientWorld.hpp"
|
||||
#include "Inventory.hpp"
|
||||
#include "Player.hpp"
|
||||
#include "World.hpp"
|
||||
|
||||
class Hotbar;
|
||||
|
||||
class BlockCursor : public gk::IDrawable {
|
||||
public:
|
||||
BlockCursor(Player &player, World &world)
|
||||
BlockCursor(Player &player, ClientWorld &world)
|
||||
: m_player(player), m_world(world) {}
|
||||
|
||||
void onEvent(const SDL_Event &event, const Hotbar &hotbar);
|
||||
@ -43,7 +43,7 @@ class BlockCursor : public gk::IDrawable {
|
||||
glm::vec4 findSelectedBlock(bool useDepthBuffer) const;
|
||||
|
||||
Player &m_player;
|
||||
World &m_world;
|
||||
ClientWorld &m_world;
|
||||
|
||||
gk::VertexBuffer m_vbo;
|
||||
gk::VertexBuffer m_animationVBO;
|
||||
|
@ -14,6 +14,8 @@
|
||||
#ifndef HUD_HPP_
|
||||
#define HUD_HPP_
|
||||
|
||||
#include <gk/gl/Shader.hpp>
|
||||
|
||||
#include "BlockCursor.hpp"
|
||||
#include "BlockInfoWidget.hpp"
|
||||
#include "Crosshair.hpp"
|
||||
@ -22,7 +24,7 @@
|
||||
|
||||
class HUD : public gk::Transformable, public gk::IDrawable {
|
||||
public:
|
||||
HUD(Player &player);
|
||||
HUD(Player &player, ClientWorld &world);
|
||||
|
||||
void onEvent(const SDL_Event &event);
|
||||
|
||||
@ -34,16 +36,16 @@ class HUD : public gk::Transformable, public gk::IDrawable {
|
||||
gk::Shader m_shader;
|
||||
glm::mat4 m_orthoMatrix;
|
||||
|
||||
// Hotbar m_hotbar;
|
||||
Hotbar m_hotbar;
|
||||
|
||||
glm::vec4 m_selectedBlock{0, 0, 0, -1};
|
||||
// BlockCursor m_blockCursor;
|
||||
BlockCursor m_blockCursor;
|
||||
Crosshair m_crosshair;
|
||||
|
||||
DebugOverlay m_debugOverlay;
|
||||
bool m_isDebugOverlayVisible = false;
|
||||
|
||||
// BlockInfoWidget m_blockInfoWidget;
|
||||
BlockInfoWidget m_blockInfoWidget;
|
||||
};
|
||||
|
||||
#endif // HUD_HPP_
|
||||
|
@ -51,7 +51,7 @@ class GameState : public gk::ApplicationState {
|
||||
gk::Camera m_camera{FOV, DIST_NEAR, DIST_FAR};
|
||||
Player m_player{m_camera};
|
||||
|
||||
HUD m_hud{m_player};
|
||||
HUD m_hud{m_player, m_world};
|
||||
|
||||
LuaCore m_luaCore;
|
||||
|
||||
|
@ -28,7 +28,9 @@ class ClientWorld : public gk::IDrawable {
|
||||
void receiveChunkData(sf::Packet &packet);
|
||||
|
||||
ClientChunk *getChunk(int cx, int cy, int cz) const;
|
||||
|
||||
u16 getBlock(int x, int y, int z) const;
|
||||
void setBlock(int x, int y, int z, u16 id);
|
||||
|
||||
private:
|
||||
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
|
||||
|
@ -71,7 +71,8 @@ void BlockCursor::onEvent(const SDL_Event &event, const Hotbar &hotbar) {
|
||||
const Block &block = Registry::getInstance().getBlock(blockId);
|
||||
const Item &item = Registry::getInstance().getItem(hotbar.currentItem());
|
||||
|
||||
if (block.id() && !block.onBlockActivated({m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z}, m_player, m_world)
|
||||
// FIXME
|
||||
if (block.id()// && !block.onBlockActivated({m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z}, m_player, m_world)
|
||||
&& hotbar.currentItem() && item.isBlock()) {
|
||||
int face = m_selectedBlock.w;
|
||||
|
||||
|
@ -14,11 +14,10 @@
|
||||
#include "Config.hpp"
|
||||
#include "HUD.hpp"
|
||||
|
||||
HUD::HUD(Player &player) :
|
||||
// FIXME
|
||||
// : m_hotbar{player.inventory()},
|
||||
// m_blockCursor(player, world),
|
||||
m_debugOverlay(player)
|
||||
HUD::HUD(Player &player, ClientWorld &world)
|
||||
: m_hotbar{player.inventory()},
|
||||
m_blockCursor(player, world),
|
||||
m_debugOverlay(player)
|
||||
{
|
||||
setScale(GUI_SCALE, GUI_SCALE, 1);
|
||||
|
||||
@ -30,44 +29,36 @@ HUD::HUD(Player &player) :
|
||||
|
||||
m_orthoMatrix = glm::ortho(0.0f, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.0f);
|
||||
|
||||
// FIXME
|
||||
// m_hotbar.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_hotbar.width() / 2, SCREEN_HEIGHT / getScale().y - m_hotbar.height(), 0);
|
||||
m_hotbar.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_hotbar.width() / 2, SCREEN_HEIGHT / getScale().y - m_hotbar.height(), 0);
|
||||
|
||||
// FIXME
|
||||
// m_blockInfoWidget.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_blockInfoWidget.width() / 2, 2, 0);
|
||||
m_blockInfoWidget.setPosition(SCREEN_WIDTH / getScale().x / 2 - m_blockInfoWidget.width() / 2, 2, 0);
|
||||
}
|
||||
|
||||
void HUD::onEvent(const SDL_Event &event) {
|
||||
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_F3)
|
||||
m_isDebugOverlayVisible ^= 1;
|
||||
|
||||
// FIXME
|
||||
// m_hotbar.onEvent(event);
|
||||
// m_blockCursor.onEvent(event, m_hotbar);
|
||||
m_hotbar.onEvent(event);
|
||||
m_blockCursor.onEvent(event, m_hotbar);
|
||||
}
|
||||
|
||||
void HUD::update() {
|
||||
// FIXME: Shouldn't be called every tick
|
||||
// FIXME
|
||||
// m_hotbar.update();
|
||||
m_hotbar.update();
|
||||
|
||||
// FIXME
|
||||
// m_blockCursor.update(m_hotbar, false);
|
||||
m_blockCursor.update(m_hotbar, false);
|
||||
|
||||
if (m_isDebugOverlayVisible)
|
||||
m_debugOverlay.update();
|
||||
|
||||
// FIXME
|
||||
// m_blockInfoWidget.update();
|
||||
m_blockInfoWidget.update();
|
||||
|
||||
// FIXME
|
||||
// if (m_blockCursor.currentBlock() != m_blockInfoWidget.currentBlock())
|
||||
// m_blockInfoWidget.setCurrentBlock(m_blockCursor.currentBlock());
|
||||
if (m_blockCursor.currentBlock() != m_blockInfoWidget.currentBlock())
|
||||
m_blockInfoWidget.setCurrentBlock(m_blockCursor.currentBlock());
|
||||
}
|
||||
|
||||
void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
// FIXME
|
||||
// target.draw(m_blockCursor, states);
|
||||
target.draw(m_blockCursor, states);
|
||||
|
||||
target.disableView();
|
||||
|
||||
@ -81,9 +72,8 @@ void HUD::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
if (m_isDebugOverlayVisible)
|
||||
target.draw(m_debugOverlay, states);
|
||||
|
||||
// FIXME
|
||||
// target.draw(m_blockInfoWidget, states);
|
||||
// target.draw(m_hotbar, states);
|
||||
target.draw(m_blockInfoWidget, states);
|
||||
target.draw(m_hotbar, states);
|
||||
|
||||
states.transform = gk::Transform::Identity;
|
||||
|
||||
|
@ -40,8 +40,6 @@ GameState::GameState() {
|
||||
|
||||
m_camera.setAspectRatio((float)SCREEN_WIDTH / SCREEN_HEIGHT);
|
||||
|
||||
// World::setInstance(m_world);
|
||||
|
||||
testLuaAPI();
|
||||
|
||||
initShaders();
|
||||
@ -49,7 +47,6 @@ GameState::GameState() {
|
||||
m_client.setCommandCallback(Network::Command::ChunkData, [this](sf::Packet &packet) {
|
||||
m_world.receiveChunkData(packet);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void GameState::testLuaAPI() {
|
||||
|
@ -98,6 +98,19 @@ u16 ClientWorld::getBlock(int x, int y, int z) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClientWorld::setBlock(int x, int y, int z, u16 id) {
|
||||
int cx = (x + CHUNK_WIDTH * (m_width / 2)) / CHUNK_WIDTH;
|
||||
int cy = (y + CHUNK_HEIGHT * (m_height / 2)) / CHUNK_HEIGHT;
|
||||
int cz = (z + CHUNK_DEPTH * (m_depth / 2)) / CHUNK_DEPTH;
|
||||
|
||||
if (cx < 0 || cx >= m_width || cy < 0 || cy >= m_height || cz < 0 || cz >= m_depth)
|
||||
return;
|
||||
|
||||
ClientChunk *chunk = m_chunks.at(cx + cy * m_width + cz * m_width * m_height).get();
|
||||
if (chunk)
|
||||
chunk->setBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_HEIGHT - 1), z & (CHUNK_DEPTH - 1), id);
|
||||
}
|
||||
|
||||
void ClientWorld::draw(gk::RenderTarget &target, gk::RenderStates states) const {
|
||||
if (!target.getView()) {
|
||||
DEBUG("ERROR: Trying to draw world without a camera");
|
||||
|
Loading…
x
Reference in New Issue
Block a user