| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838 |
- import pygame
- import json
- import subprocess
- import os
- import sys
- import pygame_gui
- from pygame_gui.ui_manager import UIManager
- from pygame_gui.elements.ui_text_entry_line import UITextEntryLine
- import tkinter as tk
- from tkinter import ttk
- from datetime import datetime
- import hashlib
- # 处理过长的成就
- def generate_verification_code(timestamp):
- """基于时间戳生成一个长度为6的验证字符串"""
- hash_object = hashlib.sha256(timestamp.encode())
- # 取SHA256哈希值的前6位作为验证字符串
- return hash_object.hexdigest()[:6]
- def handle_long_achievements():
- user_documents_folder = os.path.expanduser("~\\Documents")
- qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE")
- os.makedirs(qqtpve_folder, exist_ok=True)
- def process_file(file_path, file_key="STAT"):
- try:
- with open(file_path, encoding="utf-8") as file:
- data = json.load(file)
- except FileNotFoundError:
- data = {file_key: []}
- with open(file_path, 'w', encoding="utf-8") as file:
- json.dump(data, file, indent=2)
- except Exception as e:
- print(f"读取{file_path}错误: {e}")
- return
- if len(data[file_key]) > 5000:
- extracted_data = data[file_key][:]
- data[file_key] = []
- with open(file_path, 'w', encoding="utf-8") as file:
- json.dump(data, file, indent=2)
- timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
- verification_code = generate_verification_code(timestamp)
- base_name = os.path.basename(file_path)
- name, ext = os.path.splitext(base_name)
- new_name = f"{name}_{timestamp}_{verification_code}{ext}"
- new_file_path = os.path.join(os.path.dirname(file_path), new_name)
- with open(new_file_path, 'w', encoding="utf-8") as file:
- json.dump({file_key: extracted_data}, file, indent=2)
- print(f"已保存到{new_file_path}")
- # achievements_file_path = os.path.join(qqtpve_folder, "achievements.json")
- monster_stats_file_path = os.path.join(qqtpve_folder, "monster_stats.json")
- # process_file(achievements_file_path)
- process_file(monster_stats_file_path)
- # 读取时需要解析文件名,提取时间戳和验证字符串,然后使用generate_verification_code函数来验证这个字符串是否匹配。
- try:
- handle_long_achievements()
- except Exception as e:
- print(e)
- # 初始化pygame
- pygame.init()
- # 屏幕大小
- SCREEN_WIDTH, SCREEN_HEIGHT = 960, 680
- screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- pygame.display.set_caption("游戏主菜单(游戏作者:永恒,菜单作者:100の雨女),讨论群:756422783,官方wiki网址:qqtwiki.free.nf")
- # 颜色定义
- PAPER = (255, 235, 205)
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- LIGHT_GRAY = (168, 168, 168)
- BROWN = (127, 70, 44)
- DARK_BROWN = (100, 50, 30)
- ORANGE_PINK = (127, 82, 93)
- LAVENDER_BLUE = (227, 228, 250)
- bg_music = "res/music/M09.ogg"
- # 播放背景音乐
- # pygame.mixer.music.load(bg_music)
- # pygame.mixer.music.play(-1)
- # 全局变量,用于保存launcher进程对象
- launcher_process = None
- app_process = None
- achievement_process = None
- # 在全局定义一个变量来保存鼠标左键是否按下的状态
- mouse_left_button_down = False
- mouse_left_button_up = True
- is_click_setting = False
- settings_changed = False
- show_map_info = False
- show_map_name = None
- show_custom_map_name = None
- leave_map_info = True
- current_page = 1
- try:
- with open("config.json", encoding="utf-8") as f:
- cfg_json = json.load(f)
- except:
- with open("config.json", encoding="utf-8_sig") as f:
- cfg_json = json.load(f)
- # 初始化一个空字典来存储合并后的数据
- map_name_en = {}
- # 遍历指定目录中的所有文件
- for filename in os.listdir("game/menu_list/menu_map_set"):
- # 检查文件是否是 JSON 文件
- if filename.endswith('.json'):
- # 构造文件的完整路径
- file_path = os.path.join("game/menu_list/menu_map_set", filename)
- # 读取 JSON 数据并合并
- with open(file_path, 'r', encoding='utf-8') as file:
- # 文件名(不包括扩展名)作为键
- key = filename[:-5]
- tmp_file = json.load(file)
- if len(tmp_file) == 0:
- continue
- if key == '0Official':
- for mname in tmp_file[0].keys():
- map_name_en[mname] = tmp_file[0][mname]["map_name"]
- else:
- for thame in tmp_file:
- for thame_name in thame.keys():
- for mname_dic in thame[thame_name]["selections"]:
- map_name_en[mname_dic["map_name"]] = mname_dic["difficulty"]
- # 读取地图信息
- def read_map_selection():
- # 初始化一个空字典来存储合并后的数据
- merged_data = {}
- # 遍历指定目录中的所有文件
- for filename in os.listdir("game/menu_list/menu_map_set"):
- # 检查文件是否是 JSON 文件
- if filename.endswith('.json'):
- # 构造文件的完整路径
- file_path = os.path.join("game/menu_list/menu_map_set", filename)
- # 读取 JSON 数据并合并
- with open(file_path, 'r', encoding='utf-8') as file:
- # 文件名(不包括扩展名)作为键
- key = filename[:-5]
- # 读取文件内容并添加到字典
- # print(filename)
- # print(json.load(file))
- merged_data[key] = json.load(file)
- return merged_data
- # 初始化一个空字典来存储合并后的数据
- app_name = {}
- # 遍历指定目录中的所有文件
- for filename in os.listdir("game/menu_list/menu_app"):
- # 检查文件是否是 JSON 文件
- if filename.endswith('.json'):
- # 构造文件的完整路径
- file_path = os.path.join("game/menu_list/menu_app", filename)
- # 读取 JSON 数据并合并
- with open(file_path, 'r', encoding='utf-8') as file:
- # 文件名(不包括扩展名)作为键
- key = filename[:-5]
- tmp_file = json.load(file)
- app_name[key] = tmp_file[0]
- def stars_string(n):
- if n <= 0:
- raise ValueError("输入必须为正整数")
- num_stars = n // 10
- num_dots = n % 10
- stars_string = "★" * num_stars + "☆" * num_dots
- return stars_string
- # 绘制主菜单界面
- def draw_menu():
- screen.fill(PAPER)
- # 加载自定义字体文件
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- # 定义按钮的外观
- button_width, button_height = 600, 100
- button_margin = 20
- # 定义按钮的文本和位置
- 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) * 2)),
- ("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),
- ]
- # 绘制按钮
- for button_text, (x, y) in buttons:
- button_rect = pygame.Rect(x, y, button_width, button_height)
- if button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, button_rect)
- else:
- pygame.draw.rect(screen, BROWN, button_rect)
- # pygame.draw.rect(screen, BROWN, button_rect)
- text = font.render(button_text, True, WHITE)
- text_rect = text.get_rect(center=button_rect.center)
- screen.blit(text, text_rect)
- # 定义按钮的文本和位置
- buttons2 = [
- ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
- ("成就记录", (SCREEN_WIDTH // 2 - button_width // 2 + 210, 100 + (button_height + button_margin) * 2)),
- ("操作帮助", (SCREEN_WIDTH // 2 - button_width // 2 + 210 * 2, 100 + (button_height + button_margin) * 2))
- ]
- # 绘制按钮
- for button_text, (x, y) in buttons2:
- button_rect = pygame.Rect(x, y, 180, 100)
- if button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, button_rect)
- else:
- pygame.draw.rect(screen, BROWN, button_rect)
- # pygame.draw.rect(screen, BROWN, button_rect)
- text = font.render(button_text, True, WHITE)
- text_rect = text.get_rect(center=button_rect.center)
- screen.blit(text, text_rect)
- # 更新屏幕显示
- pygame.display.flip()
- # 绘制作者信息界面
- def draw_author_info():
- screen.fill(PAPER)
- # 加载自定义字体文件
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- # 作者信息文本
- author_info_text = "关于作者:\n\n QQTPVE作者: 永恒 B站曾用id: QQTPVE-永恒(已注销) \n\n 联机作者: KY B站id: Zageku" + \
- "\n\n 菜单作者与后续单机运营: 100の雨女 B站id同名 \n\n 链接: https://space.bilibili.com/12132334" + \
- "\n\n 感谢悠闲人生,疾风等改图作者与根号十三,冰神等老玩家与Null等技术人员的支持" + \
- "\n\n 官方探险群:756422783,老群:133753304 \n\n 官方wiki网站: qqtwiki.free.nf"
- # 将文本按换行符拆分成多行
- lines = author_info_text.split("\n")
- # 绘制每一行文本
- line_height = 30
- y_offset = 120
- for line in lines:
- text_surface = font.render(line, True, BLACK)
- text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2, y_offset))
- screen.blit(text_surface, text_rect)
- y_offset += line_height
- # 绘制返回按钮
- return_button_text = "返回主菜单"
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- return_text_surface = font.render(return_button_text, True, WHITE)
- return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
- screen.blit(return_text_surface, return_text_rect)
- # 更新屏幕显示
- pygame.display.flip()
- # 绘制操作帮助
- def draw_helper_info():
- screen.fill(PAPER)
- # 加载自定义字体文件
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- # 作者信息文本
- author_info_text = "操作帮助:\n\n 开关怪物姓名牌快捷键:F6(部分机型F6+Fn) \n\n 怪物姓名与血量切换显示快捷键:F7(部分机型F7+Fn)" + \
- "\n\n 重新开始本地图快捷键: 0(主键盘数字) \n\n 上下左右移动,空格放置糖泡,数字123使用道具 \n\n 修改特殊键位置请使用其他辅助程序或参阅config修改手册" + \
- "\n\n 换衣服换糖泡请参阅永恒大佬B站视频教学 \n\n 此为单机探险不可联机不可进入商城更不可能恢复原账号数据 \n\n 打不过原图就去打新手教程!!能过教程基本能过所有原图(黑龙除外)!!"
- # 将文本按换行符拆分成多行
- lines = author_info_text.split("\n")
- # 绘制每一行文本
- line_height = 30
- y_offset = 50
- for line in lines:
- text_surface = font.render(line, True, BLACK)
- text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2, y_offset))
- screen.blit(text_surface, text_rect)
- y_offset += line_height
- # 绘制返回按钮
- return_button_text = "返回主菜单"
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- return_text_surface = font.render(return_button_text, True, WHITE)
- return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
- screen.blit(return_text_surface, return_text_rect)
- # 更新屏幕显示
- pygame.display.flip()
- # 运行游戏launcher
- def launch_game():
- global launcher_process
- print("PVE, Launch!!!")
- try:
- # 替换为launcher.exe的路径
- launcher_path = "launcher.exe"
- # 启动launcher.exe并隐藏窗口
- launcher_process = subprocess.Popen([launcher_path], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, creationflags=subprocess.DETACHED_PROCESS)
- # 隐藏主菜单窗口
- pygame.display.iconify()
- # 等待launcher.exe结束
- # launcher_process.communicate()
- # 当launcher.exe关闭后,关闭主菜单窗口并退出程序
- # pygame.display.quit()
- # sys.exit()
- except FileNotFoundError:
- print("找不到launcher.exe,请确保它与Python脚本在同一目录下。")
- except Exception as e:
- print("运行launcher.exe时出现错误:", e)
- finally:
- launcher_process = None
- # 运行app
- def launch_app(app_name):
- global app_process
- print(app_name + ", Launch!!!")
- try:
- # 替换为launcher.exe的路径
- launcher_path = app_name + ".exe"
- # 启动launcher.exe
- app_process = subprocess.Popen([launcher_path])
- except FileNotFoundError:
- print("找不到" + app_name + ".exe,请确保它与Python脚本在同一目录下。")
- except Exception as e:
- print("运行" + app_name + "时出现错误:", e)
- finally:
- app_process = None
- # 运行成就
- def achievement():
- global achievement_process
- try:
- # 替换为launcher.exe的路径
- achievement_path = "点亮式成就.exe"
- # 启动launcher.exe并隐藏窗口
- achievement_process = subprocess.Popen([achievement_path], shell=True, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- creationflags=subprocess.DETACHED_PROCESS)
- # 隐藏主菜单窗口
- # pygame.display.iconify()
- # 等待launcher.exe结束
- # achievement_process.communicate()
- # 当launcher.exe关闭后,关闭主菜单窗口并退出程序
- # pygame.display.quit()
- # sys.exit()
- except FileNotFoundError:
- print("找不到点亮式成就.exe,请确保它与Python脚本在同一目录下。")
- except Exception as e:
- print("运行点亮式成就.exe时出现错误:", e)
- finally:
- achievement_process = None
- # 地图选择菜单中的按钮
- map_buttons = []
- map_button_width, map_button_height = 300, 60
- map_button_margin = 20
- # 处理地图选择按钮的点击事件
- def handle_map_selection_click(map):
- # 在这里处理地图选择,例如更新config.json中的选定地图
- cfg_json["map_set"] = map
- # 返回到上一个界面(地图选择菜单)
- current_screen = "main_menu"
- draw_menu()
- # map_selection_loop(map_selection_data, map_info["author"])
- # 绘制地图选择菜单
- def draw_map_selection_menu():
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"原图"按钮
- original_maps_button_rect = pygame.Rect(250, 150, map_button_width, map_button_height)
- if original_maps_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, original_maps_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, original_maps_button_rect)
- # pygame.draw.rect(screen, BROWN, original_maps_button_rect)
- pygame.draw.rect(screen, PAPER, original_maps_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("官方原图与教程", True, WHITE)
- text_rect = text.get_rect(center=original_maps_button_rect.center)
- screen.blit(text, text_rect)
- # 绘制"其他作者的地图"按钮
- other_authors_button_rect = pygame.Rect(250, 150 + map_button_height + map_button_margin, map_button_width,
- map_button_height)
- if other_authors_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, other_authors_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, other_authors_button_rect)
- # pygame.draw.rect(screen, BROWN, other_authors_button_rect)
- pygame.draw.rect(screen, PAPER, other_authors_button_rect, 3)
- text = font.render("改图(玩家自创)", True, WHITE)
- text_rect = text.get_rect(center=other_authors_button_rect.center)
- screen.blit(text, text_rect)
- # 绘制"其他地图生成工具"按钮
- other_apps_button_rect = pygame.Rect(250, 150 + 2*map_button_height + 2*map_button_margin, map_button_width,
- map_button_height)
- if other_apps_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, other_apps_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, other_apps_button_rect)
- pygame.draw.rect(screen, PAPER, other_apps_button_rect, 3)
- text = font.render("其他(地图生成/辅助)", True, WHITE)
- text_rect = text.get_rect(center=other_apps_button_rect.center)
- screen.blit(text, text_rect)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(250, SCREEN_HEIGHT - 150 - map_button_height, map_button_width, map_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- text = font.render("返回主菜单", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 更新屏幕显示
- pygame.display.flip()
- random_map_type = ""
- def show_official_map_name(map):
- if map in list(map_name_en.keys()):
- return map_name_en[map]
- else:
- if map == "randomMapSet":
- if random_map_type != "":
- return "随机地图("+random_map_type+")"
- else: return "随机地图(未知)"
- else: return map
- # 地图信息显示框
- map_info_box_width, map_info_box_height = 300, 100
- map_info_box_margin = 10
- map_info_box_rect = None
- map_info_text = ""
- original_map_button_width = 200
- # 绘制原图子菜单
- def draw_original_maps_submenu():
- global map_info_box_rect, map_info_text
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - map_button_height, original_map_button_width, map_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("返回", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 绘制所有原图按钮
- x, y = 200, 50
- # for map_info in map_selection_data[author]:
- # print(list(map_selection_data["Official"][0].keys()))
- for k, map_info in enumerate(list(map_selection_data["0Official"][0].keys())):
- # print(map_info)
- map_button_rect = pygame.Rect(x, y, original_map_button_width, map_button_height)
- if map_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, map_button_rect)
- # pygame.draw.rect(screen, BROWN, map_button_rect)
- pygame.draw.rect(screen, PAPER, map_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- # text = font.render(map_info[list(map_info.keys())[0]]["map_name"], True, WHITE)
- text = font.render(show_official_map_name(map_info), True, WHITE)
- text_rect = text.get_rect(center=map_button_rect.center)
- screen.blit(text, text_rect)
- # 添加地图按钮到列表中以备后续处理事件
- map_buttons.append((map_button_rect, map_info))
- if y + map_button_height + map_button_margin <= SCREEN_HEIGHT - 3 * map_button_height:
- y += map_button_height + map_button_margin
- else:
- x += original_map_button_width + map_button_margin
- y = 50
- map_info_box_width, map_info_box_height = 600, 120
- 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)
- pygame.draw.rect(screen, ORANGE_PINK, map_info_box_rect)
- pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
- if show_map_info and show_map_name is not None:
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- lines = show_map_name.split("\n")
- for i, line in enumerate(lines):
- text_surface = font.render(line, True, WHITE)
- text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2 + 100, SCREEN_HEIGHT - 120 + i * 20))
- screen.blit(text_surface, text_rect)
- # pygame.display.flip()
- # 更新屏幕显示
- pygame.display.flip()
- def show_author_name(author):
- if author == 'AmeOnna': return '100の雨女'
- elif author == '0YouXian0': return '0悠闲人生0'
- elif author == 'MingGui': return '冥の归'
- elif author == 'JiFeng': return '疾风'
- elif author == 'CanBing': return '残冰'
- elif author == 'Null': return '闹神'
- elif author == 'YongHeng': return '永恒'
- elif author == 'PBGuangYing': return '光影'
- elif author == 'TaXue': return '踏雪无痕'
- elif author == 'XiaoLieQuan': return '小猎犬'
- elif author == 'u7iui': return 'u7iui'
- elif author == 'z_Unknown': return '敬请期待更多'
- else: return author
- # 改图子菜单的按钮宽高和间距
- custom_map_button_width, custom_map_button_height = 200, 60
- custom_map_button_margin = 10
- def draw_custom_maps_submenu():
- global map_info_box_rect, map_info_text
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - custom_map_button_height, custom_map_button_width, custom_map_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("返回", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 获取所有改图作者的名字
- caremove = list(map_selection_data.keys())
- caremove.remove('0Official')
- custom_authors = caremove
- # 计算可以显示的改图作者的数量
- max_custom_authors = (SCREEN_HEIGHT - 2 * custom_map_button_height) // (custom_map_button_height + custom_map_button_margin)
- # 计算总页数
- total_pages = (len(custom_authors) + max_custom_authors - 1) // max_custom_authors
- # 绘制改图作者按钮
- x, y = SCREEN_WIDTH // 2 - custom_map_button_width // 2, 50
- custom_map_buttons = [] # 存储改图作者按钮的位置和对应作者名
- # print(custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))])
- # print(current_page)
- # print((current_page - 1) * max_custom_authors , min(len(custom_authors),(current_page * max_custom_authors)))
- for author in custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]:
- author_button_rect = pygame.Rect(x, y, custom_map_button_width, custom_map_button_height)
- if author_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, author_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, author_button_rect)
- # pygame.draw.rect(screen, BROWN, author_button_rect)
- pygame.draw.rect(screen, PAPER, author_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- text = font.render(show_author_name(author)+'改图', True, WHITE)
- text_rect = text.get_rect(center=author_button_rect.center)
- screen.blit(text, text_rect)
- custom_map_buttons.append((author_button_rect, author))
- y += custom_map_button_height + custom_map_button_margin
- # 绘制滚动条或下一页按钮
- if total_pages > 1:
- scroll_button_width, scroll_button_height = 80, 120
- scroll_button_margin = 10
- 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)
- 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)
- if next_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
- if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
- # pygame.draw.rect(screen, BROWN, next_button_rect)
- # pygame.draw.rect(screen, BROWN, prev_button_rect)
- 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)])
- 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)])
- pygame.display.flip()
- return custom_map_buttons, total_pages, next_button_rect, prev_button_rect
- # 更新屏幕显示
- pygame.display.flip()
- return custom_map_buttons, total_pages, None, None
- # 选大关界面
- def draw_custom_maps(author):
- global map_info_box_rect, map_info_text, custom_map_buttons
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - custom_map_button_height, custom_map_button_width, custom_map_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("返回作者菜单", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 获取所有改图的名字
- custom_maps = [list(item.keys())[0] for item in map_selection_data[author]]
- # 计算可以显示的改图的数量
- max_custom_maps = (SCREEN_HEIGHT - 2 * custom_map_button_height) // (custom_map_button_height + custom_map_button_margin) - 1
- # 计算总页数
- total_pages = (len(custom_maps) + max_custom_maps - 1) // max_custom_maps
- # print(custom_maps, max_custom_maps, total_pages)
- # 绘制改图作者按钮
- x, y = SCREEN_WIDTH // 4 - custom_map_button_width // 2, 50
- custom_map_buttons = [] # 存储改图作者按钮的位置和对应作者名
- for map in custom_maps[(current_page - 1) * max_custom_maps : min(len(custom_maps),(current_page * max_custom_maps))]:
- map_button_rect = pygame.Rect(x, y, custom_map_button_width, custom_map_button_height)
- if map_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, map_button_rect)
- pygame.draw.rect(screen, PAPER, map_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- text = font.render(next(item[map]['full_name'] for item in map_selection_data[author] if map in item), True, WHITE)
- text_rect = text.get_rect(center=map_button_rect.center)
- screen.blit(text, text_rect)
- custom_map_buttons.append((map_button_rect, map))
- y += custom_map_button_height + custom_map_button_margin
- map_info_box_width, map_info_box_height = 450, 620
- map_info_box_rect = pygame.Rect((SCREEN_WIDTH - map_info_box_width) // 2 + 215, 30, map_info_box_width, map_info_box_height)
- pygame.draw.rect(screen, ORANGE_PINK, map_info_box_rect)
- pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
- if show_map_info and show_map_name is not None:
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- lines = show_map_name.split("\n")
- for i, line in enumerate(lines):
- text_surface = font.render(line, True, WHITE)
- text_rect = text_surface.get_rect(center=(SCREEN_WIDTH // 2 + 220, 80 + i * 15))
- screen.blit(text_surface, text_rect)
- # 绘制滚动条或下一页按钮
- if total_pages > 1:
- scroll_button_width, scroll_button_height = 80, 120
- scroll_button_margin = 10
- next_button_rect = pygame.Rect(360, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
- prev_button_rect = pygame.Rect(40, SCREEN_HEIGHT - custom_map_button_height*7 - scroll_button_margin, scroll_button_width, scroll_button_height)
- if next_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
- if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
- 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)])
- 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)])
- pygame.display.flip()
- return custom_map_buttons, total_pages, next_button_rect, prev_button_rect
- # 更新屏幕显示
- pygame.display.flip()
- return custom_map_buttons, total_pages, None, None
- difficulty_button_width, difficulty_button_height = 280, 70
- difficulty_button_margin = 10
- def draw_custom_difficulty(author, map):
- global map_info_box_rect, map_info_text, difficulty_buttons
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - difficulty_button_height, difficulty_button_width, difficulty_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("返回"+show_author_name(author)+"改图", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 获取所有难度
- difficulty = next(item[map]['selections'] for item in map_selection_data[author] if map in item)
- # 计算可以显示的难度数量
- max_difficulty = (SCREEN_HEIGHT - 2 * difficulty_button_height) // (difficulty_button_height + difficulty_button_margin)
- # 计算总页数
- total_pages = (len(difficulty) + max_difficulty - 1) // max_difficulty
- # 绘制改图作者按钮
- x, y = SCREEN_WIDTH // 2 - difficulty_button_width // 2, 50
- difficulty_buttons = [] # 存储改图作者按钮的位置和对应作者名
- for diff in difficulty[(current_page - 1) * max_difficulty : min(len(difficulty),(current_page * max_difficulty))]:
- map_button_rect = pygame.Rect(x, y, difficulty_button_width, difficulty_button_height)
- if map_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, map_button_rect)
- pygame.draw.rect(screen, PAPER, map_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- text = font.render(diff['difficulty'], True, WHITE)
- text_rect = text.get_rect(center=map_button_rect.center)
- screen.blit(text, text_rect)
- difficulty_buttons.append((map_button_rect, diff))
- y += difficulty_button_height + difficulty_button_margin
- # 绘制滚动条或下一页按钮
- if total_pages > 1:
- scroll_button_width, scroll_button_height = 80, 120
- scroll_button_margin = 10
- 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)
- 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)
- if next_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
- if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
- 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)])
- 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)])
- pygame.display.flip()
- return difficulty_buttons, total_pages, next_button_rect, prev_button_rect
- # 更新屏幕显示
- pygame.display.flip()
- return difficulty_buttons, total_pages, None, None
- def draw_custom_apps():
- global map_info_box_rect, map_info_text, app_buttons
- # 清空屏幕
- screen.fill(PAPER)
- # 绘制"返回"按钮
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - difficulty_button_height, 200, difficulty_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- pygame.draw.rect(screen, PAPER, return_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- text = font.render("返回", True, WHITE)
- text_rect = text.get_rect(center=return_button_rect.center)
- screen.blit(text, text_rect)
- # 获取所有难度
- difficulty = list(app_name.keys())
- # 计算可以显示的难度数量
- max_difficulty = (SCREEN_HEIGHT - 2 * difficulty_button_height) // (difficulty_button_height + difficulty_button_margin)
- # 计算总页数
- total_pages = (len(difficulty) + max_difficulty - 1) // max_difficulty
- # 绘制按钮
- x, y = SCREEN_WIDTH // 2 - difficulty_button_width // 2, 50
- app_buttons = [] # 存储改图作者按钮的位置和对应作者名
- for diff in difficulty[(current_page - 1) * max_difficulty : min(len(difficulty),(current_page * max_difficulty))]:
- map_button_rect = pygame.Rect(x, y, difficulty_button_width, difficulty_button_height)
- if map_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, map_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, map_button_rect)
- pygame.draw.rect(screen, PAPER, map_button_rect, 3)
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- text = font.render(app_name[diff], True, WHITE)
- text_rect = text.get_rect(center=map_button_rect.center)
- screen.blit(text, text_rect)
- app_buttons.append((map_button_rect, diff))
- y += difficulty_button_height + difficulty_button_margin
- # 绘制滚动条或下一页按钮
- if total_pages > 1:
- scroll_button_width, scroll_button_height = 80, 120
- scroll_button_margin = 10
- 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)
- 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)
- if next_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, next_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, next_button_rect)
- if prev_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, prev_button_rect)
- else:
- pygame.draw.rect(screen, ORANGE_PINK, prev_button_rect)
- 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)])
- 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)])
- pygame.display.flip()
- return app_buttons, total_pages, next_button_rect, prev_button_rect
- # 更新屏幕显示
- pygame.display.flip()
- return app_buttons, total_pages, None, None
- def get_map_info_text(map_info):
- # 从map_info字典中提取地图信息
- # 这里假设map_info字典中包含地图信息的字段
- return "难度:" + stars_string(map_selection_data["0Official"][0][map_info]["difficulty"]) + "\n\n" + map_selection_data["0Official"][0][map_info]["info"]
- def get_custom_map_info_text(author, map):
- # 从map_info字典中提取地图信息
- # 这里假设map_info字典中包含地图信息的字段
- for i, m in enumerate(map_selection_data[author]):
- if map == next(iter(m.keys())):
- return map_selection_data[author][i][map]['info']
- # 新增变量用于保存信息框矩形
- map_info_box_rect = None
- custom_map_info_box_rect = None
- # 绘制信息文本框的函数
- def draw_map_info_box():
- global map_info_box_rect
- if map_info_box_rect is not None:
- # 绘制带颜色的矩形背景
- pygame.draw.rect(screen, BROWN, map_info_box_rect)
- pygame.draw.rect(screen, PAPER, map_info_box_rect, 3)
- # 绘制信息文本
- font = pygame.font.Font("res/font/simsun.ttc", 18)
- lines = map_info_text.split("\n")
- for i, line in enumerate(lines):
- text = font.render(line, True, WHITE)
- text_rect = text.get_rect(x=map_info_box_rect.x + 10, y=map_info_box_rect.y + 10 + i * 20)
- screen.blit(text, text_rect)
- # 在绘制函数之外添加一个字典用于保存勾选框的状态
- checkbox_states = {
- "full_screen": cfg_json["full_screen"],
- "low_config_mode": cfg_json["low_config_mode"],
- "display_stat": cfg_json["display_stat"],
- "monster_records": cfg_json["monster_records"],
- "v_sync": cfg_json["v_sync"],
- "show_time": cfg_json["show_time"],
- "drop_item": cfg_json["drop_item"]
- }
- # 增加一个变量来表示下拉菜单是否处于显示状态
- dropdown_menu_active = False
- drop_hero_choices = False
- drop_colour_choices = False
- music_slider_x = 0
- sound_slider_x = 0
- music_dragging = False
- sound_dragging = False
- music_slider_rect = pygame.Rect(0, 0, 0, 0)
- sound_slider_rect = pygame.Rect(0, 0, 0, 0)
- def show_hero_name(hero):
- if hero == "Maomao": return "毛毛"
- if hero == "Asha": return "阿莎"
- if hero == "Monkey": return "小悟空"
- if hero == "Titan": return "泰坦"
- if hero == "Fox": return "小倩"
- if hero == "FoxPlus": return "小倩(很多道具)"
- if hero == "Maria": return "玛丽亚"
- if hero == "CaiBaozi": return "菜包子(幻制)"
- if hero == "Xiami": return "小虾米(悠制)"
- if hero == "Chunli": return "春丽(悠制)"
- if hero == "Boboli": return "波波丽(悠制)"
- if hero == "XingZai": return "星仔(悠制)"
- if hero == "SeaPrince": return "海王子(光影制)"
- if hero == "SeaPrince_old": return "海王子(旧)(悠制)"
- if hero == "Naruto": return "火影(光影制)"
- if hero == "Naruto_old": return "火影(旧)(悠制)"
- if hero == "Cola": return "可乐(悠制)"
- if hero == "Nezha": return "哪吒(悠制)"
- if hero == "Chris": return "克莉丝(悠制)"
- if hero == "mxfc": return "梦小繁(残冰制)"
- if hero == "Flandre": return "芙兰朵露(雨制)"
- if hero == "Remilia": return "蕾米莉亚(雨制)"
- if hero == "DeepseekBlueWhale": return "蓝色大肥鱼(DeepSeek)"
- if hero == "Red": return "红色"
- if hero == "Blue": return "蓝色"
- if hero == "Yellow": return "黄色"
- if hero == "Green": return "绿色"
- if hero == "Pink": return "粉色"
- if hero == "Orange": return "橙色"
- if hero == "Purple": return "紫色"
- if hero == "Black": return "黑色"
- if hero == "SkyBlue": return "蓝灰色"
- if hero == "SakuraPink": return "香芋紫"
- if hero == "ForestGreen": return "森绿色"
- if hero == "GrassGreen": return "若草色"
- if hero == "Withered":
- return "枯叶色"
- else:
- return hero
- def draw_slider(setting_value, slider_x, setting_y):
- slider_width = 150
- slider_height = 10
- slider_rect = pygame.Rect(slider_x, setting_y, slider_width, slider_height)
- # Draw the slider track
- pygame.draw.rect(screen, LIGHT_GRAY, slider_rect, border_radius=5)
- # Calculate the position of the slider button based on the setting value
- slider_button_width = 15
- slider_button_x = slider_x + int((slider_width - slider_button_width) * setting_value)
- slider_button_rect = pygame.Rect(slider_button_x, setting_y - 5, slider_button_width, slider_height + 10)
- # Draw the slider button
- pygame.draw.rect(screen, BLACK, slider_button_rect, border_radius=5)
- return slider_button_rect
- # 设置界面代码
- def draw_game_settings():
- 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
- screen.fill(PAPER)
- # 加载自定义字体文件
- font = pygame.font.Font("res/font/simsun.ttc", 24)
- # 标题
- title_text = "游戏设置"
- title_surface = font.render(title_text, True, BLACK)
- title_rect = title_surface.get_rect(center=(SCREEN_WIDTH // 2, 50))
- screen.blit(title_surface, title_rect)
- # 绘制返回按钮
- return_button_text = "返回主菜单"
- return_button_width, return_button_height = 160, 50
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, return_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, return_button_rect)
- # pygame.draw.rect(screen, BROWN, return_button_rect)
- return_text_surface = font.render(return_button_text, True, WHITE)
- return_text_rect = return_text_surface.get_rect(center=return_button_rect.center)
- screen.blit(return_text_surface, return_text_rect)
- # 绘制保存设置按钮
- save_button_text = "保存设置"
- save_button_width, save_button_height = 150, 50
- save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width, SCREEN_HEIGHT - 50 - save_button_height,
- save_button_width, save_button_height)
- if save_button_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, DARK_BROWN, save_button_rect)
- else:
- pygame.draw.rect(screen, BROWN, save_button_rect)
- # pygame.draw.rect(screen, BROWN, save_button_rect)
- save_text_surface = font.render(save_button_text, True, WHITE)
- save_text_rect = save_text_surface.get_rect(center=save_button_rect.center)
- screen.blit(save_text_surface, save_text_rect)
- # 绘制设置项
- setting_margin = 50
- setting_y = 120
- setting_height = 30
- # 设置项的名称和取值范围
- settings = [
- {"name": "your_hero", "label": "角色:",
- "choices": [
- "Maomao", "Asha", "Monkey", "Titan", "Fox", "FoxPlus", "Maria", "CaiBaozi", "Xiami", "Chunli", "Boboli",
- "XingZai", "SeaPrince_old", "Naruto_old", "Cola", "SeaPrince", "Naruto", "Nezha", "Chris",
- "mxfc", "Flandre", "Remilia", "DeepseekBlueWhale"
- ]},
- {"name": "your_character_color", "label": "角色颜色:",
- "choices": [
- "Red", "Blue", "Yellow", "Green", "Pink", "Orange", "Purple", "Black", "SkyBlue", "SakuraPink",
- "ForestGreen", "GrassGreen", "Withered"
- ]},
- {"name": "music_volume", "label": "音乐音量:", "min_value": 0, "max_value": 1},
- {"name": "sound_volume", "label": "音效音量:", "min_value": 0, "max_value": 1},
- {"name": "full_screen", "label": "全屏模式(有颜色表示ON/空白表示OFF):", "type": "checkbox"},
- {"name": "low_config_mode", "label": "低配模式(推荐打开):", "type": "checkbox"},
- {"name": "display_stat", "label": "显示数据(推荐打开):", "type": "checkbox"},
- {"name": "monster_records", "label": "怪物统计(只有玩家死亡和通关时会保存记录):", "type": "checkbox"},
- {"name": "v_sync", "label": "垂直同步(除低配机外推荐打开):", "type": "checkbox"},
- {"name": "show_time", "label": "显示时间特效(电脑不卡就开):", "type": "checkbox"},
- {"name": "drop_item", "label": "炸砖掉道具(电脑不卡可选择开):", "type": "checkbox"}
- ]
- # 绘制每个设置项
- for setting in settings:
- setting_name = setting["name"]
- setting_label = setting["label"]
- setting_value = cfg_json[setting_name]
- # 绘制标签
- label_surface = font.render(setting_label, True, BLACK)
- label_rect = label_surface.get_rect(topleft=(setting_margin, setting_y))
- screen.blit(label_surface, label_rect)
- # 绘制输入框或下拉列表或勾选框
- if setting["name"] == "music_volume":
- music_slider_x = SCREEN_WIDTH - setting_margin - 150
- music_slider_rect = draw_slider(setting_value, music_slider_x, setting_y)
- if setting["name"] == "sound_volume":
- sound_slider_x = SCREEN_WIDTH - setting_margin - 150
- sound_slider_rect = draw_slider(setting_value, sound_slider_x, setting_y)
- if "choices" in setting:
- choices = setting["choices"]
- dropdown_width = 150
- dropdown_height = 30
- dropdown_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - dropdown_width, setting_y, dropdown_width,
- dropdown_height)
- pygame.draw.rect(screen, PAPER, dropdown_rect, border_radius=5)
- pygame.draw.rect(screen, BLACK, dropdown_rect, 2)
- # 绘制当前值
- value_surface = font.render(show_hero_name(setting_value), True, BLACK)
- value_rect = value_surface.get_rect(center=dropdown_rect.center)
- screen.blit(value_surface, value_rect)
- # 绘制下拉箭头
- arrow_surface = font.render("▼", True, BLACK)
- arrow_rect = arrow_surface.get_rect(midright=(dropdown_rect.right - 5, dropdown_rect.centery))
- screen.blit(arrow_surface, arrow_rect)
- # 处理下拉按钮点击事件
- if dropdown_rect.collidepoint(pygame.mouse.get_pos()):
- if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
- # dropdown_menu_active = not dropdown_menu_active
- if setting["name"] == "your_hero":
- if drop_colour_choices:
- dropdown_menu_active = True
- drop_colour_choices = False
- else:
- dropdown_menu_active = not dropdown_menu_active
- drop_hero_choices = not drop_hero_choices
- if setting["name"] == "your_character_color":
- if drop_hero_choices:
- dropdown_menu_active = True
- drop_hero_choices = False
- else:
- dropdown_menu_active = not dropdown_menu_active
- drop_colour_choices = not drop_colour_choices
- is_click_setting = True
- elif setting.get("type") == "checkbox":
- checkbox_size = 25
- checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
- checkbox_size)
- pygame.draw.rect(screen, WHITE, checkbox_rect, border_radius=5)
- pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
- # 修改勾选状态的绘制
- if checkbox_states[setting_name]:
- checkbox_rect = pygame.Rect(SCREEN_WIDTH - setting_margin - checkbox_size, setting_y, checkbox_size,
- checkbox_size)
- pygame.draw.rect(screen, BLACK, checkbox_rect, 2)
- # 绘制实心正方形,使其与勾选框大小相同且在其中居中
- pygame.draw.rect(screen, BROWN, checkbox_rect) # 绘制实心正方形
- # 处理勾选框的点击事件
- if checkbox_rect.collidepoint(pygame.mouse.get_pos()):
- if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
- settings_changed = True
- is_click_setting = True
- checkbox_states[setting_name] = not checkbox_states[setting_name]
- cfg_json[setting_name] = not cfg_json[setting_name]
- setting_y += setting_height + 10
- # 在绘制下拉选项的循环之外定义一个变量来追踪选中的选项
- selected_choice = None
- # 绘制下拉选项(只有在下拉菜单处于显示状态时才进行绘制)
- if dropdown_menu_active:
- for setting in settings:
- if "choices" in setting:
- if (setting["name"] == "your_hero" and drop_hero_choices) or (setting["name"] == "your_character_color" and drop_colour_choices):
- choices = setting["choices"]
- dropdown_width = 180
- dropdown_height = 30
- num_per_col = 10
- dropdown_menu_height = len(choices) * dropdown_height + 10
- if setting["name"] == "your_hero":
- setting_y = 110
- if setting["name"] == "your_character_color":
- setting_y = 150
- dropdown_menu_y = setting_y + dropdown_height
- for i in range(len(choices)):
- choice_rect = pygame.Rect(
- SCREEN_WIDTH - setting_margin - (2 + i//num_per_col) * dropdown_width - 2 * (i//num_per_col) + 20,
- dropdown_menu_y + (i % num_per_col - 1) * dropdown_height + 10,
- dropdown_width,
- dropdown_height
- )
- # Change the color of the option when the mouse hovers over it
- if choice_rect.collidepoint(pygame.mouse.get_pos()):
- pygame.draw.rect(screen, LIGHT_GRAY, choice_rect, border_radius=5)
- else:
- pygame.draw.rect(screen, LAVENDER_BLUE, choice_rect, border_radius=5)
- pygame.draw.rect(screen, BLACK, choice_rect, 2)
- # 绘制选项文本
- choice_text = font.render(show_hero_name(choices[i]), True, BLACK)
- choice_text_rect = choice_text.get_rect(center=choice_rect.center)
- screen.blit(choice_text, choice_text_rect)
- # 处理选项列表的点击事件
- if choice_rect.collidepoint(pygame.mouse.get_pos()):
- if pygame.mouse.get_pressed()[0] and not is_click_setting: # Left mouse button clicked
- # 更新选中的选项
- selected_choice = choices[i]
- is_click_setting = True
- break
- if selected_choice is not None:
- cfg_json[setting["name"]] = selected_choice
- dropdown_menu_active = False
- drop_hero_choices = False
- drop_colour_choices = False
- settings_changed = True
- break
- # 更新屏幕显示
- pygame.display.flip()
- # 主菜单循环
- def main_menu_loop():
- 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, \
- 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
- current_screen = "main_menu"
- running = True
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- running = False
- if event.type == pygame.MOUSEMOTION and mouse_left_button_down and not mouse_left_button_up and current_screen == "game_settings":
- setting_margin = 50
- if music_dragging:
- # Update the music volume setting based on the slider position
- # print(event.pos[0], SCREEN_WIDTH - setting_margin - 150)
- music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
- SCREEN_WIDTH - setting_margin - 150) / 15) * 15
- setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
- SCREEN_WIDTH - setting_margin - 150) - (
- SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
- cfg_json["music_volume"] = max(0.0, min(1.0, setting_value))
- settings_changed = True
- # print("music=",setting_value)
- if sound_dragging:
- # Update the sound volume setting based on the slider position
- music_slider_x = round(max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
- SCREEN_WIDTH - setting_margin - 150) / 15) * 15
- setting_value = round((max(min(event.pos[0], SCREEN_WIDTH - setting_margin),
- SCREEN_WIDTH - setting_margin - 150) - (
- SCREEN_WIDTH - setting_margin - 150)) / 150, 1)
- cfg_json["sound_volume"] = max(0.0, min(1.0, setting_value))
- settings_changed = True
- # print("sound=",setting_value)
- if event.type == pygame.MOUSEMOTION and current_screen == "original_maps_submenu":
- for button_rect, map_info in map_buttons:
- if button_rect.collidepoint(event.pos):
- map_info_text = get_map_info_text(map_info) # 获取信息文本
- # print("collode button", map_info, map_info_text)
- if leave_map_info:
- show_map_info = True
- leave_map_info = False
- show_map_name = map_info_text
- # 如果鼠标不在按钮上方,则隐藏信息框
- if not any(button_rect.collidepoint(event.pos) for button_rect, _ in map_buttons):
- if show_map_info:
- # print("hide")
- map_info_box_rect = None
- map_info_text = ""
- show_map_info = False
- show_map_name = None
- leave_map_info = True
- if event.type == pygame.MOUSEMOTION and current_screen == "custom_maps":
- for button_rect, map in custom_map_buttons:
- if button_rect.collidepoint(event.pos):
- map_info_text = get_custom_map_info_text(author_chosen, map) # 获取信息文本
- # print(map, map_info_text)
- if leave_map_info:
- show_map_info = True
- leave_map_info = False
- show_map_name = map_info_text
- # 如果鼠标不在按钮上方,则隐藏信息框
- if not any(button_rect.collidepoint(event.pos) for button_rect, _ in custom_map_buttons):
- if show_map_info:
- map_info_box_rect = None
- map_info_text = ""
- show_map_info = False
- show_map_name = None
- leave_map_info = True
- elif event.type == pygame.MOUSEBUTTONDOWN:
- # 更新鼠标左键按下的状态
- if event.button == 1:
- mouse_left_button_down = True
- mouse_left_button_up = False
- if music_slider_rect.collidepoint(event.pos):
- music_dragging = True
- if sound_slider_rect.collidepoint(event.pos):
- sound_dragging = True
- # print("down", mouse_left_button_down, mouse_left_button_up)
- effect_sound = "res/sound/uiLeave.wav"
- try:
- pygame.mixer.Sound(effect_sound).play()
- except Exception as e:
- print(e)
- elif event.type == pygame.MOUSEBUTTONUP:
- # 更新鼠标左键按下的状态
- if event.button == 1:
- mouse_left_button_down = False
- mouse_left_button_up = True
- is_click_setting = False
- # Stop dragging when the user releases the mouse button
- music_dragging = False
- sound_dragging = False
- # print("up", mouse_left_button_down, mouse_left_button_up)
- # 在这里处理按钮点击事件
- if current_screen == "main_menu":
- for button_text, (x, y) in buttons:
- button_rect = pygame.Rect(x, y, button_width, button_height)
- if button_rect.collidepoint(event.pos):
- try:
- pygame.mixer.music.stop()
- except Exception as e:
- print(e)
- print(button_text, "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")")
- if button_text == "直接开始(当前关卡:" + show_official_map_name(cfg_json["map_set"]) + ")":
- # 处理直接开始按钮点击事件
- print("ready_launch")
- if launcher_process is None:
- launch_game()
- elif button_text == "选择关卡":
- # 处理选择关卡按钮点击事件
- current_screen = "map_selection_menu"
- draw_map_selection_menu()
- # elif button_text == "游戏设置":
- # 处理游戏设置按钮点击事件
- # current_screen = "game_settings"
- # draw_game_settings()
- elif button_text == "关于作者":
- # 处理作者信息按钮点击事件
- current_screen = "author_info"
- draw_author_info()
- for button_text, (x, y) in buttons2:
- button_rect = pygame.Rect(x, y, 180, 100)
- if button_rect.collidepoint(event.pos):
- if button_text == "成就记录":
- # 处理直接开始按钮点击事件
- if achievement_process is None:
- achievement()
- elif button_text == "游戏设置":
- # 处理游戏设置按钮点击事件
- current_screen = "game_settings"
- draw_game_settings()
- elif button_text == "操作帮助":
- # 处理作者信息按钮点击事件
- current_screen = "helper_info"
- draw_helper_info()
- elif current_screen == "author_info":
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "main_menu"
- draw_menu()
- elif current_screen == "helper_info":
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "main_menu"
- draw_menu()
- elif current_screen == "game_settings":
- # 在游戏设置界面点击返回按钮
- return_button_width, return_button_height = 160, 50
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "main_menu"
- draw_menu()
- # 处理保存设置按钮点击事件
- save_button_width, save_button_height = 150, 50
- save_button_rect = pygame.Rect(SCREEN_WIDTH - 50 - save_button_width,
- SCREEN_HEIGHT - 50 - save_button_height, save_button_width,
- save_button_height)
- if save_button_rect.collidepoint(event.pos) and settings_changed:
- # 保存设置到config.json文件中
- try:
- with open("config.json", "w", encoding="utf-8") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- except:
- with open("config.json", "w", encoding="utf-8_sig") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- # 重置设置改变的标记
- settings_changed = False
- # 返回主菜单
- current_screen = "main_menu"
- draw_menu()
- elif current_screen == "map_selection_menu":
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 300, 60
- return_button_rect = pygame.Rect(250, SCREEN_HEIGHT - 150 - return_button_height,
- return_button_width, return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "main_menu"
- draw_menu()
- original_maps_button_rect = pygame.Rect(250, 150, return_button_width, return_button_height)
- if original_maps_button_rect.collidepoint(event.pos):
- current_screen = "original_maps_submenu"
- draw_original_maps_submenu()
- custom_maps_button_rect = pygame.Rect(250, 150 + map_button_height + map_button_margin, return_button_width, return_button_height)
- if custom_maps_button_rect.collidepoint(event.pos):
- current_screen = "custom_maps_submenu"
- current_page = 1
- draw_custom_maps_submenu()
- custom_apps_button_rect = pygame.Rect(250, 150 + 2*map_button_height + 2*map_button_margin, return_button_width, return_button_height)
- if custom_apps_button_rect.collidepoint(event.pos):
- current_screen = "apps"
- current_page = 1
- draw_custom_apps()
- elif current_screen == "original_maps_submenu":
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "map_selection_menu"
- draw_map_selection_menu()
- # 绘制信息文本框
- draw_map_info_box()
- for button_rect, map_info in map_buttons:
- if button_rect.collidepoint(event.pos):
- handle_map_selection_click(map_info)
- try:
- with open("config.json", "w", encoding="utf-8") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- except:
- with open("config.json", "w", encoding="utf-8_sig") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- 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)),]
- current_screen = "main_menu"
- draw_menu()
- break
- elif current_screen == "custom_maps_submenu":
- custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_screen = "map_selection_menu"
- draw_map_selection_menu()
- break
- # 检查是否点击了改图作者按钮
- # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
- for author_button_rect, author in custom_map_buttons:
- if author_button_rect.collidepoint(event.pos):
- total_pages = 1
- show_map_name = None
- author_chosen = author
- draw_custom_maps(author_chosen)
- current_screen = "custom_maps"
- current_page = 1
- break
- # return # 退出改图子菜单循环
- # 检查是否点击了下一页按钮
- if total_pages > 1 and next_button_rect.collidepoint(event.pos):
- current_page = (current_page % total_pages) + 1
- # print(current_page)
- draw_custom_maps_submenu() # 重新绘制改图子菜单以显示下一页
- # 检查是否点击了上一页按钮
- if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
- current_page = (current_page - 2 + total_pages) % total_pages + 1
- # print(current_page)
- draw_custom_maps_submenu() # 重新绘制改图子菜单以显示上一页
- elif current_screen == "custom_maps":
- custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 60
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- current_page = 1
- current_screen = "custom_maps_submenu"
- draw_custom_maps_submenu()
- break
- # 检查是否点击了改图作者按钮
- # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
- for map_button_rect, map in custom_map_buttons:
- if map_button_rect.collidepoint(event.pos):
- current_page = 1
- current_screen = "difficulties"
- map_chosen = map
- draw_custom_difficulty(author_chosen, map_chosen)
- break
- # current_screen = "custom_maps"
- # draw_custom_maps(author) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!下一步写这个函数以打开每个改图作者的子界面
- # return # 退出改图子菜单循环
- # 检查是否点击了下一页按钮
- if total_pages > 1 and next_button_rect.collidepoint(event.pos):
- current_page = (current_page % total_pages) + 1
- # print(current_page)
- draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示下一页
- # 检查是否点击了上一页按钮
- if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
- current_page = (current_page - 2 + total_pages) % total_pages + 1
- # print(current_page)
- draw_custom_maps(author_chosen) # 重新绘制改图子菜单以显示上一页
- elif current_screen == "difficulties":
- difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 280, 70
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- current_page = 1
- current_screen = "custom_maps"
- # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- draw_custom_maps(author_chosen)
- # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- break
- # 检查是否点击了改图作者按钮
- # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
- for map_button_rect, diff in difficulty_buttons:
- if map_button_rect.collidepoint(event.pos):
- handle_map_selection_click(diff['map_name'])
- try:
- with open("config.json", "w", encoding="utf-8") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- except:
- with open("config.json", "w", encoding="utf-8_sig") as f:
- json.dump(cfg_json, f, indent=4, ensure_ascii=False)
- 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))]
- current_screen = "main_menu"
- draw_menu()
- break
- # 检查是否点击了下一页按钮
- if total_pages > 1 and next_button_rect.collidepoint(event.pos):
- current_page = (current_page % total_pages) + 1
- # print(current_page)
- draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示下一页
- # 检查是否点击了上一页按钮
- if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
- current_page = (current_page - 2 + total_pages) % total_pages + 1
- # print(current_page)
- draw_custom_difficulty(author_chosen, map_chosen) # 重新绘制改图子菜单以显示上一页
- elif current_screen == "apps":
- app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
- # 在作者信息界面点击返回按钮
- return_button_width, return_button_height = 200, 70
- return_button_rect = pygame.Rect(50, SCREEN_HEIGHT - 50 - return_button_height, return_button_width,
- return_button_height)
- if return_button_rect.collidepoint(event.pos):
- # print("碰撞返回按钮"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- current_page = 1
- current_screen = "map_selection_menu"
- # print("切屏幕名"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- draw_map_selection_menu()
- launcher_process = None
- app_process = None
- try:
- with open("config.json", encoding="utf-8") as f:
- cfg_json = json.load(f)
- except:
- with open("config.json", encoding="utf-8_sig") as f:
- cfg_json = json.load(f)
- 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))]
- # print("显示新屏幕"+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
- break
- # 检查是否点击了改图作者按钮
- # custom_authors[(current_page - 1) * max_custom_authors : min(len(custom_authors),(current_page * max_custom_authors))]
- for map_button_rect, diff in app_buttons:
- if map_button_rect.collidepoint(event.pos):
- random_map_type = diff
- launch_app(diff)
- break
- # 检查是否点击了下一页按钮
- if total_pages > 1 and next_button_rect.collidepoint(event.pos):
- current_page = (current_page % total_pages) + 1
- draw_custom_apps()
- # 检查是否点击了上一页按钮
- if total_pages > 1 and prev_button_rect.collidepoint(event.pos):
- current_page = (current_page - 2 + total_pages) % total_pages + 1
- draw_custom_apps()
- if current_screen == "main_menu":
- # 绘制主菜单界面
- draw_menu()
- elif current_screen == "game_settings":
- # 绘制游戏设置界面
- draw_game_settings()
- elif current_screen == "author_info":
- # 绘制作者信息界面
- draw_author_info()
- elif current_screen == "map_selection_menu":
- # 处理选图菜单
- draw_map_selection_menu()
- elif current_screen == "original_maps_submenu":
- # 处理原图子菜单
- draw_original_maps_submenu()
- elif current_screen == "custom_maps_submenu":
- # 处理改图子菜单
- custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps_submenu()
- draw_custom_maps_submenu()
- elif current_screen == "custom_maps":
- # 处理具体作者改图
- custom_map_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_maps(author_chosen)
- draw_custom_maps(author_chosen)
- elif current_screen == "difficulties":
- # 处理具体改图具体难度
- difficulty_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_difficulty(author_chosen, map_chosen)
- draw_custom_difficulty(author_chosen, map_chosen)
- elif current_screen == "apps":
- # 处理具体改图具体难度
- app_buttons, total_pages, next_button_rect, prev_button_rect = draw_custom_apps()
- draw_custom_apps()
- # 更新屏幕显示
- pygame.display.flip()
- pygame.quit()
- # 地图选择循环
- def map_selection_loop(map_selection, selected_author):
- running = True
- selected_map = None
- while running:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- running = False
- elif event.type == pygame.MOUSEBUTTONDOWN:
- # 检查是否点击了任意一个地图按钮
- for button_rect, map_info in map_buttons:
- if button_rect.collidepoint(event.pos):
- handle_map_selection_click(map_info)
- return # 返回到上一个界面(主菜单或原图子菜单)
- # draw_map_selection(map_selection, selected_author, selected_map)
- pygame.display.flip()
- pygame.quit()
- if __name__ == "__main__":
- # 读取地图选择数据
- map_selection_data = read_map_selection()
- # 运行主菜单循环
- # 定义按钮的外观
- button_width, button_height = 600, 100
- button_margin = 20
- # 定义按钮的文本和位置
- 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) * 2)),
- ("关于作者", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 3)),
- ]
- buttons2 = [
- ("游戏设置", (SCREEN_WIDTH // 2 - button_width // 2, 100 + (button_height + button_margin) * 2)),
- ("成就记录", (SCREEN_WIDTH // 2 - button_width // 2 + 210, 100 + (button_height + button_margin) * 2)),
- ("操作帮助", (SCREEN_WIDTH // 2 - button_width // 2 + 210 * 2, 100 + (button_height + button_margin) * 2))
- ]
- main_menu_loop()
|