Add title to boxes to have pretty boxes, fixes #28
This commit is contained in:
@ -222,6 +222,10 @@ class HorizontalSplit(Display):
|
||||
|
||||
|
||||
class Box(Display):
|
||||
title: str = ""
|
||||
|
||||
def update_title(self, title: str) -> None:
|
||||
self.title = title
|
||||
|
||||
def __init__(self, *args, fg_border_color: Optional[int] = None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -236,5 +240,11 @@ class Box(Display):
|
||||
self.addstr(self.pad, i, self.width - 1, "┃", self.fg_border_color)
|
||||
self.addstr(self.pad, self.height - 1, 0,
|
||||
"┗" + "━" * (self.width - 2) + "┛", self.fg_border_color)
|
||||
|
||||
if self.title:
|
||||
self.addstr(self.pad, 0, (self.width - len(self.title) - 8) // 2,
|
||||
f" == {self.title} == ", curses.COLOR_GREEN,
|
||||
italic=True, bold=True)
|
||||
|
||||
self.refresh_pad(self.pad, 0, 0, self.y, self.x,
|
||||
self.y + self.height - 1, self.x + self.width - 1)
|
||||
|
@ -6,7 +6,7 @@ from random import randint
|
||||
from typing import List
|
||||
|
||||
from squirrelbattle.menus import Menu, MainMenu
|
||||
from .display import Display, Box
|
||||
from .display import Box, Display
|
||||
from ..enums import KeyValues
|
||||
from ..game import Game
|
||||
from ..resources import ResourceManager
|
||||
@ -135,15 +135,12 @@ class MainMenuDisplay(Display):
|
||||
|
||||
|
||||
class PlayerInventoryDisplay(MenuDisplay):
|
||||
message = _("== INVENTORY ==")
|
||||
|
||||
def update_pad(self) -> None:
|
||||
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
|
||||
self.message, bold=True, italic=True)
|
||||
self.menubox.update_title(_("INVENTORY"))
|
||||
for i, item in enumerate(self.menu.values):
|
||||
rep = self.pack[item.name.upper()]
|
||||
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
|
||||
self.addstr(self.pad, 2 + i, 0, selection
|
||||
self.addstr(self.pad, i + 1, 0, selection
|
||||
+ " " + item.translated_name.capitalize())
|
||||
|
||||
@property
|
||||
@ -163,15 +160,12 @@ class PlayerInventoryDisplay(MenuDisplay):
|
||||
|
||||
|
||||
class StoreInventoryDisplay(MenuDisplay):
|
||||
message = _("== STALL ==")
|
||||
|
||||
def update_pad(self) -> None:
|
||||
self.addstr(self.pad, 0, (self.width - len(self.message)) // 2,
|
||||
self.message, bold=True, italic=True)
|
||||
self.menubox.update_title(_("STALL"))
|
||||
for i, item in enumerate(self.menu.values):
|
||||
rep = self.pack[item.name.upper()]
|
||||
selection = f"[{rep}]" if i == self.menu.position else f" {rep} "
|
||||
self.addstr(self.pad, 2 + i, 0, selection
|
||||
self.addstr(self.pad, i + 1, 0, selection
|
||||
+ " " + item.translated_name.capitalize()
|
||||
+ ": " + str(item.price) + " Hazels")
|
||||
|
||||
|
Reference in New Issue
Block a user