|
|
@ -1,6 +1,7 @@ |
|
|
|
import tkinter |
|
|
|
from tkinter import filedialog |
|
|
|
import os |
|
|
|
import math |
|
|
|
|
|
|
|
class Terrain: |
|
|
|
def __init__(self): |
|
|
@ -60,11 +61,22 @@ class Gui: |
|
|
|
self.filemenu.add_command(label="exit", command=self.root.quit) |
|
|
|
self.menubar.add_cascade(label="file", menu=self.filemenu) |
|
|
|
|
|
|
|
|
|
|
|
self.action_to_show = [] |
|
|
|
|
|
|
|
# topbar |
|
|
|
self.root.config(menu=self.menubar) |
|
|
|
|
|
|
|
# image des actions |
|
|
|
|
|
|
|
self.tir_reussi = tkinter.PhotoImage(file='img/tir_reussi.png') |
|
|
|
self.tir_rate = tkinter.PhotoImage(file='img/tir_rate.png') |
|
|
|
self.lance_reussi = tkinter.PhotoImage(file='img/lance_reussi.png') |
|
|
|
self.lance_rate = tkinter.PhotoImage(file='img/lance_rate.png') |
|
|
|
self.rebond_def = tkinter.PhotoImage(file='img/rebond_def.png') |
|
|
|
self.rebond_off = tkinter.PhotoImage(file='img/rebond_off.png') |
|
|
|
self.faute = tkinter.PhotoImage(file='img/faute.png') |
|
|
|
self.passe_dec = tkinter.PhotoImage(file='img/passe_dec.png') |
|
|
|
|
|
|
|
|
|
|
|
self.root.bind("<Control-o>", self.browse_open) |
|
|
|
self.root.bind("<Control-n>", self.new) |
|
|
@ -141,16 +153,29 @@ class Gui: |
|
|
|
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) |
|
|
|
self.statmenu.add_command(label='team', command=lambda: self.draw_player('*')) |
|
|
|
|
|
|
|
# actions menubar |
|
|
|
self.actionmenu = tkinter.Menu(self.menubar, tearoff=0) |
|
|
|
self.actionmenu.add_checkbutton(0, label='tirs', background='red') |
|
|
|
self.actionmenu.add_checkbutton(0, label='tirs', command=lambda: self.check_action('tirs')) |
|
|
|
self.actionmenu.add_checkbutton(0, label='lance', command=lambda: self.check_action('lance')) |
|
|
|
self.actionmenu.add_checkbutton(0, label='rebonds', command=lambda: self.check_action('rebond')) |
|
|
|
self.actionmenu.add_checkbutton(0, label='passe', command=lambda: self.check_action('passe')) |
|
|
|
self.actionmenu.add_checkbutton(0, label='faute', command=lambda: self.check_action('faute')) |
|
|
|
for i in range(5): |
|
|
|
self.actionmenu.invoke(i) |
|
|
|
|
|
|
|
|
|
|
|
# menu contextuel des actions |
|
|
|
self.action = tkinter.Menu(self.root, tearoff=0) |
|
|
|
self.action.add_command(label='marque', command=lambda: self.action_menu('marque')) |
|
|
|
self.action.add_command(label='rate', command=lambda: self.action_menu('rate')) |
|
|
|
self.action.add_command(label='tir réussi', command=lambda: self.action_menu('tm')) |
|
|
|
self.action.add_command(label='tir raté', command=lambda: self.action_menu('tr')) |
|
|
|
self.action.add_command(label='lancé franc réussi', command=lambda: self.action_menu('lfm')) |
|
|
|
self.action.add_command(label='lancé franc raté', command=lambda: self.action_menu('lfr')) |
|
|
|
self.action.add_command(label='faute', command=lambda: self.action_menu('f')) |
|
|
|
self.action.add_command(label='rebond offensif', command=lambda: self.action_menu('ro')) |
|
|
|
self.action.add_command(label='rebond défensif', command=lambda: self.action_menu('rd')) |
|
|
|
self.action.add_command(label='passe décisive', command=lambda: self.action_menu('pd')) |
|
|
|
|
|
|
|
# Menu contextuel des joueurs |
|
|
|
self.menu = tkinter.Menu(self.root, tearoff = 0) |
|
|
@ -163,13 +188,20 @@ class Gui: |
|
|
|
self.bind_click = "<Button-1>" |
|
|
|
self.bind_ctrl_s = "<Control-s>" |
|
|
|
|
|
|
|
def check_action(self, action): |
|
|
|
if action in self.action_to_show: |
|
|
|
self.action_to_show.remove(action) |
|
|
|
else: |
|
|
|
self.action_to_show.append(action) |
|
|
|
|
|
|
|
def changemode(self, newmode): |
|
|
|
if self.mode != newmode: |
|
|
|
if newmode == 'stat': |
|
|
|
self.menubar.add_cascade(label='stat', menu=self.statmenu) |
|
|
|
self.menubar.add_cascade(label='actions', menu=self.actionmenu) |
|
|
|
else: |
|
|
|
self.menubar.delete(3) |
|
|
|
for i in range(2): |
|
|
|
self.menubar.delete(3) |
|
|
|
self.mode = newmode |
|
|
|
items = self.canvas.find_all() |
|
|
|
while len(items) > 4: |
|
|
@ -192,18 +224,40 @@ class Gui: |
|
|
|
"""enregistre temporairement l'action""" |
|
|
|
self.clean_terrain() |
|
|
|
# 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: |
|
|
|
score = 2 |
|
|
|
else: |
|
|
|
score = 3 |
|
|
|
if action == 'marque': |
|
|
|
self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='green') |
|
|
|
else: |
|
|
|
self.canvas.create_oval(self.team.posx-12, self.team.posy-12, self.team.posx+12, self.team.posy+12, fill='red') |
|
|
|
if action == 'tm': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.tir_reussi, anchor='nw') |
|
|
|
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 |
|
|
|
else: |
|
|
|
score = 3 |
|
|
|
if action == 'tr': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.tir_rate, anchor='nw') |
|
|
|
score = 0 |
|
|
|
if action == 'lfm': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.lance_reussi, anchor='nw') |
|
|
|
score = 1 |
|
|
|
if action == 'lfr': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.lance_rate, anchor='nw') |
|
|
|
score = 0 |
|
|
|
if action == 'ro': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.rebond_off, anchor='nw') |
|
|
|
score = 0 |
|
|
|
if action == 'rd': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.rebond_def, anchor='nw') |
|
|
|
score = 0 |
|
|
|
if action == 'f': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.faute, anchor='nw') |
|
|
|
score = 0 |
|
|
|
if action == 'pd': |
|
|
|
self.canvas.create_image(self.team.posx-20, self.team.posy-20, image=self.passe_dec, anchor='nw') |
|
|
|
score = 0 |
|
|
|
|
|
|
|
|
|
|
|
if self.file.temp_data == '': |
|
|
|
self.root.title(self.file.name+' *') |
|
|
|
self.file.temp_data += self.team.ac_player+' '+action+' '+str(score)+' '+str(self.team.posx)+' '+str(self.team.posy)+'\n' |
|
|
|
|
|
|
|
|
|
|
|
def clean_terrain(self): |
|
|
|
"""Nettoie le terrain""" |
|
|
|
items = self.canvas.find_all() |
|
|
@ -211,28 +265,32 @@ class Gui: |
|
|
|
self.canvas.delete(items[-1]) |
|
|
|
items = self.canvas.find_all() |
|
|
|
|
|
|
|
def draw_team(self, *event): |
|
|
|
def draw_player(self, player, *event): |
|
|
|
"""dessine les actions de toute l'équipe""" |
|
|
|
self.clean_terrain() |
|
|
|
for line in self.file.content[2:]: |
|
|
|
# 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() |
|
|
|
for line in self.file.content[2:]: |
|
|
|
# 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') |
|
|
|
if params[0] == player or player == '*': # nom du joueur |
|
|
|
if 'tirs' in self.action_to_show: |
|
|
|
if params[1] == 'tm': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.tir_reussi, anchor='nw') |
|
|
|
if params[1] == 'tr': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.tir_rate, anchor='nw') |
|
|
|
if 'lance' in self.action_to_show: |
|
|
|
if params[1] == 'lfm': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.lance_reussi, anchor='nw') |
|
|
|
if params[1] == 'lfr': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.lance_rate, anchor='nw') |
|
|
|
if 'faute' in self.action_to_show and params[1] == 'f': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.faute, anchor='nw') |
|
|
|
if 'rebond' in self.action_to_show: |
|
|
|
if params[1] == 'ro': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.rebond_off, anchor='nw') |
|
|
|
if params[1] == 'rd': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.rebond_def, anchor='nw') |
|
|
|
if 'passe' in self.action_to_show and params[1] == 'pd': |
|
|
|
self.canvas.create_image(int(params[3]), int(params[4]), image=self.passe_dec, anchor='nw') |
|
|
|
|
|
|
|
def draw_terrain(self): |
|
|
|
"""dessinne les lignes du terrain""" |
|
|
|