# HG changeset patch # User Rizmari Versfeld # Date 1336698802 -7200 # Node ID 821ecb98e8884947a029a86c945362397dc5b0d9 # Parent 3e02a8ccd72b278e5d5957f578920ba6db0da42e some icons and toggle button diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/artificialintelligence_down.png Binary file data/images/icons/artificialintelligence_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/artificialintelligence_normal.png Binary file data/images/icons/artificialintelligence_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/biogenetics_down.png Binary file data/images/icons/biogenetics_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/biogenetics_normal.png Binary file data/images/icons/biogenetics_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/electrickery_down.png Binary file data/images/icons/electrickery_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/electrickery_normal.png Binary file data/images/icons/electrickery_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/fusion_down.png Binary file data/images/icons/fusion_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/fusion_normal.png Binary file data/images/icons/fusion_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/lasers_down.png Binary file data/images/icons/lasers_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/lasers_normal.png Binary file data/images/icons/lasers_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/medicalexperiments_down.png Binary file data/images/icons/medicalexperiments_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/medicalexperiments_normal.png Binary file data/images/icons/medicalexperiments_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/meteorology2_down.png Binary file data/images/icons/meteorology2_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/meteorology2_normal.png Binary file data/images/icons/meteorology2_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/meteorology_down.png Binary file data/images/icons/meteorology_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/meteorology_normal.png Binary file data/images/icons/meteorology_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/physics_down.png Binary file data/images/icons/physics_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/physics_normal.png Binary file data/images/icons/physics_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/space_down.png Binary file data/images/icons/space_down.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 data/images/icons/space_normal.png Binary file data/images/icons/space_normal.png has changed diff -r 3e02a8ccd72b -r 821ecb98e888 gamelib/constants.py --- 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 diff -r 3e02a8ccd72b -r 821ecb98e888 gamelib/gui.py --- 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") diff -r 3e02a8ccd72b -r 821ecb98e888 gamelib/gui_base.py --- 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): diff -r 3e02a8ccd72b -r 821ecb98e888 gamelib/mainmenu.py --- 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()