|
|
@ -1,3 +1,5 @@ |
|
|
|
from charaters.personnage import Personnage, ClassType |
|
|
|
|
|
|
|
from graphics.colors import Colors |
|
|
|
from graphics.writer import Layer |
|
|
|
|
|
|
@ -5,15 +7,16 @@ 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) |
|
|
|
def __init__(self, screen, z_index, buttons): |
|
|
|
super().__init__(screen, z_index, "gui") |
|
|
|
self.buttons = buttons |
|
|
|
self.current = 0 |
|
|
|
|
|
|
|
self.__personnage = personnage |
|
|
|
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) |
|
|
@ -22,7 +25,7 @@ class GUI(Layer): |
|
|
|
self.put_string(button, x, self.y-10, color) |
|
|
|
x += len(button)+1 |
|
|
|
|
|
|
|
stats = self.__personnage.affiche_caracteristiques() |
|
|
|
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): |
|
|
@ -36,30 +39,32 @@ class GUI(Layer): |
|
|
|
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) |
|
|
|
super().__init__(screen, z_index, "popup") |
|
|
|
#screen.add_key_handler(self.key_handler) |
|
|
|
|
|
|
|
self.classes = ["GUERRIER", "MAGICIEN", "VOLEUR", "ELF"] |
|
|
|
self.choosen_class = 0 |
|
|
|
self.name = "" |
|
|
|
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.name, self.x//3 + 1, self.y//6 + 2, [Colors.WHITE, 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: |
|
|
|
for user_class in self.__classes: |
|
|
|
colors = [Colors.GREYBG, Colors.WHITE] |
|
|
|
if y == self.choosen_class: |
|
|
|
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 |
|
|
@ -70,10 +75,12 @@ class PopUp(Layer): |
|
|
|
|
|
|
|
def key_handler(self, key): |
|
|
|
if match("[a-zA-Z]", key): |
|
|
|
self.name += key |
|
|
|
self.__username += key |
|
|
|
elif key == keys.BACKSPACE: |
|
|
|
self.name = self.name[:-1] |
|
|
|
self.__username = self.__username[:-1] |
|
|
|
elif match("[1-4]", key): |
|
|
|
self.choosen_class = int(key)-1 |
|
|
|
self.__choosen_class = int(key)-1 |
|
|
|
elif key == keys.TAB: |
|
|
|
print("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]]) |