changeset 519:f84ad10a9625

Remove move tool. Add basic controls reference dialog
author Neil Muller <drnlmuller@gmail.com>
date Fri, 27 Nov 2009 13:55:07 +0000
parents a42852e50df1
children 3e19a7f5333e
files gamelib/gameboard.py gamelib/misc.py gamelib/toolbar.py
diffstat 3 files changed, 75 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gameboard.py	Fri Nov 27 13:34:50 2009 +0000
+++ b/gamelib/gameboard.py	Fri Nov 27 13:55:07 2009 +0000
@@ -332,12 +332,8 @@
             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"])
-                    if self.toolbar.IS_DEFAULT:
-                        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.toggle_move_on()
             return
         elif e.button == 2: # Middle button
             self.reset_states()
@@ -352,8 +348,6 @@
         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"])
-            if self.toolbar.IS_DEFAULT:
-                self.toolbar.toggle_select_on()
         elif self.selected_tool == constants.TOOL_SELECT_CHICKENS:
             # ctrl moves current selection without having to select move tool
             if (mods & KMOD_CTRL):
--- a/gamelib/misc.py	Fri Nov 27 13:34:50 2009 +0000
+++ b/gamelib/misc.py	Fri Nov 27 13:55:07 2009 +0000
@@ -115,4 +115,26 @@
     dialog.open()
     return dialog
 
+# Utility layout functions
 
+def make_box(text):
+    style = {
+            'border' : 1
+            }
+    word = gui.Label(text, style=style)
+    return word
+
+def fix_widths(doc):
+    """Loop through all the widgets in the doc, and set the
+       width of the labels to max + 10"""
+    # We need to do this because of possible font issues
+    max_width = 0
+    for thing in doc.widgets:
+        if hasattr(thing, 'style'):
+            # A label
+            if thing.style.width > max_width:
+                max_width = thing.style.width
+    for thing in doc.widgets:
+        if hasattr(thing, 'style'):
+            thing.style.width = max_width + 10
+
--- a/gamelib/toolbar.py	Fri Nov 27 13:34:50 2009 +0000
+++ b/gamelib/toolbar.py	Fri Nov 27 13:55:07 2009 +0000
@@ -8,6 +8,7 @@
 import cursors
 import engine
 import savegame
+import misc
 
 class RinkhalsTool(gui.Tool):
     def __init__(self, group, label, value, func, **params):
@@ -113,56 +114,36 @@
 
     def show_prices(self):
         """Popup dialog of prices"""
-        def make_box(text):
-            style = {
-                    'border' : 1
-                    }
-            word = gui.Label(text, style=style)
-            return word
-
-        def fix_widths(doc):
-            """Loop through all the widgets in the doc, and set the
-               width of the labels to max + 10"""
-            # We need to do this because of possible font issues
-            max_width = 0
-            for thing in doc.widgets:
-                if hasattr(thing, 'style'):
-                    # A label
-                    if thing.style.width > max_width:
-                        max_width = thing.style.width
-            for thing in doc.widgets:
-                if hasattr(thing, 'style'):
-                    thing.style.width = max_width + 10
 
         tbl = gui.Table()
         tbl.tr()
         doc = gui.Document(width=510)
         space = doc.style.font.size(" ")
         for header in ['Item', 'Buy Price', 'Sell Price', 'Repair Price']:
-            doc.add(make_box(header))
+            doc.add(misc.make_box(header))
         doc.br(space[1])
         for building in buildings.BUILDINGS:
-            doc.add(make_box(building.NAME))
-            doc.add(make_box('%d planks' % building.BUY_PRICE))
-            doc.add(make_box('%d planks' % building.SELL_PRICE))
+            doc.add(misc.make_box(building.NAME))
+            doc.add(misc.make_box('%d planks' % building.BUY_PRICE))
+            doc.add(misc.make_box('%d planks' % building.SELL_PRICE))
             if building.BREAKABLE:
-                doc.add(make_box('%d planks' % building.REPAIR_PRICE))
+                doc.add(misc.make_box('%d planks' % building.REPAIR_PRICE))
             else:
