changeset 573:ffdaac5d6cf8

Select is the default tool.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 28 Nov 2009 20:29:33 +0000
parents 40eee9e1246c
children ecad90bbdc61
files gamelib/gameboard.py gamelib/toolbar.py
diffstat 2 files changed, 29 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gameboard.py	Sat Nov 28 20:22:51 2009 +0000
+++ b/gamelib/gameboard.py	Sat Nov 28 20:29:33 2009 +0000
@@ -247,6 +247,9 @@
     def set_selected_tool(self, tool, cursor):
         if not self.day:
             return False
+        if tool is None:
+            tool = constants.TOOL_SELECT_CHICKENS
+            cursor = cursors.cursors['select']
         if self.apply_tool_to_selected(tool):
             return False # Using the tool on selected chickens is immediate
         self.selected_tool = tool
@@ -312,6 +315,9 @@
         self.day, self.night = False, True
         self.tv.sun(False)
         self.reset_states()
+        self.selected_tool = None
+        self.current_cursor = (cursors.cursors['arrow'],)
+        self.set_menu_cursor()
         self.unselect_all()
         self.toolbar.start_night()
         self.spawn_foxes()
@@ -356,17 +362,13 @@
         if not self.day:
             return
         if e.button == 3: # Right button
-            if self.toolbar.MOVE_SELECT_PERMITTED:
-                if self.selected_tool != constants.TOOL_SELECT_CHICKENS:
-                    self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"])
-                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.highlight_move_select_button()
+            if self.selected_tool == constants.TOOL_SELECT_CHICKENS:
+                self.place_animal(self.tv.screen_to_tile(e.pos))
             return
         elif e.button == 2: # Middle button
             self.reset_states()
             self.unselect_all()
+            return
         elif e.button != 1: # Left button
             return
         mods = pygame.key.get_mods()
@@ -377,6 +379,7 @@
         elif self.selected_tool == constants.TOOL_PLACE_ANIMALS:
             self.place_animal(self.tv.screen_to_tile(e.pos))
             self.set_selected_tool(constants.TOOL_SELECT_CHICKENS, cursors.cursors["select"])
+            self.toolbar.unhighlight_move_button()
         elif self.selected_tool == constants.TOOL_SELECT_CHICKENS:
             # ctrl moves current selection without having to select move tool
             if (mods & KMOD_CTRL):
@@ -397,8 +400,7 @@
         elif equipment.is_equipment(self.selected_tool):
             if not self.selected_chickens:
                 # old selection behaviour
-                self.buy_equipment(self.tv.screen_to_tile(e.pos),
-                        self.selected_tool)
+                self.buy_equipment(self.tv.screen_to_tile(e.pos), self.selected_tool)
 
     def get_outside_chicken(self, tile_pos):
         for chick in self.chickens:
--- a/gamelib/toolbar.py	Sat Nov 28 20:22:51 2009 +0000
+++ b/gamelib/toolbar.py	Sat Nov 28 20:29:33 2009 +0000
@@ -273,9 +273,16 @@
         self.group = gui.Group(name='default_toolbar', value=None)
         self.make_toolbar()
 
+    def toggle_move(self):
+        if self.gameboard.selected_tool == constants.TOOL_PLACE_ANIMALS:
+            self.gameboard.set_selected_tool(None, None)
+            return False
+        else:
+            self.gameboard.set_selected_tool(constants.TOOL_PLACE_ANIMALS, cursors.cursors['chicken'])
+            return True
+
     def make_toolbar(self):
-        self._select_tool = self.add_tool_button("Select / Move", constants.TOOL_SELECT_CHICKENS,
-                None, cursors.cursors['select'])
+        self._move_tool = self.add_tool("Move", self.toggle_move)
 
         self.add_spacer(5)
 
@@ -313,12 +320,16 @@
         #self.add_spacer(570-cur_height)
         self.fin_tool = self.add_tool("Finished Day", self.day_done)
 
-        if self.gameboard.selected_tool in [constants.TOOL_PLACE_ANIMALS, constants.TOOL_SELECT_CHICKENS]:
-            self.highlight_move_select_button()
+        if self.gameboard.selected_tool == constants.TOOL_PLACE_ANIMALS:
+            self.highlight_move_button()
 
-    def highlight_move_select_button(self):
-        self._select_tool.group.value = self._select_tool.value
-        self._select_tool.pcls = "down"
+    def unhighlight_move_button(self):
+        self._move_tool.group.value = None
+        self._move_tool.pcls = "up"
+
+    def highlight_move_button(self):
+        self._move_tool.group.value = self._move_tool.value
+        self._move_tool.pcls = "down"
 
     def add_building_toolbar(self):
         self.gameboard.change_toolbar(BuildingToolBar(self.gameboard,