#include <Protocol/Protocol.hpp>
#include <Widget/Layout/Row/GuiControllerView/GuiControllerView.hpp>
#include <Entity/PhysicsEntity/CameraEntity/Player/Player.hpp>
#include <World/World.hpp>

GuiControllerView::GuiControllerView(std::shared_ptr<Player> player, Widget *widget, uint16_t stamp) :
    Row(
        Layout::WithProportion<1>(),
        widget
    ),
    player(player),
    stamp(stamp)
{}

GuiControllerView::~GuiControllerView()
{
    player->disconnectController();

    auto server = player->world->getPeerMessenger(*player);
    if (server != nullptr)
    {
        // We are a remote client; send a notification that we closed the GUI.
        server->sendSerial(Protocol::MessageType::GuiClosed, stamp);
    }
}