Changeset 245:634491bf37e8


Ignore:
Timestamp:
Sep 5, 2009, 12:15:46 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@246
Message:

Change toolbar to gui.Toolbar -- gives nicer highlighting.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/engine.py

    r237 r245  
    119119    def event(self, e):
    120120        if events_equal(e, START_NIGHT):
     121            self.game.gameboard.reset_states()
    121122            return NightState(self.game)
    122123        elif e.type is KEYDOWN and e.key == K_ESCAPE:
  • gamelib/gameboard.py

    r243 r245  
    5959    def __init__(self, gameboard, **params):
    6060        gui.Table.__init__(self, **params)
     61        self.group = gui.Group(name='toolbar', value=None)
     62        self._next_tool_value = 0
    6163        self.gameboard = gameboard
    6264        self.cash_counter = mklabel(align=1)
     
    101103        self.add_spacer(30)
    102104
    103         self.add_button("Finished Day", self.day_done)
     105        self.add_tool("Finished Day", self.day_done)
    104106
    105107    def day_done(self):
     
    122124
    123125    def add_tool_button(self, text, tool, cursor=None):
    124         self.add_button(text, lambda: self.gameboard.set_selected_tool(tool,
     126        self.add_tool(text, lambda: self.gameboard.set_selected_tool(tool,
    125127            cursor))
    126128
    127     def add_button(self, text, func):
    128         button = gui.Button(text, width=self.rect.w, style={"padding_left": 0})
    129         button.connect(gui.CLICK, func)
     129    def add_tool(self, text, func):
     130        label = gui.basic.Label(text)
     131        value = self._next_tool_value
     132        self._next_tool_value += 1
     133        tool = gui.Tool(self.group, label, value, width=self.rect.w, style={"padding_left": 0})
     134        tool.connect(gui.CLICK, func)
    130135        self.tr()
    131         self.td(button, align=-1, colspan=2)
     136        self.td(tool, align=-1, colspan=2)
     137
     138    def clear_tool(self):
     139        self.group.value = None
    132140
    133141    def add_counter(self, icon, label):
     
    286294    def reset_states(self):
    287295        """Clear current states (highlights, etc.)"""
    288         if self.animal_to_place:
    289             self.select_animal_to_place(None)
    290         self.set_cursor()
     296        self.set_selected_tool(None, None)
     297        self.toolbar.clear_tool()
    291298
    292299    def update_sprite_cursor(self, e):
Note: See TracChangeset for help on using the changeset viewer.