From 0b3dd2f0d42dd7b016492ea44a6063aabad45990 Mon Sep 17 00:00:00 2001 From: raphael60650 Date: Wed, 27 Jan 2021 23:42:50 +0100 Subject: [PATCH] v0.2 --- assets/add.png | Bin 0 -> 1010 bytes assets/config-fr.json | 94 +++++++++++++ main.pyw | 315 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 392 insertions(+), 17 deletions(-) create mode 100644 assets/add.png create mode 100644 assets/config-fr.json diff --git a/assets/add.png b/assets/add.png new file mode 100644 index 0000000000000000000000000000000000000000..f1d2460511af6da357883756b51626d3f6bff72c GIT binary patch literal 1010 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBufiR<}hF1dv19Q8li(^Pd+}pdmvqb`Bj(%LTfWvd8#z+4T zjTwtMnx-ZsFI?I?HQ{NzLQ{fz7~_8iYuz_JOPe^7)FWJVT7EbsKV;^VIDhuu1EV85 z%QtOKd2f54U#4!dD!+R5H>=69Wog%dfZ5;rQHv&5LLbwN#SG8bq}dyq4<^)xX}!6l z`E-Smyz%lgTB}c$r@BUlO`9TqDtc)hTRP+RDf(VFPU=O5@M)H=-owD{^||lur2JEn zOXEbvA9P&WX8gmbS9ADN;lYj8V!~(r^1-4cQS<5NDco@JSR*KStA=G(J5&34zC9Q>ch z|Euco3wf^}u75j=g--swmushWeyX(BtK$DJKeRPJe0$yfzhR11as0{a3mM)|ea5eR zdFE@cX?KzvickG}sK!-bcy7rZrkD=lREsq-@_E}%>mHbC5!feOxb2kgfkq%}FOa2q zz%KQAfiUY$;q=vWm_EGF56;&<@XjJ|+FX#N!;W=&rzV%~e=71Ic#g*D>lV>KR`aLI z9i2^kx;KaVF*YqPTqL9aIA>~f1AE~jp7m4I51%cI<@!*)qm$`QxAEG;n;WN3dA8Xv z<(JXM<;~66rxtzk&it3Ksg_e;t#a+1K&zL(x)$ija+w<5n$Oz1`f&fT#eZMEpMH6B z;rs1(k{Lp}aD_ZDy}%*?i3yC4+y8fMVG3XX#lvxiXAz+IgT%>k#|4&QFt%ZXWf(9i zgbQ&^aAV|hWi$$CFabrbNSCMrGbk!AMSz5hN@|v0m~>DYW+Z*H)$_8<|921S4-caz_oHs$<7l; zCly6=PCvW$mW!T*;ZZ)Vhe10&pIT$Ie2vyarEcw0n?AX5_Sf*UX){D!sS)Vlfu^A~ dXV3g$ 0: + self.cup_offset -=1 + self.refresh_cup_menu() + + + def cup_right(self): + if self.cup_offset < (len(self.config["cup"]) // 2 - 3): + self.cup_offset +=1 + self.refresh_cup_menu() + + + def select_cup(self, index): + self.frame_CupNameManager.grid(row=10, column=1, columnspan=10) + self.frame_CupIconManager.grid(row=20, column=1, columnspan=10) + self.frame_RaceManager.grid(row=100, column=1, columnspan=6, sticky="NEWS") + self.button_DeleteCupManager.grid(row=101,column=1,columnspan=10, sticky="W") + + _cup_config = self.config["cup"][str(index)] + + self.entry_CupNameManager.config(state=NORMAL) + self.entry_CupNameManager.delete(0, END) + self.entry_CupNameManager.insert(0, _cup_config["name"]) + + self.button_CupNameManager.config(command=lambda i=index:self.change_cup_name(i)) + self.button_DeleteCupManager.config(command=lambda i=index:self.delete_cup(i)) + + self._selected_cup_img = ImageTk.PhotoImage(Image.open(f"{self.path}/files/.MKCreator/cup_icon/{index}.png")) + self.button_CupIconManager.config(image=self._selected_cup_img, command=lambda i=index:self.select_new_cup_icon(i)) + + if _cup_config["locked"]: + self.entry_CupNameManager.config(state=DISABLED) + self.button_CupIconManager.config(state=DISABLED) + self.button_DeleteCupManager.config(state=DISABLED) + self.button_CupNameManager.config(state=DISABLED) + else: + self.button_CupIconManager.config(state=NORMAL) + self.button_DeleteCupManager.config(state=NORMAL) + self.button_CupNameManager.config(state=NORMAL) + + for x in range(4): + self.button_RaceManager[x].config(text=_cup_config["courses"][str(x)]["name"], command=lambda t=index,r=x:self.edit_track(t,r)) + if _cup_config["locked"]: self.button_RaceManager[x].config(state=DISABLED) + else: self.button_RaceManager[x].config(state=NORMAL) + + + def create_new_cup(self): + tl = Toplevel() + tl.title("Nouvelle Coupe") + tl.resizable(False, False) + + new_icon = self._add_img_raw + new_icon_tk = self._add_img + + def select_icon(): + nonlocal new_icon, new_icon_tk + path = filedialog.askopenfilename() + if path: + if os.path.exists(path): + new_icon = Image.open(path) + new_icon_tk = ImageTk.PhotoImage(new_icon) + button_NewCupIcon.config(image=new_icon_tk) + + Label(tl, text="Choississez un nom pour votre coupe :").grid(row=1, column=1) + entry_NewCupName = Entry(tl) + entry_NewCupName.grid(row=2,column=1,sticky="NEWS") + Label(tl, text="Choississez une icone pour votre coupe :").grid(row=3, column=1) + button_NewCupIcon = Button(tl, image=self._add_img, command=select_icon) + button_NewCupIcon.grid(row=4, column=1) + + def confirm(): + nonlocal new_icon + cup_name = entry_NewCupName.get() + if cup_name.replace(" ", "") != "": + + cup_id = len(self.config["cup"]) + + new_icon.save(f"{self.path}/files/.MKCreator/cup_icon/{cup_id}.png") + self.config["cup"][str(cup_id)] = { + "name": cup_name, + "locked": False, + "courses": { + "0": {"name":"/", "music": 0x75, "special": 0x08, "new": False}, + "1": {"name":"/", "music": 0x75, "special": 0x08, "new": False}, + "2": {"name":"/", "music": 0x75, "special": 0x08, "new": False}, + "3": {"name":"/", "music": 0x75, "special": 0x08, "new": False}, + } + } + self.save_config() + self.refresh_cup_menu() + tl.destroy() + + else: + messagebox.showerror("Erreur", "Veuillez choisir un nom pour votre coupe.") + + Button(tl, text="Confirmer", relief=RIDGE, command = confirm).grid(row=5, column=1, sticky="E") + + + def select_new_cup_icon(self, index): + path = filedialog.askopenfilename() + if path: + if os.path.exists(path): + shutil.copy(path, f"{self.path}/files/.MKCreator/cup_icon/{index}.png") + self._selected_cup_img = ImageTk.PhotoImage(Image.open(path)) + self.button_CupIconManager.config(image=self._selected_cup_img) + self.refresh_cup_menu() + else: + messagebox.showerror("Erreur", "Ce fichier n'existe pas.") + + + def change_cup_name(self, index): + self.config["cup"][str(index)]["name"] = self.entry_CupNameManager.get() + self.save_config() + + + def delete_cup(self, index): + ans = messagebox.askyesno("Confirmer", f"Voulez-vous vraiment supprimer la coupe {self.config['cup'][str(index)]['name']} ?") + if ans: + total_cup = len(self.config["cup"]) + os.remove(f"{self.path}/files/.MKCreator/cup_icon/{index}.png") + self.config["cup"].pop(str(index)) + + for i in range(index+1, total_cup): + self.config["cup"][str(i-1)] = self.config["cup"].pop(str(i)) + + os.rename(f"{self.path}/files/.MKCreator/cup_icon/{i}.png", f"{self.path}/files/.MKCreator/cup_icon/{i-1}.png") + + self.save_config() + self.refresh_cup_menu() + + + def edit_track(self, cup_index, course_index): + tl = Toplevel() + tl.title("Modifier la course") + tl.resizable(False, False) + + track2ID = { + "Circuit Luigi (slot 1.1)": [0x75, 0x08], + "Prairie Meuh Meuh (slot 1.2)": [0x77, 0x01], + "Gorge Champignon (slot 1.3)": [0x79, 0x02], + "Usine Toad (slot 1.4)": [0x7B, 0x04], + + "Circuit Mario (slot 2.1)": [0x7D, 0x00], + "Supermarché Coco (slot 2.2)": [0x7F, 0x05], + "Pic DK (slot 2.3)": [0x81, 0x06], + "Mine Wario (slot 2.4)": [0x83, 0x07], + + "Circuit Daisy (slot 3.1)": [0x87, 0x09], + "Cap Koopa (slot 3.2)": [0x85, 0x0F], + "Bois Vermeil (slot 3.3)": [0x8F, 0x0B], + "Volcan Grondant (slot 3.4)": [0x8B, 0x03], + + "Ruines Sec Sec (slot 4.1)": [0x89, 0x0E], + "Route Clair de Lune (slot 4.2)": [0x8D, 0x0A], + "Château de Bowser (slot 4.3)": [0x91, 0x0C], + "Route Arc-en-Ciel (slot 4.4)": [0x93, 0x0D], + + "GCN Plage Peach (slot 5.1)": [0xA5, 0x10], + "DS Cascades Yoshi (slot 5.2)": [0xAD, 0x14], + "SNES Vallée Fantôme 2 (slot 5.3)": [0x97, 0x19], + "N64 Autodrome Mario (slot 5.4)": [0x9F, 0x1A], + + "N64 Royaume Sorbet (slot 6.1)": [0x9D, 0x1B], + "GBA Plage Maskass (slot 6.2)": [0x95, 0x1F], + "DS Quartier Delfino (slot 6.3)": [0xAF, 0x17], + "GCN Stade Waluigi (slot 6.4)": [0xA9, 0x12], + + "DS Désert du Soleil (slot 7.1)": [0xB1, 0x15], + "GBA Château de Bowser 3 (slot 7.2)":[0x9B, 0x1E], + "N64 Jungle DK (slot 7.3)": [0xA1, 0x1D], + "GCN Circuit Mario (slot 7.4)": [0xA7, 0x11], + + "SNES Circuit Mario 3 (slot 8.1)": [0x99, 0x18], + "DS Jardin Peach (slot 8.2)": [0xB3, 0x16], + "GCN Montagne DK (slot 8.3)": [0xAB, 0x13], + "N64 Château de Bowser (slot 8.4)": [0xA3, 0x1C], + + "Block Plaza (battle slot 1.1)": [0xB7, 0x21], + "Quai Delfino (battle slot 1.2)": [0xB5, 0x20], + "Stade de Funky Kong (battle slot 1.3)": [0xB9, 0x23], + "Roulette Chomp (battle slot 1.4)": [0xBB, 0x22], + "Désert Thwomp (battle slot 1.5)": [0xBD, 0x24], + + "SNES Circuit de Bataille 4 (battle slot 2.1)": [0xC3, 0x27], + "GBA Circuit de Bataille 3 (battle slot 2.2)": [0xC5, 0x28], + "N64 Gratte-ciel (battle slot 2.3)": [0xC7, 0x29], + "GCN Cookie Arena (battle slot 2.4)": [0xBF, 0x25], + "DS Maison de l'Aube (battle slot 2.5)": [0xC1, 0x26], + + "Colisée Galactique": [0xC9, 0x36], + } + + def select_file(): + path = filedialog.askopenfilename() + if path: + if os.path.exists(path): + name = path.split("/")[-1].replace("_", " ").replace(".szs", "") + entry_CoursePath.delete(0, END) + entry_CoursePath.insert(0, path) + entry_CourseName.delete(0, END) + entry_CourseName.insert(0, name) + else: + messagebox.showerror("Erreur", "Ce fichier n'existe pas.") + + Label(tl, text="Fichier du jeu :").grid(row=1, column=1) + entry_CoursePath = Entry(tl, width=40) + entry_CoursePath.grid(row=2, column=1, sticky="NEWS") + Button(tl, text="...", relief=RIDGE, command=select_file).grid(row=2, column=2, sticky="NEWS") + + Label(tl, text="Nom de la course :").grid(row=3, column=1, columnspan=2) + entry_CourseName = Entry(tl, width=50) + entry_CourseName.grid(row=4, column=1, sticky="NEWS", columnspan=2) + + Label(tl, text="Musique de la course :").grid(row=5, column=1, columnspan=2) + listbox_MusicType = ttk.Combobox(tl, width=50, values=list(track2ID.keys())) + listbox_MusicType.current(0) + listbox_MusicType.grid(row=6, column=1, sticky="NEWS", columnspan=2) + + Label(tl, text="Type de la course :\n(généralement indiqué par son créateur)\n(si non spécifié, choisir slot 1.1)").grid(row=7, column=1, columnspan=2) + listbox_TrackType = ttk.Combobox(tl, width=50, values=list(track2ID.keys())) + listbox_TrackType.current(0) + listbox_TrackType.grid(row=8, column=1, sticky="NEWS", columnspan=2) + + Checkbutton(tl, text="marqué comme étant nouveau").grid(row=9, column=1, columnspan=2) + + + def save_config(self): + with open(f"{self.path}/files/.MKCreator/config.json", "w") as file: + json.dump(self.config, file) + + +#TODO: wimgt encode "src" --DEST "dst" -x tpl.CMPR - pour convertir un .png en .tpl +#TODO: sélectionné un fichier force à choisir un type valide +#TODO: chargement de la partie d'injection améliorer (barre de chargement, ...) Main = main() mainloop() \ No newline at end of file