From 9afa34c5978b650f54a7914f35687195f58009be Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Mon, 21 Jul 2014 18:11:08 +0000 Subject: Reset the game when the creen is rotated When the screen is rotated, we need reload the cards in the table game, to resize images if needed. This patch reset values in the game too. In particular set last_flipped = -1, we need check if something more is needed. --- diff --git a/activity.py b/activity.py index c18e5dc..87a9142 100644 --- a/activity.py +++ b/activity.py @@ -141,6 +141,7 @@ class MemorizeActivity(Activity): self.connect('key-press-event', self.table.key_press_event) self.table.connect('card-flipped', self.game.card_flipped) self.table.connect('card-highlighted', self.game.card_highlighted) + self.table.connect('resize-table', self.__resize_table_cb) self.game.connect('set-border', self.table.set_border) self.game.connect('flop-card', self.table.flop_card) @@ -238,6 +239,11 @@ class MemorizeActivity(Activity): self.table.resize(width, height - style.GRID_CELL_SIZE) self.show_all() + def __resize_table_cb(self, widget): + # need reset the game + # because we reload the cards in the table + self.game.last_flipped = -1 + def _change_mode_bt(self, button): if button.get_active(): self._change_mode(_MODE_CREATE) diff --git a/cardtable.py b/cardtable.py index ad292bc..b2afd5c 100644 --- a/cardtable.py +++ b/cardtable.py @@ -37,7 +37,9 @@ class CardTable(Gtk.EventBox): 'card-flipped': (GObject.SignalFlags.RUN_FIRST, None, [int, GObject.TYPE_PYOBJECT]), 'card-highlighted': (GObject.SignalFlags.RUN_FIRST, - None, [int, GObject.TYPE_PYOBJECT]), } + None, [int, GObject.TYPE_PYOBJECT]), + 'resize-table': (GObject.SignalFlags.RUN_FIRST, + None, []), } def __init__(self): Gtk.EventBox.__init__(self) @@ -82,6 +84,7 @@ class CardTable(Gtk.EventBox): self.change_game(None, self.data, self.cards_data) else: self.load_game(None, self.data, self.cards_data) + self.emit('resize-table') def _allocate_cb(self, widget, allocation): size = allocation.height -- cgit v0.9.1