From: <Blu...@us...> - 2010-07-28 19:19:10
|
Revision: 342 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=342&view=rev Author: BlueWolf_ Date: 2010-07-28 19:19:04 +0000 (Wed, 28 Jul 2010) Log Message: ----------- Made a really fast (fake) login. But it will connect and login with the server now! Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/layout.py trunk/client/playground.py trunk/client/windows.py Added Paths: ----------- trunk/client/fonts/ trunk/client/fonts/DejaVuSans-Bold.ttf trunk/client/fonts/DejaVuSans.ttf Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-07-28 16:06:43 UTC (rev 341) +++ trunk/client/VP.py 2010-07-28 19:19:04 UTC (rev 342) @@ -2,6 +2,8 @@ from functions import * +import core + from playground import Playground from layout import Layout from windows import Windows @@ -9,30 +11,43 @@ class Main(): def __init__(self): - self.blit_lock = threading.Lock() + self.sh = {} # Fire up pygame os.environ['SDL_VIDEO_CENTERED']='1' pygame.init() pygame.display.set_caption('Virtual Playground') - sh['screen'] = pygame.display.set_mode((1000, 700)) + self.sh['screen'] = pygame.display.set_mode((1000, 700)) #icon = load_image('img','icon.png') #pygame.display.set_icon(icon) pygame.key.set_repeat(250, 40) pygame.scrap.init() - + self.clock = pygame.time.Clock() + + self.sh['main'] = self + # Give the surfaces a way to blit itself - sh['update'] = self.update + self.sh['update'] = self.update + self.updaterect = [] + self.updatewaiting = False - sh['status'] = "login" # What the user is seeing - # login - playground # Create all our surfaces - sh['playground'] = Playground() - sh['layout'] = Layout() - sh['windows'] = Windows() + self.sh['playground'] = Playground(self.sh) + self.sh['layout'] = Layout(self.sh) + self.sh['windows'] = Windows(self.sh) self.update() + + + # Connect to the server + self.sh['client'] = core.Client({ + 'app_name': "Virtual Playground", + 'app_version': VERSION}, + Callback(self.sh)) + + self.changestatus("connecting") + self.sh['client'].connect('vp.bluewolf.nl', 6653) # Wait for all the events to come @@ -47,9 +62,9 @@ pygame.event.clear(MOUSEMOTION) # Send through all the layers - if sh['windows'].event(ev): continue - if sh['layout'].event(ev): continue - if sh['playground'].event(ev): continue + if self.sh['windows'].event(ev): continue + if self.sh['layout'].event(ev): continue + if self.sh['playground'].event(ev): continue except KeyboardInterrupt: # Note: this does not work properly @@ -66,15 +81,65 @@ and update the screen """ - # Prevent multiple threads from blitting at the same time - self.blit_lock.acquire() + # The following code will prevent it from going crazy on the cpu + # aka: using unlimited FPS. This will limit the FPS to 50 and + # will remember everything that should be updated in the mean + # time - sh['screen'].blit(sh['playground'].surf, rect, rect) - sh['screen'].blit(sh['layout'].surf, rect, rect) - sh['screen'].blit(sh['windows'].surf, rect, rect) + self.updaterect.append(rect) + if self.updatewaiting: + # Rect is saved. Will be updated once self.clock stops + # blocking + return + # When there are more updates from here one, they will be saved + # without being updated immediately. We will do that once tick + # stops blocking + self.updatewaiting = True + self.clock.tick(50) + + # Get all the rects to update + if len(self.updaterect) == 1: + rects = self.updaterect[0] + else: + rects = self.updaterect[0].unionall(self.updaterect[1:]) + + self.updaterect = [] + self.updatewaiting = False + + + # The actual updating happens here + self.sh['screen'].blit(self.sh['playground'].surf, rect, rect) + self.sh['screen'].blit(self.sh['layout'].surf, rect, rect) + self.sh['screen'].blit(self.sh['windows'].surf, rect, rect) + pygame.display.update(rect) + + def changestatus(self, status): + self.sh['playground'].changestatus(status) + self.sh['layout'].changestatus(status) + self.sh['windows'].changestatus(status) + + +class Callback(core.Callback): + def __init__(self, sh): + self.sh = sh - self.blit_lock.release() + def data_received(self, data): + print " --> " + repr(data) + + def data_send(self, data): + print " <-- " + repr(data) + + def disconnect(self, reason): + print "Server disconnected: " + reason + + def received_rsa(self, public): + # We are connected + self.sh['main'].changestatus("login") + + def logged_in(self, username, cid, owner): + self.sh['main'].changestatus("playground") + if __name__ == "__main__": Main() Added: trunk/client/fonts/DejaVuSans-Bold.ttf =================================================================== (Binary files differ) Property changes on: trunk/client/fonts/DejaVuSans-Bold.ttf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/client/fonts/DejaVuSans.ttf =================================================================== (Binary files differ) Property changes on: trunk/client/fonts/DejaVuSans.ttf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-07-28 16:06:43 UTC (rev 341) +++ trunk/client/functions.py 2010-07-28 19:19:04 UTC (rev 342) @@ -2,6 +2,8 @@ from pygame.locals import * import core +VERSION = "0.0.1" + # This will be used to [sh]are all variables, functions and classes across the # code sh = {} Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-07-28 16:06:43 UTC (rev 341) +++ trunk/client/layout.py 2010-07-28 19:19:04 UTC (rev 342) @@ -1,9 +1,38 @@ from functions import * class Layout(): - def __init__(self): + def __init__(self, sh): + self.sh = sh + self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() + self.status = None + + # Login stuff + self.loginbg = None + self.loginfont = None + + # Playground stuff + self.topbar = None + def event(self, ev): pass + + + 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 + self.topbar = None + + elif status == "playground": + self.topbar = [ + load_image(True, "images", "topbar1.png"), + load_image(True, "images", "topbar2.png"), + load_image(True, "images", "topbar3.png") + ] + + self.surf.blit(self.topbar[0], (0,0)) + + self.sh['update']() Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-07-28 16:06:43 UTC (rev 341) +++ trunk/client/playground.py 2010-07-28 19:19:04 UTC (rev 342) @@ -1,18 +1,81 @@ from functions import * class Playground(): - def __init__(self): + def __init__(self, sh): + self.sh = sh + self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() self.surf.fill([0,0,0]) + self.status = None + # Login stuff self.loginbg = None - self.drawlogin() + self.loginfont = None + + # Playground stuff + # ... def event(self, ev): - print ev + if self.status == "login": + if ev.type == KEYDOWN and ev.unicode == "\r": + # Fake login + self.drawlogin("logging in") + self.sh['client'].login("myname", "mypass") + - def drawlogin(self): - self.loginbg = load_image(False, "images", "loginbg.png") + 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 + self.loginbg = load_image(False, "images", \ + "loginbg.png") + self.loginfont = pygame.font.Font(real_path("fonts", \ + "DejaVuSans.ttf"), 35) + + + elif status == "playground": + # (Un)oad all the data + self.loginbg = None + self.loginfont = None + + self.surf.fill([0,0,0]) + self.sh['update']() + + + if status == "connecting": + self.drawlogin("connecting") + elif status == "login": + self.drawlogin("login") + elif status == "logging in": + self.drawlogin("logging in") + + self.status = status + + + 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": + 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)) + + 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)) + + self.sh['update']() Modified: trunk/client/windows.py =================================================================== --- trunk/client/windows.py 2010-07-28 16:06:43 UTC (rev 341) +++ trunk/client/windows.py 2010-07-28 19:19:04 UTC (rev 342) @@ -1,9 +1,14 @@ from functions import * class Windows(): - def __init__(self): + def __init__(self, sh): + self.sh = sh + self.surf = pygame.Surface((1000, 700), \ SRCALPHA).convert_alpha() def event(self, ev): pass + + def changestatus(self, status): + pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |