You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.8 KiB

from graphics.colors import Colors
from graphics.writer import Layer
from getkey import keys
from re import match
class GUI(Layer):
def __init__(self, screen, z_index, buttons, personnage):
super().__init__(screen, z_index)
screen.add_key_handler(self.key_handler)
self.buttons = buttons
self.current = 0
self.__personnage = personnage
def draw(self):
x = 1
for button in self.buttons:
color = (Colors.WHITEBG, Colors.BLACK)
if self.buttons[self.current] == button:
color = (Colors.REDBG, Colors.BLACK)
self.put_string(button, x, self.y-10, color)
x += len(button)+1
stats = self.__personnage.affiche_caracteristiques()
for i in range(4):
self.put_string(stats[i], 0, self.y-8+i, [Colors.RED2])
for i in range(7):
self.put_string(stats[i+4], 40, self.y-8+i, [Colors.RED2])
return self
def key_handler(self, key):
if key == keys.RIGHT and self.current < len(self.buttons)-1:
self.current += 1
elif key == keys.LEFT and self.current > 0:
self.current -= 1
class PopUp(Layer):
def __init__(self, screen, z_index):
super().__init__(screen, z_index)
screen.add_key_handler(self.key_handler)
self.classes = ["GUERRIER", "MAGICIEN", "VOLEUR", "ELF"]
self.choosen_class = 0
self.name = ""
def draw(self):
#bg
self.rect(self.x//3, self.y//6, self.x//3 + self.x//4, self.y//4 + self.y//3, Colors.WHITEBG)
#name
self.put_string("Nom: [A-z]", self.x//3 + 1, self.y//6 + 1, [Colors.WHITEBG, Colors.BLACK])
self.rect(self.x//3 + 1, self.y//6 + 2, self.x//3 + self.x//4 - 1, self.y//6 + 2, Colors.BLACKBG)
self.put_string(self.name, self.x//3 + 1, self.y//6 + 2, [Colors.WHITE, Colors.BLACKBG])
#Classes
self.put_string("Classe perso.: SHIFT+[1-4]", self.x//3 + 1, self.y//6 + 4, [Colors.WHITEBG, Colors.BLACK])
y = 0
for user_class in self.classes:
colors = [Colors.GREYBG, Colors.WHITE]
if y == self.choosen_class:
colors = [Colors.REDBG, Colors.BLACK]
self.put_string(user_class, self.x//3 + 2, self.y//6 + 5 + y, colors)
y += 1
self.put_string("TAB pour confirmer", self.x//3 + 1, self.y//4 + self.y//3 -1, [Colors.WHITEBG, Colors.BLACK])
return self
def key_handler(self, key):
if match("[a-zA-Z]", key):
self.name += key
elif key == keys.BACKSPACE:
self.name = self.name[:-1]
elif match("[1-4]", key):
self.choosen_class = int(key)-1
elif key == keys.TAB:
print("TAB")