36
|
1 #!/usr/bin/python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 """ |
|
5 Libervia: a Salut à Toi frontend |
|
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
|
7 |
|
8 This program is free software: you can redistribute it and/or modify |
|
9 it under the terms of the GNU Affero General Public License as published by |
|
10 the Free Software Foundation, either version 3 of the License, or |
|
11 (at your option) any later version. |
|
12 |
|
13 This program is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU Affero General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU Affero General Public License |
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20 """ |
|
21 |
|
22 import pyjd # this is dummy in pyjs |
|
23 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
|
24 from pyjamas.ui.Image import Image |
|
25 |
|
26 from pyjamas.dnd import makeDraggable |
|
27 from pyjamas.ui.DragWidget import DragWidget, DragContainer |
|
28 from jid import JID |
|
29 from tools import html_sanitize |
|
30 from datetime import datetime |
|
31 from time import time |
|
32 from games import TarotCard |
|
33 |
|
34 |
|
35 |
|
36 CARD_WIDTH = 74 |
|
37 CARD_HEIGHT = 136 |
|
38 MIN_WIDTH = 950 #Minimum size of the panel |
|
39 MIN_HEIGHT = 500 |
|
40 |
|
41 |
|
42 class CardWidget(TarotCard, Image): |
|
43 """This class is used to represent a card, graphically and logically""" |
|
44 |
|
45 def __init__(self, file): |
|
46 """@param file: path of the PNG file""" |
|
47 Image.__init__(self,file) |
|
48 root_name = file[file.rfind("/")+1:-4] |
|
49 suit,value = root_name.split('_') |
|
50 TarotCard.__init__(self, (suit, value)) |
|
51 print "Carte:",suit, value #, self.bout |
|
52 |
|
53 def draw(self, dc, x, y): |
|
54 """Draw the card on the device context |
|
55 @param dc: device context |
|
56 @param x: abscissa |
|
57 @param y: ordinate""" |
|
58 pass |
|
59 #dc.DrawBitmap(self.bitmap, x, y, True) |
|
60 |
|
61 class CardPanel(AbsolutePanel): |
|
62 |
|
63 def __init__(self, parent, referee, players, player_nick): |
|
64 self._parent = parent |
|
65 self._autoplay = None #XXX: use 0 to activate fake play, None else |
|
66 self.referee = referee |
|
67 self.players = players |
|
68 self.played = {} |
|
69 for player in players: |
|
70 self.played[player] = None |
|
71 self.player_nick = player_nick |
|
72 self.bottom_nick = self.player_nick |
|
73 idx = self.players.index(self.player_nick) |
|
74 idx = (idx + 1) % len(self.players) |
|
75 self.right_nick = self.players[idx] |
|
76 idx = (idx + 1) % len(self.players) |
|
77 self.top_nick = self.players[idx] |
|
78 idx = (idx + 1) % len(self.players) |
|
79 self.left_nick = self.players[idx] |
|
80 self.bottom_nick = player_nick |
|
81 self.selected = [] #Card choosed by the player (e.g. during ecart) |
|
82 self.hand_size = 13 #number of cards in a hand |
|
83 self.hand = [] |
|
84 self.to_show = [] |
|
85 self.state = None |
|
86 AbsolutePanel.__init__(self) |
|
87 self.setSize("%spx" % MIN_WIDTH, "%spx" % MIN_HEIGHT) |
|
88 self.setStyleName("cardPanel") |
|
89 self.loadCards() |
|
90 self.mouse_over_card = None #contain the card to highlight |
|
91 self.visible_size = CARD_WIDTH/2 #number of pixels visible for cards |
|
92 |
|
93 def _getTarotCardsPathsCb(self, paths): |
|
94 for file in paths: |
|
95 card = CardWidget(file) |
|
96 self.cards[(card.suit, card.value)]=card |
|
97 self.deck.append(card) |
|
98 |
|
99 def loadCards(self, dir): |
|
100 """Load all the cards in memory |
|
101 @param dir: directory where the PNG files are""" |
|
102 self.cards={} |
|
103 self.deck=[] |
|
104 self.cards["atout"]={} #As Tarot is a french game, it's more handy & logical to keep french names |
|
105 self.cards["pique"]={} #spade |
|
106 self.cards["coeur"]={} #heart |
|
107 self.cards["carreau"]={} #diamond |
|
108 self.cards["trefle"]={} #club |
|
109 self._parent.host.bridge.call('getTarotCardsPaths', self._getTarotCardsPathsCb) |
|
110 |