Permalink
Browse files

added actions menu

  • Loading branch information...
zielmicha committed Apr 10, 2012
1 parent 8cc7ac1 commit 4740b526f9e904ac7cf493ec5ac9371cf306c438
Showing with 44 additions and 20 deletions.
  1. +43 −18 lib/gamemenu.py
  2. +1 −2 lib/gamescreen.py
View
@@ -57,27 +57,52 @@ def __init__(self, client):
self.add(self.panel)
self.panel.add(ui.Label('loading...', color=(0, 255, 0)))
- def update(self, actions):
+ def update(self, unit):
self.panel.items = []
self.items = [self.panel]
- if actions:
- joystick_layout = ui.LinearLayoutWidget()
- j_type = get_joystick_type()
- if j_type == 'new':
- joystick = NewJoystick(client)
- joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 50
- elif j_type == 'tile':
- joystick = TileJoystick(client)
- joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 20
- else:
- joystick = Joystick(client)
- joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 10
- joystick_layout.add(joystick)
- self.items.insert(0, joystick_layout)
- for action_ident, action_name, action_length in actions:
- self.panel.add(Button(self.client, action_ident, action_name))
-
+ if unit:
+ self.update_joystick()
+ self.update_actions(unit)
+
self.update_layout()
+
+ def update_joystick(self):
+ joystick_layout = ui.LinearLayoutWidget()
+ j_type = get_joystick_type()
+ if j_type == 'new':
+ joystick = NewJoystick(client)
+ joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 50
+ elif j_type == 'tile':
+ joystick = TileJoystick(client)
+ joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 20
+ else:
+ joystick = Joystick(client)
+ joystick_layout.marginleft = self.client.ui.map.size[0] - joystick.size[0] - 10
+ joystick_layout.add(joystick)
+ self.items.insert(0, joystick_layout)
+
+ def update_actions(self, unit):
+ image = unit.get_image()
+ self.panel.add(ui.Button('', callback=lambda: self.show_action_list(unit),
+ image=image, force_width=image.get_width(), force_height=image.get_height()))
+ for action_ident, action_name, action_length in unit.get_actions():
+ self.panel.add(Button(self.client, action_ident, action_name))
+
+ def show_action_list(self, unit):
+ def fcallback(action_ident):
+ self.client.get_unit_in_focus().perform_activity(action_ident)
+
+ panel = ui.LinearLayoutWidget()
+
+ for action_ident, action_name, action_length in unit.get_actions():
+ callback = functools.partial(fcallback, action_ident)
+ hor = ui.HorizontalLayoutWidget()
+ hor.add(ui.Image(get_order_sprite(action_name), callback))
+ hor.add(ui.Label('%s' % (action_name, ), callback))
+ panel.add(hor)
+
+ ui.set_dialog(panel, scroll=True)
+
class Button(object):
def __init__(self, client, action_ident, action_name):
View
@@ -57,8 +57,7 @@ def overview_size_changed(self, w, h):
self.ui.resize_left_pane(self.ui.overview.size[0])
def update_menus(self, unit):
- actions = unit.get_actions()
- self.ui.menu.update(actions)
+ self.ui.menu.update(unit)
def disable_menus(self):
self.ui.menu.update(None)

0 comments on commit 4740b52

Please sign in to comment.