Mercurial > libervia-web
changeset 41:7782a786b2f0
Tarot game: score is now shown (need to use XMLUI later)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 22 May 2011 17:56:59 +0200 |
parents | 49f1829fb928 |
children | 71a9cc9b9d57 |
files | browser_side/card_game.py browser_side/dialog.py libervia.py libervia.tac |
diffstat | 4 files changed, 34 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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 <b>win</b> !" + else: + title = "You <b>loose</b> :(" + body = re.sub(r'<.*?>',lambda x:'<br />' if '/elem' in x.group(0) else '', xml_data) #Q&D conversion to simple HTML text + SimpleDialog(title, body).show()
--- 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()
--- 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):
--- 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))