comparison gamelib/gui.py @ 150:0090ecf08544

Use blank placeholder for missing images
author Neil Muller <drnlmuller@gmail.com>
date Fri, 11 May 2012 17:17:44 +0200
parents 53277724645b
children 16ce5ed563c9
comparison
equal deleted inserted replaced
149:e49f2dba0ad4 150:0090ecf08544
1 import pygame
2
1 from gamelib import data 3 from gamelib import data
2 from gamelib.gui_base import Drawable, TextButton, font_auto, ToggleButton 4 from gamelib.gui_base import Drawable, TextButton, font_auto, ToggleButton
3 5
4 6
5 class ImageDrawable(Drawable): 7 class ImageDrawable(Drawable):
32 BG_IMAGE_NORMAL = data.load_image('images/research_normal.png') 34 BG_IMAGE_NORMAL = data.load_image('images/research_normal.png')
33 BG_IMAGE_DOWN = data.load_image('images/research_down.png') 35 BG_IMAGE_DOWN = data.load_image('images/research_down.png')
34 36
35 def __init__(self, pos, name): 37 def __init__(self, pos, name):
36 rect = (pos[0], pos[1], self.WIDTH, self.HEIGHT) 38 rect = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
37 n_icon = data.load_image('images/icons/%s_normal.png' % name) 39 try:
38 d_icon = data.load_image('images/icons/%s_down.png' % name) 40 n_icon = data.load_image('images/icons/%s_normal.png' % name)
41 d_icon = data.load_image('images/icons/%s_down.png' % name)
42 except:
43 n_icon = pygame.Surface((64, 64), pygame.SRCALPHA)
44 d_icon = pygame.Surface((64, 64), pygame.SRCALPHA)
39 n = ImageDrawable(rect, self.BG_IMAGE_NORMAL.copy()) 45 n = ImageDrawable(rect, self.BG_IMAGE_NORMAL.copy())
40 n.image.blit(n_icon, (0, 0)) 46 n.image.blit(n_icon, (0, 0))
41 d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy()) 47 d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy())
42 d.image.blit(d_icon, (0, 0)) 48 d.image.blit(d_icon, (0, 0))
43 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT) 49 rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
60 super(IconTextButton, self).__init__( 66 super(IconTextButton, self).__init__(
61 rect, n, d, text, font, shadow, text_rect) 67 rect, n, d, text, font, shadow, text_rect)
62 68
63 def _mk_image(self, name, suffix): 69 def _mk_image(self, name, suffix):
64 bg = data.load_image('images/button_%s.png' % (suffix,)) 70 bg = data.load_image('images/button_%s.png' % (suffix,))
65 icon = data.load_image('images/icons/%s_%s.png' % (name, suffix)) 71 try:
72 icon = data.load_image('images/icons/%s_%s.png' % (name, suffix))
73 except pygame.error:
74 icon = pygame.Surface((64, 64), pygame.SRCALPHA)
66 drawable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), bg.copy()) 75 drawable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), bg.copy())
67 drawable.image.blit(icon, (0, 0)) 76 drawable.image.blit(icon, (0, 0))
68 return drawable 77 return drawable
69 78
70 79