From: <Blu...@us...> - 2010-09-09 19:35:03
|
Revision: 398 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=398&view=rev Author: BlueWolf_ Date: 2010-09-09 19:34:56 +0000 (Thu, 09 Sep 2010) Log Message: ----------- * Added a userlist, useronline and useroffline callback into the core * The 'Who is online' subtext in topbar from the layout is now dynamic and gets updated as soon as someone goes online or offline Modified Paths: -------------- trunk/client/callback.py trunk/client/core/callback.py trunk/client/core/client.py trunk/client/core/parser.py trunk/client/layout.py Modified: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2010-09-09 15:26:04 UTC (rev 397) +++ trunk/client/callback.py 2010-09-09 19:34:56 UTC (rev 398) @@ -126,3 +126,9 @@ sh['main'].call("filetable", { "action": "update" }) + + def useronline(self, user, userlist): + sh['main'].call("useronline", user) + + def useroffline(self, user, userlist): + sh['main'].call("useroffline", user) Modified: trunk/client/core/callback.py =================================================================== --- trunk/client/core/callback.py 2010-09-09 15:26:04 UTC (rev 397) +++ trunk/client/core/callback.py 2010-09-09 19:34:56 UTC (rev 398) @@ -157,3 +157,54 @@ """ pass + + def userlist(self, userlist): + """ + Just after the user is logged in the current list of users will be send. + This variable is the same as client.userlist. This callback can be used + to append the app's own data to the clients. + + userlist: + A dict with the current list of users. The cid is the key and the + value is the data for this user. The data consist of a dict with: + * cid - The unique ID for this user + * user - The username + * app - [Appname, Appversion] + * version - Which core it's using (string) + * bot - If it's a bot + * owner - The owner for this bot (only available when bot = True) + * pos - [Z, X, Y] The position for this user. Is None + when you can't see this user. + * ? - And any other extra data the server's app has defined + for its users + """ + + pass + + def useronline(self, user, userlist): + """ + When an other users comes online, this event will be fired. + + user: + Same as the dict in callback.userlist + userlist: + Dictionary with all current online users. This is the same as + client.userlist + """ + + pass + + def useroffline(self, user, userlist): + """ + When an other user goes offline, this event will be fired. This happens + AFTER the user is removed from client.userlist. + + user: + Same as the dict in callback.userlist + userlist: + Dictionary with all current online users. The user that did go + offline is already removed from this list. This is the same as + client.userlist + """ + + pass Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2010-09-09 15:26:04 UTC (rev 397) +++ trunk/client/core/client.py 2010-09-09 19:34:56 UTC (rev 398) @@ -86,6 +86,7 @@ self.username = None self.owner = None self.cid = None # Connection-id + self.userlist = {} # Class that parsers all incomming data self.__parse = Parser(self.__sh) @@ -330,6 +331,7 @@ self.username = None self.owner = None self.cid = None + self.userlist = {} try: self.__sock.shutdown(0) except: pass Modified: trunk/client/core/parser.py =================================================================== --- trunk/client/core/parser.py 2010-09-09 15:26:04 UTC (rev 397) +++ trunk/client/core/parser.py 2010-09-09 19:34:56 UTC (rev 398) @@ -99,39 +99,37 @@ * owner - The owner for this bot (only available when bot = True) * pos - [Z, X, Y] The position for this user. Is None when you can't see this user. + * ? - And any other extra data the server's app has defined for + its users """ - # TODO + for user in msg: + self.core.userlist[user['cid']] = user - pass + self.call.userlist(self.core.userlist) + def useronline(self, msg): """ Called after an user (or bot) has signed on. - * cid - The unique ID for this connection - * user - The username - * app - [Appname, Appversion] - * version - Which core it's using (string) - * bot - If it's a bot - * owner - The owner for this bot (only available when - bot = True) - * pos - [Z, X, Y] The position for this user. Is None - when you can't see this user. + Data is the same as the dict in callback.userlist """ - # TODO - - pass + self.core.userlist[msg['cid']] = msg + self.call.useronline(msg, self.core.userlist) + def useroffline(self, msg): """ An user has gone offline * cid - The connection-id for this client """ - # TODO + if not self.core.userlist.has_key(msg['cid']): return - pass + user = self.core.userlist[msg['cid']] + del self.core.userlist[msg['cid']] + self.call.useroffline(user, self.core.userlist) def error(self, msg): Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-09-09 15:26:04 UTC (rev 397) +++ trunk/client/layout.py 2010-09-09 19:34:56 UTC (rev 398) @@ -41,6 +41,9 @@ self.toppos = None self.topbar_mainfont = None self.topbar_subfont = None + self.topbar_lastsub = [""]*3 # Used for caching, when the connection's + # already closed but the animation is still + # going def event(self, ev): if self.status == "playground": @@ -111,8 +114,14 @@ time.time(), 1) self.status = data['status'] + + + elif name == "useronline" or name == "useroffline": + self.updatetop() + + # [TODO] Show notification + - def updatetop(self, wholebar = False): if wholebar: # This happens when the WHOLE bar needs to be updated @@ -152,12 +161,28 @@ textcolor_subshadow = (0, 0, 0) if i == 0: text_main = "General" - text_sub = sh['client'].username + ": 0 V" + + # Sub text + if sh['client'].username: + text_sub = sh['client'].username + ": 0 V" + else: + text_sub = self.topbar_lastsub[0] textpos_sub += 30 elif i == 1: text_main = "Who is online" - text_sub = "Only you" + + # Sub text + if sh['client'].username: + if len(sh['client'].userlist) == 1: + text_sub = "Only you" + elif len(sh['client'].userlist) == 2: + text_sub = "1 other person" + else: + text_sub = len(sh['client'].userlist)-1 + " people" + else: + text_sub = self.topbar_lastsub[1] + textpos_sub += 32 elif i == 2: @@ -165,6 +190,7 @@ text_sub = "0 items" textpos_sub += 30 + self.topbar_lastsub[i] = text_sub # Blit image rect2.move_ip(0, -self.toppos) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |