From: adrianna Date: Sat, 10 Sep 2016 22:54:09 +0000 (+0200) Subject: added exit button to load level screen X-Git-Tag: tabakrolletjie-v1.0.0~18^2~1 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=107db4ceddddbffa91e8969c3956be10058e2efc;p=tabakrolletjie.git added exit button to load level screen --- diff --git a/tabakrolletjie/scenes/load_level.py b/tabakrolletjie/scenes/load_level.py index 7f3223f..015a5f6 100644 --- a/tabakrolletjie/scenes/load_level.py +++ b/tabakrolletjie/scenes/load_level.py @@ -7,7 +7,7 @@ import pygame.locals as pgl from .base import BaseScene from ..constants import SCREEN_SIZE from ..events import SceneChangeEvent -from ..widgets import TextButton +from ..widgets import TextButton, ImageButton from ..loader import loader @@ -35,12 +35,24 @@ class LoadLevelScene(BaseScene): height += button.get_height() + 20 self._buttons.append(button) + self._tools = self.create_tools(gamestate) + + def create_tools(self, gamestate): + tools = [] + tools.append(ImageButton( + '32', 'exit.png', name='exit', + pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40))) + return tools + def render(self, surface, gamestate): surface.fill((0, 128, 128)) self._title.render(surface) for button in self._buttons: button.render(surface) + for tool in self._tools: + tool.render(surface) + def _get_pressed(self, ev): for button in self._buttons: if button.pressed(ev): @@ -62,3 +74,10 @@ class LoadLevelScene(BaseScene): pressed = self._get_pressed(ev) if pressed: self._do_load(pressed.station, gamestate) + else: + # Check tools + for tool in self._tools: + if tool.pressed(ev): + if tool.name == 'exit': + from .menu import MenuScene + SceneChangeEvent.post(scene=MenuScene())