OpenMiner/client/include/gui/ItemWidget.hpp

63 lines
1.8 KiB
C++
Raw Normal View History

/*
* =====================================================================================
*
* OpenMiner
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* =====================================================================================
*/
#ifndef ITEMWIDGET_HPP_
#define ITEMWIDGET_HPP_
2019-01-05 18:37:59 +01:00
#include <gk/graphics/Image.hpp>
2018-12-29 02:23:23 +01:00
#include "Inventory.hpp"
2020-02-10 14:16:24 +09:00
#include "InventoryCube.hpp"
#include "Text.hpp"
#include "Widget.hpp"
class ItemWidget : public Widget {
public:
ItemWidget(Inventory &inventory, u16 x, u16 y, Widget *parent = nullptr);
void update() override;
2020-02-19 20:08:46 +09:00
void updateImage(const Block *block = nullptr);
const ItemStack &stack() const { return m_inventory.getStack(m_x, m_y); }
void setStack(const std::string &name, unsigned int amount = 1);
protected:
2018-12-29 02:23:23 +01:00
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
private:
Inventory &m_inventory;
unsigned int m_x = 0;
unsigned int m_y = 0;
TextureAtlas &m_textureAtlas;
2018-12-29 02:23:23 +01:00
gk::Image m_image;
Text m_text;
2020-02-10 14:16:24 +09:00
InventoryCube m_cube{10};
2020-01-30 16:03:49 +09:00
bool m_isImage = false;
};
#endif // ITEMWIDGET_HPP_