Add infobar.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 16:38:13 +0000 (18:38 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 16:38:13 +0000 (18:38 +0200)
tabakrolletjie/infobar.py [new file with mode: 0644]

diff --git a/tabakrolletjie/infobar.py b/tabakrolletjie/infobar.py
new file mode 100644 (file)
index 0000000..f468ef6
--- /dev/null
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+""" A bar. With info. """
+
+import pygame.surface
+import pygame.locals as pgl
+
+from .constants import FONTS
+from .loader import loader
+
+
+class InfoBar(object):
+    """ Info.bar. """
+
+    def __init__(
+            self, time_of_day, battery, scene,
+            color=(255, 255, 255), pos=(50, 10)):
+        self.time_of_day = time_of_day
+        self.battery = battery
+        self.scene = scene
+        self.color = color
+        self.pos = pos
+        self.template = u" ยท ".join([
+            "{time_of_day} {gamestate.days}",
+            "{gamestate.harvested}/{gamestate.turnip_target} turnips",
+            "{gamestate.seeds} seeds",
+            "{scene.turnip_count} plants",
+            "battery {battery.current}/{battery.max}",
+            "power usage {scene.power_usage}"
+        ])
+        self._font = loader.load_font(FONTS['sans'], size=20)
+
+    def render(self, surface):
+        surface.blit(self._infobar, self.pos, None)
+
+    def update(self, gamestate):
+        options = {
+            "gamestate": gamestate, "battery": self.battery,
+            "scene": self.scene, "time_of_day": self.time_of_day,
+        }
+        text = self.template.format(**options)
+        text_img = self._font.render(text, True, self.color)
+
+        width = text_img.get_width() + 10
+        height = text_img.get_height() + 10
+        self._infobar = pygame.surface.Surface(
+            (width, height), pgl.SWSURFACE).convert_alpha()
+        self._infobar.fill((0, 0, 0, 64))
+        self._infobar.blit(text_img, (5, 3), None)