|
|
|
from charaters.personnage import Personnage, ClassType
|
|
|
|
|
|
|
|
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):
|
|
|
|
super().__init__(screen, z_index, "gui")
|
|
|
|
self.buttons = buttons
|
|
|
|
self.current = 0
|
|
|
|
|
|
|
|
self.handle_keys = False
|
|
|
|
self.personnage = Personnage(" ", ClassType.GUERRIER)
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
super().draw()
|
|
|
|
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, "popup")
|
|
|
|
#screen.add_key_handler(self.key_handler)
|
|
|
|
|
|
|
|
self.__classes = ["GUERRIER", "MAGICIEN", "VOLEUR", "ELF"]
|
|
|
|
self.__choosen_class = 0
|
|
|
|
self.__username = ""
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
super().draw()
|
|
|
|
#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.__username, 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.__username += key
|
|
|
|
elif key == keys.BACKSPACE:
|
|
|
|
self.__username = self.__username[:-1]
|
|
|
|
elif match("[1-4]", key):
|
|
|
|
self.__choosen_class = int(key)-1
|
|
|
|
elif key == keys.TAB:
|
|
|
|
self.screen.get_layer("gui").handle_keys = True
|
|
|
|
self.screen.del_layer("popup")
|
|
|
|
self.screen.get_layer("gui").personnage = Personnage(self.__username, ClassType[self.__classes[self.__choosen_class]])
|