[Hotbar] Small improvements. [ItemWidget] Cube size increased. [game.v.glsl] Small fix on leaves movement.
This commit is contained in:
parent
ea9053ac8b
commit
8843c8f346
@ -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_
|
||||
|
@ -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(); }
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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});
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user