diff options
| author | untodesu <kirill@untode.su> | 2025-09-12 14:09:34 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-09-12 14:09:34 +0500 |
| commit | 73cbcdd6e8c849e32abbf9757e603e6a6654e870 (patch) | |
| tree | 136e1aef82a25c31552b8990952a7607cfd4708e /game/client/gui | |
| parent | e9076f22fe2a49d1cd8933e54b7b00c5dd943269 (diff) | |
| download | voxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.tar.bz2 voxelius-73cbcdd6e8c849e32abbf9757e603e6a6654e870.zip | |
Metaitems
Diffstat (limited to 'game/client/gui')
| -rw-r--r-- | game/client/gui/hotbar.cc | 19 | ||||
| -rw-r--r-- | game/client/gui/hotbar.hh | 9 | ||||
| -rw-r--r-- | game/client/gui/status_lines.cc | 4 | ||||
| -rw-r--r-- | game/client/gui/status_lines.hh | 2 |
4 files changed, 18 insertions, 16 deletions
diff --git a/game/client/gui/hotbar.cc b/game/client/gui/hotbar.cc index 806d82b..e9458dd 100644 --- a/game/client/gui/hotbar.cc +++ b/game/client/gui/hotbar.cc @@ -25,7 +25,7 @@ constexpr static float SELECTOR_PADDING = 1.0f; constexpr static float HOTBAR_PADDING = 2.0f;
unsigned int gui::hotbar::active_slot = 0U;
-item_id gui::hotbar::slots[HOTBAR_SIZE];
+std::array<const world::Item*, HOTBAR_SIZE> gui::hotbar::slots = {};
static config::KeyBind hotbar_keys[HOTBAR_SIZE];
@@ -40,14 +40,13 @@ static ImU32 get_color_alpha(ImGuiCol style_color, float alpha) static void update_hotbar_item(void)
{
- if(gui::hotbar::slots[gui::hotbar::active_slot] == NULL_ITEM_ID) {
+ auto current_item = gui::hotbar::slots[gui::hotbar::active_slot];
+
+ if(current_item == nullptr) {
gui::status_lines::unset(gui::STATUS_HOTBAR);
- return;
}
-
- if(auto info = world::item_registry::find(gui::hotbar::slots[gui::hotbar::active_slot])) {
- gui::status_lines::set(gui::STATUS_HOTBAR, info->name, ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
- return;
+ else {
+ gui::status_lines::set(gui::STATUS_HOTBAR, current_item->get_name(), ImVec4(1.0f, 1.0f, 1.0f, 1.0f), 5.0f);
}
}
@@ -154,9 +153,9 @@ void gui::hotbar::layout(void) // Draw individual item textures in the hotbar
for(std::size_t i = 0; i < HOTBAR_SIZE; ++i) {
- const auto info = world::item_registry::find(gui::hotbar::slots[i]);
+ auto item = gui::hotbar::slots[i];
- if((info == nullptr) || (info->cached_texture == nullptr)) {
+ if((item == nullptr) || (item->get_cached_texture() == nullptr)) {
// There's either no item in the slot
// or the item doesn't have a texture
continue;
@@ -164,7 +163,7 @@ void gui::hotbar::layout(void) const auto item_start = ImVec2(background_start.x + i * item_size + item_padding_a, background_start.y + item_padding_a);
const auto item_end = ImVec2(item_start.x + item_size - item_padding_b, item_start.y + item_size - item_padding_b);
- draw_list->AddImage(info->cached_texture->handle, item_start, item_end);
+ draw_list->AddImage(item->get_cached_texture()->handle, item_start, item_end);
}
}
diff --git a/game/client/gui/hotbar.hh b/game/client/gui/hotbar.hh index 88ce791..223dbc9 100644 --- a/game/client/gui/hotbar.hh +++ b/game/client/gui/hotbar.hh @@ -1,16 +1,19 @@ #pragma once
-#include "shared/types.hh"
-
// TODO: design an inventory system and an item
// registry and integrate the hotbar into that system
+namespace world
+{
+class Item;
+} // namespace world
+
constexpr static unsigned int HOTBAR_SIZE = 9U;
namespace gui::hotbar
{
extern unsigned int active_slot;
-extern item_id slots[HOTBAR_SIZE];
+extern std::array<const world::Item*, HOTBAR_SIZE> slots;
} // namespace gui::hotbar
namespace gui::hotbar
diff --git a/game/client/gui/status_lines.cc b/game/client/gui/status_lines.cc index d1a919a..c146478 100644 --- a/game/client/gui/status_lines.cc +++ b/game/client/gui/status_lines.cc @@ -65,11 +65,11 @@ void gui::status_lines::layout(void) }
}
-void gui::status_lines::set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout)
+void gui::status_lines::set(unsigned int line, std::string_view text, const ImVec4& color, float fadeout)
{
line_text_colors[line] = ImVec4(color.x, color.y, color.z, color.w);
line_shadow_colors[line] = ImVec4(color.x * 0.1f, color.y * 0.1f, color.z * 0.1f, color.w);
- line_strings[line] = std::string(text);
+ line_strings[line] = text;
line_spawns[line] = globals::curtime;
line_fadeouts[line] = fadeout;
}
diff --git a/game/client/gui/status_lines.hh b/game/client/gui/status_lines.hh index 7245d68..f694fd3 100644 --- a/game/client/gui/status_lines.hh +++ b/game/client/gui/status_lines.hh @@ -16,6 +16,6 @@ void layout(void); namespace gui::status_lines
{
-void set(unsigned int line, const std::string& text, const ImVec4& color, float fadeout);
+void set(unsigned int line, std::string_view text, const ImVec4& color, float fadeout);
void unset(unsigned int line);
} // namespace gui::status_lines
|
