From 9378dbd6e33c174b2af1ff1488cb4d77fc7a1c82 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sat, 30 Jun 2018 04:17:08 +0200 Subject: [PATCH] [MouseItemWidget] Burn time info added on tooltip. --- include/gui/MouseItemWidget.hpp | 1 + include/gui/Text.hpp | 4 ++++ resources/config/blocks.xml | 3 +-- source/gui/MouseItemWidget.cpp | 14 ++++++++++++-- source/gui/Text.cpp | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/gui/MouseItemWidget.hpp b/include/gui/MouseItemWidget.hpp index aa2a85fe..b7bfdcbf 100644 --- a/include/gui/MouseItemWidget.hpp +++ b/include/gui/MouseItemWidget.hpp @@ -42,6 +42,7 @@ class MouseItemWidget : public ItemWidget { Sprite m_tooltipBackground{"texture-toasts", 160, 32}; Text m_tooltipText; + Text m_tooltipInfoText; }; #endif // MOUSEITEMWIDGET_HPP_ diff --git a/include/gui/Text.hpp b/include/gui/Text.hpp index 645c38c6..d383e432 100644 --- a/include/gui/Text.hpp +++ b/include/gui/Text.hpp @@ -25,6 +25,8 @@ class Text : public IDrawable, public Transformable { const std::string &text() const { return m_text; } void setText(const std::string &text) { m_text = text; updateTextSprites(); } + void setColor(const Color &color) { m_color = color; } + const Vector2i &getSize() const { return m_size; } private: @@ -42,6 +44,8 @@ class Text : public IDrawable, public Transformable { VertexBuffer m_vbo; Vector2i m_size; + + Color m_color = Color::white; }; #endif // TEXT_HPP_ diff --git a/resources/config/blocks.xml b/resources/config/blocks.xml index c7398e4a..1c7220c5 100644 --- a/resources/config/blocks.xml +++ b/resources/config/blocks.xml @@ -22,7 +22,7 @@ - + @@ -39,5 +39,4 @@ - diff --git a/source/gui/MouseItemWidget.cpp b/source/gui/MouseItemWidget.cpp index c2113563..793db596 100644 --- a/source/gui/MouseItemWidget.cpp +++ b/source/gui/MouseItemWidget.cpp @@ -14,9 +14,13 @@ #include "MouseItemWidget.hpp" MouseItemWidget::MouseItemWidget(Widget *parent) : ItemWidget(m_inventory, 0, 0, parent) { - m_tooltipBackground.setColor(Color{255, 255, 255, 220}); + m_tooltipBackground.setColor(Color{255, 255, 255, 240}); m_tooltipBackground.setPosition(20, 17, 0); - m_tooltipText.setPosition(27, 25, 0); + + m_tooltipText.setPosition(26, 24, 0); + + m_tooltipInfoText.setPosition(26, 35, 0); + m_tooltipInfoText.setColor({180, 180, 180}); } void MouseItemWidget::onEvent(const SDL_Event &event) { @@ -33,6 +37,11 @@ void MouseItemWidget::update(const ItemWidget *currentItemWidget) { if (currentItemWidget) { m_currentItemWidget = (currentItemWidget->stack().item().id()) ? currentItemWidget : nullptr; m_tooltipText.setText(currentItemWidget->stack().item().name() + " [" + std::to_string(currentItemWidget->stack().item().id()) + "]"); + + if (currentItemWidget->stack().item().isFuel()) + m_tooltipInfoText.setText("Burn time: " + std::to_string(currentItemWidget->stack().item().burnTime()) + " ticks"); + else + m_tooltipInfoText.setText(""); } else { m_currentItemWidget = nullptr; @@ -85,6 +94,7 @@ void MouseItemWidget::draw(RenderTarget &target, RenderStates states) const { if (m_currentItemWidget) { target.draw(m_tooltipBackground, states); target.draw(m_tooltipText, states); + target.draw(m_tooltipInfoText, states); } } diff --git a/source/gui/Text.cpp b/source/gui/Text.cpp index 683a2976..20f57353 100644 --- a/source/gui/Text.cpp +++ b/source/gui/Text.cpp @@ -42,7 +42,7 @@ void Text::updateTextSprites() { x += m_charWidth[(u8)c]; } x = 0; - color = Color::white; + color = m_color; for(char c : m_text) { Sprite sprite{"texture-font", 8, 8}; sprite.setCurrentFrame(c);