Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
29699418
Commit
29699418
authored
Sep 25, 2009
by
Max-Wilhelm Bruker
Browse files
removed some unneeded code, counter appearance changed
parent
a543c9b9
Changes
20
Hide whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
29699418
...
...
@@ -13,14 +13,12 @@ HEADERS += src/counter.h \
src
/
gamesmodel
.
h
\
src
/
client
.
h
\
src
/
window_main
.
h
\
src
/
zonelist
.
h
\
src
/
cardzone
.
h
\
src
/
player
.
h
\
src
/
cardlist
.
h
\
src
/
carditem
.
h
\
src
/
tablezone
.
h
\
src
/
handzone
.
h
\
src
/
playerlist
.
h
\
src
/
game
.
h
\
src
/
carddatabase
.
h
\
src
/
gameview
.
h
\
...
...
@@ -53,12 +51,10 @@ SOURCES += src/counter.cpp \
src
/
gamesmodel
.
cpp
\
src
/
player
.
cpp
\
src
/
cardzone
.
cpp
\
src
/
zonelist
.
cpp
\
src
/
cardlist
.
cpp
\
src
/
carditem
.
cpp
\
src
/
tablezone
.
cpp
\
src
/
handzone
.
cpp
\
src
/
playerlist
.
cpp
\
src
/
game
.
cpp
\
src
/
carddatabase
.
cpp
\
src
/
gameview
.
cpp
\
...
...
cockatrice/src/carditem.cpp
View file @
29699418
...
...
@@ -245,10 +245,11 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
if
(
!
zone
->
getPlayer
()
->
getLocal
())
return
;
if
(
zone
->
getName
()
==
"table"
)
((
TableZone
*
)
zone
)
->
toggleTapped
();
TableZone
*
tz
=
qobject_cast
<
TableZone
*>
(
zone
);
if
(
tz
)
tz
->
toggleTapped
();
else
{
TableZone
*
table
=
(
TableZone
*
)
zone
->
getPlayer
()
->
get
Zones
().
findZone
(
"t
able
"
);
TableZone
*
table
=
zone
->
getPlayer
()
->
get
T
able
(
);
QPoint
gridPoint
=
table
->
getFreeGridPoint
(
info
->
getTableRow
());
table
->
handleDropEventByGrid
(
id
,
zone
,
gridPoint
,
false
);
}
...
...
cockatrice/src/cardzone.cpp
View file @
29699418
...
...
@@ -132,13 +132,12 @@ void CardZone::setCardAttr(int cardId, const QString &aname, const QString &aval
player
->
client
->
setCardAttr
(
name
,
cardId
,
aname
,
avalue
);
}
void
CardZone
::
setView
(
ZoneViewZone
*
_view
)
void
CardZone
::
moveAllToZone
(
)
{
view
=
_view
;
}
QList
<
QVariant
>
data
=
static_cast
<
QAction
*>
(
sender
())
->
data
().
toList
();
QString
targetZone
=
data
[
0
].
toString
();
int
targetX
=
data
[
1
].
toInt
();
void
CardZone
::
moveAllToZone
(
const
QString
&
targetZone
,
int
targetX
)
{
// Cards need to be moved in reverse order so that the other
// cards' list index doesn't change
for
(
int
i
=
cards
.
size
()
-
1
;
i
>=
0
;
i
--
)
...
...
cockatrice/src/cardzone.h
View file @
29699418
...
...
@@ -29,6 +29,8 @@ protected:
virtual
void
addCardImpl
(
CardItem
*
card
,
int
x
,
int
y
)
=
0
;
signals:
void
contentsChanged
();
public
slots
:
void
moveAllToZone
();
public:
enum
{
Type
=
typeZone
};
int
type
()
const
{
return
Type
;
}
...
...
@@ -52,9 +54,8 @@ public:
virtual
CardItem
*
takeCard
(
int
position
,
int
cardId
,
const
QString
&
cardName
,
bool
canResize
=
true
);
void
setCardAttr
(
int
cardId
,
const
QString
&
aname
,
const
QString
&
avalue
);
ZoneViewZone
*
getView
()
const
{
return
view
;
}
void
setView
(
ZoneViewZone
*
_view
)
;
void
setView
(
ZoneViewZone
*
_view
)
{
view
=
_view
;
}
virtual
void
reorganizeCards
()
=
0
;
void
moveAllToZone
(
const
QString
&
targetZone
,
int
targetX
);
virtual
QPointF
closestGridPoint
(
const
QPointF
&
point
);
};
...
...
cockatrice/src/client.cpp
View file @
29699418
...
...
@@ -314,14 +314,14 @@ void Client::readLine()
emit
protocolError
();
}
}
else
if
(
prefix
==
"list_counters"
)
{
if
(
values
.
size
()
!=
5
)
{
if
(
values
.
size
()
!=
6
)
{
emit
protocolError
();
continue
;
}
int
cmdid
=
values
.
takeFirst
().
toInt
();
PendingCommand
*
pc
=
pendingCommands
.
value
(
cmdid
,
0
);
int
colorValue
=
values
[
2
].
toInt
();
ServerCounter
sc
(
values
[
0
].
toInt
(),
values
[
1
],
QColor
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
),
values
[
3
].
toInt
());
int
colorValue
=
values
[
3
].
toInt
();
ServerCounter
sc
(
values
[
0
].
toInt
(),
values
[
1
]
.
toInt
(),
values
[
2
]
,
QColor
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
),
values
[
4
].
toInt
(),
values
[
5
].
toInt
());
PendingCommand_ListCounters
*
pcLC
=
qobject_cast
<
PendingCommand_ListCounters
*>
(
pc
);
if
(
pcLC
)
...
...
@@ -508,24 +508,24 @@ PendingCommand *Client::readyStart()
return
cmd
(
"ready_start"
);
}
PendingCommand
*
Client
::
incCounter
(
const
QString
&
counter
,
int
delta
)
PendingCommand
*
Client
::
incCounter
(
int
counter
Id
,
int
delta
)
{
return
cmd
(
QString
(
"inc_counter|%1|%2"
).
arg
(
counter
).
arg
(
delta
));
return
cmd
(
QString
(
"inc_counter|%1|%2"
).
arg
(
counter
Id
).
arg
(
delta
));
}
PendingCommand
*
Client
::
addCounter
(
const
QString
&
counter
,
QColor
color
,
int
value
)
PendingCommand
*
Client
::
addCounter
(
const
QString
&
counter
Name
,
QColor
color
,
int
radius
,
int
value
)
{
return
cmd
(
QString
(
"add_counter|%1|%2|%3"
).
arg
(
counter
).
arg
(
color
.
red
()
*
65536
+
color
.
green
()
*
256
+
color
.
blue
()).
arg
(
value
));
return
cmd
(
QString
(
"add_counter|%1|%2|%3
|%4
"
).
arg
(
counter
Name
).
arg
(
color
.
red
()
*
65536
+
color
.
green
()
*
256
+
color
.
blue
()).
arg
(
radius
).
arg
(
value
));
}
PendingCommand
*
Client
::
setCounter
(
const
QString
&
counter
,
int
value
)
PendingCommand
*
Client
::
setCounter
(
int
counter
Id
,
int
value
)
{
return
cmd
(
QString
(
"set_counter|%1|%2"
).
arg
(
counter
).
arg
(
value
));
return
cmd
(
QString
(
"set_counter|%1|%2"
).
arg
(
counter
Id
).
arg
(
value
));
}
PendingCommand
*
Client
::
delCounter
(
const
QString
&
counter
)
PendingCommand
*
Client
::
delCounter
(
int
counter
Id
)
{
return
cmd
(
QString
(
"del_counter|%1"
).
arg
(
counter
));
return
cmd
(
QString
(
"del_counter|%1"
).
arg
(
counter
Id
));
}
PendingCommand_ListCounters
*
Client
::
listCounters
(
int
playerId
)
...
...
cockatrice/src/client.h
View file @
29699418
...
...
@@ -173,15 +173,19 @@ public:
class
ServerCounter
{
private:
int
playerId
;
int
id
;
QString
name
;
QColor
color
;
int
radius
;
int
count
;
public:
ServerCounter
(
int
_playerId
,
const
QString
&
_name
,
QColor
_color
,
int
_count
)
:
playerId
(
_playerId
),
name
(
_name
),
color
(
_color
),
count
(
_count
)
{
}
ServerCounter
(
int
_playerId
,
int
_id
,
const
QString
&
_name
,
QColor
_color
,
int
_radius
,
int
_count
)
:
playerId
(
_playerId
),
id
(
_id
),
name
(
_name
),
color
(
_color
),
radius
(
_radius
),
count
(
_count
)
{
}
int
getPlayerId
()
const
{
return
playerId
;
}
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
QColor
getColor
()
const
{
return
color
;
}
int
getRadius
()
const
{
return
radius
;
}
int
getCount
()
const
{
return
count
;
}
};
...
...
@@ -355,10 +359,10 @@ public slots:
PendingCommand
*
createToken
(
const
QString
&
zone
,
const
QString
&
name
,
const
QString
&
powtough
,
int
x
,
int
y
);
PendingCommand
*
setCardAttr
(
const
QString
&
zone
,
int
cardid
,
const
QString
&
aname
,
const
QString
&
avalue
);
PendingCommand
*
readyStart
();
PendingCommand
*
incCounter
(
const
QString
&
counter
,
int
delta
);
PendingCommand
*
addCounter
(
const
QString
&
counter
,
QColor
color
,
int
value
);
PendingCommand
*
setCounter
(
const
QString
&
counter
,
int
value
);
PendingCommand
*
delCounter
(
const
QString
&
counter
);
PendingCommand
*
incCounter
(
int
counter
Id
,
int
delta
);
PendingCommand
*
addCounter
(
const
QString
&
counter
Name
,
QColor
color
,
int
radius
,
int
value
);
PendingCommand
*
setCounter
(
int
counter
Id
,
int
value
);
PendingCommand
*
delCounter
(
int
counter
Id
);
PendingCommand_ListCounters
*
listCounters
(
int
playerId
);
PendingCommand
*
nextTurn
();
PendingCommand
*
setActivePhase
(
int
phase
);
...
...
cockatrice/src/counter.cpp
View file @
29699418
...
...
@@ -3,14 +3,16 @@
#include
"client.h"
#include
<QtGui>
Counter
::
Counter
(
Player
*
_player
,
const
QString
&
_name
,
QColor
_color
,
int
_value
,
QGraphicsItem
*
parent
)
:
QGraphicsItem
(
parent
),
name
(
_name
),
color
(
_color
),
value
(
_value
),
player
(
_player
)
Counter
::
Counter
(
Player
*
_player
,
int
_id
,
const
QString
&
_name
,
QColor
_color
,
int
_radius
,
int
_value
,
QGraphicsItem
*
parent
)
:
QGraphicsItem
(
parent
),
id
(
_id
),
name
(
_name
),
color
(
_color
),
radius
(
_radius
),
value
(
_value
),
player
(
_player
)
{
if
(
radius
>
Player
::
counterAreaWidth
/
2
)
radius
=
Player
::
counterAreaWidth
/
2
;
}
QRectF
Counter
::
boundingRect
()
const
{
return
QRectF
(
0
,
0
,
40
,
40
);
return
QRectF
(
0
,
0
,
radius
*
2
,
radius
*
2
);
}
void
Counter
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
...
...
@@ -18,8 +20,8 @@ void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*
painter
->
setBrush
(
QBrush
(
color
));
painter
->
drawEllipse
(
boundingRect
());
if
(
value
)
{
QFont
f
(
"
Times
"
);
f
.
setPixelSize
(
20
);
QFont
f
(
"
Serif
"
);
f
.
setPixelSize
(
radius
*
0.8
);
f
.
setWeight
(
QFont
::
Bold
);
painter
->
setFont
(
f
);
painter
->
drawText
(
boundingRect
(),
Qt
::
AlignCenter
,
QString
::
number
(
value
));
...
...
@@ -35,7 +37,7 @@ void Counter::setValue(int _value)
void
Counter
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
(
event
->
button
()
==
Qt
::
LeftButton
)
player
->
client
->
incCounter
(
name
,
1
);
player
->
client
->
incCounter
(
id
,
1
);
else
if
(
event
->
button
()
==
Qt
::
RightButton
)
player
->
client
->
incCounter
(
name
,
-
1
);
player
->
client
->
incCounter
(
id
,
-
1
);
}
cockatrice/src/counter.h
View file @
29699418
...
...
@@ -7,17 +7,20 @@ class Player;
class
Counter
:
public
QGraphicsItem
{
private:
int
id
;
QString
name
;
QColor
color
;
int
radius
;
int
value
;
protected:
Player
*
player
;
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
public:
Counter
(
Player
*
_player
,
const
QString
&
_name
,
QColor
_color
,
int
_value
,
QGraphicsItem
*
parent
=
0
);
Counter
(
Player
*
_player
,
int
_id
,
const
QString
&
_name
,
QColor
_color
,
int
_radius
,
int
_value
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
int
getValue
()
const
{
return
value
;
}
void
setValue
(
int
_value
);
...
...
cockatrice/src/game.cpp
View file @
29699418
...
...
@@ -11,6 +11,7 @@
#include
"dlg_startgame.h"
#include
"counter.h"
#include
"gamescene.h"
#include
"player.h"
Game
::
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
GameScene
*
_scene
,
QMenuBar
*
menuBar
,
QObject
*
parent
)
:
QObject
(
parent
),
db
(
_db
),
client
(
_client
),
scene
(
_scene
),
started
(
false
),
currentPhase
(
-
1
)
...
...
@@ -83,10 +84,14 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menu
Game
::~
Game
()
{
qDebug
(
"Game destructor"
);
for
(
int
i
=
0
;
i
<
players
.
size
();
i
++
)
{
emit
playerRemoved
(
players
.
at
(
i
));
delete
players
.
at
(
i
);
QMapIterator
<
int
,
Player
*>
i
(
players
);
while
(
i
.
hasNext
())
{
i
.
next
();
emit
playerRemoved
(
i
.
value
());
delete
i
.
value
();
}
delete
gameMenu
;
delete
cardMenu
;
}
...
...
@@ -115,8 +120,9 @@ void Game::retranslateUi()
moveMenu
->
setTitle
(
tr
(
"&Move to"
));
for
(
int
i
=
0
;
i
<
players
.
size
();
++
i
)
players
[
i
]
->
retranslateUi
();
QMapIterator
<
int
,
Player
*>
i
(
players
);
while
(
i
.
hasNext
())
i
.
next
().
value
()
->
retranslateUi
();
}
Player
*
Game
::
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
bool
local
)
...
...
@@ -132,7 +138,7 @@ Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
connect
(
newPlayer
,
SIGNAL
(
logSetCounter
(
Player
*
,
QString
,
int
,
int
)),
this
,
SIGNAL
(
logSetCounter
(
Player
*
,
QString
,
int
,
int
)));
connect
(
newPlayer
,
SIGNAL
(
logSetDoesntUntap
(
Player
*
,
QString
,
bool
)),
this
,
SIGNAL
(
logSetDoesntUntap
(
Player
*
,
QString
,
bool
)));
players
<<
newPlayer
;
players
.
insert
(
playerId
,
newPlayer
)
;
emit
playerAdded
(
newPlayer
);
return
newPlayer
;
...
...
@@ -141,10 +147,11 @@ Player *Game::addPlayer(int playerId, const QString &playerName, bool local)
void
Game
::
cardListReceived
(
QList
<
ServerZoneCard
>
list
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
Player
*
p
=
players
.
findPlayer
(
list
[
i
].
getPlayerId
());
Player
*
p
=
players
.
value
(
list
[
i
].
getPlayerId
()
,
0
);
if
(
!
p
)
continue
;
CardZone
*
zone
=
p
->
getZones
().
findZone
(
list
[
i
].
getZoneName
());
CardZone
*
zone
=
p
->
getZones
().
value
(
list
[
i
].
getZoneName
(),
0
);
if
(
!
zone
)
continue
;
...
...
@@ -161,12 +168,14 @@ void Game::cardListReceived(QList<ServerZoneCard> list)
void
Game
::
zoneListReceived
(
QList
<
ServerZone
>
list
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
Player
*
p
=
players
.
findPlayer
(
list
[
i
].
getPlayerId
());
Player
*
p
=
players
.
value
(
list
[
i
].
getPlayerId
()
,
0
);
if
(
!
p
)
continue
;
CardZone
*
zone
=
p
->
getZones
().
findZone
(
list
[
i
].
getName
());
CardZone
*
zone
=
p
->
getZones
().
value
(
list
[
i
].
getName
(),
0
);
if
(
!
zone
)
continue
;
zone
->
clearContents
();
if
(
(
list
[
i
].
getType
()
!=
ServerZone
::
PublicZone
)
...
...
@@ -181,13 +190,15 @@ void Game::zoneListReceived(QList<ServerZone> list)
void
Game
::
counterListReceived
(
QList
<
ServerCounter
>
list
)
{
for
(
int
i
=
0
;
i
<
players
.
size
();
++
i
)
players
[
i
]
->
clearCounters
();
QMapIterator
<
int
,
Player
*>
i
(
players
);
while
(
i
.
hasNext
())
i
.
next
().
value
()
->
clearCounters
();
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
Player
*
p
=
players
.
findPlayer
(
list
[
i
].
getPlayerId
());
if
(
p
)
p
->
addCounter
(
list
[
i
].
getName
(),
list
[
i
].
getColor
(),
list
[
i
].
getCount
());
Player
*
p
=
players
.
value
(
list
[
i
].
getPlayerId
(),
0
);
if
(
!
p
)
continue
;
p
->
addCounter
(
list
[
i
].
getId
(),
list
[
i
].
getName
(),
list
[
i
].
getColor
(),
list
[
i
].
getRadius
(),
list
[
i
].
getCount
());
}
}
...
...
@@ -215,7 +226,7 @@ void Game::restartGameDialog()
void
Game
::
gameEvent
(
const
ServerEventData
&
msg
)
{
qDebug
(
QString
(
"game::gameEvent: public=%1, player=%2, name=%3, type=%4, data=%5"
).
arg
(
msg
.
getPublic
()).
arg
(
msg
.
getPlayerId
()).
arg
(
msg
.
getPlayerName
()).
arg
(
msg
.
getEventType
()).
arg
(
msg
.
getEventData
().
join
(
"/"
)).
toLatin1
());
Player
*
p
=
players
.
findPlayer
(
msg
.
getPlayerId
());
Player
*
p
=
players
.
value
(
msg
.
getPlayerId
()
,
0
);
if
(
!
msg
.
getPublic
())
{
if
(
!
p
)
return
;
...
...
@@ -287,13 +298,16 @@ void Game::gameEvent(const ServerEventData &msg)
case
eventSetActivePlayer
:
{
QStringList
data
=
msg
.
getEventData
();
int
playerId
=
data
[
0
].
toInt
();
Player
*
player
=
players
.
findPlayer
(
playerId
);
Player
*
player
=
players
.
value
(
playerId
,
0
);
if
(
!
player
)
{
qDebug
(
QString
(
"setActivePlayer: invalid player: %1"
).
arg
(
playerId
).
toLatin1
());
break
;
}
for
(
int
i
=
0
;
i
<
players
.
size
();
++
i
)
players
[
i
]
->
setActive
(
players
[
i
]
==
player
);
QMapIterator
<
int
,
Player
*>
i
(
players
);
while
(
i
.
hasNext
())
{
i
.
next
();
i
.
value
()
->
setActive
(
i
.
value
()
==
player
);
}
emit
logSetActivePlayer
(
player
);
break
;
}
...
...
@@ -319,10 +333,10 @@ void Game::gameEvent(const ServerEventData &msg)
}
case
eventDumpZone
:
{
QStringList
data
=
msg
.
getEventData
();
Player
*
zoneOwner
=
players
.
findPlayer
(
data
[
0
].
toInt
());
Player
*
zoneOwner
=
players
.
value
(
data
[
0
].
toInt
()
,
0
);
if
(
!
zoneOwner
)
break
;
CardZone
*
zone
=
zoneOwner
->
getZones
().
findZon
e
(
data
[
1
]);
CardZone
*
zone
=
zoneOwner
->
getZones
().
valu
e
(
data
[
1
]
,
0
);
if
(
!
zone
)
break
;
emit
logDumpZone
(
p
,
zone
,
data
[
2
].
toInt
());
...
...
@@ -330,10 +344,10 @@ void Game::gameEvent(const ServerEventData &msg)
}
case
eventStopDumpZone
:
{
QStringList
data
=
msg
.
getEventData
();
Player
*
zoneOwner
=
players
.
findPlayer
(
data
[
0
].
toInt
());
Player
*
zoneOwner
=
players
.
value
(
data
[
0
].
toInt
()
,
0
);
if
(
!
zoneOwner
)
break
;
CardZone
*
zone
=
zoneOwner
->
getZones
().
findZon
e
(
data
[
1
]);
CardZone
*
zone
=
zoneOwner
->
getZones
().
valu
e
(
data
[
1
]
,
0
);
if
(
!
zone
)
break
;
emit
logStopDumpZone
(
p
,
zone
);
...
...
cockatrice/src/game.h
View file @
29699418
...
...
@@ -2,8 +2,10 @@
#define GAME_H
#include
<QHash>
#include
<QMap>
#include
<QStringList>
#include
"playerlist.h"
#include
<QMenu>
#include
<QAction>
#include
"client.h"
class
GameScene
;
...
...
@@ -13,6 +15,7 @@ class CardDatabase;
class
DlgStartGame
;
class
CardItem
;
class
QMenuBar
;
class
CardZone
;
class
Game
:
public
QObject
{
Q_OBJECT
...
...
@@ -32,7 +35,7 @@ private:
Client
*
client
;
GameScene
*
scene
;
QStringList
spectatorList
;
Player
List
players
;
QMap
<
int
,
Player
*>
players
;
bool
started
;
int
currentPhase
;
public
slots
:
...
...
cockatrice/src/player.cpp
View file @
29699418
...
...
@@ -21,7 +21,7 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
bgPixmap
.
load
(
bgPath
);
setCacheMode
(
DeviceCoordinateCache
);
QPointF
base
=
QPointF
(
55
,
50
);
QPointF
base
=
QPointF
(
counterAreaWidth
,
50
);
PileZone
*
deck
=
new
PileZone
(
this
,
"deck"
,
true
,
false
,
this
);
deck
->
setPos
(
base
);
...
...
@@ -41,7 +41,7 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
connect
(
table
,
SIGNAL
(
sizeChanged
()),
this
,
SLOT
(
updateBoundingRect
()));
hand
=
new
HandZone
(
this
,
(
int
)
table
->
boundingRect
().
height
(),
this
);
base
=
QPointF
(
deck
->
boundingRect
().
width
()
+
60
,
0
);
base
=
QPointF
(
deck
->
boundingRect
().
width
()
+
counterAreaWidth
+
5
,
0
);
hand
->
setPos
(
base
);
base
+=
QPointF
(
hand
->
boundingRect
().
width
(),
0
);
table
->
setPos
(
base
);
...
...
@@ -49,10 +49,31 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
updateBoundingRect
();
if
(
local
)
{
aMoveHandToTopLibrary
=
new
QAction
(
this
);
connect
(
aMoveHandToTopLibrary
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actMoveHandToTopLibrary
()));
aMoveHandToBottomLibrary
=
new
QAction
(
this
);
connect
(
aMoveHandToBottomLibrary
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actMoveHandToBottomLibrary
()));
aMoveToTopLibrary
=
new
QAction
(
this
);
aMoveToTopLibrary
->
setData
(
QList
<
QVariant
>
()
<<
"deck"
<<
0
);
aMoveToBottomLibrary
=
new
QAction
(
this
);
aMoveToBottomLibrary
->
setData
(
QList
<
QVariant
>
()
<<
"deck"
<<
-
1
);
aMoveToHand
=
new
QAction
(
this
);
aMoveToHand
->
setData
(
QList
<
QVariant
>
()
<<
"hand"
<<
0
);
aMoveToGraveyard
=
new
QAction
(
this
);
aMoveToGraveyard
->
setData
(
QList
<
QVariant
>
()
<<
"grave"
<<
0
);
aMoveToRfg
=
new
QAction
(
this
);
aMoveToRfg
->
setData
(
QList
<
QVariant
>
()
<<
"rfg"
<<
0
);
connect
(
aMoveToTopLibrary
,
SIGNAL
(
triggered
()),
hand
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToBottomLibrary
,
SIGNAL
(
triggered
()),
hand
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToGraveyard
,
SIGNAL
(
triggered
()),
hand
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToRfg
,
SIGNAL
(
triggered
()),
hand
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToTopLibrary
,
SIGNAL
(
triggered
()),
grave
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToBottomLibrary
,
SIGNAL
(
triggered
()),
grave
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToHand
,
SIGNAL
(
triggered
()),
grave
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToRfg
,
SIGNAL
(
triggered
()),
grave
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToTopLibrary
,
SIGNAL
(
triggered
()),
rfg
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToBottomLibrary
,
SIGNAL
(
triggered
()),
rfg
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToHand
,
SIGNAL
(
triggered
()),
rfg
,
SLOT
(
moveAllToZone
()));
connect
(
aMoveToGraveyard
,
SIGNAL
(
triggered
()),
rfg
,
SLOT
(
moveAllToZone
()));
aViewLibrary
=
new
QAction
(
this
);
connect
(
aViewLibrary
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actViewLibrary
()));
...
...
@@ -82,8 +103,10 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
if
(
local
)
{
handMenu
=
playerMenu
->
addMenu
(
QString
());
handMenu
->
addAction
(
aMoveHandToTopLibrary
);
handMenu
->
addAction
(
aMoveHandToBottomLibrary
);
handMenu
->
addAction
(
aMoveToTopLibrary
);
handMenu
->
addAction
(
aMoveToBottomLibrary
);
handMenu
->
addAction
(
aMoveToGraveyard
);
handMenu
->
addAction
(
aMoveToRfg
);
hand
->
setMenu
(
handMenu
);
libraryMenu
=
playerMenu
->
addMenu
(
QString
());
...
...
@@ -109,6 +132,18 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl
rfg
->
setMenu
(
rfgMenu
,
aViewRfg
);
if
(
local
)
{
graveMenu
->
addSeparator
();
graveMenu
->
addAction
(
aMoveToTopLibrary
);
graveMenu
->
addAction
(
aMoveToBottomLibrary
);
graveMenu
->
addAction
(
aMoveToHand
);
graveMenu
->
addAction
(
aMoveToRfg
);
rfgMenu
->
addSeparator
();
rfgMenu
->
addAction
(
aMoveToTopLibrary
);
rfgMenu
->
addAction
(
aMoveToBottomLibrary
);
rfgMenu
->
addAction
(
aMoveToHand
);
rfgMenu
->
addAction
(
aMoveToGraveyard
);
sbMenu
=
playerMenu
->
addMenu
(
QString
());
sbMenu
->
addAction
(
aViewSideboard
);
sb
->
setMenu
(
sbMenu
,
aViewSideboard
);
...
...
@@ -153,8 +188,9 @@ Player::~Player()
{
qDebug
(
"Player destructor"
);
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
delete
zones
.
at
(
i
);
QMapIterator
<
QString
,
CardZone
*>
i
(
zones
);
while
(
i
.
hasNext
())
delete
i
.
next
().
value
();
clearCounters
();
delete
playerMenu
;
...
...
@@ -175,8 +211,11 @@ void Player::retranslateUi()
rfgMenu
->
setTitle
(
tr
(
"&Exile"
));
if
(
local
)
{
aMoveHandToTopLibrary
->
setText
(
tr
(
"Move to &top of library"
));
aMoveHandToBottomLibrary
->
setText
(
tr
(
"Move to &bottom of library"
));
aMoveToTopLibrary
->
setText
(
tr
(
"Move to &top of library"
));
aMoveToBottomLibrary
->
setText
(
tr
(
"Move to &bottom of library"
));
aMoveToHand
->
setText
(
tr
(
"Move to &hand"
));
aMoveToGraveyard
->
setText
(
tr
(
"Move to g&raveyard"
));
aMoveToRfg
->
setText
(
tr
(
"Move to &exile"
));
aViewLibrary
->
setText
(
tr
(
"&View library"
));
aViewLibrary
->
setShortcut
(
tr
(
"F3"
));
aViewTopCards
->
setText
(
tr
(
"View &top cards of library..."
));
...
...
@@ -233,16 +272,6 @@ void Player::initSayMenu()
}
}
void
Player
::
actMoveHandToTopLibrary
()
{
zones
.
findZone
(
"hand"
)
->
moveAllToZone
(
"deck"
,
0
);
}
void
Player
::
actMoveHandToBottomLibrary
()
{
zones
.
findZone
(
"hand"
)
->
moveAllToZone
(
"deck"
,
-
1
);
}
void
Player
::
actViewLibrary
()
{
emit
toggleZoneView
(
this
,
"deck"
,
-
1
);
...
...
@@ -297,20 +326,22 @@ void Player::actUntapAll()
void
Player
::
actIncLife
()
{
client
->
incCounter
(
"life"
,
1
);
// XXX
client
->
incCounter
(
lifeCounter
->
getId
(),
1
);
}
void
Player
::
actDecLife
()
{
client
->
incCounter
(
"life"
,
-
1
);
// XXX
client
->
incCounter
(
lifeCounter
->
getId
(),
-
1
);
}
void
Player
::
actSetLife
()
{
bool
ok
;
int
life
=
QInputDialog
::
getInteger
(
0
,
tr
(
"Set life"
),
tr
(
"New life total:"
),
get
Counter
(
"life"
)
->
getValue
(),
0
,
2000000000
,
1
,
&
ok
);
int
life
=
QInputDialog
::
getInteger
(
0
,
tr
(
"Set life"
),
tr
(
"New life total:"
),
life
Counter
->
getValue
(),
0
,
2000000000
,
1
,
&
ok
);
if
(
ok
)
client
->
setCounter
(
"
life
"
,
life
);
client
->
setCounter
(
life
Counter
->
getId
()
,
life
);
}
void
Player
::
actRollDie
()
...
...
@@ -336,7 +367,7 @@ void Player::actSayMessage()
void
Player
::
addZone
(
CardZone
*
z
)
{
zones
<<
z
;
zones
.
insert
(
z
->
getName
(),
z
)
;
}
void
Player
::
setCardAttrHelper
(
CardItem
*
card
,
const
QString
&
aname
,
const
QString
&
avalue
,
bool
allCards
)
...
...
@@ -376,41 +407,44 @@ void Player::gameEvent(const ServerEventData &event)
// XXX Fehlerbehandlung
// Clean up existing zones first
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
{
if
(
ZoneViewZone
*
view
=
zones
.
at
(
i
)
->
getView
())
QMapIterator
<
QString
,
CardZone
*>
zoneIterator
(
zones
);
while
(
zoneIterator
.
hasNext
())
{
zoneIterator
.
next
();
if
(
ZoneViewZone
*
view
=
zoneIterator
.
value
()
->
getView
())
((
ZoneViewWidget
*
)
view
->
parentItem
())
->
close
();
zone
s
.
at
(
i
)
->
clearContents
();
zone
Iterator
.
value
(
)
->
clearContents
();
}
clearCounters
();
CardZone
*
deck
=
zones
.
findZon
e
(
"deck"
);
CardZone
*
deck
=
zones
.
valu
e
(
"deck"
);
for
(;
deck_cards
;
deck_cards
--
)
deck
->
addCard
(
new
CardItem
(
db
),
false
,
-
1
);
CardZone
*
sb
=
zones
.
findZon
e
(
"sb"
);
CardZone
*
sb
=
zones
.
valu
e
(
"sb"
);
for
(;
sb_cards
;
sb_cards
--
)
sb
->
addCard
(
new
CardItem
(
db
),
false
,
-
1
);
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
zones
.
at
(
i
)
->
reorganizeCards
();
zoneIterator
.
toFront
();
while
(
zoneIterator
.
hasNext
())
zoneIterator
.
next
().
value
()
->
reorganizeCards
();
if
(
local
)
{
client
->
addCounter
(
"life"
,
Qt
::
white
,
20
);
client
->
addCounter
(
"w"
,
QColor
(
255
,
255
,
150
),
0
);
client
->
addCounter
(
"u"
,
QColor
(
150
,
150
,
255
),
0
);
client
->
addCounter
(
"b"
,
QColor
(
150
,
150
,
150
),
0
);
client
->
addCounter
(
"r"
,
QColor
(
250
,
150
,
150
),
0
);
client
->
addCounter
(
"g"
,
QColor
(
150
,
255
,
150
),
0
);
client
->
addCounter
(
"x"
,
QColor
(
255
,
255
,
255
),
0
);
client
->
addCounter
(
"storm"
,
QColor
(
255
,
255
,
255
),
0
);
client
->
addCounter
(
"life"
,
Qt
::
white
,
25
,
20
);
client
->
addCounter
(
"w"
,
QColor
(
255
,
255
,
150
),
20
,
0
);
client
->
addCounter
(
"u"
,
QColor
(
150
,
150
,
255
),
20
,
0
);
client
->
addCounter
(
"b"
,
QColor
(
150
,
150
,
150
),
20
,
0
);
client
->
addCounter
(
"r"
,
QColor
(
250
,
150
,
150
),
20
,
0
);
client
->
addCounter
(
"g"
,
QColor
(
150
,
255
,
150
),
20
,
0
);
client
->
addCounter
(
"x"
,
QColor
(
255
,
255
,
255
),
20
,
0
);
client
->
addCounter
(
"storm"
,
QColor
(
255
,
255
,
255
),
20
,
0
);
}
break
;
}
case
eventDraw
:
{
CardZone
*
deck
=
zones
.
findZon
e
(
"deck"
);
CardZone
*
hand
=
zones
.
findZon
e
(
"hand"
);
CardZone
*
deck
=
zones
.
valu
e
(
"deck"
);
CardZone
*
hand
=
zones
.
valu
e
(
"hand"
);
if
(
!
event
.
getPublic
())
{
hand
->
addCard
(
deck
->
takeCard
(
0
,
data
[
0
].
toInt
(),
data
[
1
]),
true
,
-
1
);
}
else
{
...
...
@@ -428,13 +462,17 @@ void Player::gameEvent(const ServerEventData &event)
}
int
cardId
=
data
[
0
].
toInt
();
QString
cardName
=
data
[
1
];
CardZone
*
startZone
=
zones
.
findZon
e
(
data
[
2
]);
if
(
!
startZone
)
CardZone
*
startZone
=
zones
.
valu
e
(
data
[
2
]
,
0
);
if
(
!
startZone
)
{
qDebug
(
QString
(
"start zone invalid: %1"
).
arg
(
data
[
2
]).
toLatin1
());
break
;
}
int
position
=
data
[
3
].
toInt
();
CardZone
*
targetZone
=
zones
.
findZon
e
(
data
[
4
]);
if
(
!
targetZone
)
CardZone
*
targetZone
=
zones
.
valu
e
(
data
[
4
]
,
0
);
if
(
!
targetZone
)
{
qDebug
(
QString
(
"target zone invalid: %1"
).
arg
(
data
[
4
]).
toLatin1
());
break
;
}
int
x
=
data
[
5
].
toInt
();
int
y
=
data
[
6
].
toInt
();
bool
facedown
=
data
[
7
].
toInt
();
...
...
@@ -467,7 +505,9 @@ void Player::gameEvent(const ServerEventData &event)
if
(
data
.
size
()
!=
6
)
{
qDebug
(
"error"
);
}
CardZone
*
zone
=
zones
.
findZone
(
data
[
0
]);
CardZone
*
zone
=
zones
.
value
(
data
[
0
],
0
);
if
(
!
zone
)
break
;
int
cardid
=
data
[
1
].
toInt
();
QString
cardname
=
data
[
2
];
QString
powtough
=
data
[
3
];
...
...
@@ -485,7 +525,9 @@ void Player::gameEvent(const ServerEventData &event)
if
(
data
.
size
()
!=
4
)
{
// XXX
}
CardZone
*
zone
=
zones
.
findZone
(
data
[
0
]);
CardZone
*
zone
=
zones
.
value
(
data
[
0
],
0
);
if
(
!
zone
)
break
;
int
cardId
=
data
[
1
].
toInt
();
QString
aname
=
data
[
2
];
QString
avalue
=
data
[
3
];
...
...
@@ -504,23 +546,27 @@ void Player::gameEvent(const ServerEventData &event)
break
;
}
case
eventAddCounter
:
{
if
(
data
.
size
()
!=
3
)
{
if
(
data
.
size
()
!=
4
)
{
// XXX
}
QString
counterName
=
data
[
0
];
int
colorValue
=
data
[
1
].
toInt
();
int
value
=
data
[
2
].
toInt
();
int
counterId
=
data
[
0
].
toInt
();
QString
counterName
=
data
[
1
];
int
colorValue
=
data
[
2
].
toInt
();
int
radius
=
data
[
3
].
toInt
();
int
value
=
data
[
4
].
toInt
();
QColor
color
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
);
addCounter
(
counterName
,
color
,
value
);
addCounter
(
counterId
,
counterName
,
color
,
radius
,
value
);
break
;
}
case
eventSetCounter
:
{
if
(
data
.
size
()
!=
2
)
{
// XXX
}
int
counterId
=
data
[
0
].
toInt
();
int
value
=
data
[
1
].
toInt
();
QString
counterName
=
data
[
0
];
Counter
*
c
=
getCounter
(
counterName
);
Counter
*
c
=
counters
.
value
(
counterId
,
0
);
if
(
!
c
)
break
;
int
oldValue
=
c
->
getValue
();
c
->
setValue
(
value
);
emit
logSetCounter
(
this
,
c
->
getName
(),
value
,
oldValue
);
...
...
@@ -583,46 +629,62 @@ void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/
painter
->
drawText
(
QRectF
(
0
,
0
,
totalWidth
,
40
),
Qt
::
AlignCenter
,
nameStr
);
}
Counter
*
Player
::
get
Counter
(
const
QString
&
name
,
bool
remov
e
)
void
Player
::
add
Counter
(
int
counterId
,
const
QString
&
name
,
QColor
color
,
int
radius
,
int
valu
e
)
{
for
(
int
i
=
0
;
i
<
counterList
.
size
();
i
++
)
{
Counter
*
temp
=
counterList
.
at
(
i
);
if
(
temp
->
getName
()
==
name
)
{
if
(
remove
)
counterList
.
removeAt
(
i
);
return
temp
;
}
}
return
0
;
}
void
Player
::
addCounter
(
const
QString
&
name
,
QColor
color
,
int
value
)
{
counterList
.
append
(
new
Counter
(
this
,
name
,
color
,
value
,
this
));
Counter
*
c
=
new
Counter
(
this
,
counterId
,
name
,
color
,
radius
,
value
,
this
);
counters
.
insert
(
counterId
,
c
);
if
(
name
==
"life"
)
lifeCounter
=
c
;
// XXX
rearrangeCounters
();
}
void
Player
::
delCounter
(
const
QString
&
name
)
void
Player
::
delCounter
(
int
counterId
)
{
delete
getCounter
(
name
,
true
);
Counter
*
c
=
counters
.
value
(
counterId
,
0
);
if
(
!
c
)
return
;
counters
.
remove
(
counterId
);
delete
c
;
rearrangeCounters
();
}
void
Player
::
clearCounters
()
{
for
(
int
i
=
0
;
i
<
counterList
.
size
();
i
++
)
delete
counterList
.
at
(
i
);
counterList
.
clear
();
QMapIterator
<
int
,
Counter
*>
counterIterator
(
counters
);
while
(
counterIterator
.
hasNext
())
delete
counterIterator
.
next
().
value
();
counters
.
clear
();
}
void
Player
::
rearrangeCounters
()
{
const
int
counterAreaWidth
=
55
;
qreal
y
=
50
;
for
(
int
i
=
0
;
i
<
counterList
.
size
();
i
++
)
{
Counter
*
temp
=
counterList
.
at
(
i
);
QRectF
br
=
temp
->
boundingRect
();
temp
->
setPos
((
counterAreaWidth
-
br
.
width
())
/
2
,
y
);
y
+=
br
.
height
()
+
10
;
qreal
marginTop
=
50
;
qreal
marginBottom
=
15
;
// Determine total height of bounding rectangles
qreal
totalHeight
=
0
;
QMapIterator
<
int
,
Counter
*>
counterIterator
(
counters
);
while
(
counterIterator
.
hasNext
())
{
counterIterator
.
next
();
totalHeight
+=
counterIterator
.
value
()
->
boundingRect
().
height
();
}
// Determine free space between objects
qreal
padding
=
(
boundingRect
().
height
()
-
marginTop
-
marginBottom
-
totalHeight
)
/
(
counters
.
size
()
-
1
);
qreal
y
=
boundingRect
().
y
()
+
marginTop
;
if
(
counters
.
size
()
==
1
)
{
padding
=
0
;
y
+=
(
boundingRect
().
height
()
-
marginTop
-
marginBottom
)
/
2
;
}
// Place objects
for
(
counterIterator
.
toFront
();
counterIterator
.
hasNext
();
)
{
Counter
*
c
=
counterIterator
.
next
().
value
();
QRectF
br
=
c
->
boundingRect
();
c
->
setPos
((
counterAreaWidth
-
br
.
width
())
/
2
,
y
);
y
+=
br
.
height
()
+
padding
;
}
}
cockatrice/src/player.h
View file @
29699418
...
...
@@ -3,8 +3,9 @@
#include
<QInputDialog>
#include
<QPoint>
#include
"zonelist.h"
#include
<QMap>
#include
"client.h"
#include
"carditem.h"
class
Client
;
class
CardDatabase
;
...
...
@@ -13,6 +14,7 @@ class QAction;
class
ZoneViewZone
;
class
Game
;
class
Counter
;
class
CardZone
;
class
TableZone
;
class
HandZone
;
...
...
@@ -45,9 +47,6 @@ public slots:
private
slots
:
void
updateBoundingRect
();
void
actMoveHandToTopLibrary
();
void
actMoveHandToBottomLibrary
();
void
actShuffle
();
void
actDrawCard
();
void
actDrawCards
();
...
...
@@ -59,7 +58,7 @@ private slots:
void
actViewSideboard
();
private:
QMenu
*
playerMenu
,
*
handMenu
,
*
graveMenu
,
*
rfgMenu
,
*
libraryMenu
,
*
sbMenu
,
*
sayMenu
;
QAction
*
aMove
Hand
ToTopLibrary
,
*
aMove
Hand
ToBottomLibrary
,
QAction
*
aMoveToTopLibrary
,
*
aMoveToBottomLibrary
,
*
aMoveToHand
,
*
aMoveToGraveyard
,
*
aMoveToRfg
,
*
aViewLibrary
,
*
aViewTopCards
,
*
aViewGraveyard
,
*
aViewRfg
,
*
aViewSideboard
,
*
aDrawCard
,
*
aDrawCards
,
*
aShuffle
,
*
aUntapAll
,
*
aDecLife
,
*
aIncLife
,
*
aSetLife
,
*
aRollDie
,
*
aCreateToken
;
...
...
@@ -70,7 +69,7 @@ private:
bool
active
;
bool
local
;
ZoneList
zones
;
QMap
<
QString
,
CardZone
*>
zones
;
TableZone
*
table
;
HandZone
*
hand
;
...
...
@@ -80,18 +79,21 @@ private:
QPixmap
bgPixmap
;
QRectF
bRect
;
QList
<
Counter
*>
counterList
;
QMap
<
int
,
Counter
*>
counters
;
Counter
*
lifeCounter
;
void
rearrangeCounters
();
void
initSayMenu
();
public:
static
const
int
counterAreaWidth
=
65
;
enum
{
Type
=
typeOther
};
int
type
()
const
{
return
Type
;
}
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
Counter
*
getCounter
(
const
QString
&
name
,
bool
remove
=
false
);
void
addCounter
(
const
QString
&
name
,
QColor
color
,
int
value
);
void
delCounter
(
const
QString
&
name
);
void
addCounter
(
int
counterId
,
const
QString
&
name
,
QColor
color
,
int
radius
,
int
value
);
void
delCounter
(
int
counterId
);
void
clearCounters
();
Client
*
client
;
...
...
@@ -103,7 +105,8 @@ public:
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
bool
getLocal
()
const
{
return
local
;
}
const
ZoneList
&
getZones
()
const
{
return
zones
;
}
const
QMap
<
QString
,
CardZone
*>
&
getZones
()
const
{
return
zones
;
}
TableZone
*
getTable
()
const
{
return
table
;
}
void
gameEvent
(
const
ServerEventData
&
event
);
CardDatabase
*
getDb
()
const
{
return
db
;
}
void
showCardMenu
(
const
QPoint
&
p
);
...
...
cockatrice/src/playerlist.cpp
deleted
100644 → 0
View file @
a543c9b9
#include
"playerlist.h"
Player
*
PlayerList
::
findPlayer
(
int
id
)
const
{
for
(
int
i
=
0
;
i
<
size
();
i
++
)
{
Player
*
temp
=
at
(
i
);
if
(
temp
->
getId
()
==
id
)
return
temp
;
}
return
0
;
}
cockatrice/src/playerlist.h
deleted
100644 → 0
View file @
a543c9b9
#ifndef PLAYERLIST_H
#define PLAYERLIST_H
#include
"player.h"
#include
<QList>
class
PlayerList
:
public
QList
<
Player
*>
{
public:
Player
*
findPlayer
(
int
id
)
const
;
};
#endif
cockatrice/src/zonelist.cpp
deleted
100644 → 0
View file @
a543c9b9
#include
"zonelist.h"
CardZone
*
ZoneList
::
findZone
(
const
QString
&
name
)
const
{
for
(
int
i
=
0
;
i
<
size
();
i
++
)
{
CardZone
*
temp
=
at
(
i
);
if
(
!
temp
->
getName
().
compare
(
name
))
return
temp
;
}
return
0
;
}
cockatrice/src/zonelist.h
deleted
100644 → 0
View file @
a543c9b9
#ifndef ZONELIST_H
#define ZONELIST_H
#include
"cardzone.h"
#include
<QList>
class
ZoneList
:
public
QList
<
CardZone
*>
{
public:
CardZone
*
findZone
(
const
QString
&
name
)
const
;
};
#endif
cockatrice/src/zoneviewlayout.cpp
View file @
29699418
...
...
@@ -45,7 +45,7 @@ void ZoneViewLayout::toggleZoneView(Player *player, const QString &zoneName, int
}
}
ZoneViewWidget
*
item
=
new
ZoneViewWidget
(
db
,
player
,
player
->
getZones
().
findZon
e
(
zoneName
),
numberCards
,
this
);
ZoneViewWidget
*
item
=
new
ZoneViewWidget
(
db
,
player
,
player
->
getZones
().
valu
e
(
zoneName
),
numberCards
,
this
);
views
.
append
(
item
);
connect
(
item
,
SIGNAL
(
closePressed
(
ZoneViewWidget
*
)),
this
,
SLOT
(
removeItem
(
ZoneViewWidget
*
)));
connect
(
item
,
SIGNAL
(
sizeChanged
()),
this
,
SLOT
(
reorganize
()));
...
...
servatrice/src/counter.h
View file @
29699418
...
...
@@ -24,14 +24,18 @@
class
Counter
{
protected:
int
id
;
QString
name
;
int
color
;
int
radius
;
int
count
;
public:
Counter
(
QString
_name
,
int
_color
,
int
_count
=
0
)
:
name
(
_name
),
color
(
_color
),
count
(
_count
)
{
}
Counter
(
int
_id
,
const
QString
&
_name
,
int
_color
,
int
_radius
,
int
_count
=
0
)
:
id
(
_id
),
name
(
_name
),
color
(
_color
),
radius
(
_radius
),
count
(
_count
)
{
}
~
Counter
()
{
}
int
getId
()
const
{
return
id
;
}
QString
getName
()
const
{
return
name
;
}
int
getColor
()
const
{
return
color
;
}
int
getRadius
()
const
{
return
radius
;
}
int
getCount
()
const
{
return
count
;
}
void
setCount
(
int
_count
)
{
count
=
_count
;
}
};
...
...
servatrice/src/serversocket.cpp
View file @
29699418
...
...
@@ -33,7 +33,7 @@
QHash
<
QString
,
ServerSocket
::
CommandProperties
>
ServerSocket
::
commandHash
;
ServerSocket
::
ServerSocket
(
Server
*
_server
,
QObject
*
parent
)
:
QTcpSocket
(
parent
),
server
(
_server
),
game
(
0
),
spectator
(
false
),
PlayerStatus
(
StatusNormal
),
authState
(
PasswordWrong
),
acceptsGameListChanges
(
false
)
:
QTcpSocket
(
parent
),
server
(
_server
),
game
(
0
),
spectator
(
false
),
nextCardId
(
0
),
PlayerStatus
(
StatusNormal
),
authState
(
PasswordWrong
),
acceptsGameListChanges
(
false
)
{
if
(
commandHash
.
isEmpty
())
{
commandHash
.
insert
(
"ping"
,
CommandProperties
(
false
,
false
,
false
,
true
,
QList
<
QVariant
::
Type
>
(),
&
ServerSocket
::
cmdPing
));
...
...
@@ -94,12 +94,13 @@ ServerSocket::ServerSocket(Server *_server, QObject *parent)
commandHash
.
insert
(
"add_counter"
,
CommandProperties
(
true
,
true
,
true
,
false
,
QList
<
QVariant
::
Type
>
()
<<
QVariant
::
String
<<
QVariant
::
Int
<<
QVariant
::
Int
<<
QVariant
::
Int
,
&
ServerSocket
::
cmdAddCounter
));
commandHash
.
insert
(
"set_counter"
,
CommandProperties
(
true
,
true
,
true
,
false
,
QList
<
QVariant
::
Type
>
()
<<
QVariant
::
String
<<
QVariant
::
Int
<<
QVariant
::
Int
,
&
ServerSocket
::
cmdSetCounter
));
commandHash
.
insert
(
"del_counter"
,
CommandProperties
(
true
,
true
,
true
,
false
,
QList
<
QVariant
::
Type
>
()
<<
QVariant
::
String
,
&
ServerSocket
::
cmdDelCounter
));
<<
QVariant
::
Int
,
&
ServerSocket
::
cmdDelCounter
));
commandHash
.
insert
(
"list_counters"
,
CommandProperties
(
true
,
true
,
true
,
true
,
QList
<
QVariant
::
Type
>
()
<<
QVariant
::
Int
,
&
ServerSocket
::
cmdListCounters
));
commandHash
.
insert
(
"list_zones"
,
CommandProperties
(
true
,
true
,
true
,
true
,
QList
<
QVariant
::
Type
>
()
...
...
@@ -143,22 +144,23 @@ int ServerSocket::newCardId()
return
nextCardId
++
;
}
PlayerZone
*
ServerSocket
::
getZone
(
const
QString
&
name
)
const
int
ServerSocket
::
newCounterId
(
)
const
{
QListIterator
<
PlayerZone
*>
ZoneIterator
(
zones
);
while
(
ZoneIterator
.
hasNext
())
{
PlayerZone
*
temp
=
ZoneIterator
.
next
();
if
(
temp
->
getName
()
==
name
)
return
temp
;
int
id
=
0
;
QMapIterator
<
int
,
Counter
*>
i
(
counters
);
while
(
i
.
hasNext
())
{
Counter
*
c
=
i
.
next
().
value
();
if
(
c
->
getId
()
>
id
)
id
=
c
->
getId
();
}
return
NULL
;
return
id
+
1
;
}
Counter
*
ServerSocket
::
get
Counter
(
const
QString
&
name
)
const
PlayerZone
*
ServerSocket
::
get
Zone
(
const
QString
&
name
)
const
{
QListIterator
<
Counter
*>
Counter
Iterator
(
counter
s
);
while
(
Counter
Iterator
.
hasNext
())
{
Counter
*
temp
=
Counter
Iterator
.
next
();
QListIterator
<
PlayerZone
*>
Zone
Iterator
(
zone
s
);
while
(
Zone
Iterator
.
hasNext
())
{
PlayerZone
*
temp
=
Zone
Iterator
.
next
();
if
(
temp
->
getName
()
==
name
)
return
temp
;
}
...
...
@@ -209,8 +211,9 @@ void ServerSocket::clearZones()
delete
zones
.
at
(
i
);
zones
.
clear
();
for
(
int
i
=
0
;
i
<
counters
.
size
();
i
++
)
delete
counters
.
at
(
i
);
QMapIterator
<
int
,
Counter
*>
counterIterator
(
counters
);
while
(
counterIterator
.
hasNext
())
delete
counterIterator
.
next
().
value
();
counters
.
clear
();
}
...
...
@@ -588,60 +591,62 @@ ReturnMessage::ReturnCode ServerSocket::cmdSetCardAttr(const QList<QVariant> &pa
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdIncCounter
(
const
QList
<
QVariant
>
&
params
)
{
Counter
*
c
=
getC
ounter
(
params
[
0
].
to
String
()
);
Counter
*
c
=
c
ounter
s
.
value
(
params
[
0
].
to
Int
(),
0
);
if
(
!
c
)
return
ReturnMessage
::
ReturnContextError
;
int
delta
=
params
[
1
].
toInt
();
c
->
setCount
(
c
->
getCount
()
+
delta
);
emit
broadcastEvent
(
QString
(
"set_counter|%1|%2"
).
arg
(
c
->
get
Name
()).
arg
(
c
->
getCount
()),
this
);
emit
broadcastEvent
(
QString
(
"set_counter|%1|%2"
).
arg
(
c
->
get
Id
()).
arg
(
c
->
getCount
()),
this
);
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdAddCounter
(
const
QList
<
QVariant
>
&
params
)
{
QString
name
=
params
[
0
].
toString
();
if
(
getCounter
(
name
))
return
ReturnMessage
::
ReturnContextError
;
int
color
=
params
[
1
].
toInt
();
int
count
=
params
[
2
].
toInt
();
int
radius
=
params
[
2
].
toInt
();
int
count
=
params
[
3
].
toInt
();
Counter
*
c
=
new
Counter
(
name
,
color
,
count
);
counters
<<
c
;
emit
broadcastEvent
(
QString
(
"add_counter|%1|%2|%3"
).
arg
(
c
->
getName
()).
arg
(
color
).
arg
(
count
),
this
);
Counter
*
c
=
new
Counter
(
newCounterId
(),
name
,
color
,
radius
,
count
);
counters
.
insert
(
c
->
getId
(),
c
)
;
emit
broadcastEvent
(
QString
(
"add_counter|%1|%2|%3
|%4|%5
"
).
arg
(
c
->
getId
()).
arg
(
c
->
getName
()).
arg
(
color
).
arg
(
radius
).
arg
(
count
),
this
);
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdSetCounter
(
const
QList
<
QVariant
>
&
params
)
{
Counter
*
c
=
getC
ounter
(
params
[
0
].
to
String
()
);
Counter
*
c
=
c
ounter
s
.
value
(
params
[
0
].
to
Int
(),
0
);
if
(
!
c
)
return
ReturnMessage
::
ReturnContextError
;
int
count
=
params
[
1
].
toInt
();
c
->
setCount
(
count
);
emit
broadcastEvent
(
QString
(
"set_counter|%1|%2"
).
arg
(
c
->
get
Name
()).
arg
(
count
),
this
);
emit
broadcastEvent
(
QString
(
"set_counter|%1|%2"
).
arg
(
c
->
get
Id
()).
arg
(
count
),
this
);
return
ReturnMessage
::
ReturnOk
;
}
ReturnMessage
::
ReturnCode
ServerSocket
::
cmdDelCounter
(
const
QList
<
QVariant
>
&
params
)
{
Counter
*
c
=
getCounter
(
params
[
0
].
toString
());
int
counterId
=
params
[
0
].
toInt
();
Counter
*
c
=
counters
.
value
(
counterId
,
0
);
if
(
!
c
)
return
ReturnMessage
::
ReturnContextError
;
counters
.
remove
(
counterId
);
delete
c
;
counters
.
removeAt
(
counters
.
indexOf
(
c
));
emit
broadcastEvent
(
QString
(
"del_counter|%1"
).
arg
(
params
[
0
].
toString
()),
this
);
emit
broadcastEvent
(
QString
(
"del_counter|%1"
).
arg
(
counterId
),
this
);
return
ReturnMessage
::
ReturnOk
;
}
QStringList
ServerSocket
::
listCountersHelper
(
ServerSocket
*
player
)
{
QStringList
result
;
const
QList
<
Counter
*>
&
counterList
=
player
->
getCounters
();
for
(
int
i
=
0
;
i
<
counterList
.
size
();
++
i
)
result
<<
QString
(
"%1|%2|%3|%4"
).
arg
(
player
->
getPlayerId
()).
arg
(
counterList
[
i
]
->
getName
()).
arg
(
counterList
[
i
]
->
getColor
()).
arg
(
counterList
[
i
]
->
getCount
());
QMapIterator
<
int
,
Counter
*>
i
(
player
->
getCounters
());
while
(
i
.
hasNext
())
{
Counter
*
c
=
i
.
next
().
value
();
result
<<
QString
(
"%1|%2|%3|%4|%5|%6"
).
arg
(
player
->
getPlayerId
()).
arg
(
c
->
getId
()).
arg
(
c
->
getName
()).
arg
(
c
->
getColor
()).
arg
(
c
->
getRadius
()).
arg
(
c
->
getCount
());
}
return
result
;
}
...
...
servatrice/src/serversocket.h
View file @
29699418
...
...
@@ -110,14 +110,14 @@ private:
QList
<
QString
>
DeckList
;
QList
<
QString
>
SideboardList
;
QList
<
PlayerZone
*>
zones
;
Q
List
<
Counter
*>
counters
;
Q
Map
<
int
,
Counter
*>
counters
;
int
playerId
;
QString
playerName
;
bool
spectator
;
int
nextCardId
;
int
newCardId
();
int
newCounterId
()
const
;
PlayerZone
*
getZone
(
const
QString
&
name
)
const
;
Counter
*
getCounter
(
const
QString
&
name
)
const
;
void
clearZones
();
bool
parseCommand
(
QString
line
);
PlayerStatusEnum
PlayerStatus
;
...
...
@@ -143,7 +143,7 @@ public:
bool
getAcceptsGameListChanges
()
const
{
return
acceptsGameListChanges
;
}
bool
getAcceptsChatChannelListChanges
()
const
{
return
acceptsChatChannelListChanges
;
}
const
QList
<
PlayerZone
*>
&
getZones
()
const
{
return
zones
;
}
const
Q
List
<
Counter
*>
&
getCounters
()
const
{
return
counters
;
}
const
Q
Map
<
int
,
Counter
*>
&
getCounters
()
const
{
return
counters
;
}
void
setupZones
();
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment