void HudItemDesc::onDraw(Renderer2D &out) const { HudLayer::onDraw(out); FRect rect = this->rect(); if(!m_item.isDummy()) { float ypos = topOffset() + rect.y(); FRect uv_rect; auto texture = m_item.guiImage(false, uv_rect); float2 size(texture->width() * uv_rect.width(), texture->height() * uv_rect.height()); float2 pos = (float2)(int2)(float2(rect.center().x - size.x * 0.5f, ypos)); out.addFilledRect(FRect(pos, pos + size), uv_rect, {texture, mulAlpha(ColorId::white, alpha())}); ypos += size.y + 10.0f; FRect desc_rect(rect.x() + 5.0f, ypos, rect.ex() - 5.0f, rect.ey() - 5.0f); // TODO: fix drawing of text that does not fit string params_desc; if(m_item.type() == ItemType::weapon) params_desc = Weapon(m_item).paramDesc(); else if(m_item.type() == ItemType::ammo) params_desc = Ammo(m_item).paramDesc(); else if(m_item.type() == ItemType::armour) params_desc = Armour(m_item).paramDesc(); m_font->draw(out, float2(rect.x() + 5.0f, ypos), {titleColor(), titleShadowColor()}, params_desc); } }
HudTargetInfo::HudTargetInfo(const FRect &target_rect) :HudLayer(target_rect), m_hit_chance(0.0f), m_health(1.0f), m_kills(0), m_deaths(0) { m_anim_speed = 10.0f; FRect rect = this->rect(); FRect icon_rect(s_char_icon_size); icon_rect += float2(rect.width() - icon_rect.width() - layer_spacing, rect.center().y - icon_rect.height() * 0.5f); m_char_icon = make_shared<HudCharIcon>(icon_rect); m_char_icon->setEnabled(true, false); attach(m_char_icon); }
void HudItemButton::onDraw(Renderer2D &out) const { HudButton::onDraw(out); FRect rect = this->rect(); if(!m_entry.item.isDummy()) { FRect uv_rect; auto texture = m_entry.item.guiImage(true, uv_rect); float2 size(texture->width() * uv_rect.width(), texture->height() * uv_rect.height()); float2 pos = (float2)(int2)(rect.center() - size / 2); out.addFilledRect(FRect(pos, pos + size), texture); if(m_entry.count > 1) m_font->draw(out, rect, {textColor(), textShadowColor(), HAlign::right}, format("%", m_entry.count)); if(isDropping()) m_font->draw(out, rect, {textColor(true), textShadowColor(), HAlign::left, VAlign::bottom}, format("-%", dropCount())); } }
void HudWeapon::onDraw(Renderer2D &out) const { HudButton::onDraw(out); FRect rect = this->rect(); if(!m_weapon.isDummy()) { FRect uv_rect; auto texture = m_weapon.guiImage(false, uv_rect); float2 size(texture->width() * uv_rect.width(), texture->height() * uv_rect.height()); float2 pos = (int2)(rect.center() - size / 2); out.addFilledRect(FRect(pos, pos + size), uv_rect, {texture, Color::white}); //TODO: print current attack mode if(m_weapon.proto().max_ammo) { TextFormatter fmt; fmt("%d/%d", m_ammo_count, m_weapon.proto().max_ammo); //TODO: alpha for shadow color m_font->draw(out, rect, {m_style.enabled_color, Color::black, HAlign::right, VAlign::top}, fmt); } } }
EmissionSource::EmissionSource(FRect rect) : pos(rect.center()), param(rect.size() * 0.5f), type(Type::rect) {}