From 8843c8f3463498390425c7b2b232598d55ee92a5 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Tue, 26 Jun 2018 23:33:01 +0200 Subject: [PATCH] [Hotbar] Small improvements. [ItemWidget] Cube size increased. [game.v.glsl] Small fix on leaves movement. --- include/gui/ItemWidget.hpp | 2 +- include/hud/Hotbar.hpp | 6 +++--- resources/shaders/basic.f.glsl | 4 ++-- resources/shaders/game.f.glsl | 2 +- resources/shaders/game.v.glsl | 4 ++-- source/gui/Image.cpp | 4 ++-- source/gui/ItemWidget.cpp | 2 +- source/hud/Hotbar.cpp | 32 +++++++++++++++----------------- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/include/gui/ItemWidget.hpp b/include/gui/ItemWidget.hpp index 2867a789..fafecaa0 100644 --- a/include/gui/ItemWidget.hpp +++ b/include/gui/ItemWidget.hpp @@ -41,7 +41,7 @@ class ItemWidget : public Widget { Image m_image; Text m_text; - Cube m_cube{9}; + Cube m_cube{10}; }; #endif // ITEMWIDGET_HPP_ diff --git a/include/hud/Hotbar.hpp b/include/hud/Hotbar.hpp index a5ddad89..82197aed 100644 --- a/include/hud/Hotbar.hpp +++ b/include/hud/Hotbar.hpp @@ -21,14 +21,14 @@ #include "SDLHeaders.hpp" #include "Shader.hpp" -class Hotbar : public IDrawable { +class Hotbar : public Widget { public: Hotbar(Inventory &inventory); - void update(); - void onEvent(const SDL_Event &event); + void update(); + int cursorPos() const { return m_cursorPos; } u16 currentItem() const { return m_inventory.getStack(m_cursorPos, 0).item().id(); } diff --git a/resources/shaders/basic.f.glsl b/resources/shaders/basic.f.glsl index 456711da..cf011ff7 100644 --- a/resources/shaders/basic.f.glsl +++ b/resources/shaders/basic.f.glsl @@ -17,9 +17,9 @@ void main() { if (color.a < 0.3) discard; if (v_faceValue == 2) - color -= vec4(0.2, 0.2, 0.2, 0.0); + color -= vec4(0.25, 0.25, 0.25, 0.0); else if (v_faceValue == 4) - color -= vec4(0.1, 0.1, 0.1, 0.0); + color -= vec4(0.15, 0.15, 0.15, 0.0); gl_FragColor = color; } diff --git a/resources/shaders/game.f.glsl b/resources/shaders/game.f.glsl index 2e95b026..ad032015 100644 --- a/resources/shaders/game.f.glsl +++ b/resources/shaders/game.f.glsl @@ -40,7 +40,7 @@ void main() { // color *= light(vec3(1.0, 1.0, 1.0), vec4(lightPosition, 1.0), 0.5, 0.5); if (v_lightValue.x != -1) { - float ambientIntensity = max(max(v_lightValue.x, v_lightValue.y) / 16.0, 4.0 / 16.0); + float ambientIntensity = max(max(v_lightValue.x, v_lightValue.y) / 16.0, 2.0 / 16.0); float diffuseIntensity = max(v_lightValue.x, v_lightValue.y) / 32.0; color = light(color, vec3(1.0, 1.0, 1.0), v_coord3d, ambientIntensity, diffuseIntensity); diff --git a/resources/shaders/game.v.glsl b/resources/shaders/game.v.glsl index a3fe0184..53003df8 100644 --- a/resources/shaders/game.v.glsl +++ b/resources/shaders/game.v.glsl @@ -32,8 +32,8 @@ void main() { finalPos.y += sin(u_time / 1000.0) / 16.0 - 0.125; } else if (coord3d.w == 4) { - finalPos.xz += sin((u_time / 1000.0 + mod(finalPos.x, 32)) * 2) / 30.0; - finalPos.xz += cos((u_time / 1000.0 + mod(finalPos.z, 32)) * 2) / 30.0; + finalPos.xz += sin((u_time / 1000.0 + finalPos.x) * 2) / 30.0; + finalPos.xz += cos((u_time / 1000.0 + finalPos.z) * 2) / 30.0; } // Used for lighting diff --git a/source/gui/Image.cpp b/source/gui/Image.cpp index da8493bc..55e075bd 100644 --- a/source/gui/Image.cpp +++ b/source/gui/Image.cpp @@ -97,7 +97,7 @@ void Image::draw(RenderTarget &target, RenderStates states) const { states.texture = m_texture; - glDisable(GL_BLEND); + // glDisable(GL_BLEND); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); @@ -106,6 +106,6 @@ void Image::draw(RenderTarget &target, RenderStates states) const { glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glEnable(GL_BLEND); + // glEnable(GL_BLEND); } diff --git a/source/gui/ItemWidget.cpp b/source/gui/ItemWidget.cpp index bc83e945..84e9de5b 100644 --- a/source/gui/ItemWidget.cpp +++ b/source/gui/ItemWidget.cpp @@ -17,7 +17,7 @@ ItemWidget::ItemWidget(Inventory &inventory, u16 x, u16 y, Widget *parent) : Widget(18, 18, parent), m_inventory(inventory), m_x(x), m_y(y) { - m_cube.setPosition(-12.5, -13.5, 0); + m_cube.setPosition(-12.7, -14.6, 0); // m_cube.setPosition(8.5, 14, 0); // m_cube.setRotation(-172, glm::vec3{0.42, -0.2, 1}); diff --git a/source/hud/Hotbar.cpp b/source/hud/Hotbar.cpp index f7ee9464..f213d580 100644 --- a/source/hud/Hotbar.cpp +++ b/source/hud/Hotbar.cpp @@ -14,11 +14,10 @@ #include "Config.hpp" #include "Hotbar.hpp" -// FIXME -static const auto backgroundX = SCREEN_WIDTH / 2 - 182 * 3 / 2; -static const auto backgroundY = SCREEN_HEIGHT - 22 * 3; - Hotbar::Hotbar(Inventory &inventory) : m_inventory(inventory) { + setPosition(SCREEN_WIDTH / 2 - 182 * 3 / 2, SCREEN_HEIGHT - 22 * 3, 0); + setScale(3, 3, 1); + 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"); @@ -26,24 +25,15 @@ Hotbar::Hotbar(Inventory &inventory) : m_inventory(inventory) { m_background.load("texture-widgets"); m_background.setClipRect(0, 0, 182, 22); - m_background.setPosition(backgroundX, backgroundY, 0); - m_background.setScale(3, 3, 1); + m_background.setPosition(0, 0, 0); m_cursor.load("texture-widgets"); m_cursor.setClipRect(0, 22, 24, 24); - m_cursor.setPosition(backgroundX - 3, backgroundY - 3, 0); - m_cursor.setScale(3, 3, 1); + m_cursor.setPosition(-1, -1, 0); for (u16 i = 0 ; i < 9 ; ++i) { ItemWidget &widget = m_items.emplace_back(m_inventory, i, 0); - widget.setPosition(backgroundX + 16 + 180 / 3.0 * i - 9, backgroundY + 7, 0); - widget.setScale(3, 3, 1); - } -} - -void Hotbar::update() { - for (u16 i = 0 ; i < 9 ; ++i) { - m_items[i].setStack(m_inventory.getStack(i, 0).item().id(), m_inventory.getStack(i, 0).amount()); + widget.setPosition(5 + 20 * i - 3, 2, 0); } } @@ -54,11 +44,19 @@ void Hotbar::onEvent(const SDL_Event &event) { else if (event.wheel.y == 1) m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1; - m_cursor.setPosition(backgroundX - 3 + 20 * 3 * m_cursorPos, backgroundY - 3, 0); + m_cursor.setPosition(-1 + 20 * m_cursorPos, -1, 0); + } +} + +void Hotbar::update() { + for (u16 i = 0 ; i < 9 ; ++i) { + m_items[i].setStack(m_inventory.getStack(i, 0).item().id(), m_inventory.getStack(i, 0).amount()); } } void Hotbar::draw(RenderTarget &target, RenderStates states) const { + applyTransform(states); + states.shader = &m_shader; target.draw(m_background, states);