From 5ee3a75030e3e36aed530aa89394982cfe711da2 Mon Sep 17 00:00:00 2001 From: adrianna Date: Fri, 16 Sep 2016 17:04:01 +0200 Subject: [PATCH] added tooltips for all the other tools --- tabakrolletjie/lights.py | 10 ++++++++++ tabakrolletjie/scenes/day.py | 22 +++++++++++----------- tabakrolletjie/scenes/help.py | 4 ++-- tabakrolletjie/scenes/load_level.py | 4 ++-- tabakrolletjie/scenes/night.py | 18 +++++++++--------- tabakrolletjie/widgets.py | 11 ++++++----- 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 00f4c85..ac6f08e 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -148,6 +148,12 @@ def light_info(light_config): return cls.get_info(light_config) +def light_name(light_config): + """Find formatted light name. """ + cls = BaseLight.find_cls(light_config["type"]) + return cls.NAME + + class BaseLight(object): """ Common light functionality. """ @@ -156,6 +162,7 @@ class BaseLight(object): FITTING_IMG = None FITTING_RADIUS = 24.0 BASE_COST = 0 + NAME = "light" # cached surfaces _surface_cache = {} @@ -335,6 +342,7 @@ class Lamp(BaseLight): FITTING_IMG = "lamp.png" BASE_COST = 1 + NAME = "lamp" class PulsatingLamp(BaseLight): @@ -345,6 +353,7 @@ class PulsatingLamp(BaseLight): DEFAULT_INTENSITY_RANGE = (0.0, 0.9) DEFAULT_INTENSITY_VELOCITY = 0.1 BASE_COST = 3 + NAME = "pulsating lamp" def __init__(self, **kw): self.pulse_range = kw.pop("pulse_range", self.DEFAULT_PULSE_RANGE) @@ -407,6 +416,7 @@ class SpotLight(BaseLight): FITTING_IMG = "spotlight.png" BASE_COST = 5 + NAME = "spotlight" def __init__(self, **kw): self.angular_velocity = kw.pop("angular_velocity", None) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index a43517c..ecab05f 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -11,7 +11,7 @@ import pymunk.pygame_util from .base import BaseScene from ..battery import BatteryManager -from ..lights import LightManager, light_fitting_by_type, check_space_for_light, seed_cost, light_info +from ..lights import LightManager, light_fitting_by_type, check_space_for_light, seed_cost, light_info, light_name from ..infobar import InfoBar from ..obstacles import ObstacleManager from ..events import SceneChangeEvent @@ -96,7 +96,7 @@ class DayScene(BaseScene): x, y, step = 50, SCREEN_SIZE[1] - 40, 50 - tools.append(ImageButton('32', 'seed.png', name='seed', pos=(x, y))) + tools.append(ImageButton('32', 'seed.png', name='seed', pos=(x, y), tooltip=Tooltip(["Plant seed"]))) x += step for light_config in gamestate.station["available_lights"]: @@ -104,21 +104,23 @@ class DayScene(BaseScene): '32', '%s.png' % light_config["type"], name='light', pos=(x, y)) tool.light_config = light_config + tool_name = light_name(light_config) + tool.tooltip = Tooltip(["Place %s" % tool_name]) tools.append(tool) x += step tools.append(ImageButton( - '32', 'remove.png', name='remove light', pos=(x, y))) + '32', 'remove.png', name='remove light', pos=(x, y), tooltip=Tooltip(["Remove light"]))) x += step tools.append(ImageButton( - '32', 'default_cursor.png', name='reset tool', pos=(x, y))) + '32', 'default_cursor.png', name='reset tool', pos=(x, y), tooltip=Tooltip(["Reset tool"]))) tools.append(ImageButton( '32', 'night.png', name='start night', - pos=(SCREEN_SIZE[0] - 100, y))) + pos=(SCREEN_SIZE[0] - 100, y), tooltip=Tooltip(["Start night"]))) tools.append(ImageButton( - '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y))) + '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y), tooltip=Tooltip(["Exit"]))) return tools def exit(self, gamestate): @@ -155,10 +157,10 @@ class DayScene(BaseScene): self._obstacles.render(surface) self._lights.render_fittings(surface) self._infobar.render(surface, gamestate) - for tool in self._tools: - tool.render(surface) for light_tool in self._light_toolbar: light_tool.render(surface) + for tool in self._tools: + tool.render(surface) self._draw_cursor(surface) if self._game_over_text: @@ -182,9 +184,7 @@ class DayScene(BaseScene): light_tool.cost = cost tooltip_text = ["cost: %d" % cost] + light_info(light_config) - - tooltip = Tooltip(tooltip_text) - light_tool.tooltip = tooltip + light_tool.tooltip = Tooltip(tooltip_text) self._light_toolbar.append(light_tool) x += 40 diff --git a/tabakrolletjie/scenes/help.py b/tabakrolletjie/scenes/help.py index 4ec31fc..d44e8f6 100644 --- a/tabakrolletjie/scenes/help.py +++ b/tabakrolletjie/scenes/help.py @@ -6,7 +6,7 @@ import pymunk import pygame.locals as pgl from .base import BaseScene -from ..widgets import ImageButton +from ..widgets import ImageButton, Tooltip from ..constants import SCREEN_SIZE, FONTS, COLOURS from ..loader import loader from ..events import SceneChangeEvent @@ -52,7 +52,7 @@ class HelpScene(BaseScene): tools = [] tools.append(ImageButton( '32', 'exit.png', name='exit', - pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40))) + pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40), tooltip=Tooltip(["Exit"]))) return tools def create_items(self, gamestate): diff --git a/tabakrolletjie/scenes/load_level.py b/tabakrolletjie/scenes/load_level.py index 015a5f6..af7bf6a 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, ImageButton +from ..widgets import TextButton, ImageButton, Tooltip from ..loader import loader @@ -41,7 +41,7 @@ class LoadLevelScene(BaseScene): tools = [] tools.append(ImageButton( '32', 'exit.png', name='exit', - pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40))) + pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40), tooltip=Tooltip(["Exit"]))) return tools def render(self, surface, gamestate): diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 9f86745..5d55231 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -17,7 +17,7 @@ from ..loader import loader from ..sound import sound from ..transforms import Overlay from ..turnip import Turnip -from ..widgets import ImageButton +from ..widgets import ImageButton, Tooltip from ..constants import ( NIGHT_LENGTH, NIGHT_HOURS_PER_TICK, DEBUG, FONTS, SCREEN_SIZE, FPS) @@ -54,18 +54,16 @@ class NightScene(BaseScene): def create_tools(self, gamestate): tools = [] y = SCREEN_SIZE[1] - 40 + tools.append(ImageButton( + '32', 'day.png', name='day', pos=(SCREEN_SIZE[0] - 200, y), tooltip=Tooltip(["Skip to day"]))) tools.append(ImageButton( '32', 'pause.png', name='pause play', - pos=(SCREEN_SIZE[0] - 150, y))) + pos=(SCREEN_SIZE[0] - 150, y), tooltip=Tooltip(["Pause"]))) tools.append(ImageButton( - '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y))) + '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y), tooltip=Tooltip(["Exit"]))) + tools[0].disable() return tools - def add_day_button(self): - y = SCREEN_SIZE[1] - 40 - self._tools.append(ImageButton( - '32', 'day.png', name='day', pos=(SCREEN_SIZE[0] - 200, y))) - @property def turnip_count(self): return len(self._turnips) @@ -144,9 +142,11 @@ class NightScene(BaseScene): def toggle_pause(self): self._paused = not self._paused pause_img = "play.png" if self._paused else "pause.png" + pause_text = "Play" if self._paused else "Pause" for tool in self._tools: if tool.name == 'pause play': tool.update_image("32", pause_img) + tool.tooltip = Tooltip([pause_text]) def _to_day(self, gamestate): # End the night @@ -204,7 +204,7 @@ class NightScene(BaseScene): if not self._mould.alive(): self._end_night() if not self.turnip_count: - self.add_day_button() + self._tools[0].enable() if not self.turnip_count and not self._battery.current: self._end_night() diff --git a/tabakrolletjie/widgets.py b/tabakrolletjie/widgets.py index 166cfc0..5d58d29 100644 --- a/tabakrolletjie/widgets.py +++ b/tabakrolletjie/widgets.py @@ -39,13 +39,13 @@ class Tooltip(object): class Button(object): - def __init__(self, size, name=None, pos=None, padding=10): + def __init__(self, size, name=None, pos=None, padding=10, tooltip=None): self._size = size self._padding = padding self.position = pos self.name = name self.enabled = True - self.tooltip = None + self.tooltip = tooltip def enable(self): self.enabled = True @@ -114,7 +114,7 @@ class TextButton(Button): def __init__( self, text, colour, name=None, pos=None, padding=10, size=24, - font='sans', centre=False): + font='sans', centre=False, tooltip=None): font = loader.load_font(FONTS[font], size=size) self._text = font.render(text, True, colour) if centre: @@ -123,7 +123,7 @@ class TextButton(Button): self._disabled_text = self._text.copy() Multiply(colour=(80, 80, 80)).apply(self._disabled_text) super(TextButton, self).__init__(self._text.get_size(), name, - pos, padding) + pos, padding, tooltip) def render(self, surface): if self.enabled: @@ -147,8 +147,9 @@ class ImageButton(Button): name = kwargs.get('name') pos = kwargs.get('pos') padding = kwargs.get('padding', 0) + tooltip = kwargs.get('tooltip') super(ImageButton, self).__init__(self._img.get_size(), name, - pos, padding) + pos, padding, tooltip) def update_image(self, *imgparts, **kwargs): transform = kwargs.pop("transform", NullTransform()) -- 2.34.1