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
c8a2ed94
Commit
c8a2ed94
authored
Jun 20, 2009
by
Max-Wilhelm Bruker
Browse files
some changes
parent
9b1adf2d
Changes
26
Hide whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
c8a2ed94
...
...
@@ -14,5 +14,5 @@ QT += network
#
QTPLUGIN
+=
qjpeg
#
Input
HEADERS
+=
src
/
counter
.
h
src
/
dlg_
games
.
h
src
/
dlg_creategame
.
h
src
/
dlg_connect
.
h
src
/
gamesmodel
.
h
src
/
client
.
h
src
/
window_main
.
h
src
/
servergame
.
h
src
/
servereventdata
.
h
src
/
serverresponse
.
h
src
/
pendingcommand
.
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
src
/
decklistmodel
.
h
src
/
dlg_startgame
.
h
src
/
cardinfowidget
.
h
src
/
messagelogwidget
.
h
src
/
serverzonecard
.
h
src
/
zoneviewzone
.
h
src
/
zoneviewwidget
.
h
src
/
libraryzone
.
h
src
/
gravezone
.
h
src
/
rfgzone
.
h
src
/
sideboard
zone
.
h
src
/
carddragitem
.
h
src
/
zoneviewlayout
.
h
src
/
playerarea
.
h
src
/
carddatabasemodel
.
h
src
/
window_deckeditor
.
h
src
/
decklist
.
h
SOURCES
+=
src
/
counter
.
cpp
src
/
dlg_
games
.
cpp
src
/
dlg_creategame
.
cpp
src
/
dlg_connect
.
cpp
src
/
client
.
cpp
src
/
main
.
cpp
src
/
window_main
.
cpp
src
/
servereventdata
.
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
src
/
decklistmodel
.
cpp
src
/
dlg_startgame
.
cpp
src
/
cardinfowidget
.
cpp
src
/
messagelogwidget
.
cpp
src
/
zoneviewzone
.
cpp
src
/
zoneviewwidget
.
cpp
src
/
libraryzone
.
cpp
src
/
gravezone
.
cpp
src
/
rfgzone
.
cpp
src
/
sideboard
zone
.
cpp
src
/
carddragitem
.
cpp
src
/
zoneviewlayout
.
cpp
src
/
playerarea
.
cpp
src
/
carddatabasemodel
.
cpp
src
/
window_deckeditor
.
cpp
src
/
decklist
.
cpp
HEADERS
+=
src
/
counter
.
h
src
/
games
elector
.
h
src
/
dlg_creategame
.
h
src
/
dlg_connect
.
h
src
/
gamesmodel
.
h
src
/
client
.
h
src
/
window_main
.
h
src
/
servergame
.
h
src
/
servereventdata
.
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
src
/
decklistmodel
.
h
src
/
dlg_startgame
.
h
src
/
cardinfowidget
.
h
src
/
messagelogwidget
.
h
src
/
serverzonecard
.
h
src
/
zoneviewzone
.
h
src
/
zoneviewwidget
.
h
src
/
libraryzone
.
h
src
/
pile
zone
.
h
src
/
carddragitem
.
h
src
/
zoneviewlayout
.
h
src
/
playerarea
.
h
src
/
carddatabasemodel
.
h
src
/
window_deckeditor
.
h
src
/
decklist
.
h
SOURCES
+=
src
/
counter
.
cpp
src
/
games
elector
.
cpp
src
/
dlg_creategame
.
cpp
src
/
dlg_connect
.
cpp
src
/
client
.
cpp
src
/
main
.
cpp
src
/
window_main
.
cpp
src
/
servereventdata
.
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
src
/
decklistmodel
.
cpp
src
/
dlg_startgame
.
cpp
src
/
cardinfowidget
.
cpp
src
/
messagelogwidget
.
cpp
src
/
zoneviewzone
.
cpp
src
/
zoneviewwidget
.
cpp
src
/
libraryzone
.
cpp
src
/
pile
zone
.
cpp
src
/
carddragitem
.
cpp
src
/
zoneviewlayout
.
cpp
src
/
playerarea
.
cpp
src
/
carddatabasemodel
.
cpp
src
/
window_deckeditor
.
cpp
src
/
decklist
.
cpp
cockatrice/src/client.cpp
View file @
c8a2ed94
#include
<QTimer>
#include
"client.h"
PendingCommand
::
PendingCommand
(
const
QString
&
_cmd
,
int
_msgid
,
QObject
*
parent
)
:
QObject
(
parent
),
cmd
(
_cmd
),
msgid
(
_msgid
),
time
(
0
)
{
}
void
PendingCommand
::
responseReceived
(
int
_msgid
,
ServerResponse
_resp
)
{
if
(
_msgid
==
msgid
)
{
emit
finished
(
_resp
);
deleteLater
();
}
}
void
PendingCommand
::
checkTimeout
()
{
if
(
++
time
>
5
)
emit
timeout
();
}
Client
::
Client
(
QObject
*
parent
)
:
QObject
(
parent
),
status
(
StatusDisconnected
),
MsgId
(
0
)
{
timer
=
new
QTimer
(
this
);
timer
->
setInterval
(
1000
);
connect
(
timer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
checkTimeout
()));
connect
(
timer
,
SIGNAL
(
timeout
()),
this
,
SLOT
(
ping
()));
socket
=
new
QTcpSocket
(
this
);
socket
->
setTextModeEnabled
(
true
);
...
...
@@ -20,22 +39,10 @@ Client::~Client()
disconnectFromServer
();
}
void
Client
::
checkT
imeout
()
void
Client
::
t
imeout
()
{
bool
timeout
=
false
;
QListIterator
<
PendingCommand
*>
i
(
PendingCommands
);
while
(
i
.
hasNext
())
{
PendingCommand
*
c
=
i
.
next
();
if
(
c
->
timeout
())
{
timeout
=
true
;
break
;
}
}
if
(
timeout
)
{
disconnectFromServer
();
emit
serverTimeout
();
}
else
ping
();
emit
serverTimeout
();
disconnectFromServer
();
}
void
Client
::
slotSocketError
(
QAbstractSocket
::
SocketError
/*error*/
)
...
...
@@ -50,6 +57,33 @@ void Client::slotConnected()
setStatus
(
StatusAwaitingWelcome
);
}
void
Client
::
removePendingCommand
()
{
PendingCommands
.
removeAt
(
PendingCommands
.
indexOf
(
static_cast
<
PendingCommand
*>
(
sender
())));
}
void
Client
::
loginResponse
(
ServerResponse
response
)
{
if
(
response
==
RespOk
)
setStatus
(
StatusIdle
);
else
{
emit
serverError
(
response
);
disconnectFromServer
();
}
}
void
Client
::
enterGameResponse
(
ServerResponse
response
)
{
if
(
response
==
RespOk
)
setStatus
(
StatusPlaying
);
}
void
Client
::
leaveGameResponse
(
ServerResponse
response
)
{
if
(
response
==
RespOk
)
setStatus
(
StatusIdle
);
}
void
Client
::
readLine
()
{
while
(
socket
->
canReadLine
())
{
...
...
@@ -57,7 +91,7 @@ void Client::readLine()
if
(
line
.
isNull
())
break
;
qDebug
(
QString
(
"
readLine:
%1"
).
arg
(
line
).
toLatin1
());
qDebug
(
QString
(
"
<<
%1"
).
arg
(
line
).
toLatin1
());
QStringList
values
=
line
.
split
(
"|"
);
QString
prefix
=
values
.
takeFirst
();
// prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone}
...
...
@@ -87,29 +121,14 @@ void Client::readLine()
// XXX
}
ok
=
!
values
.
takeFirst
().
compare
(
"ok"
);
// XXX
ServerErrorMessage
message
=
msgNone
;
// Update list of pending commands
QListIterator
<
PendingCommand
*>
i
(
PendingCommands
);
bool
found
=
false
;
PendingCommand
*
c
;
while
(
i
.
hasNext
())
{
c
=
i
.
next
();
if
(
c
->
getMsgId
()
==
msgid
)
{
found
=
true
;
break
;
}
}
if
(
found
)
{
PendingCommands
.
removeAt
(
PendingCommands
.
indexOf
(
c
));
delete
c
;
}
else
qDebug
(
QString
(
"msgid unknown: %1"
).
arg
(
msgid
).
toLatin1
());
emit
responseReceived
(
new
ServerResponse
(
msgid
,
ok
,
message
));
ServerResponse
resp
;
if
(
values
[
0
]
==
"ok"
)
resp
=
RespOk
;
else
if
(
values
[
1
]
==
"password"
)
resp
=
RespPassword
;
else
resp
=
RespErr
;
emit
responseReceived
(
msgid
,
resp
);
}
else
if
(
prefix
==
"list_games"
)
{
emit
gameListEvent
(
new
ServerGame
(
values
[
0
].
toInt
(),
values
[
5
],
values
[
1
],
values
[
2
].
toInt
(),
values
[
3
].
toInt
(),
values
[
4
].
toInt
()));
}
else
if
((
prefix
==
"list_players"
)
||
(
prefix
==
"list_counters"
)
||
(
prefix
==
"list_zones"
)
||
(
prefix
==
"dump_zone"
)
||
(
prefix
==
"welcome"
))
{
...
...
@@ -124,29 +143,29 @@ void Client::readLine()
QStringList
val
=
i
.
next
();
// XXX Parametergültigkeit überprüfen
if
(
!
prefix
.
compare
(
"list_players"
)
)
if
(
prefix
==
"list_players"
)
playerlist
<<
new
ServerPlayer
(
val
[
0
].
toInt
(),
val
[
1
]);
else
if
(
!
prefix
.
compare
(
"list_counters"
)
)
else
if
(
prefix
==
"list_counters"
)
{
}
else
if
(
!
prefix
.
compare
(
"list_zones"
)
)
else
if
(
prefix
==
"list_zones"
)
zonelist
<<
new
ServerZone
(
val
[
0
],
val
[
1
]
==
"1"
,
val
[
2
]
==
"1"
,
val
[
3
].
toInt
());
else
if
(
!
prefix
.
compare
(
"dump_zone"
)
)
else
if
(
prefix
==
"dump_zone"
)
zonedump
<<
new
ServerZoneCard
(
val
[
0
].
toInt
(),
val
[
1
],
val
[
2
].
toInt
(),
val
[
3
].
toInt
(),
val
[
4
].
toInt
(),
val
[
5
]
==
"1"
,
val
[
6
]);
else
if
(
!
prefix
.
compare
(
"welcome"
)
)
else
if
(
prefix
==
"welcome"
)
welcomemsg
<<
val
[
0
];
}
if
(
!
prefix
.
compare
(
"list_players"
)
)
if
(
prefix
==
"list_players"
)
emit
playerListReceived
(
playerlist
);
else
if
(
!
prefix
.
compare
(
"list_counters"
)
)
else
if
(
prefix
==
"list_counters"
)
{
}
else
if
(
!
prefix
.
compare
(
"list_zones"
)
)
else
if
(
prefix
==
"list_zones"
)
emit
zoneListReceived
(
cmdid
,
zonelist
);
else
if
(
!
prefix
.
compare
(
"dump_zone"
)
)
else
if
(
prefix
==
"dump_zone"
)
emit
zoneDumpReceived
(
cmdid
,
zonedump
);
else
if
(
!
prefix
.
compare
(
"welcome"
)
)
{
else
if
(
prefix
==
"welcome"
)
{
emit
welcomeMsgReceived
(
welcomemsg
);
setStatus
(
Status
Connected
);
login
(
P
layerName
,
password
);
setStatus
(
Status
LoggingIn
);
login
(
p
layerName
,
password
);
}
msgbuf
.
clear
();
}
else
...
...
@@ -165,23 +184,27 @@ void Client::setStatus(const ProtocolStatus _status)
void
Client
::
msg
(
const
QString
&
s
)
{
qDebug
(
QString
(
"
msg gibt aus:
%1"
).
arg
(
s
).
toLatin1
());
qDebug
(
QString
(
"
>>
%1"
).
arg
(
s
).
toLatin1
());
QTextStream
stream
(
socket
);
stream
.
setCodec
(
"UTF-8"
);
stream
<<
s
<<
endl
;
stream
.
flush
();
}
int
Client
::
cmd
(
const
QString
&
s
)
PendingCommand
*
Client
::
cmd
(
const
QString
&
s
)
{
msg
(
QString
(
"%1|%2"
).
arg
(
++
MsgId
).
arg
(
s
));
PendingCommands
<<
new
PendingCommand
(
s
,
MsgId
);
return
MsgId
;
PendingCommand
*
pc
=
new
PendingCommand
(
s
,
MsgId
,
this
);
PendingCommands
<<
pc
;
connect
(
this
,
SIGNAL
(
responseReceived
(
int
,
ServerResponse
)),
pc
,
SLOT
(
responseReceived
(
int
,
ServerResponse
)));
connect
(
pc
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
removePendingCommand
()));
connect
(
timer
,
SIGNAL
(
timeout
()),
pc
,
SLOT
(
checkTimeout
()));
return
pc
;
}
void
Client
::
connectToServer
(
const
QString
&
hostname
,
unsigned
int
port
,
const
QString
&
player
n
ame
,
const
QString
&
_password
)
void
Client
::
connectToServer
(
const
QString
&
hostname
,
unsigned
int
port
,
const
QString
&
_
player
N
ame
,
const
QString
&
_password
)
{
P
layerName
=
player
n
ame
;
p
layerName
=
_
player
N
ame
;
password
=
_password
;
socket
->
connectToHost
(
hostname
,
port
);
setStatus
(
StatusConnecting
);
...
...
@@ -199,74 +222,82 @@ void Client::disconnectFromServer()
socket
->
close
();
}
int
Client
::
ping
()
void
Client
::
ping
()
{
return
cmd
(
"ping"
);
cmd
(
"ping"
);
}
int
Client
::
listGames
()
PendingCommand
*
Client
::
listGames
()
{
return
cmd
(
"list_games"
);
}
int
Client
::
listPlayers
()
PendingCommand
*
Client
::
listPlayers
()
{
return
cmd
(
"list_players"
);
}
int
Client
::
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
)
PendingCommand
*
Client
::
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
)
{
return
cmd
(
QString
(
"create_game|%1|%2|%3"
).
arg
(
description
).
arg
(
password
).
arg
(
maxPlayers
));
PendingCommand
*
pc
=
cmd
(
QString
(
"create_game|%1|%2|%3"
).
arg
(
description
).
arg
(
password
).
arg
(
maxPlayers
));
connect
(
pc
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
enterGameResponse
(
ServerResponse
)));
return
pc
;
}
int
Client
::
joinGame
(
int
gameId
,
const
QString
&
password
)
PendingCommand
*
Client
::
joinGame
(
int
gameId
,
const
QString
&
password
)
{
return
cmd
(
QString
(
"join_game|%1|%2"
).
arg
(
gameId
).
arg
(
password
));
PendingCommand
*
pc
=
cmd
(
QString
(
"join_game|%1|%2"
).
arg
(
gameId
).
arg
(
password
));
connect
(
pc
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
enterGameResponse
(
ServerResponse
)));
return
pc
;
}
int
Client
::
leaveGame
()
PendingCommand
*
Client
::
leaveGame
()
{
return
cmd
(
"leave_game"
);
PendingCommand
*
pc
=
cmd
(
"leave_game"
);
connect
(
pc
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
leaveGameResponse
(
ServerResponse
)));
return
pc
;
}
int
Client
::
login
(
const
QString
&
name
,
const
QString
&
pass
)
PendingCommand
*
Client
::
login
(
const
QString
&
name
,
const
QString
&
pass
)
{
return
cmd
(
QString
(
"login|%1|%2"
).
arg
(
name
).
arg
(
pass
));
PendingCommand
*
pc
=
cmd
(
QString
(
"login|%1|%2"
).
arg
(
name
).
arg
(
pass
));
connect
(
pc
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
loginResponse
(
ServerResponse
)));
return
pc
;
}
int
Client
::
say
(
const
QString
&
s
)
PendingCommand
*
Client
::
say
(
const
QString
&
s
)
{
return
cmd
(
QString
(
"say|%1"
).
arg
(
s
));
}
int
Client
::
shuffle
()
PendingCommand
*
Client
::
shuffle
()
{
return
cmd
(
"shuffle"
);
}
int
Client
::
rollDice
(
unsigned
int
sides
)
PendingCommand
*
Client
::
rollDice
(
unsigned
int
sides
)
{
return
cmd
(
QString
(
"roll_dice|%1"
).
arg
(
sides
));
}
int
Client
::
drawCards
(
unsigned
int
number
)
PendingCommand
*
Client
::
drawCards
(
unsigned
int
number
)
{
return
cmd
(
QString
(
"draw_cards|%1"
).
arg
(
number
));
}
int
Client
::
moveCard
(
int
cardid
,
const
QString
&
startzone
,
const
QString
&
targetzone
,
int
x
,
int
y
,
bool
faceDown
)
PendingCommand
*
Client
::
moveCard
(
int
cardid
,
const
QString
&
startzone
,
const
QString
&
targetzone
,
int
x
,
int
y
,
bool
faceDown
)
{
// if startzone is public: cardid is the card's id
// else: cardid is the position of the card in the zone (e.g. deck)
return
cmd
(
QString
(
"move_card|%1|%2|%3|%4|%5|%6"
).
arg
(
cardid
).
arg
(
startzone
).
arg
(
targetzone
).
arg
(
x
).
arg
(
y
).
arg
(
faceDown
?
1
:
0
));
}
int
Client
::
createToken
(
const
QString
&
zone
,
const
QString
&
name
,
const
QString
&
powtough
,
int
x
,
int
y
)
PendingCommand
*
Client
::
createToken
(
const
QString
&
zone
,
const
QString
&
name
,
const
QString
&
powtough
,
int
x
,
int
y
)
{
return
cmd
(
QString
(
"create_token|%1|%2|%3|%4|%5"
).
arg
(
zone
).
arg
(
name
).
arg
(
powtough
).
arg
(
x
).
arg
(
y
));
}
int
Client
::
setCardAttr
(
const
QString
&
zone
,
int
cardid
,
const
QString
&
aname
,
const
QString
&
avalue
)
PendingCommand
*
Client
::
setCardAttr
(
const
QString
&
zone
,
int
cardid
,
const
QString
&
aname
,
const
QString
&
avalue
)
{
return
cmd
(
QString
(
"set_card_attr|%1|%2|%3|%4"
).
arg
(
zone
).
arg
(
cardid
).
arg
(
aname
).
arg
(
avalue
));
}
...
...
@@ -280,42 +311,42 @@ void Client::submitDeck(const QStringList &deck)
msg
(
"."
);
}
int
Client
::
readyStart
()
PendingCommand
*
Client
::
readyStart
()
{
return
cmd
(
"ready_start"
);
}
int
Client
::
incCounter
(
const
QString
&
counter
,
int
delta
)
PendingCommand
*
Client
::
incCounter
(
const
QString
&
counter
,
int
delta
)
{
return
cmd
(
QString
(
"inc_counter|%1|%2"
).
arg
(
counter
).
arg
(
delta
));
}
int
Client
::
addCounter
(
const
QString
&
counter
,
QColor
color
,
int
value
)
PendingCommand
*
Client
::
addCounter
(
const
QString
&
counter
,
QColor
color
,
int
value
)
{
return
cmd
(
QString
(
"add_counter|%1|%2|%3"
).
arg
(
counter
).
arg
(
color
.
red
()
*
65536
+
color
.
green
()
*
256
+
color
.
blue
()).
arg
(
value
));
}
int
Client
::
setCounter
(
const
QString
&
counter
,
int
value
)
PendingCommand
*
Client
::
setCounter
(
const
QString
&
counter
,
int
value
)
{
return
cmd
(
QString
(
"set_counter|%1|%2"
).
arg
(
counter
).
arg
(
value
));
}
int
Client
::
delCounter
(
const
QString
&
counter
)
PendingCommand
*
Client
::
delCounter
(
const
QString
&
counter
)
{
return
cmd
(
QString
(
"del_counter|%1"
).
arg
(
counter
));
}
int
Client
::
setActivePlayer
(
int
player
)
PendingCommand
*
Client
::
setActivePlayer
(
int
player
)
{
return
cmd
(
QString
(
"set_active_player|%1"
).
arg
(
player
));
}
int
Client
::
setActivePhase
(
int
phase
)
PendingCommand
*
Client
::
setActivePhase
(
int
phase
)
{
return
cmd
(
QString
(
"set_active_phase|%1"
).
arg
(
phase
));
}
int
Client
::
dumpZone
(
int
player
,
const
QString
&
zone
,
int
numberCards
)
PendingCommand
*
Client
::
dumpZone
(
int
player
,
const
QString
&
zone
,
int
numberCards
)
{
return
cmd
(
QString
(
"dump_zone|%1|%2|%3"
).
arg
(
player
).
arg
(
zone
).
arg
(
numberCards
));
}
cockatrice/src/client.h
View file @
c8a2ed94
...
...
@@ -2,12 +2,10 @@
#define CLIENT_H
#include
"servereventdata.h"
#include
"serverresponse.h"
#include
"servergame.h"
#include
"serverplayer.h"
#include
"serverzone.h"
#include
"serverzonecard.h"
#include
"pendingcommand.h"
#include
<QTcpSocket>
#include
<QColor>
...
...
@@ -19,7 +17,33 @@ class QTimer;
enum
ProtocolStatus
{
StatusDisconnected
,
StatusConnecting
,
StatusAwaitingWelcome
,
StatusConnected
};
StatusLoggingIn
,
StatusIdle
,
StatusPlaying
};
enum
ServerResponse
{
RespOk
,
RespPassword
,
RespErr
};
class
PendingCommand
:
public
QObject
{
Q_OBJECT
private:
QString
cmd
;
int
msgid
;
int
time
;
signals:
void
finished
(
ServerResponse
resp
);
public
slots
:
void
responseReceived
(
int
_msgid
,
ServerResponse
_resp
);
void
checkTimeout
();
public:
int
getMsgId
()
const
{
return
msgid
;
}
QString
getCmd
()
const
{
return
cmd
;
}
bool
timeout
()
{
return
++
time
>
5
;
}
PendingCommand
(
const
QString
&
_cmd
,
int
_msgid
,
QObject
*
parent
=
0
);
};
class
Client
:
public
QObject
{
Q_OBJECT
...
...
@@ -30,60 +54,62 @@ signals:
void
playerListReceived
(
QList
<
ServerPlayer
*>
players
);
void
zoneListReceived
(
int
commandId
,
QList
<
ServerZone
*>
zones
);
void
zoneDumpReceived
(
int
commandId
,
QList
<
ServerZoneCard
*>
cards
);
void
responseReceived
(
ServerResponse
*
resp
onse
);
void
responseReceived
(
int
msgid
,
ServerResponse
resp
);
void
playerIdReceived
(
int
id
,
QString
name
);
void
gameEvent
(
const
ServerEventData
&
msg
);
void
serverTimeout
();
void
logSocketError
(
const
QString
&
errorString
);
void
serverError
(
ServerResponse
resp
);
private
slots
:
void
slotConnected
();
void
readLine
();
void
checkT
imeout
();
void
t
imeout
();
void
slotSocketError
(
QAbstractSocket
::
SocketError
error
);
void
ping
();
void
removePendingCommand
();
void
loginResponse
(
ServerResponse
response
);
void
enterGameResponse
(
ServerResponse
response
);
void
leaveGameResponse
(
ServerResponse
response
);
private:
QTimer
*
timer
;
QList
<
PendingCommand
*>
PendingCommands
;
QTcpSocket
*
socket
;
ProtocolStatus
status
;
QList
<
QStringList
>
msgbuf
;
QString
PlayerName
;
QString
password
;
QString
playerName
,
password
;
unsigned
int
MsgId
;
void
msg
(
const
QString
&
s
);
int
cmd
(
const
QString
&
s
);
PendingCommand
*
cmd
(
const
QString
&
s
);
void
setStatus
(
const
ProtocolStatus
_status
);
public:
Client
(
QObject
*
parent
=
0
);
~
Client
();
ProtocolStatus
getStatus
()
const
{
return
status
;
}
QString
peerName
()
const
{
return
socket
->
peerName
();
}
void
connectToServer
(
const
QString
&
hostname
,
unsigned
int
port
,
const
QString
&
player
n
ame
,
const
QString
&
password
);
void
connectToServer
(
const
QString
&
hostname
,
unsigned
int
port
,
const
QString
&
_
player
N
ame
,
const
QString
&
_
password
);
void
disconnectFromServer
();
int
ping
();
int
listGames
();
int
listPlayers
();
int
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
);
int
joinGame
(
int
gameId
,
const
QString
&
password
);
int
leaveGame
();
int
login
(
const
QString
&
name
,
const
QString
&
pass
);
int
say
(
const
QString
&
s
);
int
shuffle
();
int
rollDice
(
unsigned
int
sides
);
int
drawCards
(
unsigned
int
number
);
int
moveCard
(
int
cardid
,
const
QString
&
startzone
,
const
QString
&
targetzone
,
int
x
,
int
y
=
0
,
bool
faceDown
=
false
);
int
createToken
(
const
QString
&
zone
,
const
QString
&
name
,
const
QString
&
powtough
,
int
x
,
int
y
);
int
setCardAttr
(
const
QString
&
zone
,
int
cardid
,
const
QString
&
aname
,
const
QString
&
avalue
);
int
readyStart
();
int
incCounter
(
const
QString
&
counter
,
int
delta
);
int
addCounter
(
const
QString
&
counter
,
QColor
color
,
int
value
);
int
setCounter
(
const
QString
&
counter
,
int
value
);
int
delCounter
(
const
QString
&
counter
);
int
setActivePlayer
(
int
player
);
int
setActivePhase
(
int
phase
);
int
dumpZone
(
int
player
,
const
QString
&
zone
,
int
numberCards
);
PendingCommand
*
listGames
();
PendingCommand
*
listPlayers
();
PendingCommand
*
createGame
(
const
QString
&
description
,
const
QString
&
password
,
unsigned
int
maxPlayers
);
PendingCommand
*
joinGame
(
int
gameId
,
const
QString
&
password
);
PendingCommand
*
leaveGame
();
PendingCommand
*
login
(
const
QString
&
name
,
const
QString
&
pass
);
PendingCommand
*
say
(
const
QString
&
s
);
PendingCommand
*
shuffle
();
PendingCommand
*
rollDice
(
unsigned
int
sides
);
PendingCommand
*
drawCards
(
unsigned
int
number
);
PendingCommand
*
moveCard
(
int
cardid
,
const
QString
&
startzone
,
const
QString
&
targetzone
,
int
x
,
int
y
=
0
,
bool
faceDown
=
false
);
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
*
setActivePlayer
(
int
player
);
PendingCommand
*
setActivePhase
(
int
phase
);
PendingCommand
*
dumpZone
(
int
player
,
const
QString
&
zone
,
int
numberCards
);
public
slots
:
void
submitDeck
(
const
QStringList
&
deck
);
};
...
...
cockatrice/src/counter.cpp
View file @
c8a2ed94
...
...
@@ -15,14 +15,12 @@ QRectF Counter::boundingRect() const
void
Counter
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
painter
->
save
();
painter
->
setBrush
(
QBrush
(
color
));
painter
->
drawEllipse
(
boundingRect
());
if
(
value
)
{
painter
->
setFont
(
QFont
(
"Times"
,
16
,
QFont
::
Bold
));
painter
->
drawText
(
boundingRect
(),
Qt
::
AlignCenter
,
QString
::
number
(
value
));
}
painter
->
restore
();
}
void
Counter
::
setValue
(
int
_value
)
...
...
cockatrice/src/dlg_creategame.cpp
View file @
c8a2ed94
...
...
@@ -2,7 +2,7 @@
#include
"dlg_creategame.h"
DlgCreateGame
::
DlgCreateGame
(
Client
*
_client
,
QWidget
*
parent
)
:
QDialog
(
parent
),
client
(
_client
)
,
msgid
(
0
)
:
QDialog
(
parent
),
client
(
_client
)
{
descriptionLabel
=
new
QLabel
(
tr
(
"&Description:"
));
descriptionEdit
=
new
QLineEdit
;
...
...
@@ -27,50 +27,48 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
okButton
=
new
QPushButton
(
tr
(
"&OK"
));
okButton
->
setDefault
(
true
);
cancelButton
=
new
QPushButton
(
tr
(
"&Cancel"
));
QHBoxLayout
*
buttonLayout
=
new
QHBoxLayout
;
buttonLayout
->
addStretch
();
buttonLayout
->
addWidget
(
okButton
);
buttonLayout
->
addWidget
(
cancelButton
);
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addLayout
(
grid
);
mainLayout
->
addLayout
(
buttonLayout
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Create game"
));
setFixedHeight
(
sizeHint
().
height
());
connect
(
okButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actOK
()));
connect
(
cancelButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
reject
()));
connect
(
client
,
SIGNAL
(
responseReceived
(
ServerResponse
*
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
*
)));
}
void
DlgCreateGame
::
actOK
()
{
bool
ok
;
int
maxPlayers
=
maxPlayersEdit
->
text
().
toInt
(
&
ok
);
if
(
msgid
)
return
;
if
(
!
ok
)
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"Invalid number of players."
));
return
;
}
msgid
=
client
->
createGame
(
descriptionEdit
->
text
(),
passwordEdit
->
text
(),
maxPlayers
);
PendingCommand
*
createCommand
=
client
->
createGame
(
descriptionEdit
->
text
(),
passwordEdit
->
text
(),
maxPlayers
);
connect
(
createCommand
,
SIGNAL
(
finished
(
ServerResponse
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
)));
okButton
->
setEnabled
(
false
);
cancelButton
->
setEnabled
(
false
);
}
void
DlgCreateGame
::
checkResponse
(
ServerResponse
*
response
)
void
DlgCreateGame
::
checkResponse
(
ServerResponse
response
)
{
if
(
response
->
getMsgId
()
!=
msgid
)
return
;
if
(
response
->
getOk
())
okButton
->
setEnabled
(
true
);
cancelButton
->
setEnabled
(
true
);
if
(
response
==
RespOk
)
accept
();
else
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"XXX"
));
msgid
=
0
;
return
;
}
}
cockatrice/src/dlg_creategame.h
View file @
c8a2ed94
...
...
@@ -14,15 +14,14 @@ public:
DlgCreateGame
(
Client
*
_client
,
QWidget
*
parent
=
0
);
private
slots
:
void
actOK
();
void
checkResponse
(
ServerResponse
*
response
);
void
checkResponse
(
ServerResponse
response
);
private:
Client
*
client
;
int
msgid
;
QLabel
*
descriptionLabel
,
*
passwordLabel
,
*
maxPlayersLabel
;
QLineEdit
*
descriptionEdit
,
*
passwordEdit
,
*
maxPlayersEdit
;
QPushButton
*
okButton
,
*
cancelButton
;
};
#endif
cockatrice/src/dlg_games.cpp
deleted
100644 → 0
View file @
9b1adf2d
#include
<QtGui>
#include
"dlg_games.h"
#include
"dlg_creategame.h"
DlgGames
::
DlgGames
(
Client
*
_client
,
QWidget
*
parent
)
:
QDialog
(
parent
),
client
(
_client
),
msgid
(
0
)
{
gameListView
=
new
QTreeView
;
gameListModel
=
new
GamesModel
(
this
);
gameListView
->
setModel
(
gameListModel
);
createButton
=
new
QPushButton
(
tr
(
"&Create"
));
joinButton
=
new
QPushButton
(
tr
(
"&Join"
));
QHBoxLayout
*
buttonLayout
=
new
QHBoxLayout
;
buttonLayout
->
addStretch
();
buttonLayout
->
addWidget
(
createButton
);
buttonLayout
->
addWidget
(
joinButton
);
QVBoxLayout
*
mainLayout
=
new
QVBoxLayout
;
mainLayout
->
addWidget
(
gameListView
);
mainLayout
->
addLayout
(
buttonLayout
);
setLayout
(
mainLayout
);
setWindowTitle
(
tr
(
"Games"
));
setMinimumWidth
(
gameListView
->
columnWidth
(
0
)
*
gameListModel
->
columnCount
());
connect
(
createButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actCreate
()));
connect
(
joinButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
actJoin
()));
connect
(
client
,
SIGNAL
(
gameListEvent
(
ServerGame
*
)),
gameListModel
,
SLOT
(
updateGameList
(
ServerGame
*
)));
client
->
listGames
();
}
void
DlgGames
::
actCreate
()
{
DlgCreateGame
dlg
(
client
,
this
);
if
(
dlg
.
exec
())
accept
();
}
void
DlgGames
::
actRefresh
()
{
client
->
listGames
();
}
void
DlgGames
::
checkResponse
(
ServerResponse
*
response
)
{
if
(
response
->
getMsgId
()
!=
msgid
)
return
;
if
(
response
->
getOk
())
accept
();
else
{
QMessageBox
::
critical
(
this
,
tr
(
"Error"
),
tr
(
"XXX"
));
msgid
=
0
;
return
;
}
}
void
DlgGames
::
actJoin
()
{
if
(
msgid
)
return
;
ServerGame
*
game
=
gameListModel
->
getGame
(
gameListView
->
currentIndex
().
row
());
QString
password
;
if
(
game
->
getHasPassword
())
{
bool
ok
;
password
=
QInputDialog
::
getText
(
this
,
tr
(
"Join game"
),
tr
(
"Password:"
),
QLineEdit
::
Password
,
QString
(),
&
ok
);
if
(
!
ok
)
return
;
}
connect
(
client
,
SIGNAL
(
responseReceived
(
ServerResponse
*
)),
this
,
SLOT
(
checkResponse
(
ServerResponse
*
)));
msgid
=
client
->
joinGame
(
game
->
getGameId
(),
password
);
}
cockatrice/src/dlg_games.h
deleted
100644 → 0
View file @
9b1adf2d
#ifndef DLG_GAMES_H
#define DLG_GAMES_H
#include
<QDialog>
#include
"gamesmodel.h"
#include
"servergame.h"
#include
"client.h"
class
QPushButton
;
class
QTreeView
;
class
DlgGames
:
public
QDialog
{
Q_OBJECT
public:
DlgGames
(
Client
*
_client
,
QWidget
*
parent
=
0
);
private
slots
:
void
actCreate
();
void
actRefresh
();
void
actJoin
();
void
checkResponse
(
ServerResponse
*
response
);
private:
Client
*
client
;
int
msgid
;
QTreeView
*
gameListView
;
GamesModel
*
gameListModel
;
QPushButton
*
refreshButton
,
*
createButton
,
*
joinButton
;
};
#endif
cockatrice/src/gameview.cpp
View file @
c8a2ed94
...
...
@@ -5,7 +5,6 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
{
setBackgroundBrush
(
QBrush
(
QColor
(
0
,
0
,
0
)));
setRenderHints
(
QPainter
::
TextAntialiasing
|
QPainter
::
Antialiasing
/* | QPainter::SmoothPixmapTransform*/
);
// setOptimizationFlags(/*DontClipPainter | */DontSavePainterState);
setDragMode
(
RubberBandDrag
);
// setViewportUpdateMode(FullViewportUpdate);
}
...
...
cockatrice/src/gravezone.cpp
deleted
100644 → 0
View file @
9b1adf2d
#include
<QtGui>
#include
"gravezone.h"
#include
"player.h"
#include
"client.h"
#include
"carddragitem.h"
#include
"zoneviewzone.h"
GraveZone
::
GraveZone
(
Player
*
_p
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
"grave"
,
false
,
false
,
parent
)
{
cards
=
new
CardList
(
true
);
setCacheMode
(
DeviceCoordinateCache
);
// Do not move this line to the parent constructor!
setCursor
(
Qt
::
OpenHandCursor
);
}
QRectF
GraveZone
::
boundingRect
()
const
{
return
QRectF
(
0
,
0
,
CARD_WIDTH
,
CARD_HEIGHT
);
}
void
GraveZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
qDebug
(
"grave: paint"
);
if
(
!
cards
->
isEmpty
())
cards
->
at
(
0
)
->
paint
(
painter
,
option
,
widget
);
painter
->
save
();
paintCardNumberEllipse
(
painter
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
painter
->
restore
();
}
void
GraveZone
::
addCardImpl
(
CardItem
*
card
,
int
x
,
int
/*y*/
)
{
cards
->
insert
(
x
,
card
);
card
->
setPos
(
0
,
0
);
card
->
setVisible
(
false
);
card
->
resetState
();
card
->
setParentItem
(
this
);
}
void
GraveZone
::
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
/*dropPoint*/
,
bool
/*faceDown*/
)
{
player
->
client
->
moveCard
(
cardId
,
startZone
->
getName
(),
getName
(),
0
,
0
);
}
void
GraveZone
::
reorganizeCards
()
{
qDebug
(
QString
(
"grave: reorganize, x=%1, y=%2, w=%3, h=%4"
).
arg
(
boundingRect
().
x
()).
arg
(
boundingRect
().
y
()).
arg
(
boundingRect
().
width
()).
arg
(
boundingRect
().
height
()).
toLatin1
());
update
(
boundingRect
());
}
void
GraveZone
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
CardZone
::
mousePressEvent
(
event
);
if
(
event
->
isAccepted
())
return
;
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
setCursor
(
Qt
::
ClosedHandCursor
);
event
->
accept
();
}
else
event
->
ignore
();
}
void
GraveZone
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
((
event
->
screenPos
()
-
event
->
buttonDownScreenPos
(
Qt
::
LeftButton
)).
manhattanLength
()
<
QApplication
::
startDragDistance
())
return
;
if
(
cards
->
empty
())
return
;
bool
faceDown
=
event
->
modifiers
().
testFlag
(
Qt
::
ShiftModifier
);
CardItem
*
card
=
cards
->
at
(
0
);
CardDragItem
*
drag
=
card
->
createDragItem
(
card
->
getId
(),
event
->
pos
(),
event
->
scenePos
(),
faceDown
);
drag
->
grabMouse
();
setCursor
(
Qt
::
OpenHandCursor
);
}
void
GraveZone
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*/
*
event
*/
)
{
setCursor
(
Qt
::
OpenHandCursor
);
}
cockatrice/src/gravezone.h
deleted
100644 → 0
View file @
9b1adf2d
#ifndef GRAVEZONE_H
#define GRAVEZONE_H
#include
"cardzone.h"
class
GraveZone
:
public
CardZone
{
private:
public:
GraveZone
(
Player
*
_p
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
reorganizeCards
();
void
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
dropPoint
,
bool
faceDown
);
protected:
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
addCardImpl
(
CardItem
*
card
,
int
x
,
int
y
);
};
#endif
cockatrice/src/libraryzone.cpp
View file @
c8a2ed94
...
...
@@ -21,15 +21,15 @@ QRectF LibraryZone::boundingRect() const
void
LibraryZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*/
*
widget
*/
)
{
painter
->
save
();
QSizeF
translatedSize
=
option
->
matrix
.
mapRect
(
boundingRect
()).
size
();
QPixmap
*
translatedPixmap
=
player
->
getDb
()
->
getCard
()
->
getPixmap
(
translatedSize
.
toSize
());
painter
->
drawPixmap
(
boundingRect
(),
*
translatedPixmap
,
translatedPixmap
->
rect
());
paintCardNumberEllipse
(
painter
);
painter
->
save
();
painter
->
resetTransform
();
painter
->
drawPixmap
(
translatedPixmap
->
rect
(),
*
translatedPixmap
,
translatedPixmap
->
rect
());
painter
->
restore
();
paintCardNumberEllipse
(
painter
);
}
void
LibraryZone
::
addCardImpl
(
CardItem
*
card
,
int
x
,
int
/*y*/
)
...
...
cockatrice/src/messagelogwidget.cpp
View file @
c8a2ed94
...
...
@@ -26,6 +26,14 @@ void MessageLogWidget::logSocketError(const QString &errorString)
append
(
errorString
);
}
void
MessageLogWidget
::
logServerError
(
ServerResponse
response
)
{
switch
(
response
)
{
case
RespPassword
:
append
(
tr
(
"Invalid password."
));
break
;
default:
;
}
}
void
MessageLogWidget
::
logPlayerListReceived
(
QStringList
players
)
{
append
(
"---"
);
...
...
cockatrice/src/messagelogwidget.h
View file @
c8a2ed94
...
...
@@ -3,6 +3,7 @@
#include
<QTextEdit>
#include
<QAbstractSocket>
#include
"client.h"
class
Game
;
...
...
@@ -13,6 +14,7 @@ public slots:
void
logConnected
(
const
QStringList
WelcomeMsg
);
void
logDisconnected
();
void
logSocketError
(
const
QString
&
errorString
);
void
logServerError
(
ServerResponse
response
);
private
slots
:
void
logPlayerListReceived
(
QStringList
players
);
void
logJoin
(
QString
playerName
);
...
...
cockatrice/src/pendingcommand.h
deleted
100644 → 0
View file @
9b1adf2d
#ifndef PENDINGCOMMAND_H
#define PENDINGCOMMAND_H
#include
<QString>
class
PendingCommand
{
private:
QString
cmd
;
int
msgid
;
int
time
;
public:
int
getMsgId
()
const
{
return
msgid
;
}
QString
getCmd
()
const
{
return
cmd
;
}
bool
timeout
()
{
return
++
time
>
5
;
}
PendingCommand
(
const
QString
&
_cmd
,
int
_msgid
)
:
cmd
(
_cmd
),
msgid
(
_msgid
),
time
(
0
)
{
}
};
#endif
cockatrice/src/player.cpp
View file @
c8a2ed94
...
...
@@ -174,12 +174,12 @@ void Player::gameEvent(const ServerEventData &event)
zones
.
at
(
i
)
->
reorganizeCards
();
if
(
local
)
{
client
->
addCounter
(
"life"
,
Q
Color
(
"
white
"
)
,
20
);
client
->
addCounter
(
"w"
,
QColor
(
2
00
,
2
00
,
20
0
),
0
);
client
->
addCounter
(
"u"
,
QColor
(
0
,
0
,
2
00
),
0
);
client
->
addCounter
(
"b"
,
QColor
(
1
0
0
,
1
0
0
,
1
0
0
),
0
);
client
->
addCounter
(
"r"
,
QColor
(
2
0
0
,
0
,
0
),
0
);
client
->
addCounter
(
"g"
,
QColor
(
0
,
2
00
,
0
),
0
);
client
->
addCounter
(
"life"
,
Q
t
::
white
,
20
);
client
->
addCounter
(
"w"
,
QColor
(
2
55
,
2
55
,
15
0
),
0
);
client
->
addCounter
(
"u"
,
QColor
(
15
0
,
15
0
,
2
55
),
0
);
client
->
addCounter
(
"b"
,
QColor
(
1
5
0
,
1
5
0
,
1
5
0
),
0
);
client
->
addCounter
(
"r"
,
QColor
(
2
5
0
,
15
0
,
15
0
),
0
);
client
->
addCounter
(
"g"
,
QColor
(
15
0
,
2
55
,
15
0
),
0
);
client
->
addCounter
(
"x"
,
QColor
(
255
,
255
,
255
),
0
);
client
->
addCounter
(
"storm"
,
QColor
(
255
,
255
,
255
),
0
);
}
...
...
cockatrice/src/playerarea.cpp
View file @
c8a2ed94
...
...
@@ -3,9 +3,7 @@
#include
"tablezone.h"
#include
"handzone.h"
#include
"libraryzone.h"
#include
"gravezone.h"
#include
"rfgzone.h"
#include
"sideboardzone.h"
#include
"pilezone.h"
#include
"counter.h"
#include
<QPainter>
...
...
@@ -19,13 +17,13 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
qreal
h
=
deck
->
boundingRect
().
height
()
+
20
;
Grav
eZone
*
grave
=
new
Grav
eZone
(
_player
,
this
);
Pil
eZone
*
grave
=
new
Pil
eZone
(
_player
,
"grave"
,
this
);
grave
->
setPos
(
base
+
QPointF
(
0
,
h
));
Rfg
Zone
*
rfg
=
new
Rfg
Zone
(
_player
,
this
);
Pile
Zone
*
rfg
=
new
Pile
Zone
(
_player
,
"rfg"
,
this
);
rfg
->
setPos
(
base
+
QPointF
(
0
,
2
*
h
));
Sideboard
Zone
*
sb
=
new
Sideboard
Zone
(
_player
,
this
);
Pile
Zone
*
sb
=
new
Pile
Zone
(
_player
,
"sb"
,
this
);
sb
->
setVisible
(
false
);
base
=
QPointF
(
deck
->
boundingRect
().
width
()
+
60
,
0
);
...
...
@@ -38,7 +36,6 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
table
->
setPos
(
base
);
bRect
=
QRectF
(
0
,
0
,
base
.
x
()
+
table
->
boundingRect
().
width
(),
base
.
y
()
+
table
->
boundingRect
().
height
());
qDebug
(
QString
(
"%1"
).
arg
(
bRect
.
width
()).
toLatin1
());
}
PlayerArea
::~
PlayerArea
()
...
...
@@ -53,15 +50,11 @@ QRectF PlayerArea::boundingRect() const
void
PlayerArea
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
painter
->
save
();
painter
->
fillRect
(
boundingRect
(),
QColor
(
200
,
200
,
200
));
painter
->
setFont
(
QFont
(
"Times"
,
16
,
QFont
::
Bold
));
painter
->
setPen
(
QPen
(
Qt
::
black
));
painter
->
drawText
(
QRectF
(
0
,
0
,
CARD_WIDTH
+
60
,
40
),
Qt
::
AlignCenter
,
player
->
getName
());
painter
->
restore
();
}
Counter
*
PlayerArea
::
getCounter
(
const
QString
&
name
,
bool
remove
)
...
...
cockatrice/src/rfgzone.cpp
deleted
100644 → 0
View file @
9b1adf2d
#include
<QtGui>
#include
"rfgzone.h"
#include
"player.h"
#include
"client.h"
#include
"carddragitem.h"
#include
"zoneviewzone.h"
RfgZone
::
RfgZone
(
Player
*
_p
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
"rfg"
,
false
,
false
,
parent
)
{
cards
=
new
CardList
(
true
);
setCacheMode
(
DeviceCoordinateCache
);
// Do not move this line to the parent constructor!
setCursor
(
Qt
::
OpenHandCursor
);
}
QRectF
RfgZone
::
boundingRect
()
const
{
return
QRectF
(
0
,
0
,
CARD_WIDTH
,
CARD_HEIGHT
);
}
void
RfgZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
if
(
!
cards
->
isEmpty
())
cards
->
at
(
0
)
->
paint
(
painter
,
option
,
widget
);
painter
->
save
();
paintCardNumberEllipse
(
painter
);
painter
->
drawRect
(
QRectF
(
0.5
,
0.5
,
CARD_WIDTH
-
1
,
CARD_HEIGHT
-
1
));
painter
->
restore
();
}
void
RfgZone
::
addCardImpl
(
CardItem
*
card
,
int
x
,
int
/*y*/
)
{
cards
->
insert
(
x
,
card
);
card
->
setPos
(
0
,
0
);
card
->
setVisible
(
false
);
card
->
resetState
();
card
->
setParentItem
(
this
);
}
void
RfgZone
::
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
/*dropPoint*/
,
bool
/*faceDown*/
)
{
player
->
client
->
moveCard
(
cardId
,
startZone
->
getName
(),
getName
(),
0
,
0
);
}
void
RfgZone
::
reorganizeCards
()
{
update
(
boundingRect
());
}
void
RfgZone
::
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
CardZone
::
mousePressEvent
(
event
);
if
(
event
->
isAccepted
())
return
;
if
(
event
->
button
()
==
Qt
::
LeftButton
)
{
setCursor
(
Qt
::
ClosedHandCursor
);
event
->
accept
();
}
else
event
->
ignore
();
}
void
RfgZone
::
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
)
{
if
((
event
->
screenPos
()
-
event
->
buttonDownScreenPos
(
Qt
::
LeftButton
)).
manhattanLength
()
<
QApplication
::
startDragDistance
())
return
;
if
(
cards
->
empty
())
return
;
bool
faceDown
=
event
->
modifiers
().
testFlag
(
Qt
::
ShiftModifier
);
CardItem
*
card
=
cards
->
at
(
0
);
CardDragItem
*
drag
=
card
->
createDragItem
(
card
->
getId
(),
event
->
pos
(),
event
->
scenePos
(),
faceDown
);
drag
->
grabMouse
();
setCursor
(
Qt
::
OpenHandCursor
);
}
void
RfgZone
::
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*/
*
event
*/
)
{
setCursor
(
Qt
::
OpenHandCursor
);
}
cockatrice/src/rfgzone.h
deleted
100644 → 0
View file @
9b1adf2d
#ifndef RFGZONE_H
#define RFGZONE_H
#include
"cardzone.h"
class
RfgZone
:
public
CardZone
{
private:
public:
RfgZone
(
Player
*
_p
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
reorganizeCards
();
void
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
dropPoint
,
bool
faceDown
);
protected:
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
void
addCardImpl
(
CardItem
*
card
,
int
x
,
int
y
);
};
#endif
cockatrice/src/serverresponse.h
deleted
100644 → 0
View file @
9b1adf2d
#ifndef SERVERRESPONSE_H
#define SERVERRESPONSE_H
enum
ServerErrorMessage
{
msgNone
,
msgSyntaxError
};
class
ServerResponse
{
private:
int
msgId
;
bool
ok
;
ServerErrorMessage
message
;
public:
ServerResponse
(
int
_msgId
,
bool
_ok
,
ServerErrorMessage
_message
)
:
msgId
(
_msgId
),
ok
(
_ok
),
message
(
_message
)
{
}
int
getMsgId
()
const
{
return
msgId
;
}
bool
getOk
()
const
{
return
ok
;
}
ServerErrorMessage
getMessage
()
const
{
return
message
;
}
};
#endif
Prev
1
2
Next
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