Browse Source

ajout de fonctions

master
BARRAUX Arthur 3 years ago
parent
commit
4f77010d8a
  1. 69
      main.py
  2. 1
      stat.bbm

69
main.py

@ -22,6 +22,7 @@ class Gui:
def __init__(self, ): def __init__(self, ):
self.terrain = Terrain() self.terrain = Terrain()
self.team = Team() self.team = Team()
self.mode = 'match'
self.file = 'untitled.bbm' self.file = 'untitled.bbm'
self.temp_data = '' self.temp_data = ''
self.list_button_menu = [] self.list_button_menu = []
@ -31,17 +32,35 @@ class Gui:
self.canvas.pack() self.canvas.pack()
# topbar # file menu
self.menubar = tkinter.Menu(self.root) self.menubar = tkinter.Menu(self.root)
self.filemenu = tkinter.Menu(self.menubar, tearoff=0) self.filemenu = tkinter.Menu(self.menubar, tearoff=0)
self.filemenu.add_command(label="new", command=self.new) self.filemenu.add_command(label="new", command=self.new)
self.filemenu.add_command(label="open", command=self.browse_open) self.filemenu.add_command(label="open", command=self.browse_open)
self.filemenu.add_command(label="save", command=self.save) self.filemenu.add_command(label="save", command=self.save)
self.filemenu.add_separator() self.filemenu.add_separator()
self.filemenu.add_command(label="rename") self.filemenu.add_command(label="rename")
self.filemenu.add_command(label="exit", command=self.root.quit) self.filemenu.add_command(label="exit", command=self.root.quit)
self.menubar.add_cascade(label="file", menu=self.filemenu) self.menubar.add_cascade(label="file", menu=self.filemenu)
# mode menu
self.modemenu = tkinter.Menu(self.menubar, tearoff=0)
self.modemenu.add_command(label="stat", command=lambda: self.changemode('stat'))
self.modemenu.add_command(label="match", command=lambda: self.changemode('match'))
self.menubar.add_cascade(label="mode", menu=self.modemenu)
# stat menu
self.statmenu = tkinter.Menu(self.menubar, tearoff=0)
self.statsubmenu = tkinter.Menu(self.statmenu, tearoff=0)
self.statsubmenu.add_command(label=self.team.players[0], command=lambda: self.draw_player(self.team.players[0]))
self.statsubmenu.add_command(label=self.team.players[1], command=lambda: self.draw_player(self.team.players[1]))
self.statsubmenu.add_command(label=self.team.players[2], command=lambda: self.draw_player(self.team.players[2]))
self.statsubmenu.add_command(label=self.team.players[3], command=lambda: self.draw_player(self.team.players[3]))
self.statsubmenu.add_command(label=self.team.players[4], command=lambda: self.draw_player(self.team.players[4]))
self.statmenu.add_cascade(label="player", menu=self.statsubmenu)
self.statmenu.add_command(label='team', command=self.draw_team)
# topbar
self.root.config(menu=self.menubar) self.root.config(menu=self.menubar)
# menu contextuel des actions # menu contextuel des actions
@ -78,6 +97,18 @@ class Gui:
f.read() f.read()
self.root.title(self.file) self.root.title(self.file)
def changemode(self, newmode):
print(self.mode, newmode)
if self.mode != newmode:
if newmode == 'stat':
self.menubar.add_cascade(label='stat', menu=self.statmenu)
else:
self.menubar.delete(3)
self.mode = newmode
items = self.canvas.find_all()
while len(items) > 4:
self.canvas.delete(items[-1])
items = self.canvas.find_all()
def context_menu(self, event): def context_menu(self, event):
self.team.posx, self.team.posy = event.x, event.y self.team.posx, self.team.posy = event.x, event.y
@ -91,6 +122,8 @@ class Gui:
self.action.grab_release() self.action.grab_release()
def action_menu(self, action): def action_menu(self, action):
"""enregistre temporairement l'action"""
self.clean_terrain()
# test si l'action est dans la liste des 3 points # test si l'action est dans la liste des 3 points
if ((self.team.posx-0)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2 or ((self.team.posx-self.terrain.width)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2: if ((self.team.posx-0)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2 or ((self.team.posx-self.terrain.width)**2) + ((self.team.posy-self.terrain.height/2)**2) <= self.terrain.three_points**2:
score = 2 score = 2
@ -104,14 +137,40 @@ class Gui:
self.root.title(self.file+' *') self.root.title(self.file+' *')
self.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n' self.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n'
def draw_actions(self, *event): def clean_terrain(self):
# dessine l'entièreté des actions """Nettoie le terrain"""
items = self.canvas.find_all() items = self.canvas.find_all()
while len(items) > 4: while len(items) > 4:
self.canvas.delete(items[-1]) self.canvas.delete(items[-1])
items = self.canvas.find_all() items = self.canvas.find_all()
def draw_team(self, *event):
"""dessine les actions de toute l'équipe"""
self.clean_terrain()
with open(self.file, 'r') as f:
for line in f:
# forme type: joueur action points x y
params = line.strip().split(' ')
if params[1] == 'marque':
self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green')
else:
self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red')
def draw_player(self, player):
"""dessine les actions d'un joueur"""
self.clean_terrain()
with open(self.file, 'r') as f:
for line in f:
# forme type: joueur action points x y
params = line.strip().split(' ')
if params[0] == player: # nom du joueur
if params[1] == 'marque':
self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='green')
else:
self.canvas.create_oval(int(params[3])-12, int(params[4])-12, int(params[3])+12, int(params[4])+12, fill='red')
def draw_terrain(self): def draw_terrain(self):
"""dessinne les lignes du terrain"""
# ligne des 3 points # ligne des 3 points
self.canvas.create_arc(-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=-180) self.canvas.create_arc(-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=-180)
self.canvas.create_arc(self.terrain.width-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.width+self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=180) self.canvas.create_arc(self.terrain.width-self.terrain.three_points, self.terrain.height//2 - self.terrain.three_points, self.terrain.width+self.terrain.three_points, self.terrain.height - (self.terrain.height//2 - self.terrain.three_points),width=3, start=90, extent=180)
@ -131,6 +190,6 @@ gui.root.bind("<Button-1>", gui.context_menu)
gui.root.bind("<Control-s>", gui.save) gui.root.bind("<Control-s>", gui.save)
gui.root.bind("<Control-o>", gui.browse_open) gui.root.bind("<Control-o>", gui.browse_open)
gui.root.bind("<Control-n>", gui.new) gui.root.bind("<Control-n>", gui.new)
gui.root.bind("<a>", gui.draw_actions) gui.root.bind("<a>", gui.draw_team)
gui.root.mainloop() gui.root.mainloop()

1
stat.bbm

@ -7,3 +7,4 @@ jl marque 2 186 283
alex marque 3 393 274 alex marque 3 393 274
arthur rate 3 359 210 arthur rate 3 359 210
arthur marque 3 416 212 arthur marque 3 416 212
jl rate 3 448 234

Loading…
Cancel
Save