diff options
author | doug <doug@printer-g589.(none)> | 2009-08-07 02:48:33 (GMT) |
---|---|---|
committer | doug <doug@printer-g589.(none)> | 2009-08-07 02:48:33 (GMT) |
commit | f826dda2fd07a572b6b4ec7c8a65562f78502131 (patch) | |
tree | b958eeb05c19a3db2512d0d142c2e6a6e00441f6 | |
parent | 4e8a7e0dd2b444a1fdd5976f4ec91be8f9459f3f (diff) |
Real commit this time... Level Options menu now displays stubbed stats. No handling of input for that menu yet.
-rw-r--r-- | docs/diagrams/TextMenus.dia | bin | 5147 -> 5110 bytes | |||
-rw-r--r-- | docs/examples/config.xml | 7 | ||||
-rw-r--r-- | src/setup/config.py | 29 | ||||
-rw-r--r-- | src/setup/menus.py | 132 | ||||
-rw-r--r-- | src/setup/profile.py | 52 |
5 files changed, 194 insertions, 26 deletions
diff --git a/docs/diagrams/TextMenus.dia b/docs/diagrams/TextMenus.dia Binary files differindex b08cd5d..81d5181 100644 --- a/docs/diagrams/TextMenus.dia +++ b/docs/diagrams/TextMenus.dia diff --git a/docs/examples/config.xml b/docs/examples/config.xml index 7867322..8178cd6 100644 --- a/docs/examples/config.xml +++ b/docs/examples/config.xml @@ -18,7 +18,12 @@ <!-- --> <settings> - + <!-- + model-store + * "enabled='true'" for storing a copy of the model on this client and validating all use input before sending to the server + * "enabled='false'" for not storing a model copy in-order to save memory, but at the cost of sending every use command to the server + --> + <model-store enabled='true'/> </settings> </config> </muthris> diff --git a/src/setup/config.py b/src/setup/config.py index 696c039..e394665 100644 --- a/src/setup/config.py +++ b/src/setup/config.py @@ -29,9 +29,9 @@ def getLevelDescriptors(): # convert them all into objects levels = [] for file in files: - level = Level(path) + level = Level(file) levels.append(level) - return files + return levels def getProfiles(): '''Returns a list of Profiles representing all known profiles''' @@ -41,10 +41,23 @@ def getProfiles(): # convert the files into Profile objects profiles = [] for file in files: - profile = Profile(file) + profile = Profile(path=file) profiles.append(profile) return profiles +def getProfile(name): + ''' ''' + + # search through the know profiles for the one with the given name + profiles = getProfiles() + for profile in profiles: + log.debug('Looking for a profile named: ' + name + ' and found: ' + profile.getName()) + if profile.getName() == name: + return profile + + # the wanted profile doesn't exist, so create a new one + return createProfile(name) + # ----------------------------------------------------------------------------- # File related methods # ----------------------------------------------------------------------------- @@ -87,6 +100,16 @@ def findFiles(folders, extension): return files # ----------------------------------------------------------------------------- +# +# ----------------------------------------------------------------------------- + +def createProfile(profileName): + ''' ''' + + log.debug('Creating a Profile with the name: ' + profileName) + return Profile(name=profileName) + +# ----------------------------------------------------------------------------- # Folder related methods # ----------------------------------------------------------------------------- diff --git a/src/setup/menus.py b/src/setup/menus.py index e229277..2ac048d 100644 --- a/src/setup/menus.py +++ b/src/setup/menus.py @@ -22,10 +22,11 @@ class MenuData(object): ''' Constructor ''' - self.levels = [] - self.profiles = [] - self.profile = None - self.screen = None + self.levels = [] # all the known levels + self.profiles = [] # all the known profiles + self.profile = None # the player's current profile + self.screen = None # the curses display + self.level = None # the level the player wants to play # ----------------------------------------------------------------------------- @@ -68,15 +69,17 @@ def mainMenu(data): # refresh the screen data.screen.refresh() + ## No longer matters as we are redrawing the entire screen after every key press # store the current cursor location, so we can keep it here when the user types - y, x = data.screen.getyx() - log.debug('Y,X are at: ' + str(y) + ' ' + str(x)) + #y, x = data.screen.getyx() + #log.debug('Y,X are at: ' + str(y) + ' ' + str(x)) # wait for user input c = data.screen.getch() + ## No longer matters as we are redrawing the entire screen after every key press # keep the cursor in the same spot - data.screen.move(y, x) + #data.screen.move(y, x) # process input if c == ord('1'): playGameMenu(data) @@ -130,21 +133,120 @@ def changePlayerMenu(data): def playGameMenu(data): ''' ''' - # check for required vars - # clear the screen and display the title - # display the menu - # refresh the screen - # wait for input - # process input + # create a list of levels + if (data.levels == None) | (data.levels == []): + data.levels = config.getLevelDescriptors() - pass + # configure the screen for our needs + data.screen.erase() + curses.cbreak() + curses.echo() + + # display the title + title = strs.Title_PlayGame + strs.Title_Seperator + (data.profile or '[No Player]') + displayTitle(data.screen, title) + + # display the menu options + lines = ['', 'Levels:'] + for index, level in enumerate(data.levels): + lines.append(' ' + str(index) + ') ' + level.getName() ) + displayOptions(data.screen, lines, 1) + + # display the input prompt + minLevels = 1 + offset = len(lines) + 1 + if len(data.levels) < minLevels: + lines = ('', 'No known levels. Press anything to continue...'), + curses.nocbreak() + else: + lines = ('','Enter the number of the level to play: ') + displayPrompt(data.screen, lines, offset) + + # refresh and wait for valid user input + data.screen.refresh() + input = data.screen.getstr() + + # process input + if len(data.levels) < minLevels: + mainMenu(data) + return + input = int(input) + data.level = data.levels[input] + + #move on to configuring the selected level + levelOptionsMenu(data) def levelOptionsMenu(data): ''' ''' - pass + + # make sure there is a level + if (data.level == None) | (data.level == ''): + log.error('Made it to the levelOptionsMenu() without a selected level! This should not be possible.') + return + + # get the player's stats for this level + stats = [] + if data.profile == None: + pass + else: + stats.append('') + stats.append('Your Stats:') + + # get the max score, max duration, and last time played + profile = config.getProfile(data.profile) + stats.append('Max Score - ' + str(profile.getMaxScore(data.level))) + stats.append('Max Duration - ' + str(profile.getMaxDuration(data.level))) + stats.append('Last Played - ' + profile.getLastTimePlayed(data.level)) + stats.append('') + + # configure the screen for our needs + data.screen.erase() + curses.cbreak() + curses.echo() + + # display the title + title = data.level.getName() + strs.Title_Seperator + (data.profile or '[No Player]') + displayTitle(data.screen, title) + + # display the level's description, the player's stats, and the level's options + lines = ['', data.level.getDescription()] + lines.extend(stats) + lines.append('-------------------- -------------------- --------------------') + lines.extend(['','Options:', + '1) Skill level - Easy - Stubbed', + '2) Number of players - 1 - Stubbed', + '', + 'p) Play now', + 's) Spectate - Stubbed', + 'm) Main Menu']) + displayOptions(data.screen, lines, 1) + #displayOptions(data.screen, ['Nothing'], 1) + + # display the input prompt + offset = len(lines) + 1 + lines = ('','Pick [p,m]: ') + displayPrompt(data.screen, lines, offset) + + # refresh and wait for valid user input + data.screen.refresh() + c = data.screen.getstr() + + # process input + if c == ord('1'): playGameMenu(data) + elif c == ord('c'): changePlayerMenu(data) + elif c == ord('e'): pass + else: + levelOptionsMenu(data) def skillLevelMenu(data): ''' ''' + # check for required vars + + # clear the screen and display the title + # display the menu + # refresh the screen + # wait for input + # process input pass def numberOfPlayersMenu(data): diff --git a/src/setup/profile.py b/src/setup/profile.py index 0aceea3..3d45e9a 100644 --- a/src/setup/profile.py +++ b/src/setup/profile.py @@ -6,25 +6,63 @@ from lxml import etree # using lxml for XML processing from utils import strs # string constants from utils import utils # some XML utilities - +# setup logging +import logging +logging.basicConfig(filename=strs.LoggingFile,level=logging.DEBUG) +log = logging.getLogger('setup.profile') class Profile(object): ''' ''' - def __init__(self, path): + def __init__(self, path=None, name=None ): ''' Constructor ''' - #open up the mpro file and read in its basic properties - root = utils.getXMLRoot(path) - self.name = root.xpath(strs.XP_ProfileName)[0] - self.path = path + # new profiles have a name instead of a path + if path != None: + #open up the mpro file and read in its basic properties + root = utils.getXMLRoot(path) + self.name = root.xpath(strs.XP_ProfileName)[0] + self.path = path + else: + # there is no XML representation of this Profile, so just store its name + self.name = name pass def getName(self): '''Returns the name of the profile's user''' return self.name - + def getMaxScore(self, level=None, skill=None): + ''' ''' + + # if no path, then no XML to read for the max score + if self.path == None: + return 0 + + # TODO read in/calculate the max score of this player. Need to take into account the level and skill parameters + log.debug('getMaxScore() is stubbed to return 1') + return 1 + + def getMaxDuration(self, level=None, skill=None): + ''' ''' + + # if no path, then no XML to read for the max duration + if self.path == None: + return 0 + + # TODO read in/calculate the max duration of this player. Need to take into account the level and skill parameters + log.debug('getMaxDuration() is stubbed to return 1') + return 1 + + def getLastTimePlayed(self, level=None, skill=None): + ''' ''' + # if no path, then no XML to read for the last time played + if self.path == None: + return 0 + + # TODO read in/calculate the last time played for this player. Need to take into account the level and skill parameters + log.debug('getLastTimePlayed() is stubbed to return "06-21-2009.12:59"') + return '06-21-2009.12:59' |