test_menu.py 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. import pygame
  2. import json
  3. import subprocess
  4. import os
  5. import sys
  6. import pygame_gui
  7. from pygame_gui.ui_manager import UIManager
  8. from pygame_gui.elements.ui_text_entry_line import UITextEntryLine
  9. import tkinter as tk
  10. from tkinter import ttk
  11. from datetime import datetime
  12. import hashlib
  13. # 处理过长的成就
  14. def generate_verification_code(timestamp):
  15. """基于时间戳生成一个长度为6的验证字符串"""
  16. hash_object = hashlib.sha256(timestamp.encode())
  17. # 取SHA256哈希值的前6位作为验证字符串
  18. return hash_object.hexdigest()[:6]
  19. def handle_long_achievements():
  20. user_documents_folder = os.path.expanduser("~\\Documents")
  21. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE")
  22. os.makedirs(qqtpve_folder, exist_ok=True)
  23. def process_file(file_path, file_key="STAT"):
  24. try:
  25. with open(file_path, encoding="utf-8") as file:
  26. data = json.load(file)
  27. except FileNotFoundError:
  28. data = {file_key: []}
  29. with open(file_path, 'w', encoding="utf-8") as file:
  30. json.dump(data, file, indent=2)
  31. except Exception as e:
  32. print(f"读取{file_path}错误: {e}")
  33. return
  34. if len(data[file_key]) > 5000:
  35. extracted_data = data[file_key][:]
  36. data[file_key] = []
  37. with open(file_path, 'w', encoding="utf-8") as file:
  38. json.dump(data, file, indent=2)
  39. timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
  40. verification_code = generate_verification_code(timestamp)
  41. base_name = os.path.basename(file_path)
  42. name, ext = os.path.splitext(base_name)
  43. new_name = f"{name}_{timestamp}_{verification_code}{ext}"
  44. new_file_path = os.path.join(os.path.dirname(file_path), new_name)
  45. with open(new_file_path, 'w', encoding="utf-8") as file:
  46. json.dump({file_key: extracted_data}, file, indent=2)
  47. print(f"已保存到{new_file_path}")
  48. # achievements_file_path = os.path.join(qqtpve_folder, "achievements.json")
  49. monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json")
  50. # process_file(achievements_file_path)
  51. process_file(monster_stats_file_path)
  52. # 读取时需要解析文件名,提取时间戳和验证字符串,然后使用generate_verification_code函数来验证这个字符串是否匹配。
  53. try:
  54. handle_long_achievements()
  55. except Exception as e:
  56. print(e)
  57. # 初始化pygame
  58. pygame.init()
  59. # 屏幕大小
  60. SCREEN_WIDTH, SCREEN_HEIGHT = 960, 680
  61. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  62. pygame.display.set_caption("游戏主菜单(游戏作者:永恒,菜单作者:100の雨女),讨论群:756422783,官方wiki网址:qqtwiki.free.nf")
  63. # 颜色定义
  64. PAPER = (255, 235, 205)
  65. WHITE = (255, 255, 255)
  66. BLACK = (0, 0, 0)
  67. LIGHT_GRAY = (168, 168, 168)
  68. BROWN = (127, 70, 44)
  69. DARK_BROWN = (100, 50, 30)
  70. ORANGE_PINK = (127, 82, 93)
  71. LAVENDER_BLUE = (227, 228, 250)
  72. bg_music = "res/music/M09.ogg"
  73. # 播放背景音乐
  74. # pygame.mixer.music.load(bg_music)
  75. # pygame.mixer.music.play(-1)
  76. # 全局变量,用于保存launcher进程对象
  77. launcher_process = None
  78. app_process = None
  79. achievement_process = None
  80. # 在全局定义一个变量来保存鼠标左键是否按下的状态
  81. mouse_left_button_down = False
  82. mouse_left_button_up = True
  83. is_click_setting = False
  84. settings_changed = False
  85. show_map_info = False
  86. show_map_name = None
  87. show_custom_map_name = None
  88. leave_map_info = True
  89. current_page = 1
  90. try:
  91. with open("config.json", encoding="utf-8") as f:
  92. cfg_json = json.load(f)
  93. except:
  94. with open("config.json", encoding="utf-8_sig") as f:
  95. cfg_json = json.load(f)
  96. # 初始化一个空字典来存储合并后的数据
  97. map_name_en = {}
  98. # 遍历指定目录中的所有文件
  99. for filename in os.listdir("game/menu_list/menu_map_set"):
  100. # 检查文件是否是 JSON 文件
  101. if filename.endswith('.json'):
  102. # 构造文件的完整路径
  103. file_path = os.path.join("game/menu_list/menu_map_set", filename)
  104. # 读取 JSON 数据并合并
  105. with open(file_path, 'r', encoding='utf-8') as file:
  106. # 文件名(不包括扩展名)作为键
  107. key = filename[:-5]
  108. tmp_file = json.load(file)
  109. if len(tmp_file) == 0:
  110. continue
  111. if key == '0Official':
  112. for mname in tmp_file[0].keys():
  113. map_name_en[mname] = tmp_file[0][mname]["map_name"]
  114. else:
  115. for thame in tmp_file:
  116. for thame_name in thame.keys():
  117. for mname_dic in thame[thame_name]["selections"]:
  118. map_name_en[mname_dic["map_name"]] = mname_dic["difficulty"]
  119. # 读取地图信息
  120. def read_map_selection():
  121. # 初始化一个空字典来存储合并后的数据
  122. merged_data = {}
  123. # 遍历指定目录中的所有文件
  124. for filename in os.listdir("game/menu_list/menu_map_set"):
  125. # 检查文件是否是 JSON 文件
  126. if filename.endswith('.json'):
  127. # 构造文件的完整路径
  128. file_path = os.path.join("game/menu_list/menu_map_set", filename)
  129. # 读取 JSON 数据并合并
  130. with open(file_path, 'r', encoding='utf-8') as file:
  131. # 文件名(不包括扩展名)作为键
  132. key = filename[:-5]
  133. # 读取文件内容并添加到字典
  134. # print(filename)
  135. # print(json.load(file))
  136. merged_data[key] = json.load(file)
  137. return merged_data
  138. # 初始化一个空字典来存储合并后的数据
  139. app_name = {}
  140. # 遍历指定目录中的所有文件
  141. for filename in os.listdir("game/menu_list/menu_app"):
  142. # 检查文件是否是 JSON 文件
  143. if filename.endswith('.json'):
  144. # 构造文件的完整路径
  145. file_path = os.path.join("game/menu_list/menu_app", filename)
  146. # 读取 JSON 数据并合并
  147. with open(file_path, 'r', encoding='utf-8') as file:
  148. # 文件名(不包括扩展名)作为键
  149. key = filename[:-5]
  150. tmp_file = json.load(file)
  151. app_name[key] = tmp_file[0]
  152. def stars_string(n):
  153. if n <= 0:
  154. raise ValueError("输入必须为正整数")
  155. num_stars = n // 10
  156. num_dots = n % 10
  157. stars_string = "★" * num_stars + "☆" * num_dots
  158. return stars_string
  159. # 绘制主菜单界面
  160. def draw_menu():
  161. screen.fill(PAPER)
  162. # 加载自定义字体文件
  163. font = pygame.font.Font("res/font/simsun.ttc", 24)
  164. # 定义按钮的外观
  165. button_width, button_height = 600, 100
  166. button_margin = 20
  167. # 定义按钮的文本和位置
  168. buttons = [
  169. ("直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),
  170. ("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),
  171. # ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  172. ("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),
  173. ]
  174. # 绘制按钮
  175. for button_text, (x, y) in buttons:
  176. button_rect = pygame.Rect(x, y, button_width, button_height)
  177. if button_rect.collidepoint(pygame.mouse.get_pos()):
  178. pygame.draw.rect(screen, DARK_BROWN, button_rect)
  179. else:
  180. pygame.draw.rect(screen, BROWN, button_rect)
  181. # pygame.draw.rect(screen, BROWN, button_rect)
  182. text = font.render(button_text, True, WHITE)
  183. text_rect = text.get_rect(center=button_rect.center)
  184. screen.blit(text, text_rect)
  185. # 定义按钮的文本和位置
  186. buttons2 = [
  187. ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  188. ("成就记录", (SCREEN_WIDTH // 2 - button_width // 2 + 210, 100 + (button_height + button_margin) * 2)),
  189. ("操作帮助", (SCREEN_WIDTH // 2 - button_width // 2 + 210 * 2, 100 + (button_height + button_margin) * 2))
  190. ]
  191. # 绘制按钮
  192. for button_text, (x, y) in buttons2:
  193. button_rect = pygame.Rect(x, y, 180, 100)
  194. if button_rect.collidepoint(pygame.mouse.get_pos()):
  195. pygame.draw.rect(screen, DARK_BROWN, button_rect)
  196. else:
  197. pygame.draw.rect(screen, BROWN, button_rect)
  198. # pygame.draw.rect(screen, BROWN, button_rect)
  199. text = font.render(button_text, True, WHITE)
  200. text_rect = text.get_rect(center=button_rect.center)
  201. screen.blit(text, text_rect)
  202. # 更新屏幕显示
  203. pygame.display.flip()
  204. # 绘制作者信息界面
  205. def draw_author_info():
  206. screen.fill(PAPER)
  207. # 加载自定义字体文件
  208. font = pygame.font.Font("res/font/simsun.ttc", 24)
  209. # 作者信息文本
  210. author_info_text = "关于作者:\n\n QQTPVE作者: 永恒 B站曾用id: QQTPVE-永恒(已注销) \n\n 联机作者: KY B站id: Zageku" + \
  211. "\n\n 菜单作者与后续单机运营: 100の雨女 B站id同名 \n\n 链接: https://space.bilibili.com/12132334" + \
  212. "\n\n 感谢悠闲人生,疾风等改图作者与根号十三,冰神等老玩家与Null等技术人员的支持" + \
  213. "\n\n 官方探险群:756422783,老群:133753304 \n\n 官方wiki网站: qqtwiki.free.nf"
  214. # 将文本按换行符拆分成多行
  215. lines = author_info_text.split("\n")
  216. # 绘制每一行文本
  217. line_height = 30
  218. y_offset = 120
  219. for line in lines:
  220. text_surface = font.render(line, True, BLACK)
  221. text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2, y_offset))
  222. screen.blit(text_surface, text_rect)
  223. y_offset += line_height
  224. # 绘制返回按钮
  225. return_button_text = "返回主菜单"
  226. return_button_width, return_button_height = 200, 60
  227. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  228. return_button_height)
  229. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  230. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  231. else:
  232. pygame.draw.rect(screen, BROWN, return_button_rect)
  233. # pygame.draw.rect(screen, BROWN, return_button_rect)
  234. return_text_surface = font.render(return_button_text, True, WHITE)
  235. return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
  236. screen.blit(return_text_surface, return_text_rect)
  237. # 更新屏幕显示
  238. pygame.display.flip()
  239. # 绘制操作帮助
  240. def draw_helper_info():
  241. screen.fill(PAPER)
  242. # 加载自定义字体文件
  243. font = pygame.font.Font("res/font/simsun.ttc", 24)
  244. # 作者信息文本
  245. author_info_text = "操作帮助:\n\n 开关怪物姓名牌快捷键:F6(部分机型F6+Fn) \n\n 怪物姓名与血量切换显示快捷键:F7(部分机型F7+Fn)" + \
  246. "\n\n 重新开始本地图快捷键: 0(主键盘数字) \n\n 上下左右移动,空格放置糖泡,数字123使用道具 \n\n 修改特殊键位置请使用其他辅助程序或参阅config修改手册" + \
  247. "\n\n 换衣服换糖泡请参阅永恒大佬B站视频教学 \n\n 此为单机探险不可联机不可进入商城更不可能恢复原账号数据 \n\n 打不过原图就去打新手教程!!能过教程基本能过所有原图(黑龙除外)!!"
  248. # 将文本按换行符拆分成多行
  249. lines = author_info_text.split("\n")
  250. # 绘制每一行文本
  251. line_height = 30
  252. y_offset = 50
  253. for line in lines:
  254. text_surface = font.render(line, True, BLACK)
  255. text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2, y_offset))
  256. screen.blit(text_surface, text_rect)
  257. y_offset += line_height
  258. # 绘制返回按钮
  259. return_button_text = "返回主菜单"
  260. return_button_width, return_button_height = 200, 60
  261. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  262. return_button_height)
  263. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  264. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  265. else:
  266. pygame.draw.rect(screen, BROWN, return_button_rect)
  267. # pygame.draw.rect(screen, BROWN, return_button_rect)
  268. return_text_surface = font.render(return_button_text, True, WHITE)
  269. return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
  270. screen.blit(return_text_surface, return_text_rect)
  271. # 更新屏幕显示
  272. pygame.display.flip()
  273. # 运行游戏launcher
  274. def launch_game():
  275. global launcher_process
  276. print("PVE, Launch!!!")
  277. try:
  278. # 替换为launcher.exe的路径
  279. launcher_path = "launcher.exe"
  280. # 启动launcher.exe并隐藏窗口
  281. launcher_process = subprocess.Popen([launcher_path], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  282. stderr=subprocess.PIPE, creationflags=subprocess.DETACHED_PROCESS)
  283. # 隐藏主菜单窗口
  284. pygame.display.iconify()
  285. # 等待launcher.exe结束
  286. # launcher_process.communicate()
  287. # 当launcher.exe关闭后,关闭主菜单窗口并退出程序
  288. # pygame.display.quit()
  289. # sys.exit()
  290. except FileNotFoundError:
  291. print("找不到launcher.exe,请确保它与Python脚本在同一目录下。")
  292. except Exception as e:
  293. print("运行launcher.exe时出现错误:", e)
  294. finally:
  295. launcher_process = None
  296. # 运行app
  297. def launch_app(app_name):
  298. global app_process
  299. print(app_name + ", Launch!!!")
  300. try:
  301. # 替换为launcher.exe的路径
  302. launcher_path = app_name + ".exe"
  303. # 启动launcher.exe
  304. app_process = subprocess.Popen([launcher_path])
  305. except FileNotFoundError:
  306. print("找不到" + app_name + ".exe,请确保它与Python脚本在同一目录下。")
  307. except Exception as e:
  308. print("运行" + app_name + "时出现错误:", e)
  309. finally:
  310. app_process = None
  311. # 运行成就
  312. def achievement():
  313. global achievement_process
  314. try:
  315. # 替换为launcher.exe的路径
  316. achievement_path = "点亮式成就.exe"
  317. # 启动launcher.exe并隐藏窗口
  318. achievement_process = subprocess.Popen([achievement_path], shell=True, stdin=subprocess.PIPE,
  319. stdout=subprocess.PIPE, stderr=subprocess.PIPE,
  320. creationflags=subprocess.DETACHED_PROCESS)
  321. # 隐藏主菜单窗口
  322. # pygame.display.iconify()
  323. # 等待launcher.exe结束
  324. # achievement_process.communicate()
  325. # 当launcher.exe关闭后,关闭主菜单窗口并退出程序
  326. # pygame.display.quit()
  327. # sys.exit()
  328. except FileNotFoundError:
  329. print("找不到点亮式成就.exe,请确保它与Python脚本在同一目录下。")
  330. except Exception as e:
  331. print("运行点亮式成就.exe时出现错误:", e)
  332. finally:
  333. achievement_process = None
  334. # 地图选择菜单中的按钮
  335. map_buttons = []
  336. map_button_width, map_button_height = 300, 60
  337. map_button_margin = 20
  338. # 处理地图选择按钮的点击事件
  339. def handle_map_selection_click(map):
  340. # 在这里处理地图选择,例如更新config.json中的选定地图
  341. cfg_json["map_set"] = map
  342. # 返回到上一个界面(地图选择菜单)
  343. current_screen = "main_menu"
  344. draw_menu()
  345. # map_selection_loop(map_selection_data, map_info["author"])
  346. # 绘制地图选择菜单
  347. def draw_map_selection_menu():
  348. # 清空屏幕
  349. screen.fill(PAPER)
  350. # 绘制"原图"按钮
  351. original_maps_button_rect = pygame.Rect(250, 150, map_button_width, map_button_height)
  352. if original_maps_button_rect.collidepoint(pygame.mouse.get_pos()):
  353. pygame.draw.rect(screen, DARK_BROWN, original_maps_button_rect)
  354. else:
  355. pygame.draw.rect(screen, BROWN, original_maps_button_rect)
  356. # pygame.draw.rect(screen, BROWN, original_maps_button_rect)
  357. pygame.draw.rect(screen, PAPER, original_maps_button_rect, 3)
  358. font = pygame.font.Font("res/font/simsun.ttc", 24)
  359. text = font.render("官方原图与教程", True, WHITE)
  360. text_rect = text.get_rect(center=original_maps_button_rect.center)
  361. screen.blit(text, text_rect)
  362. # 绘制"其他作者的地图"按钮
  363. other_authors_button_rect = pygame.Rect(250, 150 + map_button_height + map_button_margin, map_button_width,
  364. map_button_height)
  365. if other_authors_button_rect.collidepoint(pygame.mouse.get_pos()):
  366. pygame.draw.rect(screen, DARK_BROWN, other_authors_button_rect)
  367. else:
  368. pygame.draw.rect(screen, BROWN, other_authors_button_rect)
  369. # pygame.draw.rect(screen, BROWN, other_authors_button_rect)
  370. pygame.draw.rect(screen, PAPER, other_authors_button_rect, 3)
  371. text = font.render("改图(玩家自创)", True, WHITE)
  372. text_rect = text.get_rect(center=other_authors_button_rect.center)
  373. screen.blit(text, text_rect)
  374. # 绘制"其他地图生成工具"按钮
  375. other_apps_button_rect = pygame.Rect(250, 150 + 2*map_button_height + 2*map_button_margin, map_button_width,
  376. map_button_height)
  377. if other_apps_button_rect.collidepoint(pygame.mouse.get_pos()):
  378. pygame.draw.rect(screen, DARK_BROWN, other_apps_button_rect)
  379. else:
  380. pygame.draw.rect(screen, BROWN, other_apps_button_rect)
  381. pygame.draw.rect(screen, PAPER, other_apps_button_rect, 3)
  382. text = font.render("其他(地图生成/辅助)", True, WHITE)
  383. text_rect = text.get_rect(center=other_apps_button_rect.center)
  384. screen.blit(text, text_rect)
  385. # 绘制"返回"按钮
  386. return_button_rect = pygame.Rect(250, SCREEN_HEIGHT - 150 - map_button_height, map_button_width, map_button_height)
  387. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  388. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  389. else:
  390. pygame.draw.rect(screen, BROWN, return_button_rect)
  391. # pygame.draw.rect(screen, BROWN, return_button_rect)
  392. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  393. text = font.render("返回主菜单", True, WHITE)
  394. text_rect = text.get_rect(center=return_button_rect.center)
  395. screen.blit(text, text_rect)
  396. # 更新屏幕显示
  397. pygame.display.flip()
  398. random_map_type = ""
  399. def show_official_map_name(map):
  400. if map in list(map_name_en.keys()):
  401. return map_name_en[map]
  402. else:
  403. if map == "randomMapSet":
  404. if random_map_type != "":
  405. return "随机地图("+random_map_type+")"
  406. else: return "随机地图(未知)"
  407. else: return map
  408. # 地图信息显示框
  409. map_info_box_width, map_info_box_height = 300, 100
  410. map_info_box_margin = 10
  411. map_info_box_rect = None
  412. map_info_text = ""
  413. original_map_button_width = 200
  414. # 绘制原图子菜单
  415. def draw_original_maps_submenu():
  416. global map_info_box_rect, map_info_text
  417. # 清空屏幕
  418. screen.fill(PAPER)
  419. # 绘制"返回"按钮
  420. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - map_button_height, original_map_button_width, map_button_height)
  421. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  422. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  423. else:
  424. pygame.draw.rect(screen, BROWN, return_button_rect)
  425. # pygame.draw.rect(screen, BROWN, return_button_rect)
  426. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  427. font = pygame.font.Font("res/font/simsun.ttc", 24)
  428. text = font.render("返回", True, WHITE)
  429. text_rect = text.get_rect(center=return_button_rect.center)
  430. screen.blit(text, text_rect)
  431. # 绘制所有原图按钮
  432. x, y = 200, 50
  433. # for map_info in map_selection_data[author]:
  434. # print(list(map_selection_data["Official"][0].keys()))
  435. for k, map_info in enumerate(list(map_selection_data["0Official"][0].keys())):
  436. # print(map_info)
  437. map_button_rect = pygame.Rect(x, y, original_map_button_width, map_button_height)
  438. if map_button_rect.collidepoint(pygame.mouse.get_pos()):
  439. pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
  440. else:
  441. pygame.draw.rect(screen, BROWN, map_button_rect)
  442. # pygame.draw.rect(screen, BROWN, map_button_rect)
  443. pygame.draw.rect(screen, PAPER, map_button_rect, 3)
  444. font = pygame.font.Font("res/font/simsun.ttc", 24)
  445. # text = font.render(map_info[list(map_info.keys())[0]]["map_name"], True, WHITE)
  446. text = font.render(show_official_map_name(map_info), True, WHITE)
  447. text_rect = text.get_rect(center=map_button_rect.center)
  448. screen.blit(text, text_rect)
  449. # 添加地图按钮到列表中以备后续处理事件
  450. map_buttons.append((map_button_rect, map_info))
  451. if y + map_button_height + map_button_margin <= SCREEN_HEIGHT - 3 * map_button_height:
  452. y += map_button_height + map_button_margin
  453. else:
  454. x += original_map_button_width + map_button_margin
  455. y = 50
  456. map_info_box_width, map_info_box_height = 600, 120
  457. map_info_box_rect = pygame.Rect((SCREEN_WIDTH - map_info_box_width) // 2 + 100, SCREEN_HEIGHT - 150, map_info_box_width, map_info_box_height)
  458. pygame.draw.rect(screen, ORANGE_PINK, map_info_box_rect)
  459. pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
  460. if show_map_info and show_map_name is not None:
  461. font = pygame.font.Font("res/font/simsun.ttc", 24)
  462. lines = show_map_name.split("\n")
  463. for i, line in enumerate(lines):
  464. text_surface = font.render(line, True, WHITE)
  465. text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2 + 100, SCREEN_HEIGHT - 120 + i * 20))
  466. screen.blit(text_surface, text_rect)
  467. # pygame.display.flip()
  468. # 更新屏幕显示
  469. pygame.display.flip()
  470. def show_author_name(author):
  471. if author == 'AmeOnna': return '100の雨女'
  472. elif author == '0YouXian0': return '0悠闲人生0'
  473. elif author == 'MingGui': return '冥の归'
  474. elif author == 'JiFeng': return '疾风'
  475. elif author == 'CanBing': return '残冰'
  476. elif author == 'Null': return '闹神'
  477. elif author == 'YongHeng': return '永恒'
  478. elif author == 'PBGuangYing': return '光影'
  479. elif author == 'TaXue': return '踏雪无痕'
  480. elif author == 'XiaoLieQuan': return '小猎犬'
  481. elif author == 'u7iui': return 'u7iui'
  482. elif author == 'z_Unknown': return '敬请期待更多'
  483. else: return author
  484. # 改图子菜单的按钮宽高和间距
  485. custom_map_button_width, custom_map_button_height = 200, 60
  486. custom_map_button_margin = 10
  487. def draw_custom_maps_submenu():
  488. global map_info_box_rect, map_info_text
  489. # 清空屏幕
  490. screen.fill(PAPER)
  491. # 绘制"返回"按钮
  492. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - custom_map_button_height, custom_map_button_width, custom_map_button_height)
  493. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  494. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  495. else:
  496. pygame.draw.rect(screen, BROWN, return_button_rect)
  497. # pygame.draw.rect(screen, BROWN, return_button_rect)
  498. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  499. font = pygame.font.Font("res/font/simsun.ttc", 24)
  500. text = font.render("返回", True, WHITE)
  501. text_rect = text.get_rect(center=return_button_rect.center)
  502. screen.blit(text, text_rect)
  503. # 获取所有改图作者的名字
  504. caremove = list(map_selection_data.keys())
  505. caremove.remove('0Official')
  506. custom_authors = caremove
  507. # 计算可以显示的改图作者的数量
  508. max_custom_authors = (SCREEN_HEIGHT - 2 * custom_map_button_height) // (custom_map_button_height + custom_map_button_margin)
  509. # 计算总页数
  510. total_pages = (len(custom_authors) + max_custom_authors - 1) // max_custom_authors
  511. # 绘制改图作者按钮
  512. x, y = SCREEN_WIDTH // 2 - custom_map_button_width // 2, 50
  513. custom_map_buttons = [] # 存储改图作者按钮的位置和对应作者名
  514. # print(custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))])
  515. # print(current_page)
  516. # print((current_page - 1) * max_custom_authors , min(len(custom_authors),(current_page * max_custom_authors)))
  517. for author in custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]:
  518. author_button_rect = pygame.Rect(x, y, custom_map_button_width, custom_map_button_height)
  519. if author_button_rect.collidepoint(pygame.mouse.get_pos()):
  520. pygame.draw.rect(screen, DARK_BROWN, author_button_rect)
  521. else:
  522. pygame.draw.rect(screen, BROWN, author_button_rect)
  523. # pygame.draw.rect(screen, BROWN, author_button_rect)
  524. pygame.draw.rect(screen, PAPER, author_button_rect, 3)
  525. font = pygame.font.Font("res/font/simsun.ttc", 18)
  526. text = font.render(show_author_name(author)+'改图', True, WHITE)
  527. text_rect = text.get_rect(center=author_button_rect.center)
  528. screen.blit(text, text_rect)
  529. custom_map_buttons.append((author_button_rect, author))
  530. y += custom_map_button_height + custom_map_button_margin
  531. # 绘制滚动条或下一页按钮
  532. if total_pages > 1:
  533. scroll_button_width, scroll_button_height = 80, 120
  534. scroll_button_margin = 10
  535. next_button_rect = pygame.Rect(SCREEN_WIDTH - scroll_button_width - scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  536. prev_button_rect = pygame.Rect(scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  537. if next_button_rect.collidepoint(pygame.mouse.get_pos()):
  538. pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
  539. else:
  540. pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
  541. if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
  542. pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
  543. else:
  544. pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
  545. # pygame.draw.rect(screen, BROWN, next_button_rect)
  546. # pygame.draw.rect(screen, BROWN, prev_button_rect)
  547. pygame.draw.polygon(screen, WHITE, [(next_button_rect.centerx, next_button_rect.centery - 10), (next_button_rect.centerx, next_button_rect.centery + 10), (next_button_rect.centerx + 10, next_button_rect.centery)])
  548. pygame.draw.polygon(screen, WHITE, [(prev_button_rect.centerx, prev_button_rect.centery - 10), (prev_button_rect.centerx, prev_button_rect.centery + 10), (prev_button_rect.centerx - 10, prev_button_rect.centery)])
  549. pygame.display.flip()
  550. return custom_map_buttons, total_pages, next_button_rect, prev_button_rect
  551. # 更新屏幕显示
  552. pygame.display.flip()
  553. return custom_map_buttons, total_pages, None, None
  554. # 选大关界面
  555. def draw_custom_maps(author):
  556. global map_info_box_rect, map_info_text, custom_map_buttons
  557. # 清空屏幕
  558. screen.fill(PAPER)
  559. # 绘制"返回"按钮
  560. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - custom_map_button_height, custom_map_button_width, custom_map_button_height)
  561. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  562. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  563. else:
  564. pygame.draw.rect(screen, BROWN, return_button_rect)
  565. # pygame.draw.rect(screen, BROWN, return_button_rect)
  566. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  567. font = pygame.font.Font("res/font/simsun.ttc", 24)
  568. text = font.render("返回作者菜单", True, WHITE)
  569. text_rect = text.get_rect(center=return_button_rect.center)
  570. screen.blit(text, text_rect)
  571. # 获取所有改图的名字
  572. custom_maps = [list(item.keys())[0] for item in map_selection_data[author]]
  573. # 计算可以显示的改图的数量
  574. max_custom_maps = (SCREEN_HEIGHT - 2 * custom_map_button_height) // (custom_map_button_height + custom_map_button_margin) - 1
  575. # 计算总页数
  576. total_pages = (len(custom_maps) + max_custom_maps - 1) // max_custom_maps
  577. # print(custom_maps, max_custom_maps, total_pages)
  578. # 绘制改图作者按钮
  579. x, y = SCREEN_WIDTH // 4 - custom_map_button_width // 2, 50
  580. custom_map_buttons = [] # 存储改图作者按钮的位置和对应作者名
  581. for map in custom_maps[(current_page - 1) * max_custom_maps : min(len(custom_maps),(current_page * max_custom_maps))]:
  582. map_button_rect = pygame.Rect(x, y, custom_map_button_width, custom_map_button_height)
  583. if map_button_rect.collidepoint(pygame.mouse.get_pos()):
  584. pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
  585. else:
  586. pygame.draw.rect(screen, BROWN, map_button_rect)
  587. pygame.draw.rect(screen, PAPER, map_button_rect, 3)
  588. font = pygame.font.Font("res/font/simsun.ttc", 18)
  589. text = font.render(next(item[map]['full_name'] for item in map_selection_data[author] if map in item), True, WHITE)
  590. text_rect = text.get_rect(center=map_button_rect.center)
  591. screen.blit(text, text_rect)
  592. custom_map_buttons.append((map_button_rect, map))
  593. y += custom_map_button_height + custom_map_button_margin
  594. map_info_box_width, map_info_box_height = 450, 620
  595. map_info_box_rect = pygame.Rect((SCREEN_WIDTH - map_info_box_width) // 2 + 215, 30, map_info_box_width, map_info_box_height)
  596. pygame.draw.rect(screen, ORANGE_PINK, map_info_box_rect)
  597. pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
  598. if show_map_info and show_map_name is not None:
  599. font = pygame.font.Font("res/font/simsun.ttc", 18)
  600. lines = show_map_name.split("\n")
  601. for i, line in enumerate(lines):
  602. text_surface = font.render(line, True, WHITE)
  603. text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2 + 220, 80 + i * 15))
  604. screen.blit(text_surface, text_rect)
  605. # 绘制滚动条或下一页按钮
  606. if total_pages > 1:
  607. scroll_button_width, scroll_button_height = 80, 120
  608. scroll_button_margin = 10
  609. next_button_rect = pygame.Rect(360, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  610. prev_button_rect = pygame.Rect(40, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  611. if next_button_rect.collidepoint(pygame.mouse.get_pos()):
  612. pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
  613. else:
  614. pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
  615. if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
  616. pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
  617. else:
  618. pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
  619. pygame.draw.polygon(screen, WHITE, [(next_button_rect.centerx, next_button_rect.centery - 10), (next_button_rect.centerx, next_button_rect.centery + 10), (next_button_rect.centerx + 10, next_button_rect.centery)])
  620. pygame.draw.polygon(screen, WHITE, [(prev_button_rect.centerx, prev_button_rect.centery - 10), (prev_button_rect.centerx, prev_button_rect.centery + 10), (prev_button_rect.centerx - 10, prev_button_rect.centery)])
  621. pygame.display.flip()
  622. return custom_map_buttons, total_pages, next_button_rect, prev_button_rect
  623. # 更新屏幕显示
  624. pygame.display.flip()
  625. return custom_map_buttons, total_pages, None, None
  626. difficulty_button_width, difficulty_button_height = 280, 70
  627. difficulty_button_margin = 10
  628. def draw_custom_difficulty(author, map):
  629. global map_info_box_rect, map_info_text, difficulty_buttons
  630. # 清空屏幕
  631. screen.fill(PAPER)
  632. # 绘制"返回"按钮
  633. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - difficulty_button_height, difficulty_button_width, difficulty_button_height)
  634. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  635. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  636. else:
  637. pygame.draw.rect(screen, BROWN, return_button_rect)
  638. # pygame.draw.rect(screen, BROWN, return_button_rect)
  639. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  640. font = pygame.font.Font("res/font/simsun.ttc", 24)
  641. text = font.render("返回"+show_author_name(author)+"改图", True, WHITE)
  642. text_rect = text.get_rect(center=return_button_rect.center)
  643. screen.blit(text, text_rect)
  644. # 获取所有难度
  645. difficulty = next(item[map]['selections'] for item in map_selection_data[author] if map in item)
  646. # 计算可以显示的难度数量
  647. max_difficulty = (SCREEN_HEIGHT - 2 * difficulty_button_height) // (difficulty_button_height + difficulty_button_margin)
  648. # 计算总页数
  649. total_pages = (len(difficulty) + max_difficulty - 1) // max_difficulty
  650. # 绘制改图作者按钮
  651. x, y = SCREEN_WIDTH // 2 - difficulty_button_width // 2, 50
  652. difficulty_buttons = [] # 存储改图作者按钮的位置和对应作者名
  653. for diff in difficulty[(current_page - 1) * max_difficulty : min(len(difficulty),(current_page * max_difficulty))]:
  654. map_button_rect = pygame.Rect(x, y, difficulty_button_width, difficulty_button_height)
  655. if map_button_rect.collidepoint(pygame.mouse.get_pos()):
  656. pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
  657. else:
  658. pygame.draw.rect(screen, BROWN, map_button_rect)
  659. pygame.draw.rect(screen, PAPER, map_button_rect, 3)
  660. font = pygame.font.Font("res/font/simsun.ttc", 18)
  661. text = font.render(diff['difficulty'], True, WHITE)
  662. text_rect = text.get_rect(center=map_button_rect.center)
  663. screen.blit(text, text_rect)
  664. difficulty_buttons.append((map_button_rect, diff))
  665. y += difficulty_button_height + difficulty_button_margin
  666. # 绘制滚动条或下一页按钮
  667. if total_pages > 1:
  668. scroll_button_width, scroll_button_height = 80, 120
  669. scroll_button_margin = 10
  670. next_button_rect = pygame.Rect(SCREEN_WIDTH - scroll_button_width - scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  671. prev_button_rect = pygame.Rect(scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  672. if next_button_rect.collidepoint(pygame.mouse.get_pos()):
  673. pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
  674. else:
  675. pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
  676. if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
  677. pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
  678. else:
  679. pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
  680. pygame.draw.polygon(screen, WHITE, [(next_button_rect.centerx, next_button_rect.centery - 10), (next_button_rect.centerx, next_button_rect.centery + 10), (next_button_rect.centerx + 10, next_button_rect.centery)])
  681. pygame.draw.polygon(screen, WHITE, [(prev_button_rect.centerx, prev_button_rect.centery - 10), (prev_button_rect.centerx, prev_button_rect.centery + 10), (prev_button_rect.centerx - 10, prev_button_rect.centery)])
  682. pygame.display.flip()
  683. return difficulty_buttons, total_pages, next_button_rect, prev_button_rect
  684. # 更新屏幕显示
  685. pygame.display.flip()
  686. return difficulty_buttons, total_pages, None, None
  687. def draw_custom_apps():
  688. global map_info_box_rect, map_info_text, app_buttons
  689. # 清空屏幕
  690. screen.fill(PAPER)
  691. # 绘制"返回"按钮
  692. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - difficulty_button_height, 200, difficulty_button_height)
  693. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  694. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  695. else:
  696. pygame.draw.rect(screen, BROWN, return_button_rect)
  697. # pygame.draw.rect(screen, BROWN, return_button_rect)
  698. pygame.draw.rect(screen, PAPER, return_button_rect, 3)
  699. font = pygame.font.Font("res/font/simsun.ttc", 24)
  700. text = font.render("返回", True, WHITE)
  701. text_rect = text.get_rect(center=return_button_rect.center)
  702. screen.blit(text, text_rect)
  703. # 获取所有难度
  704. difficulty = list(app_name.keys())
  705. # 计算可以显示的难度数量
  706. max_difficulty = (SCREEN_HEIGHT - 2 * difficulty_button_height) // (difficulty_button_height + difficulty_button_margin)
  707. # 计算总页数
  708. total_pages = (len(difficulty) + max_difficulty - 1) // max_difficulty
  709. # 绘制按钮
  710. x, y = SCREEN_WIDTH // 2 - difficulty_button_width // 2, 50
  711. app_buttons = [] # 存储改图作者按钮的位置和对应作者名
  712. for diff in difficulty[(current_page - 1) * max_difficulty : min(len(difficulty),(current_page * max_difficulty))]:
  713. map_button_rect = pygame.Rect(x, y, difficulty_button_width, difficulty_button_height)
  714. if map_button_rect.collidepoint(pygame.mouse.get_pos()):
  715. pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
  716. else:
  717. pygame.draw.rect(screen, BROWN, map_button_rect)
  718. pygame.draw.rect(screen, PAPER, map_button_rect, 3)
  719. font = pygame.font.Font("res/font/simsun.ttc", 18)
  720. text = font.render(app_name[diff], True, WHITE)
  721. text_rect = text.get_rect(center=map_button_rect.center)
  722. screen.blit(text, text_rect)
  723. app_buttons.append((map_button_rect, diff))
  724. y += difficulty_button_height + difficulty_button_margin
  725. # 绘制滚动条或下一页按钮
  726. if total_pages > 1:
  727. scroll_button_width, scroll_button_height = 80, 120
  728. scroll_button_margin = 10
  729. next_button_rect = pygame.Rect(SCREEN_WIDTH - scroll_button_width - scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  730. prev_button_rect = pygame.Rect(scroll_button_margin*20, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
  731. if next_button_rect.collidepoint(pygame.mouse.get_pos()):
  732. pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
  733. else:
  734. pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
  735. if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
  736. pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
  737. else:
  738. pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
  739. pygame.draw.polygon(screen, WHITE, [(next_button_rect.centerx, next_button_rect.centery - 10), (next_button_rect.centerx, next_button_rect.centery + 10), (next_button_rect.centerx + 10, next_button_rect.centery)])
  740. pygame.draw.polygon(screen, WHITE, [(prev_button_rect.centerx, prev_button_rect.centery - 10), (prev_button_rect.centerx, prev_button_rect.centery + 10), (prev_button_rect.centerx - 10, prev_button_rect.centery)])
  741. pygame.display.flip()
  742. return app_buttons, total_pages, next_button_rect, prev_button_rect
  743. # 更新屏幕显示
  744. pygame.display.flip()
  745. return app_buttons, total_pages, None, None
  746. def get_map_info_text(map_info):
  747. # 从map_info字典中提取地图信息
  748. # 这里假设map_info字典中包含地图信息的字段
  749. return "难度:" + stars_string(map_selection_data["0Official"][0][map_info]["difficulty"]) + "\n\n" + map_selection_data["0Official"][0][map_info]["info"]
  750. def get_custom_map_info_text(author, map):
  751. # 从map_info字典中提取地图信息
  752. # 这里假设map_info字典中包含地图信息的字段
  753. for i, m in enumerate(map_selection_data[author]):
  754. if map == next(iter(m.keys())):
  755. return map_selection_data[author][i][map]['info']
  756. # 新增变量用于保存信息框矩形
  757. map_info_box_rect = None
  758. custom_map_info_box_rect = None
  759. # 绘制信息文本框的函数
  760. def draw_map_info_box():
  761. global map_info_box_rect
  762. if map_info_box_rect is not None:
  763. # 绘制带颜色的矩形背景
  764. pygame.draw.rect(screen, BROWN, map_info_box_rect)
  765. pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
  766. # 绘制信息文本
  767. font = pygame.font.Font("res/font/simsun.ttc", 18)
  768. lines = map_info_text.split("\n")
  769. for i, line in enumerate(lines):
  770. text = font.render(line, True, WHITE)
  771. text_rect = text.get_rect(x=map_info_box_rect.x + 10, y=map_info_box_rect.y + 10 + i * 20)
  772. screen.blit(text, text_rect)
  773. # 在绘制函数之外添加一个字典用于保存勾选框的状态
  774. checkbox_states = {
  775. "full_screen": cfg_json["full_screen"],
  776. "low_config_mode": cfg_json["low_config_mode"],
  777. "display_stat": cfg_json["display_stat"],
  778. "monster_records": cfg_json["monster_records"],
  779. "v_sync": cfg_json["v_sync"],
  780. "show_time": cfg_json["show_time"],
  781. "drop_item": cfg_json["drop_item"]
  782. }
  783. # 增加一个变量来表示下拉菜单是否处于显示状态
  784. dropdown_menu_active = False
  785. drop_hero_choices = False
  786. drop_colour_choices = False
  787. music_slider_x = 0
  788. sound_slider_x = 0
  789. music_dragging = False
  790. sound_dragging = False
  791. music_slider_rect = pygame.Rect(0, 0, 0, 0)
  792. sound_slider_rect = pygame.Rect(0, 0, 0, 0)
  793. def show_hero_name(hero):
  794. if hero == "Maomao": return "毛毛"
  795. if hero == "Asha": return "阿莎"
  796. if hero == "Monkey": return "小悟空"
  797. if hero == "Titan": return "泰坦"
  798. if hero == "Fox": return "小倩"
  799. if hero == "FoxPlus": return "小倩(很多道具)"
  800. if hero == "Maria": return "玛丽亚"
  801. if hero == "CaiBaozi": return "菜包子(幻制)"
  802. if hero == "Xiami": return "小虾米(悠制)"
  803. if hero == "Chunli": return "春丽(悠制)"
  804. if hero == "Boboli": return "波波丽(悠制)"
  805. if hero == "XingZai": return "星仔(悠制)"
  806. if hero == "SeaPrince": return "海王子(光影制)"
  807. if hero == "SeaPrince_old": return "海王子(旧)(悠制)"
  808. if hero == "Naruto": return "火影(光影制)"
  809. if hero == "Naruto_old": return "火影(旧)(悠制)"
  810. if hero == "Cola": return "可乐(悠制)"
  811. if hero == "Nezha": return "哪吒(悠制)"
  812. if hero == "Chris": return "克莉丝(悠制)"
  813. if hero == "mxfc": return "梦小繁(残冰制)"
  814. if hero == "Flandre": return "芙兰朵露(雨制)"
  815. if hero == "Remilia": return "蕾米莉亚(雨制)"
  816. if hero == "Red": return "红色"
  817. if hero == "Blue": return "蓝色"
  818. if hero == "Yellow": return "黄色"
  819. if hero == "Green": return "绿色"
  820. if hero == "Pink": return "粉色"
  821. if hero == "Orange": return "橙色"
  822. if hero == "Purple": return "紫色"
  823. if hero == "Black": return "黑色"
  824. if hero == "SkyBlue": return "蓝灰色"
  825. if hero == "SakuraPink": return "香芋紫"
  826. if hero == "ForestGreen": return "森绿色"
  827. if hero == "GrassGreen": return "若草色"
  828. if hero == "Withered":
  829. return "枯叶色"
  830. else:
  831. return hero
  832. def draw_slider(setting_value, slider_x, setting_y):
  833. slider_width = 150
  834. slider_height = 10
  835. slider_rect = pygame.Rect(slider_x, setting_y, slider_width, slider_height)
  836. # Draw the slider track
  837. pygame.draw.rect(screen, LIGHT_GRAY, slider_rect, border_radius=5)
  838. # Calculate the position of the slider button based on the setting value
  839. slider_button_width = 15
  840. slider_button_x = slider_x + int((slider_width - slider_button_width) * setting_value)
  841. slider_button_rect = pygame.Rect(slider_button_x, setting_y - 5, slider_button_width, slider_height + 10)
  842. # Draw the slider button
  843. pygame.draw.rect(screen, BLACK, slider_button_rect, border_radius=5)
  844. return slider_button_rect
  845. # 设置界面代码
  846. def draw_game_settings():
  847. global cfg_json, is_click_setting, settings_changed, dropdown_menu_active, drop_hero_choices, drop_colour_choices, music_slider_x, sound_slider_x, music_dragging, sound_dragging, music_slider_rect, sound_slider_rect
  848. screen.fill(PAPER)
  849. # 加载自定义字体文件
  850. font = pygame.font.Font("res/font/simsun.ttc", 24)
  851. # 标题
  852. title_text = "游戏设置"
  853. title_surface = font.render(title_text, True, BLACK)
  854. title_rect = title_surface.get_rect(center=(SCREEN_WIDTH // 2, 50))
  855. screen.blit(title_surface, title_rect)
  856. # 绘制返回按钮
  857. return_button_text = "返回主菜单"
  858. return_button_width, return_button_height = 160, 50
  859. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  860. return_button_height)
  861. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  862. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  863. else:
  864. pygame.draw.rect(screen, BROWN, return_button_rect)
  865. # pygame.draw.rect(screen, BROWN, return_button_rect)
  866. return_text_surface = font.render(return_button_text, True, WHITE)
  867. return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
  868. screen.blit(return_text_surface, return_text_rect)
  869. # 绘制保存设置按钮
  870. save_button_text = "保存设置"
  871. save_button_width, save_button_height = 150, 50
  872. save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width, SCREEN_HEIGHT - 50 - save_button_height,
  873. save_button_width, save_button_height)
  874. if save_button_rect.collidepoint(pygame.mouse.get_pos()):
  875. pygame.draw.rect(screen, DARK_BROWN, save_button_rect)
  876. else:
  877. pygame.draw.rect(screen, BROWN, save_button_rect)
  878. # pygame.draw.rect(screen, BROWN, save_button_rect)
  879. save_text_surface = font.render(save_button_text, True, WHITE)
  880. save_text_rect = save_text_surface.get_rect(center=save_button_rect.center)
  881. screen.blit(save_text_surface, save_text_rect)
  882. # 绘制设置项
  883. setting_margin = 50
  884. setting_y = 120
  885. setting_height = 30
  886. # 设置项的名称和取值范围
  887. settings = [
  888. {"name": "your_hero", "label": "角色:",
  889. "choices": [
  890. "Maomao", "Asha", "Monkey", "Titan", "Fox", "FoxPlus", "Maria", "CaiBaozi", "Xiami", "Chunli", "Boboli",
  891. "XingZai", "SeaPrince_old", "Naruto_old", "Cola", "SeaPrince", "Naruto", "Nezha", "Chris",
  892. "mxfc", "Flandre", "Remilia"
  893. ]},
  894. {"name": "your_character_color", "label": "角色颜色:",
  895. "choices": [
  896. "Red", "Blue", "Yellow", "Green", "Pink", "Orange", "Purple", "Black", "SkyBlue", "SakuraPink",
  897. "ForestGreen", "GrassGreen", "Withered"
  898. ]},
  899. {"name": "music_volume", "label": "音乐音量:", "min_value": 0, "max_value": 1},
  900. {"name": "sound_volume", "label": "音效音量:", "min_value": 0, "max_value": 1},
  901. {"name": "full_screen", "label": "全屏模式(有颜色表示ON/空白表示OFF):", "type": "checkbox"},
  902. {"name": "low_config_mode", "label": "低配模式(推荐打开):", "type": "checkbox"},
  903. {"name": "display_stat", "label": "显示数据(推荐打开):", "type": "checkbox"},
  904. {"name": "monster_records", "label": "怪物统计(只有玩家死亡和通关时会保存记录):", "type": "checkbox"},
  905. {"name": "v_sync", "label": "垂直同步(除低配机外推荐打开):", "type": "checkbox"},
  906. {"name": "show_time", "label": "显示时间特效(电脑不卡就开):", "type": "checkbox"},
  907. {"name": "drop_item", "label": "炸砖掉道具(电脑不卡可选择开):", "type": "checkbox"}
  908. ]
  909. # 绘制每个设置项
  910. for setting in settings:
  911. setting_name = setting["name"]
  912. setting_label = setting["label"]
  913. setting_value = cfg_json[setting_name]
  914. # 绘制标签
  915. label_surface = font.render(setting_label, True, BLACK)
  916. label_rect = label_surface.get_rect(topleft=(setting_margin, setting_y))
  917. screen.blit(label_surface, label_rect)
  918. # 绘制输入框或下拉列表或勾选框
  919. if setting["name"] == "music_volume":
  920. music_slider_x = SCREEN_WIDTH - setting_margin - 150
  921. music_slider_rect = draw_slider(setting_value, music_slider_x, setting_y)
  922. if setting["name"] == "sound_volume":
  923. sound_slider_x = SCREEN_WIDTH - setting_margin - 150
  924. sound_slider_rect = draw_slider(setting_value, sound_slider_x, setting_y)
  925. if "choices" in setting:
  926. choices = setting["choices"]
  927. dropdown_width = 150
  928. dropdown_height = 30
  929. dropdown_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - dropdown_width, setting_y, dropdown_width,
  930. dropdown_height)
  931. pygame.draw.rect(screen, PAPER, dropdown_rect, border_radius=5)
  932. pygame.draw.rect(screen, BLACK, dropdown_rect, 2)
  933. # 绘制当前值
  934. value_surface = font.render(show_hero_name(setting_value), True, BLACK)
  935. value_rect = value_surface.get_rect(center=dropdown_rect.center)
  936. screen.blit(value_surface, value_rect)
  937. # 绘制下拉箭头
  938. arrow_surface = font.render("▼", True, BLACK)
  939. arrow_rect = arrow_surface.get_rect(midright=(dropdown_rect.right - 5, dropdown_rect.centery))
  940. screen.blit(arrow_surface, arrow_rect)
  941. # 处理下拉按钮点击事件
  942. if dropdown_rect.collidepoint(pygame.mouse.get_pos()):
  943. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  944. # dropdown_menu_active = not dropdown_menu_active
  945. if setting["name"] == "your_hero":
  946. if drop_colour_choices:
  947. dropdown_menu_active = True
  948. drop_colour_choices = False
  949. else:
  950. dropdown_menu_active = not dropdown_menu_active
  951. drop_hero_choices = not drop_hero_choices
  952. if setting["name"] == "your_character_color":
  953. if drop_hero_choices:
  954. dropdown_menu_active = True
  955. drop_hero_choices = False
  956. else:
  957. dropdown_menu_active = not dropdown_menu_active
  958. drop_colour_choices = not drop_colour_choices
  959. is_click_setting = True
  960. elif setting.get("type") == "checkbox":
  961. checkbox_size = 25
  962. checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
  963. checkbox_size)
  964. pygame.draw.rect(screen, WHITE, checkbox_rect, border_radius=5)
  965. pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
  966. # 修改勾选状态的绘制
  967. if checkbox_states[setting_name]:
  968. checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
  969. checkbox_size)
  970. pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
  971. # 绘制实心正方形,使其与勾选框大小相同且在其中居中
  972. pygame.draw.rect(screen, BROWN, checkbox_rect) # 绘制实心正方形
  973. # 处理勾选框的点击事件
  974. if checkbox_rect.collidepoint(pygame.mouse.get_pos()):
  975. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  976. settings_changed = True
  977. is_click_setting = True
  978. checkbox_states[setting_name] = not checkbox_states[setting_name]
  979. cfg_json[setting_name] = not cfg_json[setting_name]
  980. setting_y += setting_height + 10
  981. # 在绘制下拉选项的循环之外定义一个变量来追踪选中的选项
  982. selected_choice = None
  983. # 绘制下拉选项(只有在下拉菜单处于显示状态时才进行绘制)
  984. if dropdown_menu_active:
  985. for setting in settings:
  986. if "choices" in setting:
  987. if (setting["name"] == "your_hero" and drop_hero_choices) or (setting["name"] == "your_character_color" and drop_colour_choices):
  988. choices = setting["choices"]
  989. dropdown_width = 180
  990. dropdown_height = 30
  991. num_per_col = 10
  992. dropdown_menu_height = len(choices) * dropdown_height + 10
  993. if setting["name"] == "your_hero":
  994. setting_y = 110
  995. if setting["name"] == "your_character_color":
  996. setting_y = 150
  997. dropdown_menu_y = setting_y + dropdown_height
  998. for i in range(len(choices)):
  999. choice_rect = pygame.Rect(
  1000. SCREEN_WIDTH - setting_margin - (2 + i//num_per_col) * dropdown_width - 2 * (i//num_per_col) + 20,
  1001. dropdown_menu_y + (i % num_per_col - 1) * dropdown_height + 10,
  1002. dropdown_width,
  1003. dropdown_height
  1004. )
  1005. # Change the color of the option when the mouse hovers over it
  1006. if choice_rect.collidepoint(pygame.mouse.get_pos()):
  1007. pygame.draw.rect(screen, LIGHT_GRAY, choice_rect, border_radius=5)
  1008. else:
  1009. pygame.draw.rect(screen, LAVENDER_BLUE, choice_rect, border_radius=5)
  1010. pygame.draw.rect(screen, BLACK, choice_rect, 2)
  1011. # 绘制选项文本
  1012. choice_text = font.render(show_hero_name(choices[i]), True, BLACK)
  1013. choice_text_rect = choice_text.get_rect(center=choice_rect.center)
  1014. screen.blit(choice_text, choice_text_rect)
  1015. # 处理选项列表的点击事件
  1016. if choice_rect.collidepoint(pygame.mouse.get_pos()):
  1017. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  1018. # 更新选中的选项
  1019. selected_choice = choices[i]
  1020. is_click_setting = True
  1021. break
  1022. if selected_choice is not None:
  1023. cfg_json[setting["name"]] = selected_choice
  1024. dropdown_menu_active = False
  1025. drop_hero_choices = False
  1026. drop_colour_choices = False
  1027. settings_changed = True
  1028. break
  1029. # 更新屏幕显示
  1030. pygame.display.flip()
  1031. # 主菜单循环
  1032. def main_menu_loop():
  1033. global buttons, current_screen, mouse_left_button_down, mouse_left_button_up, is_click_setting, settings_changed, cfg_json, music_slider_x, sound_slider_x, music_dragging, sound_dragging, music_slider_rect, sound_slider_rect, achievement_process, \
  1034. show_map_info, show_map_name, leave_map_info, custom_map_buttons, current_page, difficulty_buttons, app_buttons, random_map_type, app_process, launcher_process
  1035. current_screen = "main_menu"
  1036. running = True
  1037. while running:
  1038. for event in pygame.event.get():
  1039. if event.type == pygame.QUIT:
  1040. running = False
  1041. elif event.type == pygame.KEYDOWN:
  1042. if event.key == pygame.K_ESCAPE:
  1043. running = False
  1044. if event.type == pygame.MOUSEMOTION and mouse_left_button_down and not mouse_left_button_up and current_screen == "game_settings":
  1045. setting_margin = 50
  1046. if music_dragging:
  1047. # Update the music volume setting based on the slider position
  1048. # print(event.pos[0], SCREEN_WIDTH - setting_margin - 150)
  1049. music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1050. SCREEN_WIDTH - setting_margin - 150) / 15) * 15
  1051. setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1052. SCREEN_WIDTH - setting_margin - 150) - (
  1053. SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
  1054. cfg_json["music_volume"] = max(0.0, min(1.0, setting_value))
  1055. settings_changed = True
  1056. # print("music=",setting_value)
  1057. if sound_dragging:
  1058. # Update the sound volume setting based on the slider position
  1059. music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1060. SCREEN_WIDTH - setting_margin - 150) / 15) * 15
  1061. setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1062. SCREEN_WIDTH - setting_margin - 150) - (
  1063. SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
  1064. cfg_json["sound_volume"] = max(0.0, min(1.0, setting_value))
  1065. settings_changed = True
  1066. # print("sound=",setting_value)
  1067. if event.type == pygame.MOUSEMOTION and current_screen == "original_maps_submenu":
  1068. for button_rect, map_info in map_buttons:
  1069. if button_rect.collidepoint(event.pos):
  1070. map_info_text = get_map_info_text(map_info) # 获取信息文本
  1071. # print("collode button", map_info, map_info_text)
  1072. if leave_map_info:
  1073. show_map_info = True
  1074. leave_map_info = False
  1075. show_map_name = map_info_text
  1076. # 如果鼠标不在按钮上方,则隐藏信息框
  1077. if not any(button_rect.collidepoint(event.pos) for button_rect, _ in map_buttons):
  1078. if show_map_info:
  1079. # print("hide")
  1080. map_info_box_rect = None
  1081. map_info_text = ""
  1082. show_map_info = False
  1083. show_map_name = None
  1084. leave_map_info = True
  1085. if event.type == pygame.MOUSEMOTION and current_screen == "custom_maps":
  1086. for button_rect, map in custom_map_buttons:
  1087. if button_rect.collidepoint(event.pos):
  1088. map_info_text = get_custom_map_info_text(author_chosen, map) # 获取信息文本
  1089. # print(map, map_info_text)
  1090. if leave_map_info:
  1091. show_map_info = True
  1092. leave_map_info = False
  1093. show_map_name = map_info_text
  1094. # 如果鼠标不在按钮上方,则隐藏信息框
  1095. if not any(button_rect.collidepoint(event.pos) for button_rect, _ in custom_map_buttons):
  1096. if show_map_info:
  1097. map_info_box_rect = None
  1098. map_info_text = ""
  1099. show_map_info = False
  1100. show_map_name = None
  1101. leave_map_info = True
  1102. elif event.type == pygame.MOUSEBUTTONDOWN:
  1103. # 更新鼠标左键按下的状态
  1104. if event.button == 1:
  1105. mouse_left_button_down = True
  1106. mouse_left_button_up = False
  1107. if music_slider_rect.collidepoint(event.pos):
  1108. music_dragging = True
  1109. if sound_slider_rect.collidepoint(event.pos):
  1110. sound_dragging = True
  1111. # print("down", mouse_left_button_down, mouse_left_button_up)
  1112. effect_sound = "res/sound/uiLeave.wav"
  1113. try:
  1114. pygame.mixer.Sound(effect_sound).play()
  1115. except Exception as e:
  1116. print(e)
  1117. elif event.type == pygame.MOUSEBUTTONUP:
  1118. # 更新鼠标左键按下的状态
  1119. if event.button == 1:
  1120. mouse_left_button_down = False
  1121. mouse_left_button_up = True
  1122. is_click_setting = False
  1123. # Stop dragging when the user releases the mouse button
  1124. music_dragging = False
  1125. sound_dragging = False
  1126. # print("up", mouse_left_button_down, mouse_left_button_up)
  1127. # 在这里处理按钮点击事件
  1128. if current_screen == "main_menu":
  1129. for button_text, (x, y) in buttons:
  1130. button_rect = pygame.Rect(x, y, button_width, button_height)
  1131. if button_rect.collidepoint(event.pos):
  1132. try:
  1133. pygame.mixer.music.stop()
  1134. except Exception as e:
  1135. print(e)
  1136. print(button_text, "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")")
  1137. if button_text == "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")":
  1138. # 处理直接开始按钮点击事件
  1139. print("ready_launch")
  1140. if launcher_process is None:
  1141. launch_game()
  1142. elif button_text == "选择关卡":
  1143. # 处理选择关卡按钮点击事件
  1144. current_screen = "map_selection_menu"
  1145. draw_map_selection_menu()
  1146. # elif button_text == "游戏设置":
  1147. # 处理游戏设置按钮点击事件
  1148. # current_screen = "game_settings"
  1149. # draw_game_settings()
  1150. elif button_text == "关于作者":
  1151. # 处理作者信息按钮点击事件
  1152. current_screen = "author_info"
  1153. draw_author_info()
  1154. for button_text, (x, y) in buttons2:
  1155. button_rect = pygame.Rect(x, y, 180, 100)
  1156. if button_rect.collidepoint(event.pos):
  1157. if button_text == "成就记录":
  1158. # 处理直接开始按钮点击事件
  1159. if achievement_process is None:
  1160. achievement()
  1161. elif button_text == "游戏设置":
  1162. # 处理游戏设置按钮点击事件
  1163. current_screen = "game_settings"
  1164. draw_game_settings()
  1165. elif button_text == "操作帮助":
  1166. # 处理作者信息按钮点击事件
  1167. current_screen = "helper_info"
  1168. draw_helper_info()
  1169. elif current_screen == "author_info":
  1170. # 在作者信息界面点击返回按钮
  1171. return_button_width, return_button_height = 200, 60
  1172. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1173. return_button_height)
  1174. if return_button_rect.collidepoint(event.pos):
  1175. current_screen = "main_menu"
  1176. draw_menu()
  1177. elif current_screen == "helper_info":
  1178. # 在作者信息界面点击返回按钮
  1179. return_button_width, return_button_height = 200, 60
  1180. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1181. return_button_height)
  1182. if return_button_rect.collidepoint(event.pos):
  1183. current_screen = "main_menu"
  1184. draw_menu()
  1185. elif current_screen == "game_settings":
  1186. # 在游戏设置界面点击返回按钮
  1187. return_button_width, return_button_height = 160, 50
  1188. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1189. return_button_height)
  1190. if return_button_rect.collidepoint(event.pos):
  1191. current_screen = "main_menu"
  1192. draw_menu()
  1193. # 处理保存设置按钮点击事件
  1194. save_button_width, save_button_height = 150, 50
  1195. save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width,
  1196. SCREEN_HEIGHT - 50 - save_button_height, save_button_width,
  1197. save_button_height)
  1198. if save_button_rect.collidepoint(event.pos) and settings_changed:
  1199. # 保存设置到config.json文件中
  1200. try:
  1201. with open("config.json", "w", encoding="utf-8") as f:
  1202. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1203. except:
  1204. with open("config.json", "w", encoding="utf-8_sig") as f:
  1205. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1206. # 重置设置改变的标记
  1207. settings_changed = False
  1208. # 返回主菜单
  1209. current_screen = "main_menu"
  1210. draw_menu()
  1211. elif current_screen == "map_selection_menu":
  1212. # 在作者信息界面点击返回按钮
  1213. return_button_width, return_button_height = 300, 60
  1214. return_button_rect = pygame.Rect(250, SCREEN_HEIGHT - 150 - return_button_height,
  1215. return_button_width, return_button_height)
  1216. if return_button_rect.collidepoint(event.pos):
  1217. current_screen = "main_menu"
  1218. draw_menu()
  1219. original_maps_button_rect = pygame.Rect(250, 150, return_button_width, return_button_height)
  1220. if original_maps_button_rect.collidepoint(event.pos):
  1221. current_screen = "original_maps_submenu"
  1222. draw_original_maps_submenu()
  1223. custom_maps_button_rect = pygame.Rect(250, 150 + map_button_height + map_button_margin, return_button_width, return_button_height)
  1224. if custom_maps_button_rect.collidepoint(event.pos):
  1225. current_screen = "custom_maps_submenu"
  1226. current_page = 1
  1227. draw_custom_maps_submenu()
  1228. custom_apps_button_rect = pygame.Rect(250, 150 + 2*map_button_height + 2*map_button_margin, return_button_width, return_button_height)
  1229. if custom_apps_button_rect.collidepoint(event.pos):
  1230. current_screen = "apps"
  1231. current_page = 1
  1232. draw_custom_apps()
  1233. elif current_screen == "original_maps_submenu":
  1234. # 在作者信息界面点击返回按钮
  1235. return_button_width, return_button_height = 200, 60
  1236. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1237. return_button_height)
  1238. if return_button_rect.collidepoint(event.pos):
  1239. current_screen = "map_selection_menu"
  1240. draw_map_selection_menu()
  1241. # 绘制信息文本框
  1242. draw_map_info_box()
  1243. for button_rect, map_info in map_buttons:
  1244. if button_rect.collidepoint(event.pos):
  1245. handle_map_selection_click(map_info)
  1246. try:
  1247. with open("config.json", "w", encoding="utf-8") as f:
  1248. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1249. except:
  1250. with open("config.json", "w", encoding="utf-8_sig") as f:
  1251. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1252. buttons = [("直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),]
  1253. current_screen = "main_menu"
  1254. draw_menu()
  1255. break
  1256. elif current_screen == "custom_maps_submenu":
  1257. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
  1258. # 在作者信息界面点击返回按钮
  1259. return_button_width, return_button_height = 200, 60
  1260. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1261. return_button_height)
  1262. if return_button_rect.collidepoint(event.pos):
  1263. current_screen = "map_selection_menu"
  1264. draw_map_selection_menu()
  1265. break
  1266. # 检查是否点击了改图作者按钮
  1267. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1268. for author_button_rect, author in custom_map_buttons:
  1269. if author_button_rect.collidepoint(event.pos):
  1270. total_pages = 1
  1271. show_map_name = None
  1272. author_chosen = author
  1273. draw_custom_maps(author_chosen)
  1274. current_screen = "custom_maps"
  1275. current_page = 1
  1276. break
  1277. # return # 退出改图子菜单循环
  1278. # 检查是否点击了下一页按钮
  1279. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1280. current_page = (current_page % total_pages) + 1
  1281. # print(current_page)
  1282. draw_custom_maps_submenu() # 重新绘制改图子菜单以显示下一页
  1283. # 检查是否点击了上一页按钮
  1284. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1285. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1286. # print(current_page)
  1287. draw_custom_maps_submenu() # 重新绘制改图子菜单以显示上一页
  1288. elif current_screen == "custom_maps":
  1289. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
  1290. # 在作者信息界面点击返回按钮
  1291. return_button_width, return_button_height = 200, 60
  1292. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1293. return_button_height)
  1294. if return_button_rect.collidepoint(event.pos):
  1295. current_page = 1
  1296. current_screen = "custom_maps_submenu"
  1297. draw_custom_maps_submenu()
  1298. break
  1299. # 检查是否点击了改图作者按钮
  1300. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1301. for map_button_rect, map in custom_map_buttons:
  1302. if map_button_rect.collidepoint(event.pos):
  1303. current_page = 1
  1304. current_screen = "difficulties"
  1305. map_chosen = map
  1306. draw_custom_difficulty(author_chosen, map_chosen)
  1307. break
  1308. # current_screen = "custom_maps"
  1309. # draw_custom_maps(author) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!下一步写这个函数以打开每个改图作者的子界面
  1310. # return # 退出改图子菜单循环
  1311. # 检查是否点击了下一页按钮
  1312. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1313. current_page = (current_page % total_pages) + 1
  1314. # print(current_page)
  1315. draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示下一页
  1316. # 检查是否点击了上一页按钮
  1317. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1318. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1319. # print(current_page)
  1320. draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示上一页
  1321. elif current_screen == "difficulties":
  1322. difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
  1323. # 在作者信息界面点击返回按钮
  1324. return_button_width, return_button_height = 280, 70
  1325. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1326. return_button_height)
  1327. if return_button_rect.collidepoint(event.pos):
  1328. # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1329. current_page = 1
  1330. current_screen = "custom_maps"
  1331. # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1332. draw_custom_maps(author_chosen)
  1333. # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1334. break
  1335. # 检查是否点击了改图作者按钮
  1336. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1337. for map_button_rect, diff in difficulty_buttons:
  1338. if map_button_rect.collidepoint(event.pos):
  1339. handle_map_selection_click(diff['map_name'])
  1340. try:
  1341. with open("config.json", "w", encoding="utf-8") as f:
  1342. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1343. except:
  1344. with open("config.json", "w", encoding="utf-8_sig") as f:
  1345. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1346. buttons = [("直接开始(当前关卡:" + diff['difficulty'] + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3))]
  1347. current_screen = "main_menu"
  1348. draw_menu()
  1349. break
  1350. # 检查是否点击了下一页按钮
  1351. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1352. current_page = (current_page % total_pages) + 1
  1353. # print(current_page)
  1354. draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示下一页
  1355. # 检查是否点击了上一页按钮
  1356. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1357. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1358. # print(current_page)
  1359. draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示上一页
  1360. elif current_screen == "apps":
  1361. app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
  1362. # 在作者信息界面点击返回按钮
  1363. return_button_width, return_button_height = 200, 70
  1364. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1365. return_button_height)
  1366. if return_button_rect.collidepoint(event.pos):
  1367. # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1368. current_page = 1
  1369. current_screen = "map_selection_menu"
  1370. # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1371. draw_map_selection_menu()
  1372. launcher_process = None
  1373. app_process = None
  1374. try:
  1375. with open("config.json", encoding="utf-8") as f:
  1376. cfg_json = json.load(f)
  1377. except:
  1378. with open("config.json", encoding="utf-8_sig") as f:
  1379. cfg_json = json.load(f)
  1380. buttons = [("直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3))]
  1381. # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1382. break
  1383. # 检查是否点击了改图作者按钮
  1384. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1385. for map_button_rect, diff in app_buttons:
  1386. if map_button_rect.collidepoint(event.pos):
  1387. random_map_type = diff
  1388. launch_app(diff)
  1389. break
  1390. # 检查是否点击了下一页按钮
  1391. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1392. current_page = (current_page % total_pages) + 1
  1393. draw_custom_apps()
  1394. # 检查是否点击了上一页按钮
  1395. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1396. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1397. draw_custom_apps()
  1398. if current_screen == "main_menu":
  1399. # 绘制主菜单界面
  1400. draw_menu()
  1401. elif current_screen == "game_settings":
  1402. # 绘制游戏设置界面
  1403. draw_game_settings()
  1404. elif current_screen == "author_info":
  1405. # 绘制作者信息界面
  1406. draw_author_info()
  1407. elif current_screen == "map_selection_menu":
  1408. # 处理选图菜单
  1409. draw_map_selection_menu()
  1410. elif current_screen == "original_maps_submenu":
  1411. # 处理原图子菜单
  1412. draw_original_maps_submenu()
  1413. elif current_screen == "custom_maps_submenu":
  1414. # 处理改图子菜单
  1415. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
  1416. draw_custom_maps_submenu()
  1417. elif current_screen == "custom_maps":
  1418. # 处理具体作者改图
  1419. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
  1420. draw_custom_maps(author_chosen)
  1421. elif current_screen == "difficulties":
  1422. # 处理具体改图具体难度
  1423. difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
  1424. draw_custom_difficulty(author_chosen, map_chosen)
  1425. elif current_screen == "apps":
  1426. # 处理具体改图具体难度
  1427. app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
  1428. draw_custom_apps()
  1429. # 更新屏幕显示
  1430. pygame.display.flip()
  1431. pygame.quit()
  1432. # 地图选择循环
  1433. def map_selection_loop(map_selection, selected_author):
  1434. running = True
  1435. selected_map = None
  1436. while running:
  1437. for event in pygame.event.get():
  1438. if event.type == pygame.QUIT:
  1439. running = False
  1440. elif event.type == pygame.KEYDOWN:
  1441. if event.key == pygame.K_ESCAPE:
  1442. running = False
  1443. elif event.type == pygame.MOUSEBUTTONDOWN:
  1444. # 检查是否点击了任意一个地图按钮
  1445. for button_rect, map_info in map_buttons:
  1446. if button_rect.collidepoint(event.pos):
  1447. handle_map_selection_click(map_info)
  1448. return # 返回到上一个界面(主菜单或原图子菜单)
  1449. # draw_map_selection(map_selection, selected_author, selected_map)
  1450. pygame.display.flip()
  1451. pygame.quit()
  1452. if __name__ == "__main__":
  1453. # 读取地图选择数据
  1454. map_selection_data = read_map_selection()
  1455. # 运行主菜单循环
  1456. # 定义按钮的外观
  1457. button_width, button_height = 600, 100
  1458. button_margin = 20
  1459. # 定义按钮的文本和位置
  1460. buttons = [
  1461. ("直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),
  1462. ("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),
  1463. # ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  1464. ("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),
  1465. ]
  1466. buttons2 = [
  1467. ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  1468. ("成就记录", (SCREEN_WIDTH // 2 - button_width // 2 + 210, 100 + (button_height + button_margin) * 2)),
  1469. ("操作帮助", (SCREEN_WIDTH // 2 - button_width // 2 + 210 * 2, 100 + (button_height + button_margin) * 2))
  1470. ]
  1471. main_menu_loop()