forked from aerinon/ALttPDoorRandomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGui.py
executable file
·206 lines (166 loc) · 8.22 KB
/
Gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import json
import os
import sys
from tkinter import Tk, Button, BOTTOM, TOP, StringVar, BooleanVar, X, BOTH, RIGHT, ttk, messagebox
from CLI import get_args_priority
from DungeonRandomizer import parse_cli
from source.gui.adjust.overview import adjust_page
from source.gui.startinventory.overview import startinventory_page
from source.gui.custom.overview import custom_page
from source.gui.loadcliargs import loadcliargs, loadadjustargs
from source.gui.randomize.item import item_page
from source.gui.randomize.entrando import entrando_page
from source.gui.randomize.enemizer import enemizer_page
from source.gui.randomize.dungeon import dungeon_page
#from source.gui.randomize.multiworld import multiworld_page
from source.gui.randomize.gameoptions import gameoptions_page
from source.gui.randomize.generation import generation_page
from source.gui.bottom import bottom_frame, create_guiargs
from GuiUtils import set_icon
from Main import __version__ as ESVersion
from source.classes.BabelFish import BabelFish
from source.classes.Empty import Empty
def check_python_version(fish):
import sys
version = sys.version_info
if version.major < 3 or version.minor < 7:
messagebox.showinfo("Door Shuffle " + ESVersion, fish.translate("cli","cli","old.python.version") % sys.version)
def guiMain(args=None):
# Save settings to file
def save_settings(args):
user_resources_path = os.path.join(".", "resources", "user")
settings_path = os.path.join(user_resources_path)
if not os.path.exists(settings_path):
os.makedirs(settings_path)
for widget in self.pages["adjust"].content.widgets:
args["adjust." + widget] = self.pages["adjust"].content.widgets[widget].storageVar.get()
with open(os.path.join(settings_path, "settings.json"), "w+") as f:
f.write(json.dumps(args, indent=2))
os.chmod(os.path.join(settings_path, "settings.json"),0o755)
# Save settings from GUI
def save_settings_from_gui(confirm):
gui_args = vars(create_guiargs(self))
if self.randomSprite.get():
gui_args['sprite'] = 'random'
elif gui_args['sprite']:
gui_args['sprite'] = gui_args['sprite'].name
save_settings(gui_args)
if confirm:
messagebox.showinfo("Door Shuffle " + ESVersion, "Settings saved from GUI.")
# routine for exiting the app
def guiExit():
skip_exit = False
if self.settings['saveonexit'] == 'ask':
dosave = messagebox.askyesnocancel("Door Shuffle " + ESVersion, "Save settings before exit?")
if dosave:
save_settings_from_gui(True)
if dosave is None:
skip_exit = True
elif self.settings['saveonexit'] == 'always':
save_settings_from_gui(False)
if not skip_exit:
sys.exit(0)
# make main window
# add program title & version number
mainWindow = Tk()
self = mainWindow
mainWindow.wm_title("Door Shuffle %s" % ESVersion)
mainWindow.protocol("WM_DELETE_WINDOW", guiExit) # intercept when user clicks the X
# set program icon
set_icon(mainWindow)
# get args
# getting Settings & CLI (no GUI built yet)
self.args = get_args_priority(None, None, None)
lang = "en"
if "load" in self.args and "lang" in self.args["load"]:
lang = self.args["load"].lang
self.fish = BabelFish(lang=lang)
# get saved settings
self.settings = vars(self.args["settings"])
# make array for pages
self.pages = {}
# make array for frames
self.frames = {}
# make pages for each section
self.notebook = ttk.Notebook(self)
self.pages["randomizer"] = ttk.Frame(self.notebook)
self.pages["adjust"] = ttk.Frame(self.notebook)
self.pages["startinventory"] = ttk.Frame(self.notebook)
self.pages["custom"] = ttk.Frame(self.notebook)
self.notebook.add(self.pages["randomizer"], text='Randomize')
self.notebook.add(self.pages["adjust"], text='Adjust')
self.notebook.add(self.pages["startinventory"], text='Starting Inventory')
self.notebook.add(self.pages["custom"], text='Custom Item Pool')
self.notebook.pack()
# randomizer controls
# Randomize notebook page:
# make notebook pages: Item, Entrances, Enemizer, Dungeon Shuffle, Multiworld, Game Options, Generation Setup
# Item: Item Randomizer settings
# Entrances: Entrance Randomizer settings
# Enemizer: Enemy Randomizer settings
# Dungeon Shuffle: Dungeon Door Randomizer settings
# Multiworld: Multiworld settings
# Game Options: Cosmetic settings that don't affect logic/placement
# Generation Setup: Primarily one&done settings
self.pages["randomizer"].notebook = ttk.Notebook(self.pages["randomizer"])
# make array for pages
self.pages["randomizer"].pages = {}
# Item Randomizer
self.pages["randomizer"].pages["item"] = item_page(self.pages["randomizer"].notebook)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["item"], text="Items")
# Entrance Randomizer
self.pages["randomizer"].pages["entrance"] = entrando_page(self.pages["randomizer"].notebook)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["entrance"], text="Entrances")
# Enemizer
self.pages["randomizer"].pages["enemizer"],self.settings = enemizer_page(self.pages["randomizer"].notebook,self.settings)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["enemizer"], text="Enemizer")
# Dungeon Shuffle
self.pages["randomizer"].pages["dungeon"] = dungeon_page(self.pages["randomizer"].notebook)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["dungeon"], text="Dungeon Shuffle")
# Multiworld
# self.pages["randomizer"].pages["multiworld"],self.settings = multiworld_page(self.pages["randomizer"].notebook,self.settings)
# self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["multiworld"], text="Multiworld")
# Game Options
self.pages["randomizer"].pages["gameoptions"] = gameoptions_page(self, self.pages["randomizer"].notebook)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["gameoptions"], text="Game Options")
# Generation Setup
self.pages["randomizer"].pages["generation"],self.settings = generation_page(self.pages["randomizer"].notebook,self.settings)
self.pages["randomizer"].notebook.add(self.pages["randomizer"].pages["generation"], text="Generation Setup")
# add randomizer notebook to main window
self.pages["randomizer"].notebook.pack()
# bottom of window: Open Output Directory, Open Documentation (if exists)
self.pages["bottom"] = Empty()
self.pages["bottom"].pages = {}
self.pages["bottom"].pages["content"] = bottom_frame(self, self, None)
## Save Settings Button
savesettingsButton = Button(self.pages["bottom"].pages["content"], text='Save Settings to File', command=lambda: save_settings_from_gui(True))
savesettingsButton.pack(side=RIGHT)
# set bottom frame to main window
self.pages["bottom"].pages["content"].pack(side=BOTTOM, fill=X, padx=5, pady=5)
self.outputPath = StringVar()
self.randomSprite = BooleanVar()
# Adjuster Controls
self.pages["adjust"].content,self.settings = adjust_page(self, self.pages["adjust"], self.settings)
self.pages["adjust"].content.pack(side=TOP, fill=BOTH, expand=True)
# Starting Inventory Controls
self.pages["startinventory"].content = startinventory_page(self, self.pages["startinventory"])
self.pages["startinventory"].content.pack(side=TOP, fill=BOTH, expand=True)
# Custom Controls
self.pages["custom"].content = custom_page(self,self.pages["custom"])
self.pages["custom"].content.pack(side=TOP, fill=BOTH, expand=True)
def validation(P):
if str.isdigit(P) or P == "":
return True
else:
return False
vcmd=(self.pages["custom"].content.register(validation), '%P')
# load args
loadcliargs(self, self.args["load"])
# load adjust settings into options
loadadjustargs(self, self.settings)
check_python_version(self.fish)
# run main window
mainWindow.mainloop()
if __name__ == '__main__':
args = parse_cli(None)
guiMain(args)