Forráskód Böngészése

增加毛玻璃UI,初始化任务界面切换

detopoi 1 éve
szülő
commit
7855e7a426
6 módosított fájl, 261 hozzáadás és 44 törlés
  1. 1 0
      game/const/window.py
  2. 1 1
      game/sprite/hero.py
  3. 1 0
      game/ui/game/dlg_pveFunc.py
  4. 100 27
      game/ui/menu/component.py
  5. 126 0
      game/ui/menu/task_menu.py
  6. 32 16
      launcher.py

+ 1 - 0
game/const/window.py

@@ -11,4 +11,5 @@ WINDOW_SIZE = WINDOW_W, WINDOW_H = (800, 600)
 WINDOW_CAPTION = f"QQTRogue{G.VERSION}(引擎:永恒; 肉鸽作者:100の雨女; 唯一官方群689297964免费下载; 擅自售卖皆属剽窃!)"
 WINDOW_SCROLL_PADDING = 200
 
+MENU = None
 PAGE = Page.HOME

+ 1 - 1
game/sprite/hero.py

@@ -185,7 +185,7 @@ class Hero(Player):
 
         # 开发者模式
         if R.debug_mode:
-            self.blood = R.current_standard_HP = self.remain_blood = 100000000
+            # 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(10000, R.current_standard_damage)

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

@@ -72,6 +72,7 @@ class ExitBtn(pygame.sprite.Sprite):
             # app_task = tk.Tk()
             # roguetest.App(app_task)
             W.PAGE = W.Page.HOME
+            W.MENU.refresh()
             music_loader.play("rogue_menu.mp3", 0.7)
             # pygame.event.post(pygame.event.Event(pygame.QUIT))
             return True

+ 100 - 27
game/ui/menu/component.py

@@ -1,27 +1,50 @@
 import pygame
 import random
 
-from game.sound import sound_player
-
 
 class PygameButton:
     """
     文字渲染按钮
     """
-    def __init__(self, screen, text, relx, rely, font_size, bg_color, fg_color=(0,0,0), action=None, anchor='center', is_bold=True, fix_shape=None, bg_alpha=255):
+    def __init__(
+            self, screen, text, relx, rely, font_size, bg_color,
+            fg_color=(0,0,0), action=None, anchor='center', is_bold=True, fix_shape=None, bg_alpha=255,
+            frosted_glass=False, blur_radius=4, glass_alpha=120, frame_radius=8, glass_surf_color=(255,255,255), background=None):
         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%
+        # self.font = pygame.font.Font(r"res\font\SourceHanSerifCN-Bold.otf", font_size)
+        # 毛玻璃相关参数
+        self.frosted_glass = frosted_glass
+        self.blur_radius = blur_radius
+        self.glass_alpha = glass_alpha
+        self.frame_radius = frame_radius
+        self.background = background
+        self.glass_surf_color = glass_surf_color
 
-        # h = self.bg_color_normal
-        # self.bg_color_hover = pygame.Color(max(0, int(h.r*0.8)), max(0, int(h.g*0.8)), max(0, int(h.b*0.8)))
+        # 普通模式颜色设置
+        self._init_normal_colors(bg_color, bg_alpha)
 
+        self.fg_color = fg_color
+        self.action = action
+        self.relx = relx
+        self.rely = rely
+        self.fix_shape = fix_shape
+        self.anchor = anchor  # 'center', 'topleft'
+        self.hovered = False
+        self._render()
+        # 毛玻璃特效所需Surface
+        if self.frosted_glass:
+            self._init_frosted_glass()
+
+    def _init_normal_colors(self, bg_color, bg_alpha):
+        """初始化普通模式的背景颜色"""
+        self.bg_color_normal = pygame.Color(bg_color)
         self.bg_color_normal.a = bg_alpha
