comparison gamelib/gamegui.py @ 249:8c237a830efe

merge
author Rizmari Versfeld <rizziepit@gmail.com>
date Sun, 13 May 2012 00:51:29 +0200
parents 25ea20b9803c 235b1faf590e
children c5fdfa96cfb2
comparison
equal deleted inserted replaced
248:25ea20b9803c 249:8c237a830efe
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
3 3
4 """Gui for the actual game""" 4 """Gui for the actual game"""
5 5
6 from pygame import image
7 try: 6 try:
8 import simplejson 7 import simplejson
9 json = simplejson 8 json = simplejson
10 except ImportError: 9 except ImportError:
11 import json 10 import json
12 11
13 12
14 from gamelib.data import filepath 13 from gamelib.data import load_image
15 from gamelib.game_base import get_save_filename 14 from gamelib.game_base import get_save_filename
16 from gamelib.gui_base import (Window, TextLabel, TextBox, font_small, 15 from gamelib.gui_base import (Window, TextLabel, TextBox, font_small,
17 font_medium, font_large) 16 font_medium, font_large)
18 from gamelib.gui import BigButton, ImageDrawable, IconTextButton 17 from gamelib.gui import BigButton, ImageDrawable, IconTextButton
19 from gamelib.engine import PopWindow, AddWindow, GameOver 18 from gamelib.engine import PopWindow, AddWindow, GameOver
167 class MissionWidget(BigButton): 166 class MissionWidget(BigButton):
168 167
169 WIDTH = 260 168 WIDTH = 260
170 HEIGHT = 48 169 HEIGHT = 48
171 170
172 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png')) 171 BG_IMAGE_NORMAL = load_image('images/science_normal.png')
173 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png')) 172 BG_IMAGE_DOWN = load_image('images/science_down.png')
174 BG_IMAGE_SELECTED = image.load(filepath('images/mission_selected.png')) 173 BG_IMAGE_SELECTED = load_image('images/mission_selected.png')
175 174
176 def __init__(self, mission, pos, parent): 175 def __init__(self, mission, pos, parent):
177 self.mission = mission 176 self.mission = mission
178 self.parent = parent 177 self.parent = parent
179 self.game = self.parent.game 178 self.game = self.parent.game
236 class EquipWidget(BigButton): 235 class EquipWidget(BigButton):
237 236
238 WIDTH = 260 237 WIDTH = 260
239 HEIGHT = 48 238 HEIGHT = 48
240 239
241 BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png')) 240 BG_IMAGE_NORMAL = load_image('images/science_normal.png')
242 BG_IMAGE_DOWN = image.load(filepath('images/science_down.png')) 241 BG_IMAGE_DOWN = load_image('images/science_down.png')
243 BG_IMAGE_UNAVAILABLE = image.load(filepath('images/equip_grey.png')) 242 BG_IMAGE_UNAVAILABLE = load_image('images/equip_grey.png')
244 243
245 def __init__(self, equip, pos, parent, copies, available): 244 def __init__(self, equip, pos, parent, copies, available):
246 self.equip = equip 245 self.equip = equip
247 self.parent = parent 246 self.parent = parent
248 self.available = available 247 self.available = available
432 431
433 def _make_win_screen(self, turn, msg): 432 def _make_win_screen(self, turn, msg):
434 # Clear existing widgets, and turn this into a won screen 433 # Clear existing widgets, and turn this into a won screen
435 for child in self.children[:]: 434 for child in self.children[:]:
436 self.remove_child(child) 435 self.remove_child(child)
436 # Replace background
437 self.background_image = load_image('images/main_background.jpg')
437 exitbut = ExitGameButton() 438 exitbut = ExitGameButton()
439 # FIXME: 1:20 minutes to hackery here
440 exitbut.rect.topleft = (500, 350)
438 self.add_child(exitbut) 441 self.add_child(exitbut)
439 title = TextLabel((200, 20, 400, 50), "Results for turn %d" % turn, 442 title = TextLabel((500, 20, 200, 50), "Results for turn %d" % turn,
440 font_medium, (255, 255, 255)) 443 font_medium, (255, 255, 255))
441 self.add_child(title) 444 self.add_child(title)
442 won = TextBox((200, 200, 400, 50), "You've succeeded in your quest", 445 won = TextBox((400, 200, 400, 50), "You've succeeded in your quest",
443 font_large, (255, 255, 255)) 446 font_large, (255, 255, 255))
444 self.add_child(won) 447 self.add_child(won)
445 won = TextBox((200, 250, 400, 50), msg, font_large, 448 won = TextBox((450, 250, 400, 50), msg, font_large,
446 (255, 255, 255)) 449 (255, 255, 255))
447 self.add_child(won) 450 self.add_child(won)
448 451
449 452
450 class GameStateWindow(Window): 453 class GameStateWindow(Window):
556 class DevelopmentWindow(GameStateWindow): 559 class DevelopmentWindow(GameStateWindow):
557 """Window for handling schematics research""" 560 """Window for handling schematics research"""
558 561
559 def __init__(self, screen, lab): 562 def __init__(self, screen, lab):
560 super(DevelopmentWindow, self).__init__(screen, lab.game) 563 super(DevelopmentWindow, self).__init__(screen, lab.game)
561 self.background_image = image.load( 564 self.background_image = load_image('images/engineering_background.jpg')
562 filepath('images/engineering_background.jpg'))
563 self.lab = lab 565 self.lab = lab
564 566
565 labbut = SwitchWinButton((150, 0), 'SCIENCE!!', lab) 567 labbut = SwitchWinButton((150, 0), 'SCIENCE!!', lab)
566 self.add_child(labbut) 568 self.add_child(labbut)
567 self.activity = None 569 self.activity = None
626 628
627 def __init__(self, screen, game_dict): 629 def __init__(self, screen, game_dict):
628 self.game = Game(game_dict) 630 self.game = Game(game_dict)
629 super(LabWindow, self).__init__(screen, self.game) 631 super(LabWindow, self).__init__(screen, self.game)
630 self.autosave = get_save_filename() 632 self.autosave = get_save_filename()
631 self.background_image = image.load( 633 self.background_image = load_image('images/lab_background.jpg')
632 filepath('images/lab_background.jpg'))
633 634
634 # Ensure we setup everything with the correct state set 635 # Ensure we setup everything with the correct state set
635 self.game.start_turn() 636 self.game.start_turn()
636 637
637 self.develop = DevelopmentWindow(screen, self) 638 self.develop = DevelopmentWindow(screen, self)