comparison browser_side/panels.py @ 275:a763b2ac5d41

bridge + browser_side: bridge signals for games and their callbacks: - added radiocolPlayers and tarotGamePlayers to get the list of players - added roomLeft to remove the muc from the host's room list - display symbols to identify the players in a muc - factorization of ChatPanel.startGame
author souliane <souliane@mailoo.org>
date Thu, 21 Nov 2013 16:13:14 +0100
parents 11718798ab8a
children aebb96bfa8d1
comparison
equal deleted inserted replaced
274:886b47896f3c 275:a763b2ac5d41
50 import base_widget 50 import base_widget
51 from richtext import RichTextEditor 51 from richtext import RichTextEditor
52 from plugin_xep_0085 import ChatStateMachine 52 from plugin_xep_0085 import ChatStateMachine
53 from pyjamas import Window 53 from pyjamas import Window
54 from __pyjamas__ import doc 54 from __pyjamas__ import doc
55 from sat.tools.frontends.games import SYMBOLS
55 56
56 57
57 class UniBoxPanel(HorizontalPanel): 58 class UniBoxPanel(HorizontalPanel):
58 """Panel containing the UniBox""" 59 """Panel containing the UniBox"""
59 60
835 self.printInfo('* %s %s' % (nick, msg[4:]), type='me') 836 self.printInfo('* %s %s' % (nick, msg[4:]), type='me')
836 return 837 return
837 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml'))) 838 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
838 self.content_scroll.scrollToBottom() 839 self.content_scroll.scrollToBottom()
839 840
840 def startGame(self, game_type, referee, players): 841 def startGame(self, game_type, referee, players, waiting=False):
841 """Configure the chat window to start a game""" 842 """Configure the chat window to start a game"""
842 if game_type == "Tarot": 843 classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel}
843 if hasattr(self, "tarot_panel"): 844 if game_type not in classes.keys():
844 return 845 return # unknown game
845 self.tarot_panel = CardPanel(self, referee, players, self.nick) 846 attr = game_type.lower()
846 self.vpanel.insert(self.tarot_panel, 0) 847 self.occupants_list.addSpecials(players, SYMBOLS[attr])
847 self.vpanel.setCellHeight(self.tarot_panel, self.tarot_panel.getHeight()) 848 if waiting or not self.nick in players:
848 elif game_type == "RadioCol": 849 return # waiting for player or not playing
849 # XXX: We can have double panel if we join quickly enough to have the group chat start signal 850 attr = "%s_panel" % attr
850 # on invitation + the one triggered on room join 851 if hasattr(self, attr):
851 if hasattr(self, "radiocol_panel"): 852 return
852 return 853 print ("%s Game Started \o/" % game_type)
853 self.radiocol_panel = RadioColPanel(self, referee, self.nick) 854 panel = classes[game_type](self, referee, self.nick, players)
854 self.vpanel.insert(self.radiocol_panel, 0) 855 setattr(self, attr, panel)
855 self.vpanel.setCellHeight(self.radiocol_panel, self.radiocol_panel.getHeight()) 856 self.vpanel.insert(panel, 0)
857 self.vpanel.setCellHeight(panel, panel.getHeight())
856 858
857 def getGame(self, game_type): 859 def getGame(self, game_type):
858 """Return class managing the game type""" 860 """Return class managing the game type"""
859 # TODO: check that the game is launched, and manage errors 861 # TODO: check that the game is launched, and manage errors
860 if game_type == "Tarot": 862 if game_type == "Tarot":