+
+        # 悬停颜色计算
         h = self.bg_color_normal
         hover_rgb = (
             max(0, int(h.r * 0.8)),
@@ -31,14 +54,40 @@ class PygameButton:
         self.bg_color_hover = pygame.Color(*hover_rgb)
         self.bg_color_hover.a = bg_alpha
 
-        self.fg_color = fg_color
-        self.action = action
-        self.relx = relx
-        self.rely = rely
-        self.fix_shape = fix_shape
-        self.anchor = anchor  # 'center', 'topleft'
-        self.hovered = False
-        self._render()
+    def _init_frosted_glass(self):
+        """初始化毛玻璃特效所需资源"""
+        # 创建模糊用的临时surface
+        self.blur_surface = pygame.Surface(
+            (self.bg_rect.width//self.blur_radius,
+             self.bg_rect.height//self.blur_radius),
+            pygame.SRCALPHA
+        )
+        self.overlay_surf = pygame.Surface(
+            (self.bg_rect.width, self.bg_rect.height),
+            pygame.SRCALPHA
+        )
+        # self.overlay_surf.fill((255, 255, 255, self.glass_alpha))
+        self.overlay_surf.fill((*self.glass_surf_color, self.glass_alpha))
+
+    def _create_blurred_background(self, background):
+        """创建模糊背景(毛玻璃特效核心)"""
+        if not self.frosted_glass:
+            return
+        # 截取背景区域
+        try:
+            sub = background.subsurface(self.bg_rect)
+        except ValueError:
+            return
+        # 快速缩放模糊算法
+        scaled = pygame.transform.scale(
+            sub,
+            (self.bg_rect.w//self.blur_radius,
+             self.bg_rect.h//self.blur_radius)
+        )
+        self.blur_surface = pygame.transform.smoothscale(
+            scaled,
+            (self.bg_rect.w, self.bg_rect.h)
+        )
 
     def _render(self):
         # 渲染多行文本
@@ -69,22 +118,48 @@ class PygameButton:
             line_x = self.bg_rect.x + (self.bg_rect.width - surf.get_width())//2 if self.anchor=='center' else self.bg_rect.x + 10
             self.text_positions.append((line_x, offset_y))
             offset_y += surf.get_height() + 5
+        if self.frosted_glass:
+            self._init_frosted_glass()
 
     def draw(self):
-        # 绘制背景
-        # color = self.bg_color_hover if self.hovered else self.bg_color_normal
-        # pygame.draw.rect(self.screen, color, self.bg_rect)
+        """新增background参数用于毛玻璃特效"""
+        if self.frosted_glass and self.background is not None:
+            # 毛玻璃模式
+            self._draw_frosted_glass(self.background.bg_image)
+        else:
+            # 普通模式
+            self._draw_normal()
+        # 绘制文本(通用)
+        for surf, pos in zip(self.text_surfs, self.text_positions):
+            self.screen.blit(surf, pos)
 
+    def _draw_normal(self):
+        """普通按钮绘制"""
         color = self.bg_color_hover if self.hovered else self.bg_color_normal
         bg_surf = pygame.Surface(
             (self.bg_rect.width, self.bg_rect.height),
-            pygame.SRCALPHA  # 允许 per-pixel alpha
+            pygame.SRCALPHA
         )
-        bg_surf.fill(color)       # color 中已包含 a 通道
+        bg_surf.fill(color)
         self.screen.blit(bg_surf, self.bg_rect.topleft)
-        # 绘制文本
-        for surf, pos in zip(self.text_surfs, self.text_positions):
-            self.screen.blit(surf, pos)
+
+    def _draw_frosted_glass(self, background):
+        """毛玻璃特效绘制"""
+        # 生成模糊背景
+        self._create_blurred_background(background)
+        # 绘制模糊层
+        if not (self.hovered and self.action is not None):
+            self.screen.blit(self.blur_surface, self.bg_rect.topleft)
+            # 添加白色半透覆盖层
+            self.screen.blit(self.overlay_surf, self.bg_rect.topleft)
+        # 绘制边框
+        pygame.draw.rect(
+            self.screen,
+            (63, 63, 63, 31),
+            self.bg_rect,
+            1,
+            border_radius=self.frame_radius
+        )
 
     def handle_event(self, event):
         if event.type == pygame.MOUSEMOTION:
@@ -93,7 +168,6 @@ class PygameButton:
             if self.hovered:
                 if self.action:
                     self.action()
-                sound_player.play("uiLeave")
 
 
 class PygameButtonBackIMG:
@@ -158,7 +232,6 @@ class PygameButtonBackIMG:
                 self.hover_out_action()
         elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
             if self.hovered and self.action:
-                sound_player.play("uiLeave")
                 self.action()
 
 

+ 126 - 0
game/ui/menu/task_menu.py

@@ -0,0 +1,126 @@
+from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
+import json
+import os
+from game.const import game as G
+from game.const import window as W
+from game.const import rouge as R
+from datetime import datetime
+from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle
+
+current_folder_path = os.getcwd()
+
+
+class TaskPage:
+    def __init__(self):
+        self.screen = W.MENU
+        self.now = datetime.now()
+        self.year = "1970"
+        self.month = "1"
+        self.day = "1"
+        user_documents_folder = os.path.expanduser("~\\Documents")  # 获取用户的"文档"文件夹路径
+        qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE")  # 构建QQTPVE文件夹路径
+        os.makedirs(qqtpve_folder, exist_ok=True)  # 确保QQTPVE文件夹存在,如果不存在则创建
+        self.rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata")  # 构建任务文件路径
+        self.rougeOB_task_data = {}
+        self.init_task()
+
+    def init_task(self):
+        # 第一次打开
+        if not os.path.exists(self.rouge_task_file_path):
+            self.rougeOB_task_data = {
+                "1":  {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "2":  {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "3":  {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "4":  {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "5":  {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "6":  {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "7":  {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "8":  {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "9":  {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
+                "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1, "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}
+            }
+            save_encrypt_single_rouge_file(self.rougeOB_task_data, "rougeOB_task")
+        # 正常打开
+        else:
+            self.rougeOB_task_data = load_rouge_data(self.rouge_task_file_path)
+
+        # 格式化年月日
+        year = self.now.strftime("%Y")
+        month = self.now.strftime("%m")
+        day = self.now.strftime("%d")
+        # 移除月份和日期的前导零(如果有)
+        month = month.lstrip("0")
+        day = day.lstrip("0")
+        self.year = str(year)
+        self.month = str(month)
+        self.day = str(day)
+
+        if int(self.rougeOB_task_data[str(month)]["last_finish"]) < int(year):
+            self.rougeOB_task_data[str(month)]["process"] = 0
+            self.rougeOB_task_data[str(month)]["last_finish"] = year
+            self.rougeOB_task_data[str(month)]["rewarded"] = False
+        if self.rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day:
+            self.rougeOB_task_data["today"]["process"] = 0
+            self.rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day
+            self.rougeOB_task_data["today"]["rewarded"] = False
+        save_encrypt_single_rouge_file(self.rougeOB_task_data, "rougeOB_task")
+
+    def draw(self):
+        """
+        # ============================================= 月常任务 =============================================
+        if self.rougeOB_task_data[self.month]["process"] < self.rougeOB_task_data[self.month]["finish"]:
+            # 若还未完成
+            text = f"○月度征召\n{self.rougeOB_task_data[self.month]['task']} \n酬谢: {self.rougeOB_task_data[self.month]['reward']}\n进度: {self.rougeOB_task_data[self.month]['process']}/{self.rougeOB_task_data[self.month]['finish']}"
+            self.screen.buttons.append(
+                PygameButton(self.screen.screen, text, 0.3, 0.35, 18, "#2a2a2a",
+                             fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
+                             frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
+            )
+        else:
+            text = f"○月度征召\n{self.rougeOB_task_data[self.month]['task']} \n酬谢: {self.rougeOB_task_data[self.month]['reward']}\n\n by {R.hero_name[self.rougeOB_task_data['today']['hero']]}"
+            self.screen.buttons.append(
+                PygameButton(self.screen.screen, text, 0.3, 0.35, 18, "#2a2a2a",
+                             fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
+                             frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
+            )
+            self.screen.buttons.append(PygameButtonBackIMG(
+                self.screen, self.screen.screen, 0.3, 0.41, "res/ui/button/task_finish.png", "res/ui/button/task_finish.png", anchor='center')
+            )
+
+        # ============================================= 日常任务 =============================================
+        print(self.rougeOB_task_data["today"]["process"], self.rougeOB_task_data["today"]["finish"])
+        if self.rougeOB_task_data["today"]["process"] < self.rougeOB_task_data["today"]["finish"]:
+            # 若还未完成
+            text = f"○日常委托\n{self.rougeOB_task_data['today']['task']} \n酬谢: {self.rougeOB_task_data['today']['reward']}\n进度: {self.rougeOB_task_data['today']['process']}/{self.rougeOB_task_data['today']['finish']}"
+            self.screen.buttons.append(
+                PygameButton(self.screen.screen, text, 0.7, 0.35, 18, "#2a2a2a",
+                             fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
+                             frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
+            )
+        else:
+            text = f"○日常委托\n{self.rougeOB_task_data['today']['task']} \n酬谢: {self.rougeOB_task_data['today']['reward']}\n\n by {R.hero_name[self.rougeOB_task_data['today']['hero']]}"
+            self.screen.buttons.append(
+                PygameButton(self.screen.screen, text, 0.7, 0.35, 18, "#2a2a2a",
+                             fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
+                             frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
+            )
+            self.screen.buttons.append(PygameButtonBackIMG(
+                self.screen, self.screen.screen, 0.7, 0.41, "res/ui/button/task_finish.png", "res/ui/button/task_finish.png", anchor='center')
+            )
+        """
+        text = f"\n\n任务系统升级中.."
+        self.screen.buttons.append(
+            PygameButton(self.screen.screen, text, 0.5, 0.35, 18, "#2a2a2a",
+                         fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
+                         frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21),
+                         background=self.screen)
+        )
+
+        # 返回主界面
+        self.screen.buttons.append(PygameButtonBackIMG(
+            self.screen, self.screen.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.refresh, anchor='center')
+        )
+

+ 32 - 16
launcher.py

@@ -3,6 +3,7 @@ import json
 import os
 import win32gui
 import sys
+import time
 import logging
 import rougetask
 import rougesetting
@@ -66,6 +67,7 @@ class Menu:
             self.bg_image = pygame.transform.scale(img, screen.get_size())
         else:
             self.bg_image = None
+        W.MENU = self
         self._init_data()
         self._create_buttons()
 
@@ -321,12 +323,7 @@ class Menu:
         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(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(PygameButtonBackIMG(self, self.screen, 0.5, 0.44, "res/ui/button/continue.png", "res/ui/button/continue_press.png", action=lambda: self._continue_game(), anchor='center'))
         # 任务系统
         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'))
         # 陈列馆
@@ -382,6 +379,10 @@ class Menu:
         record = getattr(self, 'record_text', "暂无挑战记录")
         self.buttons.append(PygameButton(self.screen, record, 0.5, 0.56, 14, "#7E354D", fg_color=(255, 255, 255), bg_alpha=191))
 
+    def refresh(self):
+        """ 外部接口 """
+        self._create_buttons()
+
     # 各个按钮动作方法
     def _start_game(self):
         rougeGen.main_func()
@@ -391,7 +392,23 @@ class Menu:
         )
         game.update()
 
-    def _continue_game(self, last):
+    def _continue_game(self):
+        self.buttons.clear()
+        last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
+        modification_time = os.path.getmtime(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
+        readable_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modification_time))
+        lvl = ((last["current_level"] + 4) // 2 - 1) // 5 + 1
+        stage = ((last["current_level"] + 4) // 2 - 1) % 5 + 1
+        text_c = f"\n继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})\n{readable_time}"
+        self.buttons.append(
+            PygameButton(self.screen, text_c, 0.5, 0.4, 18, "#2a2a2a",
+                         fg_color=(215,220,217), action=lambda: self._continue_to_start(last),
+                         anchor="center", is_bold=True, fix_shape=(240,160), bg_alpha=159,
+                         frosted_glass=True, blur_radius=8, glass_alpha=8, background=self)
+        )
+        self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self._create_buttons, anchor='center'))
+
+    def _continue_to_start(self, last):
         self.read_continue_data(last)
         game = rogue_control.Control(
             screen=self.screen,
@@ -400,14 +417,11 @@ class Menu:
         game.update()
 
     def _open_task(self):
-        try:
-            from rougetask import task
-            print("启动 Task...")
-            t = threading.Thread(target=task, daemon=True)
-            t.start()
-        except Exception as e:
-            print("启动 Task 时出错:", e)
-        # Task(pygame.display.set_mode((800, 600)))
+        self.buttons.clear()
+        from game.ui.menu.task_menu import TaskPage
+        page = TaskPage()
+        page.draw()
+        del page
 
     def _open_setting(self):
         try:
@@ -449,7 +463,7 @@ class Menu:
         clock = pygame.time.Clock()
         spawn_timer = 0
         while True:
-            dt = clock.tick(60)
+            dt = clock.tick(120)
             spawn_timer += dt
             # ================================= 处理鼠标事件 =====================================
             for event in pygame.event.get():
@@ -462,6 +476,8 @@ class Menu:
                     # 看看有没有按钮自己处理了这次点击
                     if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
                         sound_player.play("uiFail")
+                    else:
+                        sound_player.play("uiLeave")
             # ===================================================================================
             # 随机生成新粒子: 每200ms生成一个
             if spawn_timer > 200: