2022-03-24 18:20:39 +01:00
|
|
|
from os import system
|
2022-03-23 14:20:59 +01:00
|
|
|
import keyboard
|
2022-03-24 18:20:39 +01:00
|
|
|
from colorama import Fore
|
|
|
|
class MenuManager:
|
|
|
|
'''
|
2022-05-04 14:26:32 +02:00
|
|
|
Vytváří navigovatelná textová menu
|
2022-03-24 18:20:39 +01:00
|
|
|
'''
|
|
|
|
def __init__(self,selections:list,additional:str):
|
2022-05-04 14:26:32 +02:00
|
|
|
self.selected = 0 # aktuální výběr
|
|
|
|
self.selections = selections # Dostupné možnosti
|
|
|
|
self.additional = additional # Text, který se zobrazí nad menu
|
2022-03-24 18:20:39 +01:00
|
|
|
keyboard.add_hotkey("up",self.up)
|
|
|
|
keyboard.add_hotkey("down",self.down)
|
|
|
|
keyboard.add_hotkey("enter",self.make_selection)
|
|
|
|
self.show_menu()
|
|
|
|
input()
|
|
|
|
|
2022-05-04 10:16:30 +02:00
|
|
|
def make_selection(self) -> None:
|
2022-03-24 18:20:39 +01:00
|
|
|
keyboard.remove_all_hotkeys()
|
|
|
|
|
|
|
|
def up(self):
|
|
|
|
if self.selected == 0:
|
|
|
|
self.selected = len(self.selections)-1
|
|
|
|
else:
|
|
|
|
self.selected -= 1
|
|
|
|
system("cls||clear")
|
|
|
|
self.show_menu()
|
|
|
|
|
|
|
|
def down(self):
|
|
|
|
if self.selected == len(self.selections)-1:
|
|
|
|
self.selected = 0
|
|
|
|
else:
|
|
|
|
self.selected += 1
|
|
|
|
system("cls||clear")
|
|
|
|
self.show_menu()
|
|
|
|
|
|
|
|
def show_menu(self):
|
2022-04-06 09:42:47 +02:00
|
|
|
system("cls||clear")
|
2022-03-24 18:20:39 +01:00
|
|
|
print(self.additional)
|
|
|
|
for selection in self.selections:
|
|
|
|
if(self.selected == self.selections.index(selection)):
|
|
|
|
print(f"{Fore.RED}->{Fore.RESET} {selection}")
|
|
|
|
else:
|
|
|
|
print(f" {selection}")
|
2022-04-05 11:59:11 +02:00
|
|
|
|
|
|
|
class HasItemDialogue(MenuManager):
|
|
|
|
'''
|
2022-05-04 14:26:32 +02:00
|
|
|
Odvozená třída pro kontrolu, zda-li má hráč předmět
|
2022-04-05 11:59:11 +02:00
|
|
|
'''
|
|
|
|
def __init__(self, selections: list, additional: str,inv:list,need_item:list):
|
2022-04-06 09:42:47 +02:00
|
|
|
system("cls||clear")
|
2022-04-05 11:59:11 +02:00
|
|
|
self.inventory = inv
|
|
|
|
self.need_items = need_item
|
|
|
|
super().__init__(selections, additional)
|
|
|
|
|
|
|
|
def show_menu(self):
|
|
|
|
print(self.additional)
|
2022-04-06 09:42:47 +02:00
|
|
|
|
2022-04-05 11:59:11 +02:00
|
|
|
for i,selection in enumerate(self.selections):
|
2022-04-06 09:42:47 +02:00
|
|
|
if(self.need_items[i] != None and all(element not in self.inventory for element in self.need_items[i])):
|
|
|
|
c = ""
|
|
|
|
for i,item in enumerate(self.need_items[i]):
|
|
|
|
if item not in self.inventory:
|
|
|
|
if i == len(self.need_items)-self.need_items.count(None)-1: # last item, don't add a comma
|
|
|
|
c+=f"{item} "
|
|
|
|
else:
|
|
|
|
c+=f"{item}, "
|
2022-04-05 11:59:11 +02:00
|
|
|
# user does not have the needed item
|
|
|
|
if(self.selected == i):
|
2022-04-06 09:42:47 +02:00
|
|
|
print(f"{Fore.RED}-> {Fore.CYAN}{selection}{Fore.RESET} (Need {c})")
|
2022-04-05 11:59:11 +02:00
|
|
|
else:
|
|
|
|
print(f" {Fore.CYAN}{selection}{Fore.RESET}")
|
|
|
|
else:
|
|
|
|
# we don't need to change color for an item user doesn't have
|
|
|
|
if(self.selected == i):
|
|
|
|
print(f"{Fore.RED}->{Fore.RESET} {selection}")
|
|
|
|
else:
|
|
|
|
print(f" {selection}")
|
2022-04-06 09:42:47 +02:00
|
|
|
def make_selection(self) -> int:
|
|
|
|
keyboard.remove_all_hotkeys()
|