|
|
@@ -20,6 +20,8 @@ from game.algo import utils as util
|
|
|
from game.algo import rougeGen as RG
|
|
|
from game.const import window as W, color as C, game as G
|
|
|
from game.const import rouge as R
|
|
|
+from game.music import music_loader
|
|
|
+from game.sound import sound_player
|
|
|
|
|
|
|
|
|
current_folder_path = os.getcwd()
|
|
|
@@ -50,11 +52,11 @@ def check_rouge_ob_data(data):
|
|
|
|
|
|
|
|
|
class PygameButton:
|
|
|
- def __init__(self, screen, text, relx, rely, font_size, bg_color, fg_color=(255,255,255), action=None, anchor='center'):
|
|
|
+ def __init__(self, screen, text, relx, rely, font_size, bg_color, fg_color=(0,0,0), action=None, anchor='center', is_bold=False):
|
|
|
self.screen = screen
|
|
|
self.text = text
|
|
|
self.lines = text.split('\n')
|
|
|
- self.font = pygame.font.SysFont("Microsoft YaHei", font_size)
|
|
|
+ self.font = pygame.font.SysFont("Microsoft YaHei", font_size, bold=is_bold)
|
|
|
self.bg_color_normal = pygame.Color(bg_color)
|
|
|
# 计算 hover 颜色:加深 20%
|
|
|
h = self.bg_color_normal
|
|
|
@@ -105,8 +107,10 @@ class PygameButton:
|
|
|
if event.type == pygame.MOUSEMOTION:
|
|
|
self.hovered = self.bg_rect.collidepoint(event.pos)
|
|
|
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
|
|
- if self.hovered and self.action:
|
|
|
- self.action()
|
|
|
+ if self.hovered:
|
|
|
+ if self.action:
|
|
|
+ self.action()
|
|
|
+ sound_player.play("uiLeave")
|
|
|
|
|
|
|
|
|
class Menu:
|
|
|
@@ -335,35 +339,39 @@ class Menu:
|
|
|
# 主界面按钮
|
|
|
self.buttons.clear()
|
|
|
# "进入游戏"
|
|
|
- text = f"进入游戏 \n (当前难度: {R.difficulty}; 当前英雄: {R.cursor_skin})"
|
|
|
- self.buttons.append(PygameButton(self.screen, text, 0.5, 0.29, 20, "#C68E17", action=self._start_game))
|
|
|
+ text = f"进入游戏 \n (当前难度: {self.diff_dic[R.difficulty]}; 当前英雄: {self.hero_dic[R.rouge_hero]})"
|
|
|
+ self.buttons.append(PygameButton(self.screen, text, 0.5, 0.29, 20, "#C68E17", action=self._start_game, is_bold=True))
|
|
|
# "继续游戏"
|
|
|
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, "#C68E17", action=lambda: self._continue_game(last)))
|
|
|
+ self.buttons.append(PygameButton(self.screen, text_c, 0.5, 0.44, 18, "#C68E17", action=lambda: self._continue_game(last), is_bold=True))
|
|
|
# 任务系统
|
|
|
- self.buttons.append(PygameButton(self.screen, "任务系统", 0.16, 0.16, 24, "#C68E17", action=self._open_task))
|
|
|
+ self.buttons.append(PygameButton(self.screen, "任务系统", 0.16, 0.16, 24, "#C68E17", action=self._open_task, is_bold=True))
|
|
|
# 陈列馆
|
|
|
- self.buttons.append(PygameButton(self.screen, "陈列馆", 0.16, 0.28, 18, "#C68E17", action=self._open_setting))
|
|
|
+ self.buttons.append(PygameButton(self.screen, "陈列馆", 0.16, 0.28, 18, "#C68E17", action=self._open_setting, is_bold=True))
|
|
|
# 难度选择
|
|
|
for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]:
|
|
|
enabled = R.pass_status.get(diff, 0) > 0
|
|
|
- text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)"
|
|
|
- color = "#C47451" if enabled else "#614051"
|
|
|
+ if diff == "Easy":
|
|
|
+ text = f"● 选择{self.diff_dic[diff]}难度"
|
|
|
+ color = "#C47451"
|
|
|
+ else:
|
|
|
+ text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)"
|
|
|
+ color = "#C47451" if enabled else "#614051"
|
|
|
action = lambda d=diff: self._choose_diff(d) if enabled else None
|
|
|
- self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 12, color, action=action))
|
|
|
+ self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=False))
|
|
|
# ================================= 英雄选择 =================================
|
|
|
heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
|
|
|
x_position = 0.07
|
|
|
y_positions = [0.64, 0.70, 0.76, 0.82, 0.88, 0.49]
|
|
|
for hero, y in zip(heroes, y_positions):
|
|
|
text = f"● 选择{self.hero_dic[hero]}"
|
|
|
- self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#C47451", action=lambda h=hero: self._choose_hero(h), anchor="topleft"))
|
|
|
+ self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#C47451", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True))
|
|
|
# 随机开局
|
|
|
- self.buttons.append(PygameButton(self.screen, "● 随机开局", x_position, 0.94, 12, "#C47451", action=lambda: self._choose_hero("Random"), anchor="topleft"))
|
|
|
+ self.buttons.append(PygameButton(self.screen, "● 随机开局", x_position, 0.94, 12, "#C47451", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True))
|
|
|
# 英雄信息提示
|
|
|
infos = [getattr(self, attr) for attr in ['Fox_info','Boboli_info','Naruto_old_info','Asha_info','Maria_info']]
|
|
|
for info, y in zip(infos, y_positions):
|
|
|
@@ -402,7 +410,7 @@ class Menu:
|
|
|
def _choose_hero(self, hero):
|
|
|
if hero == "Random":
|
|
|
hero = random.choice(["Fox","Boboli","Naruto_old","Asha","Maria","Surprise"])
|
|
|
- R.cursor_skin = hero
|
|
|
+ R.rouge_hero = hero
|
|
|
self._create_buttons()
|
|
|
|
|
|
def run(self):
|
|
|
@@ -414,11 +422,15 @@ class Menu:
|
|
|
sys.exit()
|
|
|
for btn in self.buttons:
|
|
|
btn.handle_event(event)
|
|
|
+ if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
|
|
|
+ # 看看有没有按钮自己处理了这次点击
|
|
|
+ if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
|
|
|
+ sound_player.play("uiFail")
|
|
|
self.screen.fill((30,30,30))
|
|
|
for btn in self.buttons:
|
|
|
btn.draw()
|
|
|
pygame.display.flip()
|
|
|
- clock.tick(30)
|
|
|
+ clock.tick(60)
|
|
|
|
|
|
# 读取上次存档
|
|
|
def button_continue(self, last_data, last_path):
|
|
|
@@ -520,11 +532,14 @@ class Launcher:
|
|
|
self.screen = pygame.display.set_mode(W.WINDOW_SIZE)
|
|
|
pygame.display.set_caption(W.WINDOW_CAPTION)
|
|
|
self.cfg_json = {}
|
|
|
- self.display_flags = None
|
|
|
+ self.music_volume = 1
|
|
|
+ self.display_flags = 0
|
|
|
self.init_config()
|
|
|
+ self.init_window()
|
|
|
# 预加载资源
|
|
|
- self.preload_resources()
|
|
|
+ # self.preload_resources()
|
|
|
# 启动菜单
|
|
|
+ music_loader.play("M10.ogg", self.music_volume)
|
|
|
self.menu = Menu(self.screen)
|
|
|
self.menu.run()
|
|
|
|
|
|
@@ -535,6 +550,7 @@ class Launcher:
|
|
|
except json.JSONDecodeError:
|
|
|
with open("config.json", encoding="utf-8_sig") as f:
|
|
|
self.cfg_json = json.load(f)
|
|
|
+ self.music_volume = self.cfg_json["music_volume"]
|
|
|
if not self.cfg_json["frame_screen"]:
|
|
|
self.display_flags = pygame.NOFRAME
|
|
|
if self.cfg_json["full_screen"]:
|