瀏覽代碼

(250629) 寻路算法回退; 技能火球自定义修复

detopoi 1 年之前
父節點
當前提交
b480697a68

+ 8 - 92
client_local/algo/aStar.py

@@ -1,5 +1,3 @@
-import heapq
-from collections import defaultdict
 from queue import PriorityQueue
 from client_local.level import level
 
@@ -24,14 +22,6 @@ def bomb_exist(x, y):
     return len(level.current_level.get_bomb_instance(x, y)) > 0
 
 
-def can_reach(x, y):
-    # 检查当前位置的右、上、左、下是否可达
-    return not r_block(x, y) and not bomb_exist(x + 1, y), \
-           not u_block(x, y) and not bomb_exist(x, y - 1), \
-           not l_block(x, y) and not bomb_exist(x - 1, y), \
-           not d_block(x, y) and not bomb_exist(x, y + 1)
-
-
 def can_reach_r(x, y):
     return not r_block(x, y) and not bomb_exist(x + 1, y)
 
@@ -48,43 +38,8 @@ def can_reach_d(x, y):
     return not d_block(x, y) and not bomb_exist(x, y + 1)
 
 
-def neighbors(current, npc_grid, limit1, limit2, is_ghost):
-    points = []
-    x, y = current  # 当前坐标
-    x1, y1 = limit1  # 区域左上角坐标
-    x2, y2 = limit2  # 区域右下角坐标
-
-    # 优化为通用的可达判断
-    can_r, can_u, can_l, can_d = can_reach(x, y)
-
-    if is_ghost:
-        return [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
-
-    # 使用缓存的can_reach结果来减少重复的检查
-    if heuristic(current, npc_grid) == 1 and bomb_exist(*npc_grid):
-        if can_r and x + 1 <= x2:
-            points.append((x + 1, y))
-        if can_u and y - 1 >= y1:
-            points.append((x, y - 1))
-        if can_l and x - 1 >= x1:
-            points.append((x - 1, y))
-        if can_d and y + 1 <= y2:
-            points.append((x, y + 1))
-    else:
-        if can_r and x + 1 <= x2:
-            points.append((x + 1, y))
-        if can_u and y - 1 >= y1:
-            points.append((x, y - 1))
-        if can_l and x - 1 >= x1:
-            points.append((x - 1, y))
-        if can_d and y + 1 <= y2:
-            points.append((x, y + 1))
-
-    return points
-
-
 # PVE优先级:下>左>上>右
-def neighbors_old(current, npc_grid, limit1, limit2, is_ghost):
+def neighbors(current, npc_grid, limit1, limit2, is_ghost):
     # 计算四个邻位是否可达
     points = []
     x, y = current  # 当前坐标
@@ -130,33 +85,7 @@ def reverse(came_from, hero_grid, npc_grid):
     return go_to
 
 
-def cal_path_new(npc_grid, hero_grid, limit1, limit2, is_ghost=False):
-    frontier = []
-    heapq.heappush(frontier, (0, npc_grid))  # 用heapq的heappush替代PriorityQueue的put
-    came_from = defaultdict(lambda: None)  # 用defaultdict来简化came_from的访问
-    cost_so_far = defaultdict(lambda: float('inf'))  # 初始化cost_so_far的默认值为无限大
-    came_from[npc_grid] = None
-    cost_so_far[npc_grid] = 0
-
-    while frontier:
-        current_cost, current = heapq.heappop(frontier)  # 用heapq的heappop替代PriorityQueue的get
-        if current == hero_grid:
-            break
-
-        for _next in neighbors(current, npc_grid, limit1, limit2, is_ghost):
-            new_cost = current_cost + 1
-            if new_cost < cost_so_far[_next]:
-                cost_so_far[_next] = new_cost
-                priority = new_cost + heuristic(_next, hero_grid)
-                heapq.heappush(frontier, (priority, _next))  # 用heapq的heappush来更新队列
-                came_from[_next] = current
-
-    return reverse(came_from, hero_grid, npc_grid)
-
-
-def cal_path(npc_grid, hero_grid, limit1, limit2, is_ghost=False, path_cache=None):
-    if path_cache is None:
-        path_cache = dict()  # 初始化缓存表,若未传入则创建一个新的缓存表
+def cal_path(npc_grid, hero_grid, limit1, limit2, is_ghost=False):
     # limit1 区域左上角
     # limit2 区域右下角
     frontier = PriorityQueue()
@@ -167,28 +96,15 @@ def cal_path(npc_grid, hero_grid, limit1, limit2, is_ghost=False, path_cache=Non
     cost_so_far[npc_grid] = 0
 
     while not frontier.empty():
-
         current = frontier.get()[1]
-
         if current == hero_grid:
             break
-
-        for _next in neighbors(current, npc_grid, limit1, limit2, is_ghost):
+        for next in neighbors(current, npc_grid, limit1, limit2, is_ghost):
             new_cost = cost_so_far[current] + 1
-            if _next not in cost_so_far or new_cost < cost_so_far[_next]:
-                cost_so_far[_next] = new_cost
-                priority = new_cost + heuristic(_next, hero_grid)
-                frontier.put((priority, _next))
-                came_from[_next] = current
-                if _next in path_cache.keys():  # 如果已经缓存了路径,直接拼接缓存路径
-                    cached_path = path_cache[_next]
-                    if cached_path:
-                        combined_path = reverse(came_from, _next, npc_grid)
-                        combined_path.update(cached_path)
-                        if not combined_path:
-                            return dict()
-                        return combined_path
-                    else:
-                        return dict()
+            if next not in cost_so_far or new_cost < cost_so_far[next]:
+                cost_so_far[next] = new_cost
+                priority = new_cost + heuristic(next, hero_grid)
+                frontier.put((priority, next))
+                came_from[next] = current
 
     return reverse(came_from, hero_grid, npc_grid)

+ 2 - 3
client_local/level/level.py

@@ -33,6 +33,7 @@ from datetime import datetime
 
 
 current_level = None
+level_font = pygame.font.Font("res/font/simsun.ttc", 16)
 
 max_alpha = 255  # 最大透明度
 circleMasks = {}
@@ -125,7 +126,7 @@ class Level:
         current_level = self
         self.times_num = 0  # 秒计数器,每秒累加
         self.frames_num = 0  # 帧计数器,每秒清空
-        self.frame_rate_text_font = pygame.font.Font("res/font/simsun.ttc", 16)
+        self.frame_rate_text_font = level_font
         self.me = me
         self.pets = []
         self.your_name = your_name
@@ -616,8 +617,6 @@ class Level:
                 self.npcs.remove(n)
             else:
                 n.update()
-        if self.recal_npc_paths:
-            self.path_map.clear()
         self.recal_npc_paths = False
 
         # 刷新宠物

+ 1 - 7
client_local/skill/parametric2_skill.py

@@ -709,7 +709,7 @@ class CustomGroupDirectionLaserFireBall(Skill):
             [self.damage_blood, self.angles, self.speed, self.energy] = params
             self.effect = "fire_ball_laser"
         self.path_points = []  # 新增:火苗经过的所有点
-        self.end_time = 8000/(max(0.01,self.speed/0.16))
+        self.end_time = 8000/(max(0.01, self.speed/0.16))
 
     def update(self):
         super().update()
@@ -1818,7 +1818,6 @@ class CustomLightTrap(Skill):
                 self.to_already_on = False
 
 
-
 # 自定义范围内治疗敌方  "params": {"radius": 3, "heal_amount": 3000}
 class CustomLightRangeRecovery(Skill):
 
@@ -1858,8 +1857,6 @@ class CustomLightRangeRecovery(Skill):
             return
 
 
-
-
 # 自定义移动到玩家最近的实体  "params": {"target": "npc_name"}
 class CustomMoveToTarget(Skill):
 
@@ -1902,9 +1899,6 @@ class CustomMoveToTarget(Skill):
             return
 
 
-
-
-
 # 自定义光盾  "params": {"break_times": 1, "recover_time": 1000}
 class CustomLightShield(Skill):
 

+ 3 - 3
client_local/skill/parametric_skill.py

@@ -1835,7 +1835,7 @@ class CustomDirectionLaserFireBall(Skill):
             [self.damage_blood, self.angle, self.speed, self.energy] = params
             self.effect = "fire_ball_laser"
         self.path_points = []  # 新增:火苗经过的所有点
-        self.end_time = 8000/(max(0.01,self.speed/0.16))
+        self.end_time = 8000/(max(0.01, self.speed/0.16))
 
     def update(self):
         super().update()
@@ -1881,9 +1881,9 @@ class CustomDirectionLaserFireBall(Skill):
             self.delta_y = 4 * round(sin(self.angle * pi / 180), 3)
             self.delta_len = sqrt(self.delta_x * self.delta_x + self.delta_y * self.delta_y)
             if self.delta_x > 0:
-                self.effect_fire = EffectInstance("fire_ball_laser", self.user, False, level.current_level.effects_front)
+                self.effect_fire = EffectInstance(self.effect, self.user, False, level.current_level.effects_front)
             else:
-                self.effect_fire = EffectInstance("fire_ball_laser", self.user, False, level.current_level.effects_front)
+                self.effect_fire = EffectInstance(self.effect, self.user, False, level.current_level.effects_front)
             self.effect_instances.append(self.effect_fire)
 
         if self.current_time - self.skill_time_init > 1000 and self.knife_charge:

+ 6 - 12
client_local/sprite/npc.py

@@ -302,18 +302,12 @@ class Npc(Player, Throwable):
         path_map = level.current_level.path_map
         # 如果重新计算路径标志为True则重新追踪玩家
         if level.current_level.recal_npc_paths:
-            if now not in path_map.keys():
-                self.chase_path = aStar.cal_path(
-                    now, me,
-                    (level.current_level.district_square_grid["x1"], level.current_level.district_square_grid["y1"]),
-                    (level.current_level.district_square_grid["x2"], level.current_level.district_square_grid["y2"]),
-                    is_ghost=self.is_ghost,
-                    path_cache=path_map
-                )
-                if self.chase_path != {}:
-                    path_map[now] = self.chase_path
-            else:
-                self.chase_path = path_map[now]
+            self.chase_path = aStar.cal_path(
+                now, me,
+                (level.current_level.district_square_grid["x1"], level.current_level.district_square_grid["y1"]),
+                (level.current_level.district_square_grid["x2"], level.current_level.district_square_grid["y2"]),
+                is_ghost=self.is_ghost
+            )
         if now in self.chase_path.keys():
             _next = self.chase_path[now]
             if _next is None:

+ 1 - 1
client_local/ui/game/game_top.py

@@ -7,7 +7,7 @@ class GameTop(UIInstance):
     def __init__(self):
         super().__init__("game", "gameTop")
         self.font = pygame.font.Font("res/font/simsun.ttc", 16)
-        self.rend = self.font.render("v20250622", True, (0, 196, 255))
+        self.rend = self.font.render("v20250628", True, (0, 196, 255))
 
     def draw(self, screen: pygame.Surface):
         super().draw(screen)

+ 2 - 2
menulauncher.py

@@ -3,11 +3,11 @@ import os
 import subprocess
 
 current_folder_path = os.getcwd()
-app_name = current_folder_path + "\游戏文件\测试主菜单.exe"
+app_name = f"{current_folder_path}\游戏文件\测试主菜单.exe"
 
 try:
     # 改变当前工作目录
-    os.chdir(current_folder_path+"\游戏文件")
+    os.chdir(f"{current_folder_path}\游戏文件")
     # 替换为launcher.exe的路径
     launcher_path = app_name
     # 启动launcher.exe

+ 1837 - 0
test_menu.py

@@ -0,0 +1,1837 @@
+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()