diff gamelib/gamegui.py @ 145:53277724645b

Science button juggling.
author Jeremy Thurgood <firxen@gmail.com>
date Fri, 11 May 2012 14:58:00 +0200
parents 07be37129447
children abaf6853fe37
line wrap: on
line diff
--- a/gamelib/gamegui.py	Fri May 11 10:15:40 2012 +0200
+++ b/gamelib/gamegui.py	Fri May 11 14:58:00 2012 +0200
@@ -15,7 +15,7 @@
 from gamelib.game_base import get_save_filename
 from gamelib.gui_base import (Window, TextLabel, TextBox, font_small,
         font_medium, font_large)
-from gamelib.gui import BigButton, ImageDrawable
+from gamelib.gui import BigButton, ImageDrawable, IconTextButton
 from gamelib.engine import PopWindow, AddWindow, GameOver
 from gamelib.constants import WIDTH, HEIGHT, FAILURE, SUCCESS, GAME_WIN, INFO
 from gamelib.gamestate import Game
@@ -91,19 +91,21 @@
         AddWindow.post(self.new_window)
 
 
-class ScienceWidget(BigButton):
-
-    WIDTH = 200
-
-    BG_IMAGE_NORMAL = image.load(filepath('images/science_normal.png'))
-    BG_IMAGE_DOWN = image.load(filepath('images/science_down.png'))
+class ScienceWidget(IconTextButton):
 
     def __init__(self, science, pos, parent):
         self.science = science
         self.points = 0
         self.parent = parent
-        super(ScienceWidget, self).__init__(pos, '%s: %d' % (science.NAME,
-            science.points), font_small)
+        super(ScienceWidget, self).__init__(
+            pos, science.get_image_name(), self.make_text(), font_small)
+
+    def make_text(self):
+        name = self.science.NAME[:4]
+        text = '%s: %d' % (name, self.science.points)
+        if self.points > 0:
+            text = "%s + %d" % (text, self.points)
+        return text
 
     def on_click(self):
         if (self.parent.game.get_available_points() > 0 and
@@ -114,11 +116,7 @@
             self.set_text()
 
     def set_text(self):
-        if self.points > 0:
-            self.text = '%s: %d + %d' % (self.science.NAME,
-                    self.science.points, self.points)
-        else:
-            self.text = '%s: %d' % (self.science.NAME, self.science.points)
+        self.text = self.make_text()
         self._draw_text()
 
     def reset(self):