Skip to content

Commit

Permalink
[FurnaceWidget] Removed. Now completely implemented in Lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Feb 23, 2020
1 parent 4eb3e37 commit 879dc28
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 233 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TODO

• DONE: Implement `PlayerInventoryWidget` completely in Lua
• DONE: Implement `PlayerCraftingWidget` completely in Lua
WIP: Implement `FurnaceWidget` completely in Lua
DONE: Implement `FurnaceWidget` completely in Lua
◦ DONE: Add a `ProgressBarWidget`

# Menus
Expand Down
61 changes: 0 additions & 61 deletions client/include/gui/FurnaceWidget.hpp

This file was deleted.

2 changes: 2 additions & 0 deletions client/include/gui/InventoryWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class InventoryWidget : public Widget {

void onMouseEvent(const SDL_Event &event, MouseItemWidget &mouseItemWidget, bool isReadOnly = false);

void update() override;

const ItemWidget *currentItemWidget() const { return m_currentItemWidget; }

private:
Expand Down
12 changes: 6 additions & 6 deletions client/include/gui/ProgressBarWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
#include "BlockData.hpp"
#include "Widget.hpp"

enum class ProgressBarType {
ItemProcess,
BurnProcess
enum class ProgressBarType : u8 {
ItemProcess = 0,
BurnProcess = 1
};

class ProgressBarWidget : public Widget {
public:
ProgressBarWidget(const std::string &texture, BlockData &blockData, ProgressBarType type, Widget *parent = nullptr);

void init(const gk::IntRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue);
void init(const gk::IntRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue);
void init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta);

void update() override;

Expand All @@ -47,7 +47,7 @@ class ProgressBarWidget : public Widget {

BlockData &m_blockData;

gk::IntRect m_clipRect;
gk::FloatRect m_clipRect;
gk::Vector2i m_position;

std::string m_meta;
Expand Down
96 changes: 0 additions & 96 deletions client/source/gui/FurnaceWidget.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions client/source/gui/InventoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ void InventoryWidget::onMouseEvent(const SDL_Event &event, MouseItemWidget &mous
}
}

void InventoryWidget::update() {
for (auto &it : m_itemWidgets)
it.update();
}

void InventoryWidget::sendUpdatePacket() {
if (m_inventory->inBlock()) {
m_client.sendBlockInvUpdate(*m_inventory);
Expand Down
4 changes: 2 additions & 2 deletions client/source/gui/ProgressBarWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ProgressBarWidget::ProgressBarWidget(const std::string &texture, BlockData &bloc
m_type = type;
}

void ProgressBarWidget::init(const gk::IntRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue) {
void ProgressBarWidget::init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, unsigned int maxMetaValue) {
m_clipRect = clipRect;
m_position = position;

Expand All @@ -39,7 +39,7 @@ void ProgressBarWidget::init(const gk::IntRect &clipRect, const gk::Vector2i &po
m_maxMetaValue = maxMetaValue;
}

void ProgressBarWidget::init(const gk::IntRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta) {
void ProgressBarWidget::init(const gk::FloatRect &clipRect, const gk::Vector2i &position, const std::string &meta, const std::string &maxMeta) {
m_clipRect = clipRect;
m_position = position;

Expand Down
79 changes: 58 additions & 21 deletions client/source/states/LuaGUIState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include "ClientPlayer.hpp"
#include "ClientWorld.hpp"
#include "Config.hpp"
#include "FurnaceWidget.hpp"
#include "InventoryWidget.hpp"
#include "LuaGUIState.hpp"
#include "LuaWidget.hpp"
#include "Network.hpp"
#include "Player.hpp"
#include "ProgressBarWidget.hpp"
#include "TextButton.hpp"

LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, ClientWorld &world, sf::Packet &packet, gk::ApplicationState *parent)
Expand Down Expand Up @@ -85,6 +85,10 @@ void LuaGUIState::update() {
it.update();
}

for (auto &it : m_inventoryWidgets) {
it.update();
}

const ItemWidget *currentItemWidget = nullptr;
for (auto &it : m_inventoryWidgets) {
if (!currentItemWidget)
Expand Down Expand Up @@ -149,18 +153,64 @@ void LuaGUIState::loadGUI(ClientPlayer &player, ClientWorld &world, sf::Packet &
m_widgets.emplace_back(button);
}
else if (type == LuaWidget::InventoryWidget) {
std::string playerName, inventory;
std::string inventory, playerName, inventory_name;
gk::Vector3i block;
float width, height;
u16 offset, count;
packet >> playerName >> inventory >> width >> height >> offset >> count;
packet >> inventory >> playerName >> inventory_name
>> block.x >> block.y >> block.z
>> width >> height >> offset >> count;

Inventory *widgetInventory = nullptr;
if (inventory == "player") {
widgetInventory = &player.inventory();
}
else if (inventory == "block") {
BlockData *data = world.getBlockData(block.x, block.y, block.z);
if (!data) {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
return;
}

widgetInventory = &data->inventory;
}

if (widgetInventory) {
m_inventoryWidgets.emplace_back(m_client, &m_mainWidget);

auto &inventoryWidget = m_inventoryWidgets.back();
inventoryWidget.setPosition(x, y);
inventoryWidget.init(*widgetInventory, offset, count);
}
else {
DEBUG("ERROR: Widget inventory is invalid");
}
}
else if (type == LuaWidget::ProgressBarWidget) {
u8 type;
gk::Vector3i block;
std::string meta, maxMeta;
u32 maxValue;
std::string texture;
gk::FloatRect clipRect;
packet >> type >> block.x >> block.y >> block.z >> meta >> maxMeta >> maxValue >> texture
>> clipRect.x >> clipRect.y >> clipRect.sizeX >> clipRect.sizeY;

m_inventoryWidgets.emplace_back(m_client, &m_mainWidget);
BlockData *data = world.getBlockData(block.x, block.y, block.z);
if (!data) {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
return;
}

auto &inventoryWidget = m_inventoryWidgets.back();
inventoryWidget.setPosition(x, y);
inventoryWidget.init(player.inventory(), offset, count);
ProgressBarWidget *widget = new ProgressBarWidget(texture, *data, ProgressBarType(type));
if (!maxMeta.empty())
widget->init(clipRect, gk::Vector2i{x, y}, meta, maxMeta);
else
widget->init(clipRect, gk::Vector2i{x, y}, meta, maxValue);

m_widgets.emplace_back(widget);
}
else if (type == LuaWidget::CraftingWidget) {
else if (type == LuaWidget::CraftingWidget) { // FIXME
std::string inventory;
gk::Vector3i block;
u16 offset, size;
Expand Down Expand Up @@ -194,18 +244,5 @@ void LuaGUIState::loadGUI(ClientPlayer &player, ClientWorld &world, sf::Packet &
DEBUG("ERROR: Crafting inventory is invalid");
}
}
else if (type == LuaWidget::FurnaceWidget) {
gk::Vector3i block;
packet >> block.x >> block.y >> block.z;
BlockData *data = world.getBlockData(block.x, block.y, block.z);
if (data) {
auto *furnaceWidget = new FurnaceWidget(m_client, m_mouseItemWidget, player.inventory(), *data, &m_mainWidget);
furnaceWidget->setPosition(x, y);
m_widgets.emplace_back(furnaceWidget);
}
else {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
}
}
}

10 changes: 5 additions & 5 deletions common/include/core/LuaWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

namespace LuaWidget {
enum : u8 {
Image = 0,
TextButton = 1,
InventoryWidget = 2,
CraftingWidget = 3,
FurnaceWidget = 4,
Image = 0,
TextButton = 1,
InventoryWidget = 2,
CraftingWidget = 3,
ProgressBarWidget = 4,
};
}

Expand Down
Loading

0 comments on commit 879dc28

Please sign in to comment.