~ubuntu-branches/ubuntu/trusty/qgo/trusty

« back to all changes in this revision

Viewing changes to src/game_interfaces/countdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Yann Dirson
  • Date: 2012-05-19 19:05:05 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120519190505-lf69o1jee5aaizd9
Tags: 2~svn764-1
* The "Raise dead" release (Closes: #673520), new maintainer.
* New upstream snapshot with Qt4 support (Closes: #604589), adjusted
  build-deps.
* Switched to source format "3.0 (quilt)", adjusted build-deps.
* Switched to dh and debhelper compat level 9, adjusted build-deps.
* Build with -fpermissive.
* New build-dep libasound2-dev, remove obsolete build-dep on libxinerama-dev.
* Refreshed patches 01_gnugo and 04_desktop, leaving 20_kfreebsd away
  for this release, and removing the remaining ones, now obsolete.
* Added patch 02_usrgames for FHS-correct install location.
* Adjusted icon names in menu file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by The qGo Project                                 *
 
3
 *                                                                         *
 
4
 *   This file is part of qGo.                                             *
 
5
 *                                                                         *
 
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.                                   *
 
10
 *                                                                         *
 
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.                          *
 
15
 *                                                                         *
 
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
 ***************************************************************************/
 
21
 
 
22
 
 
23
#include <QtGui>
 
24
#include "../network/messages.h"
 
25
#include "countdialog.h"
 
26
#include "board/boardwindow.h"
 
27
#include "../network/boarddispatch.h"
 
28
 
 
29
CountDialog::CountDialog(BoardWindow * parent, BoardDispatch * dis, unsigned int game_id) 
 
30
        : QDialog((QDialog *)parent), dispatch(dis), board(parent)
 
31
{
 
32
        oppAcceptsCount = 0;
 
33
        oppRejectsCount = 0;
 
34
        weAcceptCount = 0;
 
35
        weRejectCount = 0;
 
36
        
 
37
        acceptButton = new QPushButton(tr("&Accept"));
 
38
        //acceptButton->setDefault(true);
 
39
        rejectButton = new QPushButton(tr("&Reject"));
 
40
        
 
41
        if(!dispatch)
 
42
        {
 
43
                qDebug("CountDialog called without board dispatch");
 
44
                deleteLater();
 
45
                return;
 
46
        }
 
47
        result = new GameResult(board->getBoardHandler()->retrieveScore());
 
48
        GameData * gamedata = board->getGameData();
 
49
        if(result->winner_color == stoneWhite)
 
50
        {
 
51
                result->winner_name = gamedata->white_name;
 
52
                result->loser_name = gamedata->black_name;
 
53
        }
 
54
        else
 
55
        {
 
56
                result->winner_name = gamedata->black_name;
 
57
                result->loser_name = gamedata->white_name;
 
58
        }
 
59
        
 
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
 
65
         * FIXME */
 
66
        
 
67
        buttonBox = new QDialogButtonBox(Qt::Horizontal);
 
68
        buttonBox->addButton(acceptButton, QDialogButtonBox::ActionRole);
 
69
        buttonBox->addButton(rejectButton, QDialogButtonBox::ActionRole);
 
70
        
 
71
        connect(acceptButton, SIGNAL(clicked()), this, SLOT(slot_accept()));
 
72
        connect(rejectButton, SIGNAL(clicked()), this, SLOT(slot_reject()));
 
73
        
 
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);
 
79
 
 
80
        
 
81
        setWindowTitle(QString::number(game_id) + tr(": Accept result?"));
 
82
        //setSizePolicy(QSizePolicy::Minimum);
 
83
        // FIXME size?
 
84
        resize(200, 100);
 
85
        //setMinimumSize(QSize(300, 150));
 
86
        show();
 
87
}
 
88
 
 
89
CountDialog::~CountDialog()
 
90
{
 
91
        dispatch->clearCountDialog();
 
92
        delete acceptButton;
 
93
        delete rejectButton;
 
94
        delete mainlabel;
 
95
        delete buttonBox;
 
96
        delete result;
 
97
}
 
98
 
 
99
void CountDialog::recvRejectCount()
 
100
{
 
101
        oppRejectsCount = 1;
 
102
        if(weRejectCount || weAcceptCount)
 
103
        {
 
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
 
111
                 * FIXME */
 
112
                board->qgoboard->leaveScoreMode();
 
113
                deleteLater();
 
114
        }
 
115
}
 
116
 
 
117
void CountDialog::recvAcceptCount()
 
118
{
 
119
        oppAcceptsCount = 1;
 
120
        if(weRejectCount)
 
121
        {
 
122
                /* See above comment FIXME */
 
123
                board->qgoboard->leaveScoreMode();
 
124
                deleteLater();
 
125
        }
 
126
        else if(weAcceptCount)
 
127
        {
 
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);
 
133
                deleteLater();
 
134
        }
 
135
}
 
136
 
 
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
 
142
 * buttons */
 
143
void CountDialog::slot_accept(void)
 
144
{
 
145
        weAcceptCount = 1;
 
146
        dispatch->sendAcceptCount();    
 
147
        hide();
 
148
        if(oppRejectsCount)
 
149
        {
 
150
                /* See above comment FIXME */
 
151
                board->qgoboard->leaveScoreMode();
 
152
                deleteLater();
 
153
        }
 
154
        else if(oppAcceptsCount)
 
155
        {
 
156
                /* See above comment FIXME */
 
157
                dispatch->recvResult(result);
 
158
                dispatch->sendResult(result);
 
159
                //board->qgoboard->setResult(*result);
 
160
                deleteLater();
 
161
        }
 
162
}
 
163
 
 
164
void CountDialog::slot_reject(void)
 
165
{
 
166
        weRejectCount = 1;
 
167
        dispatch->sendRejectCount();    
 
168
        hide();
 
169
        if(oppRejectsCount || oppAcceptsCount)
 
170
        {
 
171
                /* See above comment FIXME */
 
172
                board->qgoboard->leaveScoreMode();
 
173
                deleteLater();
 
174
        }
 
175
}