From: <Blu...@us...> - 2010-09-04 20:55:44
|
Revision: 389 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=389&view=rev Author: BlueWolf_ Date: 2010-09-04 20:55:38 +0000 (Sat, 04 Sep 2010) Log Message: ----------- Spreading some code across multiple files to make them more findable Modified Paths: -------------- trunk/client/VP.py trunk/client/functions.py trunk/client/playground.py Added Paths: ----------- trunk/client/callback.py trunk/client/timer.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-01 21:01:21 UTC (rev 388) +++ trunk/client/VP.py 2010-09-04 20:55:38 UTC (rev 389) @@ -25,6 +25,8 @@ from layout import Layout from windows import Windows from downloader import Downloader +from timer import Timer +from callback import Callback class Main(): @@ -147,164 +149,5 @@ sh['layout'].call(name, data) sh['windows'].call(name, data) -class Timer(): - """ - This timer will update every frame as defined in the config - """ - def __init__(self): - self.speed = 1/float(sh['config']['graphics']['fps']) - self.callers = {} - self.timer = None - - def start(self, name, call, *extra): - # Start a timer for this call - - self.callers[name] = (call, extra) - - if self.timer == None: # Start a timer - self.timer = threading.Timer(self.speed, self.update) - self.timer.start() - - def stop(self, name): - try: del self.callers[name] - except: pass - - if self.callers == {} and self.timer: - self.timer.cancel() - self.timer = None - - def update(self): - # Stop blitting to the screen - sh['main'].updaterect = [] - sh['main'].updatewaiting = True - - # Do stuff - for name, info in self.callers.items(): - if info[0](name, *info[1]): - del self.callers[name] - - # Force one big update - sh['main'].updatewaiting = False - if sh['main'].updaterect != []: - sh['main'].update(sh['main'].updaterect) - sh['main'].updaterect = [] - - - # Start the next timer - if self.callers != {}: - self.timer = threading.Timer(self.speed, self.update) - self.timer.start() - else: - self.timer = None - -class Callback(core.Callback): - - def data_received(self, data): - print " --> \t" + repr(data) - - def data_send(self, data): - print " <-- \t" + repr(data) - - def connection_ready(self, public_rsa, reconnecting): - # We are connected - - if reconnecting: - sh['main'].call("status", { - "status": "login", - "where": "logging in" - }) - else: - # Do we need to log in automatically? - if sh['config']['user']['username'] != "": - sh['main'].call("status", { - "status": "login", - "where": "logging in" - }) - sh['client'].login(sh['config']['user']['username'], \ - sh['config']['user']['password']) - - else: - sh['main'].call("status", { - "status": "login", - "where": "waiting" - }) - - def logged_in(self, username, cid, owner): - sh['main'].call("status", { - "status": "login", - "where": "downloading" - }) - - # Save the login - if sh['login_info'] != None: - sh['config']['user']['username'] = sh['login_info'][0] - sh['config']['user']['password'] = sh['login_info'][1] - sh['login_info'] = None - sh['config'].write() - - def failed_logging_in(self, reason): - # [TODO] Send the reason in some way - - sh['main'].call("status", { - "status": "login", - "where": "waiting" - }) - - sh['config']['user']['username'] = "" - sh['config']['user']['password'] = "" - sh['login_info'] = None - sh['config'].write() - - - def disconnected(self, reason): - print " !!! \tConnection closed: " + reason - - sh['login_info'] = None - - if reason == "manual": return - - # [TODO] Send the reason in some way - if reason in ["closed", "gone offline"]: - # Reconnect while logging in - sh['main'].call("status", { - "status": "login", - "where": "connecting" - }) - return True - - elif reason in ["duplicate", "crash"]: - # Reconnecting while not logging in - sh['main'].call("status", { - "status": "login", - "where": "connecting" - }) - - # But don't reconnect when we where a duplicate - if reason == "duplicate": - sh['config']['user']['username'] = "" - sh['config']['user']['password'] = "" - sh['config'].write() - - sh['client'].connect(sh['config']['host']['host'], \ - sh['config']['host']['port']) - - else: - # Not doing anything at all - # [TODO] Show popup or something, without reconnecting? - sh['main'].call("status", { - "status": "login", - "where": "connecting" - }) - - def custom_received(self, header, body): - if header == "filetable": # List of all the downloadable objects - sh['filetable'] = body - - sh['main'].call("filetable", { - "action": "update" - }) - - - if __name__ == "__main__": Main() Added: trunk/client/callback.py =================================================================== --- trunk/client/callback.py (rev 0) +++ trunk/client/callback.py 2010-09-04 20:55:38 UTC (rev 389) @@ -0,0 +1,128 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2010 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 core + +class Callback(core.Callback): + + def data_received(self, data): + print " --> \t" + repr(data) + + def data_send(self, data): + print " <-- \t" + repr(data) + + def connection_ready(self, public_rsa, reconnecting): + # We are connected + + if reconnecting: + sh['main'].call("status", { + "status": "login", + "where": "logging in" + }) + else: + # Do we need to log in automatically? + if sh['config']['user']['username'] != "": + sh['main'].call("status", { + "status": "login", + "where": "logging in" + }) + sh['client'].login(sh['config']['user']['username'], \ + sh['config']['user']['password']) + + else: + sh['main'].call("status", { + "status": "login", + "where": "waiting" + }) + + def logged_in(self, username, cid, owner): + sh['main'].call("status", { + "status": "login", + "where": "downloading" + }) + + # Save the login + if sh['login_info'] != None: + sh['config']['user']['username'] = sh['login_info'][0] + sh['config']['user']['password'] = sh['login_info'][1] + sh['login_info'] = None + sh['config'].write() + + def failed_logging_in(self, reason): + # [TODO] Send the reason in some way + + sh['main'].call("status", { + "status": "login", + "where": "waiting" + }) + + sh['config']['user']['username'] = "" + sh['config']['user']['password'] = "" + sh['login_info'] = None + sh['config'].write() + + + def disconnected(self, reason): + print " !!! \tConnection closed: " + reason + + sh['login_info'] = None + + if reason == "manual": return + + # [TODO] Send the reason in some way + if reason in ["closed", "gone offline"]: + # Reconnect while logging in + sh['main'].call("status", { + "status": "login", + "where": "connecting" + }) + return True + + elif reason in ["duplicate", "crash"]: + # Reconnecting while not logging in + sh['main'].call("status", { + "status": "login", + "where": "connecting" + }) + + # But don't reconnect when we where a duplicate + if reason == "duplicate": + sh['config']['user']['username'] = "" + sh['config']['user']['password'] = "" + sh['config'].write() + + sh['client'].connect(sh['config']['host']['host'], \ + sh['config']['host']['port']) + + else: + # Not doing anything at all + # [TODO] Show popup or something, without reconnecting? + sh['main'].call("status", { + "status": "login", + "where": "connecting" + }) + + def custom_received(self, header, body): + if header == "filetable": # List of all the downloadable objects + sh['filetable'] = body + + sh['main'].call("filetable", { + "action": "update" + }) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-01 21:01:21 UTC (rev 388) +++ trunk/client/functions.py 2010-09-04 20:55:38 UTC (rev 389) @@ -87,9 +87,3 @@ print "Config: The '%s' section is missing" % section_list[0] sys.exit() - - - -# GUI needs the functions again. That's why it has to be imported after all -# functions have been defined -import gui Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-01 21:01:21 UTC (rev 388) +++ trunk/client/playground.py 2010-09-04 20:55:38 UTC (rev 389) @@ -16,6 +16,7 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. from functions import * +import gui class Playground(): Added: trunk/client/timer.py =================================================================== --- trunk/client/timer.py (rev 0) +++ trunk/client/timer.py 2010-09-04 20:55:38 UTC (rev 389) @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2010 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 * + +class Timer(): + """ + This timer will update every frame as defined in the config + """ + def __init__(self): + self.speed = 1/float(sh['config']['graphics']['fps']) + self.callers = {} + self.timer = None + + def start(self, name, call, *extra): + # Start a timer for this call + + self.callers[name] = (call, extra) + + if self.timer == None: # Start a timer + self.timer = threading.Timer(self.speed, self.update) + self.timer.start() + + def stop(self, name): + try: del self.callers[name] + except: pass + + if self.callers == {} and self.timer: + self.timer.cancel() + self.timer = None + + def update(self): + # Stop blitting to the screen + sh['main'].updaterect = [] + sh['main'].updatewaiting = True + + # Do stuff + for name, info in self.callers.items(): + if info[0](name, *info[1]): + del self.callers[name] + + # Force one big update + sh['main'].updatewaiting = False + if sh['main'].updaterect != []: + sh['main'].update(sh['main'].updaterect) + sh['main'].updaterect = [] + + + # Start the next timer + if self.callers != {}: + self.timer = threading.Timer(self.speed, self.update) + self.timer.start() + else: + self.timer = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-04 22:48:39
|
Revision: 390 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=390&view=rev Author: BlueWolf_ Date: 2010-09-04 22:48:33 +0000 (Sat, 04 Sep 2010) Log Message: ----------- Window now has a GUI and opening one works now Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-04 20:55:38 UTC (rev 389) +++ trunk/client/gui.py 2010-09-04 22:48:33 UTC (rev 390) @@ -412,6 +412,135 @@ self.caption = "" self.canclose = True + self.gui = load_image(True, "images", "gui", "window.png") + self.backgroundsurf = self.surf.copy() + self.font = pygame.font.Font(real_path("fonts", \ + "DejaVuSans-Bold.ttf"), 14) + + self.buttonstate = 0 + + self.pos = { + # img is the position on the image + # pos is the rendered position + # If the pos or size it's negative, it's (-value - width or + # height). + + # Corners + "topleft_img": (0, 0, 29, 37), + "topleft_pos": (0, 0, 29, 37), + + "topright_img": (32, 0, 29, 37), + "topright_pos": (-29, 0, 29, 37), + + "bottomleft_img": (0, 40, 14, 14), + "bottomleft_pos": (0, -14, 14, 14), + + "bottomright_img": (47, 40, 14, 14), + "bottomright_pos": (-14, -14, 14, 14), + + # Middle parts + "topmiddle_img": (30, 0, 1, 37), + "topmiddle_pos": (29, 0, -58, 37), + + "bottommiddle_img": (30, 40, 1, 14), + "bottommiddle_pos": (14, -14, -28, 14), + + "leftmiddle_img": (0, 38, 14, 1), + "leftmiddle_pos": (0, 37, 14, -51), + + "rightmiddle_img": (47, 38, 14, 1), + "rightmiddle_pos": (-14, 37, 14, -51), + + # Close button + "close_img": (61, 0, 28, 28), + "closeH_img": (90, 0, 28, 28), + "closeC_img": (119, 0, 28, 28), + "close_pos": (-42, 9, 28, 28), + + # Other + "inner_pos": (14, 37, -28, -51) + } + + self.colors = { + "bgcolor": (51, 51, 51), + "title": (230, 230, 230), + "title_shadow": (0, 0, 0), + } + + self.create_layout() + + def calculate_pos(self, pos): + rect = Rect(0, 0, 0, 0) + for posid, rectid in zip((0, 1, 2, 3), (2, 3, 2, 3)): + if pos[posid] < 0: + rect[posid] = self.rect[rectid] + pos[posid] + else: + rect[posid] = pos[posid] + return rect + + def create_layout(self): + # Calculate every position in self.pos and blit it + for name in ["topleft", "topright", "bottomleft", "bottomright", \ + "topmiddle", "bottommiddle", "leftmiddle", "rightmiddle"]: + + img = self.pos[name + "_img"] + pos = self.pos[name + "_pos"] + + # Calculate the position + rect = self.calculate_pos(pos) + + # Blit the image + + # Do we need to resize it? + if (pos[2], pos[3]) != (rect[2], rect[3]): + tempsurf = pygame.Surface((img[2], img[3]), SRCALPHA).convert_alpha() + tempsurf.blit(self.gui, (0,0), img) + tempsurf = pygame.transform.scale(tempsurf, (rect[2], rect[3])) + self.backgroundsurf.blit(tempsurf, rect) + else: + self.backgroundsurf.blit(self.gui, rect, img) + + # Fill inner part + inner = self.calculate_pos(self.pos['inner_pos']) + self.backgroundsurf.fill(self.colors['bgcolor'], inner) + + def render(self): + self.surf.fill([0, 0, 0, 0]) + self.surf.blit(self.backgroundsurf, (0,0)) + + # Create title + if self.canclose: + width = self.rect.width - 56 + else: + width = self.rect.width - 28 + + textwidth = self.font.size(self.caption)[0] + pos = ((width/2) - (textwidth/2)) + 14 + + # Shadow + text = self.font.render(self.caption, True, self.colors['title_shadow']) + self.surf.blit(text, (pos+1, 15)) + + # Foreground + text = self.font.render(self.caption, True, self.colors['title']) + self.surf.blit(text, (pos, 14)) + + # Create button + if self.canclose: + if self.buttonstate == 0: + img = self.pos['close_img'] + elif self.buttonstate == 1: + img = self.pos['closeH_img'] + elif self.buttonstate == 2: + img = self.pos['closeC_img'] + rect = self.calculate_pos(self.pos['close_pos']) + + self.surf.blit(self.gui, rect, img) + + + + + def move(self, topos): # [TODO] pass Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-04 20:55:38 UTC (rev 389) +++ trunk/client/playground.py 2010-09-04 22:48:33 UTC (rev 390) @@ -349,7 +349,14 @@ sh['client'].login(usr, pwd) elif obj.name == "signup": - print "signup!" + + # Create signup window + window = self.parent.logingui.add(gui.Window, "signup", \ + Rect(0, 0, 200, 200), SignupFeedback()) + window.caption = "Signup" + + window.unfreeze() + def mousedown(self, obj): if obj.name == "usrlabel": @@ -357,3 +364,7 @@ elif obj.name == "pwdlabel": self.parent.logingui.give_focus('pwd') + + +class SignupFeedback(gui.Feedback): + pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-05 21:06:36
|
Revision: 391 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=391&view=rev Author: BlueWolf_ Date: 2010-09-05 21:06:29 +0000 (Sun, 05 Sep 2010) Log Message: ----------- Windows can now be moved and stacked. I also miiiight have forgotten to add the gui-window images in my last commit. So I'm adding it now. There seems to be a minor pygame/SDL bug with transparent images above transparant images. It's barely noticable though Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Added Paths: ----------- trunk/client/images/gui/window.png Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-04 22:48:33 UTC (rev 390) +++ trunk/client/gui.py 2010-09-05 21:06:29 UTC (rev 391) @@ -183,7 +183,7 @@ elif ev.type == MOUSEBUTTONDOWN: # Clicking # Check which object we've focused - rect, hover = self.this_pos(ev.pos) + rect, hover = self.this_pos(ev.pos, bringontop = True) if hover: pos = (ev.pos[0] - rect[0], ev.pos[1] - rect[1]) hover.click(0, pos) @@ -230,15 +230,15 @@ elif (ev.type == KEYDOWN or ev.type == KEYUP) and self.focus: self.focus.keypress(ev) - def this_pos(self, pos): + def this_pos(self, pos, bringontop = False): # Return the object and their actual rect on this position - for child in self.children: + for child in reversed(self.children): if not child.rect.collidepoint(pos): continue child_pos = (pos[0] - child.rect[0], pos[1] - child.rect[1]) - rect, hover = child.this_pos(child_pos) + rect, hover = child.this_pos(child_pos, bringontop) if hover: return rect, hover @@ -326,14 +326,15 @@ return obj - def update(self, rect = None): + def update(self, rect = None, render = True): """ Update this part of the object """ # Send a message to our parent, telling them this rect needs to be # updated - self.needs_update = True + if render: + self.needs_update = True if self.frozen: return @@ -376,19 +377,30 @@ if isparent: self.main_parent.update_mouse() self.frozen = False - self.update() + + if self.needs_update: + self.update() else: self.frozen = False - def this_pos(self, pos): + def this_pos(self, pos, bringontop = False): # Return the object on this position - for child in self.children: + # Bring to the foreground if needed + if bringontop and self.canrise: + # Find ourself in our parent's children-list + i = self.parent.children.index(self) + del self.parent.children[i] + self.parent.children.append(self) + self.update() + + # Find the child on this position + for child in reversed(self.children): if not child.rect.collidepoint(pos): continue child_pos = (pos[0] - child.rect[0], pos[1] - child.rect[1]) - rect, hover = child.this_pos(child_pos) + rect, hover = child.this_pos(child_pos, bringontop) rect.move_ip(child.rect[0], child.rect[1]) return rect, hover @@ -416,9 +428,9 @@ self.backgroundsurf = self.surf.copy() self.font = pygame.font.Font(real_path("fonts", \ "DejaVuSans-Bold.ttf"), 14) + self.buttonstate = 0 # 0 = Nothing, 1 = Hover, 2 = Click + self.mousepos = None # Mouse position when clicking the title - self.buttonstate = 0 - self.pos = { # img is the position on the image # pos is the rendered position @@ -504,6 +516,8 @@ inner = self.calculate_pos(self.pos['inner_pos']) self.backgroundsurf.fill(self.colors['bgcolor'], inner) + self.update() + def render(self): self.surf.fill([0, 0, 0, 0]) self.surf.blit(self.backgroundsurf, (0,0)) @@ -537,13 +551,33 @@ self.surf.blit(self.gui, rect, img) + def click(self, state, pos): + if state == 0: + if self.canclose: + border = Rect(9, 9, self.rect.width-51, 28) + else: + border = Rect(9, 9, self.rect.width-18, 28) + if border.collidepoint(pos): + # Get the REAL pos, not the one relative to self.rect + self.mousepos = (pos[0]-self.rect[0], pos[1]-self.rect[1]) + elif state == 1: + if self.mousepos != None: + movepos = [pos[0]-self.mousepos[0], pos[1]-self.mousepos[1]] + self.move(movepos) + elif state == 2: + self.mousepos = None + def move(self, newpos): + # Move the current window + oldrect = self.rect.move(0,0) # Where is .copy? + self.rect.topleft = newpos - def move(self, topos): - # [TODO] - pass + # Combina the old rect and the new rect to update our whole move + updaterect = oldrect.union(self.rect) + updaterect.topleft = (oldrect[0]-self.rect[0], oldrect[1]-self.rect[1]) + self.update(updaterect, render=False) Added: trunk/client/images/gui/window.png =================================================================== (Binary files differ) Property changes on: trunk/client/images/gui/window.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-04 22:48:33 UTC (rev 390) +++ trunk/client/playground.py 2010-09-05 21:06:29 UTC (rev 391) @@ -352,7 +352,7 @@ # Create signup window window = self.parent.logingui.add(gui.Window, "signup", \ - Rect(0, 0, 200, 200), SignupFeedback()) + Rect(50, 50, 200, 200), SignupFeedback()) window.caption = "Signup" window.unfreeze() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-06 19:38:03
|
Revision: 393 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=393&view=rev Author: BlueWolf_ Date: 2010-09-06 19:37:54 +0000 (Mon, 06 Sep 2010) Log Message: ----------- A GUI-window can now be closed, among other small fixes Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-06 16:00:32 UTC (rev 392) +++ trunk/client/gui.py 2010-09-06 19:37:54 UTC (rev 393) @@ -58,6 +58,11 @@ raise KeyError(key) + def has(self, key): + for child in self.children: + if child.name == key: return True + return False + def add(self, Obj, name, rect, feedback = None): """ Append a child to this object @@ -114,21 +119,25 @@ if pygame.mouse.get_focused(): # Get the current hovered object rect, hover = self.this_pos(pos) - + # Is it different from the previous check? if hover != self.hover: # De-hover the previous one if self.hover: self.hover.hover = False - self.hover.hovering(False) + self.hover.hovering(state=False) self.hover = hover # Hover the current one if self.hover: self.hover.hover = True - self.hover.hovering(True) + pos = (pos[0] - rect[0], pos[1] - rect[1]) + self.hover.hovering(state=True, pos=pos) + elif hover != None: + pos = (pos[0] - rect[0], pos[1] - rect[1]) + self.hover.hovering(pos=pos) if hover: return True # Disable events further down the interface @@ -136,7 +145,7 @@ # Remove the previous hover if self.hover: self.hover.hover = False - self.hover.hovering(False) + self.hover.hovering(state=False) self.hover = None def give_focus(self, *obj): @@ -296,11 +305,16 @@ def __defaults__(self): pass - + + def has(self, key): + for child in self.children: + if child.name == key: return True + return False + def render(self): pass - def hovering(self, value): + def hovering(self, state=None, pos=None): pass def click(self, state, pos): @@ -411,6 +425,11 @@ if pos == len(self.children): pos = 0 self.give_focus(self.children[pos]) + + def remove(self): + # Remove this object + self.parent.children.remove(self) + self.update() @@ -428,7 +447,10 @@ self.backgroundsurf = self.surf.copy() self.font = pygame.font.Font(real_path("fonts", \ "DejaVuSans-Bold.ttf"), 14) - self.buttonstate = 0 # 0 = Nothing, 1 = Hover, 2 = Click + self.closehover = False # If the mouse is hovering above the X + self.closedown = False # If the mouse is clicking the X + self.closedown_visible = False # If the button should be seen as pressed + self.mousepos = None # Mouse position when clicking the title self.pos = { @@ -541,12 +563,12 @@ # Create button if self.canclose: - if self.buttonstate == 0: + if self.closedown_visible: + img = self.pos['closeC_img'] + elif self.closehover or self.closedown: + img = self.pos['closeH_img'] + else: img = self.pos['close_img'] - elif self.buttonstate == 1: - img = self.pos['closeH_img'] - elif self.buttonstate == 2: - img = self.pos['closeC_img'] rect = self.calculate_pos(self.pos['close_pos']) self.surf.blit(self.gui, rect, img) @@ -555,20 +577,66 @@ if state == 0: if self.canclose: border = Rect(9, 9, self.rect.width-51, 28) + close = self.calculate_pos(self.pos['close_pos']) else: border = Rect(9, 9, self.rect.width-18, 28) - if border.collidepoint(pos): + if border.collidepoint(pos): # Move the window # Get the REAL pos, not the one relative to self.rect self.mousepos = (pos[0]-self.rect[0], pos[1]-self.rect[1]) + + elif self.canclose and close.collidepoint(pos): # Close window + self.closedown_visible = True + self.closedown = True + self.update(close) elif state == 1: if self.mousepos != None: movepos = [pos[0]-self.mousepos[0], pos[1]-self.mousepos[1]] self.move(movepos) + + if self.closedown: + close = self.calculate_pos(self.pos['close_pos']) + inside = close.collidepoint(pos) + if self.closedown_visible and not inside: + self.closedown_visible = False + self.update(close) + elif self.closedown_visible == False and inside: + self.closedown_visible = True + self.update(close) elif state == 2: self.mousepos = None + + if self.closedown: + close = self.calculate_pos(self.pos['close_pos']) + if self.closedown_visible: + self.remove() + return + + self.closedown_visible = False + self.closedown = False + self.update(close) + + + def hovering(self, state=None, pos=None): + if state == False and self.closehover: + close = self.calculate_pos(self.pos['close_pos']) + self.closehover = 0 + self.update(close) + elif pos != None: + close = self.calculate_pos(self.pos['close_pos']) + inside = close.collidepoint(pos) + if self.closehover == False and inside: + self.closehover = True + self.update(close) + elif self.closehover and not inside: + self.closehover = False + self.update(close) + + + + def move(self, newpos): # Move the current window oldrect = self.rect.move(0,0) # Where is .copy? @@ -849,8 +917,9 @@ self.surf.blit(font, pos) - def hovering(self, value): - self.update() + def hovering(self, state=None, pos=None): + if state != None: + self.update() def click(self, state, pos): if state == 0: @@ -983,8 +1052,9 @@ self.surf.blit(font, (pos, 0)) - def hovering(self, state): - self.update() + def hovering(self, state=None, pos=None): + if state != None: + self.update() def click(self, state, pos): if state == 0: Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-06 16:00:32 UTC (rev 392) +++ trunk/client/playground.py 2010-09-06 19:37:54 UTC (rev 393) @@ -170,7 +170,7 @@ usrlabel.color = [177, 93, 39] usrlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) - usr = self.logingui.add(gui.Textbox, "usr", (345, 285, 310, 37)) + usr = self.logingui.add(gui.Textbox, "usrtextbox", (345, 285, 310, 37)) usr.set_style("login") pwdlabel = self.logingui.add(gui.Label, "pwdlabel", \ @@ -180,15 +180,15 @@ pwdlabel.color = [177, 93, 39] pwdlabel.set_font(("fonts", "DejaVuSans-Bold.ttf"), 15) - pwd = self.logingui.add(gui.Textbox, "pwd", (345, 350, 310, 37)) + 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, "login", (425, 398, 151, 34)) + 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, "signup", (345, 470, 310, 18)) + 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] @@ -316,26 +316,26 @@ self.parent = parent def keypress(self, obj, ev): - if obj.name == "usr": + 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("pwd") + self.parent.logingui.give_focus("pwdtextbox") - elif obj.name == "pwd": + elif obj.name == "pwdtextbox": # Using the enter key in the password field if ev.type == KEYDOWN and ev.key == K_RETURN: - self.parent.logingui['login'].manualpush(True) + self.parent.logingui['loginbutton'].manualpush(True) elif ev.type == KEYUP and ev.key == K_RETURN: - self.parent.logingui['login'].manualpush(False) - self.parent.logingui['login'].submit() + self.parent.logingui['loginbutton'].manualpush(False) + self.parent.logingui['loginbutton'].submit() 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() + 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", { @@ -348,8 +348,10 @@ sh['client'].login(usr, pwd) - elif obj.name == "signup": + elif obj.name == "signuplink": + if self.parent.logingui.has("signup"): return + # Create signup window window = self.parent.logingui.add(gui.Window, "signup", \ Rect(50, 50, 200, 200), SignupFeedback()) @@ -360,10 +362,10 @@ def mousedown(self, obj): if obj.name == "usrlabel": - self.parent.logingui.give_focus('usr') + self.parent.logingui.give_focus('usrtextbox') elif obj.name == "pwdlabel": - self.parent.logingui.give_focus('pwd') + self.parent.logingui.give_focus('pwdtextbox') class SignupFeedback(gui.Feedback): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-07 20:38:36
|
Revision: 394 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=394&view=rev Author: BlueWolf_ Date: 2010-09-07 20:38:29 +0000 (Tue, 07 Sep 2010) Log Message: ----------- Added mouse_focus and key_focus back to the sh again, as a certian pygame-bug came back again (Not always giving the right variable, depending on OS/Window Manager) Modified Paths: -------------- trunk/client/VP.py trunk/client/gui.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-06 19:37:54 UTC (rev 393) +++ trunk/client/VP.py 2010-09-07 20:38:29 UTC (rev 394) @@ -37,6 +37,9 @@ sh['timer'] = Timer() sh['downloader'] = Downloader() sh['login_info'] = None + + sh['key_focus'] = True + sh['mouse_focus'] = True # Fire up pygame os.environ['SDL_VIDEO_CENTERED']='1' @@ -86,7 +89,7 @@ if ev.type == QUIT: break - if ev.type == MOUSEMOTION: + elif ev.type == MOUSEMOTION: # Prevent this event from overflowing the queue. Always # return the position right now and remove al other # mousemotions in the queue @@ -96,7 +99,18 @@ ev = pygame.event.Event(MOUSEMOTION, buttons = ev.buttons, pos = pos) + + sh['mouse_focus'] = True + elif ev.type == KEYDOWN: + sh['key_focus'] = True + + elif ev.type == ACTIVEEVENT: + if ev.state == 1: # Mouse + sh['mouse_focus'] = bool(ev.gain) + elif ev.state == 2: # Key + sh['key_focus'] = bool(ev.gain) + # Send through all the layers if sh['windows'].event(ev): continue if sh['layout'].event(ev): continue Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-06 19:37:54 UTC (rev 393) +++ trunk/client/gui.py 2010-09-07 20:38:29 UTC (rev 394) @@ -116,7 +116,7 @@ if pos == None: pos = pygame.mouse.get_pos() - if pygame.mouse.get_focused(): + if sh['mouse_focus']: # Get the current hovered object rect, hover = self.this_pos(pos) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-08 15:50:33
|
Revision: 395 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=395&view=rev Author: BlueWolf_ Date: 2010-09-08 15:50:22 +0000 (Wed, 08 Sep 2010) Log Message: ----------- Moved and changed the size of the signup-window. Fixed some variables in gui.Button and gui.Link regarding appearance when clicked. When clicked, it didn't rendered its new state properly Modified Paths: -------------- trunk/client/gui.py trunk/client/playground.py Modified: trunk/client/gui.py =================================================================== --- trunk/client/gui.py 2010-09-07 20:38:29 UTC (rev 394) +++ trunk/client/gui.py 2010-09-08 15:50:22 UTC (rev 395) @@ -851,8 +851,8 @@ self.backgroundsurf = pygame.Surface((self.rect.width, \ self.rect.height*3), SRCALPHA).convert_alpha() self.style = None - self.mousedown = False - self.ispressed = False + self.clicked = False + self.clicked_visible = False self.caption = "" @@ -893,9 +893,9 @@ if self.style == "login": # Which state do we need? - if self.ispressed: + if self.clicked_visible: top = 68 - elif self.hover:# and not self.mousedown: + elif self.hover or self.clicked: top = 34 else: top = 0 @@ -923,31 +923,34 @@ def click(self, state, pos): if state == 0: - self.mousedown = True - self.ispressed = True + self.clicked = True + self.clicked_visible = True self.update() elif state == 1: - hover = bool(Rect(0, 0, self.rect.width, self.rect.height).collidepoint(pos)) - if hover != self.ispressed: - self.ispressed = hover + hover = bool(Rect(0, 0, self.rect.width, self.rect.height) + .collidepoint(pos)) + if hover != self.clicked_visible: + self.clicked_visible = hover self.update() elif state == 2: - self.mousedown = False + waspressed = self.clicked_visible + self.clicked = False + self.clicked_visible = False + self.update() - if self.ispressed: + if waspressed: self.submit() - - self.ispressed = False def submit(self): self.feedback.submit(self) def manualpush(self, state): - self.ispressed = state + self.clicked = state + self.clicked_visible = state self.update() @@ -1000,8 +1003,8 @@ def __defaults__(self): self.cangetfocus = False self.font = None - self.mousedown = False - self.ispressed = False + self.clicked = False + self.clicked_visible = False self.caption = "" self.color = [0, 0, 0] @@ -1038,10 +1041,10 @@ pos = self.rect.width - textwidth # Which state do we need? - if self.ispressed: + if self.clicked_visible: color = self.color_click self.font.set_underline(True) - elif self.hover and not self.mousedown: + elif self.hover or self.clicked: color = self.color_hover self.font.set_underline(True) else: @@ -1058,25 +1061,25 @@ def click(self, state, pos): if state == 0: - self.mousedown = True - self.ispressed = True + self.clicked = True + self.clicked_visible = True self.update() elif state == 1: hover = bool(Rect(0, 0, self.rect.width, self.rect.height).collidepoint(pos)) - if hover != self.ispressed: - self.ispressed = hover + if hover != self.clicked_visible: + self.clicked_visible = hover self.update() elif state == 2: - self.mousedown = False + wasclicked = self.clicked_visible + self.clicked = False + self.clicked_visible = False self.update() - if self.ispressed: + if wasclicked: self.submit() - - self.ispressed = False def submit(self): self.feedback.submit(self) Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-07 20:38:29 UTC (rev 394) +++ trunk/client/playground.py 2010-09-08 15:50:22 UTC (rev 395) @@ -354,8 +354,10 @@ # Create signup window window = self.parent.logingui.add(gui.Window, "signup", \ - Rect(50, 50, 200, 200), SignupFeedback()) + Rect(300, 140, 400, 420), SignupFeedback()) window.caption = "Signup" + + #window.add(gui. window.unfreeze() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <Blu...@us...> - 2010-09-10 19:20:49
|
Revision: 399 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=399&view=rev Author: BlueWolf_ Date: 2010-09-10 19:20:43 +0000 (Fri, 10 Sep 2010) Log Message: ----------- Added a better way to log text to the console. Also added a config-option to change the amount of debugging. Fixed a rather stupid error in the core Modified Paths: -------------- trunk/client/VP.py trunk/client/callback.py trunk/client/configspec trunk/client/core/parser.py trunk/client/downloader.py trunk/client/functions.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/VP.py 2010-09-10 19:20:43 UTC (rev 399) @@ -81,7 +81,6 @@ sh['client'].connect(sh['config']['host']['host'], \ sh['config']['host']['port']) - # Wait for all the events to come try: while 1: @@ -125,6 +124,8 @@ except: pass sh['downloader'].stop() sh['config'].write() + + log("succeed", "System closed") sys.exit() @@ -157,7 +158,7 @@ pygame.display.update(rect) def call(self, name, data): - print " [>] \t", name, data + log("debug", "Call:", name + ' - ' + str(data)) sh['playground'].call(name, data) sh['layout'].call(name, data) Modified: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/callback.py 2010-09-10 19:20:43 UTC (rev 399) @@ -23,15 +23,21 @@ class Callback(core.Callback): def data_received(self, data): - print " --> \t" + repr(data) + name = data.keys()[0] + value = data[name] + log("sendin", name + " - " + repr(data)) def data_send(self, data): - print " <-- \t" + repr(data) + name = data.keys()[0] + value = data[name] + log("sendout", name + " - " + repr(data)) def connection_ready(self, public_rsa, reconnecting): # We are connected if reconnecting: + log("succeed", "Connection ready!", "Core is logging in again") + sh['main'].call("status", { "status": "login", "where": "logging in" @@ -39,6 +45,9 @@ else: # Do we need to log in automatically? if sh['config']['user']['username'] != "": + log("succeed", "Connection ready!", "App is logging in based "+\ + "on config-settings") + sh['main'].call("status", { "status": "login", "where": "logging in" @@ -47,12 +56,16 @@ sh['config']['user']['password']) else: + log("succeed", "Connection ready!") + sh['main'].call("status", { "status": "login", "where": "waiting" }) def logged_in(self, username, cid, owner): + log("succeed", "We're logged in") + sh['main'].call("status", { "status": "login", "where": "downloading" @@ -68,6 +81,8 @@ def failed_logging_in(self, reason): # [TODO] Send the reason in some way + log("warning", "Failed logging in:", reason) + sh['main'].call("status", { "status": "login", "where": "waiting" @@ -80,7 +95,10 @@ def disconnected(self, reason): - print " !!! \tConnection closed: " + reason + if reason == "manual": + log("debug", "Connection closed:", reason) + else: + log("warning", "Connection closed:", reason) sh['login_info'] = None Modified: trunk/client/configspec =================================================================== --- trunk/client/configspec 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/configspec 2010-09-10 19:20:43 UTC (rev 399) @@ -9,3 +9,7 @@ [host] host = string(default=vp.bluewolf.nl) port = integer(default=6653) + +[debug] +level = integer(min=1, max=5, default=2) +use_colors = boolean(default=True) Modified: trunk/client/core/parser.py =================================================================== --- trunk/client/core/parser.py 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/core/parser.py 2010-09-10 19:20:43 UTC (rev 399) @@ -56,8 +56,7 @@ self.sh['rsakey'] = msg['public'] - reconnect = (self.core.cid == None and self.sh['auto_login']) - + reconnect = (self.core.cid == None and bool(self.sh['auto_login'])) self.call.connection_ready(msg['public'], reconnect) if reconnect: Modified: trunk/client/downloader.py =================================================================== --- trunk/client/downloader.py 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/downloader.py 2010-09-10 19:20:43 UTC (rev 399) @@ -40,7 +40,7 @@ def get_file(self, filename, filetype, callback, *arg): - print " !!! \tDownload task:", filename + log("debug", "Download task:", filename) # First check if we already have this file loaded if filename in self.loaded_files: @@ -68,7 +68,7 @@ self.queue.put((1, filename)) else: - print "File '" + filename + "' is not in the repository!" + log("warning", "File '" + filename + "' is not in the repository!") callback(filename, self.error(filetype, "not in repos"), *arg) @@ -124,7 +124,7 @@ filename) if not filename in sh['filetable']: - print "File '" + filename + "' is not in the repository!" + log("warning", "File '"+filename+"' is not in the repository!") self.callbacks(filename, task['callbacks'], \ self.error(task['filetype'], "not in repos")) return @@ -158,7 +158,7 @@ try: f = urllib2.urlopen(request) except urllib2.URLError, e: - print "Url '" + url + "' could not be found!" + log("warning", "Url '" + url + "' could not be found!") self.callbacks(filename, task['callbacks'], \ self.error(filename, "not found")) return @@ -180,8 +180,8 @@ filename + ".tmp") if checksum != filehash: - print "Checksum mismatch for '" + filename + "! " + \ - filehash + " > " + checksum + log("warning" "Checksum mismatch for '" + filename + "!", \ + filehash + " > " + checksum) self.callbacks(filename, task['callbacks'], \ self.error(task['filetype'], "checksum")) Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-09 19:34:56 UTC (rev 398) +++ trunk/client/functions.py 2010-09-10 19:20:43 UTC (rev 399) @@ -48,7 +48,7 @@ else: image = image.convert_alpha() except pygame.error, message: - print 'Cannot load image:', fullname + log("error", 'Cannot load image:', fullname) raise SystemExit, message return image @@ -70,8 +70,8 @@ sh['config'] = configobj.ConfigObj(real_path("config.conf"), \ configspec = real_path("configspec")) except configobj.ParseError: - print "Config: The config-file is malformed. Please check the file " + \ - "or remove it to create a new default one" + log("error", "Config:", "The config-file is malformed. Please check " +\ + "the file or remove it to create a new default one") sys.exit() validator = Validator() @@ -81,9 +81,60 @@ for (section_list, key, _) in configobj.flatten_errors(sh['config'], \ result): if key is not None: - print "Config: Something is wrong with the " + \ - "'%s/%s' key. Please check" % (section_list[0], key) + log("error", "Config:", "Something is wrong with the " + \ + "'%s/%s' key. Please check" % (section_list[0], key)) else: - print "Config: The '%s' section is missing" % section_list[0] + log("error", "Config:", \ + "The '%s' section is missing" % section_list[0]) sys.exit() + +def log(t, *m): + def level(i): + return sh['config']['debug']['level'] >= i + use_colors = sh['config']['debug']['use_colors'] + write = sys.stdout.write + def color(c): + write("\033[" + c + "m") + + message = "\t".join([str(part) for part in m]) + + if t == "error" and level(1): + icon = "!!!" + icon_color = "1;31;7" + text_color = "1;91" + + elif t == "warning" and level(2): + icon = "[!]" + icon_color = "1;33;7" + text_color = "93" + + elif t == "succeed" and level(3): + icon = "OK " + icon_color = "1;32;7" + text_color = "32" + + elif t == "debug" and level(4): + icon = " ~ " + icon_color = "1;7" + text_color = "" + + elif t == "sendin" and level(5): + icon = "|<-" + icon_color = "1;100;2" + text_color = "2" + + elif t == "sendout" and level(5): + icon = "|->" + icon_color = "1;100;2" + text_color = "2" + + else: + return + + if use_colors: color(icon_color) + write(" " + icon + " ") + if use_colors: color("0;" + text_color) + write("\t" + message) + if use_colors: color("0") + write("\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-11 17:54:00
|
Revision: 400 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=400&view=rev Author: BlueWolf_ Date: 2010-09-11 17:53:53 +0000 (Sat, 11 Sep 2010) Log Message: ----------- Added some level 3 (succeed) messages and fixed a bug in the layout which made it crash when 3 or more people where connected with the server Modified Paths: -------------- trunk/client/callback.py trunk/client/layout.py Modified: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2010-09-10 19:20:43 UTC (rev 399) +++ trunk/client/callback.py 2010-09-11 17:53:53 UTC (rev 400) @@ -36,7 +36,7 @@ # We are connected if reconnecting: - log("succeed", "Connection ready!", "Core is logging in again") + log("succeed", "Connection ready! Core is logging in again") sh['main'].call("status", { "status": "login", @@ -45,7 +45,7 @@ else: # Do we need to log in automatically? if sh['config']['user']['username'] != "": - log("succeed", "Connection ready!", "App is logging in based "+\ + log("succeed", "Connection ready! App is logging in based "+\ "on config-settings") sh['main'].call("status", { @@ -145,8 +145,25 @@ "action": "update" }) + def userlist(self, userlist): + if len(userlist) == 1: + log("succeed", "We are alone on this server") + else: + log("succeed", "There are " + str(len(userlist)) + " users on " + \ + "this server, including myself") + def useronline(self, user, userlist): + log("succeed", user['user'] + " came online. There are now " + \ + str(len(userlist)) + " users on this server") + sh['main'].call("useronline", user) def useroffline(self, user, userlist): + if len(userlist) == 1: + amount = "We are alone this server now" + else: + amount = "There are now " + str(len(userlist)) + " users on " + \ + "this server" + log("succeed", user['user'] + " went offline. " + amount) + sh['main'].call("useroffline", user) Modified: trunk/client/layout.py =================================================================== --- trunk/client/layout.py 2010-09-10 19:20:43 UTC (rev 399) +++ trunk/client/layout.py 2010-09-11 17:53:53 UTC (rev 400) @@ -179,7 +179,7 @@ elif len(sh['client'].userlist) == 2: text_sub = "1 other person" else: - text_sub = len(sh['client'].userlist)-1 + " people" + text_sub = str(len(sh['client'].userlist)-1) + " people" else: text_sub = self.topbar_lastsub[1] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-11 23:32:21
|
Revision: 401 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=401&view=rev Author: BlueWolf_ Date: 2010-09-11 23:32:12 +0000 (Sat, 11 Sep 2010) Log Message: ----------- Starting with the avatar-code. Code isn't much commented yet as the code will change a lot with every new change. Most is still temporary Modified Paths: -------------- trunk/client/playground.py Added Paths: ----------- trunk/client/playground_avatar.py Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-11 17:53:53 UTC (rev 400) +++ trunk/client/playground.py 2010-09-11 23:32:12 UTC (rev 401) @@ -17,6 +17,7 @@ from functions import * import gui +from playground_avatar import Avatar class Playground(): @@ -39,7 +40,10 @@ # Playground stuff self.backgrounds = {} self.viewport = None - self.direction_pressed = None + self.direction = None + self.avatars = {} + self.this_user = None + self.avatar_offset = None def event(self, ev): @@ -59,30 +63,49 @@ elif self.status == "playground": - if ev.type == KEYDOWN: - if ev.key == K_UP and self.direction_pressed != 0: - self.direction_pressed = 0 - sh['timer'].start("playground-move", self.playground_move, \ - time.time(), self.viewport.top, 0) - elif ev.key == K_DOWN and self.direction_pressed != 1: - self.direction_pressed = 1 - sh['timer'].start("playground-move", self.playground_move, \ - time.time(), self.viewport.top, 1) - elif ev.key == K_LEFT and self.direction_pressed != 2: - self.direction_pressed = 2 - sh['timer'].start("playground-move", self.playground_move, \ - time.time(), self.viewport.left, 2) - elif ev.key == K_RIGHT and self.direction_pressed != 3: - self.direction_pressed = 3 - sh['timer'].start("playground-move", self.playground_move, \ - time.time(), self.viewport.left, 3) - - elif ev.type == KEYUP: + if ev.type == KEYDOWN or ev.type == KEYUP: + if ev.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: - self.direction_pressed = None - sh['timer'].stop("playground-move") - + keys = pygame.key.get_pressed() + keys = (keys[K_UP], keys[K_RIGHT], keys[K_DOWN], + keys[K_LEFT]) + + direction = None + # Multiple keys + if keys[0] and keys[1]: + direction = 1 + elif keys[1] and keys[2]: + direction = 3 + elif keys[2] and keys[3]: + direction = 5 + elif keys[3] and keys[0]: + direction = 7 + + # Single keys + elif keys[0]: + direction = 0 + elif keys[1]: + direction = 2 + elif keys[2]: + direction = 4 + elif keys[3]: + direction = 6 + + if direction == None and self.direction != None: + # Stop the timer. We are not walking + sh['timer'].stop("playground-walk") + + elif self.direction == None or \ + direction != self.direction[0]: + # We started walking or changed direction + + self.direction = (direction, time.time(), + self.this_user['pos'][:]) + sh['timer'].start("playground-walk", + self.playground_walk) + + def call(self, name, data): if name == "status": # A status update if data['status'] == "login": @@ -94,6 +117,11 @@ 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") @@ -124,7 +152,30 @@ self.logingui = None # Load the data for the playground - self.viewport = Rect(0, 0, 1000, 700) + + # 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) @@ -232,7 +283,7 @@ rect = Rect(rect) # Blit the background - bg_offset = (self.viewport.left%250, self.viewport.top%250) + bg_offset = (-self.viewport.left%250, -self.viewport.top%250) x_min = bg_offset[0]-250 if x_min == -250: x_min = 0 x_max = x_min + 250 * ((float(self.viewport.width) / 250)+1) @@ -257,6 +308,25 @@ self.surf.blit(background, rect, bg_area) + # Blit the users + for avatar in self.avatars.values(): + avatar_rect = Rect( + avatar.user['pos'][0] - self.viewport[0], + avatar.user['pos'][1] - self.viewport[1], + avatar.size[0], + avatar.size[1], + ) + + if not rect.colliderect(avatar_rect): continue + + avatar_area = Rect( + rect.left - avatar_rect.left, + rect.top - avatar_rect.top, + rect.width, + 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)) @@ -293,21 +363,37 @@ self.playground_render() - def playground_move(self, name, startime, startpos, direction): - # Temporary test function to walk - - timeline = time.time() - startime + def playground_walk(self, name): + direction, starttime, startpos = self.direction + timeline = time.time() - starttime speed = 175 move = timeline*speed if direction == 0: - self.viewport.top = startpos - move + self.this_user['pos'][1] = startpos[1] - move elif direction == 1: - self.viewport.top = startpos + move + self.this_user['pos'][1] = startpos[1] - (move/1.7) + self.this_user['pos'][0] = startpos[0] + (move/1.7) elif direction == 2: - self.viewport.left = startpos - move + self.this_user['pos'][0] = startpos[0] + move elif direction == 3: - self.viewport.left = startpos + move + self.this_user['pos'][0] = startpos[0] + (move/1.7) + self.this_user['pos'][1] = startpos[1] + (move/1.7) + elif direction == 4: + self.this_user['pos'][1] = startpos[1] + move + elif direction == 5: + self.this_user['pos'][1] = startpos[1] + (move/1.7) + self.this_user['pos'][0] = startpos[0] - (move/1.7) + elif direction == 6: + self.this_user['pos'][0] = startpos[0] - move + elif direction == 7: + self.this_user['pos'][0] = startpos[0] - (move/1.7) + self.this_user['pos'][1] = startpos[1] - (move/1.7) + + self.viewport.topleft = ( + self.this_user['pos'][0]+self.avatar_offset[0], + self.this_user['pos'][1]+self.avatar_offset[1], + ) self.playground_render() Added: trunk/client/playground_avatar.py =================================================================== --- trunk/client/playground_avatar.py (rev 0) +++ trunk/client/playground_avatar.py 2010-09-11 23:32:12 UTC (rev 401) @@ -0,0 +1,34 @@ +## 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 * + +class Avatar(): + def __init__(self, user): + self.user = user + self.lastpos = user['pos'] + + self.avatar = None + self.size = (40,40) + sh['downloader'].get_file("happyblock.png", "img", self.download) + + def download(self, filename, cache): + self.avatar = cache + + def blit(self, surf, area): + if self.avatar: + surf.blit(self.avatar, (0,0), area) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-12 14:27:58
|
Revision: 403 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=403&view=rev Author: BlueWolf_ Date: 2010-09-12 14:27:52 +0000 (Sun, 12 Sep 2010) Log Message: ----------- Changed some log-stuff for windows and screen Modified Paths: -------------- trunk/client/callback.py trunk/client/functions.py Modified: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2010-09-12 01:01:32 UTC (rev 402) +++ trunk/client/callback.py 2010-09-12 14:27:52 UTC (rev 403) @@ -25,12 +25,12 @@ def data_received(self, data): name = data.keys()[0] value = data[name] - log("sendin", name + " - " + repr(data)) + log("recv", name + " - " + repr(data)) def data_send(self, data): name = data.keys()[0] value = data[name] - log("sendout", name + " - " + repr(data)) + log("send", name + " - " + repr(data)) def connection_ready(self, public_rsa, reconnecting): # We are connected Modified: trunk/client/functions.py =================================================================== --- trunk/client/functions.py 2010-09-12 01:01:32 UTC (rev 402) +++ trunk/client/functions.py 2010-09-12 14:27:52 UTC (rev 403) @@ -22,6 +22,10 @@ from validate import Validator import core +# To get colors working in Windows +if os.name == "nt": import colerama + + VERSION = "0.0.1" # This will be used to [sh]are all variables, functions and classes across the @@ -119,15 +123,15 @@ icon_color = "1;7" text_color = "" - elif t == "sendin" and level(5): + elif t == "recv" and level(5): icon = "|<-" - icon_color = "1;100;2" - text_color = "2" + icon_color = "1;90;7" + text_color = "90" - elif t == "sendout" and level(5): + elif t == "send" and level(5): icon = "|->" - icon_color = "1;100;2" - text_color = "2" + icon_color = "1;90;7" + text_color = "90" else: return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <Blu...@us...> - 2010-09-25 21:17:04
|
Revision: 410 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=410&view=rev Author: BlueWolf_ Date: 2010-09-25 21:16:57 +0000 (Sat, 25 Sep 2010) Log Message: ----------- Finally made a proper engine for the viewport mover when walking with the avatar. Background temporary removed as it will be placed in a seperated file as well. Beware of weird effects while walking! :D Modified Paths: -------------- trunk/client/playground.py trunk/client/playground_avatar.py Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-17 18:10:18 UTC (rev 409) +++ trunk/client/playground.py 2010-09-25 21:16:57 UTC (rev 410) @@ -19,6 +19,11 @@ import gui from playground_avatar import Avatar +POS_UPDATE_DELAY = 1 # Determines when a pos-update should be send. + # Every x seconds. +MOVE_SPEED = 175 # How fast the avatar shoud walk + + class Playground(): def __init__(self): @@ -28,11 +33,11 @@ self.statuswhere = None self.backgrounds = {} + self.viewport_float = None self.viewport = None self.direction = None self.avatars = {} self.this_user = None - self.avatar_offset = None def event(self, ev): @@ -68,6 +73,7 @@ if direction == None and self.direction != None: # Stop the timer. We are not walking + self.direction = None sh['timer'].stop("playground-walk") elif self.direction == None or \ @@ -77,7 +83,9 @@ self.direction = (direction, time.time(), self.this_user['pos'][:]) sh['timer'].start("playground-walk", - self.playground_walk) + self.timer_walk) + #sh['timer'].start("playground-pos-update", + # self.timer_walk, time.time()) def call(self, name, data): @@ -89,10 +97,10 @@ sh['downloader'].remove_usage(name) self.backgrounds = {} self.viewport = None + self.viewport_float = 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 @@ -101,26 +109,18 @@ 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.avatars[user['cid']] = Avatar(user, self) - self.viewport = Rect( - self.avatar_offset[0], - self.avatar_offset[1], - 1000, - 700) - - self.playground_render() + avatar = self.avatars[self.this_user['cid']] + self.viewport_float = [ + (self.this_user['pos'][0] - avatar.center[0]) - (1000/2), + (self.this_user['pos'][1] - avatar.center[1]) - (700/2), + ] + self.viewport = [ + int(self.viewport_float[0]), + int(self.viewport_float[1]) + ] + self.update() self.status = data['status'] self.statuswhere = data['where'] @@ -136,56 +136,20 @@ "background", counter) - def playground_render(self, rect = None, doupdate = True): - # Render the playground + def update(self, rect = None, doupdate = True): + # This will blit and update the screen at rect + if rect == None: rect = Rect(0, 0, 1000, 700) else: rect = Rect(rect) # Blit the background - bg_offset = (-self.viewport.left%250, -self.viewport.top%250) - x_min = bg_offset[0]-250 - if x_min == -250: x_min = 0 - x_max = x_min + 250 * ((float(self.viewport.width) / 250)+1) - x_max = int(x_max) - y_min = bg_offset[1]-250 - if y_min == -250: y_min = 0 - y_max = y_min + 250 * ((float(self.viewport.height) / 250)+1) - y_max = int(y_max) + #self.background.update(self.surf, self.viewport, rect) - # Find the blocks that are within rect - for y in range(y_min, y_max, 250): - for x in range(x_min, x_max, 250): - bg_rect = Rect(x, y, 250, 250) - if bg_rect.colliderect(rect): - - background = self.backgrounds['bg-grass.png'] - bg_area = Rect( - rect.left - bg_rect.left, - rect.top - bg_rect.top, - rect.width, - rect.height) - - self.surf.blit(background, rect, bg_area) - # Blit the users for avatar in self.avatars.values(): - avatar_rect = Rect( - avatar.user['pos'][0] - self.viewport[0], - avatar.user['pos'][1] - self.viewport[1], - avatar.size[0], - avatar.size[1], - ) - - if not rect.colliderect(avatar_rect): continue - - avatar_area = Rect( - rect.left - avatar_rect.left, - rect.top - avatar_rect.top, - rect.width, - rect.height) - avatar.blit(self.surf, avatar_area) + avatar.update(self.surf, self.viewport, rect) if doupdate: sh['update'](rect) @@ -206,35 +170,87 @@ }) - def playground_walk(self, name): - direction, starttime, startpos = self.direction - timeline = time.time() - starttime - speed = 175 - move = timeline*speed + def timer_walk(self, name, starttime = None): + if name == "playground-walk": + direction, starttime, startpos = self.direction + timeline = time.time() - starttime + speed = MOVE_SPEED + move = timeline*speed + + pos = self.this_user['pos'][:] + if direction == 0: + pos[1] = int(startpos[1] - move) + elif direction == 1: + pos[1] = int(startpos[1] - (move/1.7)) + pos[0] = int(startpos[0] + (move/1.7)) + elif direction == 2: + pos[0] = int(startpos[0] + move) + elif direction == 3: + pos[0] = int(startpos[0] + (move/1.7)) + pos[1] = int(startpos[1] + (move/1.7)) + elif direction == 4: + pos[1] = int(startpos[1] + move) + elif direction == 5: + pos[1] = int(startpos[1] + (move/1.7)) + pos[0] = int(startpos[0] - (move/1.7)) + elif direction == 6: + pos[0] = int(startpos[0] - move) + elif direction == 7: + pos[0] = int(startpos[0] - (move/1.7)) + pos[1] = int(startpos[1] - (move/1.7)) + + avatar = self.avatars[self.this_user['cid']] + avatar.move(pos) + sh['timer'].start("playground-viewport-move", + self.timer_walk) - if direction == 0: - self.this_user['pos'][1] = startpos[1] - move - elif direction == 1: - self.this_user['pos'][1] = startpos[1] - (move/1.7) - self.this_user['pos'][0] = startpos[0] + (move/1.7) - elif direction == 2: - self.this_user['pos'][0] = startpos[0] + move - elif direction == 3: - self.this_user['pos'][0] = startpos[0] + (move/1.7) - self.this_user['pos'][1] = startpos[1] + (move/1.7) - elif direction == 4: - self.this_user['pos'][1] = startpos[1] + move - elif direction == 5: - self.this_user['pos'][1] = startpos[1] + (move/1.7) - self.this_user['pos'][0] = startpos[0] - (move/1.7) - elif direction == 6: - self.this_user['pos'][0] = startpos[0] - move - elif direction == 7: - self.this_user['pos'][0] = startpos[0] - (move/1.7) - self.this_user['pos'][1] = startpos[1] - (move/1.7) - self.viewport.topleft = ( - self.this_user['pos'][0]+self.avatar_offset[0], - self.this_user['pos'][1]+self.avatar_offset[1], - ) - self.playground_render() + elif name == "playground-viewport-move": + # Move the viewport in a smooth way + + # First get the current viewport pos and the desired pos + pos = self.viewport_float + avatar = self.avatars[self.this_user['cid']] + desired_pos = [ + (self.this_user['pos'][0] - avatar.center[0]) - (1000/2), + (self.this_user['pos'][1] - avatar.center[1]) - (700/2) + ] + + # Calculate the differences between these two positions. + # Hello Pythagoras! + distance = math.sqrt( + (pos[0] - desired_pos[0])**2 + + (pos[1] - desired_pos[1])**2) + + if distance < 1: + self.viewport_float = desired_pos + else: + # Calculate how much we should move + speed = (distance/100000) + + if speed > 0.9: speed = 0.9 + speed += 0.05 + move = [0,0] + + move[0] = (desired_pos[0] - pos[0]) * speed + move[1] = (desired_pos[1] - pos[1]) * speed + + self.viewport_float[0] += move[0] + self.viewport_float[1] += move[1] + + # Keep in mind that pygame only likes integers, not floats + real_move = [ + int(self.viewport_float[0] - self.viewport[0]), + int(self.viewport_float[1] - self.viewport[1]) + ] + self.viewport[0] += real_move[0] + self.viewport[1] += real_move[1] + + self.surf.scroll(-real_move[0], -real_move[1]) + sh['update']() + + if self.viewport_float == desired_pos: return True + + + elif name == "playground-pos-update": + pass Modified: trunk/client/playground_avatar.py =================================================================== --- trunk/client/playground_avatar.py 2010-09-17 18:10:18 UTC (rev 409) +++ trunk/client/playground_avatar.py 2010-09-25 21:16:57 UTC (rev 410) @@ -18,17 +18,55 @@ from functions import * class Avatar(): - def __init__(self, user): + def __init__(self, user, playground): self.user = user - self.lastpos = user['pos'] + self.playground = playground self.avatar = None self.size = (40,40) + self.center = (20, 40) + sh['downloader'].get_file("happyblock.png", "img", self.download) + def move(self, pos): + lastpos = self.user['pos'] + self.user['pos'] = pos + + self.update_parent() + def download(self, filename, cache): self.avatar = cache - def blit(self, surf, area): - if self.avatar: - surf.blit(self.avatar, (0,0), area) + self.update_parent() + + def update_parent(self): + # Update ourself. Send it to our parent + self_rect = Rect( + self.user['pos'][0] - self.playground.viewport[0] - + self.center[0], + self.user['pos'][1] - self.playground.viewport[1] - + self.center[1], + self.size[0], + self.size[1]) + + if not Rect(0, 0, 1000, 700).colliderect(self_rect): return + + self.playground.update(self_rect) + + def update(self, surf, viewport, rect): + if not self.avatar: return + + # Check if we collide + self_rect = Rect( + self.user['pos'][0] - viewport[0] - self.center[0], + self.user['pos'][1] - viewport[1] - self.center[1], + self.size[0], + self.size[1]) + + if not rect.colliderect(self_rect): return + + surf.blit(self.avatar, rect, Rect( + rect.left - self_rect.left, + rect.top - self_rect.top, + rect.width, + rect.height)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-26 22:16:22
|
Revision: 411 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=411&view=rev Author: BlueWolf_ Date: 2010-09-26 22:16:14 +0000 (Sun, 26 Sep 2010) Log Message: ----------- And we have a background which you can walk on! Next step: Sending and receiving user positions Modified Paths: -------------- trunk/client/callback.py trunk/client/playground.py trunk/client/playground_avatar.py trunk/client/timer.py Added Paths: ----------- trunk/client/playground_background.py Modified: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2010-09-25 21:16:57 UTC (rev 410) +++ trunk/client/callback.py 2010-09-26 22:16:14 UTC (rev 411) @@ -144,6 +144,13 @@ sh['main'].call("filetable", { "action": "update" }) + + elif header == "landscapes": # How the background should look like + sh['landscapes'] = body + + sh['main'].call("landscapes", { + "action": "update" + }) def userlist(self, userlist): if len(userlist) == 1: Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-25 21:16:57 UTC (rev 410) +++ trunk/client/playground.py 2010-09-26 22:16:14 UTC (rev 411) @@ -18,6 +18,7 @@ from functions import * import gui from playground_avatar import Avatar +from playground_background import Background POS_UPDATE_DELAY = 1 # Determines when a pos-update should be send. # Every x seconds. @@ -32,7 +33,7 @@ self.status = None self.statuswhere = None - self.backgrounds = {} + self.background = Background(self) self.viewport_float = None self.viewport = None self.direction = None @@ -84,8 +85,6 @@ self.this_user['pos'][:]) sh['timer'].start("playground-walk", self.timer_walk) - #sh['timer'].start("playground-pos-update", - # self.timer_walk, time.time()) def call(self, name, data): @@ -93,12 +92,13 @@ 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.background.reset() self.viewport = None self.viewport_float = None self.direction = None + + for avatar in self.avatars.values(): + avatar.stop() self.avatars = {} self.this_user = None @@ -135,6 +135,9 @@ sh['downloader'].get_file("bg-grass.png", "img", self.download,\ "background", counter) + elif name == "landscapes": + if data['action'] == "update": + self.background.update_landscapes(sh['landscapes']) def update(self, rect = None, doupdate = True): # This will blit and update the screen at rect @@ -145,7 +148,7 @@ rect = Rect(rect) # Blit the background - #self.background.update(self.surf, self.viewport, rect) + self.background.update(self.surf, self.viewport, rect) # Blit the users for avatar in self.avatars.values(): @@ -157,7 +160,7 @@ def download(self, filename, cache, name, *arg): if name == "background": - self.backgrounds[filename] = cache + self.background.add_background(filename, cache) counter = arg[0] counter['counter'] -= 1 @@ -172,6 +175,9 @@ def timer_walk(self, name, starttime = None): if name == "playground-walk": + if self.direction == None: + return True # No direction. We aren't moving + direction, starttime, startpos = self.direction timeline = time.time() - starttime speed = MOVE_SPEED @@ -247,6 +253,33 @@ self.viewport[1] += real_move[1] self.surf.scroll(-real_move[0], -real_move[1]) + + # Blit the 2 sides that now appear + + if real_move[0] < 0: # Left side + rect = Rect(0, 0, -real_move[0], 700) + self.update(rect, doupdate=False) + elif real_move[0] > 0: # Right side + rect = Rect(1000-real_move[0], 0, real_move[0], 700) + self.update(rect, doupdate=False) + + if real_move[1] < 0: # Top + rect = Rect(0, 0, 1000, -real_move[1]) + if real_move[0] < 0 : # And to the left + rect.left = -real_move[0] + rect.width = 1000 + real_move[0] + elif real_move[0] > 0: # And to the right + rect.width = 1000 - real_move[0] + self.update(rect, doupdate=False) + elif real_move[1] > 0: # Bottom + rect = Rect(0, 700-real_move[1], 1000, real_move[1]) + if real_move[0] < 0 : # And to the left + rect.left = -real_move[0] + rect.width = 1000 + real_move[0] + elif real_move[0] > 0: # And to the right + rect.width = 1000 - real_move[0] + self.update(rect, doupdate=False) + sh['update']() if self.viewport_float == desired_pos: return True Modified: trunk/client/playground_avatar.py =================================================================== --- trunk/client/playground_avatar.py 2010-09-25 21:16:57 UTC (rev 410) +++ trunk/client/playground_avatar.py 2010-09-26 22:16:14 UTC (rev 411) @@ -28,30 +28,45 @@ sh['downloader'].get_file("happyblock.png", "img", self.download) + def stop(self): + # Playground is quiting. Stop everything + sh['downloader'].remove_usage("happyblock.png") + def move(self, pos): + # Move the avatar to this place lastpos = self.user['pos'] self.user['pos'] = pos - self.update_parent() + rect = self.get_rect(pos) + rect_old = self.get_rect(lastpos) + rect.union_ip(rect_old) + + self.update_parent(rect) def download(self, filename, cache): + # Callback for the avatar-downloader self.avatar = cache self.update_parent() - - def update_parent(self): - # Update ourself. Send it to our parent - self_rect = Rect( - self.user['pos'][0] - self.playground.viewport[0] - - self.center[0], - self.user['pos'][1] - self.playground.viewport[1] - - self.center[1], + + def get_rect(self, pos): + # Get a rect, pased on the position + return Rect( + pos[0] - self.playground.viewport[0] - self.center[0], + pos[1] - self.playground.viewport[1] - self.center[1], self.size[0], self.size[1]) + + def update_parent(self, rect = None): + if self.playground.viewport == None: + return # Without viewport, we can't update (this can happen due to + # threading + + if rect == None: + rect = self.get_rect(self.user['pos']) - if not Rect(0, 0, 1000, 700).colliderect(self_rect): return - - self.playground.update(self_rect) + if not Rect(0, 0, 1000, 700).colliderect(rect): return + self.playground.update(rect) def update(self, surf, viewport, rect): if not self.avatar: return Added: trunk/client/playground_background.py =================================================================== --- trunk/client/playground_background.py (rev 0) +++ trunk/client/playground_background.py 2010-09-26 22:16:14 UTC (rev 411) @@ -0,0 +1,77 @@ +## 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 * + +class Background(): + def __init__(self, playground): + self.playground = playground + self.backgrounds = {} + self.landscapes = {} + + def add_background(self, filename, surface): + self.backgrounds[filename] = surface + + def update_landscapes(self, landscapes): + self.landscapes = landscapes + + def reset(self): + # Reset everything because the client has been signed off + + # Remove backgrounds + for name in self.backgrounds.keys(): + sh['downloader'].remove_usage(name) + self.backgrounds = {} + + # Remove landscapes + self.landscapes = {} + + def update_parent(self): + self.playground.update(Rect(0, 0, 1000, 700)) + + def update(self, surf, viewport, rect): + # Blit the background + viewport_left = viewport[0] + viewport_top = viewport[1] + viewport_width = 1000 + viewport_height = 700 + + # Calculate the start and end positions of the background + bg_offset = (-viewport_left%250, -viewport_top%250) + x_min = bg_offset[0]-250 + if x_min == -250: x_min = 0 + x_max = x_min + 250 * ((float(viewport_width) / 250)+1) + x_max = int(x_max) + y_min = bg_offset[1]-250 + if y_min == -250: y_min = 0 + y_max = y_min + 250 * ((float(viewport_height) / 250)+1) + y_max = int(y_max) + + # Find the blocks that are within rect + for y in range(y_min, y_max, 250): + for x in range(x_min, x_max, 250): + bg_rect = Rect(x, y, 250, 250) + if bg_rect.colliderect(rect): + + background = self.backgrounds['bg-grass.png'] + bg_area = Rect( + rect.left - bg_rect.left, + rect.top - bg_rect.top, + rect.width, + rect.height) + + surf.blit(background, rect, bg_area) Modified: trunk/client/timer.py =================================================================== --- trunk/client/timer.py 2010-09-25 21:16:57 UTC (rev 410) +++ trunk/client/timer.py 2010-09-26 22:16:14 UTC (rev 411) @@ -53,7 +53,8 @@ # Do stuff for name, info in self.callers.items(): if info[0](name, *info[1]): - del self.callers[name] + try: del self.callers[name] + except: pass # This can happen due to threading. It's not bad # Force one big update sh['main'].updatewaiting = False This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-27 22:02:55
|
Revision: 412 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=412&view=rev Author: BlueWolf_ Date: 2010-09-27 22:02:49 +0000 (Mon, 27 Sep 2010) Log Message: ----------- Sending move-events to the server Modified Paths: -------------- trunk/client/core/client.py trunk/client/playground.py Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2010-09-26 22:16:14 UTC (rev 411) +++ trunk/client/core/client.py 2010-09-27 22:02:49 UTC (rev 412) @@ -274,6 +274,12 @@ "version": __version__ }) + def move(self, moving, pos, direction = None, speed = None): + data = {"moving": moving, "pos": pos} + if moving: + data['direction'] = direction + data['speed'] = speed + self.send("move", data) def send(self, data_header, data_body = {}): Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-26 22:16:14 UTC (rev 411) +++ trunk/client/playground.py 2010-09-27 22:02:49 UTC (rev 412) @@ -20,8 +20,6 @@ from playground_avatar import Avatar from playground_background import Background -POS_UPDATE_DELAY = 1 # Determines when a pos-update should be send. - # Every x seconds. MOVE_SPEED = 175 # How fast the avatar shoud walk @@ -75,12 +73,16 @@ if direction == None and self.direction != None: # Stop the timer. We are not walking self.direction = None + sh['client'].move(False, self.this_user['pos'][0:2]) sh['timer'].stop("playground-walk") elif self.direction == None or \ direction != self.direction[0]: # We started walking or changed direction + sh['client'].move(True, self.this_user['pos'][0:2], + direction, MOVE_SPEED) + self.direction = (direction, time.time(), self.this_user['pos'][:]) sh['timer'].start("playground-walk", @@ -139,6 +141,7 @@ if data['action'] == "update": self.background.update_landscapes(sh['landscapes']) + def update(self, rect = None, doupdate = True): # This will blit and update the screen at rect @@ -283,7 +286,3 @@ sh['update']() if self.viewport_float == desired_pos: return True - - - elif name == "playground-pos-update": - pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2010-09-28 21:59:18
|
Revision: 413 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=413&view=rev Author: BlueWolf_ Date: 2010-09-28 21:59:12 +0000 (Tue, 28 Sep 2010) Log Message: ----------- Client will now send all move-events to the server the way it should. It does't process the response from the server though Modified Paths: -------------- trunk/client/core/client.py trunk/client/downloader.py trunk/client/login.py trunk/client/playground.py Modified: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py 2010-09-27 22:02:49 UTC (rev 412) +++ trunk/client/core/client.py 2010-09-28 21:59:12 UTC (rev 413) @@ -274,12 +274,12 @@ "version": __version__ }) - def move(self, moving, pos, direction = None, speed = None): - data = {"moving": moving, "pos": pos} - if moving: - data['direction'] = direction - data['speed'] = speed - self.send("move", data) + def move(self, moving, pos, direction = None): + self.send("move", { + "moving": moving, + "pos": pos, + "direction": direction + }) def send(self, data_header, data_body = {}): Modified: trunk/client/downloader.py =================================================================== --- trunk/client/downloader.py 2010-09-27 22:02:49 UTC (rev 412) +++ trunk/client/downloader.py 2010-09-28 21:59:12 UTC (rev 413) @@ -74,7 +74,7 @@ def remove_usage(self, filename): try: load = self.loaded_files[filename] - except: pass + except: return load['usages'] -= 1 if load['usages'] == 0: Modified: trunk/client/login.py =================================================================== --- trunk/client/login.py 2010-09-27 22:02:49 UTC (rev 412) +++ trunk/client/login.py 2010-09-28 21:59:12 UTC (rev 413) @@ -52,6 +52,7 @@ if data['status'] == "login": if self.status != "login": # Load the data for the login + sh['timer'].stop("login-transit") self.surf.set_alpha(None) self.background = load_image(False, "images", "loginbg.png") self.loginbox = load_image(True, "images", "loginbox.png") Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-09-27 22:02:49 UTC (rev 412) +++ trunk/client/playground.py 2010-09-28 21:59:12 UTC (rev 413) @@ -70,18 +70,23 @@ elif keys[3]: direction = 6 + if direction == None and self.direction == None: + # Not moving and nothing has changed (this can happen + # in some circumstances. Faulty window manager + return + if direction == None and self.direction != None: # Stop the timer. We are not walking self.direction = None - sh['client'].move(False, self.this_user['pos'][0:2]) + sh['client'].move(False, self.this_user['pos']) sh['timer'].stop("playground-walk") elif self.direction == None or \ direction != self.direction[0]: # We started walking or changed direction - sh['client'].move(True, self.this_user['pos'][0:2], - direction, MOVE_SPEED) + sh['client'].move(True, self.this_user['pos'], + direction) self.direction = (direction, time.time(), self.this_user['pos'][:]) @@ -94,6 +99,7 @@ if data['status'] == "login" and self.status == "playground": # Unload data from the playground sh['timer'].stop("playground-move") + sh['timer'].stop("playground-viewport-move") self.background.reset() self.viewport = None self.viewport_float = None This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |