comparison gamelib/gamescreen.py @ 122:d2f84f22def0

Move MessageDialog to widgets
author Neil Muller <neil@dip.sun.ac.za>
date Tue, 24 Aug 2010 17:45:46 +0200
parents 2f672e98d488
children 97322b78d1c1
comparison
equal deleted inserted replaced
121:2f672e98d488 122:d2f84f22def0
1 # gamescreen.py 1 # gamescreen.py
2 # Copyright Boomslang team, 2010 (see COPYING File) 2 # Copyright Boomslang team, 2010 (see COPYING File)
3 # Main menu for the game 3 # Main menu for the game
4
5 import textwrap
6 4
7 from albow.controls import Button, Label, Widget 5 from albow.controls import Button, Label, Widget
8 from albow.layout import Row 6 from albow.layout import Row
9 from albow.palette_view import PaletteView 7 from albow.palette_view import PaletteView
10 from albow.screen import Screen 8 from albow.screen import Screen
15 from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE 13 from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE
16 from cursor import CursorWidget 14 from cursor import CursorWidget
17 from hand import HandButton 15 from hand import HandButton
18 from popupmenu import PopupMenu, PopupMenuButton 16 from popupmenu import PopupMenu, PopupMenuButton
19 from state import initial_state, Item 17 from state import initial_state, Item
20 from widgets import BoomLabel 18 from widgets import MessageDialog
21 19
22 20
23 class InventoryView(PaletteView): 21 class InventoryView(PaletteView):
24 22
25 sel_color = Color("yellow") 23 sel_color = Color("yellow")
44 def item_is_selected(self, item_no): 42 def item_is_selected(self, item_no):
45 return self.state.tool is self.state.inventory[item_no] 43 return self.state.tool is self.state.inventory[item_no]
46 44
47 def unselect(self): 45 def unselect(self):
48 self.state.set_tool(None) 46 self.state.set_tool(None)
49
50
51 class MessageDialog(BoomLabel, CursorWidget):
52
53 def __init__(self, text, wrap_width, **kwds):
54 CursorWidget.__init__(self)
55 paras = text.split("\n\n")
56 text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])
57 Label.__init__(self, text, **kwds)
58 self.set_margin(5)
59 self.border_width = 1
60 self.border_color = (0, 0, 0)
61 self.bg_color = (127, 127, 127)
62 self.fg_color = (0, 0, 0)
63
64 def mouse_down(self, event):
65 self.dismiss()
66 47
67 48
68 class StateWidget(Widget): 49 class StateWidget(Widget):
69 50
70 def __init__(self, state): 51 def __init__(self, state):