1
/***************************************************************************
2
* Copyright (C) 2009 by The qGo Project *
4
* This file is part of qGo. *
6
* qGo is free software: you can redistribute it and/or modify *
7
* it under the terms of the GNU General Public License as published by *
8
* the Free Software Foundation; either version 2 of the License, or *
9
* (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU General Public License *
17
* along with this program; if not, see <http://www.gnu.org/licenses/> *
18
* or write to the Free Software Foundation, Inc., *
19
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20
***************************************************************************/
24
#include "../network/messages.h"
25
#include "countdialog.h"
26
#include "board/boardwindow.h"
27
#include "../network/boarddispatch.h"
29
CountDialog::CountDialog(BoardWindow * parent, BoardDispatch * dis, unsigned int game_id)
30
: QDialog((QDialog *)parent), dispatch(dis), board(parent)
37
acceptButton = new QPushButton(tr("&Accept"));
38
//acceptButton->setDefault(true);
39
rejectButton = new QPushButton(tr("&Reject"));
43
qDebug("CountDialog called without board dispatch");
47
result = new GameResult(board->getBoardHandler()->retrieveScore());
48
GameData * gamedata = board->getGameData();
49
if(result->winner_color == stoneWhite)
51
result->winner_name = gamedata->white_name;
52
result->loser_name = gamedata->black_name;
56
result->winner_name = gamedata->black_name;
57
result->loser_name = gamedata->white_name;
60
mainlabel = new QLabel(result->longMessage() +
61
"\nWhite has " + QString::number(gamedata->white_prisoners)
62
+ " captures\nBlack has " +
63
QString::number(gamedata->black_prisoners) + " captures");
64
/* These needs to also post black and white captures and ultimate score
67
buttonBox = new QDialogButtonBox(Qt::Horizontal);
68
buttonBox->addButton(acceptButton, QDialogButtonBox::ActionRole);
69
buttonBox->addButton(rejectButton, QDialogButtonBox::ActionRole);
71
connect(acceptButton, SIGNAL(clicked()), this, SLOT(slot_accept()));
72
connect(rejectButton, SIGNAL(clicked()), this, SLOT(slot_reject()));
74
QGridLayout * mainLayout = new QGridLayout;
75
/*mainLayout->setSizeConstraint(QLayout::SetFixedSize);*/
76
mainLayout->addWidget(mainlabel, 0, 0);
77
mainLayout->addWidget(buttonBox, 1, 0);
78
setLayout(mainLayout);
81
setWindowTitle(QString::number(game_id) + tr(": Accept result?"));
82
//setSizePolicy(QSizePolicy::Minimum);
85
//setMinimumSize(QSize(300, 150));
89
CountDialog::~CountDialog()
91
dispatch->clearCountDialog();
99
void CountDialog::recvRejectCount()
102
if(weRejectCount || weAcceptCount)
104
/* Regardless of what happens, I think
105
* we have to restart the game, get back into it
106
* this may require sending clear stone messages
107
* or some other messsage and it definitely
108
* requires leaving score mode and starting
109
* any timers that may have stopped in addition
110
* to possibly deleting "pass" moves from the tree
112
board->qgoboard->leaveScoreMode();
117
void CountDialog::recvAcceptCount()
122
/* See above comment FIXME */
123
board->qgoboard->leaveScoreMode();
126
else if(weAcceptCount)
128
/* This means we notify network connection
129
* to send any necessary game result messages FIXME */
130
dispatch->recvResult(result);
131
dispatch->sendResult(result);
132
//board->qgoboard->setResult(*result);
137
/* We're not going to delete the countdialog immediately
138
* but instead let it keep track of things... I don't
139
* really know why... I guess because this is a dialog
140
* for counting and its light so why not have it do
141
* something besides displaying info and a couple
143
void CountDialog::slot_accept(void)
146
dispatch->sendAcceptCount();
150
/* See above comment FIXME */
151
board->qgoboard->leaveScoreMode();
154
else if(oppAcceptsCount)
156
/* See above comment FIXME */
157
dispatch->recvResult(result);
158
dispatch->sendResult(result);
159
//board->qgoboard->setResult(*result);
164
void CountDialog::slot_reject(void)
167
dispatch->sendRejectCount();
169
if(oppRejectsCount || oppAcceptsCount)
171
/* See above comment FIXME */
172
board->qgoboard->leaveScoreMode();