2020-11-10 09:01:31 +00:00
|
|
|
from dungeonbattle.menus import Menu, MainMenu
|
2020-11-08 15:36:21 +00:00
|
|
|
from typing import Any
|
2020-11-09 00:33:23 +00:00
|
|
|
import curses
|
2020-11-08 15:36:21 +00:00
|
|
|
|
2020-11-09 00:33:23 +00:00
|
|
|
class MenuDisplay:
|
|
|
|
position: int
|
|
|
|
|
2020-11-10 09:01:31 +00:00
|
|
|
def __init__(self, menu : Menu, height : int, width : int, topleftx: int, toplefty: int) :
|
2020-11-08 15:36:21 +00:00
|
|
|
self.values = menu.values
|
2020-11-09 00:33:23 +00:00
|
|
|
self.width = width
|
|
|
|
self.height = height
|
2020-11-08 15:36:21 +00:00
|
|
|
self.trueheight = len(menu.values)
|
2020-11-09 00:33:23 +00:00
|
|
|
self.truewidth = max(map(len,self.values))
|
2020-11-08 15:36:21 +00:00
|
|
|
self.topleftx = topleftx
|
|
|
|
self.toplefty = toplefty
|
|
|
|
|
2020-11-09 00:33:23 +00:00
|
|
|
#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])
|
|
|
|
|
|
|
|
#Menu box
|
|
|
|
self.menubox = curses.newpad(self.height,self.width)
|
|
|
|
self.menubox.addstr(0,0,"┏"+"━"*(self.width-2)+"┓")
|
|
|
|
for i in range(1,self.height-2) :
|
|
|
|
self.menubox.addstr(i,0,"┃"+" "*(self.width-2)+"┃")
|
|
|
|
self.menubox.addstr(self.height-2, 0, "┗"+"━"*(self.width-2)+"┛")
|
|
|
|
|
|
|
|
def update_pad(self) -> None:
|
|
|
|
for i in range(self.trueheight) :
|
|
|
|
self.pad.addstr(i,0," ")
|
|
|
|
self.pad.addstr(self.position,0,">") #set a marker on the selected line
|
|
|
|
|
|
|
|
def refresh(self, position : int) -> None:
|
|
|
|
self.position = position
|
|
|
|
if self.height-2>=position-1 :
|
2020-11-08 15:36:21 +00:00
|
|
|
cornery = 0
|
2020-11-09 00:33:23 +00:00
|
|
|
elif self.height-2 >= self.trueheight-position :
|
|
|
|
cornery = self.trueheight-self.height+2
|
|
|
|
|
2020-11-08 15:36:21 +00:00
|
|
|
self.menubox.refresh(0, 0, self.toplefty, self.topleftx,
|
2020-11-09 00:33:23 +00:00
|
|
|
self.height + self.toplefty,
|
|
|
|
self.width + self.topleftx)
|
|
|
|
self.update_pad(position)
|
|
|
|
self.pad.refresh(cornery, 0, self.toplefty+1, self.topleftx+1,
|
|
|
|
self.height-2 + self.toplefty,
|
|
|
|
self.width-2 + self.topleftx)
|
2020-11-10 09:01:31 +00:00
|
|
|
|
|
|
|
class MainMenuDisplay:
|
|
|
|
def __init__(self, menu : MainMenu) :
|
|
|
|
self.menu = menu
|
|
|
|
self.pad = curses.newpad(curses.LINES, curses.COLS)
|
|
|
|
|
|
|
|
with open("ascii_art.txt", "r") as file:
|
|
|
|
title = file.read().split("\n")
|
|
|
|
|
|
|
|
width = len(title[0])
|
|
|
|
height = len(title)
|
|
|
|
|
|
|
|
for i in range(len(title)) :
|
|
|
|
self.pad.addstr(4+i,curses.COLS//2-width//2-1,title[i])
|
|
|
|
self.pad.refresh(0,0,0,0,curses.LINES,curses.COLS)
|
|
|
|
|
|
|
|
self.menudisplay = MenuDisplay(self.menu, 15, 15, height+8, curses.COLS//2-15//2-1)
|
|
|
|
|
|
|
|
def refresh(self, position) -> None:
|
|
|
|
self.menudisplay.refresh(position)
|
|
|
|
|
|
|
|
|