fixed GoEngine number parameter conversion issue, SetupScreen now correctly sets fixed handicap
svn path=/trunk/playground/games/kgo/; revision=837492
This commit is contained in:
parent
e9deb2e0ec
commit
a759e21208
9 changed files with 49 additions and 40 deletions
|
@ -143,7 +143,7 @@ bool GoEngine::loadSgf(const QString &fileName, int moveNumber)
|
|||
msg.append("loadsgf ");
|
||||
msg.append(fileName.toLatin1());
|
||||
msg.append(" ");
|
||||
msg.append(moveNumber);
|
||||
msg.append(QString::number(moveNumber));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
if (waitResponse()) {
|
||||
|
@ -207,7 +207,7 @@ bool GoEngine::setBoardSize(int size)
|
|||
|
||||
QByteArray msg;
|
||||
msg.append("boardsize ");
|
||||
msg.append(size);
|
||||
msg.append(QString::number(size));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
if (waitResponse()) {
|
||||
|
@ -230,6 +230,8 @@ int GoEngine::boardSize()
|
|||
|
||||
bool GoEngine::clearBoard()
|
||||
{
|
||||
kDebug() << "Clear board";
|
||||
|
||||
QByteArray msg;
|
||||
msg.append("clear_board\n");
|
||||
m_process.write(msg);
|
||||
|
@ -243,10 +245,11 @@ bool GoEngine::clearBoard()
|
|||
bool GoEngine::setKomi(float komi)
|
||||
{
|
||||
Q_ASSERT(komi >= 0);
|
||||
kDebug() << "Set komi:" << komi;
|
||||
|
||||
QByteArray msg;
|
||||
msg.append("komi ");
|
||||
msg.append(komi);
|
||||
msg.append(QString::number(komi));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
return waitResponse();
|
||||
|
@ -255,10 +258,11 @@ bool GoEngine::setKomi(float komi)
|
|||
bool GoEngine::setLevel(int level)
|
||||
{
|
||||
Q_ASSERT(level >= 1 && level <= 10);
|
||||
kDebug() << "Set level:" << level;
|
||||
|
||||
QByteArray msg;
|
||||
msg.append("level ");
|
||||
msg.append(level);
|
||||
msg.append(QString::number(level));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
return waitResponse();
|
||||
|
@ -267,10 +271,11 @@ bool GoEngine::setLevel(int level)
|
|||
bool GoEngine::setFixedHandicap(int handicap)
|
||||
{
|
||||
Q_ASSERT(handicap >= 0 && handicap <= 9);
|
||||
kDebug() << "Set handicap:" << handicap;
|
||||
|
||||
QByteArray msg;
|
||||
msg.append("fixed_handicap ");
|
||||
msg.append(handicap);
|
||||
msg.append(QString::number(handicap));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
if (waitResponse()) {
|
||||
|
@ -345,7 +350,7 @@ bool GoEngine::undoMove(int i)
|
|||
Q_ASSERT(i >= 0);
|
||||
QByteArray msg;
|
||||
msg.append("undo ");
|
||||
msg.append(i);
|
||||
msg.append(QString::number(i));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
if (waitResponse()) {
|
||||
|
@ -916,7 +921,7 @@ bool GoEngine::tuneMoveOrdering(int parameters)
|
|||
{
|
||||
QByteArray msg;
|
||||
msg.append("tune_move_ordering ");
|
||||
msg.append(parameters);
|
||||
msg.append(QString::number(parameters));
|
||||
msg.append("\n");
|
||||
m_process.write(msg);
|
||||
return waitResponse();
|
||||
|
|
|
@ -52,9 +52,9 @@ void GameScene::resizeScene(int width, int height)
|
|||
int size = qMin(width, height);
|
||||
m_boardRect.setRect(width / 2 - size / 2, height / 2 - size / 2, size, size);
|
||||
|
||||
size = static_cast<int>(size * 0.9);
|
||||
m_boardGridRect.setRect(width / 2 - size / 2, height / 2 - size / 2, size, size);
|
||||
m_boardGridSize = m_boardGridRect.width() / m_engine->boardSize();
|
||||
size = static_cast<int>(size * 0.9);
|
||||
m_boardGridRect.setRect(width / 2 - size / 2, height / 2 - size / 2, size, size);
|
||||
m_boardGridSize = m_boardGridRect.width() / m_engine->boardSize();
|
||||
}
|
||||
|
||||
GoEngine * const GameScene::engine() const
|
||||
|
@ -71,19 +71,19 @@ void GameScene::updateBoard()
|
|||
|
||||
void GameScene::showMoveHistory(bool show)
|
||||
{
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
void GameScene::showLabels(bool show)
|
||||
{
|
||||
kDebug() << "Show:" << show;
|
||||
m_showLabels = show;
|
||||
update();
|
||||
kDebug() << "Show:" << show;
|
||||
m_showLabels = show;
|
||||
update();
|
||||
}
|
||||
|
||||
void GameScene::hint()
|
||||
{
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
void GameScene::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
|
@ -91,27 +91,27 @@ void GameScene::drawBackground(QPainter *painter, const QRectF &rect)
|
|||
ThemeRenderer::instance()->renderElement(ThemeRenderer::SceneBackground, painter, sceneRect());
|
||||
ThemeRenderer::instance()->renderElement(ThemeRenderer::BoardBackground, painter, m_boardRect);
|
||||
|
||||
//FIXME: Rentrancy problem with m_engine->waitProcess, use this for now:
|
||||
//FIXME: Rentrancy problem with m_engine->waitProcess, use this for now:
|
||||
for (int i = 0; i < 19/*m_engine->boardSize()*/; i++) {
|
||||
painter->save();
|
||||
painter->save();
|
||||
|
||||
QPen linePen(painter->pen());
|
||||
linePen.setWidth(static_cast<int>(m_boardGridSize / 10));
|
||||
linePen.setColor(QColor(60, 70, 60, 200));
|
||||
QPen linePen(painter->pen());
|
||||
linePen.setWidth(static_cast<int>(m_boardGridSize / 10));
|
||||
linePen.setColor(QColor(60, 70, 60, 200));
|
||||
|
||||
painter->setPen(linePen);
|
||||
painter->setPen(linePen);
|
||||
painter->drawLine(QPointF(m_boardGridRect.left(), m_boardGridRect.top() + i * m_boardGridSize),
|
||||
QPointF(m_boardGridRect.right(), m_boardGridRect.top() + i * m_boardGridSize));
|
||||
painter->drawLine(QPointF(m_boardGridRect.left() + i * m_boardGridSize, m_boardGridRect.top()),
|
||||
QPointF(m_boardGridRect.left() + i * m_boardGridSize, m_boardGridRect.bottom()));
|
||||
|
||||
painter->restore();
|
||||
painter->restore();
|
||||
|
||||
if (m_showLabels) {
|
||||
//
|
||||
//TODO: Render board label
|
||||
painter->drawText(50, 50, "Showing labels");
|
||||
}
|
||||
if (m_showLabels) {
|
||||
//
|
||||
//TODO: Render board label
|
||||
painter->drawText(50, 50, "Showing labels");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public:
|
|||
public slots:
|
||||
void updateBoard();
|
||||
void showMoveHistory(bool show);
|
||||
void showLabels(bool show);
|
||||
void showLabels(bool show);
|
||||
void hint();
|
||||
|
||||
private:
|
||||
|
@ -82,7 +82,7 @@ private:
|
|||
GoEngine * const m_engine; ///< To interface with the go engine
|
||||
bool m_showLabels; ///< Show board labels or not
|
||||
QRectF m_boardRect; ///< Position of board in the scene
|
||||
QRectF m_boardGridRect; ///<
|
||||
QRectF m_boardGridRect; ///<
|
||||
qreal m_boardGridSize; ///<
|
||||
QList<QGraphicsPixmapItem *> m_stoneItemList; ///<
|
||||
};
|
||||
|
|
|
@ -38,12 +38,11 @@ namespace KGo {
|
|||
|
||||
GameScreen::GameScreen(GameScene *scene, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_gameScene(scene)
|
||||
, m_gameEngine(scene->engine())
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
GameView *gameView = new GameView(m_gameScene, this);
|
||||
GameView *gameView = new GameView(scene, this);
|
||||
gameView->setInteractive(true);
|
||||
gameFrame->setLayout(new QHBoxLayout());
|
||||
gameFrame->layout()->addWidget(gameView);
|
||||
|
|
|
@ -72,7 +72,6 @@ public slots:
|
|||
//void setGameStatisticsVisible(bool visible);
|
||||
|
||||
private:
|
||||
GameScene * const m_gameScene; ///<
|
||||
GoEngine * const m_gameEngine; ///<
|
||||
};
|
||||
|
||||
|
|
|
@ -149,14 +149,14 @@ void MainWindow::showPreferences()
|
|||
dialog->addPage(new GeneralConfig(), i18n("General"), "preferences-other");
|
||||
dialog->addPage(new KGameThemeSelector(dialog, Preferences::self()), i18n("Themes"), "games-config-theme");
|
||||
dialog->setHelp(QString(),"KGo");
|
||||
connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(updatePreferences()));
|
||||
connect(dialog, SIGNAL(settingsChanged(const QString &)), this, SLOT(updatePreferences()));
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void MainWindow::updatePreferences()
|
||||
{
|
||||
kDebug() <<"Update settings based on changed configuration";
|
||||
m_gameScene->showLabels(Preferences::showBoardLabels());
|
||||
kDebug() <<"Update settings based on changed configuration";
|
||||
m_gameScene->showLabels(Preferences::showBoardLabels());
|
||||
}
|
||||
|
||||
} // End of namespace KGo
|
||||
|
|
|
@ -67,7 +67,7 @@ private slots:
|
|||
void redo(); ///<
|
||||
void toggleDemoMode(); ///<
|
||||
void showPreferences(); ///< Show settings dialog
|
||||
void updatePreferences();
|
||||
void updatePreferences();
|
||||
|
||||
private:
|
||||
void setupActions();
|
||||
|
|
|
@ -38,12 +38,11 @@ namespace KGo {
|
|||
|
||||
SetupScreen::SetupScreen(GameScene *scene, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_gameScene(scene)
|
||||
, m_gameEngine(scene->engine())
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
GameView *gameView = new GameView(m_gameScene, this);
|
||||
GameView *gameView = new GameView(scene, this);
|
||||
gameView->setInteractive(false); // This is just a preview, not a real game
|
||||
previewFrame->setLayout(new QHBoxLayout());
|
||||
previewFrame->layout()->addWidget(gameView);
|
||||
|
@ -142,9 +141,16 @@ void SetupScreen::on_sizeGroupBox_changed(int /*id*/)
|
|||
sizeOtherSpinBox->setEnabled(false);
|
||||
}
|
||||
|
||||
void SetupScreen::on_handicapSpinBox_valueChanged(int value)
|
||||
{
|
||||
kDebug() << "Set to value:" << value;
|
||||
m_gameEngine->clearBoard();
|
||||
m_gameEngine->setFixedHandicap(value);
|
||||
}
|
||||
|
||||
void SetupScreen::on_startButton_clicked()
|
||||
{
|
||||
saveSettings();
|
||||
saveSettings(); // Save current game configuration
|
||||
if (newGameBox->isVisible()) { // Means we configured a new game
|
||||
m_gameEngine->setBoardSize(Preferences::boardSize());
|
||||
m_gameEngine->setLevel(Preferences::difficulty());
|
||||
|
|
|
@ -92,13 +92,13 @@ private slots:
|
|||
void on_blackPlayerCombo_currentIndexChanged(const QString &);
|
||||
void on_startMoveSpinBox_valueChanged(int);
|
||||
void on_sizeGroupBox_changed(int);
|
||||
void on_handicapSpinBox_valueChanged(int);
|
||||
void on_startButton_clicked();
|
||||
|
||||
void loadSettings(); ///< Load KConfigXT application settings
|
||||
void saveSettings(); ///< Store KConfigXT application settings
|
||||
|
||||
private:
|
||||
GameScene * const m_gameScene; ///<
|
||||
GoEngine * const m_gameEngine; ///<
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue