From: <Blu...@us...> - 2010-09-17 18:10:25
|
Revision: 409 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=409&view=rev Author: BlueWolf_ Date: 2010-09-17 18:10:18 +0000 (Fri, 17 Sep 2010) Log Message: ----------- Moved the login-part to a seperate layer Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/gui.py trunk/client/playground.py Added Paths: ----------- trunk/client/login.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-15 19:04:32 UTC (rev 408) +++ trunk/client/VP.py 2010-09-17 18:10:18 UTC (rev 409) @@ -24,6 +24,7 @@ from playground import Playground from layout import Layout from windows import Windows +from login import Login from downloader import Downloader from timer import Timer from callback import Callback @@ -64,6 +65,7 @@ sh['playground'] = Playground() sh['layout'] = Layout() sh['windows'] = Windows() + sh['login'] = Login() self.update() @@ -113,6 +115,7 @@ # Send through all the layers if sh['windows'].event(ev): continue if sh['layout'].event(ev): continue + if sh['login'].event(ev): continue if sh['playground'].event(ev): continue @@ -152,6 +155,7 @@ # The actual updating happens here sh['screen'].blit(sh['playground'].surf, rect, rect) + sh['screen'].blit(sh['login'].surf, rect, rect) sh['screen'].blit(sh['layout'].surf, rect, rect) sh['screen'].blit(sh['windows'].surf, rect, rect) @@ -161,6 +165,7 @@ log("debug", "Call:", name + ' - ' + str(data)) sh['playground'].call(name, data) + sh['login'].call(name, data) sh['layout'].call(name, data) sh['windows'].call(name, data) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-15 19:04:32 UTC (rev 408) +++ trunk/client/functions.py 2010-09-17 18:10:18 UTC (rev 409) @@ -22,10 +22,12 @@ from validate import Validator import core -# To get colors working in Windows +# To get colors working in Windows. Though it works partially if os.name == "nt": - import colarama - colarama.init() + try: import colarama + except: pass + else: + colarama.init() VERSION = "0.0.1" Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-15 19:04:32 UTC (rev 408) +++ trunk/client/gui.py 2010-09-17 18:10:18 UTC (rev 409) @@ -36,6 +36,7 @@ self.rect = Rect(0, 0, 1000, 700) self.parent_update = update self.feedback = feedback + self.feedback.gui = self self.frozen = True # Don't update until everything has been # loaded @@ -68,7 +69,10 @@ Append a child to this object """ - if feedback == None: feedback = self.feedback + if feedback == None: + feedback = self.feedback + else: + feedback.gui = self obj = Obj(name, rect, self, self, feedback) self.children.append(obj) @@ -359,7 +363,10 @@ Append a child to this object """ - if feedback == None: feedback = self.feedback + if feedback == None: + feedback = self.feedback + else: + feedback.gui = self obj = Obj(name, rect, self.main_parent, self) self.children.append(obj) Added: trunk/client/login.py =================================================================== --- trunk/client/login.py (rev 0) +++ trunk/client/login.py 2010-09-17 18:10:18 UTC (rev 409) @@ -0,0 +1,225 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from functions import * +import gui + +class Login(): + def __init__(self): + self.surf = pygame.Surface((1000, 700)).convert() + + self.status = None + self.statuswhere = None + + self.transit = None + self.background = None + self.loginbox = None + self.font = None + self.gui = None + + def event(self, ev): + if self.status == "login": + + # Some temporary debug stuff + if ev.type == KEYDOWN and ev.key == K_F1: + # Fake signup + sh['client'].signup("test123", sha1("test123").hexdigest(), + { + "realname": "Pietje Precies", + "email": "sp...@sp..." + }) + + if self.gui != None: + return self.gui.event(ev) + + + def call(self, name, data): + if name == "status": # A status update + if data['status'] == "login": + if self.status != "login": + # Load the data for the login + self.surf.set_alpha(None) + self.background = load_image(False, "images", "loginbg.png") + self.loginbox = load_image(True, "images", "loginbox.png") + self.font = pygame.font.Font(real_path("fonts", \ + "DejaVuSans.ttf"), 35) + + + if data['where'] in ["connecting", "waiting", "logging in", + "downloading"]: + self.drawlogin(data['where']) + + elif data['status'] != "login" and self.status == "login": + # Unload data from the login + self.background = None + self.loginbox = None + self.font = None + self.gui = None + self.transit = 255 + sh['timer'].start("login-transit", self.timer, time.time()) + + self.status = data['status'] + self.statuswhere = data['where'] + + def drawlogin(self, status): + self.surf.blit(self.background, (0,0)) + + if status == "connecting": # Showing text + + text = self.font.render("Connecting...", True, (132,125,114)) + posleft = (1000/2)-(text.get_width()/2) + self.surf.blit(text, (posleft, 330)) + + elif status == "waiting": # Showing loginbox + self.surf.blit(self.loginbox, (292,256)) + + # Create login-field + self.gui = gui.Container(self.gui_draw, LoginFeedback()) + + usrlabel = self.gui.add(gui.Label, "usrlabel", \ + (345, 265, 310, 18)) + usrlabel.caption = "Username:" + usrlabel.align = 1 + usrlabel.color = [177, 93, 39] + usrlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) + + usr = self.gui.add(gui.Textbox, "usrtextbox", (345, 285, 310, 37)) + usr.set_style("login") + + pwdlabel = self.gui.add(gui.Label, "pwdlabel", \ + (345, 330, 310, 18)) + pwdlabel.caption = "Password:" + pwdlabel.align = 1 + pwdlabel.color = [177, 93, 39] + pwdlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) + + pwd = self.gui.add(gui.Textbox, "pwdtextbox", (345, 350, 310, 37)) + pwd.set_style("login") + pwd.set_type("password") + + login = self.gui.add(gui.Button, "loginbutton", (425, 398, 151, 34)) + login.caption = "Log in!" + login.set_style("login") + + signup = self.gui.add(gui.Link, "signuplink", (345, 470, 310, 18)) + signup.caption = "Don't have an account yet?" + signup.align = 1 + signup.color = [140, 74, 31] + signup.color_hover = [177, 93, 39] + signup.color_click = [255, 217, 192] + signup.set_font(("fonts", "DejaVuSans.ttf"), 12) + + self.gui.give_focus(usr) + self.gui.unfreeze() + + + elif status == "logging in": # Showing text + text = self.font.render("Logging in...", True, (132,125,114)) + posleft = (1000/2)-(text.get_width()/2) + self.surf.blit(text, (posleft, 330)) + + + elif status == "downloading": # Showing text + text = self.font.render("Downloading...", True, (132,125,114)) + posleft = (1000/2)-(text.get_width()/2) + self.surf.blit(text, (posleft, 330)) + + sh['update']() + + def gui_draw(self, rect): + if self.gui == None: return + + self.surf.blit(self.background, rect, rect) + self.surf.blit(self.loginbox, (292, 256)) + self.surf.blit(self.gui.surf, rect, rect) + + sh['update'](rect) + + + def timer(self, name, starttime): + if name == "login-transit": + length = 1.0 + timeline = (time.time() - starttime) / length + if timeline > 1: + self.transit = None + self.surf.fill([0,0,0,0]) + self.surf.set_alpha(0) + sh['update']() + return True + else: + self.transit = (1-timeline)*255 + self.surf.set_alpha(self.transit) + sh['update']() + + +class LoginFeedback(gui.Feedback): + def keypress(self, obj, ev): + if obj.name == "usrtextbox": + # Using the enter key in the username field + if ev.type == KEYUP and ev.key == K_RETURN: + self.gui.give_focus("pwdtextbox") + + elif obj.name == "pwdtextbox": + # Using the enter key in the password field + if ev.type == KEYDOWN and ev.key == K_RETURN: + self.gui['loginbutton'].manualpush(True) + + elif ev.type == KEYUP and ev.key == K_RETURN: + self.gui['loginbutton'].manualpush(False) + self.gui['loginbutton'].submit() + + + def submit(self, obj): + # Clicking the login button + if obj.name == "loginbutton": + usr = self.gui['usrtextbox'].input + pwd = sha1(self.gui['pwdtextbox'].input).hexdigest() + + sh['main'].call("status", { + "status": "login", + "where": "logging in" + }) + + # Save the info so it can be saved if the login succeeds + sh['login_info'] = (usr,pwd) + + sh['client'].login(usr, pwd) + + elif obj.name == "signuplink": + + if self.gui.has("signup"): return + + # Create signup window + window = self.gui.add(gui.Window, "signup", \ + Rect(300, 140, 400, 420), SignupFeedback()) + window.caption = "Signup" + + #window.add(gui. + + window.unfreeze() + + + def mousedown(self, obj): + if obj.name == "usrlabel": + self.gui.give_focus('usrtextbox') + + elif obj.name == "pwdlabel": + self.gui.give_focus('pwdtextbox') + + +class SignupFeedback(gui.Feedback): + pass Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-15 19:04:32 UTC (rev 408) +++ trunk/client/playground.py 2010-09-17 18:10:18 UTC (rev 409) @@ -24,20 +24,9 @@ def __init__(self): self.surf = pygame.Surface((1000, 700)).convert() - self.surf.fill([0,0,0]) self.status = None self.statuswhere = None - self.oldsurf = None - self.transit = None - - # Login stuff - self.loginbg = None - self.loginbox = None - self.loginfont = None - self.logingui = None - - # Playground stuff self.backgrounds = {} self.viewport = None self.direction = None @@ -47,22 +36,7 @@ def event(self, ev): - if self.status == "login": - - # Some temporary debug stuff - if ev.type == KEYDOWN and ev.key == K_F1: - # Fake signup - sh['client'].signup("test123", sha1("test123").hexdigest(), - { - "realname": "Pietje Precies", - "email": "sp...@sp..." - }) - - if self.logingui != None: - return self.logingui.event(ev) - - - elif self.status == "playground": + if self.status == "playground": if ev.type == KEYDOWN or ev.type == KEYUP: if ev.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: @@ -108,80 +82,46 @@ def call(self, name, data): if name == "status": # A status update - if data['status'] == "login": - if data['status'] != self.status: - # Unload data from the playground - if self.status != None: - sh['timer'].stop("playground-transit") - sh['timer'].stop("playground-move") - for name in self.backgrounds.keys(): - sh['downloader'].remove_usage(name) - self.backgrounds = {} - self.viewport = None - self.direction = None - self.avatars = {} - self.this_user = None - self.avatar_offset = None - - # Load the data for the login - self.loginbg = load_image(False, "images", "loginbg.png") - self.loginbox = load_image(True, "images", "loginbox.png") - self.loginfont = pygame.font.Font(real_path("fonts", \ - "DejaVuSans.ttf"), 35) - self.loginfeedback = LoginFeedback(self) - + if data['status'] == "login" and self.status == "playground": + # Unload data from the playground + sh['timer'].stop("playground-move") + for name in self.backgrounds.keys(): + sh['downloader'].remove_usage(name) + self.backgrounds = {} + self.viewport = None + self.direction = None + self.avatars = {} + self.this_user = None + self.avatar_offset = None + + elif data['status'] == "playground" and self.status != "playground": + # Load the data for the playground - if data['where'] == "connecting": - self.drawlogin("connecting") - - elif data['where'] == "waiting": - self.drawlogin("login") - - elif data['where'] == "logging in": - self.drawlogin("logging in") - - elif data['where'] == "downloading": - self.drawlogin("downloading") + # Load all users + self.this_user = sh['client'].userlist[sh['client'].cid] + for user in sh['client'].userlist.values(): + if user['pos'] != None: + self.avatars[user['cid']] = Avatar(user) + + to_center = ( + (self.surf.get_width()/2) - \ + (self.avatars[self.this_user['cid']].size[0]/2), + (self.surf.get_height()/2) - \ + (self.avatars[self.this_user['cid']].size[1]/2), + ) + self.avatar_offset = ( + self.this_user['pos'][0] - to_center[0], + self.this_user['pos'][1] - to_center[1],\ + ) + + self.viewport = Rect( + self.avatar_offset[0], + self.avatar_offset[1], + 1000, + 700) + + self.playground_render() - elif data['status'] == "playground": - if data['status'] != self.status: - # Unload data from the login - self.loginbg = None - self.loginbox = None - self.loginfont = None - self.logingui = None - - # Load the data for the playground - - # Load all users - self.this_user = sh['client'].userlist[sh['client'].cid] - for user in sh['client'].userlist.values(): - if user['pos'] != None: - self.avatars[user['cid']] = Avatar(user) - - to_center = ( - (self.surf.get_width()/2) - \ - (self.avatars[self.this_user['cid']].size[0]/2), - (self.surf.get_height()/2) - \ - (self.avatars[self.this_user['cid']].size[1]/2), - ) - self.avatar_offset = ( - self.this_user['pos'][0] - to_center[0], - self.this_user['pos'][1] - to_center[1],\ - ) - - self.viewport = Rect( - self.avatar_offset[0], - self.avatar_offset[1], - 1000, - 700) - - self.oldsurf = self.surf.copy() - self.transit = 1 - self.playground_render(None, True) - sh['timer'].start("playground-transit", self.timer, \ - time.time()) - self.status = data['status'] self.statuswhere = data['where'] @@ -196,85 +136,6 @@ "background", counter) - def drawlogin(self, status): - self.loginstatus = status - self.surf.blit(self.loginbg, (0,0)) - - if status == "connecting": - - text = self.loginfont.render("Connecting...", True, (132,125,114)) - posleft = (1000/2)-(text.get_size()[0]/2) - self.surf.blit(text, (posleft, 330)) - - elif status == "login": - self.surf.blit(self.loginbox, (292,256)) - - # Create login-field - self.logingui = gui.Container(self.logingui_draw, \ - LoginFeedback(self)) - self.logingui.can_lose_focus = False - - usrlabel = self.logingui.add(gui.Label, "usrlabel", \ - (345, 265, 310, 18)) - usrlabel.caption = "Username:" - usrlabel.align = 1 - usrlabel.color = [177, 93, 39] - usrlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) - - usr = self.logingui.add(gui.Textbox, "usrtextbox", (345, 285, 310, 37)) - usr.set_style("login") - - pwdlabel = self.logingui.add(gui.Label, "pwdlabel", \ - (345, 330, 310, 18)) - pwdlabel.caption = "Password:" - pwdlabel.align = 1 - pwdlabel.color = [177, 93, 39] - pwdlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) - - pwd = self.logingui.add(gui.Textbox, "pwdtextbox", (345, 350, 310, 37)) - pwd.set_style("login") - pwd.set_type("password") - - login = self.logingui.add(gui.Button, "loginbutton", (425, 398, 151, 34)) - login.caption = "Log in!" - login.set_style("login") - - signup = self.logingui.add(gui.Link, "signuplink", (345, 470, 310, 18)) - signup.caption = "Don't have an account yet?" - signup.align = 1 - signup.color = [140, 74, 31] - signup.color_hover = [177, 93, 39] - signup.color_click = [255, 217, 192] - signup.set_font(("fonts", "DejaVuSans.ttf"), 12) - - self.logingui.give_focus(usr) - self.logingui.unfreeze() - - - elif status == "logging in": - text = self.loginfont.render("Logging in...", True, (132,125,114)) - posleft = (1000/2)-(text.get_size()[0]/2) - self.surf.blit(text, (posleft, 330)) - - - elif status == "downloading": - text = self.loginfont.render("Downloading...", True, (132,125,114)) - posleft = (1000/2)-(text.get_size()[0]/2) - self.surf.blit(text, (posleft, 330)) - - sh['update']() - - def logingui_draw(self, rect): - if self.logingui == None: return - - self.surf.blit(self.loginbg, rect, rect) - self.surf.blit(self.loginbox, (292, 256)) - self.surf.blit(self.logingui.surf, rect, rect) - - sh['update'](rect) - - - def playground_render(self, rect = None, doupdate = True): # Render the playground if rect == None: @@ -326,11 +187,6 @@ rect.height) avatar.blit(self.surf, avatar_area) - - if self.transit != None: # An transition is happening - self.oldsurf.set_alpha(self.transit*255) - self.surf.blit(self.oldsurf, (0,0)) - if doupdate: sh['update'](rect) @@ -348,19 +204,6 @@ "status": "playground", "where": "playground" }) - - def timer(self, name, starttime): - if name == "playground-transit": - length = 1 - timeline = (time.time() - starttime) / length - - if timeline > 1: - self.transit = None - self.playground_render() - return True - - self.transit = 1 - timeline - self.playground_render() def playground_walk(self, name): @@ -394,67 +237,4 @@ self.this_user['pos'][0]+self.avatar_offset[0], self.this_user['pos'][1]+self.avatar_offset[1], ) - self.playground_render() - - -class LoginFeedback(gui.Feedback): - def __init__(self, parent): - self.parent = parent - - def keypress(self, obj, ev): - if obj.name == "usrtextbox": - # Using the enter key in the username field - if ev.type == KEYUP and ev.key == K_RETURN: - self.parent.logingui.give_focus("pwdtextbox") - - elif obj.name == "pwdtextbox": - # Using the enter key in the password field - if ev.type == KEYDOWN and ev.key == K_RETURN: - self.parent.logingui['loginbutton'].manualpush(True) - - elif ev.type == KEYUP and ev.key == K_RETURN: - self.parent.logingui['loginbutton'].manualpush(False) - self.parent.logingui['loginbutton'].submit() - - - def submit(self, obj): - # Clicking the login button - if obj.name == "loginbutton": - usr = self.parent.logingui['usrtextbox'].input - pwd = sha1(self.parent.logingui['pwdtextbox'].input).hexdigest() - - self.parent.logingui = None - sh['main'].call("status", { - "status": "login", - "where": "logging in" - }) - - # Save the info so it can be saved it the login succeeds - sh['login_info'] = (usr,pwd) - - sh['client'].login(usr, pwd) - - elif obj.name == "signuplink": - - if self.parent.logingui.has("signup"): return - - # Create signup window - window = self.parent.logingui.add(gui.Window, "signup", \ - Rect(300, 140, 400, 420), SignupFeedback()) - window.caption = "Signup" - - #window.add(gui. - - window.unfreeze() - - - def mousedown(self, obj): - if obj.name == "usrlabel": - self.parent.logingui.give_focus('usrtextbox') - - elif obj.name == "pwdlabel": - self.parent.logingui.give_focus('pwdtextbox') - - -class SignupFeedback(gui.Feedback): - pass + self.playground_render() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |