Mercurial > rinkhals
changeset 487:a5dc09881aa1
rationalised when tools are reset; e.g. you can trade wood without losing selection / move tool. Default toolbar shows correct tool when reloaded (select/move only; other tools reset)
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Wed, 25 Nov 2009 21:58:29 +0000 |
parents | 8897a436a8cb |
children | a9f6c32c8ea9 |
files | gamelib/gameboard.py gamelib/toolbar.py |
diffstat | 2 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/gameboard.py Wed Nov 25 21:50:54 2009 +0000 +++ b/gamelib/gameboard.py Wed Nov 25 21:58:29 2009 +0000 @@ -103,6 +103,7 @@ self.selected_tool = None self.sprite_cursor = None + self.selected_chickens = [] self.chickens = set() self.foxes = set() self.buildings = set() @@ -128,8 +129,6 @@ self.tv.run_codes(cdata, (0,0,width,height)) - self.selected_chickens = [] - def get_top_widget(self): return self.top_widget @@ -267,15 +266,11 @@ if self.selected_tool == constants.TOOL_PLACE_ANIMALS: self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"]) if self.toolbar.IS_DEFAULT: - self.toolbar._select_tool.group.value = self.toolbar._select_tool.value - self.toolbar._move_tool.pcls = "" - self.toolbar._select_tool.pcls = "down" + self.toolbar.toggle_select_on() elif self.selected_tool == constants.TOOL_SELECT_CHICKENS: self.set_selected_tool(constants.TOOL_PLACE_ANIMALS, cursors.cursors["chicken"]) if self.toolbar.IS_DEFAULT: - self.toolbar._move_tool.group.value = self.toolbar._move_tool.value - self.toolbar._select_tool.pcls = "" - self.toolbar._move_tool.pcls = "down" + self.toolbar.toggle_move_on() return elif e.button != 1: # Left button return
--- a/gamelib/toolbar.py Wed Nov 25 21:50:54 2009 +0000 +++ b/gamelib/toolbar.py Wed Nov 25 21:58:29 2009 +0000 @@ -279,6 +279,23 @@ #self.add_spacer(570-cur_height) self.fin_tool = self.add_tool("Finished Day", self.day_done) + if self.gameboard.selected_tool == constants.TOOL_PLACE_ANIMALS: + self.toggle_move_on() + elif self.gameboard.selected_tool == constants.TOOL_SELECT_CHICKENS: + self.toggle_select_on() + else: + self.gameboard.set_selected_tool(None, None) + + def toggle_move_on(self): + self._select_tool.group.value = self._move_tool.value + self._move_tool.pcls = "down" + self._select_tool.pcls = "" + + def toggle_select_on(self): + self._select_tool.group.value = self._select_tool.value + self._move_tool.pcls = "" + self._select_tool.pcls = "down" + def add_building_toolbar(self): self.gameboard.change_toolbar(BuildingToolBar(self.gameboard, width=self.style.width)) @@ -287,11 +304,11 @@ def add_sell_toolbar(self): self.gameboard.change_toolbar(SellToolBar(self.gameboard, width=self.style.width)) + self.gameboard.unselect_all() def add_wood_toolbar(self): self.gameboard.change_toolbar(WoodToolBar(self.gameboard, width=self.style.width)) - self.gameboard.unselect_all() def add_equipment_toolbar(self): self.gameboard.change_toolbar(EquipmentToolBar(self.gameboard, @@ -310,7 +327,7 @@ self.make_toolbar() def make_toolbar(self): - self.gameboard.set_cursor(cursors.cursors['arrow'], None) + self.gameboard.set_selected_tool(None, None) for building_cls in buildings.BUILDINGS: self.add_tool_button(building_cls.NAME.title(), building_cls, None, cursors.cursors.get('build', None)) @@ -328,7 +345,8 @@ self.make_toolbar() def make_toolbar(self): - self.gameboard.set_cursor(cursors.cursors['arrow'], None) + if self.gameboard.selected_tool not in [constants.TOOL_SELECT_CHICKENS, constants.TOOL_PLACE_ANIMALS]: + self.gameboard.set_selected_tool(None, None) for equipment_cls in equipment.EQUIPMENT: self.add_tool_button(equipment_cls.NAME.title(), equipment_cls, @@ -348,7 +366,7 @@ self.make_toolbar() def make_toolbar(self): - self.gameboard.set_cursor(cursors.cursors['arrow'], None) + self.gameboard.set_selected_tool(None, None) self.add_heading("Sell ...") self.add_tool_button("Chicken", constants.TOOL_SELL_CHICKEN, @@ -371,7 +389,8 @@ self.make_toolbar() def make_toolbar(self): - self.gameboard.set_cursor(cursors.cursors['arrow'], None) + if self.gameboard.selected_tool not in [constants.TOOL_SELECT_CHICKENS, constants.TOOL_PLACE_ANIMALS]: + self.gameboard.set_selected_tool(None, None) self.add_heading("Trade...") self.add_tool("Buy 5 planks (%s)" % self.gameboard.wood_buy_price, self.buy_wood)