changeset 212:16ce5ed563c9

Change science buttons
author Neil Muller <drnlmuller@gmail.com>
date Sat, 12 May 2012 20:17:28 +0200
parents ba7c0953853b
children 2d72e84a765b
files gamelib/gamegui.py gamelib/gui.py gamelib/gui_base.py
diffstat 3 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gamegui.py	Sat May 12 20:20:26 2012 +0200
+++ b/gamelib/gamegui.py	Sat May 12 20:17:28 2012 +0200
@@ -124,7 +124,8 @@
             pos, science.get_image_name(), self.make_text(), font_small)
 
     def make_text(self):
-        name = self.science.NAME[:4]
+        #name = self.science.NAME[:4]
+        name = self.science.NAME
         text = '%s: %d' % (name, self.science.points)
         if self.points > 0:
             text = "%s + %d" % (text, self.points)
@@ -577,10 +578,10 @@
                 widget = ScienceWidget(science, (x, y), self)
                 self.add_child(widget)
                 self._sciences.append(widget)
-                x += 200
+                x += widget.WIDTH + 10
                 if x >= WIDTH:
                     x = 0
-                    y += 100
+                    y += widget.HEIGHT + 5
 
     def end_turn(self):
         # Drop back to the research screen
@@ -647,10 +648,10 @@
                 widget = ScienceWidget(science, (x, y), self)
                 self.add_child(widget)
                 self._sciences.append(widget)
-                x += 200
+                x += widget.WIDTH + 10
                 if x >= WIDTH:
                     x = 0
-                    y += 100
+                    y += widget.HEIGHT + 5
 
     def update_widgets(self):
         self._make_science_widgets()
--- a/gamelib/gui.py	Sat May 12 20:20:26 2012 +0200
+++ b/gamelib/gui.py	Sat May 12 20:17:28 2012 +0200
@@ -51,10 +51,10 @@
 
 
 class IconTextButton(TextButton):
-    WIDTH = 128
-    HEIGHT = 64
+    WIDTH = 270
+    HEIGHT = 80
 
-    TEXT_OFFSET = (50, 0)
+    TEXT_OFFSET = (0, 60)
 
     def __init__(self, pos, name, text, font=font_auto, shadow=True):
         rect = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
@@ -64,16 +64,20 @@
                      (self.WIDTH - self.TEXT_OFFSET[0],
                       self.HEIGHT - self.TEXT_OFFSET[1]))
         super(IconTextButton, self).__init__(
-            rect, n, d, text, font, shadow, text_rect)
+            rect, n, d, text, font, shadow, text_rect,
+            (255, 255, 255), (128, 128, 128))
 
     def _mk_image(self, name, suffix):
-        bg = data.load_image('images/button_%s.png' % (suffix,))
+        bg = data.load_image('images/research_%s.png' % (suffix,))
         try:
             icon = data.load_image('images/icons/%s_%s.png' % (name, suffix))
         except pygame.error:
             icon = pygame.Surface((64, 64), pygame.SRCALPHA)
-        drawable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), bg.copy())
-        drawable.image.blit(icon, (0, 0))
+        base = pygame.Surface((self.WIDTH, self.HEIGHT), pygame.SRCALPHA)
+        base.blit(bg, (self.WIDTH / 2 - 32, 0))
+        drawable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), base)
+        # Centre icon
+        drawable.image.blit(icon, (self.WIDTH / 2 - 32, 0))
         return drawable
 
 
--- a/gamelib/gui_base.py	Sat May 12 20:20:26 2012 +0200
+++ b/gamelib/gui_base.py	Sat May 12 20:17:28 2012 +0200
@@ -156,7 +156,8 @@
 class TextButton(Button):
 
     def __init__(self, rect, normal_drawable, down_drawable, text, font,
-                 shadow, text_rect=None):
+                 shadow, text_rect=None, color=(0, 0, 0),
+                 shadow_color=(128, 128, 128)):
         super(TextButton, self).__init__(rect, normal_drawable, down_drawable)
         self.text_rect = Rect((0, 0), self.rect.size)
         if text_rect is not None:
@@ -166,6 +167,8 @@
             font = self._auto_font()
         self.font = font
         self.shadow = shadow
+        self.shadow_color = shadow_color
+        self.color = color
         self._draw_text()
 
     def _auto_font(self):
@@ -177,10 +180,10 @@
 
     def _draw_text(self):
         self.font.set_bold(True)
-        self.text_surface = self.font.render(self.text, True, (0, 0, 0))
+        self.text_surface = self.font.render(self.text, True, self.color)
         size = self.font.size(self.text)
         if self.shadow:
-            s = self.font.render(self.text, True, (128, 128, 128))
+            s = self.font.render(self.text, True, self.shadow_color)
             temp = Surface((s.get_width() + 1, s.get_width() + 1), SRCALPHA)
             temp.fill((255, 255, 255, 0))
             temp.blit(s, (1, 1))