mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(ui): add ItemSlot widget and refactor hotbar to use it
This commit is contained in:
29
include/Cubed/ui/item_slot.hpp
Normal file
29
include/Cubed/ui/item_slot.hpp
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user