You can subscribe to this list here.
| 2009 |
Jan
|
Feb
(9) |
Mar
(11) |
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(9) |
Nov
(5) |
Dec
(18) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(4) |
Feb
|
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
(11) |
Aug
(33) |
Sep
(33) |
Oct
|
Nov
|
Dec
|
|
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-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-01 21:01:28
|
Revision: 388
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=388&view=rev
Author: BlueWolf_
Date: 2010-09-01 21:01:21 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
* Added a config to the client
* Stuff like FPS and host is now configurable
* Client now stores the login information and uses that (no way to log out yet)
* 'Effects' option doesn't do anything yet
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/functions.py
trunk/client/playground.py
Added Paths:
-----------
trunk/client/configspec
Property Changed:
----------------
trunk/client/
Property changes on: trunk/client
___________________________________________________________________
Added: svn:ignore
+ config.conf
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-09-01 18:20:17 UTC (rev 387)
+++ trunk/client/VP.py 2010-09-01 21:01:21 UTC (rev 388)
@@ -29,9 +29,12 @@
class Main():
def __init__(self):
+ load_config()
+
sh['filetable'] = {}
sh['timer'] = Timer()
sh['downloader'] = Downloader()
+ sh['login_info'] = None
# Fire up pygame
os.environ['SDL_VIDEO_CENTERED']='1'
@@ -70,7 +73,8 @@
"status": "login",
"where": "connecting"
})
- sh['client'].connect(*SERVER)
+ sh['client'].connect(sh['config']['host']['host'], \
+ sh['config']['host']['port'])
# Wait for all the events to come
@@ -104,6 +108,7 @@
try: sh['client'].close()
except: pass
sh['downloader'].stop()
+ sh['config'].write()
sys.exit()
@@ -144,10 +149,10 @@
class Timer():
"""
- This timer will update every frame as defined in UPDATE_FPS @ functions.py
+ This timer will update every frame as defined in the config
"""
def __init__(self):
- self.speed = 1/float(UPDATE_FPS)
+ self.speed = 1/float(sh['config']['graphics']['fps'])
self.callers = {}
self.timer = None
@@ -210,16 +215,33 @@
"where": "logging in"
})
else:
- sh['main'].call("status", {
- "status": "login",
- "where": "waiting"
- })
+ # 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
@@ -228,10 +250,18 @@
"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
@@ -249,8 +279,16 @@
"status": "login",
"where": "connecting"
})
- sh['client'].connect(*SERVER)
+ # 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?
Added: trunk/client/configspec
===================================================================
--- trunk/client/configspec (rev 0)
+++ trunk/client/configspec 2010-09-01 21:01:21 UTC (rev 388)
@@ -0,0 +1,11 @@
+[user]
+username = string(default="")
+password = string(default="")
+
+[graphics]
+fps = integer(min=1, default=50)
+effects = boolean(default=True)
+
+[host]
+host = string(default=vp.bluewolf.nl)
+port = integer(default=6653)
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-09-01 18:20:17 UTC (rev 387)
+++ trunk/client/functions.py 2010-09-01 21:01:21 UTC (rev 388)
@@ -18,14 +18,12 @@
import pygame, os, sys, threading, time, math
from pygame.locals import *
from hashlib import sha1, md5
+import configobj
+from validate import Validator
import core
VERSION = "0.0.1"
-SERVER = ("vp.bluewolf.nl", 6653)
-
-UPDATE_FPS = 50
-
# This will be used to [sh]are all variables, functions and classes across the
# code
sh = {}
@@ -64,7 +62,31 @@
checksum.update(data)
return checksum.hexdigest()
+
+def load_config():
+ # Load the config file and apply the default values to it if needed
+
+ try:
+ 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"
+ sys.exit()
+
+ validator = Validator()
+ result = sh['config'].validate(validator, copy = True)
+
+ if result != True:
+ 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)
+ else:
+ print "Config: The '%s' section is missing" % section_list[0]
+ sys.exit()
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-09-01 18:20:17 UTC (rev 387)
+++ trunk/client/playground.py 2010-09-01 21:01:21 UTC (rev 388)
@@ -342,6 +342,9 @@
"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 == "signup":
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-09-01 18:20:23
|
Revision: 387
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=387&view=rev
Author: BlueWolf_
Date: 2010-09-01 18:20:17 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
Forgot to let the downloader remove a task once it's finished. Also changed some debugging stuff to make it a (bit) more debugable
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/downloader.py
trunk/client/playground.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-09-01 17:41:05 UTC (rev 386)
+++ trunk/client/VP.py 2010-09-01 18:20:17 UTC (rev 387)
@@ -136,6 +136,8 @@
pygame.display.update(rect)
def call(self, name, data):
+ print " [>] \t", name, data
+
sh['playground'].call(name, data)
sh['layout'].call(name, data)
sh['windows'].call(name, data)
@@ -194,14 +196,11 @@
class Callback(core.Callback):
def data_received(self, data):
- print " --> " + repr(data)
+ print " --> \t" + repr(data)
def data_send(self, data):
- print " <-- " + repr(data)
+ print " <-- \t" + repr(data)
- def disconnect(self, reason):
- print "Server disconnected: " + reason
-
def connection_ready(self, public_rsa, reconnecting):
# We are connected
@@ -231,6 +230,8 @@
})
def disconnected(self, reason):
+ print " !!! \tConnection closed: " + reason
+
if reason == "manual": return
# [TODO] Send the reason in some way
Modified: trunk/client/downloader.py
===================================================================
--- trunk/client/downloader.py 2010-09-01 17:41:05 UTC (rev 386)
+++ trunk/client/downloader.py 2010-09-01 18:20:17 UTC (rev 387)
@@ -40,6 +40,7 @@
def get_file(self, filename, filetype, callback, *arg):
+ print " !!! \tDownload task:", filename
# First check if we already have this file loaded
if filename in self.loaded_files:
@@ -116,6 +117,7 @@
filename = task
task = self.tasks[filename]
+ del self.tasks[filename]
# Setting some variables
destination = real_path("downloads", task['filetype'], \
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-09-01 17:41:05 UTC (rev 386)
+++ trunk/client/playground.py 2010-09-01 18:20:17 UTC (rev 387)
@@ -213,8 +213,6 @@
sh['update']()
def logingui_draw(self, rect):
- print "GUIupdate", rect
-
if self.logingui == None: return
self.surf.blit(self.loginbg, rect, rect)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-09-01 17:41:11
|
Revision: 386
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=386&view=rev
Author: BlueWolf_
Date: 2010-09-01 17:41:05 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
Limited the FPS to 50 and also fixed the update-function blocking too much code (which dropped the framerate dramatically)
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/functions.py
trunk/client/playground.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-09-01 15:37:21 UTC (rev 385)
+++ trunk/client/VP.py 2010-09-01 17:41:05 UTC (rev 386)
@@ -114,30 +114,20 @@
and update the screen
"""
- # The following code will prevent it from going crazy on the cpu.
- # aka: using unlimited FPS. This will limit the FPS to 50 and will
- # remember everything that should be updated in the mean time
-
- self.updaterect.append(Rect(rect))
+ # When something updates due to a timer-update, nothing will be updated
+ # as long as the frame is still being rendered. Instead, the rect will
+ # be saved and will be updated once the timer has finished this frame
if self.updatewaiting:
- # Rect is saved. Will be updated once self.clock stops blocking
+ self.updaterect.append(Rect(rect))
return
- # When there are more updates from here one, they will be saved without
- # being updated immediately. We will do that once tick stops blocking
- self.updatewaiting = True
- self.clock.tick(UPDATE_FPS)
-
# Get all the rects to update
- if len(self.updaterect) == 1:
- rects = self.updaterect[0]
- else:
- rects = self.updaterect[0].unionall(self.updaterect[1:])
+ if type(rect) == list:
+ if len(rect) == 1:
+ rect = rect[0]
+ else:
+ rect = rect[0].unionall(rect[1:])
- self.updaterect = []
- self.updatewaiting = False
-
-
# The actual updating happens here
sh['screen'].blit(sh['playground'].surf, rect, rect)
sh['screen'].blit(sh['layout'].surf, rect, rect)
@@ -152,7 +142,7 @@
class Timer():
"""
- This timer will update every 33ms (30fps) ones called
+ This timer will update every frame as defined in UPDATE_FPS @ functions.py
"""
def __init__(self):
self.speed = 1/float(UPDATE_FPS)
@@ -177,10 +167,22 @@
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)
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-09-01 15:37:21 UTC (rev 385)
+++ trunk/client/functions.py 2010-09-01 17:41:05 UTC (rev 386)
@@ -24,7 +24,7 @@
SERVER = ("vp.bluewolf.nl", 6653)
-UPDATE_FPS = 100
+UPDATE_FPS = 50
# This will be used to [sh]are all variables, functions and classes across the
# code
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-09-01 15:37:21 UTC (rev 385)
+++ trunk/client/playground.py 2010-09-01 17:41:05 UTC (rev 386)
@@ -61,25 +61,25 @@
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, \
+ 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, \
+ 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, \
+ 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, \
+ sh['timer'].start("playground-move", self.playground_move, \
time.time(), self.viewport.left, 3)
elif ev.type == KEYUP:
if ev.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
self.direction_pressed = None
- sh['timer'].stop("playground_move")
+ sh['timer'].stop("playground-move")
def call(self, name, data):
@@ -89,6 +89,7 @@
# 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 = {}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-09-01 15:37:28
|
Revision: 385
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=385&view=rev
Author: BlueWolf_
Date: 2010-09-01 15:37:21 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
* Download-threads will now stop when closing VP.
* The playground-test-walk now works with the timer to test the performance.
* Also moved the FPS to 100 because I suspect a bug in the updater which halves the FPS in some situations. In the future 50FPS will probably be enough
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/downloader.py
trunk/client/functions.py
trunk/client/playground.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-09-01 14:24:10 UTC (rev 384)
+++ trunk/client/VP.py 2010-09-01 15:37:21 UTC (rev 385)
@@ -103,6 +103,7 @@
# Someone decided to close VP (Why??)
try: sh['client'].close()
except: pass
+ sh['downloader'].stop()
sys.exit()
@@ -125,7 +126,7 @@
# When there are more updates from here one, they will be saved without
# being updated immediately. We will do that once tick stops blocking
self.updatewaiting = True
- self.clock.tick(50)
+ self.clock.tick(UPDATE_FPS)
# Get all the rects to update
if len(self.updaterect) == 1:
@@ -154,7 +155,7 @@
This timer will update every 33ms (30fps) ones called
"""
def __init__(self):
- self.speed = 0.033
+ self.speed = 1/float(UPDATE_FPS)
self.callers = {}
self.timer = None
Modified: trunk/client/downloader.py
===================================================================
--- trunk/client/downloader.py 2010-09-01 14:24:10 UTC (rev 384)
+++ trunk/client/downloader.py 2010-09-01 15:37:21 UTC (rev 385)
@@ -15,7 +15,7 @@
## along with this program; if not, write to the Free Software
from functions import *
-from Queue import Queue
+import Queue
import urllib2, shutil
DOWNLOAD_THREADS = 2
@@ -25,17 +25,17 @@
This class will download and check all the stuff that is needed
"""
def __init__(self):
- self.notify = threading.Condition()
+ self.queue = Queue.PriorityQueue()
- self.tasks = [] # Dict within a list with the following things:
- # filename, filetype, callbacks, usages
+ self.tasks = {} # Dict with the key being the filename and value being a
+ # dict with: filetype, callbacks, usages
self.loaded_files = {} # Dict with the following things:
# filetype, cache, usages
self.workers = []
for i in range(DOWNLOAD_THREADS):
- self.workers.append(Worker(self.tasks, self.notify, self.error, \
+ self.workers.append(Worker(self.tasks, self.queue, self.error, \
self.loaded_files))
@@ -51,23 +51,20 @@
if filename in sh['filetable']:
# We know where it lives. Do we already have a task for this?
- task = self.find_task(filename)
- if task:
+ if self.tasks.has_key(filename):
# Append our callback
+ task = self.tasks[filename]
task['usages'] += 1
task['callbacks'].append((callback, arg))
else:
# Create a new task
- self.tasks.append({
- "filename": filename,
+ self.tasks[filename] = {
"filetype": filetype,
"callbacks": [(callback, arg),],
"usages": 1,
- })
- self.notify.acquire()
- self.notify.notify()
- self.notify.release()
+ }
+ self.queue.put((1, filename))
else:
print "File '" + filename + "' is not in the repository!"
@@ -87,53 +84,50 @@
def remove_loaded_file(self, filename):
try: del self.loaded_files[filename]
except: pass
-
-
- def find_task(self, filename):
- for task in self.tasks:
- if task['filename'] == filename:
- return task
- return None
def error(self, filetype, error):
if filetype == "img":
# [TODO] Maybe show a little error-image?
return pygame.Surface((1,1))
+
+ def stop(self):
+ # Stop the download-threads
+ for i in range(DOWNLOAD_THREADS):
+ self.queue.put((0, "STOP"))
+
class Worker(threading.Thread):
- def __init__(self, tasks, notify, error, loaded_files):
+ def __init__(self, tasks, queue, error, loaded_files):
self.tasks = tasks
- self.notify = notify
+ self.queue = queue
self.error = error
self.loaded_files = loaded_files
+ self.quiting = False
threading.Thread.__init__(self)
self.start()
def run(self):
- self.notify.acquire()
-
while 1:
- try:
- task = self.tasks.pop(0)
- except IndexError:
- self.notify.wait()
- continue
+ task = self.queue.get()[1]
+ if task == "STOP": return
-
+ filename = task
+ task = self.tasks[filename]
+
# Setting some variables
destination = real_path("downloads", task['filetype'], \
- task['filename'])
+ filename)
- if not task['filename'] in sh['filetable']:
+ if not filename in sh['filetable']:
print "File '" + filename + "' is not in the repository!"
- self.callbacks(task, self.error(task['filetype'], \
- "not in repos"))
+ self.callbacks(filename, task['callbacks'], \
+ self.error(task['filetype'], "not in repos"))
return
- filetable = sh['filetable'][task['filename']]
+ filetable = sh['filetable'][filename]
url = filetable['url']
checksum = filetable['checksum']
@@ -144,7 +138,7 @@
if os.path.exists(destination):
# Check if we need to download the file
filehash = file_checksum("downloads", task['filetype'], \
- task['filename'])
+ filename)
if checksum != filehash:
need_download = True
@@ -163,8 +157,8 @@
try: f = urllib2.urlopen(request)
except urllib2.URLError, e:
print "Url '" + url + "' could not be found!"
- self.callbacks(task, self.error(task['filetype'], \
- "not found"))
+ self.callbacks(filename, task['callbacks'], \
+ self.error(filename, "not found"))
return
target = file(destination + ".tmp", "wb")
@@ -181,12 +175,13 @@
# Check the checksum
filehash = file_checksum("downloads", task['filetype'], \
- task['filename'] + ".tmp")
+ filename + ".tmp")
if checksum != filehash:
- print "Checksum mismatch for '" + task['filename'] + "! " + \
+ print "Checksum mismatch for '" + filename + "! " + \
filehash + " > " + checksum
- self.callbacks(task, self.error(task['filetype'], "checksum"))
+ self.callbacks(filename, task['callbacks'], \
+ self.error(task['filetype'], "checksum"))
# Remove tmp file
os.remove(destination + ".tmp")
@@ -198,7 +193,6 @@
# Everything went good! Now load the file
load = {
- "filename": task['filename'],
"filetype": task['filetype'],
"cache": None,
"usages": task['usages']
@@ -207,15 +201,12 @@
if task['filetype'] == "img":
# Load image
load['cache'] = load_image(True, "downloads", task['filetype'],\
- task['filename'])
+ filename)
- self.loaded_files[task['filename']] = load
- self.callbacks(task, load['cache'])
+ self.loaded_files[filename] = load
+ self.callbacks(filename, task['callbacks'], load['cache'])
-
- self.notify.release()
-
- def callbacks(self, task, cache):
- for callback in task['callbacks']:
- callback[0](task['filename'], cache, *callback[1])
+ def callbacks(self, filename, callbacks, cache):
+ for callback in callbacks:
+ callback[0](filename, cache, *callback[1])
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-09-01 14:24:10 UTC (rev 384)
+++ trunk/client/functions.py 2010-09-01 15:37:21 UTC (rev 385)
@@ -22,8 +22,10 @@
VERSION = "0.0.1"
-SERVER = ("localhost", 6653)
+SERVER = ("vp.bluewolf.nl", 6653)
+UPDATE_FPS = 100
+
# This will be used to [sh]are all variables, functions and classes across the
# code
sh = {}
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-09-01 14:24:10 UTC (rev 384)
+++ trunk/client/playground.py 2010-09-01 15:37:21 UTC (rev 385)
@@ -38,6 +38,7 @@
# Playground stuff
self.backgrounds = {}
self.viewport = None
+ self.direction_pressed = None
def event(self, ev):
@@ -58,18 +59,27 @@
elif self.status == "playground":
if ev.type == KEYDOWN:
- if ev.key == K_UP:
- self.viewport.move_ip(0, -10)
- self.playground_render()
- if ev.key == K_DOWN:
- self.viewport.move_ip(0, 10)
- self.playground_render()
- if ev.key == K_LEFT:
- self.viewport.move_ip(-10, 0)
- self.playground_render()
- if ev.key == K_RIGHT:
- self.viewport.move_ip(10, 0)
- self.playground_render()
+ 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.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]:
+ self.direction_pressed = None
+ sh['timer'].stop("playground_move")
def call(self, name, data):
@@ -281,8 +291,25 @@
self.transit = 1 - timeline
self.playground_render()
+
+
+ def playground_move(self, name, startime, startpos, direction):
+ # Temporary test function to walk
+
+ timeline = time.time() - startime
+ speed = 175
+ move = timeline*speed
+
+ if direction == 0:
+ self.viewport.top = startpos - move
+ elif direction == 1:
+ self.viewport.top = startpos + move
+ elif direction == 2:
+ self.viewport.left = startpos - move
+ elif direction == 3:
+ self.viewport.left = startpos + move
+ self.playground_render()
-
class LoginFeedback(gui.Feedback):
def __init__(self, parent):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ch...@us...> - 2010-09-01 14:24:16
|
Revision: 384
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=384&view=rev
Author: chozone
Date: 2010-09-01 14:24:10 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
Fixed typo in sql-query in landscapes.py in server.
Modified Paths:
--------------
trunk/server/landscapes.py
Modified: trunk/server/landscapes.py
===================================================================
--- trunk/server/landscapes.py 2010-09-01 13:31:15 UTC (rev 383)
+++ trunk/server/landscapes.py 2010-09-01 14:24:10 UTC (rev 384)
@@ -25,7 +25,7 @@
self.list = {}
- self.db.execute("SELECT `type`, `direction`, `position`, 'transition' \
+ self.db.execute("SELECT `type`, `direction`, `position`, `transition` \
FROM `landscapes` ORDER BY `id` ASC") # Order in DB = order in world
self.list = self.db.fetchall()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ch...@us...> - 2010-09-01 13:31:27
|
Revision: 383
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=383&view=rev
Author: chozone
Date: 2010-09-01 13:31:15 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
Fixed checksum function in client.
Modified Paths:
--------------
trunk/client/functions.py
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-08-31 18:34:36 UTC (rev 382)
+++ trunk/client/functions.py 2010-09-01 13:31:15 UTC (rev 383)
@@ -54,7 +54,7 @@
def file_checksum(*dir):
# Read the file in chunks of 32KB
- f = file(real_path(*dir))
+ f = file(real_path(*dir), 'rb')
checksum = md5()
while 1:
data = f.read(32768)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-31 18:34:42
|
Revision: 382
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=382&view=rev
Author: BlueWolf_
Date: 2010-08-31 18:34:36 +0000 (Tue, 31 Aug 2010)
Log Message:
-----------
Added a transition effect for the playground. Not sure if I like it yet
Modified Paths:
--------------
trunk/client/playground.py
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-31 18:19:41 UTC (rev 381)
+++ trunk/client/playground.py 2010-08-31 18:34:36 UTC (rev 382)
@@ -20,7 +20,7 @@
class Playground():
def __init__(self):
- self.surf = pygame.Surface((1000, 700), SRCALPHA).convert_alpha()
+ self.surf = pygame.Surface((1000, 700)).convert()
self.surf.fill([0,0,0])
self.status = None
@@ -78,6 +78,7 @@
if data['status'] != self.status:
# Unload data from the playground
if self.status != None:
+ sh['timer'].stop("playground-transit")
for name in self.backgrounds.keys():
sh['downloader'].remove_usage(name)
self.backgrounds = {}
@@ -113,8 +114,10 @@
# Load the data for the playground
self.viewport = Rect(0, 0, 1000, 700)
self.oldsurf = self.surf.copy()
- self.transit = 0
+ 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']
@@ -229,6 +232,7 @@
y_max = y_min + 250 * ((float(self.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)
@@ -243,6 +247,10 @@
self.surf.blit(background, rect, bg_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)
@@ -260,9 +268,21 @@
"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()
+
+
class LoginFeedback(gui.Feedback):
def __init__(self, parent):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-31 18:19:48
|
Revision: 381
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=381&view=rev
Author: BlueWolf_
Date: 2010-08-31 18:19:41 +0000 (Tue, 31 Aug 2010)
Log Message:
-----------
Removed has_focus and has_hover from sh as it's practically a duplicate from key.get_focused() and mouse.get_focused()
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/gui.py
trunk/client/layout.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-08-31 18:13:16 UTC (rev 380)
+++ trunk/client/VP.py 2010-08-31 18:19:41 UTC (rev 381)
@@ -29,8 +29,6 @@
class Main():
def __init__(self):
- sh['has_focus'] = True
- sh['has_hover'] = True
sh['filetable'] = {}
sh['timer'] = Timer()
sh['downloader'] = Downloader()
@@ -92,17 +90,7 @@
ev = pygame.event.Event(MOUSEMOTION,
buttons = ev.buttons,
pos = pos)
-
- # As (sometimes) the mouse focus doesn't get through when
- # switching workspaces (Linux), this should "fix" it
- sh['has_hover'] = True
- elif ev.type == ACTIVEEVENT:
- if ev.state == 1: # Mouse focus
- sh['has_hover'] = (ev.gain == 1)
- elif ev.state == 2: # Window focus
- sh['has_focus'] = (ev.gain == 1)
-
# 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-08-31 18:13:16 UTC (rev 380)
+++ trunk/client/gui.py 2010-08-31 18:19:41 UTC (rev 381)
@@ -111,7 +111,7 @@
if pos == None: pos = pygame.mouse.get_pos()
- if sh['has_hover']:
+ if pygame.mouse.get_focused():
# Get the current hovered object
rect, hover = self.this_pos(pos)
Modified: trunk/client/layout.py
===================================================================
--- trunk/client/layout.py 2010-08-31 18:13:16 UTC (rev 380)
+++ trunk/client/layout.py 2010-08-31 18:19:41 UTC (rev 381)
@@ -92,7 +92,10 @@
self.topbar = load_image(True, "images", "topbar.png")
self.selected = None
- self.hover = self.topbarcursor(pygame.mouse.get_pos())
+ if pygame.mouse.get_focused():
+ self.hover = self.topbarcursor(pygame.mouse.get_pos())
+ else:
+ self.hover = None
self.toppos = 0
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-31 18:13:22
|
Revision: 380
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=380&view=rev
Author: BlueWolf_
Date: 2010-08-31 18:13:16 +0000 (Tue, 31 Aug 2010)
Log Message:
-----------
Added the background. This infinite grass likes to move! (use the keys)
Modified Paths:
--------------
trunk/client/playground.py
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-30 22:33:47 UTC (rev 379)
+++ trunk/client/playground.py 2010-08-31 18:13:16 UTC (rev 380)
@@ -26,6 +26,9 @@
self.status = None
self.statuswhere = None
+ self.oldsurf = None
+ self.transit = None
+
# Login stuff
self.loginbg = None
self.loginbox = None
@@ -34,7 +37,9 @@
# Playground stuff
self.backgrounds = {}
+ self.viewport = None
+
def event(self, ev):
if self.status == "login":
@@ -49,7 +54,22 @@
if self.logingui != None:
return self.logingui.event(ev)
-
+
+
+ elif self.status == "playground":
+ if ev.type == KEYDOWN:
+ if ev.key == K_UP:
+ self.viewport.move_ip(0, -10)
+ self.playground_render()
+ if ev.key == K_DOWN:
+ self.viewport.move_ip(0, 10)
+ self.playground_render()
+ if ev.key == K_LEFT:
+ self.viewport.move_ip(-10, 0)
+ self.playground_render()
+ if ev.key == K_RIGHT:
+ self.viewport.move_ip(10, 0)
+ self.playground_render()
def call(self, name, data):
@@ -58,6 +78,8 @@
if data['status'] != self.status:
# Unload data from the playground
if self.status != None:
+ for name in self.backgrounds.keys():
+ sh['downloader'].remove_usage(name)
self.backgrounds = {}
# Load the data for the login
@@ -89,8 +111,10 @@
self.logingui = None
# Load the data for the playground
- self.surf.fill([0,0,0])
- sh['update']()
+ self.viewport = Rect(0, 0, 1000, 700)
+ self.oldsurf = self.surf.copy()
+ self.transit = 0
+ self.playground_render(None, True)
self.status = data['status']
self.statuswhere = data['where']
@@ -187,6 +211,42 @@
+ def playground_render(self, rect = None, doupdate = True):
+ # Render the playground
+ 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)
+
+ 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)
+
+ if doupdate:
+ sh['update'](rect)
+
+
def download(self, filename, cache, name, *arg):
if name == "background":
self.backgrounds[filename] = cache
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-30 22:33:55
|
Revision: 379
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=379&view=rev
Author: BlueWolf_
Date: 2010-08-30 22:33:47 +0000 (Mon, 30 Aug 2010)
Log Message:
-----------
Cleaning up some non-used files in the resource-folder
Added Paths:
-----------
res/images/grass-250.png
res/images/grass.png
res/images/icon.svg
Removed Paths:
-------------
res/images/door.away.png
res/images/esther_drawings.png
res/images/popup.error.png
res/images/rightclick.menu.example.png
res/images/scroll_bar_horizontal.png
res/images/scroll_bar_vertical.png
res/images/scroll_button.png
res/images/scroll_button_bottom.png
res/images/scroll_button_left.png
res/images/scroll_button_right.png
res/images/scroll_button_top.png
res/images/scroll_knob.png
res/images/statwindow.png
Deleted: res/images/door.away.png
===================================================================
(Binary files differ)
Deleted: res/images/esther_drawings.png
===================================================================
(Binary files differ)
Added: res/images/grass-250.png
===================================================================
(Binary files differ)
Property changes on: res/images/grass-250.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: res/images/grass.png
===================================================================
(Binary files differ)
Property changes on: res/images/grass.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: res/images/icon.svg
===================================================================
--- res/images/icon.svg (rev 0)
+++ res/images/icon.svg 2010-08-30 22:33:47 UTC (rev 379)
@@ -0,0 +1,910 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="120"
+ height="120"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.47pre4 r22446"
+ inkscape:export-filename="/data/temp/test.png"
+ inkscape:export-xdpi="90"
+ inkscape:export-ydpi="90"
+ sodipodi:docname="icon.svg">
+ <defs
+ id="defs4">
+ <pattern
+ inkscape:stockid="Sand (bitmap)"
+ id="pattern5677"
+ height="256"
+ width="256"
+ patternUnits="userSpaceOnUse">
+ <!-- Seamless texture provided by FreeSeamlessTextures.com -->
+ <!-- License: creative commons attribution -->
+ <image
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-30 22:22:23
|
Revision: 378
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=378&view=rev
Author: BlueWolf_
Date: 2010-08-30 22:22:16 +0000 (Mon, 30 Aug 2010)
Log Message:
-----------
Added the ability to download files and fixed some other stuff, including how the playground gets notified about the current status (changed changestatus to a more general 'call'). I also changed rsa_received to connection_ready in the client-core as that's a more appropriate name for what it is used for
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/core/callback.py
trunk/client/core/parser.py
trunk/client/functions.py
trunk/client/layout.py
trunk/client/playground.py
trunk/client/windows.py
Added Paths:
-----------
trunk/client/downloader.py
trunk/client/downloads/
trunk/client/downloads/img/
trunk/client/downloads/snd/
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/VP.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -24,6 +24,7 @@
from playground import Playground
from layout import Layout
from windows import Windows
+from downloader import Downloader
class Main():
@@ -32,6 +33,7 @@
sh['has_hover'] = True
sh['filetable'] = {}
sh['timer'] = Timer()
+ sh['downloader'] = Downloader()
# Fire up pygame
os.environ['SDL_VIDEO_CENTERED']='1'
@@ -66,7 +68,10 @@
'app_version': VERSION},
Callback())
- self.changestatus("connecting")
+ self.call("status", {
+ "status": "login",
+ "where": "connecting"
+ })
sh['client'].connect(*SERVER)
@@ -151,10 +156,10 @@
pygame.display.update(rect)
- def changestatus(self, status):
- sh['playground'].changestatus(status)
- sh['layout'].changestatus(status)
- sh['windows'].changestatus(status)
+ def call(self, name, data):
+ sh['playground'].call(name, data)
+ sh['layout'].call(name, data)
+ sh['windows'].call(name, data)
class Timer():
"""
@@ -206,16 +211,33 @@
def disconnect(self, reason):
print "Server disconnected: " + reason
- def received_rsa(self, public):
+ def connection_ready(self, public_rsa, reconnecting):
# We are connected
- sh['main'].changestatus("login")
+
+ if reconnecting:
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "logging in"
+ })
+ else:
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "waiting"
+ })
def logged_in(self, username, cid, owner):
- sh['main'].changestatus("playground")
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "downloading"
+ })
def failed_logging_in(self, reason):
# [TODO] Send the reason in some way
- sh['main'].changestatus("login")
+
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "waiting"
+ })
def disconnected(self, reason):
if reason == "manual": return
@@ -223,22 +245,35 @@
# [TODO] Send the reason in some way
if reason in ["closed", "gone offline"]:
# Reconnect while logging in
- sh['main'].changestatus("connecting")
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "connecting"
+ })
return True
elif reason in ["duplicate", "crash"]:
# Reconnecting while not logging in
- sh['main'].changestatus("connecting")
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "connecting"
+ })
sh['client'].connect(*SERVER)
else:
# Not doing anything at all
# [TODO] Show popup or something, without reconnecting?
- sh['main'].changestatus("connecting")
+ 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/core/callback.py
===================================================================
--- trunk/client/core/callback.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/core/callback.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -28,15 +28,19 @@
"""
pass
- def received_rsa(self, public):
+ def connection_ready(self, public_rsa, reconnecting):
"""
When a connection is made, the server will generate a rsa-key. The
client has to wait for this, before logging in. After this event, you
- can use client.login (if you haven't specified a login at client.connect)
+ can use client.login (if you haven't specified a login at
+ client.connect)
public:
The generated public rsa-key. It is a dict with 2 values: e and n.
It's used for encoding the password
+ reconnecting:
+ Boolean which is True when the core automatically tries to log in
+ again
This is a placeholder. If you want to catch this event, overwrite this
Modified: trunk/client/core/parser.py
===================================================================
--- trunk/client/core/parser.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/core/parser.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -56,9 +56,11 @@
self.sh['rsakey'] = msg['public']
- self.call.received_rsa(msg['public'])
+ reconnect = (self.core.cid == None and self.sh['auto_login'])
- if self.core.cid == None and self.sh['auto_login'] != ():
+ self.call.connection_ready(msg['public'], reconnect)
+
+ if reconnect:
login = self.sh['auto_login']
login[0](*login[1])
Added: trunk/client/downloader.py
===================================================================
--- trunk/client/downloader.py (rev 0)
+++ trunk/client/downloader.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -0,0 +1,221 @@
+## 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
+
+from functions import *
+from Queue import Queue
+import urllib2, shutil
+
+DOWNLOAD_THREADS = 2
+
+class Downloader():
+ """
+ This class will download and check all the stuff that is needed
+ """
+ def __init__(self):
+ self.notify = threading.Condition()
+
+ self.tasks = [] # Dict within a list with the following things:
+ # filename, filetype, callbacks, usages
+
+ self.loaded_files = {} # Dict with the following things:
+ # filetype, cache, usages
+
+ self.workers = []
+ for i in range(DOWNLOAD_THREADS):
+ self.workers.append(Worker(self.tasks, self.notify, self.error, \
+ self.loaded_files))
+
+
+ def get_file(self, filename, filetype, callback, *arg):
+ # First check if we already have this file loaded
+
+ if filename in self.loaded_files:
+ # File is already loaded. Easy!
+ load = self.loaded_files[filename]
+ load['usages'] += 1
+ callback(filename, load['cache'], *arg)
+
+
+ if filename in sh['filetable']:
+ # We know where it lives. Do we already have a task for this?
+ task = self.find_task(filename)
+ if task:
+ # Append our callback
+ task['usages'] += 1
+ task['callbacks'].append((callback, arg))
+
+ else:
+ # Create a new task
+ self.tasks.append({
+ "filename": filename,
+ "filetype": filetype,
+ "callbacks": [(callback, arg),],
+ "usages": 1,
+ })
+ self.notify.acquire()
+ self.notify.notify()
+ self.notify.release()
+
+ else:
+ print "File '" + filename + "' is not in the repository!"
+ callback(filename, self.error(filetype, "not in repos"), *arg)
+
+
+ def remove_usage(self, filename):
+ try: load = self.loaded_files[filename]
+ except: pass
+
+ load['usages'] -= 1
+ if load['usages'] == 0:
+ # Remove the file
+ self.remove_loaded_file(filename)
+
+
+ def remove_loaded_file(self, filename):
+ try: del self.loaded_files[filename]
+ except: pass
+
+
+ def find_task(self, filename):
+ for task in self.tasks:
+ if task['filename'] == filename:
+ return task
+
+ return None
+
+ def error(self, filetype, error):
+ if filetype == "img":
+ # [TODO] Maybe show a little error-image?
+ return pygame.Surface((1,1))
+
+
+class Worker(threading.Thread):
+ def __init__(self, tasks, notify, error, loaded_files):
+ self.tasks = tasks
+ self.notify = notify
+ self.error = error
+ self.loaded_files = loaded_files
+
+ threading.Thread.__init__(self)
+ self.start()
+
+ def run(self):
+ self.notify.acquire()
+
+ while 1:
+ try:
+ task = self.tasks.pop(0)
+ except IndexError:
+ self.notify.wait()
+ continue
+
+
+ # Setting some variables
+ destination = real_path("downloads", task['filetype'], \
+ task['filename'])
+
+ if not task['filename'] in sh['filetable']:
+ print "File '" + filename + "' is not in the repository!"
+ self.callbacks(task, self.error(task['filetype'], \
+ "not in repos"))
+ return
+
+ filetable = sh['filetable'][task['filename']]
+ url = filetable['url']
+ checksum = filetable['checksum']
+
+
+ need_download = not os.path.exists(destination)
+
+ # Is this file already downloaded?
+ if os.path.exists(destination):
+ # Check if we need to download the file
+ filehash = file_checksum("downloads", task['filetype'], \
+ task['filename'])
+
+ if checksum != filehash:
+ need_download = True
+
+ # Remove existing file
+ os.remove(destination)
+
+
+ # Do we need to (re)download it?
+ if need_download:
+ # Download the file!
+ request = urllib2.Request(url)
+ request.add_header('User-agent', \
+ "VirtualPlayground-downloader/3.0")
+
+ try: f = urllib2.urlopen(request)
+ except urllib2.URLError, e:
+ print "Url '" + url + "' could not be found!"
+ self.callbacks(task, self.error(task['filetype'], \
+ "not found"))
+ return
+
+ target = file(destination + ".tmp", "wb")
+
+ while 1:
+ bytes = f.read(10240) #Read 10240 bytes each time
+
+ #If its zero, we've reached the end of the file!
+ if len(bytes) == 0: break
+
+ target.write(bytes)
+
+ target.close()
+
+ # Check the checksum
+ filehash = file_checksum("downloads", task['filetype'], \
+ task['filename'] + ".tmp")
+
+ if checksum != filehash:
+ print "Checksum mismatch for '" + task['filename'] + "! " + \
+ filehash + " > " + checksum
+ self.callbacks(task, self.error(task['filetype'], "checksum"))
+
+ # Remove tmp file
+ os.remove(destination + ".tmp")
+ return
+
+ # Move the file
+ shutil.move(destination + ".tmp", destination)
+
+
+ # Everything went good! Now load the file
+ load = {
+ "filename": task['filename'],
+ "filetype": task['filetype'],
+ "cache": None,
+ "usages": task['usages']
+ }
+
+ if task['filetype'] == "img":
+ # Load image
+ load['cache'] = load_image(True, "downloads", task['filetype'],\
+ task['filename'])
+
+ self.loaded_files[task['filename']] = load
+ self.callbacks(task, load['cache'])
+
+
+ self.notify.release()
+
+
+ def callbacks(self, task, cache):
+ for callback in task['callbacks']:
+ callback[0](task['filename'], cache, *callback[1])
Property changes on: trunk/client/downloads/img
___________________________________________________________________
Added: svn:ignore
+ *
Property changes on: trunk/client/downloads/snd
___________________________________________________________________
Added: svn:ignore
+ *
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/functions.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -17,7 +17,7 @@
import pygame, os, sys, threading, time, math
from pygame.locals import *
-from hashlib import sha1
+from hashlib import sha1, md5
import core
VERSION = "0.0.1"
@@ -51,6 +51,19 @@
print 'Cannot load image:', fullname
raise SystemExit, message
return image
+
+def file_checksum(*dir):
+ # Read the file in chunks of 32KB
+ f = file(real_path(*dir))
+ checksum = md5()
+ while 1:
+ data = f.read(32768)
+ if not data: break
+ checksum.update(data)
+
+ return checksum.hexdigest()
+
+
# GUI needs the functions again. That's why it has to be imported after all
Modified: trunk/client/layout.py
===================================================================
--- trunk/client/layout.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/layout.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -75,30 +75,34 @@
return True
- def changestatus(self, status):
- sh['timer'].stop("layout-topslide") # Just in case
+ def call(self, name, data):
+ if name == "status":
+ if data['status'] == "login":
+ if self.status == "playground":
+ # Unload all the from playground
+
+ # Slide the topbar out
+ sh['timer'].start("layout-topslide", self.timer, \
+ time.time(), 0)
- login_list = ['connecting', 'login', 'logging in']
- if status in login_list and self.status not in login_list:
- # (Un)load all the data
- if self.topbar:
- # Slide the topbar out
- sh['timer'].start("layout-topslide", self.timer, time.time(), 0)
+ elif data['status'] == "playground":
+ if self.status != "playground":
+ # load al the data for the playground
+ self.topbar = load_image(True, "images", "topbar.png")
+
+ self.selected = None
+ self.hover = self.topbarcursor(pygame.mouse.get_pos())
+
+ self.toppos = 0
+
+ # Slide the topbar in
+ sh['timer'].start("layout-topslide", self.timer, \
+ time.time(), 1)
- elif status == "playground":
- self.topbar = load_image(True, "images", "topbar.png")
-
- self.selected = None
- self.hover = self.topbarcursor(pygame.mouse.get_pos())
-
- self.toppos = 0
-
- # Slide the topbar in
- sh['timer'].start("layout-topslide", self.timer, time.time(), 1)
-
- self.status = status
+ self.status = data['status']
+
def updatetop(self, wholebar = False):
if wholebar:
self.surf.fill([0,0,0,0])
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/playground.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -24,6 +24,7 @@
self.surf.fill([0,0,0])
self.status = None
+ self.statuswhere = None
# Login stuff
self.loginbg = None
@@ -32,7 +33,7 @@
self.logingui = None
# Playground stuff
- # ...
+ self.backgrounds = {}
def event(self, ev):
if self.status == "login":
@@ -51,36 +52,60 @@
- def changestatus(self, status):
- login_list = ['connecting', 'login', 'logging in']
- if status in login_list and self.status not in login_list:
- # (Un)load all the data 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)
-
- elif status == "playground":
- # (Un)load all the data for the playground
- self.loginbg = None
- self.loginbox = None
- self.loginfont = None
- self.logingui = None
+ 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:
+ self.backgrounds = {}
+
+ # 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['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")
- self.surf.fill([0,0,0])
- sh['update']()
+ 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
+ self.surf.fill([0,0,0])
+ sh['update']()
+
+ self.status = data['status']
+ self.statuswhere = data['where']
- if status == "connecting":
- self.drawlogin("connecting")
- elif status == "login":
- self.drawlogin("login")
- elif status == "logging in":
- self.drawlogin("logging in")
+ elif name == "filetable":
+ if data['action'] == "update" and self.status == "login" and \
+ self.statuswhere == "downloading":
+
+ # Pre-load the necessarily files for the playground
+ counter = {"counter": 1}
+ sh['downloader'].get_file("bg-grass.png", "img", self.download,\
+ "background", counter)
+
- self.status = status
-
def drawlogin(self, status):
self.loginstatus = status
self.surf.blit(self.loginbg, (0,0))
@@ -141,6 +166,12 @@
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):
@@ -153,8 +184,26 @@
self.surf.blit(self.logingui.surf, rect, rect)
sh['update'](rect)
+
+
+
+ def download(self, filename, cache, name, *arg):
+ if name == "background":
+ self.backgrounds[filename] = cache
+
+ counter = arg[0]
+ counter['counter'] -= 1
+
+ if counter['counter'] == 0:
+ # We're finished downloading the necessarily stuff
+ sh['main'].call("status", {
+ "status": "playground",
+ "where": "playground"
+ })
-
+
+
+
class LoginFeedback(gui.Feedback):
def __init__(self, parent):
self.parent = parent
@@ -182,7 +231,10 @@
pwd = sha1(self.parent.logingui['pwd'].input).hexdigest()
self.parent.logingui = None
- sh['main'].changestatus("logging in")
+ sh['main'].call("status", {
+ "status": "login",
+ "where": "logging in"
+ })
sh['client'].login(usr, pwd)
Modified: trunk/client/windows.py
===================================================================
--- trunk/client/windows.py 2010-08-28 13:36:11 UTC (rev 377)
+++ trunk/client/windows.py 2010-08-30 22:22:16 UTC (rev 378)
@@ -24,5 +24,5 @@
def event(self, ev):
pass
- def changestatus(self, status):
+ def call(self, name, data):
pass
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ch...@us...> - 2010-08-28 13:36:17
|
Revision: 377
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=377&view=rev
Author: chozone
Date: 2010-08-28 13:36:11 +0000 (Sat, 28 Aug 2010)
Log Message:
-----------
Added landscapes to server (retrieving them from database + sending them to client upon login)
Modified Paths:
--------------
trunk/server/VPS.py
trunk/server/callback.py
trunk/server/database
trunk/server/filetable.py
trunk/server/functions.py
Added Paths:
-----------
trunk/server/landscapes.py
Modified: trunk/server/VPS.py
===================================================================
--- trunk/server/VPS.py 2010-08-27 21:40:53 UTC (rev 376)
+++ trunk/server/VPS.py 2010-08-28 13:36:11 UTC (rev 377)
@@ -43,7 +43,7 @@
# Users table has no admins
create_account_setup()
- print "Database check done..."
+ print "Database check done."
def create_account_setup():
# Ask user if he wants to create an account (1st one, admin)
@@ -81,6 +81,8 @@
check_database()
file_table.update_from_database()
+landscapes.update_from_database()
+
server = core.Server(config, Callback())
server.start_server()
Modified: trunk/server/callback.py
===================================================================
--- trunk/server/callback.py 2010-08-27 21:40:53 UTC (rev 376)
+++ trunk/server/callback.py 2010-08-28 13:36:11 UTC (rev 377)
@@ -41,6 +41,8 @@
# download what they need.
self.clients[cid]['con'].custom_send("filetable", file_table.table)
+ self.clients[cid]['con'].custom_send("landscapes", landscapes.list)
+
def leaves_vp(self, cid):
print " < %s: %s"%(cid, self.clients[cid]['con'].ip)
Modified: trunk/server/database
===================================================================
--- trunk/server/database 2010-08-27 21:40:53 UTC (rev 376)
+++ trunk/server/database 2010-08-28 13:36:11 UTC (rev 377)
@@ -26,3 +26,12 @@
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;'''
+landscapes = '''CREATE TABLE IF NOT EXISTS `landscapes` (
+ `id` int(11) NOT NULL auto_increment,
+ `type` varchar(255) NOT NULL,
+ `direction` varchar(255) NOT NULL,
+ `position` int(11) NOT NULL,
+ `transition` int(11) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;'''
+
Modified: trunk/server/filetable.py
===================================================================
--- trunk/server/filetable.py 2010-08-27 21:40:53 UTC (rev 376)
+++ trunk/server/filetable.py 2010-08-28 13:36:11 UTC (rev 377)
@@ -21,6 +21,8 @@
self.db = db
def update_from_database(self):
+ print "Retrieving file table from database..."
+
self.table = {}
self.db.execute("SELECT `filename`, `url`, `checksum` FROM `files`")
@@ -31,6 +33,8 @@
self.table[file['filename']] = {'url': fullurl,
'checksum': file['checksum']}
+
+ print "Done, found %s entries in file table." % len(self.table)
return self.table
def add(self, filename, url, checksum):
Modified: trunk/server/functions.py
===================================================================
--- trunk/server/functions.py 2010-08-27 21:40:53 UTC (rev 376)
+++ trunk/server/functions.py 2010-08-28 13:36:11 UTC (rev 377)
@@ -20,6 +20,7 @@
import database
from filetable import FileTable
+from landscapes import LandscapeManager
try: from configobj import ConfigObj
except: sys.exit("ERROR: You need the configobj-module for this to work!")
@@ -70,6 +71,7 @@
config['database']['host'])
file_table = FileTable(db)
+landscapes = LandscapeManager(db)
\ No newline at end of file
Added: trunk/server/landscapes.py
===================================================================
--- trunk/server/landscapes.py (rev 0)
+++ trunk/server/landscapes.py 2010-08-28 13:36:11 UTC (rev 377)
@@ -0,0 +1,34 @@
+## This file is part of Virtual Playground
+## Copyright (c) 2009-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.
+
+class LandscapeManager():
+ def __init__(self, db):
+ self.list = ()
+ self.db = db
+
+ def update_from_database(self):
+ print "Retrieving landscapes from database..."
+
+ self.list = {}
+
+ self.db.execute("SELECT `type`, `direction`, `position`, 'transition' \
+ FROM `landscapes` ORDER BY `id` ASC") # Order in DB = order in world
+ self.list = self.db.fetchall()
+
+ print "Done, found %s landscapes." % len(self.list)
+
+ return self.list
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-27 21:41:00
|
Revision: 376
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=376&view=rev
Author: BlueWolf_
Date: 2010-08-27 21:40:53 +0000 (Fri, 27 Aug 2010)
Log Message:
-----------
Added the X to the window. Can be very useful in some situations :-)
Modified Paths:
--------------
res/images/xcf/gui-window.xcf
Modified: res/images/xcf/gui-window.xcf
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-25 22:03:09
|
Revision: 375
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=375&view=rev
Author: BlueWolf_
Date: 2010-08-25 22:02:44 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
Added a Link object in the GUI, starting with the Window one and added the ability to create timers for stuff like animations
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/functions.py
trunk/client/gui.py
trunk/client/layout.py
trunk/client/playground.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-08-25 21:07:48 UTC (rev 374)
+++ trunk/client/VP.py 2010-08-25 22:02:44 UTC (rev 375)
@@ -30,6 +30,8 @@
def __init__(self):
sh['has_focus'] = True
sh['has_hover'] = True
+ sh['filetable'] = {}
+ sh['timer'] = Timer()
# Fire up pygame
os.environ['SDL_VIDEO_CENTERED']='1'
@@ -122,7 +124,7 @@
# aka: using unlimited FPS. This will limit the FPS to 50 and will
# remember everything that should be updated in the mean time
- self.updaterect.append(rect)
+ self.updaterect.append(Rect(rect))
if self.updatewaiting:
# Rect is saved. Will be updated once self.clock stops blocking
return
@@ -154,6 +156,44 @@
sh['layout'].changestatus(status)
sh['windows'].changestatus(status)
+class Timer():
+ """
+ This timer will update every 33ms (30fps) ones called
+ """
+ def __init__(self):
+ self.speed = 0.033
+ 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):
+ for name, info in self.callers.items():
+ if info[0](name, *info[1]):
+ del self.callers[name]
+
+ # 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):
@@ -195,7 +235,10 @@
# Not doing anything at all
# [TODO] Show popup or something, without reconnecting?
sh['main'].changestatus("connecting")
-
+
+ def custom_received(self, header, body):
+ if header == "filetable": # List of all the downloadable objects
+ sh['filetable'] = body
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-08-25 21:07:48 UTC (rev 374)
+++ trunk/client/functions.py 2010-08-25 22:02:44 UTC (rev 375)
@@ -15,7 +15,7 @@
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import pygame, os, sys, threading
+import pygame, os, sys, threading, time, math
from pygame.locals import *
from hashlib import sha1
import core
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-25 21:07:48 UTC (rev 374)
+++ trunk/client/gui.py 2010-08-25 22:02:44 UTC (rev 375)
@@ -58,12 +58,13 @@
raise KeyError(key)
- def add(self, Obj, name, rect):
+ def add(self, Obj, name, rect, feedback = None):
"""
Append a child to this object
"""
- obj = Obj(name, rect, self, self, self.feedback)
+ if feedback == None: feedback = self.feedback
+ obj = Obj(name, rect, self, self, feedback)
self.children.append(obj)
return obj
@@ -276,6 +277,9 @@
self.hover = False
self.focus = False
+ self.cangetfocus = True
+ self.canrise = False
+
# Create a surface where an object blits itself onto
self.surf = pygame.Surface((self.rect.width, self.rect.height), \
SRCALPHA).convert_alpha()
@@ -290,12 +294,34 @@
raise KeyError(key)
- def add(self, Obj, name, rect):
+ def __defaults__(self):
+ pass
+
+ def render(self):
+ pass
+
+ def hovering(self, value):
+ pass
+
+ def click(self, state, pos):
+ pass
+
+ def got_focus(self):
+ pass
+
+ def lost_focus(self):
+ pass
+
+ def keypress(self, ev):
+ pass
+
+ def add(self, Obj, name, rect, feedback = None):
"""
Append a child to this object
"""
- obj = Obj(name, rect, self.main_parent, self, self.feedback)
+ if feedback == None: feedback = self.feedback
+ obj = Obj(name, rect, self.main_parent, self)
self.children.append(obj)
return obj
@@ -376,24 +402,37 @@
+class Window(Object):
+ def __defaults__(self):
+ self.cangetfocus = False
+ self.canrise = True
+
+ self.canmove = True
+ self.hasborder = True
+ self.caption = ""
+ self.canclose = True
+
+ def move(self, topos):
+ # [TODO]
+ pass
+
+
class Textbox(Object):
def __defaults__(self):
- self.cangetfocus = True
+ self.textpos = None # Position of the text currently
- self.input = ""
+ self.font = None
+ self.backgroundsurf = pygame.Surface((self.rect.width, \
+ self.rect.height*2), SRCALPHA).convert_alpha()
self.cursorpos = 0
self.style = None
self.type = "text"
- self.textpos = None # Position of the text currently
+ self.input = ""
- self.font = None
- self.backgroundsurf = pygame.Surface((self.rect.width, \
- self.rect.height*2), SRCALPHA).convert_alpha()
-
def set_style(self, style):
"""
Change the style for this textbox
@@ -495,9 +534,6 @@
if self.focus:
pygame.draw.line(self.surf, [118, 58, 19], (pos+cursorpos+6, 10), (pos+cursorpos+6, 26), 2)
- def hovering(self, value):
- pass
-
def click(self, state, pos):
if state == 0:
@@ -580,16 +616,14 @@
def __defaults__(self):
self.cangetfocus = False
-
- self.caption = ""
+ self.font = None
+ self.backgroundsurf = pygame.Surface((self.rect.width, \
+ self.rect.height*3), SRCALPHA).convert_alpha()
self.style = None
-
self.mousedown = False
self.ispressed = False
- self.font = None
- self.backgroundsurf = pygame.Surface((self.rect.width, \
- self.rect.height*3), SRCALPHA).convert_alpha()
+ self.caption = ""
def set_style(self, style):
"""
@@ -629,10 +663,8 @@
if self.style == "login":
# Which state do we need?
if self.ispressed:
- top = 68
- elif self.mousedown and not self.ispressed:
- top = 0
- elif self.hover:
+ top = 68
+ elif self.hover:# and not self.mousedown:
top = 34
else:
top = 0
@@ -678,16 +710,7 @@
self.submit()
self.ispressed = False
-
- def got_focus(self):
- pass
-
- def lost_focus(self):
- pass
- def keypress(self, ev):
- pass
-
def submit(self):
self.feedback.submit(self)
@@ -700,10 +723,9 @@
def __defaults__(self):
self.cangetfocus = False
+ self.font = None
self.caption = ""
-
- self.font = None
self.color = [0, 0, 0]
self.align = 0
@@ -739,21 +761,92 @@
pos = self.rect.width - textwidth
self.surf.blit(font, (pos, 0))
+
+
+class Link(Object):
+
+ def __defaults__(self):
+ self.cangetfocus = False
+ self.font = None
+ self.mousedown = False
+ self.ispressed = False
+
+ self.caption = ""
+ self.color = [0, 0, 0]
+ self.color_hover = [100, 100, 100]
+ self.color_click = [255, 255, 255]
+ self.align = 0
+
+ def set_font(self, font, size):
+ """
+ Change the font for this label
+ """
+
+ self.font = pygame.font.Font(real_path(*font), size)
+
+ self.update()
+
+ def render(self):
+ """
+ Render our surface, as requested from the all mighty Container
+ """
+
+ if self.font == None: return
+
+ self.surf.fill([0,0,0,0])
+
+ textwidth = self.font.size(self.caption)[0]
+
+ # Calculate position
+ if self.align == 0: # Left
+ pos = 0
+ elif self.align == 1: # Center
+ pos = (self.rect.width/2) - (textwidth/2)
+ elif self.align == 2: # Right
+ pos = self.rect.width - textwidth
+
+ # Which state do we need?
+ if self.ispressed:
+ color = self.color_click
+ self.font.set_underline(True)
+ elif self.hover and not self.mousedown:
+ color = self.color_hover
+ self.font.set_underline(True)
+ else:
+ color = self.color
+ self.font.set_underline(False)
+
+ font = self.font.render(self.caption, True, color)
+
+ self.surf.blit(font, (pos, 0))
- def hovering(self, value):
- pass
+ def hovering(self, state):
+ self.update()
def click(self, state, pos):
- pass
+ if state == 0:
+ self.mousedown = True
+ self.ispressed = 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
+ self.update()
- def got_focus(self):
- pass
+ elif state == 2:
+ self.mousedown = False
- def lost_focus(self):
- pass
+ self.update()
+
+ if self.ispressed:
+ self.submit()
+
+ self.ispressed = False
- def keypress(self, ev):
- pass
+ def submit(self):
+ self.feedback.submit(self)
class GuiError(Exception):
Modified: trunk/client/layout.py
===================================================================
--- trunk/client/layout.py 2010-08-25 21:07:48 UTC (rev 374)
+++ trunk/client/layout.py 2010-08-25 22:02:44 UTC (rev 375)
@@ -38,6 +38,7 @@
# Playground stuff
self.topbar = None
+ self.toppos = None
def event(self, ev):
if self.status == "playground":
@@ -69,33 +70,43 @@
self.selected = None
else:
self.selected = index
+
self.updatetop()
return True
def changestatus(self, status):
+ sh['timer'].stop("layout-topslide") # Just in case
+
login_list = ['connecting', 'login', 'logging in']
if status in login_list and self.status not in login_list:
# (Un)load all the data
- self.topbar = None
- if self.status == "playground":
- self.cleartop()
+ if self.topbar:
+ # Slide the topbar out
+ sh['timer'].start("layout-topslide", self.timer, time.time(), 0)
elif status == "playground":
self.topbar = load_image(True, "images", "topbar.png")
self.selected = None
self.hover = self.topbarcursor(pygame.mouse.get_pos())
- self.surf.blit(self.topbar, (0,0), (0,0,1000,TOPHEIGHT))
- self.updatetop()
+
+ self.toppos = 0
+
+ # Slide the topbar in
+ sh['timer'].start("layout-topslide", self.timer, time.time(), 1)
self.status = status
- def updatetop(self):
+ def updatetop(self, wholebar = False):
+ if wholebar:
+ self.surf.fill([0,0,0,0])
+ self.surf.blit(self.topbar, (0,self.toppos), (0,0,1000,TOPHEIGHT))
+
for i in range(TOPBUTTONS):
left = TOPLEFT + (TOPBUTTONWIDTH*i)
- rect = Rect(left, 0, TOPBUTTONWIDTH, TOPHEIGHT)
+ rect = Rect(left, self.toppos, TOPBUTTONWIDTH, TOPHEIGHT)
self.surf.fill([0,0,0,0], rect)
@@ -108,18 +119,45 @@
else:
rect2 = rect.move(0,0)
+ rect2.move_ip(0, -self.toppos)
self.surf.blit(self.topbar, rect, rect2)
sh['update']((0,0, 1000, 65))
- def cleartop(self):
- # Remove the top bar from view
- self.surf.fill([0,0,0,0])
- sh['update']((0,0, 1000, 65))
-
def topbarcursor(self, pos):
if pos[0] > TOPLEFT and pos[0] < (TOPBUTTONWIDTH*TOPBUTTONS+TOPLEFT) \
and pos[1] < 55:
return (pos[0]-TOPLEFT) / TOPBUTTONWIDTH
else:
return False
+
+
+ def timer(self, name, starttime, direction):
+ if name == "layout-topslide": # Slide the topbar!
+ length = 0.3
+ timeline = (time.time() - starttime) / length
+
+ # Timer has ended
+ if timeline > 1:
+ if direction == 0 : # Up
+ # Clear the bar
+ self.topbar = None
+ self.surf.fill([0,0,0,0])
+ sh['update']((0,0, 1000, 65))
+
+ elif direction == 1: # Down
+ toppos = 0
+ self.updatetop(True)
+
+ return True
+
+ # Calculate current position
+ if direction == 0: # Up
+ pos = 1-math.pow(timeline, 2)
+ pos = (pos - 1) * TOPHEIGHT
+ elif direction == 1: # Down
+ pos = 1 - math.pow(1-timeline, 2)
+ pos = (pos - 1) * TOPHEIGHT
+
+ self.toppos = pos
+ self.updatetop(True)
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-25 21:07:48 UTC (rev 374)
+++ trunk/client/playground.py 2010-08-25 22:02:44 UTC (rev 375)
@@ -124,6 +124,14 @@
login.caption = "Log in!"
login.set_style("login")
+ signup = self.logingui.add(gui.Link, "signup", (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()
@@ -177,6 +185,9 @@
sh['main'].changestatus("logging in")
sh['client'].login(usr, pwd)
+
+ elif obj.name == "signup":
+ print "signup!"
def mousedown(self, obj):
if obj.name == "usrlabel":
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-25 21:07:54
|
Revision: 374
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=374&view=rev
Author: BlueWolf_
Date: 2010-08-25 21:07:48 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
Starting with the GUI window graphics
Added Paths:
-----------
res/images/xcf/gui-window.xcf
Added: res/images/xcf/gui-window.xcf
===================================================================
(Binary files differ)
Property changes on: res/images/xcf/gui-window.xcf
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ch...@us...> - 2010-08-25 19:59:00
|
Revision: 373
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=373&view=rev
Author: chozone
Date: 2010-08-25 19:58:54 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
[server]
* Added list with files (name, url and checksum) that the client will receive upon logging in, so it knows where to download stuff.
[server-core]
* Sending/receiving custom messages
Modified Paths:
--------------
trunk/server/VPS.py
trunk/server/callback.py
trunk/server/core/callback.py
trunk/server/core/parser.py
trunk/server/core/server.py
trunk/server/database
trunk/server/functions.py
Added Paths:
-----------
trunk/server/filetable.py
Modified: trunk/server/VPS.py
===================================================================
--- trunk/server/VPS.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/VPS.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -18,6 +18,7 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import core
+
from functions import *
from callback import Callback
@@ -78,6 +79,8 @@
check_database()
+
+file_table.update_from_database()
server = core.Server(config, Callback())
server.start_server()
Modified: trunk/server/callback.py
===================================================================
--- trunk/server/callback.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/callback.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -36,6 +36,11 @@
def enters_vp(self, cid):
print " > %s: %s"%(cid, self.clients[cid]['con'].ip)
+
+ # Send locations and checksums of files to client app, so they can
+ # download what they need.
+ self.clients[cid]['con'].custom_send("filetable", file_table.table)
+
def leaves_vp(self, cid):
print " < %s: %s"%(cid, self.clients[cid]['con'].ip)
Modified: trunk/server/core/callback.py
===================================================================
--- trunk/server/core/callback.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/core/callback.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -138,6 +138,21 @@
in your own callback class.
"""
pass
+
+ def custom_received(self, cid, header, body):
+ """
+ This is called when the core received custom data from the app of a
+ client. This can be used to send custom (non-core) stuff, eg money.
+
+ header:
+ What type the body is. (string)
+ body:
+ The body of the message. (can basically be any kind of object)
+
+ This is a placeholder. If you want to catch this event, overwrite this
+ in your own callback class.
+ """
+ pass
def debug_crash(self, traceback):
Modified: trunk/server/core/parser.py
===================================================================
--- trunk/server/core/parser.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/core/parser.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -274,4 +274,16 @@
connection.send("error", {"reason":result})
else:
connection.send("signup")
+
+ def custom(self, cid, msg):
+ """
+ A custom command send from the client app.
+
+ * header:
+ The type of the message
+ * body:
+ The message itself
+ """
+
+ self.call.custom(cid, msg['header'], msg['body'])
\ No newline at end of file
Modified: trunk/server/core/server.py
===================================================================
--- trunk/server/core/server.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/core/server.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -377,6 +377,16 @@
del self.__clients[self.__cid]
+ def custom_send(self, data_header, data_body = {}):
+ """
+ Sends custom data 'data_body' of type 'data_header' directly to the
+ custom_received of the client app. This can be used to implement
+ non-core stuff like money.
+ """
+
+ self.send("custom", {"header": data_header, "body": data_body})
+
+
def send(self, data_header, data_body = {}):
"""
Sends `data_body` of type `data_header` to the client. It will
Modified: trunk/server/database
===================================================================
--- trunk/server/database 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/database 2010-08-25 19:58:54 UTC (rev 373)
@@ -16,5 +16,13 @@
`lastonline` timestamp NOT NULL,
`lastip` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM DEFAULT CHARSET=latin1;'''
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;'''
+files = '''CREATE TABLE IF NOT EXISTS `files` (
+ `id` int(11) NOT NULL auto_increment,
+ `filename` varchar(255) NOT NULL,
+ `url` varchar(255) NOT NULL,
+ `checksum` varchar(32) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;'''
+
Added: trunk/server/filetable.py
===================================================================
--- trunk/server/filetable.py (rev 0)
+++ trunk/server/filetable.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -0,0 +1,55 @@
+## This file is part of Virtual Playground
+## Copyright (c) 2009-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.
+
+class FileTable():
+ def __init__(self, db):
+ self.table = {}
+ self.db = db
+
+ def update_from_database(self):
+ self.table = {}
+
+ self.db.execute("SELECT `filename`, `url`, `checksum` FROM `files`")
+ table = self.db.fetchall()
+ for file in table:
+ fullurl = file['url'].strip('/')
+ fullurl = "%s/%s" % (fullurl, file['filename'])
+ self.table[file['filename']] = {'url': fullurl,
+ 'checksum': file['checksum']}
+
+ return self.table
+
+ def add(self, filename, url, checksum):
+ filename = filename.strip('/')
+ url = url.strip('/')
+ if filename in self.table.keys():
+ raise FileTableError("File already exists in table!")
+
+ db.execute("INSERT INTO `files` (`id`, `filename`, `url`, `checksum`) \
+ VALUES (NULL, %s, %s, %s)", (filename, url, checksum))
+
+ fullurl = "%s/%s" % (url, filename)
+ self.table[filename] = {'url': fullurl,
+ 'checksum': checksum}
+
+
+
+ class FileTableError(Exception):
+ def __init__(self, value):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)
\ No newline at end of file
Modified: trunk/server/functions.py
===================================================================
--- trunk/server/functions.py 2010-08-25 12:45:22 UTC (rev 372)
+++ trunk/server/functions.py 2010-08-25 19:58:54 UTC (rev 373)
@@ -19,6 +19,7 @@
from getpass import getpass
import database
+from filetable import FileTable
try: from configobj import ConfigObj
except: sys.exit("ERROR: You need the configobj-module for this to work!")
@@ -67,6 +68,8 @@
config['database']['password'])
print "Connected to database `%s` on `%s`" % (config['database']['database'],
config['database']['host'])
+
+file_table = FileTable(db)
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-25 12:45:28
|
Revision: 372
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=372&view=rev
Author: BlueWolf_
Date: 2010-08-25 12:45:22 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
Note to myself: Don't program when feeling sleepy
Modified Paths:
--------------
trunk/client/core/callback.py
trunk/client/core/client.py
trunk/client/core/parser.py
trunk/client/gui.py
Modified: trunk/client/core/callback.py
===================================================================
--- trunk/client/core/callback.py 2010-08-25 11:45:11 UTC (rev 371)
+++ trunk/client/core/callback.py 2010-08-25 12:45:22 UTC (rev 372)
@@ -101,10 +101,10 @@
"""
pass
- def custom_receive(self, header, body):
+ def custom_received(self, header, body):
"""
- This is when custom data from the server's app has been send. This can
- be used to send custom stuff like money e.d
+ This is when custom data from the server' app has been sent. This can be
+ used to send custom stuff like money
header:
What type the body is (string)
Modified: trunk/client/core/client.py
===================================================================
--- trunk/client/core/client.py 2010-08-25 11:45:11 UTC (rev 371)
+++ trunk/client/core/client.py 2010-08-25 12:45:22 UTC (rev 372)
@@ -292,9 +292,9 @@
def custom_send(self, data_header, data_body = {}):
"""
- Sends custom data 'data_body' of type 'data_header' directly to the
- others custom_receive of the server's app. This can be used to send
- money and other custom events.
+ Sends custom data 'data_body' of type 'data_header' directly to the the
+ custom_receive of the server' app. This can be used to send money and
+ other custom events.
"""
self.send("custom", {"header": data_header, "body": data_body})
Modified: trunk/client/core/parser.py
===================================================================
--- trunk/client/core/parser.py 2010-08-25 11:45:11 UTC (rev 371)
+++ trunk/client/core/parser.py 2010-08-25 12:45:22 UTC (rev 372)
@@ -157,7 +157,7 @@
def custom(self, msg):
"""
- A custom command send from the server' app.
+ A custom command sent from the server' app.
* header:
The type of the message
@@ -165,5 +165,5 @@
The message itself
"""
- self.call.custom(msg['header'], msg['body'])
+ self.call.custom_received(msg['header'], msg['body'])
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-25 11:45:11 UTC (rev 371)
+++ trunk/client/gui.py 2010-08-25 12:45:22 UTC (rev 372)
@@ -520,7 +520,6 @@
if i == -1: i = 0
self.cursorpos = i
-
if self.focus:
self.update()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-25 11:45:17
|
Revision: 371
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=371&view=rev
Author: BlueWolf_
Date: 2010-08-25 11:45:11 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
Forgot the password special case. It now uses *'s instead of the characters to calculate the position
Modified Paths:
--------------
trunk/client/gui.py
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-25 11:42:12 UTC (rev 370)
+++ trunk/client/gui.py 2010-08-25 11:45:11 UTC (rev 371)
@@ -500,15 +500,19 @@
def click(self, state, pos):
if state == 0:
- # Calculate position based on pos
+
+ # Calculate position based on the clicked position
+ inp = self.input
+ if self.type == "password":
+ inp = "*"*len(self.input)
+
actualpos = pos[0]-6-self.textpos
-
lastsize = 0
- for i in range(len(self.input)+1):
- textsize = self.font.size(self.input[:i])[0]
+ for i in range(len(inp)+1):
+ textsize = self.font.size(inp[:i])[0]
if textsize > actualpos:
# Which direction is closer, left or right?
- if textsize-actualpos > actualpos-lastsize:
+ if textsize-actualpos > actualpos-lastsize: # Left
i = i -1
break
lastsize = textsize
@@ -516,6 +520,7 @@
if i == -1: i = 0
self.cursorpos = i
+
if self.focus:
self.update()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-25 11:42:19
|
Revision: 370
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=370&view=rev
Author: BlueWolf_
Date: 2010-08-25 11:42:12 +0000 (Wed, 25 Aug 2010)
Log Message:
-----------
Added labels and (correctly) clickable textboxes!
Modified Paths:
--------------
trunk/client/functions.py
trunk/client/gui.py
trunk/client/playground.py
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-08-24 23:40:51 UTC (rev 369)
+++ trunk/client/functions.py 2010-08-25 11:42:12 UTC (rev 370)
@@ -56,4 +56,3 @@
# GUI needs the functions again. That's why it has to be imported after all
# functions have been defined
import gui
-gui = gui.Container
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-24 23:40:51 UTC (rev 369)
+++ trunk/client/gui.py 2010-08-25 11:42:12 UTC (rev 370)
@@ -19,6 +19,17 @@
import random
+class Feedback():
+ def keypress(self, obj, ev):
+ pass
+
+ def submit(self, obj):
+ pass
+
+ def mousedown(self, obj):
+ pass
+
+
class Container(): # A modified version of Object
def __init__(self, update, feedback):
@@ -47,18 +58,11 @@
raise KeyError(key)
- def add(self, objname, name, rect):
+ def add(self, Obj, name, rect):
"""
Append a child to this object
"""
- if objname == "textbox":
- Obj = Textbox
- elif objname == "button":
- Obj = Button
- else:
- raise GuiError("Object '%s' has not been found" % objname)
-
obj = Obj(name, rect, self, self, self.feedback)
self.children.append(obj)
@@ -197,6 +201,7 @@
# Tell this object
hover.focus = True
hover.got_focus()
+ self.feedback.mousedown(hover)
return True
@@ -285,18 +290,11 @@
raise KeyError(key)
- def add(self, objname, name, rect):
+ def add(self, Obj, name, rect):
"""
Append a child to this object
"""
- if objname == "textbox":
- Obj = Textbox
- elif objname == "button":
- Obj = Button
- else:
- raise GuiError("Object '%s' has not been found" % objname)
-
obj = Obj(name, rect, self.main_parent, self, self.feedback)
self.children.append(obj)
@@ -390,13 +388,15 @@
self.style = None
self.type = "text"
+ self.textpos = None # Position of the text currently
+
self.font = None
self.backgroundsurf = pygame.Surface((self.rect.width, \
self.rect.height*2), SRCALPHA).convert_alpha()
def set_style(self, style):
"""
- Change the stle for this textbox
+ Change the style for this textbox
Possible styles:
* login
"""
@@ -486,7 +486,9 @@
pos = -textwidth + truewidth - 2
else: # Cursor is in the center
pos = -cursorpos + (truewidth/2)
-
+
+ self.textpos = pos
+
self.surf.blit(text, (6, 10), (-pos, 0, truewidth, 17))
# Blit cursor
@@ -498,9 +500,22 @@
def click(self, state, pos):
if state == 0:
- # [TODO] Calculate position based on pos
- # self.cursorpos = ...
+ # Calculate position based on pos
+ actualpos = pos[0]-6-self.textpos
+ lastsize = 0
+ for i in range(len(self.input)+1):
+ textsize = self.font.size(self.input[:i])[0]
+ if textsize > actualpos:
+ # Which direction is closer, left or right?
+ if textsize-actualpos > actualpos-lastsize:
+ i = i -1
+ break
+ lastsize = textsize
+
+ if i == -1: i = 0
+ self.cursorpos = i
+
if self.focus:
self.update()
@@ -574,7 +589,7 @@
def set_style(self, style):
"""
- Change the stle for this textbox
+ Change the style for this textbox
Possible styles:
* login
"""
@@ -677,5 +692,65 @@
self.update()
+class Label(Object):
+
+ def __defaults__(self):
+ self.cangetfocus = False
+
+ self.caption = ""
+
+ self.font = None
+ self.color = [0, 0, 0]
+ self.align = 0
+
+ def set_font(self, font, size):
+ """
+ Change the font for this label
+ """
+
+ self.font = pygame.font.Font(real_path(*font), size)
+
+ self.update()
+
+ def render(self):
+ """
+ Render our surface, as requested from the all mighty Container
+ """
+
+ # [TODO] Make enters work as it should
+
+ if self.font == None: return
+
+ self.surf.fill([0,0,0,0])
+
+ textwidth = self.font.size(self.caption)[0]
+ font = self.font.render(self.caption, True, self.color)
+
+ # Calculate position
+ if self.align == 0: # Left
+ pos = 0
+ elif self.align == 1: # Center
+ pos = (self.rect.width/2) - (textwidth/2)
+ elif self.align == 2: # Right
+ pos = self.rect.width - textwidth
+
+ self.surf.blit(font, (pos, 0))
+
+ def hovering(self, value):
+ pass
+
+ def click(self, state, pos):
+ pass
+
+ def got_focus(self):
+ pass
+
+ def lost_focus(self):
+ pass
+
+ def keypress(self, ev):
+ pass
+
+
class GuiError(Exception):
pass
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-24 23:40:51 UTC (rev 369)
+++ trunk/client/playground.py 2010-08-25 11:42:12 UTC (rev 370)
@@ -95,21 +95,36 @@
self.surf.blit(self.loginbox, (292,256))
# Create login-field
- self.logingui = gui(self.logingui_draw, LoginFeedback(self))
+ self.logingui = gui.Container(self.logingui_draw, \
+ LoginFeedback(self))
self.logingui.can_lose_focus = False
- username = self.logingui.add("textbox", "usr", (345, 279, 310, 37))
- username.set_style("login")
+ 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)
- password = self.logingui.add("textbox", "pwd", (345, 340, 310, 37))
- password.set_style("login")
- password.set_type("password")
+ usr = self.logingui.add(gui.Textbox, "usr", (345, 285, 310, 37))
+ usr.set_style("login")
- login = self.logingui.add("button", "login", (425, 398, 151, 34))
+ 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, "pwd", (345, 350, 310, 37))
+ pwd.set_style("login")
+ pwd.set_type("password")
+
+ login = self.logingui.add(gui.Button, "login", (425, 398, 151, 34))
login.caption = "Log in!"
login.set_style("login")
- self.logingui.give_focus(username)
+ self.logingui.give_focus(usr)
self.logingui.unfreeze()
@@ -132,7 +147,7 @@
sh['update'](rect)
-class LoginFeedback():
+class LoginFeedback(gui.Feedback):
def __init__(self, parent):
self.parent = parent
@@ -162,3 +177,10 @@
sh['main'].changestatus("logging in")
sh['client'].login(usr, pwd)
+
+ def mousedown(self, obj):
+ if obj.name == "usrlabel":
+ self.parent.logingui.give_focus('usr')
+
+ elif obj.name == "pwdlabel":
+ self.parent.logingui.give_focus('pwd')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-24 23:40:57
|
Revision: 369
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=369&view=rev
Author: BlueWolf_
Date: 2010-08-24 23:40:51 +0000 (Tue, 24 Aug 2010)
Log Message:
-----------
Added the possibility for the client to send and receive custom commands to app directly, making it easier to send stuff like money
Modified Paths:
--------------
trunk/client/core/callback.py
trunk/client/core/client.py
trunk/client/core/parser.py
Modified: trunk/client/core/callback.py
===================================================================
--- trunk/client/core/callback.py 2010-08-23 21:59:40 UTC (rev 368)
+++ trunk/client/core/callback.py 2010-08-24 23:40:51 UTC (rev 369)
@@ -101,6 +101,20 @@
"""
pass
+ def custom_receive(self, header, body):
+ """
+ This is when custom data from the server's app has been send. This can
+ be used to send custom stuff like money e.d
+
+ header:
+ What type the body is (string)
+ body:
+ The body of the message (can basically be every kind of object)
+
+ This is a placeholder. If you want to catch this event, overwrite this
+ in your own callback
+ """
+
def logged_in(self, username, cid, owner):
"""
Called when we are logged in.
Modified: trunk/client/core/client.py
===================================================================
--- trunk/client/core/client.py 2010-08-23 21:59:40 UTC (rev 368)
+++ trunk/client/core/client.py 2010-08-24 23:40:51 UTC (rev 369)
@@ -288,6 +288,16 @@
try:
self.__sock.send(data + chr(1))
except: pass
+
+
+ def custom_send(self, data_header, data_body = {}):
+ """
+ Sends custom data 'data_body' of type 'data_header' directly to the
+ others custom_receive of the server's app. This can be used to send
+ money and other custom events.
+ """
+
+ self.send("custom", {"header": data_header, "body": data_body})
def close(self, reason = "manual"):
Modified: trunk/client/core/parser.py
===================================================================
--- trunk/client/core/parser.py 2010-08-23 21:59:40 UTC (rev 368)
+++ trunk/client/core/parser.py 2010-08-24 23:40:51 UTC (rev 369)
@@ -105,7 +105,7 @@
def useronline(self, msg):
"""
- Called after a user (or bot) has signed on.
+ Called after an user (or bot) has signed on.
* cid - The unique ID for this connection
* user - The username
* app - [Appname, Appversion]
@@ -123,7 +123,7 @@
def useroffline(self, msg):
"""
- Some user has gone offline
+ An user has gone offline
* cid - The connection-id for this client
"""
@@ -154,4 +154,16 @@
self.call.failed_logging_in("login blocked")
elif msg['reason'] == "duplicate user":
self.call.failed_logging_in("duplicate user")
+
+ def custom(self, msg):
+ """
+ A custom command send from the server' app.
+ * header:
+ The type of the message
+ * body:
+ The message itself
+ """
+
+ self.call.custom(msg['header'], msg['body'])
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-23 21:59:47
|
Revision: 368
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=368&view=rev
Author: BlueWolf_
Date: 2010-08-23 21:59:40 +0000 (Mon, 23 Aug 2010)
Log Message:
-----------
Now handles logging in properly. Although it won't give any reason for disconnects and failed logins yet
Modified Paths:
--------------
trunk/client/VP.py
trunk/client/functions.py
trunk/client/gui.py
trunk/client/layout.py
trunk/client/playground.py
Modified: trunk/client/VP.py
===================================================================
--- trunk/client/VP.py 2010-08-19 20:13:11 UTC (rev 367)
+++ trunk/client/VP.py 2010-08-23 21:59:40 UTC (rev 368)
@@ -65,7 +65,7 @@
Callback())
self.changestatus("connecting")
- sh['client'].connect('localhost', 6653)
+ sh['client'].connect(*SERVER)
# Wait for all the events to come
@@ -172,6 +172,31 @@
def logged_in(self, username, cid, owner):
sh['main'].changestatus("playground")
+
+ def failed_logging_in(self, reason):
+ # [TODO] Send the reason in some way
+ sh['main'].changestatus("login")
+
+ def disconnected(self, reason):
+ if reason == "manual": return
+
+ # [TODO] Send the reason in some way
+ if reason in ["closed", "gone offline"]:
+ # Reconnect while logging in
+ sh['main'].changestatus("connecting")
+ return True
+
+ elif reason in ["duplicate", "crash"]:
+ # Reconnecting while not logging in
+ sh['main'].changestatus("connecting")
+ sh['client'].connect(*SERVER)
+
+ else:
+ # Not doing anything at all
+ # [TODO] Show popup or something, without reconnecting?
+ sh['main'].changestatus("connecting")
+
+
if __name__ == "__main__": Main()
Modified: trunk/client/functions.py
===================================================================
--- trunk/client/functions.py 2010-08-19 20:13:11 UTC (rev 367)
+++ trunk/client/functions.py 2010-08-23 21:59:40 UTC (rev 368)
@@ -22,6 +22,8 @@
VERSION = "0.0.1"
+SERVER = ("localhost", 6653)
+
# This will be used to [sh]are all variables, functions and classes across the
# code
sh = {}
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-19 20:13:11 UTC (rev 367)
+++ trunk/client/gui.py 2010-08-23 21:59:40 UTC (rev 368)
@@ -21,9 +21,10 @@
class Container(): # A modified version of Object
- def __init__(self, update):
+ def __init__(self, update, feedback):
self.rect = Rect(0, 0, 1000, 700)
self.parent_update = update
+ self.feedback = feedback
self.frozen = True # Don't update until everything has been
# loaded
@@ -58,7 +59,7 @@
else:
raise GuiError("Object '%s' has not been found" % objname)
- obj = Obj(name, rect, self, self)
+ obj = Obj(name, rect, self, self, self.feedback)
self.children.append(obj)
return obj
@@ -256,11 +257,12 @@
class Object():
- def __init__(self, name, rect, main_parent, parent):
+ def __init__(self, name, rect, main_parent, parent, feedback):
self.name = name
self.rect = Rect(rect)
self.main_parent = main_parent
self.parent = parent
+ self.feedback = feedback
self.needs_update = False
self.frozen = True # Don't update until everything has been
# loaded
@@ -269,9 +271,6 @@
self.hover = False
self.focus = False
- # Callbacks
- self.cb_keypress = None
-
# Create a surface where an object blits itself onto
self.surf = pygame.Surface((self.rect.width, self.rect.height), \
SRCALPHA).convert_alpha()
@@ -298,7 +297,7 @@
else:
raise GuiError("Object '%s' has not been found" % objname)
- obj = Obj(name, rect, self.main_parent, self)
+ obj = Obj(name, rect, self.main_parent, self, self.feedback)
self.children.append(obj)
return obj
@@ -555,7 +554,7 @@
self.update()
- if self.cb_keypress: self.cb_keypress(self, ev)
+ self.feedback.keypress(self, ev)
class Button(Object):
@@ -590,6 +589,10 @@
# Load the background images
self.backgroundsurf = load_image(True, "images", "gui", "button_login.png")
+ # Load the font
+ self.font = pygame.font.Font(real_path("fonts", \
+ "DejaVuSans-Bold.ttf"), 15)
+
else:
raise GuiError("Style '%s' has not been found" % style)
@@ -606,18 +609,31 @@
if self.style == "login":
# Which state do we need?
- if self.mousedown:
- if self.ispressed:
+ if self.ispressed:
top = 68
- else:
- top = 0
+ elif self.mousedown and not self.ispressed:
+ top = 0
elif self.hover:
top = 34
else:
top = 0
+ # Blit the background
self.surf.blit(self.backgroundsurf, (0,0), \
(0, top, self.rect.width, self.rect.height))
+
+ # Blit the text
+ if top == 0:
+ textcolor = [141, 56, 0]
+ elif top == 34:
+ textcolor = [214, 126, 68]
+ elif top == 68:
+ textcolor = [147, 81, 37]
+ textwidth = self.font.size(self.caption)[0]
+ font = self.font.render(self.caption, True, textcolor)
+ pos = ((self.rect.width/2) - (textwidth/2), 8)
+ self.surf.blit(font, pos)
+
def hovering(self, value):
self.update()
@@ -636,7 +652,13 @@
elif state == 2:
self.mousedown = False
+
self.update()
+
+ if self.ispressed:
+ self.submit()
+
+ self.ispressed = False
def got_focus(self):
pass
@@ -646,6 +668,13 @@
def keypress(self, ev):
pass
+
+ def submit(self):
+ self.feedback.submit(self)
+
+ def manualpush(self, state):
+ self.ispressed = state
+ self.update()
class GuiError(Exception):
Modified: trunk/client/layout.py
===================================================================
--- trunk/client/layout.py 2010-08-19 20:13:11 UTC (rev 367)
+++ trunk/client/layout.py 2010-08-23 21:59:40 UTC (rev 368)
@@ -78,6 +78,9 @@
if status in login_list and self.status not in login_list:
# (Un)load all the data
self.topbar = None
+
+ if self.status == "playground":
+ self.cleartop()
elif status == "playground":
self.topbar = load_image(True, "images", "topbar.png")
@@ -109,6 +112,11 @@
sh['update']((0,0, 1000, 65))
+ def cleartop(self):
+ # Remove the top bar from view
+ self.surf.fill([0,0,0,0])
+ sh['update']((0,0, 1000, 65))
+
def topbarcursor(self, pos):
if pos[0] > TOPLEFT and pos[0] < (TOPBUTTONWIDTH*TOPBUTTONS+TOPLEFT) \
and pos[1] < 55:
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-19 20:13:11 UTC (rev 367)
+++ trunk/client/playground.py 2010-08-23 21:59:40 UTC (rev 368)
@@ -38,12 +38,7 @@
if self.status == "login":
# Some temporary debug stuff
- if ev.type == KEYDOWN and ev.key == K_F2:
- # Fake login
- self.drawlogin("logging in")
- sh['client'].login("test123", sha1("test123").hexdigest())
-
- elif ev.type == KEYDOWN and ev.key == K_F1:
+ if ev.type == KEYDOWN and ev.key == K_F1:
# Fake signup
sh['client'].signup("test123", sha1("test123").hexdigest(),
{
@@ -64,6 +59,7 @@
self.loginbox = load_image(True, "images", "loginbox.png")
self.loginfont = pygame.font.Font(real_path("fonts", \
"DejaVuSans.ttf"), 35)
+ self.loginfeedback = LoginFeedback(self)
elif status == "playground":
# (Un)load all the data for the playground
@@ -99,19 +95,18 @@
self.surf.blit(self.loginbox, (292,256))
# Create login-field
- self.logingui = gui(self.logingui_draw)
+ self.logingui = gui(self.logingui_draw, LoginFeedback(self))
self.logingui.can_lose_focus = False
username = self.logingui.add("textbox", "usr", (345, 279, 310, 37))
username.set_style("login")
- username.cb_keypress = self.logingui_keypress
password = self.logingui.add("textbox", "pwd", (345, 340, 310, 37))
password.set_style("login")
password.set_type("password")
- password.cb_keypress = self.logingui_keypress
login = self.logingui.add("button", "login", (425, 398, 151, 34))
+ login.caption = "Log in!"
login.set_style("login")
self.logingui.give_focus(username)
@@ -128,14 +123,42 @@
def logingui_draw(self, rect):
print "GUIupdate", rect
+ if self.logingui == None: return
+
self.surf.blit(self.loginbg, rect, rect)
self.surf.blit(self.loginbox, (292, 256))
self.surf.blit(self.logingui.surf, rect, rect)
sh['update'](rect)
+
+
+class LoginFeedback():
+ def __init__(self, parent):
+ self.parent = parent
+
+ def keypress(self, obj, ev):
+ if obj.name == "usr":
+ # Using the enter key in the username field
+ if ev.type == KEYUP and ev.key == K_RETURN:
+ self.parent.logingui.give_focus("pwd")
+
+ elif obj.name == "pwd":
+ # Using the enter key in the password field
+ if ev.type == KEYDOWN and ev.key == K_RETURN:
+ self.parent.logingui['login'].manualpush(True)
+
+ elif ev.type == KEYUP and ev.key == K_RETURN:
+ self.parent.logingui['login'].manualpush(False)
+ self.parent.logingui['login'].submit()
+
- def logingui_keypress(self, obj, ev):
- if ev.type == KEYDOWN:
- if ev.unicode == "\r":
- if obj.name == "pwd":
- self.logingui.give_focus("usr") # [TODO] Not working?
+ def submit(self, obj):
+ # Clicking the login button
+ if obj.name == "login":
+ usr = self.parent.logingui['usr'].input
+ pwd = sha1(self.parent.logingui['pwd'].input).hexdigest()
+
+ self.parent.logingui = None
+ sh['main'].changestatus("logging in")
+
+ sh['client'].login(usr, pwd)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-19 20:13:17
|
Revision: 367
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=367&view=rev
Author: BlueWolf_
Date: 2010-08-19 20:13:11 +0000 (Thu, 19 Aug 2010)
Log Message:
-----------
Added the 2 other states of the button to the image
Modified Paths:
--------------
res/images/xcf/login-button.xcf
Modified: res/images/xcf/login-button.xcf
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <Blu...@us...> - 2010-08-19 20:12:43
|
Revision: 366
http://virtplayground.svn.sourceforge.net/virtplayground/?rev=366&view=rev
Author: BlueWolf_
Date: 2010-08-19 20:12:36 +0000 (Thu, 19 Aug 2010)
Log Message:
-----------
Added a button. Sort off. Not finished but looks like it's working so far
Modified Paths:
--------------
trunk/client/gui.py
trunk/client/playground.py
Added Paths:
-----------
trunk/client/images/gui/button_login.png
Modified: trunk/client/gui.py
===================================================================
--- trunk/client/gui.py 2010-08-09 17:30:56 UTC (rev 365)
+++ trunk/client/gui.py 2010-08-19 20:12:36 UTC (rev 366)
@@ -210,10 +210,13 @@
# Release mousebutton after we've clicked on an object
pos = (ev.pos[0] - self.mousedown[0][0], \
ev.pos[1] - self.mousedown[0][1])
- self.mousedown[1].click(2, pos)
+
+ obj = self.mousedown[1]
+ obj.frozen = True
+ obj.click(2, pos)
self.mousedown = None
- self.update_mouse()
+ obj.unfreeze()
return True
@@ -235,9 +238,16 @@
return None, None
def focus_next(self, current):
- pos = self.children.index(current) + 1
+ startpos = self.children.index(current)
+ pos = startpos + 1
if pos == len(self.children): pos = 0
+ while self.children[pos].cangetfocus == False:
+ pos += 1
+ if pos == len(self.children): pos = 0
+
+ if pos == startpos: return
+
self.give_focus(self.children[pos])
@@ -300,18 +310,16 @@
# Send a message to our parent, telling them this rect needs to be
# updated
-
self.needs_update = True
if self.frozen: return
if rect == None:
- rect = self.rect.move(0, 0)
-
- else:
- # We need to calculate our relative position
- rect.move_ip(self.rect.left, self.rect.top)
+ rect = Rect(0, 0, self.rect.width, self.rect.height)
+ # We need to calculate our relative position
+ rect = rect.move(self.rect.left, self.rect.top)
+
self.parent.update(rect)
def blit(self, rect, surf, onto):
@@ -345,7 +353,7 @@
if isparent:
self.main_parent.update_mouse()
self.frozen = False
- self.update(self.rect)
+ self.update()
else:
self.frozen = False
@@ -376,6 +384,8 @@
class Textbox(Object):
def __defaults__(self):
+ self.cangetfocus = True
+
self.input = ""
self.cursorpos = 0
self.style = None
@@ -511,7 +521,6 @@
self.cursorpos = 0
else:
- print pygame.key.name(ev.key)
if ev.key == K_LEFT: # Cursorpos change
if self.cursorpos > 0: self.cursorpos -= 1
@@ -547,7 +556,97 @@
self.update()
if self.cb_keypress: self.cb_keypress(self, ev)
-
+
+class Button(Object):
+
+ def __defaults__(self):
+ self.cangetfocus = False
+
+ self.caption = ""
+ self.style = None
+
+ self.mousedown = False
+ self.ispressed = False
+
+ self.font = None
+ self.backgroundsurf = pygame.Surface((self.rect.width, \
+ self.rect.height*3), SRCALPHA).convert_alpha()
+
+ def set_style(self, style):
+ """
+ Change the stle for this textbox
+ Possible styles:
+ * login
+ """
+ if style == "login":
+
+ # Check the requirements
+ if self.rect.width != 151:
+ raise GuiError("Width should be 151")
+ if self.rect.height != 34:
+ raise GuiError("Height should be 34")
+
+ # Load the background images
+ self.backgroundsurf = load_image(True, "images", "gui", "button_login.png")
+
+ else:
+ raise GuiError("Style '%s' has not been found" % style)
+
+ self.style = style
+ self.update()
+
+ def render(self):
+ """
+ Render our surface, as requested from the all mighty Container
+ """
+ if self.backgroundsurf == None: return
+
+ self.surf.fill([0,0,0,0])
+
+ if self.style == "login":
+ # Which state do we need?
+ if self.mousedown:
+ if self.ispressed:
+ top = 68
+ else:
+ top = 0
+ elif self.hover:
+ top = 34
+ else:
+ top = 0
+
+ self.surf.blit(self.backgroundsurf, (0,0), \
+ (0, top, self.rect.width, self.rect.height))
+
+ def hovering(self, value):
+ self.update()
+
+ def click(self, state, pos):
+ if state == 0:
+ self.mousedown = True
+ self.ispressed = 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
+ self.update()
+
+ elif state == 2:
+ self.mousedown = False
+ self.update()
+
+ def got_focus(self):
+ pass
+
+ def lost_focus(self):
+ pass
+
+ def keypress(self, ev):
+ pass
+
+
class GuiError(Exception):
pass
Added: trunk/client/images/gui/button_login.png
===================================================================
(Binary files differ)
Property changes on: trunk/client/images/gui/button_login.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: trunk/client/playground.py
===================================================================
--- trunk/client/playground.py 2010-08-09 17:30:56 UTC (rev 365)
+++ trunk/client/playground.py 2010-08-19 20:12:36 UTC (rev 366)
@@ -111,7 +111,9 @@
password.set_type("password")
password.cb_keypress = self.logingui_keypress
- #login = gui.Button("login", (0, 100, 417, 50))
+ login = self.logingui.add("button", "login", (425, 398, 151, 34))
+ login.set_style("login")
+
self.logingui.give_focus(username)
self.logingui.unfreeze()
@@ -135,5 +137,5 @@
def logingui_keypress(self, obj, ev):
if ev.type == KEYDOWN:
if ev.unicode == "\r":
- if obj.name == "usr":
- self.logingui.give_focus("pwd")
+ if obj.name == "pwd":
+ self.logingui.give_focus("usr") # [TODO] Not working?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|