From: <Blu...@us...> - 2010-08-01 21:27:20
|
Revision: 350 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=350&view=rev Author: BlueWolf_ Date: 2010-08-01 21:27:14 +0000 (Sun, 01 Aug 2010) Log Message: ----------- Starting with the GUI-stuff. Hitting R when seeing the black box will result in a (fake) signup-request Modified Paths: -------------- trunk/client/VP.py trunk/client/core/client.py trunk/client/functions.py trunk/client/layout.py trunk/client/playground.py Added Paths: ----------- trunk/client/gui.py trunk/client/images/loginbox.png Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-07-30 00:32:51 UTC (rev 349) +++ trunk/client/VP.py 2010-08-01 21:27:14 UTC (rev 350) @@ -71,6 +71,8 @@ print # Someone decided to close VP (Why??) + try: self.sh['client'].close() + except: pass sys.exit() Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2010-07-30 00:32:51 UTC (rev 349) +++ trunk/client/core/client.py 2010-08-01 21:27:14 UTC (rev 350) @@ -110,7 +110,7 @@ If you want to reconnect, you have to close the connection first, if it's still open. - You can to Client.login and Client.bot_login directly after + You can do Client.login and Client.bot_login directly after this. It will be done as soon as it has received a rsa-key. """ @@ -258,6 +258,28 @@ }) + def signup(self, usr, pwd, extra = {}): + """ + Create a new account with on the server. You should have a + connection first before using this. + """ + + # Convert pwd + pwd = rsa.encrypt(pwd, self.__sh['rsakey']) + + if self.cid != None: + raise SignupError("You are already logged in") + + + # Sign up + self.send("signup", { + "usr": usr, + "pwd": pwd, + "extra": extra + }) + + + def send(self, data_header, data_body = {}): """ Sends `data_body` of type `data_header` to the server. It will @@ -293,9 +315,11 @@ self.__do_connect.clear() # Block the thread-loop self.__sh['is_online'] = False - self.__pinger.cancel() - self.__pinger = None + if self.__pinger != None: + self.__pinger.cancel() + self.__pinger = None + # Reset variables self.__sh['rsakey'] = None self.username = None @@ -350,3 +374,6 @@ class LoginError(Exception): pass + +class SignupError(Exception): + pass Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-07-30 00:32:51 UTC (rev 349) +++ trunk/client/functions.py 2010-08-01 21:27:14 UTC (rev 350) @@ -1,6 +1,8 @@ import pygame, os, sys, threading from pygame.locals import * +from hashlib import sha1 import core +import gui VERSION = "0.0.1" Added: trunk/client/gui.py =================================================================== --- trunk/client/gui.py (rev 0) +++ trunk/client/gui.py 2010-08-01 21:27:14 UTC (rev 350) @@ -0,0 +1,84 @@ +from functions import * + +class Plane(): + + def __init__(self, update, width, height): + self.update = update + self.width = width + self.height = height + self.surf = pygame.Surface((self.width, self.height), \ + SRCALPHA).convert_alpha() + self.norender = True + + self.childs = {} + + def __getitem__(self, key): + return self.childs[key] + + def add(self, *objs): + for obj in objs: + self.childs[obj.name] = obj + + + def renderall(self): + self.norender = False + for child in self.childs.values(): + child.renderall(Rect(0,0,0,0), self.surf) + + self.update(Rect(0,0, self.width, self.height)) + + + +class Object(): + + def __init__(self, name, rect): + self.name = name + self.rect = Rect(rect) + self.childs = {} + self.focus = False + self.hover = False + + # Load the defaults + self.__defaults__() + + def __getitem__(self, key): + return self.childs[key] + + def add(self, *objs): + for obj in objs: + self.childs[obj.name] = obj + + def renderall(self, correction, surf): + # First render ourself + self.render(correction, surf) + + # Then render our childs + for child in self.childs.values(): + child.renderall(correction.move(self.rect.topleft), surf) + + + +class Text(Object): + + def __defaults__(self): + self.input = "" + self.cursorpos = 0 + + def render(self, correction, surf): + pos = correction.move(self.rect.topleft) + pos.size = self.rect.size + + surf.fill([255,0,0], pos) + + +class Button(Object): + + def __defaults__(self): + self.caption = "" + + def render(self, correction, surf): + pos = correction.move(self.rect.topleft) + pos.size = self.rect.size + + surf.fill([0,0,255], pos) + Added: trunk/client/images/loginbox.png =================================================================== (Binary files differ) Property changes on: trunk/client/images/loginbox.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-07-30 00:32:51 UTC (rev 349) +++ trunk/client/layout.py 2010-08-01 21:27:14 UTC (rev 350) @@ -97,7 +97,7 @@ self.surf.blit(self.topbar, rect, rect2) - self.sh['update']() + self.sh['update']((0,0, 1000, 65)) def topbarcursor(self, pos): Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-07-30 00:32:51 UTC (rev 349) +++ trunk/client/playground.py 2010-08-01 21:27:14 UTC (rev 350) @@ -12,7 +12,9 @@ # Login stuff self.loginbg = None + self.loginbox = None self.loginfont = None + self.logingui = None # Playground stuff # ... @@ -22,23 +24,34 @@ if ev.type == KEYDOWN and ev.unicode == "\r": # Fake login self.drawlogin("logging in") - self.sh['client'].login("test", "123") + self.sh['client'].login("test123", sha1("test123").hexdigest()) + + elif ev.type == KEYDOWN and ev.unicode == "r": + # Fake signup + self.sh['client'].signup("test123", sha1("test123").hexdigest(), { + "realname": "Pietje Precies", + "gender": "M" + }) def changestatus(self, status): login_list = ['connecting', 'login', 'logging in'] if status in login_list and self.status not in login_list: - # (Un)load all the data + # (Un)load all 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) elif status == "playground": - # (Un)oad all the data + # (Un)load all the data for the playground self.loginbg = None + self.loginbox = None self.loginfont = None + self.logingui = None self.surf.fill([0,0,0]) self.sh['update']() @@ -66,11 +79,17 @@ self.surf.blit(text, (posleft, 330)) elif status == "login": - text = self.loginfont.render("Login-placeholder. " + \ - "Hit enter to fake log in", True, \ - (132,125,114)) - posleft = (1000/2)-(text.get_size()[0]/2) - self.surf.blit(text, (posleft, 330)) + self.surf.blit(self.loginbox, (292,256)) + # Create login-field + #self.logingui = gui.Plane(self.drawlogingui, 417,189) + #username = gui.Text("username", (0,0, 417, 50)) + #password = gui.Text("password", (0,50, 417, 50)) + #login = gui.Button("login", (0, 100, 417, 50)) + #self.logingui.add(username, password, login) + + # [TODO] Give mouseposition + #self.logingui.renderall() + elif status == "logging in": text = self.loginfont.render("Logging in...", True, \ @@ -79,3 +98,13 @@ self.surf.blit(text, (posleft, 330)) self.sh['update']() + + + def drawlogingui(self, rect): + rect_main = rect.move(292,256) + + self.surf.blit(self.loginbg, rect_main, rect_main) + self.surf.blit(self.loginbox, rect_main, rect) + self.surf.blit(self.logingui.surf, rect_main, rect) + + self.sh['update'](rect_main) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |