From 15f4b500c2709598230f22c798130d912657c94d Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Fri, 16 Sep 2011 08:57:31 -0400 Subject: [PATCH] finish project support --- whiteboard.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/whiteboard.py b/whiteboard.py index 20673aa..16df774 100644 --- a/whiteboard.py +++ b/whiteboard.py @@ -31,8 +31,10 @@ class Project(Ownable): self.user = user self.rgboard = [] self.rgscript = [] - def NewBoard(self, user): - self.rgboard.append(Board(self, "Board " + len(self.rgboard), user)) + def NewBoard(self, stName, user): + board = Board(self, stName, user) + self.rgboard.insert(0, board) + return board def BoardTouched(self, board): if board != self.rgboard[0]: self.rgboard.remove(board) @@ -44,7 +46,7 @@ class Project(Ownable): boardLast = None for board in self.rgboard: if boardLast == None or board.dtLastModified > boardLast.dtLastModified: - board = boardLast + boardLast = board if boardLast != None: return boardLast.StLastModified() return "never" @@ -565,13 +567,18 @@ class Lobby(TokenClient): self.lobbyCurrent = LobbyProject(self, client) def SwitchToLobby(self, lobbyNew): - self.lobbyCurrent.die() + lobbyOld = self.lobbyCurrent self.lobbyCurrent = lobbyNew + lobbyOld.die() class LobbyI(TokenClient): - def InitPersistent(self, owner, client): + def InitPersistent(self, owner, client, *rgmiListTop): TokenClient.InitPersistent(self, owner, client) - self.miDrawings = MiMenu(RgmiProjected(self.RgObj(), DgProjectMiButton(self.OnObjSelected))) + + rgmiList = RgmiProjected(self.RgObj(), DgProjectMiButton(self.OnObjSelected)) + if rgmiListTop != None: + rgmiList = Rgseq(rgmiListTop, rgmiList) + self.miDrawings = MiMenu(rgmiList) self.miCmds = MiMenu([None, None, MiTypein(self.NewI, "ObjectName"), MiButton(self.StNewObj(), self.NewI), None, None, None, None, None, None, None, None, MiStatic("Last modified:"), MiDgText(self.StLastModifiedI)]) OvMenu(self, client, MiMenuHoriz([self.miDrawings, self.miCmds], [65, 35]), OvMenu.FILL) @@ -603,7 +610,7 @@ class LobbyI(TokenClient): class LobbyBoard(LobbyI): def InitPersistent(self, owner, client, project): self.project = project - LobbyI.InitPersistent(self, owner, client) + LobbyI.InitPersistent(self, owner, client, MiButton("<-- Back to projects", self.Back), None) def StNewObj(self): return "New Board" @@ -612,10 +619,14 @@ class LobbyBoard(LobbyI): def OnObjSelected(self, board): self.client.leaveGame(board) def New(self, stName): - self.project.NewBoard(stName, self.client.cld.user) + self.OnObjSelected(self.project.NewBoard(stName, self.client.cld.user)) def StLastModified(self, board): - return board.StLastModified() - + if board != None: + return board.StLastModified() + return self.project.StLastModified() + def Back(self): + self.owner.SwitchToLobby(LobbyProject(self.owner, self.client)) + class LobbyProject(LobbyI): def StNewObj(self): return "New Project" @@ -677,8 +688,17 @@ class GameLobby(Game): def StNameBoard(self, board): return board.stName + " (by " + board.user + ") [" + str(self.CclientBoard(board)) + "]" - + + def NewProject(self, stName, user): + proj = Project(self, stName, user) + self.rgproject.insert(0, proj) + return proj + def BoardTouched(self, board): + project = board.owner + if project != self.rgproject[0]: + self.rgproject.remove(project) + self.rgproject.insert(0, project) #haaaack self.ensureRun() # redraw