2018-06-21 01:32:55 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2018-06-21 01:32:55 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* 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.
|
2018-06-21 01:32:55 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 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.
|
2018-06-21 01:32:55 +02:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2018-06-21 01:32:55 +02:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
|
|
|
#ifndef INVENTORYWIDGET_HPP_
|
|
|
|
#define INVENTORYWIDGET_HPP_
|
|
|
|
|
2019-01-05 18:37:59 +01:00
|
|
|
#include <gk/graphics/RectangleShape.hpp>
|
2018-12-29 02:23:23 +01:00
|
|
|
|
2018-06-23 01:32:23 +02:00
|
|
|
#include "MouseItemWidget.hpp"
|
2018-06-21 01:32:55 +02:00
|
|
|
|
2019-04-08 12:59:02 +02:00
|
|
|
class ClientCommandHandler;
|
2019-01-26 20:29:13 +01:00
|
|
|
|
2018-06-21 09:00:53 +02:00
|
|
|
class InventoryWidget : public Widget {
|
2018-06-21 01:32:55 +02:00
|
|
|
public:
|
2019-04-08 12:59:02 +02:00
|
|
|
InventoryWidget(ClientCommandHandler &client, Widget *parent = nullptr)
|
2019-01-26 20:29:13 +01:00
|
|
|
: Widget(parent), m_client(client) {}
|
2018-06-21 09:00:53 +02:00
|
|
|
|
2018-06-29 08:56:59 +02:00
|
|
|
void init(Inventory &inventory, unsigned int offset = 0, unsigned int size = 0);
|
2018-06-21 09:00:53 +02:00
|
|
|
|
2018-12-28 06:19:40 +01:00
|
|
|
void onMouseEvent(const SDL_Event &event, MouseItemWidget &mouseItemWidget, bool isReadOnly = false);
|
2018-06-21 01:32:55 +02:00
|
|
|
|
2020-02-23 22:38:51 +09:00
|
|
|
void update() override;
|
|
|
|
|
2018-06-25 22:30:38 +02:00
|
|
|
const ItemWidget *currentItemWidget() const { return m_currentItemWidget; }
|
|
|
|
|
2018-06-21 01:32:55 +02:00
|
|
|
private:
|
2018-12-29 02:23:23 +01:00
|
|
|
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
|
2018-06-21 01:32:55 +02:00
|
|
|
|
2019-04-07 16:23:48 +02:00
|
|
|
void sendUpdatePacket();
|
|
|
|
|
2019-04-08 12:59:02 +02:00
|
|
|
ClientCommandHandler &m_client;
|
2019-01-26 20:29:13 +01:00
|
|
|
|
|
|
|
Inventory *m_inventory = nullptr;
|
|
|
|
|
2018-06-21 12:55:31 +02:00
|
|
|
u16 m_inventoryWidth = 0;
|
|
|
|
u16 m_inventoryHeight = 0;
|
|
|
|
|
2018-06-21 01:32:55 +02:00
|
|
|
std::vector<ItemWidget> m_itemWidgets;
|
2018-06-25 22:30:38 +02:00
|
|
|
ItemWidget *m_currentItemWidget = nullptr;
|
2018-12-29 02:23:23 +01:00
|
|
|
|
|
|
|
gk::RectangleShape m_selectedItemBackground{16, 16, gk::Color{255, 255, 255, 80}};
|
2018-06-21 01:32:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INVENTORYWIDGET_HPP_
|