test_menu.py 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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 == "DeepseekBlueWhale": return "蓝色大肥鱼(DeepSeek)"
  817. if hero == "Red": return "红色"
  818. if hero == "Blue": return "蓝色"
  819. if hero == "Yellow": return "黄色"
  820. if hero == "Green": return "绿色"
  821. if hero == "Pink": return "粉色"
  822. if hero == "Orange": return "橙色"
  823. if hero == "Purple": return "紫色"
  824. if hero == "Black": return "黑色"
  825. if hero == "SkyBlue": return "蓝灰色"
  826. if hero == "SakuraPink": return "香芋紫"
  827. if hero == "ForestGreen": return "森绿色"
  828. if hero == "GrassGreen": return "若草色"
  829. if hero == "Withered":
  830. return "枯叶色"
  831. else:
  832. return hero
  833. def draw_slider(setting_value, slider_x, setting_y):
  834. slider_width = 150
  835. slider_height = 10
  836. slider_rect = pygame.Rect(slider_x, setting_y, slider_width, slider_height)
  837. # Draw the slider track
  838. pygame.draw.rect(screen, LIGHT_GRAY, slider_rect, border_radius=5)
  839. # Calculate the position of the slider button based on the setting value
  840. slider_button_width = 15
  841. slider_button_x = slider_x + int((slider_width - slider_button_width) * setting_value)
  842. slider_button_rect = pygame.Rect(slider_button_x, setting_y - 5, slider_button_width, slider_height + 10)
  843. # Draw the slider button
  844. pygame.draw.rect(screen, BLACK, slider_button_rect, border_radius=5)
  845. return slider_button_rect
  846. # 设置界面代码
  847. def draw_game_settings():
  848. 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
  849. screen.fill(PAPER)
  850. # 加载自定义字体文件
  851. font = pygame.font.Font("res/font/simsun.ttc", 24)
  852. # 标题
  853. title_text = "游戏设置"
  854. title_surface = font.render(title_text, True, BLACK)
  855. title_rect = title_surface.get_rect(center=(SCREEN_WIDTH // 2, 50))
  856. screen.blit(title_surface, title_rect)
  857. # 绘制返回按钮
  858. return_button_text = "返回主菜单"
  859. return_button_width, return_button_height = 160, 50
  860. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  861. return_button_height)
  862. if return_button_rect.collidepoint(pygame.mouse.get_pos()):
  863. pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
  864. else:
  865. pygame.draw.rect(screen, BROWN, return_button_rect)
  866. # pygame.draw.rect(screen, BROWN, return_button_rect)
  867. return_text_surface = font.render(return_button_text, True, WHITE)
  868. return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
  869. screen.blit(return_text_surface, return_text_rect)
  870. # 绘制保存设置按钮
  871. save_button_text = "保存设置"
  872. save_button_width, save_button_height = 150, 50
  873. save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width, SCREEN_HEIGHT - 50 - save_button_height,
  874. save_button_width, save_button_height)
  875. if save_button_rect.collidepoint(pygame.mouse.get_pos()):
  876. pygame.draw.rect(screen, DARK_BROWN, save_button_rect)
  877. else:
  878. pygame.draw.rect(screen, BROWN, save_button_rect)
  879. # pygame.draw.rect(screen, BROWN, save_button_rect)
  880. save_text_surface = font.render(save_button_text, True, WHITE)
  881. save_text_rect = save_text_surface.get_rect(center=save_button_rect.center)
  882. screen.blit(save_text_surface, save_text_rect)
  883. # 绘制设置项
  884. setting_margin = 50
  885. setting_y = 120
  886. setting_height = 30
  887. # 设置项的名称和取值范围
  888. settings = [
  889. {"name": "your_hero", "label": "角色:",
  890. "choices": [
  891. "Maomao", "Asha", "Monkey", "Titan", "Fox", "FoxPlus", "Maria", "CaiBaozi", "Xiami", "Chunli", "Boboli",
  892. "XingZai", "SeaPrince_old", "Naruto_old", "Cola", "SeaPrince", "Naruto", "Nezha", "Chris",
  893. "mxfc", "Flandre", "Remilia", "DeepseekBlueWhale"
  894. ]},
  895. {"name": "your_character_color", "label": "角色颜色:",
  896. "choices": [
  897. "Red", "Blue", "Yellow", "Green", "Pink", "Orange", "Purple", "Black", "SkyBlue", "SakuraPink",
  898. "ForestGreen", "GrassGreen", "Withered"
  899. ]},
  900. {"name": "music_volume", "label": "音乐音量:", "min_value": 0, "max_value": 1},
  901. {"name": "sound_volume", "label": "音效音量:", "min_value": 0, "max_value": 1},
  902. {"name": "full_screen", "label": "全屏模式(有颜色表示ON/空白表示OFF):", "type": "checkbox"},
  903. {"name": "low_config_mode", "label": "低配模式(推荐打开):", "type": "checkbox"},
  904. {"name": "display_stat", "label": "显示数据(推荐打开):", "type": "checkbox"},
  905. {"name": "monster_records", "label": "怪物统计(只有玩家死亡和通关时会保存记录):", "type": "checkbox"},
  906. {"name": "v_sync", "label": "垂直同步(除低配机外推荐打开):", "type": "checkbox"},
  907. {"name": "show_time", "label": "显示时间特效(电脑不卡就开):", "type": "checkbox"},
  908. {"name": "drop_item", "label": "炸砖掉道具(电脑不卡可选择开):", "type": "checkbox"}
  909. ]
  910. # 绘制每个设置项
  911. for setting in settings:
  912. setting_name = setting["name"]
  913. setting_label = setting["label"]
  914. setting_value = cfg_json[setting_name]
  915. # 绘制标签
  916. label_surface = font.render(setting_label, True, BLACK)
  917. label_rect = label_surface.get_rect(topleft=(setting_margin, setting_y))
  918. screen.blit(label_surface, label_rect)
  919. # 绘制输入框或下拉列表或勾选框
  920. if setting["name"] == "music_volume":
  921. music_slider_x = SCREEN_WIDTH - setting_margin - 150
  922. music_slider_rect = draw_slider(setting_value, music_slider_x, setting_y)
  923. if setting["name"] == "sound_volume":
  924. sound_slider_x = SCREEN_WIDTH - setting_margin - 150
  925. sound_slider_rect = draw_slider(setting_value, sound_slider_x, setting_y)
  926. if "choices" in setting:
  927. choices = setting["choices"]
  928. dropdown_width = 150
  929. dropdown_height = 30
  930. dropdown_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - dropdown_width, setting_y, dropdown_width,
  931. dropdown_height)
  932. pygame.draw.rect(screen, PAPER, dropdown_rect, border_radius=5)
  933. pygame.draw.rect(screen, BLACK, dropdown_rect, 2)
  934. # 绘制当前值
  935. value_surface = font.render(show_hero_name(setting_value), True, BLACK)
  936. value_rect = value_surface.get_rect(center=dropdown_rect.center)
  937. screen.blit(value_surface, value_rect)
  938. # 绘制下拉箭头
  939. arrow_surface = font.render("▼", True, BLACK)
  940. arrow_rect = arrow_surface.get_rect(midright=(dropdown_rect.right - 5, dropdown_rect.centery))
  941. screen.blit(arrow_surface, arrow_rect)
  942. # 处理下拉按钮点击事件
  943. if dropdown_rect.collidepoint(pygame.mouse.get_pos()):
  944. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  945. # dropdown_menu_active = not dropdown_menu_active
  946. if setting["name"] == "your_hero":
  947. if drop_colour_choices:
  948. dropdown_menu_active = True
  949. drop_colour_choices = False
  950. else:
  951. dropdown_menu_active = not dropdown_menu_active
  952. drop_hero_choices = not drop_hero_choices
  953. if setting["name"] == "your_character_color":
  954. if drop_hero_choices:
  955. dropdown_menu_active = True
  956. drop_hero_choices = False
  957. else:
  958. dropdown_menu_active = not dropdown_menu_active
  959. drop_colour_choices = not drop_colour_choices
  960. is_click_setting = True
  961. elif setting.get("type") == "checkbox":
  962. checkbox_size = 25
  963. checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
  964. checkbox_size)
  965. pygame.draw.rect(screen, WHITE, checkbox_rect, border_radius=5)
  966. pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
  967. # 修改勾选状态的绘制
  968. if checkbox_states[setting_name]:
  969. checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
  970. checkbox_size)
  971. pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
  972. # 绘制实心正方形,使其与勾选框大小相同且在其中居中
  973. pygame.draw.rect(screen, BROWN, checkbox_rect) # 绘制实心正方形
  974. # 处理勾选框的点击事件
  975. if checkbox_rect.collidepoint(pygame.mouse.get_pos()):
  976. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  977. settings_changed = True
  978. is_click_setting = True
  979. checkbox_states[setting_name] = not checkbox_states[setting_name]
  980. cfg_json[setting_name] = not cfg_json[setting_name]
  981. setting_y += setting_height + 10
  982. # 在绘制下拉选项的循环之外定义一个变量来追踪选中的选项
  983. selected_choice = None
  984. # 绘制下拉选项(只有在下拉菜单处于显示状态时才进行绘制)
  985. if dropdown_menu_active:
  986. for setting in settings:
  987. if "choices" in setting:
  988. if (setting["name"] == "your_hero" and drop_hero_choices) or (setting["name"] == "your_character_color" and drop_colour_choices):
  989. choices = setting["choices"]
  990. dropdown_width = 180
  991. dropdown_height = 30
  992. num_per_col = 10
  993. dropdown_menu_height = len(choices) * dropdown_height + 10
  994. if setting["name"] == "your_hero":
  995. setting_y = 110
  996. if setting["name"] == "your_character_color":
  997. setting_y = 150
  998. dropdown_menu_y = setting_y + dropdown_height
  999. for i in range(len(choices)):
  1000. choice_rect = pygame.Rect(
  1001. SCREEN_WIDTH - setting_margin - (2 + i//num_per_col) * dropdown_width - 2 * (i//num_per_col) + 20,
  1002. dropdown_menu_y + (i % num_per_col - 1) * dropdown_height + 10,
  1003. dropdown_width,
  1004. dropdown_height
  1005. )
  1006. # Change the color of the option when the mouse hovers over it
  1007. if choice_rect.collidepoint(pygame.mouse.get_pos()):
  1008. pygame.draw.rect(screen, LIGHT_GRAY, choice_rect, border_radius=5)
  1009. else:
  1010. pygame.draw.rect(screen, LAVENDER_BLUE, choice_rect, border_radius=5)
  1011. pygame.draw.rect(screen, BLACK, choice_rect, 2)
  1012. # 绘制选项文本
  1013. choice_text = font.render(show_hero_name(choices[i]), True, BLACK)
  1014. choice_text_rect = choice_text.get_rect(center=choice_rect.center)
  1015. screen.blit(choice_text, choice_text_rect)
  1016. # 处理选项列表的点击事件
  1017. if choice_rect.collidepoint(pygame.mouse.get_pos()):
  1018. if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
  1019. # 更新选中的选项
  1020. selected_choice = choices[i]
  1021. is_click_setting = True
  1022. break
  1023. if selected_choice is not None:
  1024. cfg_json[setting["name"]] = selected_choice
  1025. dropdown_menu_active = False
  1026. drop_hero_choices = False
  1027. drop_colour_choices = False
  1028. settings_changed = True
  1029. break
  1030. # 更新屏幕显示
  1031. pygame.display.flip()
  1032. # 主菜单循环
  1033. def main_menu_loop():
  1034. 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, \
  1035. 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
  1036. current_screen = "main_menu"
  1037. running = True
  1038. while running:
  1039. for event in pygame.event.get():
  1040. if event.type == pygame.QUIT:
  1041. running = False
  1042. elif event.type == pygame.KEYDOWN:
  1043. if event.key == pygame.K_ESCAPE:
  1044. running = False
  1045. if event.type == pygame.MOUSEMOTION and mouse_left_button_down and not mouse_left_button_up and current_screen == "game_settings":
  1046. setting_margin = 50
  1047. if music_dragging:
  1048. # Update the music volume setting based on the slider position
  1049. # print(event.pos[0], SCREEN_WIDTH - setting_margin - 150)
  1050. music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1051. SCREEN_WIDTH - setting_margin - 150) / 15) * 15
  1052. setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1053. SCREEN_WIDTH - setting_margin - 150) - (
  1054. SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
  1055. cfg_json["music_volume"] = max(0.0, min(1.0, setting_value))
  1056. settings_changed = True
  1057. # print("music=",setting_value)
  1058. if sound_dragging:
  1059. # Update the sound volume setting based on the slider position
  1060. music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1061. SCREEN_WIDTH - setting_margin - 150) / 15) * 15
  1062. setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
  1063. SCREEN_WIDTH - setting_margin - 150) - (
  1064. SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
  1065. cfg_json["sound_volume"] = max(0.0, min(1.0, setting_value))
  1066. settings_changed = True
  1067. # print("sound=",setting_value)
  1068. if event.type == pygame.MOUSEMOTION and current_screen == "original_maps_submenu":
  1069. for button_rect, map_info in map_buttons:
  1070. if button_rect.collidepoint(event.pos):
  1071. map_info_text = get_map_info_text(map_info) # 获取信息文本
  1072. # print("collode button", map_info, map_info_text)
  1073. if leave_map_info:
  1074. show_map_info = True
  1075. leave_map_info = False
  1076. show_map_name = map_info_text
  1077. # 如果鼠标不在按钮上方,则隐藏信息框
  1078. if not any(button_rect.collidepoint(event.pos) for button_rect, _ in map_buttons):
  1079. if show_map_info:
  1080. # print("hide")
  1081. map_info_box_rect = None
  1082. map_info_text = ""
  1083. show_map_info = False
  1084. show_map_name = None
  1085. leave_map_info = True
  1086. if event.type == pygame.MOUSEMOTION and current_screen == "custom_maps":
  1087. for button_rect, map in custom_map_buttons:
  1088. if button_rect.collidepoint(event.pos):
  1089. map_info_text = get_custom_map_info_text(author_chosen, map) # 获取信息文本
  1090. # print(map, map_info_text)
  1091. if leave_map_info:
  1092. show_map_info = True
  1093. leave_map_info = False
  1094. show_map_name = map_info_text
  1095. # 如果鼠标不在按钮上方,则隐藏信息框
  1096. if not any(button_rect.collidepoint(event.pos) for button_rect, _ in custom_map_buttons):
  1097. if show_map_info:
  1098. map_info_box_rect = None
  1099. map_info_text = ""
  1100. show_map_info = False
  1101. show_map_name = None
  1102. leave_map_info = True
  1103. elif event.type == pygame.MOUSEBUTTONDOWN:
  1104. # 更新鼠标左键按下的状态
  1105. if event.button == 1:
  1106. mouse_left_button_down = True
  1107. mouse_left_button_up = False
  1108. if music_slider_rect.collidepoint(event.pos):
  1109. music_dragging = True
  1110. if sound_slider_rect.collidepoint(event.pos):
  1111. sound_dragging = True
  1112. # print("down", mouse_left_button_down, mouse_left_button_up)
  1113. effect_sound = "res/sound/uiLeave.wav"
  1114. try:
  1115. pygame.mixer.Sound(effect_sound).play()
  1116. except Exception as e:
  1117. print(e)
  1118. elif event.type == pygame.MOUSEBUTTONUP:
  1119. # 更新鼠标左键按下的状态
  1120. if event.button == 1:
  1121. mouse_left_button_down = False
  1122. mouse_left_button_up = True
  1123. is_click_setting = False
  1124. # Stop dragging when the user releases the mouse button
  1125. music_dragging = False
  1126. sound_dragging = False
  1127. # print("up", mouse_left_button_down, mouse_left_button_up)
  1128. # 在这里处理按钮点击事件
  1129. if current_screen == "main_menu":
  1130. for button_text, (x, y) in buttons:
  1131. button_rect = pygame.Rect(x, y, button_width, button_height)
  1132. if button_rect.collidepoint(event.pos):
  1133. try:
  1134. pygame.mixer.music.stop()
  1135. except Exception as e:
  1136. print(e)
  1137. print(button_text, "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")")
  1138. if button_text == "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")":
  1139. # 处理直接开始按钮点击事件
  1140. print("ready_launch")
  1141. if launcher_process is None:
  1142. launch_game()
  1143. elif button_text == "选择关卡":
  1144. # 处理选择关卡按钮点击事件
  1145. current_screen = "map_selection_menu"
  1146. draw_map_selection_menu()
  1147. # elif button_text == "游戏设置":
  1148. # 处理游戏设置按钮点击事件
  1149. # current_screen = "game_settings"
  1150. # draw_game_settings()
  1151. elif button_text == "关于作者":
  1152. # 处理作者信息按钮点击事件
  1153. current_screen = "author_info"
  1154. draw_author_info()
  1155. for button_text, (x, y) in buttons2:
  1156. button_rect = pygame.Rect(x, y, 180, 100)
  1157. if button_rect.collidepoint(event.pos):
  1158. if button_text == "成就记录":
  1159. # 处理直接开始按钮点击事件
  1160. if achievement_process is None:
  1161. achievement()
  1162. elif button_text == "游戏设置":
  1163. # 处理游戏设置按钮点击事件
  1164. current_screen = "game_settings"
  1165. draw_game_settings()
  1166. elif button_text == "操作帮助":
  1167. # 处理作者信息按钮点击事件
  1168. current_screen = "helper_info"
  1169. draw_helper_info()
  1170. elif current_screen == "author_info":
  1171. # 在作者信息界面点击返回按钮
  1172. return_button_width, return_button_height = 200, 60
  1173. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1174. return_button_height)
  1175. if return_button_rect.collidepoint(event.pos):
  1176. current_screen = "main_menu"
  1177. draw_menu()
  1178. elif current_screen == "helper_info":
  1179. # 在作者信息界面点击返回按钮
  1180. return_button_width, return_button_height = 200, 60
  1181. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1182. return_button_height)
  1183. if return_button_rect.collidepoint(event.pos):
  1184. current_screen = "main_menu"
  1185. draw_menu()
  1186. elif current_screen == "game_settings":
  1187. # 在游戏设置界面点击返回按钮
  1188. return_button_width, return_button_height = 160, 50
  1189. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1190. return_button_height)
  1191. if return_button_rect.collidepoint(event.pos):
  1192. current_screen = "main_menu"
  1193. draw_menu()
  1194. # 处理保存设置按钮点击事件
  1195. save_button_width, save_button_height = 150, 50
  1196. save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width,
  1197. SCREEN_HEIGHT - 50 - save_button_height, save_button_width,
  1198. save_button_height)
  1199. if save_button_rect.collidepoint(event.pos) and settings_changed:
  1200. # 保存设置到config.json文件中
  1201. try:
  1202. with open("config.json", "w", encoding="utf-8") as f:
  1203. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1204. except:
  1205. with open("config.json", "w", encoding="utf-8_sig") as f:
  1206. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1207. # 重置设置改变的标记
  1208. settings_changed = False
  1209. # 返回主菜单
  1210. current_screen = "main_menu"
  1211. draw_menu()
  1212. elif current_screen == "map_selection_menu":
  1213. # 在作者信息界面点击返回按钮
  1214. return_button_width, return_button_height = 300, 60
  1215. return_button_rect = pygame.Rect(250, SCREEN_HEIGHT - 150 - return_button_height,
  1216. return_button_width, return_button_height)
  1217. if return_button_rect.collidepoint(event.pos):
  1218. current_screen = "main_menu"
  1219. draw_menu()
  1220. original_maps_button_rect = pygame.Rect(250, 150, return_button_width, return_button_height)
  1221. if original_maps_button_rect.collidepoint(event.pos):
  1222. current_screen = "original_maps_submenu"
  1223. draw_original_maps_submenu()
  1224. custom_maps_button_rect = pygame.Rect(250, 150 + map_button_height + map_button_margin, return_button_width, return_button_height)
  1225. if custom_maps_button_rect.collidepoint(event.pos):
  1226. current_screen = "custom_maps_submenu"
  1227. current_page = 1
  1228. draw_custom_maps_submenu()
  1229. custom_apps_button_rect = pygame.Rect(250, 150 + 2*map_button_height + 2*map_button_margin, return_button_width, return_button_height)
  1230. if custom_apps_button_rect.collidepoint(event.pos):
  1231. current_screen = "apps"
  1232. current_page = 1
  1233. draw_custom_apps()
  1234. elif current_screen == "original_maps_submenu":
  1235. # 在作者信息界面点击返回按钮
  1236. return_button_width, return_button_height = 200, 60
  1237. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1238. return_button_height)
  1239. if return_button_rect.collidepoint(event.pos):
  1240. current_screen = "map_selection_menu"
  1241. draw_map_selection_menu()
  1242. # 绘制信息文本框
  1243. draw_map_info_box()
  1244. for button_rect, map_info in map_buttons:
  1245. if button_rect.collidepoint(event.pos):
  1246. handle_map_selection_click(map_info)
  1247. try:
  1248. with open("config.json", "w", encoding="utf-8") as f:
  1249. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1250. except:
  1251. with open("config.json", "w", encoding="utf-8_sig") as f:
  1252. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1253. 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)),]
  1254. current_screen = "main_menu"
  1255. draw_menu()
  1256. break
  1257. elif current_screen == "custom_maps_submenu":
  1258. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
  1259. # 在作者信息界面点击返回按钮
  1260. return_button_width, return_button_height = 200, 60
  1261. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1262. return_button_height)
  1263. if return_button_rect.collidepoint(event.pos):
  1264. current_screen = "map_selection_menu"
  1265. draw_map_selection_menu()
  1266. break
  1267. # 检查是否点击了改图作者按钮
  1268. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1269. for author_button_rect, author in custom_map_buttons:
  1270. if author_button_rect.collidepoint(event.pos):
  1271. total_pages = 1
  1272. show_map_name = None
  1273. author_chosen = author
  1274. draw_custom_maps(author_chosen)
  1275. current_screen = "custom_maps"
  1276. current_page = 1
  1277. break
  1278. # return # 退出改图子菜单循环
  1279. # 检查是否点击了下一页按钮
  1280. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1281. current_page = (current_page % total_pages) + 1
  1282. # print(current_page)
  1283. draw_custom_maps_submenu() # 重新绘制改图子菜单以显示下一页
  1284. # 检查是否点击了上一页按钮
  1285. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1286. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1287. # print(current_page)
  1288. draw_custom_maps_submenu() # 重新绘制改图子菜单以显示上一页
  1289. elif current_screen == "custom_maps":
  1290. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
  1291. # 在作者信息界面点击返回按钮
  1292. return_button_width, return_button_height = 200, 60
  1293. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1294. return_button_height)
  1295. if return_button_rect.collidepoint(event.pos):
  1296. current_page = 1
  1297. current_screen = "custom_maps_submenu"
  1298. draw_custom_maps_submenu()
  1299. break
  1300. # 检查是否点击了改图作者按钮
  1301. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1302. for map_button_rect, map in custom_map_buttons:
  1303. if map_button_rect.collidepoint(event.pos):
  1304. current_page = 1
  1305. current_screen = "difficulties"
  1306. map_chosen = map
  1307. draw_custom_difficulty(author_chosen, map_chosen)
  1308. break
  1309. # current_screen = "custom_maps"
  1310. # draw_custom_maps(author) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!下一步写这个函数以打开每个改图作者的子界面
  1311. # return # 退出改图子菜单循环
  1312. # 检查是否点击了下一页按钮
  1313. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1314. current_page = (current_page % total_pages) + 1
  1315. # print(current_page)
  1316. draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示下一页
  1317. # 检查是否点击了上一页按钮
  1318. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1319. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1320. # print(current_page)
  1321. draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示上一页
  1322. elif current_screen == "difficulties":
  1323. difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
  1324. # 在作者信息界面点击返回按钮
  1325. return_button_width, return_button_height = 280, 70
  1326. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1327. return_button_height)
  1328. if return_button_rect.collidepoint(event.pos):
  1329. # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1330. current_page = 1
  1331. current_screen = "custom_maps"
  1332. # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1333. draw_custom_maps(author_chosen)
  1334. # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1335. break
  1336. # 检查是否点击了改图作者按钮
  1337. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1338. for map_button_rect, diff in difficulty_buttons:
  1339. if map_button_rect.collidepoint(event.pos):
  1340. handle_map_selection_click(diff['map_name'])
  1341. try:
  1342. with open("config.json", "w", encoding="utf-8") as f:
  1343. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1344. except:
  1345. with open("config.json", "w", encoding="utf-8_sig") as f:
  1346. json.dump(cfg_json, f, indent=4, ensure_ascii=False)
  1347. 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))]
  1348. current_screen = "main_menu"
  1349. draw_menu()
  1350. break
  1351. # 检查是否点击了下一页按钮
  1352. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1353. current_page = (current_page % total_pages) + 1
  1354. # print(current_page)
  1355. draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示下一页
  1356. # 检查是否点击了上一页按钮
  1357. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1358. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1359. # print(current_page)
  1360. draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示上一页
  1361. elif current_screen == "apps":
  1362. app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
  1363. # 在作者信息界面点击返回按钮
  1364. return_button_width, return_button_height = 200, 70
  1365. return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
  1366. return_button_height)
  1367. if return_button_rect.collidepoint(event.pos):
  1368. # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1369. current_page = 1
  1370. current_screen = "map_selection_menu"
  1371. # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1372. draw_map_selection_menu()
  1373. launcher_process = None
  1374. app_process = None
  1375. try:
  1376. with open("config.json", encoding="utf-8") as f:
  1377. cfg_json = json.load(f)
  1378. except:
  1379. with open("config.json", encoding="utf-8_sig") as f:
  1380. cfg_json = json.load(f)
  1381. 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))]
  1382. # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
  1383. break
  1384. # 检查是否点击了改图作者按钮
  1385. # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
  1386. for map_button_rect, diff in app_buttons:
  1387. if map_button_rect.collidepoint(event.pos):
  1388. random_map_type = diff
  1389. launch_app(diff)
  1390. break
  1391. # 检查是否点击了下一页按钮
  1392. if total_pages > 1 and next_button_rect.collidepoint(event.pos):
  1393. current_page = (current_page % total_pages) + 1
  1394. draw_custom_apps()
  1395. # 检查是否点击了上一页按钮
  1396. if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
  1397. current_page = (current_page - 2 + total_pages) % total_pages + 1
  1398. draw_custom_apps()
  1399. if current_screen == "main_menu":
  1400. # 绘制主菜单界面
  1401. draw_menu()
  1402. elif current_screen == "game_settings":
  1403. # 绘制游戏设置界面
  1404. draw_game_settings()
  1405. elif current_screen == "author_info":
  1406. # 绘制作者信息界面
  1407. draw_author_info()
  1408. elif current_screen == "map_selection_menu":
  1409. # 处理选图菜单
  1410. draw_map_selection_menu()
  1411. elif current_screen == "original_maps_submenu":
  1412. # 处理原图子菜单
  1413. draw_original_maps_submenu()
  1414. elif current_screen == "custom_maps_submenu":
  1415. # 处理改图子菜单
  1416. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
  1417. draw_custom_maps_submenu()
  1418. elif current_screen == "custom_maps":
  1419. # 处理具体作者改图
  1420. custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
  1421. draw_custom_maps(author_chosen)
  1422. elif current_screen == "difficulties":
  1423. # 处理具体改图具体难度
  1424. difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
  1425. draw_custom_difficulty(author_chosen, map_chosen)
  1426. elif current_screen == "apps":
  1427. # 处理具体改图具体难度
  1428. app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
  1429. draw_custom_apps()
  1430. # 更新屏幕显示
  1431. pygame.display.flip()
  1432. pygame.quit()
  1433. # 地图选择循环
  1434. def map_selection_loop(map_selection, selected_author):
  1435. running = True
  1436. selected_map = None
  1437. while running:
  1438. for event in pygame.event.get():
  1439. if event.type == pygame.QUIT:
  1440. running = False
  1441. elif event.type == pygame.KEYDOWN:
  1442. if event.key == pygame.K_ESCAPE:
  1443. running = False
  1444. elif event.type == pygame.MOUSEBUTTONDOWN:
  1445. # 检查是否点击了任意一个地图按钮
  1446. for button_rect, map_info in map_buttons:
  1447. if button_rect.collidepoint(event.pos):
  1448. handle_map_selection_click(map_info)
  1449. return # 返回到上一个界面(主菜单或原图子菜单)
  1450. # draw_map_selection(map_selection, selected_author, selected_map)
  1451. pygame.display.flip()
  1452. pygame.quit()
  1453. if __name__ == "__main__":
  1454. # 读取地图选择数据
  1455. map_selection_data = read_map_selection()
  1456. # 运行主菜单循环
  1457. # 定义按钮的外观
  1458. button_width, button_height = 600, 100
  1459. button_margin = 20
  1460. # 定义按钮的文本和位置
  1461. buttons = [
  1462. ("直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")", (SCREEN_WIDTH // 2 - button_width // 2, 100)),
  1463. ("选择关卡", (SCREEN_WIDTH // 2 - button_width // 2, 100 + button_height + button_margin)),
  1464. # ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  1465. ("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),
  1466. ]
  1467. buttons2 = [
  1468. ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
  1469. ("成就记录", (SCREEN_WIDTH // 2 - button_width // 2 + 210, 100 + (button_height + button_margin) * 2)),
  1470. ("操作帮助", (SCREEN_WIDTH // 2 - button_width // 2 + 210 * 2, 100 + (button_height + button_margin) * 2))
  1471. ]
  1472. main_menu_loop()