mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[Refactor] Emit phase toolbar intent instead of protobuf commands (#7419)
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
095b135640
commit
73d5a2a0ab
5 changed files with 49 additions and 49 deletions
|
|
@ -29,11 +29,14 @@
|
||||||
#include <libcockatrice/protocol/get_pb_extension.h>
|
#include <libcockatrice/protocol/get_pb_extension.h>
|
||||||
#include <libcockatrice/protocol/pb/command_concede.pb.h>
|
#include <libcockatrice/protocol/pb/command_concede.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_delete_arrow.pb.h>
|
#include <libcockatrice/protocol/pb/command_delete_arrow.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_game_say.pb.h>
|
#include <libcockatrice/protocol/pb/command_game_say.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_leave_game.pb.h>
|
#include <libcockatrice/protocol/pb/command_leave_game.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_next_turn.pb.h>
|
#include <libcockatrice/protocol/pb/command_next_turn.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_reverse_turn.pb.h>
|
#include <libcockatrice/protocol/pb/command_reverse_turn.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_set_active_phase.pb.h>
|
#include <libcockatrice/protocol/pb/command_set_active_phase.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
|
||||||
|
#include <libcockatrice/protocol/pb/context_connection_state_changed.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/context_deck_select.pb.h>
|
#include <libcockatrice/protocol/pb/context_deck_select.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/event_game_closed.pb.h>
|
#include <libcockatrice/protocol/pb/event_game_closed.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/event_game_host_changed.pb.h>
|
#include <libcockatrice/protocol/pb/event_game_host_changed.pb.h>
|
||||||
|
|
@ -48,6 +51,7 @@
|
||||||
#include <libcockatrice/protocol/pb/event_set_active_player.pb.h>
|
#include <libcockatrice/protocol/pb/event_set_active_player.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/game_event_container.pb.h>
|
#include <libcockatrice/protocol/pb/game_event_container.pb.h>
|
||||||
#include <libcockatrice/protocol/pending_command.h>
|
#include <libcockatrice/protocol/pending_command.h>
|
||||||
|
#include <libcockatrice/utility/zone_names.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
@ -223,6 +227,24 @@ void GameEventHandler::handleActivePhaseChanged(int phase)
|
||||||
sendGameCommand(cmd);
|
sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameEventHandler::handleUntapAll()
|
||||||
|
{
|
||||||
|
Command_SetCardAttr cmd;
|
||||||
|
cmd.set_zone(ZoneNames::TABLE);
|
||||||
|
cmd.set_attribute(AttrTapped);
|
||||||
|
cmd.set_attr_value("0");
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameEventHandler::handleDrawCard()
|
||||||
|
{
|
||||||
|
Command_DrawCards cmd;
|
||||||
|
cmd.set_number(1);
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void GameEventHandler::handleGameLeft()
|
void GameEventHandler::handleGameLeft()
|
||||||
{
|
{
|
||||||
sendGameCommand(Command_LeaveGame());
|
sendGameCommand(Command_LeaveGame());
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void handleActivePhaseChanged(int phase);
|
void handleActivePhaseChanged(int phase);
|
||||||
|
|
||||||
|
/** @brief Request untapping every permanent on the table. */
|
||||||
|
void handleUntapAll();
|
||||||
|
|
||||||
|
/** @brief Request drawing a single card. */
|
||||||
|
void handleDrawCard();
|
||||||
|
|
||||||
/** @brief Leave the current game session. */
|
/** @brief Leave the current game session. */
|
||||||
void handleGameLeft();
|
void handleGameLeft();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,6 @@
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <google/protobuf/stubs/port.h>
|
#include <google/protobuf/stubs/port.h>
|
||||||
#include <libcockatrice/protocol/pb/command_draw_cards.pb.h>
|
|
||||||
#include <libcockatrice/protocol/pb/command_next_turn.pb.h>
|
|
||||||
#include <libcockatrice/protocol/pb/command_set_active_phase.pb.h>
|
|
||||||
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
|
|
||||||
#include <libcockatrice/utility/zone_names.h>
|
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <qnumeric.h>
|
#include <qnumeric.h>
|
||||||
|
|
||||||
|
|
@ -120,9 +115,9 @@ PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
||||||
: QGraphicsItem(parent), width(100), height(100), ySpacing(1), symbolSize(8)
|
: QGraphicsItem(parent), width(100), height(100), ySpacing(1), symbolSize(8)
|
||||||
{
|
{
|
||||||
auto *aUntapAll = new QAction(this);
|
auto *aUntapAll = new QAction(this);
|
||||||
connect(aUntapAll, &QAction::triggered, this, &PhasesToolbar::actUntapAll);
|
connect(aUntapAll, &QAction::triggered, this, &PhasesToolbar::untapAllRequested);
|
||||||
auto *aDrawCard = new QAction(this);
|
auto *aDrawCard = new QAction(this);
|
||||||
connect(aDrawCard, &QAction::triggered, this, &PhasesToolbar::actDrawCard);
|
connect(aDrawCard, &QAction::triggered, this, &PhasesToolbar::drawCardRequested);
|
||||||
|
|
||||||
PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll);
|
PhaseButton *untapButton = new PhaseButton("untap", this, aUntapAll);
|
||||||
PhaseButton *upkeepButton = new PhaseButton("upkeep", this);
|
PhaseButton *upkeepButton = new PhaseButton("upkeep", this);
|
||||||
|
|
@ -144,7 +139,7 @@ PhasesToolbar::PhasesToolbar(QGraphicsItem *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
nextTurnButton = new PhaseButton("nextturn", this, nullptr, false);
|
nextTurnButton = new PhaseButton("nextturn", this, nullptr, false);
|
||||||
connect(nextTurnButton, &PhaseButton::clicked, this, &PhasesToolbar::actNextTurn);
|
connect(nextTurnButton, &PhaseButton::clicked, this, &PhasesToolbar::nextTurnRequested);
|
||||||
|
|
||||||
rearrangeButtons();
|
rearrangeButtons();
|
||||||
|
|
||||||
|
|
@ -265,31 +260,5 @@ void PhasesToolbar::phaseButtonClicked()
|
||||||
button->triggerDoubleClickAction();
|
button->triggerDoubleClickAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_SetActivePhase cmd;
|
emit setActivePhaseRequested(buttonList.indexOf(button));
|
||||||
cmd.set_phase(static_cast<google::protobuf::uint32>(buttonList.indexOf(button)));
|
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhasesToolbar::actNextTurn()
|
|
||||||
{
|
|
||||||
emit sendGameCommand(Command_NextTurn(), -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhasesToolbar::actUntapAll()
|
|
||||||
{
|
|
||||||
Command_SetCardAttr cmd;
|
|
||||||
cmd.set_zone(ZoneNames::TABLE);
|
|
||||||
cmd.set_attribute(AttrTapped);
|
|
||||||
cmd.set_attr_value("0");
|
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhasesToolbar::actDrawCard()
|
|
||||||
{
|
|
||||||
Command_DrawCards cmd;
|
|
||||||
cmd.set_number(1);
|
|
||||||
|
|
||||||
emit sendGameCommand(cmd, -1);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,6 @@
|
||||||
class QAction;
|
class QAction;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
namespace google
|
|
||||||
{
|
|
||||||
namespace protobuf
|
|
||||||
{
|
|
||||||
class Message;
|
|
||||||
}
|
|
||||||
} // namespace google
|
|
||||||
|
|
||||||
class PhaseButton : public QObject, public QGraphicsItem
|
class PhaseButton : public QObject, public QGraphicsItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -95,11 +87,16 @@ public slots:
|
||||||
void triggerPhaseAction(int phase);
|
void triggerPhaseAction(int phase);
|
||||||
private slots:
|
private slots:
|
||||||
void phaseButtonClicked();
|
void phaseButtonClicked();
|
||||||
void actNextTurn();
|
|
||||||
void actUntapAll();
|
|
||||||
void actDrawCard();
|
|
||||||
signals:
|
signals:
|
||||||
void sendGameCommand(const ::google::protobuf::Message &command, int playerId);
|
/** @name Intent signals
|
||||||
|
* The view reports what the user asked for; GameEventHandler builds the commands.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
void setActivePhaseRequested(int phase);
|
||||||
|
void nextTurnRequested();
|
||||||
|
void untapAllRequested();
|
||||||
|
void drawCardRequested();
|
||||||
|
/** @} */
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) override;
|
||||||
|
|
|
||||||
|
|
@ -1276,8 +1276,14 @@ void TabGame::createPlayAreaWidget(bool bReplay)
|
||||||
{
|
{
|
||||||
phasesToolbar = new PhasesToolbar;
|
phasesToolbar = new PhasesToolbar;
|
||||||
if (!bReplay) {
|
if (!bReplay) {
|
||||||
connect(phasesToolbar, &PhasesToolbar::sendGameCommand, game->getGameEventHandler(),
|
connect(phasesToolbar, &PhasesToolbar::setActivePhaseRequested, game->getGameEventHandler(),
|
||||||
qOverload<const ::google::protobuf::Message &, int>(&GameEventHandler::sendGameCommand));
|
&GameEventHandler::handleActivePhaseChanged);
|
||||||
|
connect(phasesToolbar, &PhasesToolbar::nextTurnRequested, game->getGameEventHandler(),
|
||||||
|
&GameEventHandler::handleNextTurn);
|
||||||
|
connect(phasesToolbar, &PhasesToolbar::untapAllRequested, game->getGameEventHandler(),
|
||||||
|
&GameEventHandler::handleUntapAll);
|
||||||
|
connect(phasesToolbar, &PhasesToolbar::drawCardRequested, game->getGameEventHandler(),
|
||||||
|
&GameEventHandler::handleDrawCard);
|
||||||
}
|
}
|
||||||
scene = new GameScene(phasesToolbar, this);
|
scene = new GameScene(phasesToolbar, this);
|
||||||
connect(game->getPlayerManager(), &PlayerManager::playerConceded, scene, &GameScene::rearrange);
|
connect(game->getPlayerManager(), &PlayerManager::playerConceded, scene, &GameScene::rearrange);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue