Move all the interface stuff to interface.Interface

Draw three windows with frames:
- map window
- info window (hit point bar; turn count)
- message window

Clean up the UI code in the Engine.
This commit is contained in:
Eryn Wells 2023-02-11 01:21:52 -08:00
parent df4df06013
commit 6780b0495c
5 changed files with 114 additions and 21 deletions

View file

@ -13,6 +13,7 @@ import tcod
from .geometry import Rect
class Message:
'''A message in the message log
@ -44,6 +45,7 @@ class Message:
def __repr__(self) -> str:
return f'{self.__class__.__name__}({repr(self.text)}, fg={self.foreground})'
class MessageLog:
'''A buffer of messages sent to the player by the game'''
@ -76,12 +78,12 @@ class MessageLog:
@staticmethod
def render_messages(console: tcod.console.Console, rect: Rect, messages: Reversible[Message]):
'''Render a list of messages to the console in the given rect'''
y_offset = min(rect.size.height, len(messages))
y_offset = min(rect.size.height, len(messages)) - 1
for message in reversed(messages):
wrapped_text = textwrap.wrap(message.full_text, rect.size.width)
for line in wrapped_text:
console.print(x=rect.min_x, y=rect.min_y + y_offset - 1, string=line, fg=message.foreground)
console.print(x=rect.min_x, y=rect.min_y + y_offset, string=line, fg=message.foreground)
y_offset -= 1
if y_offset < 0: