diff src/browser/sat_browser/chat.py @ 672:b39a9eddfe56 frontends_multi_profiles

browser_side: fixes room games: - use quick_frontend.quick_games - rename the signals handlers to fit the convention (e.g.: tarotGameScoreHandler) - rename card_game to game_tarot, radiocol to game_radiocol, CardGame to TarotPanel
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:50:19 +0100
parents 2201ff543a05
children e489218886d7
line wrap: on
line diff
--- a/src/browser/sat_browser/chat.py	Mon Mar 09 16:30:06 2015 +0100
+++ b/src/browser/sat_browser/chat.py	Wed Mar 11 12:50:19 2015 +0100
@@ -23,7 +23,7 @@
 from sat_frontends.tools.games import SYMBOLS
 from sat_frontends.tools import strings
 from sat_frontends.tools import jid
-from sat_frontends.quick_frontend import quick_widgets
+from sat_frontends.quick_frontend import quick_widgets, quick_games
 from sat_frontends.quick_frontend.quick_chat import QuickChat
 from sat.core.i18n import _
 
@@ -43,11 +43,11 @@
 import base_panel
 import contact_panel
 import editor_widget
-import card_game
-import radiocol
 import contact_list
 from constants import Const as C
 import plugin_xep_0085
+import game_tarot
+import game_radiocol
 
 
 unicode = str  # FIXME: pyjamas workaround
@@ -281,32 +281,6 @@
         self.content.add(ChatText(nick, mymess, msg, extra))
         self.content_scroll.scrollToBottom()
 
-    def startGame(self, game_type, waiting, referee, players, *args):
-        """Configure the chat window to start a game"""
-        classes = {"Tarot": card_game.CardPanel, "RadioCol": radiocol.RadioColPanel}
-        if game_type not in classes.keys():
-            return  # unknown game
-        attr = game_type.lower()
-        # self.occupants_panel.updateSpecials(players, SYMBOLS[attr]) # FIXME
-        if waiting or not self.nick in players:
-            return  # waiting for player or not playing
-        attr = "%s_panel" % attr
-        if hasattr(self, attr):
-            return
-        log.info("%s Game Started \o/" % game_type)
-        panel = classes[game_type](self, referee, self.nick, players, *args)
-        setattr(self, attr, panel)
-        self.vpanel.insert(panel, 0)
-        self.vpanel.setCellHeight(panel, panel.getHeight())
-
-    def getGame(self, game_type):
-        """Return class managing the game type"""
-        # TODO: check that the game is launched, and manage errors
-        if game_type == "Tarot":
-            return self.tarot_panel
-        elif game_type == "RadioCol":
-            return self.radiocol_panel
-
     def setState(self, state, nick=None):
         """Set the chat state (XEP-0085) of the contact. Leave nick to None
         to set the state for a one2one conversation, or give a nickname or
@@ -351,6 +325,23 @@
         #TODO
         pass
 
+    def addGamePanel(self, widget):
+        """Insert a game panel to this Chat dialog.
+
+        @param widget (Widget): the game panel
+        """
+        self.vpanel.insert(widget, 0)
+        self.vpanel.setCellHeight(widget, widget.getHeight())
+
+    def removeGamePanel(self, widget):
+        """Remove the game panel from this Chat dialog.
+
+        @param widget (Widget): the game panel
+        """
+        self.vpanel.remove(widget)
+
 
 quick_widgets.register(QuickChat, Chat)
+quick_widgets.register(quick_games.Tarot, game_tarot.TarotPanel)
+quick_widgets.register(quick_games.Radiocol, game_radiocol.RadioColPanel)
 libervia_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.displayWidget(Chat, jid.JID(item), dropped=True))