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.

187 lines
7.8 KiB

from graphics.colors import Colors
from graphics.engine import Layer
2 years ago
from graphics.engine import Screen
from getkey import keys
from re import match
class GUI(Layer):
2 years ago
"""Calque du menu principal"""
def __init__(self, z_index):
2 years ago
super().__init__(z_index, "gui")
self.__current = 0
self.__buttons = ["Attaquer", "Inventaire"]
self.__inventaire = False
2 years ago
self.handle_keys = False
self.__page = 1
def draw(self):
2 years ago
super().draw()
if self.__inventaire == False:
x = 1
for button in self.__buttons:
color = (Colors.REDBG, Colors.BLACK) if self.__buttons[self.__current] == button else (Colors.WHITEBG, Colors.BLACK)
self.put_string(button, x, self.y-10, color)
x += len(button)+1
stats = Screen.instance.game.personnage.affiche_caracteristiques()
for i in range(4):
self.put_string(stats[i], 1, self.y-8+i, [Colors.RED2])
for i in range(6):
self.put_string(stats[i+4], (self.x-2)//3, self.y-8+i, [Colors.RED2])
ennemy_stats = Screen.instance.game.ennemy.reduced_stats()
for i in range(3):
self.put_string(ennemy_stats[i], self.x-(self.x-2)//3, self.y-8+i, [Colors.BLUE2])
else:
x = 1
for button in self.__buttons:
color = (Colors.REDBG, Colors.BLACK) if self.__buttons[self.__current] == button else (Colors.WHITEBG, Colors.BLACK)
self.put_string(button, x, self.y-10, color)
x += len(button)+1
2 years ago
if self.__current == 0:
self.put_string(f"ENTREE pour retourner en arrière", 1, self.y-8, [Colors.RED2])
elif self.__current == 1:
potions = Screen.instance.game.personnage.potions
self.put_string(f"Nombre total de potions: {len(potions)}", 1, self.y-8, [Colors.RED2])
if len(potions) > 0:
self.put_string(f"Rénération de la prochaine potion: {potions[0].stats}", 1, self.y-7, [Colors.RED2])
self.put_string(f"ENTEE pour utiliser", 1, self.y-5, [Colors.RED2])
elif self.__current == 2:
arme = Screen.instance.game.personnage.arme
self.put_string(f"Nom: {arme.meta.name}", 1, self.y-8, [Colors.RED2])
self.put_string(f"Stats:", 1, self.y-7, [Colors.RED2])
self.put_string(f"- HP: {arme.stats.hp}", 1, self.y-6, [Colors.RED2])
self.put_string(f"- ATK%: {arme.stats.atkP}", 1, self.y-5, [Colors.RED2])
self.put_string(f"- DEF%: {arme.stats.defP}", 1, self.y-4, [Colors.RED2])
self.put_string(f"- INITIATIVE: {arme.stats.initiative}", 1, self.y-3, [Colors.RED2])
self.put_string(f"- XPCOEF: {arme.stats.xpcoef}", 1, self.y-2, [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
elif key == keys.ENTER:
if self.__inventaire == False:
if self.__current == 0:
attacker = Screen.instance.game.personnage
victim = Screen.instance.game.ennemy
Screen.instance.game.attack(attacker, victim)
elif self.__current == 1:
self.__inventaire = True
2 years ago
self.__buttons = ["Retour", "Potion", "Arme"]
else:
if self.__current == 0:
self.__inventaire = False
self.__buttons = ["Attaquer", "Inventaire"]
2 years ago
elif self.__current == 1 and len(Screen.instance.game.personnage.potions) > 0:
personnage = Screen.instance.game.personnage
personnage.change_hp(-1*personnage.potions[0].stats)
del personnage.potions[0]
2 years ago
class StartPopUp(Layer):
2 years ago
"""Calque du menu de lancement"""
def __init__(self, z_index):
super().__init__(z_index, "popup")
self.__classes = ["GUERRIER", "MAGICIEN", "VOLEUR", "ELFE"]
2 years ago
self.__choosen_class = 0
self.__username = ""
2 years ago
self.__missing_un = False
def draw(self):
2 years ago
super().draw()
#bg
2 years ago
self.rect(self.x//3, self.y//6, self.x*2//3, self.y//4 + self.y//3, Colors.WHITEBG)
#name
2 years ago
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*2//3 - 2, self.y//6 + 2, Colors.REDBG if self.__missing_un else Colors.BLACKBG)
2 years ago
self.put_string(self.__username, self.x//3 + 1, self.y//6 + 2, [Colors.WHITE, Colors.BLACKBG])
#Classes
2 years ago
self.put_string("Classe perso.: (Flèches)", self.x//3 + 1, self.y//6 + 4, [Colors.WHITEBG, Colors.BLACK])
y = 0
2 years ago
for user_class in self.__classes:
2 years ago
colors = colors = [Colors.REDBG, Colors.BLACK] if y == self.__choosen_class else [Colors.GREYBG, Colors.WHITE]
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):
2 years ago
self.__username += key
elif key == keys.BACKSPACE:
2 years ago
self.__username = self.__username[:-1]
2 years ago
elif key == keys.UP and self.__choosen_class > 0:
self.__choosen_class -= 1
elif key == keys.DOWN and self.__choosen_class < 3:
self.__choosen_class += 1
elif key == keys.TAB:
2 years ago
if len(self.__username) == 0:
self.__missing_un = True
return
Screen.instance.get_layer("gui").handle_keys = True
Screen.instance.del_layer("popup")
Screen.instance.game.init_personnage(self.__username, self.__classes[self.__choosen_class])
class PopUp(Layer):
"""Calque du menu de lancement"""
def __init__(self, z_index, message, block=False):
super().__init__(z_index, "popup")
self.message = message
self.block = block
Screen.instance.get_layer("gui").handle_keys = False
def draw(self):
super().draw()
self.rect(self.x//3, self.y//6, self.x*2//3, self.y//4 + self.y//3, Colors.WHITEBG)
length = (self.x*2//3-1) - (self.x//3+1)
x = 0
y = 0
for char in self.message:
2 years ago
if char == "\n":
x = 0
y += 1
continue
2 years ago
self.put_char(char, self.x//3 + 1 + x, self.y//6 + 1 + y, [Colors.WHITEBG, Colors.BLACK])
x += 1
if x == length:
x = 0
y += 1
if not self.block:
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 key == keys.TAB and not self.block:
Screen.instance.get_layer("gui").handle_keys = True
Screen.instance.del_layer("popup")
class Sprite(Layer):
def __init__(self, z_index, sprite_name, place):
if place != "player" and place != "opponant":
raise ValueError("wrong sprite name")
super().__init__(z_index, place)
self.place = place
self.sprite_name = sprite_name
def draw(self):
super().draw()
with open(f"game/sprites/{self.sprite_name}.txt", "r") as sprite:
pos = (1, 1) if self.place == "player" else (Screen.instance.x*2//3+1, 1)
self.put_string(sprite.read(), *pos)
def key_handler(self, key):
pass