1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqtooltip.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqhbox.h>
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
#include "player.h"
#include "playerbox.h"
#include "defines.h"
#include "kpaint.h"
PlayerBox::PlayerBox(bool playerOne, TQWidget* parent, const char* name)
: TQGroupBox(parent, name)
{
TQHBoxLayout* l = new TQHBoxLayout(this, PLAYERBOX_BORDERS,
PLAYERBOX_HDISTANCEOFWIDGETS);
// The card and "held" label arrays.
m_cardWidgets = new CardWidget *[PokerHandSize];
m_heldLabels = new TQLabel *[PokerHandSize];
TQFont myFixedFont;
myFixedFont.setPointSize(12);
// Generate the 5 cards
for (int i = 0; i < PokerHandSize; i++) {
TQVBoxLayout* vl = new TQVBoxLayout(0);
l->addLayout(vl, 0);
TQHBox* cardBox = new TQHBox(this);
vl->addWidget(cardBox, 0);
cardBox->setFrameStyle(Box | Sunken);
m_cardWidgets[i] = new CardWidget(cardBox);
cardBox->setFixedSize(cardBox->sizeHint());
// Only add the "held" labels if this is the first player (the human one).
if (playerOne) {
TQHBox* b = new TQHBox(this);
m_heldLabels[i] = new TQLabel(b);
m_heldLabels[i]->setText(i18n("Held"));
b->setFrameStyle(Box | Sunken);
b->setFixedSize(b->sizeHint());
m_cardWidgets[i]->heldLabel = m_heldLabels[i];
TQHBoxLayout* heldLayout = new TQHBoxLayout(0);
heldLayout->addWidget(b, 0, AlignCenter);
vl->insertLayout(0, heldLayout, 0);
vl->insertStretch(0, 1);
vl->addStretch(1);
}
}
// Add the cash and bet labels.
{
TQVBoxLayout* vl = new TQVBoxLayout;
l->addLayout(vl);
vl->addStretch();
m_cashLabel = new TQLabel(this);
m_cashLabel->setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
m_cashLabel->setFont(myFixedFont);
vl->addWidget(m_cashLabel, 0, AlignHCenter);
vl->addStretch();
m_betLabel = new TQLabel(this);
m_betLabel->setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
m_betLabel->setFont(myFixedFont);
vl->addWidget(m_betLabel, 0, AlignHCenter);
vl->addStretch();
}
TQToolTip::add(m_cashLabel,
i18n("Money of %1").arg("Player"));//change via showName()
// Assume that we have a multiplayer game.
m_singlePlayer = false;
}
PlayerBox::~PlayerBox()
{
delete[] m_cardWidgets;
delete[] m_heldLabels;
}
// ----------------------------------------------------------------
void PlayerBox::resizeEvent(TQResizeEvent* e)
{
TQGroupBox::resizeEvent(e);
showCash();
showName();
}
void PlayerBox::showCash()
{
// Show the amount of cash the player has.
m_cashLabel->setText(i18n("Cash: %1")
.arg(KGlobal::locale()->formatMoney(m_player->getCash())));
// Show how much we have bet during this round.
if (m_player->out())
m_betLabel->setText(i18n("Out"));
else {
if (m_singlePlayer)
m_betLabel->setText(i18n("Cash per round: %1")
.arg(KGlobal::locale()->formatMoney(m_cashPerRound)));
else
m_betLabel->setText(i18n("Bet: %1")
.arg(KGlobal::locale()-> formatMoney(m_player->getCurrentBet())));
}
}
// Sshow the name of the player. Suppose that the players name has
// changed.
void PlayerBox::showName()
{
setTitle(m_player->getName());
TQToolTip::remove(m_cashLabel);
TQToolTip::add(m_cashLabel, i18n("Money of %1").arg(m_player->getName()));
}
// Show or unshow all the held labels depending on the 'on' parameter.
void PlayerBox::showHelds(bool on)
{
for (int i = 0; i < PokerHandSize; i++) {
if (on)
m_cardWidgets[i]->heldLabel->show();
else {
m_cardWidgets[i]->heldLabel->hide();
m_cardWidgets[i]->setHeld(on);
}
}
}
void PlayerBox::paintCard(int nr)
{
m_cardWidgets[nr]->paintCard(m_player->getCard(nr));
m_cardWidgets[nr]->show();
}
// Activate the held labels for this player (human player).
void PlayerBox::activateToggleHeld()
{
for (int i = 0; i < PokerHandSize; i++) {
connect(m_cardWidgets[i], TQT_SIGNAL(pClicked(CardWidget*)),
this, TQT_SLOT(cardClicked(CardWidget*)));
}
}
void PlayerBox::cardClicked(CardWidget* MyCW)
{
emit toggleHeld();
if (m_enableHeldLabels && MyCW->toggleHeld())
MyCW->heldLabel->show();
else
MyCW->heldLabel->hide();
}
void PlayerBox::paintDeck(int nr)
{
m_player->giveCardBack(nr);
paintCard(nr);
}
void PlayerBox::blinkOn()
{
for (int i = 0; i < PokerHandSize; i++) {
if (m_player->getFoundCard(i))
hideCard(i);
}
}
void PlayerBox::blinkOff()
{
for (int i = 0; i < PokerHandSize; i++) {
if (!m_cardWidgets[i]->isVisible())
paintCard(i);
}
}
void PlayerBox::setHeldEnabled(bool on)
{
m_enableHeldLabels = on;
if (!on) {
for (int i = 0; i < PokerHandSize; i++)
m_heldLabels[i]->hide();
}
}
void PlayerBox::singlePlayerGame(int newCashPerRound)
{
m_singlePlayer = true;
m_cashPerRound = newCashPerRound;
}
void PlayerBox::hideCard(int nr)
{
m_cardWidgets[nr]->hide();
}
bool PlayerBox::getHeld(int nr) const
{
return m_cardWidgets[nr]->getHeld();
}
void PlayerBox::cardClicked(int no)
{
cardClicked(m_cardWidgets[no-1]);
}
void PlayerBox::repaintCard()
{
for (int i = 0; i < PokerHandSize; i++)
m_cardWidgets[i]->repaintDeck();
}
#include "playerbox.moc"
|