# HG changeset patch # User Goffi # Date 1306079819 -7200 # Node ID 7782a786b2f0fd1cb91f869fcfba8fc6fbdb21a1 # Parent 49f1829fb928db6c10ebedf7d8fdbd262d53b69d Tarot game: score is now shown (need to use XMLUI later) diff -r 49f1829fb928 -r 7782a786b2f0 browser_side/card_game.py --- a/browser_side/card_game.py Sun May 22 00:17:47 2011 +0200 +++ b/browser_side/card_game.py Sun May 22 17:56:59 2011 +0200 @@ -39,11 +39,12 @@ from pyjamas.dnd import makeDraggable from pyjamas.ui.DragWidget import DragWidget, DragContainer from jid import JID -from dialog import ConfirmDialog +from dialog import ConfirmDialog, SimpleDialog from tools import html_sanitize from datetime import datetime from time import time from games import TarotCard +import re @@ -397,3 +398,14 @@ self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, [(card.suit, card.value)]) self.state = "wait" self.updateHand() + + def tarotGameScore(self, xml_data, winners, loosers): + """Show score at this end of a round""" + ###XXX: we cheat here as XMLUI is not implemented yet + #TODO: usr XMLUI + if self.player_nick in winners: + title = "You win !" + else: + title = "You loose :(" + body = re.sub(r'<.*?>',lambda x:'
' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text + SimpleDialog(title, body).show() diff -r 49f1829fb928 -r 7782a786b2f0 browser_side/dialog.py --- a/browser_side/dialog.py Sun May 22 00:17:47 2011 +0200 +++ b/browser_side/dialog.py Sun May 22 17:56:59 2011 +0200 @@ -24,6 +24,7 @@ from pyjamas.ui.DialogBox import DialogBox from pyjamas.ui.ListBox import ListBox from pyjamas.ui.Button import Button +from pyjamas.ui.HTML import HTML class ContactsChooser(DialogBox): @@ -109,3 +110,20 @@ self.hide() self.callback(False) +class SimpleDialog(DialogBox): + + def __init__(self, title, body): + """Simple notice dialog box + @param title: HTML put in the header + @param body: HTML put in the body""" + DialogBox.__init__(self, centered=True) + _body = VerticalPanel() + _body.setSpacing(4) + _body.add(HTML(body)) + _body.add(Button("Close", self.onClose)) + _body.setStyleName("dialogBody") + self.setHTML(title) + self.setWidget(_body) + + def onClose(self): + self.hide() diff -r 49f1829fb928 -r 7782a786b2f0 libervia.py --- a/libervia.py Sun May 22 00:17:47 2011 +0200 +++ b/libervia.py Sun May 22 17:56:59 2011 +0200 @@ -177,7 +177,8 @@ name == 'tarotGameShowCards' or \ name == 'tarotGameInvalidCards' or \ name == 'tarotGameCardsPlayed' or \ - name == 'tarotGameYourTurn': + name == 'tarotGameYourTurn' or \ + name == 'tarotGameScore': self._tarotGameGenericCb(name, args[0], args[1:]) def _getProfileJidCB(self, jid): diff -r 49f1829fb928 -r 7782a786b2f0 libervia.tac --- a/libervia.tac Sun May 22 00:17:47 2011 +0200 +++ b/libervia.tac Sun May 22 17:56:59 2011 +0200 @@ -367,7 +367,7 @@ self.bridge.register("connected", self.signal_handler.connected) self.bridge.register("connectionError", self.signal_handler.connectionError) for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', - 'tarotGameChooseContrat', 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn']: + 'tarotGameChooseContrat', 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore']: self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) root.putChild('json_signal_api', self.signal_handler) root.putChild('json_api', MethodHandler(self))