-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
312 lines (234 loc) · 13.5 KB
/
app.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
import shutil
from tkinter import CENTER, HORIZONTAL
from types import NoneType
import PySimpleGUI as sg
from mod_manager import create_new_mod_folder, check_if_mod_exists, get_all_current_mods, delete_mod, get_read_publishinfo_file_description, update_publishinfo_file_description, get_god_portrait_as_png, create_new_portrait_image, delete_god_portrait
import re
from PIL import Image
import json
from index import convert_to_bytes
from pathlib import Path
import os
app_title = "Age of Mythology: Extended Edition Portrait Maker"
sg.theme('DarkAmber')
a=get_all_current_mods()
pattern = r'[0-9]'
current_mod_opened = ""
current_civilization = ""
current_god_being_editied = ""
current_ui_frame = ""
image_x = int(0)
image_y = int(0)
image_width = int(0)
image_height = int(0)
file_types = [("JPEG (*.jpg)", "*.jpg"),
("PNG (*.png)", "*.png")]
layout = [
[sg.Text("AOM Portrait Maker", font=("Verdana",20))],
*[[sg.Text(i['name']), sg.Button(("Open "+i["name"]), key="open_mod_name"), sg.Button(("Delete "+i["name"]), key="delete_mod_name")] for i in (a)],
[sg.Text("enter portrait mod name:"),sg.Input(key='mod_name'), sg.Button("Create", key="update_file_manager")],
]
def return_json_file_data(file_path):
f = open(file_path)
data = json.load(f)
return data
def is_valid_path(filepath):
if filepath and Path(filepath).exists():
if check_if_mod_exists(current_mod_opened, filepath) == False:
return True
else:
delete_mod((filepath+"/"+current_mod_opened))
return True
else:
sg.popup_error("Filepath not correct.")
return False
def check_if_mod_exists(name, filepath):
for folder_name in os.listdir(filepath):
if folder_name.lower() == name.lower():
#print(folder_name)
return True
return False
workshop_image_layout = [
[sg.Text("Workshop Image")],
[sg.Image(source="./card_background.png")],
[sg.Button("change image")],
]
layout_two = [
[sg.Text(current_mod_opened, font=("Verdana",30))],
[sg.Column([[sg.Text("Workshop Description")], [sg.Multiline(size=(50, 18), key='mod_description', default_text=get_read_publishinfo_file_description(current_mod_opened))], [sg.Button("Save", key="save_mod_description")]]), sg.Column([[sg.Text("Workshop Image")],
[sg.Image(size=(290, 290), key="workshop_image")],
[sg.Button("change image")], ])],
[sg.Text("Factions", font=("Times New Roman",20))]
]
edit_god_portait_layout = [
]
window_layout = [[sg.Column(layout, visible=True, key='file_manager'), sg.Column(layout_two, visible=False, key='faction_picker')]]
window = sg.Window(app_title, window_layout)
def refresh_mod_window():
a=get_all_current_mods()
layout = [
[sg.Text("AOM Portrait Maker", font=("Verdana",20))],
*[[sg.Text(i['name']), sg.Button(("Open "+i["name"]), key="open_mod_name"), sg.Button(("Delete "+i["name"]), key="delete_mod_name")] for i in (a)],
[sg.Text("enter portrait mod name:"),sg.Input(key='mod_name'), sg.Button("Create", key="update_file_manager")],
]
window1 = sg.Window(app_title, location=window.Location).Layout(layout)
return window1
def edit_current_civilization_portaits():
civilization_data = return_json_file_data("./data/CivilizationData.json")["Civilizations"][current_civilization]
edit_god_portait_layout = [
[sg.Text(current_civilization, font=("Verdana",20))],
[sg.Text("Ui Gods", font=("Verdana",18), pad=(10, 10))],
[sg.Column([ [sg.Image(data=convert_to_bytes(get_god_portrait_as_png(current_mod_opened, text, "_ui_gods", current_civilization), (110, 110)))], [sg.Text(text, font=("Verdana",12))], [sg.Button("Edit", key=text+"_ui_gods", font=("Verdana",12)), sg.Button("Reset", key="reset_"+text+"_ui_gods", font=("Verdana",12))] ], element_justification="C", pad=(5,5)) for text in civilization_data["ui_gods"]],
[sg.Text("Major Gods", font=("Verdana",18), pad=(10, 10))],
[sg.Column([ [sg.Image(data=convert_to_bytes(get_god_portrait_as_png(current_mod_opened, text, "_major_gods", current_civilization), (64, 64)))], [sg.Text(text, font=("Verdana",12))], [sg.Button("Edit", key=text+"_major_gods", font=("Verdana",10)), sg.Button("Reset", key="reset_"+text+"_major_gods", font=("Verdana",10))] ], element_justification="C", pad=(1,1)) for text in civilization_data["major_gods"]],
[sg.Text("Minor Gods", font=("Verdana",18), pad=(10, 10))],
[sg.Column([ [sg.Image(data=convert_to_bytes(get_god_portrait_as_png(current_mod_opened, text, "_minor_gods", current_civilization), (90, 90)))], [sg.Text(text, font=("Verdana",12))], [sg.Button("Edit", key=text+"_minor_gods", font=("Verdana",10)), sg.Button("Reset", key="reset_"+text+"_minor_gods", font=("Verdana",10))] ], element_justification="C", pad=(1,1)) for text in civilization_data["minor_gods"]],
[sg.Button("Finished", pad=(20, 20), font=("Verdana", 15), key="Finished_with_civilization_layout")]
]
colum_layout = [
[sg.Column(edit_god_portait_layout, scrollable=True, element_justification="C", size=(1300, 750), expand_y=True, expand_x=True, justification=CENTER, grab=True)]
]
window1 = sg.Window(app_title, location=window.Location, element_justification="C", resizable=True).Layout(colum_layout)
return window1
def edit_god_image_layout():
make_custom_god_portrait_layout = [
[sg.Text(current_god_being_editied, font=("Verdana",30))],
[sg.Image(data=convert_to_bytes(get_god_portrait_as_png(current_mod_opened, current_god_being_editied, current_ui_frame, current_civilization), (256, 256)), key="currently_editing_god_image")],
[sg.Text("Import New Image:"), sg.FileBrowse(file_types=file_types, key="portrait_image_file")],
[sg.Text("image x coordinates"), sg.Slider(range=(-500, 500), default_value=image_x, size=(45, 10), orientation=HORIZONTAL, key="image_x_cord")],
[sg.Text("image y coordinates"), sg.Slider(range=(-500, 500), default_value=image_y, size=(45, 10), orientation=HORIZONTAL, key="image_y_cord")],
[sg.Text("image width"), sg.Slider(range=(10, 400), default_value=image_width, size=(45, 10), orientation=HORIZONTAL, key="image_width")],
[sg.Text("image height"), sg.Slider(range=(10, 400), default_value=image_height, size=(45, 10), orientation=HORIZONTAL, key="image_height")],
[sg.Button("Update Image", key="change_character_image")],
[sg.Button("Finished", key="close_edit_god_image_layout")]
]
window1 = sg.Window(app_title, location=window.Location, element_justification="C").Layout(make_custom_god_portrait_layout)
return window1
def refresh_open_faction_picker_layout():
layout_two = [
[sg.Text(current_mod_opened, font=("Verdana",30))],
[sg.Column([[sg.Text("Workshop Description")], [sg.Multiline(size=(50, 15.5), key='mod_description', default_text=get_read_publishinfo_file_description(current_mod_opened))], [sg.Button("Save", key="save_mod_description")]]), sg.Column([[sg.Text("Workshop Image")],
[sg.Image(data=convert_to_bytes("./Mods/"+current_mod_opened+"/workshop-preview-icon.jpg", (256, 256)), key="workshop_image")],
[sg.FileBrowse(file_types=file_types, key="workshop_image_file"), sg.Button("update image")] ])],
[sg.Text("Edit Civilization Portraits", font=("Times New Roman",20))],
[sg.Button("Greeks", pad=(10, 10)), sg.Button("Egyptians", pad=(10, 10)), sg.Button("Norse", pad=(10, 10)), sg.Button("Atlanteans", pad=(10, 10)), sg.Button("Chinese", pad=(10, 10))],
[sg.Text("Mod Export Folder: "), sg.Input(key="mod_export_path"), sg.FolderBrowse()],
[sg.Button("Export Mod", pad=(20, 20), font=("Verdana",12))]
]
window1 = sg.Window(app_title, location=window.Location, element_justification="C").Layout(layout_two)
return window1
while True:
event, values = window.read()
#print(event)
if event == "Export Mod" and is_valid_path(values["mod_export_path"]) != False:
#print(values["mod_export_path"])
shutil.copytree(("./Mods/"+current_mod_opened), (values["mod_export_path"]+"/"+current_mod_opened))
sg.popup("Mod Exported!")
if event == "change_character_image" and values["portrait_image_file"] != "":
new_image_path = create_new_portrait_image(current_ui_frame, current_god_being_editied, values["portrait_image_file"], values["image_x_cord"],values["image_y_cord"],values["image_width"],values["image_height"], current_mod_opened, current_civilization)
image_data = convert_to_bytes(new_image_path)
window['currently_editing_god_image'].update(data=image_data)
if event != None:
if "ui_gods" in event:
if "reset" not in event:
god = event.replace("_ui_gods", "")
ui_type = event.replace(god, "")
current_god_being_editied = god
current_ui_frame = ui_type
#print("look here:"+current_ui_frame)
image_x = 46
image_y = 50
image_width = 160
image_height = 158
window.close()
window = edit_god_image_layout()
if event != None:
if "ui_gods" in event:
if "reset" in event:
god = event.replace("_ui_gods", "").replace("reset_", "")
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god+" 256x256.tga"))
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god+" 128x128.tga"))
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god+" 64x64.tga"))
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/ui/ui god "+god+" 32x32.tga"))
window.Close()
window = edit_current_civilization_portaits()
if event != None:
if "major_gods" in event:
if "reset" in event:
god = event.replace("_major_gods", "").replace("reset_", "")
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/icons/improvement "+god+" icon.tga"))
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/icons/god major "+god+" icons 64.tga"))
window.Close()
window = edit_current_civilization_portaits()
if event != None:
if "minor_gods" in event:
if "reset" in event:
god = event.replace("_minor_gods", "").replace("reset_", "")
delete_god_portrait(("./Mods/"+current_mod_opened+"/textures/god minor portrait "+current_civilization.lower()+" "+god+".tga"))
window.Close()
window = edit_current_civilization_portaits()
if event != None:
if "major_gods" in event:
if "reset" not in event:
god = event.replace("_major_gods", "")
ui_type = event.replace(god, "")
current_god_being_editied = god
current_ui_frame = ui_type
image_x = 0
image_y = 0
image_width = 64
image_height = 64
window.close()
window = edit_god_image_layout()
if event != None:
if "minor_gods" in event:
if "reset" not in event:
god = event.replace("_minor_gods", "")
ui_type = event.replace(god, "")
current_god_being_editied = god
current_ui_frame = ui_type
image_x = 0
image_y = 0
image_width = 180
image_height = 256
window.close()
window = edit_god_image_layout()
if event in return_json_file_data("./data/CivilizationData.json")["Civilizations"].keys():
current_civilization = event
window.Close()
window = edit_current_civilization_portaits()
if event == "close_edit_god_image_layout":
current_god_being_editied = ""
window.Close()
window = edit_current_civilization_portaits()
if event == "update image":
if values["workshop_image_file"] != "":
image = Image.open(values["workshop_image_file"])
workshop_image_size = 512, 512
image = image.resize(workshop_image_size)
image.save("./Mods/"+current_mod_opened+"/workshop-preview-icon.jpg")
window.close()
window = refresh_open_faction_picker_layout()
if event == "save_mod_description":
update_publishinfo_file_description(current_mod_opened, values["mod_description"])
if event == sg.WINDOW_CLOSED or event == 'Quit':
break
if event == "Finished_with_civilization_layout":
window.close()
window = refresh_open_faction_picker_layout()
if event == "update_file_manager":
new_mod_name = values["mod_name"]
create_new_mod_folder(new_mod_name.strip())
window.Close()
window = refresh_mod_window()
if "delete_mod_name" == re.sub(pattern, '', event):
mod_to_delete = window[event].get_text().replace("Delete ", "")
delete_mod("./Mods/"+mod_to_delete)
window.Close()
window = refresh_mod_window()
if "open_mod_name" == re.sub(pattern, '', event):
current_mod_opened = window[event].get_text().replace("Open ", "")
window.close()
window = refresh_open_faction_picker_layout()
# python -m PyInstaller app.py --noconsole
window.close()