From 73fa562a97450a9a7920eadd4e84268fc4c309e2 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Sun, 12 Aug 2007 21:23:48 +0000 Subject: [PATCH] + new mouse binding: middle click -> autodrop * fixed `Octave' game git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@192 efabe8c0-fbe8-4139-b769-b5e6d273206e --- pysollib/game.py | 62 ++++++++++++++--------------- pysollib/games/fortythieves.py | 71 +++++++++++++++++++++++----------- pysollib/tile/tkwidget.py | 3 +- pysollib/tk/tkwidget.py | 3 +- 4 files changed, 82 insertions(+), 57 deletions(-) diff --git a/pysollib/game.py b/pysollib/game.py index 16af0d2c..37c740b6 100644 --- a/pysollib/game.py +++ b/pysollib/game.py @@ -253,9 +253,7 @@ class Game: def initBindings(self): # note: a Game is only allowed to bind self.canvas and not to self.top - ##bind(self.canvas, "<1>", self.clickHandler) - bind(self.canvas, "<2>", self.clickHandler) - ##bind(self.canvas, "<3>", self.clickHandler) + bind(self.canvas, "<2>", self.dropHandler) ##bind(self.canvas, "", self.undoHandler) bind(self.canvas, "<1>", self.undoHandler) bind(self.canvas, "<3>", self.redoHandler) @@ -853,45 +851,43 @@ class Game: # UI & graphics support # - def _defaultHandler(self): + def _defaultHandler(self, event): + if not self.app: + return True # FIXME (GTK) + if not self.app.opt.mouse_undo: + return True + # stop animation + if not self.event_handled and self.stopWinAnimation(): + return True self.interruptSleep() - self.deleteStackDesc() + if self.deleteStackDesc(): + # delete piles descriptions + return True + if self.demo: + # stop demo + self.stopDemo() + return True + if not self.event_handled and self.drag.stack: + # cancel drag + self.drag.stack.cancelDrag(event) + return True + return False # continue this event - def clickHandler(self, event): - if self.stopWinAnimation(): return EVENT_PROPAGATE - self._defaultHandler() + def dropHandler(self, event): + if not self._defaultHandler(event) and not self.event_handled: + self.app.menubar.mDrop() self.event_handled = False return EVENT_PROPAGATE def undoHandler(self, event): - if not self.app: return EVENT_PROPAGATE # FIXME (GTK) - if not self.event_handled and self.stopWinAnimation(): - return EVENT_PROPAGATE - self._defaultHandler() - if self.demo: - self.stopDemo() - return - if not self.event_handled: - if self.drag.stack: - self.drag.stack.cancelDrag(event) - elif self.app.opt.mouse_undo: - self.app.menubar.mUndo() + if not self._defaultHandler(event) and not self.event_handled: + self.app.menubar.mUndo() self.event_handled = False return EVENT_PROPAGATE def redoHandler(self, event): - if not self.app: return EVENT_PROPAGATE # FIXME (GTK) - if not self.event_handled and self.stopWinAnimation(): - return EVENT_PROPAGATE - self._defaultHandler() - if self.demo: - self.stopDemo() - return - if not self.event_handled: - if self.drag.stack: - self.drag.stack.cancelDrag(event) - elif self.app.opt.mouse_undo: - self.app.menubar.mRedo() + if not self._defaultHandler(event) and not self.event_handled: + self.app.menubar.mRedo() self.event_handled = False return EVENT_PROPAGATE @@ -3124,6 +3120,8 @@ in the current implementation.''') % version) for sd in self.stackdesc_list: sd.delete() self.stackdesc_list = [] + return True + return False ## for find_card_dialog def canFindCard(self): diff --git a/pysollib/games/fortythieves.py b/pysollib/games/fortythieves.py index c5ba9217..5b117d81 100644 --- a/pysollib/games/fortythieves.py +++ b/pysollib/games/fortythieves.py @@ -522,23 +522,36 @@ class Octave_Talon(WasteTalonStack): def dealCards(self, sound=False): if self.round == self.max_rounds: - # last round - old_state = self.game.enterState(self.game.S_DEAL) - num_cards = 0 - wastes = [self.waste]+list(self.game.s.reserves) - if self.cards: - if sound and not self.game.demo: - self.game.startDealSample() - num_cards = min(len(self.cards), 8) - for i in range(num_cards): - if not self.cards[-1].face_up: - self.game.flipMove(self) - self.game.moveMove(1, self, wastes[i], frames=4, shadow=0) - if sound and not self.game.demo: - self.game.stopSamples() - self.game.leaveState(old_state) - return num_cards - return WasteTalonStack.dealCards(self, sound) + return 0 + if self.cards: + return WasteTalonStack.dealCards(self, sound) + # last round + num_cards = WasteTalonStack.dealCards(self, sound) + wastes = [self.waste]+list(self.game.s.reserves) + old_state = self.game.enterState(self.game.S_DEAL) + if self.cards: + if sound and not self.game.demo: + self.game.startDealSample() + num_cards = min(len(self.cards), 8) + for i in range(num_cards): + if not self.cards[-1].face_up: + self.game.flipMove(self) + self.game.moveMove(1, self, wastes[i], frames=4, shadow=0) + if sound and not self.game.demo: + self.game.stopSamples() + self.game.leaveState(old_state) + return num_cards + + +class Octave_Waste(WasteStack): + def updateText(self): + if self.game.preview > 1 or self.texts.ncards is None: + return + if self.game.s.talon.round == self.game.s.talon.max_rounds: + t = '' + else: + t = str(len(self.cards)) + self.texts.ncards.config(text=t) class Octave(Game): @@ -558,13 +571,13 @@ class Octave(Game): self.setSize(w, h) # create stacks - x, y = l.XM, l.YM + x, y = l.XM+l.XS/2, l.YM for i in range(8): s.foundations.append(SS_FoundationStack(x, y, self, suit=int(i/2), max_cards=10)) x += l.XS - x, y = l.XM, l.YM+l.YS + x, y = l.XM+l.XS/2, l.YM+l.YS for i in range(8): s.rows.append(AC_RowStack(x, y, self, base_rank=ANY_RANK, max_move=1)) @@ -574,10 +587,12 @@ class Octave(Game): s.talon = Octave_Talon(x, y, self, max_rounds=2) l.createText(s.talon, "n") x += l.XS - s.waste = WasteStack(x, y, self) + s.waste = Octave_Waste(x, y, self) + l.createText(s.waste, 'n') x += l.XS for i in range(7): - s.reserves.append(OpenStack(x, y, self, max_accept=0)) + stack = WasteStack(x, y, self, max_accept=0) + s.reserves.append(stack) x += l.XS # define stack-groups @@ -586,7 +601,7 @@ class Octave(Game): def _shuffleHook(self, cards): # move Aces to top of the Talon (i.e. first cards to be dealt) return self._shuffleHookMoveToTop(cards, - lambda c: (c.rank == 0, c.suit)) + lambda c: (c.rank == ACE, c.suit)) def startGame(self): self.s.talon.dealRow(rows=self.s.foundations, frames=0) @@ -613,6 +628,16 @@ class Octave(Game): return self.dealCards(sound=sound) return 0 + def fillStack(self, stack): + if self.s.talon.round == self.s.talon.max_rounds: + # last round + if not stack.cards and self.s.talon.cards: + if stack is self.s.waste or stack in self.s.reserves: + old_state = self.enterState(self.S_FILL) + self.flipMove(self.s.talon) + self.moveMove(1, self.s.talon, stack, frames=4, shadow=0) + self.leaveState(old_state) + # /*********************************************************************** # // Fortune's Favor @@ -1186,7 +1211,7 @@ registerGame(GameInfo(295, NapoleonsSquare, "Napoleon's Square", registerGame(GameInfo(310, Emperor, "Emperor", GI.GT_FORTY_THIEVES, 2, 0, GI.SL_BALANCED)) registerGame(GameInfo(323, Octave, "Octave", - GI.GT_FORTY_THIEVES, 2, 1, GI.SL_BALANCED)) + GI.GT_FORTY_THIEVES, 2, 1, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(332, Mumbai, "Mumbai", GI.GT_FORTY_THIEVES, 3, 0, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(411, CarreNapoleon, "Carre Napoleon", diff --git a/pysollib/tile/tkwidget.py b/pysollib/tile/tkwidget.py index c50d8bc5..fcbc6eac 100644 --- a/pysollib/tile/tkwidget.py +++ b/pysollib/tile/tkwidget.py @@ -681,7 +681,8 @@ class StackDesc: if text: frame = Tkinter.Frame(self.canvas) self.frame = frame - label = Tkinter.Message(frame, font=font, text=text, width=cardw-8, + label = Tkinter.Message(frame, font=font, text=text, + width=cardw-8, relief='solid', fg='#000000', bg='#ffffe0', bd=1) label.pack() self.label = label diff --git a/pysollib/tk/tkwidget.py b/pysollib/tk/tkwidget.py index 2f8005e5..1f52abcc 100644 --- a/pysollib/tk/tkwidget.py +++ b/pysollib/tk/tkwidget.py @@ -672,7 +672,8 @@ class StackDesc: frame = Tkinter.Frame(self.canvas, highlightthickness=1, highlightbackground='black') self.frame = frame - label = Tkinter.Message(frame, font=font, text=text, width=cardw-8, + label = Tkinter.Message(frame, font=font, text=text, + width=cardw-8, relief='solid', fg='#000000', bg='#ffffe0', bd=1) label.pack() self.label = label