#include "client/window/hud_window.hh" namespace client { namespace window { using hw = class hud_window; bool hw::maybe_handle_keydown(const SDL_Event& event) noexcept { const auto& sym = event.key.keysym.sym; const auto index = static_cast(sym); const auto min = static_cast(SDLK_0); const auto max = static_cast(SDLK_9); if (index < min || index > max) { return false; } const auto active = static_cast((((sym - min) - 1) + 10) % 10); client::get_localplayer().get_mutable_active_item() = active; return true; } bool hw::maybe_handle_event(const SDL_Event& event) noexcept { if (is_open()) { return false; } switch (event.type) { case SDL_KEYDOWN: return this->maybe_handle_keydown(event); default: break; } return false; } void hw::draw() noexcept { this->basic_window::draw(); const float item_size = this->get_item_size(); const auto& localplayer = client::get_localplayer(); client::render::draw_rectangle( {.pos = {.offset = {this->pos.x + static_cast( localplayer.get_active_item()) * item_size, this->pos.y}}, .size = {.offset = {item_size, item_size}}, .colour = {this->secondary_clr, 1.0f}}); for (int i = 1; i < shared::player::INVENTORY_COLS; ++i) { const float off = item_size * static_cast(i); client::render::draw_rectangle( {.pos = {.offset = {this->pos.x + off, this->pos.y + OUTLINE_WIDTH}}, .size = {.offset = {OUTLINE_WIDTH, item_size - 2.0f * OUTLINE_WIDTH}}, .colour = {this->tertiary_clr, 1.0f}}); } const auto& inventory = localplayer.inventory; for (int x = 0; x < shared::player::INVENTORY_COLS; ++x) { const auto& item = inventory.contents[static_cast(x)]; if (item == nullptr) { continue; } const glm::vec2 off{glm::vec2{x, 0} * item_size}; const auto item_ptr = dynamic_cast(&*item); if (item_ptr == nullptr) { continue; } item_ptr->draw(this->pos + off, glm::vec2{item_size, item_size}); client::render::draw_text( std::to_string(item->quantity), {.pos = {.offset = this->pos + off + glm::vec2{item_size * 0.75f, item_size * 0.2f}}, .offset_height = item_size * 0.40f, .colour = {this->font_colour, 1.0f}, .has_backing = false, .is_centered = true, .is_vcentered = true}); } } } // namespace window } // namespace client