Kalyax
2 years ago
6 changed files with 128 additions and 62 deletions
@ -1,20 +0,0 @@ |
|||
from graphics.colors import Colors |
|||
from graphics.writer import Layer |
|||
|
|||
class Menu: |
|||
def __init__(self, cli, buttons): |
|||
self.cli = cli |
|||
#self.stats = stats |
|||
self.buttons = buttons |
|||
self.current = 0 |
|||
|
|||
def draw_layer(self): |
|||
layer = Layer(self.cli, 1) |
|||
x = 1 |
|||
for button in self.buttons: |
|||
color = (Colors.WHITEBG, Colors.BLACK) |
|||
if self.buttons[self.current] == button: |
|||
color = (Colors.REDBG, Colors.BLACK) |
|||
layer.put_string(button, x, self.cli.y-10, color) |
|||
x += 11 |
|||
return layer |
@ -0,0 +1,79 @@ |
|||
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") |
@ -1,11 +1,10 @@ |
|||
from threading import Thread |
|||
from getkey import getkey |
|||
|
|||
from main import key_handler |
|||
|
|||
def __listener(): |
|||
def __listener(screen): |
|||
while True: |
|||
key = getkey() |
|||
key_handler(key) |
|||
screen.send_key(key) |
|||
|
|||
key_listener = Thread(target=__listener) |
|||
def build_thread(screen): |
|||
return Thread(target=__listener, args=(screen,)) |
|||
|
@ -1,32 +1,24 @@ |
|||
from charaters.personnage import Personnage |
|||
from charaters.personnage import Personnage, ClassType |
|||
|
|||
from graphics.colors import Colors |
|||
from graphics.layer.menu import Menu |
|||
import graphics.layers as layers |
|||
from graphics.writer import * |
|||
|
|||
from getkey import keys |
|||
import listener |
|||
|
|||
from time import sleep |
|||
|
|||
game = Screen() |
|||
menu = Menu(game, ["Inventaire", "Teset"]) |
|||
personnage = Personnage("Pierre", ClassType.GUERRIER) |
|||
|
|||
def key_handler(key): |
|||
print(key) |
|||
if key == keys.RIGHT and menu.current < len(menu.buttons)-1: |
|||
main.menu.current += 1 |
|||
elif key == keys.LEFT and menu.current > 0: |
|||
menu.current -= 1 |
|||
print(menu.current) |
|||
screen = Screen() |
|||
gui = layers.GUI(screen, 2, ["Attaquer", "Inventaire"], personnage) |
|||
popup = layers.PopUp(screen, 1) |
|||
|
|||
def draw(): |
|||
game.set_layer("menu", menu.draw_layer()) |
|||
screen.set_layer("gui", gui.draw()) |
|||
screen.set_layer("popup", popup.draw()) |
|||
|
|||
if __name__ == "__main__": |
|||
from listener import key_listener |
|||
#key_listener.start() |
|||
listener.build_thread(screen).start() |
|||
while True: |
|||
draw() |
|||
game.draw() |
|||
print("t") |
|||
sleep(1) |
|||
screen.draw() |
|||
sleep(0.4) |
Loading…
Reference in new issue