Mercurial > libervia-web
changeset 381:b96b8b666d17
plugin card_game: update to use the new XMLUI mechanism + copy the autoplay mode from QuickFrontend:
TODO: the new round is not starting after the scores have been displayed
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 26 Feb 2014 02:28:19 +0100 |
parents | 5e0e2032928c |
children | 06fbe6055925 |
files | browser_side/card_game.py libervia.py libervia_server/__init__.py |
diffstat | 3 files changed, 44 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/card_game.py Tue Feb 25 12:41:31 2014 +0100 +++ b/browser_side/card_game.py Wed Feb 26 02:28:19 2014 +0100 @@ -19,24 +19,20 @@ import pyjd # this is dummy in pyjs from pyjamas.ui.AbsolutePanel import AbsolutePanel -from pyjamas.ui.VerticalPanel import VerticalPanel -from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.DockPanel import DockPanel from pyjamas.ui.SimplePanel import SimplePanel -from pyjamas.ui.DialogBox import DialogBox -from pyjamas.ui.ListBox import ListBox from pyjamas.ui.Image import Image from pyjamas.ui.Label import Label -from pyjamas.ui.Button import Button from pyjamas.ui.ClickListener import ClickHandler from pyjamas.ui.MouseListener import MouseHandler from pyjamas.ui import HasAlignment from pyjamas import Window from pyjamas import DOM -from dialog import ConfirmDialog, InfoDialog +from dialog import ConfirmDialog, GenericDialog +from xmlui import XMLUI from sat_frontends.tools.games import TarotCard -import re +from sat.core.i18n import _ CARD_WIDTH = 74 @@ -46,38 +42,6 @@ MIN_HEIGHT = 500 -class ContratChooser(DialogBox): - - def __init__(self, parent): - """ - Dialog asking to choose the contrat - """ - self._parent = parent - DialogBox.__init__(self, modal=False, centered=True) - - content = VerticalPanel() - content.setWidth('100%') - self.contrats_list = ListBox() - self.contrats_list.setVisibleItemCount(5) - self.contrats_list.setWidth("100%") - self.contrats_list.setStyleName('contratsChooser') - for contrat in ['Passe', 'Petite', 'Garde', 'Garde Sans', 'Garde Contre']: - self.contrats_list.addItem(contrat) - self.contrats_list.setSelectedIndex(0) - content.add(self.contrats_list) - button_panel = HorizontalPanel() - button_panel.addStyleName("marginAuto") - self.choose_button = Button("Choose", self.onChoose) - button_panel.add(self.choose_button) - content.add(button_panel) - self.setHTML("Please select your contrat") - self.setWidget(content) - - def onChoose(self, button): - self.hide() - self._parent.contratSelected(self.contrats_list.getSelectedItemText()[0]) - - class CardWidget(TarotCard, Image, MouseHandler): """This class is used to represent a card, graphically and logically""" @@ -240,6 +204,19 @@ def tarotGameNew(self, hand): """Start a new game, with given hand""" + if hand is []: # reset the display after the scores have been showed + self.selected.clear() + del self.hand[:] + del self.to_show[:] + self.state = None + #empty hand + self.updateHand() + #nothing on the table + self.updateToShow() + for pos in ['top', 'left', 'bottom', 'right']: + getattr(self, "inner_%s" % pos).setWidget(None) + self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) + return for suit, value in hand: self.hand.append(self.cards[(suit, value)]) self.hand.sort() @@ -307,7 +284,9 @@ self.hand.sort() self.updateHand() - Window.alert('Cards played are invalid !') + if self._autoplay == None: # No dialog if there is autoplay + Window.alert('Cards played are invalid !') + self.__fakePlay() def removeFromSelection(self, card): self.selected.remove(card) @@ -315,17 +294,12 @@ ConfirmDialog(self._ecartConfirm, "Put these cards into chien ?").show() def tarotGameChooseContrat(self, xml_data): - """Called when the player as to select his contrat + """Called when the player has to select his contrat @param xml_data: SàT xml representation of the form""" - #for the moment we cheat a little bit and make our own dialog box - #but XMLUI must be user ASAP, as in other frontends - contrat_chooser = ContratChooser(self) - contrat_chooser.show() - - def contratSelected(self, contrat): - """Must be called when the contrat is selected - @param contrat: one of the valid contrat value""" - self._parent.host.bridge.call('tarotGameContratChoosed', None, self.player_nick, self.referee, contrat or 'Passe') + body = XMLUI(self._parent.host, xml_data, flags=['NO_CANCEL']) + _dialog = GenericDialog(_('Please choose your contrat'), body, options=['NO_CLOSE']) + body.setCloseCb(_dialog.close) + _dialog.show() def tarotGameShowCards(self, game_stage, cards, data): """Display cards in the middle of the game (to show for e.g. chien ou poignée)""" @@ -374,6 +348,20 @@ self.to_show = [] self.updateToShow() self.state = "play" + self.__fakePlay() + + def __fakePlay(self): + """Convenience method for stupid autoplay + /!\ don't forgot to comment any interactive dialog for invalid card""" + if self._autoplay == None: + return + if self._autoplay >= len(self.hand): + self._autoplay = 0 + card = self.hand[self._autoplay] + self._parent.host.bridge.call('tarotGamePlayCards', None, self.player_nick, self.referee, [(card.suit, card.value)]) + del self.hand[self._autoplay] + self.state = "wait" + self._autoplay += 1 def playCard(self, card): self.hand.remove(card) @@ -382,22 +370,7 @@ 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 - def _new_game(): - self.selected.clear() - del self.hand[:] - del self.to_show[:] - self.state = None - #empty hand - self.updateHand() - #nothing on the table - self.updateToShow() - for pos in ['top', 'left', 'bottom', 'right']: - getattr(self, "inner_%s" % pos).setWidget(None) - self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee) - + """Show score at the end of a round""" if not winners and not loosers: title = "Draw game" else: @@ -405,5 +378,7 @@ 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 - InfoDialog(title, body, _new_game).show() + body = XMLUI(self._parent.host, xml_data, title=title, flags=['NO_CANCEL']) + _dialog = GenericDialog(title, body, options=['NO_CLOSE']) + body.setCloseCb(_dialog.close) + _dialog.show()
--- a/libervia.py Tue Feb 25 12:41:31 2014 +0100 +++ b/libervia.py Wed Feb 26 02:28:19 2014 +0100 @@ -121,7 +121,7 @@ "getLastMblogs", "getMassiveLastMblogs", "getMblogComments", "getProfileJid", "getHistory", "getPresenceStatus", "joinMUC", "mucLeave", "getRoomsJoined", "inviteMUC", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", - "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective", + "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCard", "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction", "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer",
--- a/libervia_server/__init__.py Tue Feb 25 12:41:31 2014 +0100 +++ b/libervia_server/__init__.py Wed Feb 26 02:28:19 2014 +0100 @@ -403,11 +403,6 @@ profile = ISATSession(self.session).profile self.sat_host.bridge.tarotGameReady(player, referee, profile) - def jsonrpc_tarotGameContratChoosed(self, player_nick, referee, contrat): - """Tell to the server that we are ready to start the game""" - profile = ISATSession(self.session).profile - self.sat_host.bridge.tarotGameContratChoosed(player_nick, referee, contrat, profile) - def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards): """Tell to the server the cards we want to put on the table""" profile = ISATSession(self.session).profile