From: <Blu...@us...> - 2010-08-23 21:59:47
|
Revision: 368 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=368&view=rev Author: BlueWolf_ Date: 2010-08-23 21:59:40 +0000 (Mon, 23 Aug 2010) Log Message: ----------- Now handles logging in properly. Although it won't give any reason for disconnects and failed logins yet Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/gui.py trunk/client/layout.py trunk/client/playground.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-08-19 20:13:11 UTC (rev 367) +++ trunk/client/VP.py 2010-08-23 21:59:40 UTC (rev 368) @@ -65,7 +65,7 @@ Callback()) self.changestatus("connecting") - sh['client'].connect('localhost', 6653) + sh['client'].connect(*SERVER) # Wait for all the events to come @@ -172,6 +172,31 @@ def logged_in(self, username, cid, owner): sh['main'].changestatus("playground") + + def failed_logging_in(self, reason): + # [TODO] Send the reason in some way + sh['main'].changestatus("login") + + def disconnected(self, reason): + if reason == "manual": return + + # [TODO] Send the reason in some way + if reason in ["closed", "gone offline"]: + # Reconnect while logging in + sh['main'].changestatus("connecting") + return True + + elif reason in ["duplicate", "crash"]: + # Reconnecting while not logging in + sh['main'].changestatus("connecting") + sh['client'].connect(*SERVER) + + else: + # Not doing anything at all + # [TODO] Show popup or something, without reconnecting? + sh['main'].changestatus("connecting") + + if __name__ == "__main__": Main() Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-08-19 20:13:11 UTC (rev 367) +++ trunk/client/functions.py 2010-08-23 21:59:40 UTC (rev 368) @@ -22,6 +22,8 @@ VERSION = "0.0.1" +SERVER = ("localhost", 6653) + # This will be used to [sh]are all variables, functions and classes across the # code sh = {} Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-08-19 20:13:11 UTC (rev 367) +++ trunk/client/gui.py 2010-08-23 21:59:40 UTC (rev 368) @@ -21,9 +21,10 @@ class Container(): # A modified version of Object - def __init__(self, update): + def __init__(self, update, feedback): self.rect = Rect(0, 0, 1000, 700) self.parent_update = update + self.feedback = feedback self.frozen = True # Don't update until everything has been # loaded @@ -58,7 +59,7 @@ else: raise GuiError("Object '%s' has not been found" % objname) - obj = Obj(name, rect, self, self) + obj = Obj(name, rect, self, self, self.feedback) self.children.append(obj) return obj @@ -256,11 +257,12 @@ class Object(): - def __init__(self, name, rect, main_parent, parent): + def __init__(self, name, rect, main_parent, parent, feedback): self.name = name self.rect = Rect(rect) self.main_parent = main_parent self.parent = parent + self.feedback = feedback self.needs_update = False self.frozen = True # Don't update until everything has been # loaded @@ -269,9 +271,6 @@ self.hover = False self.focus = False - # Callbacks - self.cb_keypress = None - # Create a surface where an object blits itself onto self.surf = pygame.Surface((self.rect.width, self.rect.height), \ SRCALPHA).convert_alpha() @@ -298,7 +297,7 @@ else: raise GuiError("Object '%s' has not been found" % objname) - obj = Obj(name, rect, self.main_parent, self) + obj = Obj(name, rect, self.main_parent, self, self.feedback) self.children.append(obj) return obj @@ -555,7 +554,7 @@ self.update() - if self.cb_keypress: self.cb_keypress(self, ev) + self.feedback.keypress(self, ev) class Button(Object): @@ -590,6 +589,10 @@ # Load the background images self.backgroundsurf = load_image(True, "images", "gui", "button_login.png") + # Load the font + self.font = pygame.font.Font(real_path("fonts", \ + "DejaVuSans-Bold.ttf"), 15) + else: raise GuiError("Style '%s' has not been found" % style) @@ -606,18 +609,31 @@ if self.style == "login": # Which state do we need? - if self.mousedown: - if self.ispressed: + if self.ispressed: top = 68 - else: - top = 0 + elif self.mousedown and not self.ispressed: + top = 0 elif self.hover: top = 34 else: top = 0 + # Blit the background self.surf.blit(self.backgroundsurf, (0,0), \ (0, top, self.rect.width, self.rect.height)) + + # Blit the text + if top == 0: + textcolor = [141, 56, 0] + elif top == 34: + textcolor = [214, 126, 68] + elif top == 68: + textcolor = [147, 81, 37] + textwidth = self.font.size(self.caption)[0] + font = self.font.render(self.caption, True, textcolor) + pos = ((self.rect.width/2) - (textwidth/2), 8) + self.surf.blit(font, pos) + def hovering(self, value): self.update() @@ -636,7 +652,13 @@ elif state == 2: self.mousedown = False + self.update() + + if self.ispressed: + self.submit() + + self.ispressed = False def got_focus(self): pass @@ -646,6 +668,13 @@ def keypress(self, ev): pass + + def submit(self): + self.feedback.submit(self) + + def manualpush(self, state): + self.ispressed = state + self.update() class GuiError(Exception): Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-08-19 20:13:11 UTC (rev 367) +++ trunk/client/layout.py 2010-08-23 21:59:40 UTC (rev 368) @@ -78,6 +78,9 @@ if status in login_list and self.status not in login_list: # (Un)load all the data self.topbar = None + + if self.status == "playground": + self.cleartop() elif status == "playground": self.topbar = load_image(True, "images", "topbar.png") @@ -109,6 +112,11 @@ sh['update']((0,0, 1000, 65)) + def cleartop(self): + # Remove the top bar from view + self.surf.fill([0,0,0,0]) + sh['update']((0,0, 1000, 65)) + def topbarcursor(self, pos): if pos[0] > TOPLEFT and pos[0] < (TOPBUTTONWIDTH*TOPBUTTONS+TOPLEFT) \ and pos[1] < 55: Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-08-19 20:13:11 UTC (rev 367) +++ trunk/client/playground.py 2010-08-23 21:59:40 UTC (rev 368) @@ -38,12 +38,7 @@ if self.status == "login": # Some temporary debug stuff - if ev.type == KEYDOWN and ev.key == K_F2: - # Fake login - self.drawlogin("logging in") - sh['client'].login("test123", sha1("test123").hexdigest()) - - elif ev.type == KEYDOWN and ev.key == K_F1: + if ev.type == KEYDOWN and ev.key == K_F1: # Fake signup sh['client'].signup("test123", sha1("test123").hexdigest(), { @@ -64,6 +59,7 @@ self.loginbox = load_image(True, "images", "loginbox.png") self.loginfont = pygame.font.Font(real_path("fonts", \ "DejaVuSans.ttf"), 35) + self.loginfeedback = LoginFeedback(self) elif status == "playground": # (Un)load all the data for the playground @@ -99,19 +95,18 @@ self.surf.blit(self.loginbox, (292,256)) # Create login-field - self.logingui = gui(self.logingui_draw) + self.logingui = gui(self.logingui_draw, LoginFeedback(self)) self.logingui.can_lose_focus = False username = self.logingui.add("textbox", "usr", (345, 279, 310, 37)) username.set_style("login") - username.cb_keypress = self.logingui_keypress password = self.logingui.add("textbox", "pwd", (345, 340, 310, 37)) password.set_style("login") password.set_type("password") - password.cb_keypress = self.logingui_keypress login = self.logingui.add("button", "login", (425, 398, 151, 34)) + login.caption = "Log in!" login.set_style("login") self.logingui.give_focus(username) @@ -128,14 +123,42 @@ def logingui_draw(self, rect): print "GUIupdate", 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) + + +class LoginFeedback(): + def __init__(self, parent): + self.parent = parent + + def keypress(self, obj, ev): + if obj.name == "usr": + # Using the enter key in the username field + if ev.type == KEYUP and ev.key == K_RETURN: + self.parent.logingui.give_focus("pwd") + + elif obj.name == "pwd": + # Using the enter key in the password field + if ev.type == KEYDOWN and ev.key == K_RETURN: + self.parent.logingui['login'].manualpush(True) + + elif ev.type == KEYUP and ev.key == K_RETURN: + self.parent.logingui['login'].manualpush(False) + self.parent.logingui['login'].submit() + - def logingui_keypress(self, obj, ev): - if ev.type == KEYDOWN: - if ev.unicode == "\r": - if obj.name == "pwd": - self.logingui.give_focus("usr") # [TODO] Not working? + def submit(self, obj): + # Clicking the login button + if obj.name == "login": + usr = self.parent.logingui['usr'].input + pwd = sha1(self.parent.logingui['pwd'].input).hexdigest() + + self.parent.logingui = None + sh['main'].changestatus("logging in") + + sh['client'].login(usr, pwd) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |