| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837 |
- 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 == "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"
- ]},
- {"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()
|