2018-06-21 01:32:55 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
|
|
|
* Filename: ItemWidget.cpp
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Created: 21/06/2018 01:11:11
|
|
|
|
*
|
|
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#include "ItemWidget.hpp"
|
|
|
|
|
2018-06-23 03:26:34 +02:00
|
|
|
ItemWidget::ItemWidget(Inventory &inventory, u16 x, u16 y, Widget *parent)
|
|
|
|
: Widget(16, 16, parent), m_inventory(inventory), m_x(x), m_y(y)
|
|
|
|
{
|
2018-06-21 05:45:17 +02:00
|
|
|
m_image.load("texture-blocks");
|
2018-06-21 02:55:11 +02:00
|
|
|
m_image.setScale(2.0f / 3.0f, 2.0f / 3.0f, 1.0f);
|
2018-06-23 01:32:23 +02:00
|
|
|
m_image.setPosition(3, 3, 0);
|
2018-06-23 06:01:23 +02:00
|
|
|
m_image.setClipRect(0, 0, 0, 0);
|
2018-06-21 09:00:53 +02:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:34 +02:00
|
|
|
void ItemWidget::update() {
|
2018-06-23 03:50:02 +02:00
|
|
|
m_image.setClipRect(item() * 16, item() / 16 * 16, 16, 16);
|
2018-06-23 03:26:34 +02:00
|
|
|
}
|
2018-06-23 00:34:02 +02:00
|
|
|
|
2018-06-23 03:26:34 +02:00
|
|
|
void ItemWidget::setItem(unsigned int id) {
|
2018-06-24 01:42:06 +02:00
|
|
|
m_inventory.setStack(m_x, m_y, id);
|
2018-06-23 03:26:34 +02:00
|
|
|
update();
|
2018-06-21 01:32:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemWidget::draw(RenderTarget &target, RenderStates states) const {
|
2018-06-21 02:55:11 +02:00
|
|
|
applyTransform(states);
|
|
|
|
|
2018-06-21 06:56:33 +02:00
|
|
|
target.draw(m_image, states);
|
2018-06-21 01:32:55 +02:00
|
|
|
}
|
|
|
|
|