Reshaped the game layout using new lines and boxes

This commit is contained in:
Nicolas Margulies
2020-11-20 18:07:09 +01:00
parent 9ca6561bc3
commit ca57fae19d
4 changed files with 26 additions and 34 deletions

View File

@ -1,16 +1,16 @@
from typing import List
from squirrelbattle.menus import Menu, MainMenu
from .display import Display
from .display import Display, Box
from ..resources import ResourceManager
class MenuDisplay(Display):
position: int
def __init__(self, *args):
super().__init__(*args)
self.menubox = self.newpad(self.rows, self.cols)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.menubox = Box(*args, **kwargs)
def update_menu(self, menu: Menu) -> None:
self.menu = menu
@ -34,16 +34,7 @@ class MenuDisplay(Display):
if self.height - 2 >= self.trueheight - self.menu.position else 0
# Menu box
self.menubox.clear()
self.menubox.addstr(0, 0, "" + "" * (self.width - 2) + "")
for i in range(1, self.height - 1):
self.menubox.addstr(i, 0, "" + " " * (self.width - 2) + "")
self.menubox.addstr(self.height - 1, 0,
"" + "" * (self.width - 2) + "")
self.menubox.refresh(0, 0, self.y, self.x,
self.height + self.y,
self.width + self.x)
self.menubox.refresh(self.y, self.x, self.height, self.width)
self.pad.clear()
self.update_pad()
self.pad.refresh(cornery, 0, self.y + 1, self.x + 2,
@ -90,7 +81,7 @@ class MainMenuDisplay(Display):
for i in range(len(self.title)):
self.pad.addstr(4 + i, max(self.width // 2
- len(self.title[0]) // 2 - 1, 0), self.title[i])
self.pad.refresh(0, 0, self.y, self.x, self.height, self.width)
self.pad.refresh(0, 0, self.y, self.x, self.height + self.y - 1, self.width + self.x - 1)
menuwidth = min(self.menudisplay.preferred_width, self.width)
menuy, menux = len(self.title) + 8, self.width // 2 - menuwidth // 2 - 1
self.menudisplay.refresh(