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. """
FITTING_IMG = None
FITTING_RADIUS = 24.0
BASE_COST = 0
+ NAME = "light"
# cached surfaces
_surface_cache = {}
FITTING_IMG = "lamp.png"
BASE_COST = 1
+ NAME = "lamp"
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)
FITTING_IMG = "spotlight.png"
BASE_COST = 5
+ NAME = "spotlight"
def __init__(self, **kw):
self.angular_velocity = kw.pop("angular_velocity", None)
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
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"]:
'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):
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:
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
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
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):
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
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):
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)
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)
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
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()
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
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:
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:
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())