projects
/
tabakrolletjie.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6c66ede
)
added tooltips for all the other tools
author
adrianna
<adrianna.pinska@gmail.com>
Fri, 16 Sep 2016 15:04:01 +0000
(17:04 +0200)
committer
adrianna
<adrianna.pinska@gmail.com>
Fri, 16 Sep 2016 15:04:01 +0000
(17:04 +0200)
tabakrolletjie/lights.py
patch
|
blob
|
history
tabakrolletjie/scenes/day.py
patch
|
blob
|
history
tabakrolletjie/scenes/help.py
patch
|
blob
|
history
tabakrolletjie/scenes/load_level.py
patch
|
blob
|
history
tabakrolletjie/scenes/night.py
patch
|
blob
|
history
tabakrolletjie/widgets.py
patch
|
blob
|
history
diff --git
a/tabakrolletjie/lights.py
b/tabakrolletjie/lights.py
index 00f4c85b6e6f767fa761f920afc31ba2db6e5fb3..ac6f08e38c279ec39d2847e2b181ca43b5a5eb6a 100644
(file)
--- a/
tabakrolletjie/lights.py
+++ b/
tabakrolletjie/lights.py
@@
-148,6
+148,12
@@
def light_info(light_config):
return cls.get_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. """
class BaseLight(object):
""" Common light functionality. """
@@
-156,6
+162,7
@@
class BaseLight(object):
FITTING_IMG = None
FITTING_RADIUS = 24.0
BASE_COST = 0
FITTING_IMG = None
FITTING_RADIUS = 24.0
BASE_COST = 0
+ NAME = "light"
# cached surfaces
_surface_cache = {}
# cached surfaces
_surface_cache = {}
@@
-335,6
+342,7
@@
class Lamp(BaseLight):
FITTING_IMG = "lamp.png"
BASE_COST = 1
FITTING_IMG = "lamp.png"
BASE_COST = 1
+ NAME = "lamp"
class PulsatingLamp(BaseLight):
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
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)
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
FITTING_IMG = "spotlight.png"
BASE_COST = 5
+ NAME = "spotlight"
def __init__(self, **kw):
self.angular_velocity = kw.pop("angular_velocity", None)
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 a43517cd92efa0574515be687539f7cb58c006d2..ecab05f289814b6bc39d0e883c28a4b0bd43e342 100644
(file)
--- 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 .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
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
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"]:
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
'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(
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(
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',
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(
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):
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)
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 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:
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)
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
self._light_toolbar.append(light_tool)
x += 40
diff --git
a/tabakrolletjie/scenes/help.py
b/tabakrolletjie/scenes/help.py
index 4ec31fc5d7e9b083b5940821f150f6fc5eff3bd1..d44e8f67cd6b38f6cb6a15f05058992d73ee049a 100644
(file)
--- 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
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
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',
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):
return tools
def create_items(self, gamestate):
diff --git
a/tabakrolletjie/scenes/load_level.py
b/tabakrolletjie/scenes/load_level.py
index 015a5f69bb6b8b378d2c52db1e0c104521f2c5b6..af7bf6afaa350f1e8301ef4ff5a310b09a6d8cbe 100644
(file)
--- 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 .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
from ..loader import loader
@@
-41,7
+41,7
@@
class LoadLevelScene(BaseScene):
tools = []
tools.append(ImageButton(
'32', 'exit.png', name='exit',
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):
return tools
def render(self, surface, gamestate):
diff --git
a/tabakrolletjie/scenes/night.py
b/tabakrolletjie/scenes/night.py
index 9f86745a052aa142acb72654a6519b3a44bf9cc9..5d55231808cb99db92afc3752abbc5d1eefd1f26 100644
(file)
--- 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 ..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)
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
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',
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(
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
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)
@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"
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)
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
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:
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()
if not self.turnip_count and not self._battery.current:
self._end_night()
diff --git
a/tabakrolletjie/widgets.py
b/tabakrolletjie/widgets.py
index 166cfc0dc84ae88dcd330fc6cdb8cf83f462b112..5d58d29bd0f3e151e9d28f7f8b2863fb3583fcd2 100644
(file)
--- a/
tabakrolletjie/widgets.py
+++ b/
tabakrolletjie/widgets.py
@@
-39,13
+39,13
@@
class Tooltip(object):
class Button(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._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 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,
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:
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,
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:
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)
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,
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())
def update_image(self, *imgparts, **kwargs):
transform = kwargs.pop("transform", NullTransform())