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
0d774b5d
Commit
0d774b5d
authored
Sep 08, 2009
by
Max-Wilhelm Bruker
Browse files
table grid improvement, unfinished
parent
914261df
Changes
16
Show whitespace changes
Inline
Side-by-side
cockatrice/cockatrice.pro
View file @
0d774b5d
...
...
@@ -36,7 +36,6 @@ HEADERS += src/counter.h \
src
/
pilezone
.
h
\
src
/
carddragitem
.
h
\
src
/
zoneviewlayout
.
h
\
src
/
playerarea
.
h
\
src
/
carddatabasemodel
.
h
\
src
/
window_deckeditor
.
h
\
src
/
decklist
.
h
\
...
...
@@ -45,7 +44,8 @@ HEADERS += src/counter.h \
src
/
abstractgraphicsitem
.
h
\
src
/
dlg_settings
.
h
\
src
/
phasestoolbar
.
h
\
src
/
chatwidget
.
h
src
/
chatwidget
.
h
\
src
/
gamescene
.
h
SOURCES
+=
src
/
counter
.
cpp
\
src
/
gameselector
.
cpp
\
src
/
dlg_creategame
.
cpp
\
...
...
@@ -75,7 +75,6 @@ SOURCES += src/counter.cpp \
src
/
pilezone
.
cpp
\
src
/
carddragitem
.
cpp
\
src
/
zoneviewlayout
.
cpp
\
src
/
playerarea
.
cpp
\
src
/
carddatabasemodel
.
cpp
\
src
/
window_deckeditor
.
cpp
\
src
/
decklist
.
cpp
\
...
...
@@ -84,5 +83,6 @@ SOURCES += src/counter.cpp \
src
/
abstractgraphicsitem
.
cpp
\
src
/
dlg_settings
.
cpp
\
src
/
phasestoolbar
.
cpp
\
src
/
chatwidget
.
cpp
src
/
chatwidget
.
cpp
\
src
/
gamescene
.
cpp
TRANSLATIONS
+=
translations
/
cockatrice_de
.
ts
translations
/
cockatrice_en
.
ts
cockatrice/src/carditem.cpp
View file @
0d774b5d
...
...
@@ -241,7 +241,7 @@ void CardItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
else
{
TableZone
*
table
=
(
TableZone
*
)
zone
->
getPlayer
()
->
getZones
()
->
findZone
(
"table"
);
QPoint
gridPoint
=
table
->
getFreeGridPoint
(
info
->
getTableRow
());
table
->
handleDropEvent
(
id
,
zone
,
table
->
mapFromGrid
(
gridPoint
).
toPoint
()
,
false
);
table
->
handleDropEvent
ByGrid
(
id
,
zone
,
gridPoint
,
false
);
}
}
...
...
cockatrice/src/game.cpp
View file @
0d774b5d
#include
<QGraphicsScene>
#include
<QMenu>
#include
<QMessageBox>
#include
<QSettings>
...
...
@@ -11,14 +10,13 @@
#include
"handzone.h"
#include
"carddatabase.h"
#include
"dlg_startgame.h"
#include
"playerarea.h"
#include
"counter.h"
#include
"gamescene.h"
Game
::
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
QGraphics
Scene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
,
QObject
*
parent
)
Game
::
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
Game
Scene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
,
QObject
*
parent
)
:
QObject
(
parent
),
actionsMenu
(
_actionsMenu
),
cardMenu
(
_cardMenu
),
db
(
_db
),
client
(
_client
),
scene
(
_scene
),
started
(
false
),
currentPhase
(
-
1
)
{
QRectF
sr
=
scene
->
sceneRect
();
localPlayer
=
addPlayer
(
playerId
,
playerName
,
QPointF
(
0
,
sr
.
y
()
+
sr
.
height
()
/
2
+
2
),
true
);
localPlayer
=
addPlayer
(
playerId
,
playerName
,
true
);
connect
(
client
,
SIGNAL
(
gameEvent
(
const
ServerEventData
&
)),
this
,
SLOT
(
gameEvent
(
const
ServerEventData
&
)));
connect
(
client
,
SIGNAL
(
playerListReceived
(
QList
<
ServerPlayer
*>
)),
this
,
SLOT
(
playerListReceived
(
QList
<
ServerPlayer
*>
)));
...
...
@@ -186,9 +184,10 @@ void Game::initSayMenu()
}
}
Player
*
Game
::
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
QPointF
base
,
bool
local
)
Player
*
Game
::
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
bool
local
)
{
Player
*
newPlayer
=
new
Player
(
playerName
,
playerId
,
base
,
local
,
db
,
client
,
scene
,
this
);
Player
*
newPlayer
=
new
Player
(
playerName
,
playerId
,
local
,
db
,
client
,
this
);
scene
->
addPlayer
(
newPlayer
);
connect
(
newPlayer
,
SIGNAL
(
sigShowCardMenu
(
QPoint
)),
this
,
SLOT
(
showCardMenu
(
QPoint
)));
connect
(
newPlayer
,
SIGNAL
(
logMoveCard
(
Player
*
,
QString
,
CardZone
*
,
int
,
CardZone
*
,
int
)),
this
,
SIGNAL
(
logMoveCard
(
Player
*
,
QString
,
CardZone
*
,
int
,
CardZone
*
,
int
)));
...
...
@@ -214,7 +213,7 @@ void Game::playerListReceived(QList<ServerPlayer *> playerList)
int
id
=
temp
->
getPlayerId
();
if
(
id
!=
localPlayer
->
getId
())
addPlayer
(
id
,
temp
->
getName
(),
QPointF
(
0
,
0
),
false
);
addPlayer
(
id
,
temp
->
getName
(),
false
);
delete
temp
;
}
...
...
@@ -248,7 +247,7 @@ void Game::gameEvent(const ServerEventData &msg)
emit
logSay
(
p
,
msg
.
getEventData
()[
0
]);
break
;
case
eventJoin
:
{
Player
*
newPlayer
=
addPlayer
(
msg
.
getPlayerId
(),
msg
.
getPlayerName
(),
QPointF
(
0
,
0
),
false
);
Player
*
newPlayer
=
addPlayer
(
msg
.
getPlayerId
(),
msg
.
getPlayerName
(),
false
);
emit
logJoin
(
newPlayer
);
break
;
}
...
...
@@ -387,7 +386,7 @@ void Game::actDecLife()
void
Game
::
actSetLife
()
{
bool
ok
;
int
life
=
QInputDialog
::
getInteger
(
0
,
tr
(
"Set life"
),
tr
(
"New life total:"
),
localPlayer
->
area
->
getCounter
(
"life"
)
->
getValue
(),
0
,
2000000000
,
1
,
&
ok
);
int
life
=
QInputDialog
::
getInteger
(
0
,
tr
(
"Set life"
),
tr
(
"New life total:"
),
localPlayer
->
getCounter
(
"life"
)
->
getValue
(),
0
,
2000000000
,
1
,
&
ok
);
if
(
ok
)
client
->
setCounter
(
"life"
,
life
);
}
...
...
cockatrice/src/game.h
View file @
0d774b5d
...
...
@@ -5,7 +5,7 @@
#include
"playerlist.h"
class
ServerPlayer
;
class
QGraphics
Scene
;
class
Game
Scene
;
class
Player
;
class
Client
;
class
ServerEventData
;
...
...
@@ -29,12 +29,12 @@ private:
CardDatabase
*
db
;
Client
*
client
;
QGraphics
Scene
*
scene
;
Game
Scene
*
scene
;
PlayerList
players
;
Player
*
localPlayer
;
bool
started
;
int
currentPhase
;
Player
*
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
QPointF
base
,
bool
local
);
Player
*
addPlayer
(
int
playerId
,
const
QString
&
playerName
,
bool
local
);
void
initSayMenu
();
public
slots
:
void
actNextPhase
();
...
...
@@ -93,7 +93,7 @@ signals:
void
logSetActivePlayer
(
Player
*
player
);
void
setActivePhase
(
int
phase
);
public:
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
QGraphics
Scene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
,
QObject
*
parent
=
0
);
Game
(
CardDatabase
*
_db
,
Client
*
_client
,
Game
Scene
*
_scene
,
QMenu
*
_actionsMenu
,
QMenu
*
_cardMenu
,
int
playerId
,
const
QString
&
playerName
,
QObject
*
parent
=
0
);
~
Game
();
Player
*
getLocalPlayer
()
const
{
return
localPlayer
;
}
void
retranslateUi
();
...
...
cockatrice/src/gameview.cpp
View file @
0d774b5d
...
...
@@ -7,10 +7,18 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
setRenderHints
(
QPainter
::
TextAntialiasing
|
QPainter
::
Antialiasing
/* | QPainter::SmoothPixmapTransform*/
);
setDragMode
(
RubberBandDrag
);
// setViewportUpdateMode(FullViewportUpdate);
connect
(
scene
,
SIGNAL
(
sceneRectChanged
(
const
QRectF
&
)),
this
,
SLOT
(
updateSceneRect
(
const
QRectF
&
)));
}
void
GameView
::
resizeEvent
(
QResizeEvent
*
event
)
{
QGraphicsView
::
resizeEvent
(
event
);
fitInView
(
scene
()
->
sceneRect
(),
Qt
::
KeepAspectRatio
);
updateSceneRect
(
scene
()
->
sceneRect
());
}
void
GameView
::
updateSceneRect
(
const
QRectF
&
rect
)
{
qDebug
(
QString
(
"updateSceneRect = %1,%2"
).
arg
(
rect
.
width
()).
arg
(
rect
.
height
()).
toLatin1
());
fitInView
(
rect
,
Qt
::
KeepAspectRatio
);
}
cockatrice/src/gameview.h
View file @
0d774b5d
...
...
@@ -4,10 +4,12 @@
#include
<QGraphicsView>
class
GameView
:
public
QGraphicsView
{
Q_OBJECT
protected:
void
resizeEvent
(
QResizeEvent
*
event
);
public
slots
:
void
updateSceneRect
(
const
QRectF
&
rect
);
public:
void
scaleToScene
();
GameView
(
QGraphicsScene
*
scene
,
QWidget
*
parent
=
0
);
};
...
...
cockatrice/src/handzone.cpp
View file @
0d774b5d
...
...
@@ -3,8 +3,8 @@
#include
"player.h"
#include
"client.h"
HandZone
::
HandZone
(
Player
*
_p
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
"hand"
,
false
,
false
,
_p
->
getLocal
(),
parent
)
HandZone
::
HandZone
(
Player
*
_p
,
int
_zoneHeight
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
"hand"
,
false
,
false
,
_p
->
getLocal
(),
parent
)
,
zoneHeight
(
_zoneHeight
)
{
QSettings
settings
;
QString
bgPath
=
settings
.
value
(
"zonebg/hand"
).
toString
();
...
...
@@ -17,7 +17,7 @@ HandZone::HandZone(Player *_p, QGraphicsItem *parent)
QRectF
HandZone
::
boundingRect
()
const
{
return
QRectF
(
0
,
0
,
100
,
578
);
return
QRectF
(
0
,
0
,
100
,
zoneHeight
);
}
void
HandZone
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
...
...
cockatrice/src/handzone.h
View file @
0d774b5d
...
...
@@ -6,8 +6,9 @@
class
HandZone
:
public
CardZone
{
private:
QPixmap
bgPixmap
;
int
zoneHeight
;
public:
HandZone
(
Player
*
_p
,
QGraphicsItem
*
parent
=
0
);
HandZone
(
Player
*
_p
,
int
_zoneHeight
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
);
void
reorganizeCards
();
...
...
cockatrice/src/player.cpp
View file @
0d774b5d
#include
"player.h"
#include
"client.h"
#include
"cardzone.h"
#include
"playerarea.h"
#include
"counter.h"
#include
"zoneviewzone.h"
#include
"zoneviewwidget.h"
#include
"game.h"
#include
<QGraphicsScene>
#include
"pilezone.h"
#include
"tablezone.h"
#include
"handzone.h"
#include
<QSettings>
#include
<QPainter>
#include
<QMenu>
Player
::
Player
(
const
QString
&
_name
,
int
_id
,
QPointF
_base
,
bool
_local
,
CardDatabase
*
_db
,
Client
*
_client
,
QGraphicsScene
*
_scene
,
Game
*
_parent
)
:
QObject
(
_parent
),
defaultNumberTopCards
(
3
),
name
(
_name
),
id
(
_id
),
active
(
false
),
base
(
_base
),
local
(
_local
),
db
(
_db
),
client
(
_client
)
Player
::
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
CardDatabase
*
_db
,
Client
*
_client
,
Game
*
_parent
)
:
QObject
(
_parent
),
defaultNumberTopCards
(
3
),
name
(
_name
),
id
(
_id
),
active
(
false
),
local
(
_local
),
db
(
_db
),
client
(
_client
)
{
area
=
new
PlayerArea
(
this
);
area
->
setPos
(
_base
);
_scene
->
addItem
(
area
);
QSettings
settings
;
QString
bgPath
=
settings
.
value
(
"zonebg/playerarea"
).
toString
();
if
(
!
bgPath
.
isEmpty
())
bgPixmap
.
load
(
bgPath
);
setCacheMode
(
DeviceCoordinateCache
);
QPointF
base
=
QPointF
(
55
,
50
);
PileZone
*
deck
=
new
PileZone
(
this
,
"deck"
,
true
,
false
,
this
);
deck
->
setPos
(
base
);
qreal
h
=
deck
->
boundingRect
().
height
()
+
20
;
PileZone
*
grave
=
new
PileZone
(
this
,
"grave"
,
false
,
true
,
this
);
grave
->
setPos
(
base
+
QPointF
(
0
,
h
));
PileZone
*
rfg
=
new
PileZone
(
this
,
"rfg"
,
false
,
true
,
this
);
rfg
->
setPos
(
base
+
QPointF
(
0
,
2
*
h
));
PileZone
*
sb
=
new
PileZone
(
this
,
"sb"
,
false
,
true
,
this
);
sb
->
setVisible
(
false
);
CardZone
*
table
=
new
TableZone
(
this
,
this
);
CardZone
*
hand
=
new
HandZone
(
this
,
table
->
boundingRect
().
height
(),
this
);
base
=
QPointF
(
deck
->
boundingRect
().
width
()
+
60
,
0
);
hand
->
setPos
(
base
);
base
+=
QPointF
(
hand
->
boundingRect
().
width
(),
0
);
table
->
setPos
(
base
);
bRect
=
QRectF
(
0
,
0
,
base
.
x
()
+
table
->
boundingRect
().
width
(),
base
.
y
()
+
table
->
boundingRect
().
height
());
if
(
local
)
{
aMoveHandToTopLibrary
=
new
QAction
(
this
);
...
...
@@ -93,7 +124,7 @@ Player::~Player()
for
(
int
i
=
0
;
i
<
zones
.
size
();
i
++
)
delete
zones
.
at
(
i
);
delete
area
;
clearCounters
()
;
}
void
Player
::
retranslateUi
()
...
...
@@ -230,7 +261,7 @@ void Player::gameEvent(const ServerEventData &event)
zones
.
at
(
i
)
->
clearContents
();
}
area
->
clearCounters
();
clearCounters
();
CardZone
*
deck
=
zones
.
findZone
(
"deck"
);
for
(;
deck_cards
;
deck_cards
--
)
...
...
@@ -359,7 +390,7 @@ void Player::gameEvent(const ServerEventData &event)
int
colorValue
=
data
[
1
].
toInt
();
int
value
=
data
[
2
].
toInt
();
QColor
color
(
colorValue
/
65536
,
(
colorValue
%
65536
)
/
256
,
colorValue
%
256
);
area
->
addCounter
(
counterName
,
color
,
value
);
addCounter
(
counterName
,
color
,
value
);
break
;
}
case
eventSetCounter
:
{
...
...
@@ -368,7 +399,7 @@ void Player::gameEvent(const ServerEventData &event)
}
int
value
=
data
[
1
].
toInt
();
QString
counterName
=
data
[
0
];
Counter
*
c
=
area
->
getCounter
(
counterName
);
Counter
*
c
=
getCounter
(
counterName
);
int
oldValue
=
c
->
getValue
();
c
->
setValue
(
value
);
emit
logSetCounter
(
this
,
c
->
getName
(),
value
,
oldValue
);
...
...
@@ -387,5 +418,90 @@ void Player::showCardMenu(const QPoint &p)
void
Player
::
setActive
(
bool
_active
)
{
active
=
_active
;
area
->
update
();
update
();
}
QRectF
Player
::
boundingRect
()
const
{
return
bRect
;
}
void
Player
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
if
(
bgPixmap
.
isNull
())
painter
->
fillRect
(
boundingRect
(),
QColor
(
200
,
200
,
200
));
else
painter
->
fillRect
(
boundingRect
(),
QBrush
(
bgPixmap
));
QString
nameStr
=
getName
();
QFont
font
(
"Times"
);
font
.
setPixelSize
(
20
);
// font.setWeight(QFont::Bold);
int
totalWidth
=
CARD_WIDTH
+
60
;
if
(
getActive
())
{
QFontMetrics
fm
(
font
);
double
w
=
fm
.
width
(
nameStr
)
*
1.7
;
double
h
=
fm
.
height
()
*
1.7
;
if
(
w
<
h
)
w
=
h
;
painter
->
setPen
(
Qt
::
transparent
);
QRadialGradient
grad
(
QPointF
(
0.5
,
0.5
),
0.5
);
grad
.
setCoordinateMode
(
QGradient
::
ObjectBoundingMode
);
grad
.
setColorAt
(
0
,
QColor
(
150
,
200
,
150
,
255
));
grad
.
setColorAt
(
0.7
,
QColor
(
150
,
200
,
150
,
255
));
grad
.
setColorAt
(
1
,
QColor
(
150
,
150
,
150
,
0
));
painter
->
setBrush
(
QBrush
(
grad
));
painter
->
drawEllipse
(
QRectF
(((
double
)
(
totalWidth
-
w
))
/
2
,
0
,
w
,
h
));
}
painter
->
setFont
(
font
);
painter
->
setPen
(
QPen
(
Qt
::
black
));
painter
->
drawText
(
QRectF
(
0
,
0
,
totalWidth
,
40
),
Qt
::
AlignCenter
,
nameStr
);
}
Counter
*
Player
::
getCounter
(
const
QString
&
name
,
bool
remove
)
{
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
));
rearrangeCounters
();
}
void
Player
::
delCounter
(
const
QString
&
name
)
{
delete
getCounter
(
name
,
true
);
rearrangeCounters
();
}
void
Player
::
clearCounters
()
{
for
(
int
i
=
0
;
i
<
counterList
.
size
();
i
++
)
delete
counterList
.
at
(
i
);
counterList
.
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
;
}
}
cockatrice/src/player.h
View file @
0d774b5d
...
...
@@ -10,11 +10,11 @@ class Client;
class
CardDatabase
;
class
QMenu
;
class
QAction
;
class
PlayerArea
;
class
ZoneViewZone
;
class
Game
;
class
Counter
;
class
Player
:
public
QObject
{
class
Player
:
public
QObject
,
public
QGraphicsItem
{
Q_OBJECT
signals:
void
moveCard
(
int
cardId
,
QString
startZone
,
QString
targetZone
,
int
x
,
int
y
);
...
...
@@ -52,16 +52,30 @@ private:
QString
name
;
int
id
;
bool
active
;
QPointF
base
;
bool
local
;
ZoneList
zones
;
CardDatabase
*
db
;
void
setCardAttrHelper
(
CardItem
*
card
,
const
QString
&
aname
,
const
QString
&
avalue
,
bool
allCards
);
QPixmap
bgPixmap
;
QRectF
bRect
;
QList
<
Counter
*>
counterList
;
void
rearrangeCounters
();
public:
PlayerArea
*
area
;
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
clearCounters
();
Client
*
client
;
void
addZone
(
CardZone
*
z
);
Player
(
const
QString
&
_name
,
int
_id
,
QPointF
_base
,
bool
_local
,
CardDatabase
*
_db
,
Client
*
_client
,
QGraphicsScene
*
_scene
,
Game
*
_parent
);
Player
(
const
QString
&
_name
,
int
_id
,
bool
_local
,
CardDatabase
*
_db
,
Client
*
_client
,
Game
*
_parent
);
~
Player
();
void
retranslateUi
();
QMenu
*
getPlayerMenu
()
const
{
return
playerMenu
;
}
...
...
cockatrice/src/playerarea.cpp
deleted
100644 → 0
View file @
914261df
#include
"playerarea.h"
#include
"player.h"
#include
"tablezone.h"
#include
"handzone.h"
#include
"pilezone.h"
#include
"counter.h"
#include
<QPainter>
#include
<QSettings>
PlayerArea
::
PlayerArea
(
Player
*
_player
,
QGraphicsItem
*
parent
)
:
QGraphicsItem
(
parent
),
player
(
_player
)
{
QSettings
settings
;
QString
bgPath
=
settings
.
value
(
"zonebg/playerarea"
).
toString
();
if
(
!
bgPath
.
isEmpty
())
bgPixmap
.
load
(
bgPath
);
setCacheMode
(
DeviceCoordinateCache
);
QPointF
base
=
QPointF
(
55
,
50
);
PileZone
*
deck
=
new
PileZone
(
_player
,
"deck"
,
true
,
false
,
this
);
deck
->
setPos
(
base
);
qreal
h
=
deck
->
boundingRect
().
height
()
+
20
;
PileZone
*
grave
=
new
PileZone
(
_player
,
"grave"
,
false
,
true
,
this
);
grave
->
setPos
(
base
+
QPointF
(
0
,
h
));
PileZone
*
rfg
=
new
PileZone
(
_player
,
"rfg"
,
false
,
true
,
this
);
rfg
->
setPos
(
base
+
QPointF
(
0
,
2
*
h
));
PileZone
*
sb
=
new
PileZone
(
_player
,
"sb"
,
false
,
true
,
this
);
sb
->
setVisible
(
false
);
base
=
QPointF
(
deck
->
boundingRect
().
width
()
+
60
,
0
);
CardZone
*
hand
=
new
HandZone
(
_player
,
this
);
hand
->
setPos
(
base
);
base
+=
QPointF
(
hand
->
boundingRect
().
width
(),
0
);
CardZone
*
table
=
new
TableZone
(
_player
,
this
);
table
->
setPos
(
base
);
bRect
=
QRectF
(
0
,
0
,
base
.
x
()
+
table
->
boundingRect
().
width
(),
base
.
y
()
+
table
->
boundingRect
().
height
());
}
PlayerArea
::~
PlayerArea
()
{
clearCounters
();
}
QRectF
PlayerArea
::
boundingRect
()
const
{
return
bRect
;
}
void
PlayerArea
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*/
*
option
*/
,
QWidget
*/
*
widget
*/
)
{
if
(
bgPixmap
.
isNull
())
painter
->
fillRect
(
boundingRect
(),
QColor
(
200
,
200
,
200
));
else
painter
->
fillRect
(
boundingRect
(),
QBrush
(
bgPixmap
));
QString
nameStr
=
player
->
getName
();
QFont
font
(
"Times"
);
font
.
setPixelSize
(
20
);
// font.setWeight(QFont::Bold);
int
totalWidth
=
CARD_WIDTH
+
60
;
if
(
player
->
getActive
())
{
QFontMetrics
fm
(
font
);
double
w
=
fm
.
width
(
nameStr
)
*
1.7
;
double
h
=
fm
.
height
()
*
1.7
;
if
(
w
<
h
)
w
=
h
;
painter
->
setPen
(
Qt
::
transparent
);
QRadialGradient
grad
(
QPointF
(
0.5
,
0.5
),
0.5
);
grad
.
setCoordinateMode
(
QGradient
::
ObjectBoundingMode
);
grad
.
setColorAt
(
0
,
QColor
(
150
,
200
,
150
,
255
));
grad
.
setColorAt
(
0.7
,
QColor
(
150
,
200
,
150
,
255
));
grad
.
setColorAt
(
1
,
QColor
(
150
,
150
,
150
,
0
));
painter
->
setBrush
(
QBrush
(
grad
));
painter
->
drawEllipse
(
QRectF
(((
double
)
(
totalWidth
-
w
))
/
2
,
0
,
w
,
h
));
}
painter
->
setFont
(
font
);
painter
->
setPen
(
QPen
(
Qt
::
black
));
painter
->
drawText
(
QRectF
(
0
,
0
,
totalWidth
,
40
),
Qt
::
AlignCenter
,
nameStr
);
}
Counter
*
PlayerArea
::
getCounter
(
const
QString
&
name
,
bool
remove
)
{
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
PlayerArea
::
addCounter
(
const
QString
&
name
,
QColor
color
,
int
value
)
{
counterList
.
append
(
new
Counter
(
player
,
name
,
color
,
value
,
this
));
rearrangeCounters
();
}
void
PlayerArea
::
delCounter
(
const
QString
&
name
)
{
delete
getCounter
(
name
,
true
);
rearrangeCounters
();
}
void
PlayerArea
::
clearCounters
()
{
for
(
int
i
=
0
;
i
<
counterList
.
size
();
i
++
)
delete
counterList
.
at
(
i
);
counterList
.
clear
();
}
void
PlayerArea
::
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
;
}
}
cockatrice/src/playerarea.h
deleted
100644 → 0
View file @
914261df
#ifndef PLAYERAREA_H
#define PLAYERAREA_H
#include
<QList>
#include
"carditem.h"
class
Player
;
class
Counter
;
class
PlayerArea
:
public
QGraphicsItem
{
private:
QPixmap
bgPixmap
;
QRectF
bRect
;
Player
*
player
;
QList
<
Counter
*>
counterList
;
void
rearrangeCounters
();
public:
enum
{
Type
=
typeOther
};
int
type
()
const
{
return
Type
;
}
PlayerArea
(
Player
*
_player
,
QGraphicsItem
*
parent
=
0
);
~
PlayerArea
();
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
clearCounters
();
};
#endif
cockatrice/src/tablezone.cpp
View file @
0d774b5d
...
...
@@ -4,56 +4,15 @@
#include
"client.h"
TableZone
::
TableZone
(
Player
*
_p
,
QGraphicsItem
*
parent
)
:
CardZone
(
_p
,
"table"
,
true
,
false
,
true
,
parent
),
width
(
864
),
height
(
5
78
)
:
CardZone
(
_p
,
"table"
,
true
,
false
,
true
,
parent
),
width
(
864
),
height
(
5
36
)
{
gridPoints
<<
(
QList
<
QPoint
>
()
<<
QPoint
(
8
,
12
)
<<
QPoint
(
9
,
13
)
<<
QPoint
(
10
,
14
)
<<
QPoint
(
12
,
12
)
<<
QPoint
(
13
,
13
)
<<
QPoint
(
14
,
14
)
<<
QPoint
(
4
,
12
)
<<
QPoint
(
5
,
13
)
<<
QPoint
(
6
,
14
)
<<
QPoint
(
16
,
12
)
<<
QPoint
(
17
,
13
)
<<
QPoint
(
18
,
14
)
<<
QPoint
(
0
,
12
)
<<
QPoint
(
1
,
13
)
<<
QPoint
(
2
,
14
)
<<
QPoint
(
20
,
12
)
<<
QPoint
(
21
,
13
)
<<
QPoint
(
22
,
14
))
<<
(
QList
<
QPoint
>
()
<<
QPoint
(
10
,
8
)
<<
QPoint
(
13
,
8
)
<<
QPoint
(
7
,
8
)
<<
QPoint
(
16
,
8
)
<<
QPoint
(
4
,
8
)
<<
QPoint
(
19
,
8
)
<<
QPoint
(
1
,
8
)
<<
QPoint
(
22
,
8
))
<<
(
QList
<
QPoint
>
()
<<
QPoint
(
10
,
4
)
<<
QPoint
(
13
,
4
)
<<
QPoint
(
7
,
4
)
<<
QPoint
(
16
,
4
)
<<
QPoint
(
4
,
4
)
<<
QPoint
(
19
,
4
)
<<
QPoint
(
1
,
4
)
<<
QPoint
(
22
,
4
))
<<
(
QList
<
QPoint
>
()
<<
QPoint
(
10
,
0
)
<<
QPoint
(
13
,
0
)
<<
QPoint
(
7
,
0
)
<<
QPoint
(
16
,
0
)
<<
QPoint
(
4
,
0
)
<<
QPoint
(
19
,
0
)
<<
QPoint
(
1
,
0
)
<<
QPoint
(
22
,
0
));
QSettings
settings
;
QString
bgPath
=
settings
.
value
(
"zonebg/table"
).
toString
();
if
(
!
bgPath
.
isEmpty
())
bgPixmap
.
load
(
bgPath
);
setCacheMode
(
DeviceCoordinateCache
);
setAcceptsHoverEvents
(
true
);
}
QRectF
TableZone
::
boundingRect
()
const
...
...
@@ -90,7 +49,11 @@ void TableZone::addCardImpl(CardItem *card, int _x, int _y)
void
TableZone
::
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
dropPoint
,
bool
faceDown
)
{
QPoint
gridPoint
=
mapToGrid
(
dropPoint
);
handleDropEventByGrid
(
cardId
,
startZone
,
mapToGrid
(
dropPoint
),
faceDown
);
}
void
TableZone
::
handleDropEventByGrid
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
gridPoint
,
bool
faceDown
)
{
player
->
client
->
moveCard
(
cardId
,
startZone
->
getName
(),
getName
(),
gridPoint
.
x
(),
gridPoint
.
y
(),
faceDown
);
}
...
...
@@ -124,13 +87,21 @@ CardItem *TableZone::getCardFromGrid(const QPoint &gridPoint) const
QPointF
TableZone
::
mapFromGrid
(
const
QPoint
&
gridPoint
)
const
{
return
QPointF
(
gridPoint
.
x
()
*
CARD_WIDTH
/
gridPointsPerCardX
,
gridPoint
.
y
()
*
CARD_HEIGHT
/
gridPointsPerCardY
);
if
(
gridPoint
.
y
()
==
3
)
return
QPointF
(
20
+
(
CARD_WIDTH
*
gridPoint
.
x
()
+
CARD_WIDTH
*
(
gridPoint
.
x
()
/
3
))
/
gridPointsPerCardX
,
(
CARD_HEIGHT
+
paddingY
)
*
gridPoint
.
y
()
/
gridPointsPerCardY
+
(
gridPoint
.
x
()
%
3
*
CARD_HEIGHT
)
/
3
);
else
return
QPointF
(
20
+
CARD_WIDTH
*
gridPoint
.
x
()
/
gridPointsPerCardX
,
(
CARD_HEIGHT
+
paddingY
)
*
gridPoint
.
y
()
/
gridPointsPerCardY
);
}
QPoint
TableZone
::
mapToGrid
(
const
QPointF
&
mapPoint
)
const
{
qreal
x
=
mapPoint
.
x
();
qreal
x
=
mapPoint
.
x
()
-
20
;
qreal
y
=
mapPoint
.
y
();
if
(
x
<
0
)
x
=
0
;
...
...
@@ -141,16 +112,27 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
else
if
(
y
>
height
-
CARD_HEIGHT
)
y
=
height
-
CARD_HEIGHT
;
return
QPoint
((
int
)
round
(((
double
)
x
*
gridPointsPerCardX
)
/
CARD_WIDTH
),
(
int
)
round
(((
double
)
y
*
gridPointsPerCardY
)
/
CARD_HEIGHT
));
if
(
y
>=
(
CARD_HEIGHT
+
paddingY
)
*
3
-
1
)
return
QPoint
(
(
int
)
round
(((
double
)
x
*
gridPointsPerCardX
)
/
CARD_WIDTH
-
x
/
(
2
*
CARD_WIDTH
)),
3
);
else
return
QPoint
(
(
int
)
round
(((
double
)
x
*
gridPointsPerCardX
)
/
CARD_WIDTH
),
(
int
)
round
(((
double
)
y
*
gridPointsPerCardY
)
/
(
CARD_HEIGHT
+
paddingY
))
);
}
QPoint
TableZone
::
getFreeGridPoint
(
int
row
)
const
{
Q_ASSERT
(
row
<
gridPoints
.
size
());
QList
<
QPoint
>
pointList
=
gridPoints
[
row
];
for
(
int
i
=
0
;
i
<
pointList
.
size
();
i
++
)
if
(
!
getCardFromGrid
(
pointList
[
i
]))
return
pointList
[
i
];
return
QPoint
(
0
,
0
);
int
x
=
0
;
int
y
=
3
-
row
;
if
(
y
==
3
)
while
(
getCardFromGrid
(
QPoint
(
x
,
y
)))
++
x
;
else
while
(((
x
>=
2
)
&&
getCardFromGrid
(
QPoint
(
x
-
2
,
y
)))
||
((
x
>=
1
)
&&
getCardFromGrid
(
QPoint
(
x
-
1
,
y
)))
||
getCardFromGrid
(
QPoint
(
x
,
y
))
||
getCardFromGrid
(
QPoint
(
x
+
1
,
y
))
||
getCardFromGrid
(
QPoint
(
x
+
2
,
y
)))
++
x
;
return
QPoint
(
x
,
y
);
}
cockatrice/src/tablezone.h
View file @
0d774b5d
...
...
@@ -6,11 +6,11 @@
class
TableZone
:
public
CardZone
{
private:
int
width
,
height
;
QList
<
QList
<
QPoint
>
>
gridPoints
;
QPixmap
bgPixmap
;
public:
static
const
int
gridPointsPerCardX
=
2
;
static
const
int
gridPointsPerCardY
=
3
;
static
const
int
gridPointsPerCardY
=
1
;
static
const
int
paddingY
=
20
;
TableZone
(
Player
*
_p
,
QGraphicsItem
*
parent
=
0
);
QRectF
boundingRect
()
const
;
...
...
@@ -18,6 +18,7 @@ public:
void
reorganizeCards
();
void
toggleTapped
();
void
handleDropEvent
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
dropPoint
,
bool
faceDown
);
void
handleDropEventByGrid
(
int
cardId
,
CardZone
*
startZone
,
const
QPoint
&
gridPoint
,
bool
faceDown
);
CardItem
*
getCardFromGrid
(
const
QPoint
&
gridPoint
)
const
;
QPointF
mapFromGrid
(
const
QPoint
&
gridPoint
)
const
;
QPoint
mapToGrid
(
const
QPointF
&
mapPoint
)
const
;
...
...
cockatrice/src/window_main.cpp
View file @
0d774b5d
...
...
@@ -29,6 +29,7 @@
#include
"messagelogwidget.h"
#include
"phasestoolbar.h"
#include
"gameview.h"
#include
"gamescene.h"
#include
"player.h"
#include
"game.h"
#include
"carddatabase.h"
...
...
@@ -154,15 +155,6 @@ void MainWindow::actExit()
close
();
}
void
MainWindow
::
updateSceneSize
()
{
QRectF
sr
=
scene
->
sceneRect
();
QSizeF
zoneSize
=
zoneLayout
->
size
();
qDebug
(
QString
(
"updateSceneSize: width=%1"
).
arg
(
1096
+
zoneSize
.
width
()).
toLatin1
());
scene
->
setSceneRect
(
sr
.
x
(),
sr
.
y
(),
1096
+
zoneSize
.
width
(),
sr
.
height
());
view
->
fitInView
(
scene
->
sceneRect
(),
Qt
::
KeepAspectRatio
);
}
void
MainWindow
::
actSay
()
{
if
(
sayEdit
->
text
().
isEmpty
())
...
...
@@ -178,6 +170,7 @@ void MainWindow::playerIdReceived(int id, QString name)
connect
(
game
,
SIGNAL
(
hoverCard
(
QString
)),
this
,
SLOT
(
hoverCard
(
QString
)));
connect
(
game
,
SIGNAL
(
playerAdded
(
Player
*
)),
this
,
SLOT
(
playerAdded
(
Player
*
)));
connect
(
game
,
SIGNAL
(
playerRemoved
(
Player
*
)),
this
,
SLOT
(
playerRemoved
(
Player
*
)));
connect
(
game
,
SIGNAL
(
playerRemoved
(
Player
*
)),
scene
,
SLOT
(
removePlayer
(
Player
*
)));
connect
(
game
,
SIGNAL
(
setActivePhase
(
int
)),
phasesToolbar
,
SLOT
(
setActivePhase
(
int
)));
connect
(
phasesToolbar
,
SIGNAL
(
signalUntapAll
()),
game
,
SLOT
(
actUntapAll
()));
playerAdded
(
game
->
getLocalPlayer
());
...
...
@@ -281,16 +274,11 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
db
=
new
CardDatabase
(
this
);
scene
=
new
QGraphicsScene
(
0
,
0
,
1096
,
1160
,
this
);
zoneLayout
=
new
ZoneViewLayout
(
db
);
scene
=
new
GameScene
(
zoneLayout
,
this
);
view
=
new
GameView
(
scene
);
view
->
hide
();
// view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
zoneLayout
=
new
ZoneViewLayout
(
db
);
zoneLayout
->
setPos
(
1096
,
0
);
scene
->
addItem
(
zoneLayout
);
connect
(
zoneLayout
,
SIGNAL
(
sizeChanged
()),
this
,
SLOT
(
updateSceneSize
()));
view
->
hide
();
cardInfo
=
new
CardInfoWidget
(
db
);
messageLog
=
new
MessageLogWidget
;
...
...
cockatrice/src/window_main.h
View file @
0d774b5d
...
...
@@ -23,8 +23,8 @@
#include
<QMainWindow>
#include
"client.h"
class
QGraphicsScene
;
class
GameView
;
class
GameScene
;
class
Game
;
class
CardDatabase
;
class
Player
;
...
...
@@ -63,8 +63,6 @@ private slots:
void
actFullScreen
(
bool
checked
);
void
actSettings
();
void
actExit
();
void
updateSceneSize
();
signals:
void
logConnecting
(
QString
hostname
);
void
logDisconnected
();
...
...
@@ -86,7 +84,7 @@ private:
ChatWidget
*
chatWidget
;
Client
*
client
;
QGraphics
Scene
*
scene
;
Game
Scene
*
scene
;
GameView
*
view
;
Game
*
game
;
CardDatabase
*
db
;
...
...
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