mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-04 11:48:22 +02:00
fixed the track sorting, added a way to save and load track configuration, track configuration is now keeped when closing and reopening the track configuration menu
This commit is contained in:
parent
7b134a88a3
commit
b5da151c73
5 changed files with 222 additions and 119 deletions
|
@ -66,10 +66,9 @@ class CT_Config:
|
||||||
cup.tracks[index] = track
|
cup.tracks[index] = track
|
||||||
yield cup
|
yield cup
|
||||||
|
|
||||||
def create_ctfile(self, directory: str = "./file/", highlight_version: str = None) -> None:
|
def create_ctfile(self, directory: str = "./file/") -> None:
|
||||||
"""
|
"""
|
||||||
create a ctfile configuration in a directory
|
create a ctfile configuration in a directory
|
||||||
:param highlight_version: highlight a specific version in light blue
|
|
||||||
:param directory: create CTFILE.txt and RCTFILE.txt in this directory
|
:param directory: create CTFILE.txt and RCTFILE.txt in this directory
|
||||||
"""
|
"""
|
||||||
with open(directory + "CTFILE.txt", "w", encoding="utf-8") as ctfile, \
|
with open(directory + "CTFILE.txt", "w", encoding="utf-8") as ctfile, \
|
||||||
|
|
|
@ -4,6 +4,7 @@ from source.Game import Game
|
||||||
from source.Gui.Main import Main
|
from source.Gui.Main import Main
|
||||||
from source.Gui.TrackSelection import TrackSelection
|
from source.Gui.TrackSelection import TrackSelection
|
||||||
|
|
||||||
|
|
||||||
class Common:
|
class Common:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
|
@ -11,6 +12,8 @@ class Common:
|
||||||
having to access an object with some obscure way
|
having to access an object with some obscure way
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.json_frame_filter = None
|
||||||
|
|
||||||
self.option = Option().load_from_file("./option.json")
|
self.option = Option().load_from_file("./option.json")
|
||||||
self.ct_config = CT_Config()
|
self.ct_config = CT_Config()
|
||||||
self.game = Game(common=self)
|
self.game = Game(common=self)
|
||||||
|
|
|
@ -432,9 +432,7 @@ class Game:
|
||||||
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.gui_main.translate("Converting files"),
|
self.common.gui_main.progress(show=True, indeter=False, statut=self.common.gui_main.translate("Converting files"),
|
||||||
max=max_step, step=0)
|
max=max_step, step=0)
|
||||||
self.common.gui_main.progress(statut=self.common.gui_main.translate("Configurating LE-CODE"), add=1)
|
self.common.gui_main.progress(statut=self.common.gui_main.translate("Configurating LE-CODE"), add=1)
|
||||||
self.common.ct_config.create_ctfile(
|
self.common.ct_config.create_ctfile()
|
||||||
highlight_version=self.common.gui_main.stringvar_mark_track_from_version.get(),
|
|
||||||
)
|
|
||||||
|
|
||||||
self.generate_cticons()
|
self.generate_cticons()
|
||||||
self.generate_all_image()
|
self.generate_all_image()
|
||||||
|
|
|
@ -203,25 +203,11 @@ class Main:
|
||||||
menu=self.menu_conv_process
|
menu=self.menu_conv_process
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for process_number in range(1, 8+1):
|
||||||
self.menu_conv_process.add_radiobutton(
|
self.menu_conv_process.add_radiobutton(
|
||||||
label=self.translate("1 ", "process"),
|
label=self.translate(f"{process_number} ", "process"),
|
||||||
variable=self.intvar_process_track, value=1,
|
variable=self.intvar_process_track, value=process_number,
|
||||||
command=lambda: self.common.option.edit("process_track", 1)
|
command=lambda p=process_number: self.common.option.edit("process_track", p)
|
||||||
)
|
|
||||||
self.menu_conv_process.add_radiobutton(
|
|
||||||
label=self.translate("2 ", "process"),
|
|
||||||
variable=self.intvar_process_track, value=2,
|
|
||||||
command=lambda: self.common.option.edit("process_track", 2)
|
|
||||||
)
|
|
||||||
self.menu_conv_process.add_radiobutton(
|
|
||||||
label=self.translate("4 ", "process"),
|
|
||||||
variable=self.intvar_process_track, value=4,
|
|
||||||
command=lambda: self.common.option.edit("process_track", 4)
|
|
||||||
)
|
|
||||||
self.menu_conv_process.add_radiobutton(
|
|
||||||
label=self.translate("8 ", "process"),
|
|
||||||
variable=self.intvar_process_track, value=8,
|
|
||||||
command=lambda: self.common.option.edit("process_track", 8)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
## GAME PARAMETER
|
## GAME PARAMETER
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
import json
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
from tkinter import filedialog
|
||||||
|
|
||||||
|
|
||||||
class Orderbox(Listbox):
|
class Orderbox(Listbox):
|
||||||
|
@ -46,7 +48,6 @@ class TrackSelection:
|
||||||
self.text_xnor = "xnor"
|
self.text_xnor = "xnor"
|
||||||
self.condition_link_end = "end"
|
self.condition_link_end = "end"
|
||||||
|
|
||||||
track_filter_row_start = 10
|
|
||||||
self.condition_links = {
|
self.condition_links = {
|
||||||
self.text_and: lambda a, b: lambda track: a(track) and b(track),
|
self.text_and: lambda a, b: lambda track: a(track) and b(track),
|
||||||
self.text_nand: lambda a, b: lambda track: not (a(track) and b(track)),
|
self.text_nand: lambda a, b: lambda track: not (a(track) and b(track)),
|
||||||
|
@ -57,14 +58,134 @@ class TrackSelection:
|
||||||
self.condition_link_end: -1
|
self.condition_link_end: -1
|
||||||
}
|
}
|
||||||
|
|
||||||
def del_frame_track_filter(frames_filter: list, index: int = 0):
|
def get_change_enable_track_filter_func(root: [Frame, LabelFrame], frames_filter: list, variable_enable: BooleanVar):
|
||||||
|
def change_enable_track_filter(event: Event = None):
|
||||||
|
if variable_enable.get(): self.add_frame_track_filter(root=root, frames_filter=frames_filter)
|
||||||
|
else: self.del_frame_track_filter(frames_filter=frames_filter)
|
||||||
|
|
||||||
|
return change_enable_track_filter
|
||||||
|
|
||||||
|
self.track_sort = LabelFrame(self.root, text="Sort Track")
|
||||||
|
self.track_sort.grid(row=1, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
Label(self.track_sort, text="Sort track by : ").grid(row=1, column=1)
|
||||||
|
self.combobox_track_sort = ttk.Combobox(
|
||||||
|
self.track_sort,
|
||||||
|
values=list(self.common.ct_config.get_all_track_possibilities().keys())
|
||||||
|
)
|
||||||
|
self.combobox_track_sort.grid(row=1, column=2, sticky="NEWS")
|
||||||
|
self.combobox_track_sort.insert(END, self.common.ct_config.sort_track_attr)
|
||||||
|
|
||||||
|
self.track_filter = LabelFrame(self.root, text="Filter Track")
|
||||||
|
self.track_filter.grid(row=2, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
self.variable_enable_track_filter = BooleanVar(value=False)
|
||||||
|
self.frames_track_filter = []
|
||||||
|
self.checkbutton_track_filter = ttk.Checkbutton(
|
||||||
|
self.track_filter,
|
||||||
|
text="Enable track filter",
|
||||||
|
variable=self.variable_enable_track_filter,
|
||||||
|
command=get_change_enable_track_filter_func(
|
||||||
|
self.track_filter,
|
||||||
|
self.frames_track_filter,
|
||||||
|
self.variable_enable_track_filter
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.checkbutton_track_filter.grid(row=1, column=1)
|
||||||
|
Label(
|
||||||
|
self.track_filter,
|
||||||
|
text="Warning : only unordered tracks are affected by this option.",
|
||||||
|
fg="gray"
|
||||||
|
).grid(row=2, column=1)
|
||||||
|
|
||||||
|
self.track_highlight = LabelFrame(self.root, text="Highlight Track")
|
||||||
|
self.track_highlight.grid(row=3, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
self.variable_enable_track_highlight = BooleanVar(value=False)
|
||||||
|
self.frames_track_highlight = []
|
||||||
|
self.checkbutton_track_highlight = ttk.Checkbutton(
|
||||||
|
self.track_highlight,
|
||||||
|
text="Enable track highlight",
|
||||||
|
variable=self.variable_enable_track_highlight,
|
||||||
|
command=get_change_enable_track_filter_func(
|
||||||
|
self.track_highlight,
|
||||||
|
self.frames_track_highlight,
|
||||||
|
self.variable_enable_track_highlight
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.checkbutton_track_highlight.grid(row=1, column=1)
|
||||||
|
|
||||||
|
self.track_random_new = LabelFrame(self.root, text="Overwrite random cup new")
|
||||||
|
self.track_random_new.grid(row=4, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
self.variable_enable_track_random_new = BooleanVar(value=False)
|
||||||
|
self.frames_track_random_new = []
|
||||||
|
self.checkbutton_track_random_new = ttk.Checkbutton(
|
||||||
|
self.track_random_new,
|
||||||
|
text="Enable overwriting random \"new\" track",
|
||||||
|
variable=self.variable_enable_track_random_new,
|
||||||
|
command=get_change_enable_track_filter_func(
|
||||||
|
self.track_random_new,
|
||||||
|
self.frames_track_random_new,
|
||||||
|
self.variable_enable_track_random_new
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.checkbutton_track_random_new.grid(row=1, column=1)
|
||||||
|
|
||||||
|
self.all_frames_filters = {
|
||||||
|
"track_filter": {
|
||||||
|
"frame": self.track_filter,
|
||||||
|
"variable_checkbox": self.variable_enable_track_filter,
|
||||||
|
"list": self.frames_track_filter
|
||||||
|
},
|
||||||
|
"track_highlight": {
|
||||||
|
"frame": self.track_highlight,
|
||||||
|
"variable_checkbox": self.variable_enable_track_highlight,
|
||||||
|
"list": self.frames_track_highlight
|
||||||
|
},
|
||||||
|
"track_random_new": {
|
||||||
|
"frame": self.track_random_new,
|
||||||
|
"variable_checkbox": self.variable_enable_track_random_new,
|
||||||
|
"list": self.frames_track_random_new
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.common.json_frame_filter: self.load_from_json(self.common.json_frame_filter)
|
||||||
|
|
||||||
|
self.frame_action_button = Frame(self.root)
|
||||||
|
self.frame_action_button.grid(row=100, column=1, sticky="E")
|
||||||
|
|
||||||
|
Button(
|
||||||
|
self.frame_action_button,
|
||||||
|
text="Apply change",
|
||||||
|
relief=RIDGE,
|
||||||
|
command=self.apply_configuration
|
||||||
|
).grid(row=1, column=1, sticky="W")
|
||||||
|
|
||||||
|
Button(
|
||||||
|
self.frame_action_button,
|
||||||
|
text="Save to file",
|
||||||
|
relief=RIDGE,
|
||||||
|
command=self.promp_save_to_file
|
||||||
|
).grid(row=1, column=2, sticky="E")
|
||||||
|
|
||||||
|
Button(
|
||||||
|
self.frame_action_button,
|
||||||
|
text="Load from file",
|
||||||
|
relief=RIDGE,
|
||||||
|
command=self.promp_load_from_file
|
||||||
|
).grid(row=1, column=3, sticky="E")
|
||||||
|
|
||||||
|
def del_frame_track_filter(self, frames_filter: list, index: int = 0):
|
||||||
for elem in frames_filter[index:]: # remove all track filter after this one
|
for elem in frames_filter[index:]: # remove all track filter after this one
|
||||||
elem["frame"].destroy()
|
elem["frame"].destroy()
|
||||||
del frames_filter[index:]
|
del frames_filter[index:]
|
||||||
|
|
||||||
def add_frame_track_filter(root: Frame, frames_filter: list, index: int = 0):
|
def add_frame_track_filter(self, root: [Frame, LabelFrame], frames_filter: list):
|
||||||
|
index = len(frames_filter) - 1
|
||||||
|
|
||||||
frame = Frame(root)
|
frame = Frame(root)
|
||||||
frame.grid(row=index + track_filter_row_start, column=1, sticky="NEWS")
|
frame.grid(row=len(frames_filter) + 10, column=1, sticky="NEWS")
|
||||||
Label(frame, text="If track's").grid(row=1, column=1)
|
Label(frame, text="If track's").grid(row=1, column=1)
|
||||||
track_property = ttk.Combobox(frame, values=list(self.common.ct_config.get_all_track_possibilities().keys()))
|
track_property = ttk.Combobox(frame, values=list(self.common.ct_config.get_all_track_possibilities().keys()))
|
||||||
track_property.current(0)
|
track_property.current(0)
|
||||||
|
@ -116,11 +237,11 @@ class TrackSelection:
|
||||||
link = next_condition_link.get()
|
link = next_condition_link.get()
|
||||||
|
|
||||||
if link == self.condition_link_end:
|
if link == self.condition_link_end:
|
||||||
del_frame_track_filter(frames_filter, index=index + 1)
|
self.del_frame_track_filter(frames_filter, index=index + 1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if frames_filter[-1]["frame"] == frame: # if this is the last filter available
|
if frames_filter[-1]["frame"] == frame: # if this is the last filter available
|
||||||
add_frame_track_filter(root=root, frames_filter=frames_filter, index=index + 1)
|
self.add_frame_track_filter(root=root, frames_filter=frames_filter)
|
||||||
|
|
||||||
next_condition_link = ttk.Combobox(frame, values=list(self.condition_links.keys()), width=10)
|
next_condition_link = ttk.Combobox(frame, values=list(self.condition_links.keys()), width=10)
|
||||||
next_condition_link.bind("<<ComboboxSelected>>", change_condition_link)
|
next_condition_link.bind("<<ComboboxSelected>>", change_condition_link)
|
||||||
|
@ -141,83 +262,7 @@ class TrackSelection:
|
||||||
"next_condition_link": next_condition_link
|
"next_condition_link": next_condition_link
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_change_enable_track_filter_func(root: [Frame, LabelFrame], frames_filter: list, variable_enable: BooleanVar):
|
def apply_configuration(self):
|
||||||
def change_enable_track_filter(event: Event = None):
|
|
||||||
if variable_enable.get(): add_frame_track_filter(root=root, frames_filter=frames_filter)
|
|
||||||
else: del_frame_track_filter(frames_filter=frames_filter)
|
|
||||||
|
|
||||||
return change_enable_track_filter
|
|
||||||
|
|
||||||
self.track_sort = LabelFrame(self.root, text="Sort Track")
|
|
||||||
self.track_sort.grid(row=1, column=1, sticky="NEWS")
|
|
||||||
|
|
||||||
Label(self.track_sort, text="Sort track by : ").grid(row=1, column=1)
|
|
||||||
self.combobox_track_sort = ttk.Combobox(
|
|
||||||
self.track_sort,
|
|
||||||
values=list(self.common.ct_config.get_all_track_possibilities().keys())
|
|
||||||
)
|
|
||||||
self.combobox_track_sort.grid(row=1, column=2, sticky="NEWS")
|
|
||||||
self.combobox_track_sort.insert(END, self.common.ct_config.sort_track_attr)
|
|
||||||
|
|
||||||
self.track_filter = LabelFrame(self.root, text="Filter Track")
|
|
||||||
self.track_filter.grid(row=2, column=1, sticky="NEWS")
|
|
||||||
|
|
||||||
self.variable_enable_track_filter = BooleanVar(value=False)
|
|
||||||
self.frames_track_filter = []
|
|
||||||
self.checkbutton_track_filter = ttk.Checkbutton(
|
|
||||||
self.track_filter,
|
|
||||||
text="Enable track filter",
|
|
||||||
variable=self.variable_enable_track_filter,
|
|
||||||
command=get_change_enable_track_filter_func(
|
|
||||||
self.track_filter,
|
|
||||||
self.frames_track_filter,
|
|
||||||
self.variable_enable_track_filter
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.checkbutton_track_filter.grid(row=1, column=1)
|
|
||||||
|
|
||||||
self.track_highlight = LabelFrame(self.root, text="Highlight Track")
|
|
||||||
self.track_highlight.grid(row=3, column=1, sticky="NEWS")
|
|
||||||
|
|
||||||
self.variable_enable_track_highlight = BooleanVar(value=False)
|
|
||||||
self.frames_track_highlight = []
|
|
||||||
self.checkbutton_track_highlight = ttk.Checkbutton(
|
|
||||||
self.track_highlight,
|
|
||||||
text="Enable track highlight",
|
|
||||||
variable=self.variable_enable_track_highlight,
|
|
||||||
command=get_change_enable_track_filter_func(
|
|
||||||
self.track_highlight,
|
|
||||||
self.frames_track_highlight,
|
|
||||||
self.variable_enable_track_highlight
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.checkbutton_track_highlight.grid(row=1, column=1)
|
|
||||||
|
|
||||||
self.track_random_new = LabelFrame(self.root, text="Overwrite random cup new")
|
|
||||||
self.track_random_new.grid(row=4, column=1, sticky="NEWS")
|
|
||||||
|
|
||||||
self.variable_enable_track_random_new = BooleanVar(value=False)
|
|
||||||
self.frames_track_random_new = []
|
|
||||||
self.checkbutton_track_random_new = ttk.Checkbutton(
|
|
||||||
self.track_random_new,
|
|
||||||
text="Enable overwriting random \"new\" track",
|
|
||||||
variable=self.variable_enable_track_random_new,
|
|
||||||
command=get_change_enable_track_filter_func(
|
|
||||||
self.track_random_new,
|
|
||||||
self.frames_track_random_new,
|
|
||||||
self.variable_enable_track_random_new
|
|
||||||
)
|
|
||||||
)
|
|
||||||
self.checkbutton_track_random_new.grid(row=1, column=1)
|
|
||||||
|
|
||||||
Button(
|
|
||||||
self.root,
|
|
||||||
text="Save configuration",
|
|
||||||
relief=RIDGE,
|
|
||||||
command=self.save_configuration
|
|
||||||
).grid(row=100, column=1, sticky="E")
|
|
||||||
|
|
||||||
def save_configuration(self):
|
|
||||||
self.common.gui_main.is_track_configuration_edited = True
|
self.common.gui_main.is_track_configuration_edited = True
|
||||||
self.common.ct_config.sort_track_attr = self.combobox_track_sort.get()
|
self.common.ct_config.sort_track_attr = self.combobox_track_sort.get()
|
||||||
self.common.ct_config.filter_track_selection = self.get_filter(
|
self.common.ct_config.filter_track_selection = self.get_filter(
|
||||||
|
@ -233,6 +278,9 @@ class TrackSelection:
|
||||||
self.frames_track_random_new
|
self.frames_track_random_new
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.common.json_frame_filter = self.save_to_json()
|
||||||
|
self.root.destroy()
|
||||||
|
|
||||||
def get_filter(self, condition_enabled: BooleanVar, frames_filter: list):
|
def get_filter(self, condition_enabled: BooleanVar, frames_filter: list):
|
||||||
s = lambda x: str(x).strip()
|
s = lambda x: str(x).strip()
|
||||||
|
|
||||||
|
@ -282,3 +330,72 @@ class TrackSelection:
|
||||||
next_condition_link_func = self.condition_links[next_condition_link]
|
next_condition_link_func = self.condition_links[next_condition_link]
|
||||||
|
|
||||||
return filter_condition
|
return filter_condition
|
||||||
|
|
||||||
|
def save_to_json(self) -> dict:
|
||||||
|
"""
|
||||||
|
save the menu values in a dictionnary
|
||||||
|
:return: dictionnary
|
||||||
|
"""
|
||||||
|
|
||||||
|
json_frame_filter = {}
|
||||||
|
|
||||||
|
for frame_name, tk_frames_data in self.all_frames_filters.items():
|
||||||
|
json_frame_filter[frame_name] = []
|
||||||
|
|
||||||
|
for tk_data in tk_frames_data["list"]:
|
||||||
|
json_frame_filter[frame_name].append({})
|
||||||
|
|
||||||
|
for varname, tkvar in tk_data.items():
|
||||||
|
if "get" in dir(tkvar):
|
||||||
|
json_frame_filter[frame_name][-1][varname] = tkvar.get()
|
||||||
|
|
||||||
|
return json_frame_filter
|
||||||
|
|
||||||
|
def save_to_file(self, path: str):
|
||||||
|
with open(path, "w", encoding="utf8") as f:
|
||||||
|
json.dump(self.save_to_json(), f, ensure_ascii=False)
|
||||||
|
|
||||||
|
def promp_save_to_file(self):
|
||||||
|
filename = filedialog.asksaveasfilename(
|
||||||
|
title="Save track configuration",
|
||||||
|
defaultextension=".mkwf.tc",
|
||||||
|
filetypes=[("track configuration (*.mkwf.tc)", "*.mkwf.tc")]
|
||||||
|
)
|
||||||
|
if filename: self.save_to_file(filename)
|
||||||
|
|
||||||
|
def load_from_json(self, json_frame_filter: dict) -> None:
|
||||||
|
"""
|
||||||
|
:param json_frame_filter: json to load in the menu
|
||||||
|
"""
|
||||||
|
|
||||||
|
for json_filter_name, json_frames in json_frame_filter.items():
|
||||||
|
|
||||||
|
tk_frame_filter = self.all_frames_filters[json_filter_name]
|
||||||
|
self.del_frame_track_filter(tk_frame_filter["list"])
|
||||||
|
tk_frame_filter["variable_checkbox"].set(len(json_frames) > 0)
|
||||||
|
|
||||||
|
for i, json_frame in enumerate(json_frames):
|
||||||
|
self.add_frame_track_filter(
|
||||||
|
self.all_frames_filters[json_filter_name]["frame"],
|
||||||
|
self.all_frames_filters[json_filter_name]["list"]
|
||||||
|
)
|
||||||
|
|
||||||
|
for json_param_name, json_param_value in json_frame.items():
|
||||||
|
obj = self.all_frames_filters[json_filter_name]["list"][i][json_param_name]
|
||||||
|
if type(obj) in [Entry]:
|
||||||
|
obj.delete(0, END)
|
||||||
|
obj.insert(0, json_param_value)
|
||||||
|
else:
|
||||||
|
obj.set(json_param_value)
|
||||||
|
|
||||||
|
def load_from_file(self, path: str) -> None:
|
||||||
|
with open(path, encoding="utf8") as f:
|
||||||
|
self.load_from_json(json.load(f))
|
||||||
|
|
||||||
|
def promp_load_from_file(self):
|
||||||
|
filename = filedialog.askopenfilename(
|
||||||
|
title="Load track configuration",
|
||||||
|
defaultextension=".mkwf.tc",
|
||||||
|
filetypes=[("track configuration (*.mkwf.tc)", "*.mkwf.tc")]
|
||||||
|
)
|
||||||
|
if filename: self.load_from_file(filename)
|
Loading…
Reference in a new issue