Mercurial > rinkhals
comparison gamelib/gameboard.py @ 302:01c1682dc250
Mostly working selling equipment in buildings
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 17:18:14 +0000 |
parents | 88a626202591 |
children | e12d99215b74 |
comparison
equal
deleted
inserted
replaced
301:8d6647c912b3 | 302:01c1682dc250 |
---|---|
548 self.tv.sprites.append(chicken) | 548 self.tv.sprites.append(chicken) |
549 else: | 549 else: |
550 if chicken in self.tv.sprites: | 550 if chicken in self.tv.sprites: |
551 self.tv.sprites.remove(chicken) | 551 self.tv.sprites.remove(chicken) |
552 | 552 |
553 def open_dialog(self, widget, close_callback=None): | 553 def open_dialog(self, widget, x=None, y=None, close_callback=None): |
554 """Open a dialog for the given widget. Add close button.""" | 554 """Open a dialog for the given widget. Add close button.""" |
555 tbl = gui.Table() | 555 tbl = gui.Table() |
556 | 556 |
557 def close_dialog(): | 557 def close_dialog(): |
558 self.disp.close(tbl) | 558 self.disp.close(tbl) |
567 tbl.td(widget, colspan=2) | 567 tbl.td(widget, colspan=2) |
568 tbl.tr() | 568 tbl.tr() |
569 tbl.td(gui.Spacer(100, 0)) | 569 tbl.td(gui.Spacer(100, 0)) |
570 tbl.td(close_button, align=1) | 570 tbl.td(close_button, align=1) |
571 | 571 |
572 self.disp.open(tbl) | 572 if x: |
573 offset = (self.disp.rect.center[0] + x, | |
574 self.disp.rect.center[1] + y) | |
575 else: | |
576 offset = None | |
577 self.disp.open(tbl, pos=offset) | |
573 return tbl | 578 return tbl |
574 | 579 |
575 def open_building_dialog(self, building, sell_callback=None): | 580 def open_building_dialog(self, building, sell_callback=None): |
576 """Create dialog for manipulating the contents of a building.""" | 581 """Create dialog for manipulating the contents of a building.""" |
577 | 582 |
740 self.add_cash(building.sell_price()) | 745 self.add_cash(building.sell_price()) |
741 building.remove(self.tv) | 746 building.remove(self.tv) |
742 self.remove_building(building) | 747 self.remove_building(building) |
743 | 748 |
744 def sell_equipment(self, tile_pos): | 749 def sell_equipment(self, tile_pos): |
750 x, y = 0, 0 | |
751 def do_sell(chicken): | |
752 if not chicken.equipment: | |
753 return | |
754 elif len(chicken.equipment) == 1: | |
755 item = chicken.equipment[0] | |
756 self.add_cash(item.sell_price()) | |
757 chicken.unequip(item) | |
758 else: | |
759 self.open_equipment_dialog(chicken, x, y) | |
760 return False | |
761 | |
745 chicken = self.get_outside_chicken(tile_pos) | 762 chicken = self.get_outside_chicken(tile_pos) |
746 if chicken is None or not chicken.equipment: | 763 if chicken is not None: |
747 return | 764 do_sell(chicken) |
748 if len(chicken.equipment) == 1: | |
749 item = chicken.equipment[0] | |
750 self.add_cash(item.sell_price()) | |
751 chicken.unequip(item) | |
752 else: | 765 else: |
753 self.open_equipment_dialog(chicken) | 766 building = self.get_building(tile_pos) |
754 | 767 if building is None: |
755 def open_equipment_dialog(self, chicken): | 768 return |
769 x, y = 50, 0 | |
770 self.open_building_dialog(building, do_sell) | |
771 | |
772 def open_equipment_dialog(self, chicken, x, y): | |
756 tbl = gui.Table() | 773 tbl = gui.Table() |
757 | 774 |
758 def sell_item(item, button): | 775 def sell_item(item, button): |
759 """Select item of equipment.""" | 776 """Select item of equipment.""" |
760 self.add_cash(item.sell_price()) | 777 self.add_cash(item.sell_price()) |
770 tbl.tr() | 787 tbl.tr() |
771 button = gui.Button(item.name().title()) | 788 button = gui.Button(item.name().title()) |
772 button.connect(gui.CLICK, sell_item, item, button) | 789 button.connect(gui.CLICK, sell_item, item, button) |
773 tbl.td(button, align=1, **kwargs) | 790 tbl.td(button, align=1, **kwargs) |
774 | 791 |
775 dialog = self.open_dialog(tbl) | 792 dialog = self.open_dialog(tbl, x=x, y=y) |
776 | 793 |
777 def event(self, e): | 794 def event(self, e): |
778 if e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: | 795 if e.type == KEYDOWN and e.key in [K_UP, K_DOWN, K_LEFT, K_RIGHT]: |
779 if e.key == K_UP: | 796 if e.key == K_UP: |
780 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) | 797 self.tvw.move_view(0, -self.TILE_DIMENSIONS[1]) |