Skip to content

Commit

Permalink
[ClientCommandHandler|LuaGUIState] Make sure only one GUI is active a…
Browse files Browse the repository at this point in the history
…t the same time.
  • Loading branch information
Unarelith committed Jul 8, 2020
1 parent 18d0fa8 commit 256700e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/client/network/ClientCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ void ClientCommandHandler::setupCallbacks() {
});

m_client.setCommandCallback(Network::Command::BlockGUIData, [this](Network::Packet &packet) {
gk::ApplicationStateStack::getInstance().push<LuaGUIState>(*this, m_player, m_world, packet, &gk::ApplicationStateStack::getInstance().top());
if (!LuaGUIState::isActive)
gk::ApplicationStateStack::getInstance().push<LuaGUIState>(*this, m_player, m_world, packet, &gk::ApplicationStateStack::getInstance().top());
});

m_client.setCommandCallback(Network::Command::BlockInvUpdate, [this](Network::Packet &packet) {
Expand Down
6 changes: 6 additions & 0 deletions source/client/states/LuaGUIState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "ScrollBarWidget.hpp"
#include "TextButton.hpp"

bool LuaGUIState::isActive = false;

LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, ClientWorld &world, sf::Packet &packet, gk::ApplicationState *parent)
: InterfaceState(parent), m_client(client), m_player(player), m_world(world)
{
Expand All @@ -62,6 +64,8 @@ LuaGUIState::LuaGUIState(ClientCommandHandler &client, ClientPlayer &player, Cli

while (!packet.endOfPacket())
loadGUI(packet);

isActive = true;
}

void LuaGUIState::onEvent(const SDL_Event &event) {
Expand All @@ -75,6 +79,8 @@ void LuaGUIState::onEvent(const SDL_Event &event) {
gk::Mouse::setCursorVisible(false);
gk::Mouse::resetToWindowCenter();

isActive = false;

m_stateStack->pop();
}

Expand Down
2 changes: 2 additions & 0 deletions source/client/states/LuaGUIState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class LuaGUIState : public InterfaceState {

void update() override;

static bool isActive;

private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;

Expand Down

0 comments on commit 256700e

Please sign in to comment.