1 # -*- coding: utf-8 -*-
3 """ A bar. With info. """
6 import pygame.locals as pgl
8 from .constants import FONTS
9 from .loader import loader
12 class InfoBar(object):
16 self, time_of_day, battery, scene,
17 color=(255, 255, 255), pos=(50, 10)):
18 self.time_of_day = time_of_day
19 self.battery = battery
23 self.template = u" ยท ".join([
24 "{time_of_day} {gamestate.days}",
25 "{gamestate.harvested}/{gamestate.turnip_target} turnips",
26 "{gamestate.seeds} seeds",
27 "{scene.turnip_count} plants",
28 "battery {battery.current}/{battery.max}",
29 "power usage {scene.power_usage}/h"
31 self._font = loader.load_font(FONTS['sans'], size=20)
35 def render(self, surface, gamestate):
36 self._update(gamestate)
37 surface.blit(self._infobar, self.pos, None)
39 def _update_infobar(self):
40 text_img = self._font.render(self._text, True, self.color)
41 width = text_img.get_width() + 10
42 height = text_img.get_height() + 10
43 self._infobar = pygame.surface.Surface(
44 (width, height), pgl.SWSURFACE).convert_alpha()
45 self._infobar.fill((0, 0, 0, 64))
46 self._infobar.blit(text_img, (5, 3), None)
48 def _update(self, gamestate):
50 "gamestate": gamestate, "battery": self.battery,
51 "scene": self.scene, "time_of_day": self.time_of_day,
53 text = self.template.format(**options)
54 if text != self._text:
56 self._update_infobar()
59 class CountDownBar(object):
60 """ Count Down Bar. """
62 def __init__(self, units="h", color=(255, 255, 255), pos=(1024, 10)):
66 self.template = "{remaining:d}{units}"
67 self._font = loader.load_font(FONTS['sans'], size=48)
72 def render(self, surface, remaining):
73 self._update(remaining)
74 surface.blit(self._countbar, self._dest, None)
76 def _update_countbar(self):
77 text_img = self._font.render(self._text, True, self.color)
78 width = text_img.get_width() + 10
79 height = text_img.get_height() + 10
80 self._countbar = pygame.surface.Surface(
81 (width, height), pgl.SWSURFACE).convert_alpha()
82 self._countbar.fill((0, 0, 0, 64))
83 self._countbar.blit(text_img, (5, 3), None)
84 self._dest = (self.pos[0] - width, self.pos[1])
86 def _update(self, remaining):
88 "remaining": remaining,
91 text = self.template.format(**options)
92 if text != self._text:
94 self._update_countbar()