feat(ui): add ItemSlot widget and refactor hotbar to use it

This commit is contained in:
2026-07-21 16:42:22 +08:00
parent c1201294b6
commit c767a5711f
5 changed files with 98 additions and 11 deletions

View File

@@ -0,0 +1,29 @@
#pragma once
#include "Cubed/gameplay/block.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/widget.hpp"
namespace Cubed {
class TextureManager;
class ItemSlot : public Widget {
public:
static constexpr float DEFAULT_WIDTH = 16.0f;
static constexpr float DEFAULT_HEIGHT = 16.0f;
ItemSlot(Widget* parent);
ItemSlot& set_default_background(TextureManager& m_texture_manager);
ItemSlot& set_scale(float m_scale);
ItemSlot& set_item(BlockType id, const Texture* texture);
float width() const override;
float height() const override;
private:
static constexpr const char* DEFAULT_SLOT_PATH = "texture/ui/slot.png";
void on_render(Renderer& renderer) override;
void on_update(float dt) override;
std::unique_ptr<Image> m_background;
std::unique_ptr<Image> m_foreground;
BlockType m_block_type;
float m_scale = 1.0f;
};
} // namespace Cubed

View File

@@ -2,6 +2,7 @@
#include "Cubed/ui/chat_box.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/item_slot.hpp"
#include "Cubed/ui/row_layout.hpp"
#include "Cubed/ui/ui_manager.hpp"
#include "Cubed/ui/widget.hpp"
@@ -35,7 +36,6 @@ private:
Label* m_disbable_voice = nullptr;
RowLayout* m_hotbar = nullptr;
std::vector<Image*> m_hotbar_items;
std::vector<Image*> m_hotbar_slot;
std::vector<ItemSlot*> m_hotbar_slot;
};
} // namespace Cubed