Mercurial > rinkhals
comparison gamelib/gameboard.py @ 286:49418fd43748
Price reference dialog - without close button
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 15:41:48 +0000 |
parents | f6bd57494e81 |
children | 21b0c4a99c0a |
comparison
equal
deleted
inserted
replaced
285:e694aa7731ed | 286:49418fd43748 |
---|---|
93 None, cursors.cursors['sell']) | 93 None, cursors.cursors['sell']) |
94 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, | 94 self.add_tool_button("Equipment", constants.TOOL_SELL_EQUIPMENT, |
95 None, cursors.cursors['sell']) | 95 None, cursors.cursors['sell']) |
96 self.add_spacer(20) | 96 self.add_spacer(20) |
97 | 97 |
98 | |
99 self.add_heading("Buy ...") | 98 self.add_heading("Buy ...") |
100 | 99 |
101 self.add_tool_button("Fence", constants.TOOL_BUY_FENCE, | 100 self.add_tool_button("Fence", constants.TOOL_BUY_FENCE, |
102 "%s/%s" % (constants.BUY_PRICE_FENCE, | 101 "%s/%s" % (constants.BUY_PRICE_FENCE, |
103 constants.REPAIR_PRICE_FENCE)) | 102 constants.REPAIR_PRICE_FENCE)) |
110 self.add_tool_button(equipment_cls.NAME.title(), | 109 self.add_tool_button(equipment_cls.NAME.title(), |
111 equipment_cls, | 110 equipment_cls, |
112 equipment_cls.BUY_PRICE, | 111 equipment_cls.BUY_PRICE, |
113 cursors.cursors.get('buy', None)) | 112 cursors.cursors.get('buy', None)) |
114 | 113 |
114 self.add_tool("Price Reference", self.show_prices) | |
115 self.add_spacer(30) | 115 self.add_spacer(30) |
116 | 116 |
117 self.add_tool("Finished Day", self.day_done) | 117 self.add_tool("Finished Day", self.day_done) |
118 | 118 |
119 def day_done(self): | 119 def day_done(self): |
120 import engine | 120 import engine |
121 pygame.event.post(engine.START_NIGHT) | 121 pygame.event.post(engine.START_NIGHT) |
122 | |
123 def show_prices(self): | |
124 """Popup dialog of prices""" | |
125 def make_box(text): | |
126 style = { | |
127 'border' : 1 | |
128 } | |
129 word = gui.Label(text, style=style) | |
130 return word | |
131 | |
132 def fix_widths(doc): | |
133 """Loop through all the widgets in the doc, and set the | |
134 width of the labels to max + 10""" | |
135 # We need to do this because of possible font issues | |
136 max_width = 0 | |
137 for thing in doc.widgets: | |
138 if hasattr(thing, 'style'): | |
139 # A label | |
140 if thing.style.width > max_width: | |
141 max_width = thing.style.width | |
142 for thing in doc.widgets: | |
143 if hasattr(thing, 'style'): | |
144 thing.style.width = max_width + 10 | |
145 | |
146 doc = gui.Document(width=400) | |
147 space = doc.style.font.size(" ") | |
148 for header in ['Item', 'Buy Price', 'Sell Price']: | |
149 doc.add(make_box(header)) | |
150 doc.br(space[1]) | |
151 for building in buildings.BUILDINGS: | |
152 doc.add(make_box(building.NAME)) | |
153 doc.add(make_box('%d' % building.BUY_PRICE)) | |
154 doc.add(make_box('%d' % building.SELL_PRICE)) | |
155 doc.br(space[1]) | |
156 for equip in equipment.EQUIPMENT: | |
157 doc.add(make_box(equip.NAME)) | |
158 doc.add(make_box('%d' % equip.BUY_PRICE)) | |
159 doc.add(make_box('%d' % equip.SELL_PRICE)) | |
160 doc.br(space[1]) | |
161 fix_widths(doc) | |
162 for word in "Damaged equipment will be sold for less than" \ | |
163 " the sell price.".split(): | |
164 doc.add(gui.Label(word)) | |
165 doc.space(space) | |
166 dialog = gui.Dialog(gui.Label('Price Reference'), doc) | |
167 dialog.open() | |
122 | 168 |
123 update_cash_counter = mkcountupdate('cash_counter') | 169 update_cash_counter = mkcountupdate('cash_counter') |
124 update_fox_counter = mkcountupdate('killed_foxes') | 170 update_fox_counter = mkcountupdate('killed_foxes') |
125 update_chicken_counter = mkcountupdate('chicken_counter') | 171 update_chicken_counter = mkcountupdate('chicken_counter') |
126 update_egg_counter = mkcountupdate('egg_counter') | 172 update_egg_counter = mkcountupdate('egg_counter') |