Changeset 83:9bd2c22e1746


Ignore:
Timestamp:
Sep 1, 2009, 7:40:08 PM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@84
Message:

Cleaned up some toolbar code a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r80 r83  
    3030        self.chicken_counter = OpaqueLabel("         ", color=constants.FG_COLOR)
    3131        self.killed_foxes = OpaqueLabel("         ", color=constants.FG_COLOR)
    32         self.tr()
    33         self.add(self.cash_counter)
    34         self.tr()
    35         self.td(icons.CHKN_ICON, align=-1)
    36         self.add(self.chicken_counter)
    37         self.tr()
    38         self.td(icons.KILLED_FOX, align=-1)
    39         self.add(self.killed_foxes)
     32
     33        self.add_counter(None, self.cash_counter)
     34        self.add_counter(icons.CHKN_ICON, self.chicken_counter)
     35        self.add_counter(icons.KILLED_FOX, self.killed_foxes)
     36
    4037        self.add_tool_button("Sell chicken", constants.TOOL_SELL_CHICKEN)
    4138        self.add_tool_button("Sell egg", constants.TOOL_SELL_EGG)
     
    4441        for building_cls in buildings.BUILDINGS:
    4542            self.add_tool_button("Buy %s" % (building_cls.NAME,), building_cls)
    46 
    47         day_done_button = gui.Button("Finished Day")
    48         day_done_button.connect(gui.CLICK, self.day_done)
    49         self.tr()
    50         self.td(day_done_button, style={"padding_top": 30})
     43        self.add_spacer()
     44        self.add_button("Finished Day", self.day_done)
    5145
    5246    def day_done(self):
     
    6660        self.repaint()
    6761
     62    def add_spacer(self, height=30):
     63        self.tr()
     64        self.add(gui.Spacer(0, height))
     65
    6866    def add_tool_button(self, text, tool):
     67        self.add_button(text, lambda: self.gameboard.set_selected_tool(tool))
     68
     69    def add_button(self, text, func):
    6970        button = gui.Button(text)
    70         button.connect(gui.CLICK, lambda: self.gameboard.set_selected_tool(tool))
     71        button.connect(gui.CLICK, func)
    7172        self.tr()
    7273        self.add(button)
    7374
     75    def add_counter(self, icon, label):
     76        self.tr()
     77        if icon:
     78            self.td(icon, align=-1)
     79        self.add(label)
    7480
    7581class VidWidget(gui.Widget):
Note: See TracChangeset for help on using the changeset viewer.