added tooltips for all the other tools
authoradrianna <adrianna.pinska@gmail.com>
Fri, 16 Sep 2016 15:04:01 +0000 (17:04 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Fri, 16 Sep 2016 15:04:01 +0000 (17:04 +0200)
tabakrolletjie/lights.py
tabakrolletjie/scenes/day.py
tabakrolletjie/scenes/help.py
tabakrolletjie/scenes/load_level.py
tabakrolletjie/scenes/night.py
tabakrolletjie/widgets.py

index 00f4c85b6e6f767fa761f920afc31ba2db6e5fb3..ac6f08e38c279ec39d2847e2b181ca43b5a5eb6a 100644 (file)
@@ -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)
index a43517cd92efa0574515be687539f7cb58c006d2..ecab05f289814b6bc39d0e883c28a4b0bd43e342 100644 (file)
@@ -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
index 4ec31fc5d7e9b083b5940821f150f6fc5eff3bd1..d44e8f67cd6b38f6cb6a15f05058992d73ee049a 100644 (file)
@@ -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):
index 015a5f69bb6b8b378d2c52db1e0c104521f2c5b6..af7bf6afaa350f1e8301ef4ff5a310b09a6d8cbe 100644 (file)
@@ -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):
index 9f86745a052aa142acb72654a6519b3a44bf9cc9..5d55231808cb99db92afc3752abbc5d1eefd1f26 100644 (file)
@@ -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()
 
index 166cfc0dc84ae88dcd330fc6cdb8cf83f462b112..5d58d29bd0f3e151e9d28f7f8b2863fb3583fcd2 100644 (file)
@@ -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())