forked from OoTRandomizer/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gui.py
185 lines (150 loc) · 6.99 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
#!/usr/bin/env python3
from argparse import Namespace
from glob import glob
import json
import random
import os
import shutil
from tkinter import Checkbutton, OptionMenu, Toplevel, LabelFrame, PhotoImage, Tk, LEFT, RIGHT, BOTTOM, TOP, StringVar, IntVar, Frame, Label, W, E, X, Entry, Spinbox, Button, filedialog, messagebox, ttk
from urllib.parse import urlparse
from urllib.request import urlopen
from GuiUtils import ToolTips, set_icon, BackgroundTaskProgress
from Main import main, __version__ as ESVersion
from Utils import is_bundled, local_path, output_path, open_file
def guiMain(args=None):
mainWindow = Tk()
mainWindow.wm_title("OoT Randomizer %s" % ESVersion)
set_icon(mainWindow)
notebook = ttk.Notebook(mainWindow)
randomizerWindow = ttk.Frame(notebook)
adjustWindow = ttk.Frame(notebook)
customWindow = ttk.Frame(notebook)
notebook.add(randomizerWindow, text='Randomize')
notebook.pack()
# Shared Controls
farBottomFrame = Frame(mainWindow)
def open_output():
open_file(output_path(''))
openOutputButton = Button(farBottomFrame, text='Open Output Directory', command=open_output)
if os.path.exists(local_path('README.html')):
def open_readme():
open_file(local_path('README.html'))
openReadmeButton = Button(farBottomFrame, text='Open Documentation', command=open_readme)
openReadmeButton.pack(side=LEFT)
farBottomFrame.pack(side=BOTTOM, fill=X, padx=5, pady=5)
# randomizer controls
topFrame = Frame(randomizerWindow)
rightHalfFrame = Frame(topFrame)
checkBoxFrame = Frame(rightHalfFrame)
createSpoilerVar = IntVar()
createSpoilerCheckbutton = Checkbutton(checkBoxFrame, text="Create Spoiler Log", variable=createSpoilerVar)
suppressRomVar = IntVar()
suppressRomCheckbutton = Checkbutton(checkBoxFrame, text="Do not create patched Rom", variable=suppressRomVar)
compressRomVar = IntVar()
compressRomCheckbutton = Checkbutton(checkBoxFrame, text="Compress patched Rom", variable=compressRomVar)
openForestVar = IntVar()
openForestCheckbutton = Checkbutton(checkBoxFrame, text="Open Forest", variable=openForestVar)
openDoorVar = IntVar()
openDoorCheckbutton = Checkbutton(checkBoxFrame, text="Open Door of Time", variable=openDoorVar)
dungeonItemsVar = IntVar()
dungeonItemsCheckbutton = Checkbutton(checkBoxFrame, text="Place Dungeon Items (Compasses/Maps)", onvalue=0, offvalue=1, variable=dungeonItemsVar)
beatableOnlyVar = IntVar()
beatableOnlyCheckbutton = Checkbutton(checkBoxFrame, text="Only ensure seed is beatable, not all items must be reachable", variable=beatableOnlyVar)
hintsVar = IntVar()
hintsCheckbutton = Checkbutton(checkBoxFrame, text="Gossip Stone Hints with Stone of Agony", variable=hintsVar)
createSpoilerCheckbutton.pack(expand=True, anchor=W)
suppressRomCheckbutton.pack(expand=True, anchor=W)
compressRomCheckbutton.pack(expand=True, anchor=W)
openForestCheckbutton.pack(expand=True, anchor=W)
openDoorCheckbutton.pack(expand=True, anchor=W)
dungeonItemsCheckbutton.pack(expand=True, anchor=W)
beatableOnlyCheckbutton.pack(expand=True, anchor=W)
hintsCheckbutton.pack(expand=True, anchor=W)
fileDialogFrame = Frame(rightHalfFrame)
romDialogFrame = Frame(fileDialogFrame)
baseRomLabel = Label(romDialogFrame, text='Base Rom')
romVar = StringVar()
romEntry = Entry(romDialogFrame, textvariable=romVar)
def RomSelect():
rom = filedialog.askopenfilename(filetypes=[("Rom Files", (".z64", ".n64")), ("All Files", "*")])
romVar.set(rom)
romSelectButton = Button(romDialogFrame, text='Select Rom', command=RomSelect)
baseRomLabel.pack(side=LEFT)
romEntry.pack(side=LEFT)
romSelectButton.pack(side=LEFT)
romDialogFrame.pack()
checkBoxFrame.pack()
fileDialogFrame.pack()
drowDownFrame = Frame(topFrame)
bridgeFrame = Frame(drowDownFrame)
bridgeVar = StringVar()
bridgeVar.set('medallions')
bridgeOptionMenu = OptionMenu(bridgeFrame, bridgeVar, 'medallions', 'vanilla', 'dungeons', 'open')
bridgeOptionMenu.pack(side=RIGHT)
bridgeLabel = Label(bridgeFrame, text='Rainbow Bridge Requirement')
bridgeLabel.pack(side=LEFT)
bridgeFrame.pack(expand=True, anchor=E)
bottomFrame = Frame(randomizerWindow)
seedLabel = Label(bottomFrame, text='Seed #')
seedVar = StringVar()
seedEntry = Entry(bottomFrame, textvariable=seedVar)
countLabel = Label(bottomFrame, text='Count')
countVar = StringVar()
countSpinbox = Spinbox(bottomFrame, from_=1, to=100, textvariable=countVar)
def generateRom():
guiargs = Namespace
guiargs.seed = int(seedVar.get()) if seedVar.get() else None
guiargs.count = int(countVar.get()) if countVar.get() != '1' else None
guiargs.bridge = bridgeVar.get()
guiargs.create_spoiler = bool(createSpoilerVar.get())
guiargs.suppress_rom = bool(suppressRomVar.get())
guiargs.compress_rom = bool(compressRomVar.get())
guiargs.open_forest = bool(openForestVar.get())
guiargs.open_door_of_time = bool(openDoorVar.get())
guiargs.nodungeonitems = bool(dungeonItemsVar.get())
guiargs.beatableonly = bool(beatableOnlyVar.get())
guiargs.hints = bool(hintsVar.get())
guiargs.rom = romVar.get()
try:
if guiargs.count is not None:
seed = guiargs.seed
for _ in range(guiargs.count):
main(seed=seed, args=guiargs)
seed = random.randint(0, 999999999)
else:
main(seed=guiargs.seed, args=guiargs)
except Exception as e:
messagebox.showerror(title="Error while creating seed", message=str(e))
else:
messagebox.showinfo(title="Success", message="Rom patched successfully")
generateButton = Button(bottomFrame, text='Generate Patched Rom', command=generateRom)
seedLabel.pack(side=LEFT)
seedEntry.pack(side=LEFT)
countLabel.pack(side=LEFT, padx=(5, 0))
countSpinbox.pack(side=LEFT)
generateButton.pack(side=LEFT, padx=(5, 0))
openOutputButton.pack(side=RIGHT)
drowDownFrame.pack(side=LEFT)
rightHalfFrame.pack(side=RIGHT)
topFrame.pack(side=TOP)
bottomFrame.pack(side=BOTTOM)
if args is not None:
# load values from commandline args
createSpoilerVar.set(int(args.create_spoiler))
suppressRomVar.set(int(args.suppress_rom))
compressRomVar.set(int(args.compress_rom))
if args.nodungeonitems:
dungeonItemsVar.set(int(not args.nodungeonitems))
openForestVar.set(int(args.open_forest))
openDoorVar.set(int(args.open_door_of_time))
beatableOnlyVar.set(int(args.beatableonly))
hintsVar.set(int(args.hints))
if args.count:
countVar.set(str(args.count))
if args.seed:
seedVar.set(str(args.seed))
bridgeVar.set(args.bridge)
romVar.set(args.rom)
mainWindow.mainloop()
if __name__ == '__main__':
guiMain()