annotate src/browser/sat_browser/game_tarot.py @ 898:2d15b484ca33

blog, browser: updated imports to reflect renaming of common.py to common/data_format.py
author Goffi <goffi@goffi.org>
date Tue, 22 Mar 2016 22:45:39 +0100
parents 09ace5cbcb9b
children fd4eae654182
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
4 # Libervia: a Salut à Toi frontend
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 782
diff changeset
5 # Copyright (C) 2011-2016 Jérôme Poisson <goffi@goffi.org>
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
10 # (at your option) any later version.
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
15 # GNU Affero General Public License for more details.
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
20 import pyjd # this is dummy in pyjs
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
21 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
22 log = getLogger(__name__)
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
23
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
24 from sat.core.i18n import _, D_
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
25 from sat_frontends.tools.games import TarotCard
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
26 from sat_frontends.tools import host_listener
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 439
diff changeset
27
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.AbsolutePanel import AbsolutePanel
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
29 from pyjamas.ui.DockPanel import DockPanel
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
30 from pyjamas.ui.SimplePanel import SimplePanel
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.Image import Image
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
32 from pyjamas.ui.Label import Label
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
33 from pyjamas.ui.ClickListener import ClickHandler
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
34 from pyjamas.ui.MouseListener import MouseHandler
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
35 from pyjamas.ui import HasAlignment
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
36 from pyjamas import Window
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
37 from pyjamas import DOM
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
38 from constants import Const as C
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
40 import dialog
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
41 import xmlui
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 CARD_WIDTH = 74
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 CARD_HEIGHT = 136
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
46 CARD_DELTA_Y = 30
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
47 MIN_WIDTH = 950 # Minimum size of the panel
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 MIN_HEIGHT = 500
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
50
684
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
51 unicode = str # XXX: pyjama doesn't manage unicode
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
52
e876f493dccc browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents: 676
diff changeset
53
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
54 class CardWidget(TarotCard, Image, MouseHandler):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 """This class is used to represent a card, graphically and logically"""
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
57 def __init__(self, parent, file_):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 """@param file: path of the PNG file"""
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
59 self._parent = parent
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
60 Image.__init__(self, file_)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
61 root_name = file_[file_.rfind("/") + 1:-4]
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
62 suit, value = root_name.split('_')
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 TarotCard.__init__(self, (suit, value))
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
64 MouseHandler.__init__(self)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
65 self.addMouseListener(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
67 def onMouseEnter(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
68 if self._parent.state == "ecart" or self._parent.state == "play":
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
69 DOM.setStyleAttribute(self.getElement(), "top", "0px")
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
71 def onMouseLeave(self, sender):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
72 if not self in self._parent.hand:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
73 return
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
74 if not self in list(self._parent.selected): # FIXME: Workaround pyjs bug, must report it
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
75 DOM.setStyleAttribute(self.getElement(), "top", "%dpx" % CARD_DELTA_Y)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
76
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
77 def onMouseUp(self, sender, x, y):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
78 if self._parent.state == "ecart":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
79 if self not in list(self._parent.selected):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
80 self._parent.addToSelection(self)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
81 else:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
82 self._parent.removeFromSelection(self)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
83 elif self._parent.state == "play":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
84 self._parent.playCard(self)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
85
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
86
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
87 class TarotPanel(DockPanel, ClickHandler):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
89 def __init__(self, parent, referee, players):
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
90 DockPanel.__init__(self)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
91 ClickHandler.__init__(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self._parent = parent
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
93 self._autoplay = None # XXX: use 0 to activate fake play, None else
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.referee = referee
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self.players = players
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
96 self.player_nick = parent.nick
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.bottom_nick = self.player_nick
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 idx = self.players.index(self.player_nick)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.right_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 self.top_nick = self.players[idx]
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 idx = (idx + 1) % len(self.players)
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.left_nick = self.players[idx]
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
105 self.bottom_nick = self.player_nick
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
106 self.selected = set() # Card choosed by the player (e.g. during ecart)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
107 self.hand_size = 13 # number of cards in a hand
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.hand = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.to_show = []
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.state = None
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
111 self.setSize("%dpx" % MIN_WIDTH, "%dpx" % MIN_HEIGHT)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.setStyleName("cardPanel")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
113
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
114 # Now we set up the layout
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
115 _label = Label(self.top_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
116 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
117 self.add(_label, DockPanel.NORTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
118 self.setCellWidth(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
119 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_CENTER)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
120
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
121 self.hand_panel = AbsolutePanel()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
122 self.add(self.hand_panel, DockPanel.SOUTH)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
123 self.setCellWidth(self.hand_panel, '100%')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
124 self.setCellHorizontalAlignment(self.hand_panel, HasAlignment.ALIGN_CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
125
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
126 _label = Label(self.left_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
127 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
128 self.add(_label, DockPanel.WEST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
129 self.setCellHeight(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
130 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
131
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
132 _label = Label(self.right_nick)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
133 _label.setStyleName('cardGamePlayerNick')
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
134 self.add(_label, DockPanel.EAST)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
135 self.setCellHeight(_label, '100%')
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
136 self.setCellHorizontalAlignment(_label, HasAlignment.ALIGN_RIGHT)
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
137 self.setCellVerticalAlignment(_label, HasAlignment.ALIGN_MIDDLE)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
138
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
139 self.center_panel = DockPanel()
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
140 self.inner_left = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
141 self.inner_left.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
142 self.center_panel.add(self.inner_left, DockPanel.WEST)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
143 self.center_panel.setCellHeight(self.inner_left, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
144 self.center_panel.setCellHorizontalAlignment(self.inner_left, HasAlignment.ALIGN_RIGHT)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
145 self.center_panel.setCellVerticalAlignment(self.inner_left, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
146
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
147 self.inner_right = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
148 self.inner_right.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
149 self.center_panel.add(self.inner_right, DockPanel.EAST)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
150 self.center_panel.setCellHeight(self.inner_right, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
151 self.center_panel.setCellVerticalAlignment(self.inner_right, HasAlignment.ALIGN_MIDDLE)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
152
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
153 self.inner_top = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
154 self.inner_top.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
155 self.center_panel.add(self.inner_top, DockPanel.NORTH)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
156 self.center_panel.setCellHorizontalAlignment(self.inner_top, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
157 self.center_panel.setCellVerticalAlignment(self.inner_top, HasAlignment.ALIGN_BOTTOM)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
158
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
159 self.inner_bottom = SimplePanel()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
160 self.inner_bottom.setSize("%dpx" % CARD_WIDTH, "%dpx" % CARD_HEIGHT)
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
161 self.center_panel.add(self.inner_bottom, DockPanel.SOUTH)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
162 self.center_panel.setCellHorizontalAlignment(self.inner_bottom, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
163 self.center_panel.setCellVerticalAlignment(self.inner_bottom, HasAlignment.ALIGN_TOP)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
164
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
165 self.inner_center = SimplePanel()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
166 self.center_panel.add(self.inner_center, DockPanel.CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
167 self.center_panel.setCellHorizontalAlignment(self.inner_center, HasAlignment.ALIGN_CENTER)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
168 self.center_panel.setCellVerticalAlignment(self.inner_center, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
169
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
170 self.add(self.center_panel, DockPanel.CENTER)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
171 self.setCellWidth(self.center_panel, '100%')
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
172 self.setCellHeight(self.center_panel, '100%')
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
173 self.setCellVerticalAlignment(self.center_panel, HasAlignment.ALIGN_MIDDLE)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
174 self.setCellHorizontalAlignment(self.center_panel, HasAlignment.ALIGN_CENTER)
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
175
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 self.loadCards()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
177 self.mouse_over_card = None # contain the card to highlight
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
178 self.visible_size = CARD_WIDTH / 2 # number of pixels visible for cards
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
179 self.addClickListener(self)
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180
77
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
181 def loadCards(self):
975e6be24e11 media paths update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
182 """Load all the cards in memory"""
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
183 def _getTarotCardsPathsCb(paths):
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
184 log.debug("_getTarotCardsPathsCb")
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
185 for file_ in paths:
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 689
diff changeset
186 log.debug(u"path: %s" % file_)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
187 card = CardWidget(self, file_)
694
82123705474b massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 689
diff changeset
188 log.debug(u"card: %s" % card)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
189 self.cards[(card.suit, card.value)] = card
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
190 self.deck.append(card)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
191 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
192 self.cards = {}
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
193 self.deck = []
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
194 self.cards["atout"] = {} # As Tarot is a french game, it's more handy & logical to keep french names
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
195 self.cards["pique"] = {} # spade
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
196 self.cards["coeur"] = {} # heart
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
197 self.cards["carreau"] = {} # diamond
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
198 self.cards["trefle"] = {} # club
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
199 self._parent.host.bridge.call('getTarotCardsPaths', _getTarotCardsPathsCb)
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
200
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
201 def onClick(self, sender):
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
202 if self.state == "chien":
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
203 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
204 self.state = "wait"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
205 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
206 elif self.state == "wait_for_ecart":
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
207 self.state = "ecart"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
208 self.hand.extend(self.to_show)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
209 self.hand.sort()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
210 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
211 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
212 self.updateHand()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
213
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
214 def tarotGameNewHandler(self, hand):
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
215 """Start a new game, with given hand"""
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
216 if hand is []: # reset the display after the scores have been showed
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
217 self.selected.clear()
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
218 del self.hand[:]
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
219 del self.to_show[:]
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
220 self.state = None
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
221 #empty hand
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
222 self.updateHand()
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
223 #nothing on the table
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
224 self.updateToShow()
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
225 for pos in ['top', 'left', 'bottom', 'right']:
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
226 getattr(self, "inner_%s" % pos).setWidget(None)
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
227 self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
228 return
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
229 for suit, value in hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
230 self.hand.append(self.cards[(suit, value)])
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
231 self.hand.sort()
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
232 self.state = "init"
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
233 self.updateHand()
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
234
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
235 def updateHand(self):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
236 """Show the cards in the hand in the hand_panel (SOUTH panel)"""
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
237 self.hand_panel.clear()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
238 self.hand_panel.setSize("%dpx" % (self.visible_size * (len(self.hand) + 1)), "%dpx" % (CARD_HEIGHT + CARD_DELTA_Y + 10))
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
239 x_pos = 0
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
240 y_pos = CARD_DELTA_Y
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
241 for card in self.hand:
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
242 self.hand_panel.add(card, x_pos, y_pos)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
243 x_pos += self.visible_size
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
244
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
245 def updateToShow(self):
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
246 """Show cards in the center panel"""
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
247 if not self.to_show:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
248 _widget = self.inner_center.getWidget()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
249 if _widget:
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
250 self.inner_center.remove(_widget)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
251 return
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
252 panel = AbsolutePanel()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
253 panel.setSize("%dpx" % ((CARD_WIDTH + 5) * len(self.to_show) - 5), "%dpx" % (CARD_HEIGHT))
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
254 x_pos = 0
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
255 y_pos = 0
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
256 for card in self.to_show:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
257 panel.add(card, x_pos, y_pos)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
258 x_pos += CARD_WIDTH + 5
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
259 self.inner_center.setWidget(panel)
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
260
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
261 def _ecartConfirm(self, confirm):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
262 if not confirm:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
263 return
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
264 ecart = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
265 for card in self.selected:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
266 ecart.append((card.suit, card.value))
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
267 self.hand.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
268 self.selected.clear()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
269 self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, ecart)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
270 self.state = "wait"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
271 self.updateHand()
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
272
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
273 def addToSelection(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
274 self.selected.add(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
275 if len(self.selected) == 6:
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
276 dialog.ConfirmDialog(self._ecartConfirm, "Put these cards into chien ?").show()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
277
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
278 def tarotGameInvalidCardsHandler(self, phase, played_cards, invalid_cards):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
279 """Invalid cards have been played
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
280 @param phase: phase of the game
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
281 @param played_cards: all the cards played
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
282 @param invalid_cards: cards which are invalid"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
283
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
284 if phase == "play":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
285 self.state = "play"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
286 elif phase == "ecart":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
287 self.state = "ecart"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
288 else:
451
1a0cec9b0f1e better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 449
diff changeset
289 log.error("INTERNAL ERROR: unmanaged game phase") # FIXME: raise an exception here
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
290
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
291 for suit, value in played_cards:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
292 self.hand.append(self.cards[(suit, value)])
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
293
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
294 self.hand.sort()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
295 self.updateHand()
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
296 if self._autoplay == None: # No dialog if there is autoplay
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
297 Window.alert('Cards played are invalid !')
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
298 self.__fakePlay()
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
299
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
300 def removeFromSelection(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
301 self.selected.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
302 if len(self.selected) == 6:
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
303 dialog.ConfirmDialog(self._ecartConfirm, "Put these cards into chien ?").show()
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
304
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
305 def tarotGameChooseContratHandler(self, xml_data):
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
306 """Called when the player has to select his contrat
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
307 @param xml_data: SàT xml representation of the form"""
500
67a4e8383b70 browser side (XMLUI): XMLUI update to follow core changes:
Goffi <goffi@goffi.org>
parents: 467
diff changeset
308 body = xmlui.create(self._parent.host, xml_data, flags=['NO_CANCEL'])
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
309 _dialog = dialog.GenericDialog(_('Please choose your contrat'), body, options=['NO_CLOSE'])
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
310 body.setCloseCb(_dialog.close)
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
311 _dialog.show()
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
312
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
313 def tarotGameShowCardsHandler(self, game_stage, cards, data):
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
314 """Display cards in the middle of the game (to show for e.g. chien ou poignée)"""
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
315 self.to_show = []
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
316 for suit, value in cards:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
317 self.to_show.append(self.cards[(suit, value)])
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
318 self.updateToShow()
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
319 if game_stage == "chien" and data['attaquant'] == self.player_nick:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
320 self.state = "wait_for_ecart"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
321 else:
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
322 self.state = "chien"
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
323
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
324 def getPlayerLocation(self, nick):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
325 """return player location (top,bottom,left or right)"""
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
326 for location in ['top', 'left', 'bottom', 'right']:
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
327 if getattr(self, '%s_nick' % location) == nick:
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
328 return location
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
329 log.error("This line should not be reached")
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
330
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
331 def tarotGameCardsPlayedHandler(self, player, cards):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
332 """A card has been played by player"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
333 if not len(cards):
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
334 log.warning("cards should not be empty")
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
335 return
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
336 if len(cards) > 1:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 381
diff changeset
337 log.error("can't manage several cards played")
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
338 if self.to_show:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
339 self.to_show = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
340 self.updateToShow()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
341 suit, value = cards[0]
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
342 player_pos = self.getPlayerLocation(player)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
343 player_panel = getattr(self, "inner_%s" % player_pos)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
344
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
345 if player_panel.getWidget() != None:
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
346 #We have already cards on the table, we remove them
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
347 for pos in ['top', 'left', 'bottom', 'right']:
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
348 getattr(self, "inner_%s" % pos).setWidget(None)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
349
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
350 card = self.cards[(suit, value)]
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
351 DOM.setElemAttribute(card.getElement(), "style", "")
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
352 player_panel.setWidget(card)
243
63e9b680d3e7 browser_side, blog: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 238
diff changeset
353
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
354 def tarotGameYourTurnHandler(self):
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
355 """Called when we have to play :)"""
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
356 if self.state == "chien":
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
357 self.to_show = []
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
358 self.updateToShow()
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
359 self.state = "play"
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
360 self.__fakePlay()
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
361
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
362 def __fakePlay(self):
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
363 """Convenience method for stupid autoplay
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
364 /!\ don't forgot to comment any interactive dialog for invalid card"""
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
365 if self._autoplay == None:
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
366 return
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
367 if self._autoplay >= len(self.hand):
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
368 self._autoplay = 0
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
369 card = self.hand[self._autoplay]
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
370 self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, [(card.suit, card.value)])
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
371 del self.hand[self._autoplay]
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
372 self.state = "wait"
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
373 self._autoplay += 1
39
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
374
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
375 def playCard(self, card):
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
376 self.hand.remove(card)
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
377 self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, [(card.suit, card.value)])
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
378 self.state = "wait"
305e81c7a32c Tarot game: a game can now be finished
Goffi <goffi@goffi.org>
parents: 38
diff changeset
379 self.updateHand()
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
380
672
b39a9eddfe56 browser_side: fixes room games:
souliane <souliane@mailoo.org>
parents: 580
diff changeset
381 def tarotGameScoreHandler(self, xml_data, winners, loosers):
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
382 """Show score at the end of a round"""
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
383 if not winners and not loosers:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
384 title = "Draw game"
41
7782a786b2f0 Tarot game: score is now shown (need to use XMLUI later)
Goffi <goffi@goffi.org>
parents: 39
diff changeset
385 else:
42
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
386 if self.player_nick in winners:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
387 title = "You <b>win</b> !"
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
388 else:
71a9cc9b9d57 Browser side: Tarot game
Goffi <goffi@goffi.org>
parents: 41
diff changeset
389 title = "You <b>loose</b> :("
500
67a4e8383b70 browser side (XMLUI): XMLUI update to follow core changes:
Goffi <goffi@goffi.org>
parents: 467
diff changeset
390 body = xmlui.create(self._parent.host, xml_data, title=title, flags=['NO_CANCEL'])
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 451
diff changeset
391 _dialog = dialog.GenericDialog(title, body, options=['NO_CLOSE'])
381
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
392 body.setCloseCb(_dialog.close)
b96b8b666d17 plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
souliane <souliane@mailoo.org>
parents: 372
diff changeset
393 _dialog.show()
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
394
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
395
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
396 ## Menu
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
397
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
398 def hostReady(host):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
399 def onTarotGame():
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
400 def onPlayersSelected(room_jid, other_players):
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
401 other_players = [unicode(contact) for contact in other_players]
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
402 room_jid_s = unicode(room_jid) if room_jid else ''
839
09ace5cbcb9b browser (games, menu): rename showFailureRoomInvalid to onJoinMUCFailure and display a nice message when the room has already been joined (it is not a real error)
souliane <souliane@mailoo.org>
parents: 818
diff changeset
403 host.bridge.launchTarotGame(other_players, room_jid_s, profile=C.PROF_KEY_NONE, callback=lambda dummy: None, errback=host.onJoinMUCFailure)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
404 dialog.RoomAndContactsChooser(host, onPlayersSelected, 3, title="Tarot", title_invite=_(u"Please select 3 other players"), visible=(False, True))
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
405
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
406 def gotMenus():
782
10a56f6bc5db browser_side (menu): moved Tarot from Games to Groups
souliane <souliane@mailoo.org>
parents: 694
diff changeset
407 host.menus.addMenu(C.MENU_GLOBAL, (D_(u"Groups"), D_(u"Tarot")), callback=onTarotGame)
676
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
408 host.addListener('gotMenus', gotMenus)
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
409
849ffb24d5bf browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents: 672
diff changeset
410 host_listener.addListener(hostReady)