-                doc.add(make_box('N/A'))
+                doc.add(misc.make_box('N/A'))
             doc.br(space[1])
         for equip in equipment.EQUIPMENT:
-            doc.add(make_box(equip.NAME))
-            doc.add(make_box('%d groats' % equip.BUY_PRICE))
-            doc.add(make_box('%d groats' % equip.SELL_PRICE))
-            doc.add(make_box('N/A'))
+            doc.add(misc.make_box(equip.NAME))
+            doc.add(misc.make_box('%d groats' % equip.BUY_PRICE))
+            doc.add(misc.make_box('%d groats' % equip.SELL_PRICE))
+            doc.add(misc.make_box('N/A'))
             doc.br(space[1])
-        doc.add(make_box("5 planks"))
-        doc.add(make_box('%d groats' % self.gameboard.wood_buy_price))
-        doc.add(make_box('%d groats' % self.gameboard.wood_sell_price))
-        doc.add(make_box('N/A'))
+        doc.add(misc.make_box("5 planks"))
+        doc.add(misc.make_box('%d groats' % self.gameboard.wood_buy_price))
+        doc.add(misc.make_box('%d groats' % self.gameboard.wood_sell_price))
+        doc.add(misc.make_box('N/A'))
         doc.br(space[1])
 
-        fix_widths(doc)
+        misc.fix_widths(doc)
         for word in "Damaged equipment or buildings will be sold for" \
                 " less than the sell price.".split():
             doc.add(gui.Label(word))
@@ -175,6 +156,41 @@
         close_button.connect(gui.CLICK, dialog.close)
         dialog.open()
 
+    def show_controls(self):
+        """Popup dialog of controls"""
+
+        COMBOS = {
+                'Select Multiple chickens' : 'Shift & Left Click',
+                'Move selected chickens' : 'Ctrl & Left Click',
+                'Change to move tool' : 'Right Click',
+                'Save selection' : 'Ctrl & 0 .. 9',
+                'Recall saved selection' : '0 .. 9',
+                'Exit game' : 'Esc',
+                }
+
+        tbl = gui.Table()
+        tbl.tr()
+        doc = gui.Document(width=410)
+        space = doc.style.font.size(" ")
+        for header in ['Action', 'Combination']:
+            doc.add(misc.make_box(header))
+        doc.br(space[1])
+        for command, combo in COMBOS.iteritems():
+            doc.add(misc.make_box(command))
+            doc.add(misc.make_box(combo))
+            doc.br(space[1])
+        doc.br(space[1])
+
+        misc.fix_widths(doc)
+        close_button = gui.Button("Close")
+        tbl.td(doc)
+        tbl.tr()
+        tbl.td(close_button, align=1)
+        dialog = gui.Dialog(gui.Label('Command Reference'), tbl)
+        close_button.connect(gui.CLICK, dialog.close)
+        dialog.open()
+
+
     def save_game(self):
         """Save game 'dialog'."""
         savegame.SaveDialog(self.gameboard).open()
@@ -241,16 +257,13 @@
         self.make_toolbar()
 
     def make_toolbar(self):
-        self._select_tool = self.add_tool_button("Select chicken", constants.TOOL_SELECT_CHICKENS,
+        self._select_tool = self.add_tool_button("Select / Move", constants.TOOL_SELECT_CHICKENS,
                 None, cursors.cursors['select'])
 
         self.add_spacer(5)
 
         self.add_tool('Equip chickens', self.add_equipment_toolbar)
 
-        self._move_tool = self.add_tool_button("Move chickens", constants.TOOL_PLACE_ANIMALS,
-                None, cursors.cursors['select'])
-
         self.add_tool('Sell stuff', self.add_sell_toolbar)
 
         self.add_tool('Trade wood', self.add_wood_toolbar)
@@ -269,6 +282,7 @@
         self.add_spacer(5)
         self.add_heading("Help")
         self.add_tool("Price Reference", self.show_prices)
+        self.add_tool("Controls", self.show_controls)
 
         self.add_spacer(5)
         self.add_heading("Game")
@@ -281,21 +295,6 @@
         #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()
-
-    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))