-
Notifications
You must be signed in to change notification settings - Fork 7
/
Gui.py
574 lines (476 loc) · 25.9 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#!/usr/bin/env python3
from argparse import Namespace
from glob import glob
import json
import random
import re
import os
import shutil
from tkinter import Scale, Checkbutton, OptionMenu, Toplevel, LabelFrame, Radiobutton, PhotoImage, Tk, BOTH, LEFT, RIGHT, BOTTOM, TOP, StringVar, IntVar, Frame, Label, W, E, X, N, S, NW, Entry, Spinbox, Button, filedialog, messagebox, ttk, HORIZONTAL, Toplevel
from tkinter.colorchooser import *
from urllib.parse import urlparse
from urllib.request import urlopen
from GuiUtils import ToolTips, set_icon, BackgroundTask, BackgroundTaskProgress, Dialog
from Main import main
from Utils import is_bundled, local_path, default_output_path, open_file
from Patches import get_tunic_color_options, get_navi_color_options
from Settings import Settings, setting_infos
import webbrowser
def settings_to_guivars(settings, guivars):
for info in setting_infos:
name = info.name
if name not in guivars:
continue
guivar = guivars[name]
value = settings.__dict__[name]
# checkbox
if info.type == bool:
guivar.set( int(value) )
# dropdown/radiobox
if info.type == str:
if value is None:
guivar.set( "" )
else:
if info.gui_params and 'options' in info.gui_params:
if 'Custom Color' in info.gui_params['options'] and re.match(r'^[A-Fa-f0-9]{6}$', value):
guivar.set('Custom (#' + value + ')')
else:
for gui_text,gui_value in info.gui_params['options'].items():
if gui_value == value:
guivar.set( gui_text )
else:
guivar.set( value )
# text field for a number...
if info.type == int:
if value is None:
guivar.set( str(1) )
else:
guivar.set( str(value) )
def guivars_to_settings(guivars):
result = {}
for info in setting_infos:
name = info.name
if name not in guivars:
result[name] = None
continue
guivar = guivars[name]
# checkbox
if info.type == bool:
result[name] = bool(guivar.get())
# dropdown/radiobox
if info.type == str:
# set guivar to hexcode if custom color
if re.match(r'^Custom \(#[A-Fa-f0-9]{6}\)$', guivar.get()):
result[name] = re.findall(r'[A-Fa-f0-9]{6}', guivar.get())[0]
elif info.gui_params and 'options' in info.gui_params:
result[name] = info.gui_params['options'][guivar.get()]
else:
result[name] = guivar.get()
# text field for a number...
if info.type == int:
result[name] = int( guivar.get() )
if result['seed'] == "":
result['seed'] = None
if result['count'] == 1:
result['count'] = None
return Settings(result)
def guiMain(settings=None):
frames = {}
mainWindow = Tk()
mainWindow.wm_title("Better OoT v3.0.2")
mainWindow.resizable(False, False)
set_icon(mainWindow)
notebook = ttk.Notebook(mainWindow)
frames['rom_tab'] = ttk.Frame(notebook)
frames['rules_tab'] = ttk.Frame(notebook)
frames['logic_tab'] = ttk.Frame(notebook)
frames['other_tab'] = ttk.Frame(notebook)
frames['aesthetic_tab'] = ttk.Frame(notebook)
frames['aesthetic_tab_left'] = Frame(frames['aesthetic_tab'])
frames['aesthetic_tab_right'] = Frame(frames['aesthetic_tab'])
adjustWindow = ttk.Frame(notebook)
customWindow = ttk.Frame(notebook)
notebook.add(frames['rom_tab'], text='ROM')
#notebook.add(frames['rules_tab'], text='Main Rules')
#notebook.add(frames['logic_tab'], text='Detailed Logic')
notebook.add(frames['other_tab'], text='Options')
notebook.add(frames['aesthetic_tab'], text='Cosmetics')
#######################
# randomizer controls #
#######################
# hold the results of the user's decisions here
guivars = {}
# hierarchy
############
#Rules Tab
frames['open'] = LabelFrame(frames['rules_tab'], text='Open', labelanchor=NW)
frames['world'] = LabelFrame(frames['rules_tab'], text='World', labelanchor=NW)
frames['logic'] = LabelFrame(frames['rules_tab'], text='Shuffle', labelanchor=NW)
# Logic tab
frames['rewards'] = LabelFrame(frames['logic_tab'], text='Remove Specific Locations', labelanchor=NW)
frames['tricks'] = LabelFrame(frames['logic_tab'], text='Specific expected tricks', labelanchor=NW)
#Other Tab
frames['convenience'] = LabelFrame(frames['other_tab'], text='Remove Area Intro Cutscenes', labelanchor=NW)
frames['other'] = LabelFrame(frames['other_tab'], text='Settings', labelanchor=NW)
#Aesthetics tab
frames['cosmetics'] = LabelFrame(frames['aesthetic_tab'], text='General', labelanchor=NW)
frames['tuniccolor'] = LabelFrame(frames['aesthetic_tab_left'], text='Tunic Color', labelanchor=NW)
frames['swordcolor'] = LabelFrame(frames['aesthetic_tab_left'], text='Sword Color', labelanchor=NW)
frames['navicolor'] = LabelFrame(frames['aesthetic_tab_right'], text='Navi Color', labelanchor=NW)
frames['lowhp'] = LabelFrame(frames['aesthetic_tab_left'], text='Low HP SFX', labelanchor=NW)
frames['navihint'] = LabelFrame(frames['aesthetic_tab_right'], text='Navi SFX', labelanchor=NW)
# shared
settingsFrame = Frame(mainWindow)
settings_string_var = StringVar()
settingsEntry = Entry(settingsFrame, textvariable=settings_string_var, width=10)
def show_settings(event=None):
settings = guivars_to_settings(guivars)
settings_string_var.set( settings.get_settings_string() )
# Update any dependencies
for info in setting_infos:
if info.gui_params and 'dependency' in info.gui_params:
dep_met = info.gui_params['dependency'](guivars)
if widgets[info.name].winfo_class() == 'Frame':
for child in widgets[info.name].winfo_children():
if child.winfo_class() == 'TCombobox':
child.configure(state= 'readonly' if dep_met else 'disabled')
else:
child.configure(state= 'normal' if dep_met else 'disabled')
if child.winfo_class() == 'Scale':
child.configure(fg='Black'if dep_met else 'Grey')
else:
if widgets[info.name].winfo_class() == 'TCombobox':
widgets[info.name].configure(state= 'readonly' if dep_met else 'disabled')
else:
widgets[info.name].configure(state= 'normal' if dep_met else 'disabled')
if widgets[info.name].winfo_class() == 'Scale':
widgets[info.name].configure(fg='Black'if dep_met else 'Grey')
if info.name in guivars and guivars[info.name].get() == 'Custom Color':
color = askcolor()
if color == (None, None):
color = ((0,0,0),'#000000')
guivars[info.name].set('Custom (' + color[1] + ')')
def show_settings_special(event=None):
if guivars['logic_tricks'].get():
widgets['logic_man_on_roof'].select()
widgets['logic_child_deadhand'].select()
widgets['logic_dc_jump'].select()
widgets['logic_windmill_hp'].select()
widgets['logic_crater_bean_hp_with_hovers'].select()
widgets['logic_zora_with_cucco'].select()
widgets['logic_fewer_tunic_requirements'].select()
else:
widgets['logic_man_on_roof'].deselect()
widgets['logic_child_deadhand'].deselect()
widgets['logic_dc_jump'].deselect()
widgets['logic_windmill_hp'].deselect()
widgets['logic_crater_bean_hp_with_hovers'].deselect()
widgets['logic_zora_with_cucco'].deselect()
widgets['logic_fewer_tunic_requirements'].deselect()
settings = guivars_to_settings(guivars)
settings_string_var.set( settings.get_settings_string() )
def import_settings(event=None):
try:
settings = guivars_to_settings(guivars)
text = settings_string_var.get().upper()
settings.update_with_settings_string(text)
settings_to_guivars(settings, guivars)
except Exception as e:
messagebox.showerror(title="Error", message="Invalid settings string")
label = Label(settingsFrame, text="Settings String")
importSettingsButton = Button(settingsFrame, text='Import Settings String', command=import_settings)
label.pack(side=LEFT, anchor=W, padx=5)
settingsEntry.pack(side=LEFT, anchor=W)
importSettingsButton.pack(side=LEFT, anchor=W, padx=5)
#Import ROM
fileDialogFrame = Frame(frames['rom_tab'])
romDialogFrame = Frame(fileDialogFrame)
baseRomLabel = Label(romDialogFrame, text='Base ROM')
guivars['rom'] = StringVar(value='ZOOTDEC.z64')
romEntry = Entry(romDialogFrame, textvariable=guivars['rom'], width=40)
def RomSelect():
rom = filedialog.askopenfilename(filetypes=[("ROM Files", (".z64", ".n64")), ("All Files", "*")])
if rom != '':
guivars['rom'].set(rom)
romSelectButton = Button(romDialogFrame, text='Select ROM', command=RomSelect, width=10)
baseRomLabel.pack(side=LEFT, padx=(38,0))
romEntry.pack(side=LEFT, padx=3)
romSelectButton.pack(side=LEFT)
romDialogFrame.pack()
fileDialogFrame.pack(side=TOP, anchor=W, padx=5, pady=(5,1))
#Import WAD
fileDialogFrame = Frame(frames['rom_tab'])
wadDialogFrame = Frame(fileDialogFrame)
baseWadLabel = Label(wadDialogFrame, text='Base WAD')
guivars['wad'] = StringVar(value='')
wadEntry = Entry(wadDialogFrame, textvariable=guivars['wad'], width=40)
def wadSelect():
wad = filedialog.askopenfilename(filetypes=[("WAD Files", (".wad")), ("All Files", "*")])
if wad != '':
guivars['wad'].set(wad)
wadSelectButton = Button(wadDialogFrame, text='Select WAD', command=wadSelect, width=10)
baseWadLabel.pack(side=LEFT, padx=(38,0))
wadEntry.pack(side=LEFT, padx=3)
wadSelectButton.pack(side=LEFT)
wadDialogFrame.pack()
fileDialogFrame.pack(side=TOP, anchor=W, padx=5, pady=(5,1))
#Output dir
def open_output():
open_file(output_path(''))
def output_dir_select():
rom = filedialog.askdirectory(initialdir = default_output_path(guivars['output_dir'].get()))
if rom != '':
guivars['output_dir'].set(rom)
outputDialogFrame = Frame(frames['rom_tab'])
outputDirLabel = Label(outputDialogFrame, text='Output Directory')
guivars['output_dir'] = StringVar(value='')
outputDirEntry = Entry(outputDialogFrame, textvariable=guivars['output_dir'], width=40)
outputDirButton = Button(outputDialogFrame, text='Select Dir', command=output_dir_select, width=10)
outputDirLabel.pack(side=LEFT, padx=(3,0))
outputDirEntry.pack(side=LEFT, padx=3)
outputDirButton.pack(side=LEFT)
outputDialogFrame.pack(side=TOP, anchor=W, padx=5, pady=(5,1))
if os.path.exists(local_path('README.html')):
def open_readme():
open_file(local_path('README.html'))
openReadmeButton = Button(outputDialogFrame, text='Open Documentation', command=open_readme)
openReadmeButton.pack(side=LEFT, padx=5)
outputDialogFrame.pack(side=TOP, anchor=W, pady=3)
countDialogFrame = Frame(frames['rom_tab'])
countLabel = Label(countDialogFrame, text='Generation Count')
guivars['count'] = StringVar()
countSpinbox = Spinbox(countDialogFrame, from_=1, to=100, textvariable=guivars['count'], width=3)
countLabel.pack(side=LEFT)
countSpinbox.pack(side=LEFT, padx=2)
#countDialogFrame.pack(side=TOP, anchor=W, padx=5, pady=(1,1))
# build gui
############
widgets = {}
for info in setting_infos:
if info.gui_params:
if info.gui_params['widget'] == 'Checkbutton':
# determine the initial value of the checkbox
default_value = 1 if info.gui_params['default'] == "checked" else 0
# create a variable to access the box's state
guivars[info.name] = IntVar(value=default_value)
# create the checkbox
widgets[info.name] = Checkbutton(frames[info.gui_params['group']], text=info.gui_params['text'], variable=guivars[info.name], justify=LEFT, wraplength=190, command=show_settings)
#Hardcode in checkboxes I want shown (messy af but who cares)
#to put on left flags tab, change type in settings info to "convenience"
#to put on right settings tab, change type in settings info to "other"
#the order they will appear is how they are ordered in settings_info
if info.name == 'fast_chests':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'no_owls':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'forest_elevator':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'dungeon_speedup':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_intro':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'song_speedup':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'knuckle_cs':
widgets[info.name].pack(expand=False, anchor=W)
#area intro cutscenes
if info.name == 'skip_deku':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_gc':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_castle':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_domain':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_kak':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_dmt':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_field':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_colossus':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_fountain':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_gy':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_jabu':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_gf':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_gv':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_lh':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_dc':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'skip_dmc':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'quest':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'quickboots':
widgets[info.name].pack(expand=False, anchor=W)
if info.name == 'fast_elevator':
widgets[info.name].pack(expand=False, anchor=W)
if info.gui_params['widget'] == 'SpecialCheckbutton':
# determine the initial value of the checkbox
default_value = 1 if info.gui_params['default'] == "checked" else 0
# create a variable to access the box's state
guivars[info.name] = IntVar(value=default_value)
# create the checkbox
widgets[info.name] = Checkbutton(frames[info.gui_params['group']], text=info.gui_params['text'], variable=guivars[info.name], justify=LEFT, wraplength=190, command=show_settings_special)
widgets[info.name].pack(expand=False, anchor=W)
elif info.gui_params['widget'] == 'Combobox':
# create the variable to store the user's decision
guivars[info.name] = StringVar(value=info.gui_params['default'])
# create the option menu
widgets[info.name] = Frame(frames[info.gui_params['group']])
# dropdown = OptionMenu(widgets[info.name], guivars[info.name], *(info['options']))
if isinstance(info.gui_params['options'], list):
info.gui_params['options'] = dict(zip(info.gui_params['options'], info.gui_params['options']))
dropdown = ttk.Combobox(widgets[info.name], textvariable=guivars[info.name], values=list(info.gui_params['options'].keys()), state='readonly', width=30)
dropdown.bind("<<ComboboxSelected>>", show_settings)
dropdown.pack(side=BOTTOM, anchor=W)
# label the option
if 'text' in info.gui_params:
label = Label(widgets[info.name], text=info.gui_params['text'])
label.pack(side=LEFT, anchor=W, padx=5)
# pack the frame
if info.name == 'hints':
continue
elif info.name == 'text_shuffle':
continue
else:
widgets[info.name].pack(expand=False, side=TOP, anchor=W, padx=3, pady=3)
elif info.gui_params['widget'] == 'Radiobutton':
# create the variable to store the user's decision
guivars[info.name] = StringVar(value=info.gui_params['default'])
# create the option menu
widgets[info.name] = LabelFrame(frames[info.gui_params['group']], text=info.gui_params['text'] if 'text' in info.gui_params else info["name"], labelanchor=NW)
if isinstance(info.gui_params['options'], list):
info.gui_params['options'] = dict(zip(info.gui_params['options'], info.gui_params['options']))
# setup orientation
side = TOP
anchor = W
if "horizontal" in info.gui_params and info.gui_params["horizontal"]:
side = LEFT
anchor = N
# add the radio buttons
for option in info.gui_params["options"]:
radio_button = Radiobutton(widgets[info.name], text=option, value=option, variable=guivars[info.name], justify=LEFT, wraplength=190, indicatoron=False, command=show_settings)
radio_button.pack(expand=True, side=side, anchor=anchor)
# pack the frame
if info.name == 'create_wad':
widgets[info.name].pack(expand=False, side=TOP, anchor=W, padx=10, pady=5)
elif info.gui_params['widget'] == 'Scale':
# create the variable to store the user's decision
guivars[info.name] = IntVar(value=info.gui_params['default'])
# create the option menu
widgets[info.name] = Frame(frames[info.gui_params['group']])
# dropdown = OptionMenu(widgets[info.name], guivars[info.name], *(info['options']))
minval = 'min' in info.gui_params and info.gui_params['min'] or 0
maxval = 'max' in info.gui_params and info.gui_params['max'] or 100
stepval = 'step' in info.gui_params and info.gui_params['step'] or 1
scale = Scale(widgets[info.name], variable=guivars[info.name], from_=minval, to=maxval, tickinterval=stepval, resolution=stepval, showvalue=0, orient=HORIZONTAL, sliderlength=15, length=200, command=show_settings)
#scale.pack(side=BOTTOM, anchor=W)
# label the option
if 'text' in info.gui_params:
label = Label(widgets[info.name], text=info.gui_params['text'])
label.pack(side=LEFT, anchor=W, padx=5)
# pack the frame
widgets[info.name].pack(expand=False, side=TOP, anchor=W, padx=3, pady=3)
elif info.gui_params['widget'] == 'Entry':
# create the variable to store the user's decision
guivars[info.name] = StringVar(value=info.gui_params['default'])
# create the option menu
widgets[info.name] = Frame(frames[info.gui_params['group']])
entry = Entry(widgets[info.name], textvariable=guivars[info.name], width=30)
entry.pack(side=BOTTOM, anchor=W)
# label the option
if 'text' in info.gui_params:
label = Label(widgets[info.name], text=info.gui_params['text'])
label.pack(side=LEFT, anchor=W, padx=5)
# pack the frame
#widgets[info.name].pack(expand=False, side=TOP, anchor=W, padx=3, pady=3)
if 'tooltip' in info.gui_params:
ToolTips.register(widgets[info.name], info.gui_params['tooltip'])
# pack the hierarchy
frames['logic'].pack( fill=BOTH, expand=True, anchor=N, side=RIGHT, pady=(5,1) )
frames['open'].pack( fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
frames['world'].pack( fill=BOTH, expand=True, anchor=W, side=BOTTOM, pady=(5,1) )
# Logic tab
frames['rewards'].pack(fill=BOTH, expand=True, anchor=N, side=LEFT, pady=(5,1) )
frames['tricks'].pack( fill=BOTH, expand=True, anchor=N, side=LEFT, pady=(5,1) )
#Other Tab
frames['convenience'].pack(fill=BOTH, expand=True, anchor=N, side=LEFT, pady=(5,1) )
frames['other'].pack( fill=BOTH, expand=True, anchor=N, side=LEFT, pady=(5,1) )
#Aesthetics tab
frames['cosmetics'].pack(fill=BOTH, expand=True, anchor=W, side=TOP)
frames['aesthetic_tab_left'].pack( fill=BOTH, expand=True, anchor=W, side=LEFT)
frames['aesthetic_tab_right'].pack(fill=BOTH, expand=True, anchor=W, side=RIGHT)
#Aesthetics tab - Left Side
frames['tuniccolor'].pack(fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
frames['swordcolor'].pack(fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
frames['lowhp'].pack( fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
#Aesthetics tab - Right Side
frames['navicolor'].pack( fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
frames['navihint'].pack( fill=BOTH, expand=True, anchor=W, side=TOP, pady=(5,1) )
notebook.pack(fill=BOTH, expand=True, padx=5, pady=5)
multiworldFrame = LabelFrame(frames['rom_tab'], text='Multi-World Generation')
countLabel = Label(multiworldFrame, wraplength=350, justify=LEFT, text='This is used for co-op generations. Increasing Player Count will drastically increase the generation time. For more information see:')
hyperLabel = Label(multiworldFrame, wraplength=350, justify=LEFT, text='https://github.com/TestRunnerSRL/bizhawk-co-op', fg='blue', cursor='hand2')
hyperLabel.bind("<Button-1>", lambda event: webbrowser.open_new(r"https://github.com/TestRunnerSRL/bizhawk-co-op"))
countLabel.pack(side=TOP, anchor=W, padx=5, pady=0)
hyperLabel.pack(side=TOP, anchor=W, padx=5, pady=0)
worldCountFrame = Frame(multiworldFrame)
countLabel = Label(worldCountFrame, text='Player Count')
guivars['world_count'] = StringVar()
countSpinbox = Spinbox(worldCountFrame, from_=1, to=100, textvariable=guivars['world_count'], width=3)
countLabel.pack(side=LEFT)
countSpinbox.pack(side=LEFT, padx=2)
#worldCountFrame.pack(side=LEFT, anchor=N, padx=10, pady=(1,5))
playerNumFrame = Frame(multiworldFrame)
countLabel = Label(playerNumFrame, text='Player ID')
guivars['player_num'] = StringVar()
countSpinbox = Spinbox(playerNumFrame, from_=1, to=100, textvariable=guivars['player_num'], width=3)
countLabel.pack(side=LEFT)
countSpinbox.pack(side=LEFT, padx=2)
playerNumFrame.pack(side=LEFT, anchor=N, padx=10, pady=(1,5))
# create the option menu
def generateRom():
settings = guivars_to_settings(guivars)
if settings.count is not None:
BackgroundTaskProgress(mainWindow, "Patching File", multiple_run, settings)
else:
BackgroundTaskProgress(mainWindow, "Patching File", main, settings)
generateButton = Button(settingsFrame, text='Generate Patched File', command=generateRom)
generateButton.pack(side=LEFT, padx=(5, 0))
settingsFrame.pack(fill=BOTH, anchor=W, padx=5, pady=(10,10))
def multiple_run(settings, window):
orig_seed = settings.seed
for i in range(settings.count):
settings.update_seed(orig_seed + '-' + str(i))
window.update_title("Patching ROM")
main(settings, window)
guivars['checked_version'] = StringVar()
if settings is not None:
# load values from commandline args
settings_to_guivars(settings, guivars)
else:
# try to load saved settings
try:
settingsFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'settings.sav')
with open(settingsFile) as f:
settings = Settings( json.load(f) )
settings.update_seed("")
settings_to_guivars(settings, guivars)
except:
pass
show_settings()
mainWindow.mainloop()
# save settings on close
with open('settings.sav', 'w') as outfile:
settings = guivars_to_settings(guivars)
json.dump(settings.__dict__, outfile)
if __name__ == '__main__':
guiMain()