Ver Fonte

UI优化+返回主菜单键

detopoi há 1 ano atrás
pai
commit
e45c085e7b

+ 2 - 2
game/const/rouge.py

@@ -3,8 +3,8 @@ from game.const import game as G
 import json
 import os
 
-# debug_mode = True
-debug_mode = False
+debug_mode = True
+# debug_mode = False
 test_mode = False
 # print_mode = True
 print_mode = False

+ 9 - 0
game/const/window.py

@@ -1,5 +1,14 @@
+from enum import Enum, auto
 from game.const import game as G
 
+
+class Page(Enum):
+    HOME = auto()  # 主菜单
+    GAME = auto()  # 游戏中
+
+
 WINDOW_SIZE = WINDOW_W, WINDOW_H = (800, 600)
 WINDOW_CAPTION = f"QQTRogue{G.VERSION}(引擎:永恒; 肉鸽作者:100の雨女; 唯一官方群689297964免费下载; 擅自售卖皆属剽窃!)"
 WINDOW_SCROLL_PADDING = 200
+
+PAGE = Page.HOME

+ 4 - 1
game/level/level.py

@@ -573,7 +573,10 @@ class Level:
             if not self.refresh_district:
                 self.refresh_district = True
                 self.finished_district.append(self.current_district)
-                self.unfinished_district.remove(self.current_district)
+                try:
+                    self.unfinished_district.remove(self.current_district)
+                except Exception as e:
+                    print(f"level.py self.unfinished_district.remove: {e}")
 
                 if G.CURRENT_LEVEL%2 == 1:
                     current_battle_cell = S.sub_cell_map_reverse((int(self.current_district["square"]["x1"]-20)/40,int(self.current_district["square"]["y1"]-20)/40))

+ 2 - 2
game/rogue_control.py

@@ -113,6 +113,7 @@ class Control:
         self.wall_walking = True
 
         # 初始化pygame
+        W.PAGE = W.Page.GAME
         self.init_game()
         # self.preload()
         self.proceed_game()
@@ -318,8 +319,7 @@ class Control:
     def update(self):
         last_time = [time.time()]
         start = time.time()
-        running = True
-        while running:
+        while W.PAGE == W.Page.GAME:
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     pygame.display.quit()

+ 1 - 1
game/sprite/hero.py

@@ -188,7 +188,7 @@ class Hero(Player):
             self.blood = R.current_standard_HP = self.remain_blood = 100000000
             self.speed = R.current_standard_speed = 0.4
             self.bomb = R.current_standard_bomb = max(7, R.current_standard_bomb)
-            self.damage = R.current_standard_damage = max(5000, R.current_standard_damage)
+            self.damage = R.current_standard_damage = max(10000, R.current_standard_damage)
             # self.power = 20
             self.wall_walking = True
             R.show_cursor = True

+ 5 - 1
game/ui/game/dlg_pveFunc.py

@@ -1,7 +1,9 @@
 from game.ui.ui import UIInstance
 import pygame
 from game.file_loader.fileLoader import load_png
+from game.music import music_loader
 import game.const.game as G
+import game.const.window as W
 
 
 class DlgPveFunc(UIInstance):
@@ -69,7 +71,9 @@ class ExitBtn(pygame.sprite.Sprite):
             self.mouseUp = False    # 退出游戏
             # app_task = tk.Tk()
             # roguetest.App(app_task)
-            pygame.event.post(pygame.event.Event(pygame.QUIT))
+            W.PAGE = W.Page.HOME
+            music_loader.play("rogue_menu.mp3", 0.7)
+            # pygame.event.post(pygame.event.Event(pygame.QUIT))
             return True
         return False
 

+ 3 - 1
game/ui/game/message_input.py

@@ -11,7 +11,9 @@ pygame.display.set_caption("Chat Optimization Demo")
 clock = pygame.time.Clock()
 
 # Preload font once
-FONT_PATH = G.GAME_PATH + r"\res\font\simsun.ttc"
+# FONT_PATH = G.GAME_PATH + r"\res\font\simsun.ttc"
+FONT_PATH = G.GAME_PATH + r"\res\font\SourceHanSerifCN-Bold.otf"
+# FONT_PATH = G.GAME_PATH + r"\res\font\SourceHanSerif-VF.ttc"
 _font = freetype.Font(FONT_PATH, 14)
 _font_small = freetype.Font(FONT_PATH, 12)
 

