[MouseItemWidget] Burn time info added on tooltip.

This commit is contained in:
Quentin Bazin 2018-06-30 04:17:08 +02:00
parent 04d3aeaaa0
commit 9378dbd6e3
5 changed files with 19 additions and 5 deletions

View File

@ -42,6 +42,7 @@ class MouseItemWidget : public ItemWidget {
Sprite m_tooltipBackground{"texture-toasts", 160, 32};
Text m_tooltipText;
Text m_tooltipInfoText;
};
#endif // MOUSEITEMWIDGET_HPP_

View File

@ -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_

View File

@ -22,7 +22,7 @@
<block id="12" name="Glowstone" textureID="218" />
<block id="13" name="Workbench"/>
<block id="14" name="Furnace" />
<block id="15" name="Iron Ore" textureID="254" />
<block id="15" name="Iron Ore" textureID="254" hardness="3" harvestRequirements="1" />
<block id="16" name="Undefined" textureID="4" />
<block id="17" name="Undefined" textureID="4" />
<block id="18" name="Undefined" textureID="4" />
@ -39,5 +39,4 @@
<block id="29" name="Undefined" textureID="4" />
<block id="30" name="Undefined" textureID="4" />
<block id="31" name="Undefined" textureID="4" />
<block id="32" name="Undefined" textureID="4" />
</blocks>

View File

@ -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);
}
}

View File

@ -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);