diff --git a/game/public_game.cpp b/game/public_game.cpp index b5d0d38..b83a186 100644 --- a/game/public_game.cpp +++ b/game/public_game.cpp @@ -261,6 +261,12 @@ vector PublicGame::toppingGetTriedMoves() const return getTypedGame(m_game).getTriedMoves(); } + +Move PublicGame::toppingGetTopMove() const +{ + return getTypedGame(m_game).getTopMove(); +} + /***************************/ void PublicGame::duplicateSetPlayer(unsigned int p) diff --git a/game/public_game.h b/game/public_game.h index 6e27617..70b91d6 100644 --- a/game/public_game.h +++ b/game/public_game.h @@ -222,6 +222,8 @@ public: vector toppingGetTriedMoves() const; + Move toppingGetTopMove() const; + /*************** * Duplicate games * These methods throw an exception if the current game is not in diff --git a/game/topping.cpp b/game/topping.cpp index b005737..236bf55 100644 --- a/game/topping.cpp +++ b/game/topping.cpp @@ -171,17 +171,19 @@ void Topping::addPlayer(Player *iPlayer) } -int Topping::getTopScore() const +Move Topping::getTopMove() const { BestResults results; results.search(getDic(), getBoard(), m_players[0]->getCurrentRack().getRack(), getHistory().beforeFirstRound()); - if (results.size() == 0) - { - // Just to be safe - return -1; - } - return results.get(0).getPoints(); + ASSERT(results.size() != 0, "No top move found"); + return Move(results.get(0)); +} + + +int Topping::getTopScore() const +{ + return getTopMove().getScore(); } diff --git a/game/topping.h b/game/topping.h index 66ba8a5..d1cd06b 100644 --- a/game/topping.h +++ b/game/topping.h @@ -72,6 +72,11 @@ public: */ vector getTriedMoves() const; + /** + * Return the best possible move (or one of them, if there are several ones). + */ + Move getTopMove() const; + private: /// Private constructor and destructor to force using the GameFactory class Topping(const GameParams &iParams, const Game *iMasterGame); @@ -86,7 +91,6 @@ private: /** * Return the score of the top move. - * If no move is possible at all, return -1. */ int getTopScore() const; diff --git a/qt/topping_widget.cpp b/qt/topping_widget.cpp index 2802517..e53bca1 100644 --- a/qt/topping_widget.cpp +++ b/qt/topping_widget.cpp @@ -24,12 +24,14 @@ #include #include "topping_widget.h" -#include "qtcommon.h" #include "play_word_mediator.h" +#include "hints_dialog.h" +#include "qtcommon.h" -#include "player.h" +#include "hints.h" #include "dic.h" #include "move.h" +#include "pldrack.h" #include "public_game.h" #include "game_exception.h" #include "debug.h" @@ -44,7 +46,10 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame : QWidget(parent), m_game(iGame), m_autoResizeColumns(true) { setupUi(this); - tableViewMoves->setAlternatingRowColors(true); + + m_hintsDialog = new HintsDialog(this); + QObject::connect(m_hintsDialog, SIGNAL(hintUsed(const AbstractHint&)), + this, SLOT(hintUsed(const AbstractHint&))); blackPalette = lineEditRack->palette(); redPalette = lineEditRack->palette(); @@ -90,6 +95,9 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame tableViewMoves->horizontalHeader()->resizeSection(1, 140); + QObject::connect(pushButtonGetHints, SIGNAL(clicked()), + this, SLOT(showHintsDialog())); + refresh(); } @@ -105,7 +113,7 @@ void ToppingWidget::refresh() } else { - wstring rack = m_game->getPlayer(0).getCurrentRack().toString(PlayedRack::RACK_SIMPLE); + wstring rack = m_game->getCurrentRack().toString(PlayedRack::RACK_SIMPLE); // Update the rack only if it is needed, to avoid losing cursor position if (qfw(rack) != lineEditRack->text()) lineEditRack->setText(qfw(rack)); @@ -164,6 +172,22 @@ void ToppingWidget::lockSizesChanged(bool checked) } +void ToppingWidget::showHintsDialog() +{ + const Move &move = m_game->toppingGetTopMove(); + m_hintsDialog->setMove(move); + // We don't care about the return value + m_hintsDialog->exec(); +} + + +void ToppingWidget::hintUsed(const AbstractHint &iHint) +{ + // TODO + LOG_INFO("Hint " << iHint.getName() << " used for a cost of " << iHint.getCost()); +} + + QSize ToppingWidget::sizeHint() const { return QSize(160, 300); diff --git a/qt/topping_widget.h b/qt/topping_widget.h index 4c5a6c1..1d36e4f 100644 --- a/qt/topping_widget.h +++ b/qt/topping_widget.h @@ -28,10 +28,11 @@ class QStandardItemModel; class QString; -class QPoint; class PlayModel; class PlayWordMediator; class PublicGame; +class HintsDialog; +class AbstractHint; class ToppingWidget: public QWidget, private Ui::ToppingWidget { @@ -56,6 +57,8 @@ protected: private slots: void lockSizesChanged(bool checked); + void showHintsDialog(); + void hintUsed(const AbstractHint&); private: /// Encapsulated training game, can be NULL @@ -70,6 +73,9 @@ private: /// Mediator for the "play word" controls PlayWordMediator *m_mediator; + /// Dialog used to display hints + HintsDialog *m_hintsDialog; + /// Palette to write text in black QPalette blackPalette; diff --git a/qt/ui/topping_widget.ui b/qt/ui/topping_widget.ui index f7fa101..8492d99 100644 --- a/qt/ui/topping_widget.ui +++ b/qt/ui/topping_widget.ui @@ -7,7 +7,7 @@ 0 0 560 - 123 + 150 @@ -68,6 +68,19 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -92,19 +105,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -124,6 +124,13 @@ + + + + _("Get hints...") + + +