+ 74 - 5
game/ui/menu/component.py

@@ -12,7 +12,9 @@ class PygameButton:
         self.screen = screen
         self.text = text
         self.lines = text.split('\n')
-        self.font = pygame.font.SysFont("Microsoft JhengHei", font_size, bold=is_bold)
+        # self.font = pygame.font.SysFont("Microsoft JhengHei", font_size, bold=is_bold)
+        # self.font = pygame.font.Font(r"res\font\SourceHanSerif-VF.ttc", font_size)
+        self.font = pygame.font.Font(r"res\font\SourceHanSerifCN-Bold.otf", font_size)
         self.bg_color_normal = pygame.Color(bg_color)
         # # 计算 hover 颜色:加深 20%
 
@@ -100,24 +102,30 @@ class PygameButtonBackIMG:
     - default_img_path: 默认状态下的背景图路径
     - hover_img_path: 悬停状态下的背景图路径
     """
-    def __init__(self, screen, relx, rely,
+    def __init__(self, menu, screen, relx, rely,
                  default_img_path, hover_img_path,
-                 action=None, anchor='center'):
+                 action=None, hover_in_action=None, hover_out_action=None,
+                 anchor='center'):
+        self.menu = menu
         self.screen = screen
         # 加载按钮图片
         self.default_img = pygame.image.load(default_img_path).convert_alpha()
         self.hover_img = pygame.image.load(hover_img_path).convert_alpha()
         self.action = action
+        self.hover_in_action = hover_in_action
+        self.hover_out_action = hover_out_action
         self.relx = relx
         self.rely = rely
         self.anchor = anchor  # 'center' 或 'topleft'
         self.hovered = False
         # 按钮尺寸使用图片原始尺寸
         self.width, self.height = self.default_img.get_size()
+        self.spawn_timer = 0
         # 计算按钮位置
         sw, sh = self.screen.get_size()
         x = int(sw * self.relx)
         y = int(sh * self.rely)
+        self.x, self.y = x, y
         if self.anchor == 'center':
             topleft = (x - self.width//2, y - self.height//2)
         else:
@@ -125,13 +133,29 @@ class PygameButtonBackIMG:
         self.bg_rect = pygame.Rect(topleft[0], topleft[1], self.width, self.height)
 
     def draw(self):
-        # 根据悬停状态绘制对应图片
+        # (实时刷新) 根据悬停状态绘制对应图片
         img = self.hover_img if self.hovered else self.default_img
         self.screen.blit(img, self.bg_rect.topleft)
+        if self.hovered:
+            self.spawn_timer += 1
+            if self.spawn_timer >= 10:
+                self.spawn_timer = 0
+                for _ in range(10):
+                    self.menu.particles.append(ButtonParticle(self.x, self.y))
 
     def handle_event(self, event):
         if event.type == pygame.MOUSEMOTION:
-            self.hovered = self.bg_rect.collidepoint(event.pos)
+            # 先记录上一次的悬停状态
+            was_hovered = self.hovered
+            # 更新当前悬停状态
+            now_hovered = self.bg_rect.collidepoint(event.pos)
+            self.hovered = now_hovered
+            # 鼠标刚进入区域
+            if not was_hovered and now_hovered and self.hover_in_action:
+                self.hover_in_action()
+            # 鼠标刚离开区域
+            elif was_hovered and not now_hovered and self.hover_out_action:
+                self.hover_out_action()
         elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
             if self.hovered and self.action:
                 sound_player.play("uiLeave")
@@ -177,3 +201,48 @@ class Particle:
 
     def is_alive(self):
         return self.life > 0 and self.alpha > 0
+
+
+class ButtonParticle:
+    def __init__(self, x, y):
+        self.x = x
+        self.y = y
+        self.radius = random.randint(1, 3)
+        # self.color = (200, 200, 200)
+        # self.color = (170, 188, 157)
+        self.color = (244, 213, 97)
+        # 垂直速度
+        self.speed_y = random.uniform(-5, 5)
+        # 水平速度,模拟风吹
+        self.speed_x = random.uniform(-10, 10)
+        # 透明度和生命周期
+        self.alpha = 255
+        self.fix_life = 30
+        self.life = random.randint(10, 20)  # 寿命更长
+        self.surface = pygame.Surface((self.radius*2, self.radius*2), pygame.SRCALPHA)
+
+    def update(self):
+        # 更新位置
+        self.y -= self.speed_y
+        self.x += self.speed_x
+        self.speed_y *= 0.9
+        self.speed_x *= 0.9
+        # 减缓透明度下降速度
+        self.fix_life -= 1
+        if self.fix_life < 0:
+            self.life -= 1
+        self.alpha = max(0, int(191 * min(1., self.life / 30)))
+        # 重绘粒子
+        self.surface.fill((0,0,0,0))
+        pygame.draw.circle(
+            self.surface,
+            (self.color[0], self.color[1], self.color[2], self.alpha),
+            (self.radius, self.radius),
+            self.radius
+        )
+
+    def draw(self, screen):
+        screen.blit(self.surface, (self.x - self.radius, self.y - self.radius))
+
+    def is_alive(self):
+        return self.life > 0 and self.alpha > 0

+ 8 - 4
launcher.py

@@ -318,18 +318,19 @@ class Menu:
         self.buttons.clear()
         # "进入游戏"
         # self.buttons.append(PygameButton(self.screen, "进入游戏", 0.5, 0.29, 32, "#e1bd48", action=self._start_game, is_bold=True))
-        self.buttons.append(PygameButtonBackIMG(self.screen, 0.5, 0.3, "res/ui/game/start_button_0.png", "res/ui/game/start_button_1.png", action=self._start_game, anchor='center'))
+        self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.5, 0.3, "res/ui/button/start.png", "res/ui/button/start_press.png", action=self._start_game, anchor='center'))
         # "继续游戏"
         if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
             last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
             lvl = ((last["current_level"] + 2) // 2 - 1) // 5 + 1
             stage = ((last["current_level"] + 2) // 2 - 1) % 5 + 1
             text_c = f"继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})"
-            self.buttons.append(PygameButton(self.screen, text_c, 0.5, 0.44, 18, "#e1bd48", action=lambda: self._continue_game(last), is_bold=True, bg_alpha=191))
+            self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.5, 0.44, "res/ui/button/continue.png", "res/ui/button/continue_press.png", action=lambda: self._continue_game(last), anchor='center'))
+            # self.buttons.append(PygameButton(self.screen, text_c, 0.5, 0.44, 18, "#e1bd48", action=lambda: self._continue_game(last), is_bold=True, bg_alpha=191))
         # 任务系统
-        self.buttons.append(PygameButton(self.screen, "任务系统", 0.16, 0.16, 24, "#e1bd48", action=self._open_task, is_bold=True, fix_shape=(120,30), bg_alpha=127))
+        self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.16, 0.16, "res/ui/button/task.png", "res/ui/button/task_press.png", action=self._open_task, anchor='center'))
         # 陈列馆
-        self.buttons.append(PygameButton(self.screen, "陈列馆", 0.16, 0.28, 24, "#e1bd48", action=self._open_setting, is_bold=True, fix_shape=(120,30), bg_alpha=127))
+        self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.16, 0.32, "res/ui/button/memory.png", "res/ui/button/memory_press.png", action=self._open_setting, anchor='center'))
         # 难度选择
         last_diff = {"Easy": "Easy", "Normal": "Easy", "Hell": "Normal", "Hell+": "Hell"}
         for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]:
@@ -450,6 +451,7 @@ class Menu:
         while True:
             dt = clock.tick(60)
             spawn_timer += dt
+            # ================================= 处理鼠标事件 =====================================
             for event in pygame.event.get():
                 if event.type == pygame.QUIT:
                     pygame.quit()
@@ -460,6 +462,7 @@ class Menu:
                     # 看看有没有按钮自己处理了这次点击
                     if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
                         sound_player.play("uiFail")
+            # ===================================================================================
             # 随机生成新粒子: 每200ms生成一个
             if spawn_timer > 200:
                 spawn_timer = 0
@@ -473,6 +476,7 @@ class Menu:
                 if p.is_alive():
                     new_particles.append(p)
             self.particles = new_particles
+            # ===================================== 绘制画面 ======================================
             # 绘制背景
             if self.bg_image:
                 self.screen.blit(self.bg_image, (0, 0))