changeset 143:821ecb98e888

some icons and toggle button
author Rizmari Versfeld <rizziepit@gmail.com>
date Fri, 11 May 2012 03:13:22 +0200
parents 3e02a8ccd72b
children 221c340f5efd
files data/images/icons/artificialintelligence_down.png data/images/icons/artificialintelligence_normal.png data/images/icons/biogenetics_down.png data/images/icons/biogenetics_normal.png data/images/icons/electrickery_down.png data/images/icons/electrickery_normal.png data/images/icons/fusion_down.png data/images/icons/fusion_normal.png data/images/icons/lasers_down.png data/images/icons/lasers_normal.png data/images/icons/medicalexperiments_down.png data/images/icons/medicalexperiments_normal.png data/images/icons/meteorology2_down.png data/images/icons/meteorology2_normal.png data/images/icons/meteorology_down.png data/images/icons/meteorology_normal.png data/images/icons/physics_down.png data/images/icons/physics_normal.png data/images/icons/space_down.png data/images/icons/space_normal.png gamelib/constants.py gamelib/gui.py gamelib/gui_base.py gamelib/mainmenu.py
diffstat 24 files changed, 48 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
Binary file data/images/icons/artificialintelligence_down.png has changed
Binary file data/images/icons/artificialintelligence_normal.png has changed
Binary file data/images/icons/biogenetics_down.png has changed
Binary file data/images/icons/biogenetics_normal.png has changed
Binary file data/images/icons/electrickery_down.png has changed
Binary file data/images/icons/electrickery_normal.png has changed
Binary file data/images/icons/fusion_down.png has changed
Binary file data/images/icons/fusion_normal.png has changed
Binary file data/images/icons/lasers_down.png has changed
Binary file data/images/icons/lasers_normal.png has changed
Binary file data/images/icons/medicalexperiments_down.png has changed
Binary file data/images/icons/medicalexperiments_normal.png has changed
Binary file data/images/icons/meteorology2_down.png has changed
Binary file data/images/icons/meteorology2_normal.png has changed
Binary file data/images/icons/meteorology_down.png has changed
Binary file data/images/icons/meteorology_normal.png has changed
Binary file data/images/icons/physics_down.png has changed
Binary file data/images/icons/physics_normal.png has changed
Binary file data/images/icons/space_down.png has changed
Binary file data/images/icons/space_normal.png has changed
--- a/gamelib/constants.py	Fri May 11 00:28:35 2012 +0200
+++ b/gamelib/constants.py	Fri May 11 03:13:22 2012 +0200
@@ -1,7 +1,7 @@
 # The usual game constants
 
-WIDTH = 800
-HEIGHT = 600
+WIDTH = 1024
+HEIGHT = 768
 SCREEN = (WIDTH, HEIGHT)
 FPS = 30
 
--- a/gamelib/gui.py	Fri May 11 00:28:35 2012 +0200
+++ b/gamelib/gui.py	Fri May 11 03:13:22 2012 +0200
@@ -1,7 +1,7 @@
 from pygame import image
 
 from gamelib import data
-from gamelib.gui_base import Drawable, TextButton, font_auto, Button
+from gamelib.gui_base import Drawable, TextButton, font_auto, ToggleButton
 
 
 class ImageDrawable(Drawable):
@@ -28,7 +28,7 @@
         super(BigButton, self).__init__(rect2, n, d, text, font, shadow)
 
 
-class IconButton(Button):
+class IconButton(ToggleButton):
     WIDTH = 64
     HEIGHT = 64
     BG_IMAGE_NORMAL = image.load(data.filepath('images/research_normal.png'))
@@ -44,3 +44,19 @@
         d.image.blit(d_icon, (0, 0))
         rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
         super(IconButton, self).__init__(rect2, n, d)
+
+
+class RadioButton(IconButton):
+    SELECTED_BUTTON = None
+
+    def on_click(self):
+        print(RadioButton.CHECK)
+        super(RadioButton, self).on_click()
+        if self.toggled:
+            if RadioButton.SELECTED_BUTTON:
+                RadioButton.SELECTED_BUTTON.on_click()
+            RadioButton.SELECTED_BUTTON = self
+            print("I am selected")
+        else:
+            RadioButton.SELECTED_BUTTON = None
+            print("I am deselected")
--- a/gamelib/gui_base.py	Fri May 11 00:28:35 2012 +0200
+++ b/gamelib/gui_base.py	Fri May 11 03:13:22 2012 +0200
@@ -197,6 +197,20 @@
         surface.blit(self.surface, self.rect)
 
 
+class ToggleButton(Button):
+
+    def __init__(self, rect, normal_drwble, down_drwble):
+        super(ToggleButton, self).__init__(rect, normal_drwble, down_drwble)
+        self.toggled = False
+
+    def on_click(self):
+        self.toggled = not self.toggled
+        if self.toggled:
+            self.set_state('DOWN')
+        else:
+            self.set_state('NORMAL')
+
+
 class TextLabel(Drawable):
 
     def __init__(self, rect, text, font, color):
--- a/gamelib/mainmenu.py	Fri May 11 00:28:35 2012 +0200
+++ b/gamelib/mainmenu.py	Fri May 11 03:13:22 2012 +0200
@@ -15,7 +15,7 @@
 
 from gamelib import data
 from gamelib.gui_base import Window
-from gamelib.gui import BigButton, IconButton
+from gamelib.gui import BigButton, RadioButton
 from gamelib.engine import AddWindow
 from gamelib.gamegui import LabWindow
 
@@ -72,9 +72,19 @@
         self.screen = screen
         self.background_colour = (0, 0, 0)
         self.background_image = image.load(data.filepath('images/temp.jpg'))
-        self.add_child(IconButton((0, 0), 'rocketry'))
-        self.add_child(IconButton((64, 0), 'marinebiology'))
-        self.add_child(IconButton((128, 0), 'robotics'))
+        self.add_child(RadioButton((0, 0), 'rocketry'))
+        self.add_child(RadioButton((64, 0), 'marinebiology'))
+        self.add_child(RadioButton((128, 0), 'robotics'))
+        self.add_child(RadioButton((192, 0), 'artificialintelligence'))
+        self.add_child(RadioButton((256, 0), 'space'))
+        self.add_child(RadioButton((320, 0), 'fusion'))
+        self.add_child(RadioButton((384, 0), 'electrickery'))
+        self.add_child(RadioButton((448, 0), 'lasers'))
+        self.add_child(RadioButton((512, 0), 'meteorology'))
+        self.add_child(RadioButton((576, 0), 'meteorology2'))
+        self.add_child(RadioButton((640, 0), 'physics'))
+        self.add_child(RadioButton((704, 0), 'biogenetics'))
+        self.add_child(RadioButton((768, 0), 'medicalexperiments'))
         button1 = NewGameButton(self)
         self.add_child(button1)
         button2 = QuitButton()