Display main menu by default
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
from dungeonbattle.display.display import Display
|
||||
from dungeonbattle.menus import Menu
|
||||
from typing import Any
|
||||
import curses
|
||||
|
||||
|
||||
class MenuDisplay:
|
||||
def __init__(self, menu: Menu, screen: Any, height: int, width: int,
|
||||
class MenuDisplay(Display):
|
||||
def __init__(self, screen: Any, menu: Menu,
|
||||
topleftx: int, toplefty: int):
|
||||
self.screen = screen
|
||||
self.position = menu.position
|
||||
super().__init__(screen)
|
||||
self.values = menu.values
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.menu = menu
|
||||
self.width = self.cols
|
||||
self.height = self.rows
|
||||
self.trueheight = len(menu.values)
|
||||
self.truewidth = max(map(len, self.values))
|
||||
self.truewidth = max(len(item.value) for item in menu.values)
|
||||
self.topleftx = topleftx
|
||||
self.toplefty = toplefty
|
||||
|
||||
# Menu values are printed in pad
|
||||
self.pad = curses.newpad(self.trueheight, self.truewidth + 1)
|
||||
for i in range(self.trueheight - 1):
|
||||
self.pad.addstr(i, 0, " " + self.values[i])
|
||||
for i in range(self.trueheight):
|
||||
self.pad.addstr(i, 0, " " + self.values[i].value)
|
||||
|
||||
# Menu box
|
||||
self.menubox = curses.newpad(self.height, self.width)
|
||||
@@ -35,16 +36,16 @@ class MenuDisplay:
|
||||
# set a marker in front of the selected line
|
||||
self.pad.addstr(position, 0, ">")
|
||||
|
||||
def refresh(self, position: int) -> None:
|
||||
if self.height - 2 >= position - 1:
|
||||
def refresh(self) -> None:
|
||||
if self.height - 2 >= self.menu.position - 1:
|
||||
cornery = 0
|
||||
elif self.height - 2 >= self.trueheight - position:
|
||||
elif self.height - 2 >= self.trueheight - self.menu.position:
|
||||
cornery = self.trueheight - self.height + 2
|
||||
|
||||
self.menubox.refresh(0, 0, self.toplefty, self.topleftx,
|
||||
self.height + self.toplefty,
|
||||
self.width + self.topleftx)
|
||||
self.update_pad(position)
|
||||
self.update_pad(self.menu.position)
|
||||
self.pad.refresh(cornery, 0, self.toplefty + 1, self.topleftx + 1,
|
||||
self.height - 2 + self.toplefty,
|
||||
self.width - 2 + self.topleftx)
|
||||
|
Reference in New Issue
Block a user