Move all interface Windows to their own modules in interface.window
This commit is contained in:
parent
1e678ff47d
commit
a8bbc47668
5 changed files with 160 additions and 133 deletions
45
erynrl/interface/window/info.py
Normal file
45
erynrl/interface/window/info.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
'''
|
||||
Declares the InfoWindow.
|
||||
'''
|
||||
|
||||
from . import Window
|
||||
from ..color import HealthBar
|
||||
from ..percentage_bar import PercentageBar
|
||||
from ...geometry import Point, Rect
|
||||
from ...object import Hero
|
||||
|
||||
|
||||
class InfoWindow(Window):
|
||||
'''A window that displays information about the player'''
|
||||
|
||||
def __init__(self, bounds: Rect):
|
||||
super().__init__(bounds, framed=True)
|
||||
|
||||
self.turn_count: int = 0
|
||||
|
||||
drawable_area = self.drawable_bounds
|
||||
self.hit_points_bar = PercentageBar(
|
||||
position=Point(drawable_area.min_x + 6, drawable_area.min_y),
|
||||
width=20,
|
||||
colors=list(HealthBar.bar_colors()))
|
||||
|
||||
def update_hero(self, hero: Hero):
|
||||
'''Update internal state for the hero'''
|
||||
assert hero.fighter
|
||||
|
||||
fighter = hero.fighter
|
||||
hp, max_hp = fighter.hit_points, fighter.maximum_hit_points
|
||||
|
||||
self.hit_points_bar.percent_filled = hp / max_hp
|
||||
|
||||
def draw(self, console):
|
||||
super().draw(console)
|
||||
|
||||
drawable_bounds = self.drawable_bounds
|
||||
console.print(x=drawable_bounds.min_x + 2, y=drawable_bounds.min_y, string='HP:')
|
||||
self.hit_points_bar.render_to_console(console)
|
||||
|
||||
if self.turn_count:
|
||||
console.print(x=drawable_bounds.min_x, y=drawable_bounds.min_y + 1, string=f'Turn: {self.turn_count}')
|
||||
Loading…
Add table
Add a link
Reference in a new issue