comparison gamelib/gamegui.py @ 223:19aae2b701d1

More layout tweaking
author Neil Muller <drnlmuller@gmail.com>
date Sat, 12 May 2012 21:28:43 +0200
parents 69941f04f1c0
children e4f9513c9dd0
comparison
equal deleted inserted replaced
222:69941f04f1c0 223:19aae2b701d1
165 165
166 166
167 class MissionWidget(BigButton): 167 class MissionWidget(BigButton):
168 168
169 WIDTH = 260 169 WIDTH = 260
170 HEIGHT = 48
170 171
171 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png')) 172 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png'))
172 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png')) 173 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png'))
173 BG_IMAGE_SELECTED = image.load(filepath('images/mission_selected.png')) 174 BG_IMAGE_SELECTED = image.load(filepath('images/mission_selected.png'))
174 175
233 234
234 235
235 class EquipWidget(BigButton): 236 class EquipWidget(BigButton):
236 237
237 WIDTH = 260 238 WIDTH = 260
239 HEIGHT = 48
238 240
239 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png')) 241 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png'))
240 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png')) 242 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png'))
241 BG_IMAGE_UNAVAILABLE = image.load(filepath('images/equip_grey.png')) 243 BG_IMAGE_UNAVAILABLE = image.load(filepath('images/equip_grey.png'))
242 244
287 self.add_child(assign) 289 self.add_child(assign)
288 cancel = CancelButton(self) 290 cancel = CancelButton(self)
289 self.add_child(cancel) 291 self.add_child(cancel)
290 reset = ResetButton(self, 'Clear inventory') 292 reset = ResetButton(self, 'Clear inventory')
291 self.add_child(reset) 293 self.add_child(reset)
292 title = TextBox((170, 20, 370, 50), "Choose equipment for %s" 294 title = TextBox((170, 10, 370, 50), "Choose equipment for %s"
293 % mission.NAME, font_medium, (255, 255, 255)) 295 % mission.NAME, font_medium, (255, 255, 255))
294 self.add_child(title) 296 self.add_child(title)
295 self.description = TextBox((10, 70, 790, 20), 297 self.description = TextBox((10, 60, 790, 20),
296 mission.get_description(), font_medium, (255, 255, 255)) 298 mission.get_description(), font_medium, (255, 255, 255))
297 self.add_child(self.description) 299 self.add_child(self.description)
298 self.parent = parent 300 self.parent = parent
299 self.game = game 301 self.game = game
300 self.money = ValueLabel((10, self.description.rect.height + 75), 302 self.money = ValueLabel((10, self.description.rect.height + 57),
301 'Money') 303 'Money')
302 self.money.set_value(self.game.money) 304 self.money.set_value(self.game.money)
303 self.minions = ValueLabel((310, self.description.rect.height + 75), 305 self.minions = ValueLabel((310, self.description.rect.height + 57),
304 'Minions Assigned') 306 'Minions Assigned')
305 self.minions.set_value(self.parent.minions) 307 self.minions.set_value(self.parent.minions)
306 self.add_child(self.money) 308 self.add_child(self.money)
307 self.add_child(self.minions) 309 self.add_child(self.minions)
308 inventory = TextLabel((10, self.description.rect.height + 90, 400, 20), 310 inventory = TextLabel((10, self.description.rect.height + 75, 400, 20),
309 'Current Inventory', font_medium, (255, 255, 255)) 311 'Current Inventory', font_medium, (255, 255, 255))
310 self.add_child(inventory) 312 self.add_child(inventory)
311 self._equip = [] 313 self._equip = []
312 self._inventory = [] 314 self._inventory = []
313 self._update_widgets() 315 self._update_widgets()
346 for widget in self._equip: 348 for widget in self._equip:
347 self.remove_child(widget) 349 self.remove_child(widget)
348 self._equip = [] 350 self._equip = []
349 x = 0 351 x = 0
350 y = max(250, 130 + self.description.rect.height + 352 y = max(250, 130 + self.description.rect.height +
351 20 * len(self._inventory) // 3) 353 18 * len(self._inventory) // 3)
352 available = self.game.get_available_equipment() 354 available = self.game.get_available_equipment()
353 for equip in sorted(self.game.get_all_equipment(), 355 for equip in sorted(self.game.get_all_equipment(),
354 key=lambda x: x.NAME): 356 key=lambda x: x.NAME):
355 copies = self.parent.equipment.count(equip) 357 copies = self.parent.equipment.count(equip)
356 widget = EquipWidget(equip, (x, y), self, copies, 358 widget = EquipWidget(equip, (x, y), self, copies,
358 self._equip.append(widget) 360 self._equip.append(widget)
359 self.add_child(widget) 361 self.add_child(widget)
360 x += widget.WIDTH + 10 362 x += widget.WIDTH + 10
361 if x >= WIDTH: 363 if x >= WIDTH:
362 x = 0 364 x = 0
363 y += 65 365 y += 45
364 366
365 def buy(self, equip): 367 def buy(self, equip):
366 self.game.money -= equip.COST 368 self.game.money -= equip.COST
367 self.money.set_value(self.game.money) 369 self.money.set_value(self.game.money)
368 self.parent.equipment.append(equip) 370 self.parent.equipment.append(equip)