launcher.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. import random
  2. import json
  3. import os
  4. import win32gui
  5. import sys
  6. import time
  7. import logging
  8. import rougetask
  9. import rougesetting
  10. import pygame
  11. import requests
  12. import threading
  13. import concurrent.futures
  14. import tkinter as tk
  15. from datetime import datetime, timedelta
  16. from game import rogue_control
  17. from game.rogue_control import Control
  18. from game.algo import rougeGen
  19. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  20. from game.algo import utils as util
  21. from game.algo import rougeGen as RG
  22. from game.const import window as W, color as C, game as G
  23. from game.const import rouge as R
  24. from game.music import music_loader
  25. from game.sound import sound_player
  26. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle
  27. from game.utils import local_data_manager as DM
  28. current_folder_path = os.getcwd()
  29. def current_lv(lv):
  30. lv_list = R.lv_list
  31. if lv >= sum(lv_list):
  32. return "--"
  33. for k in range(0, 14):
  34. if sum(lv_list[:k]) <= lv < sum(lv_list[:k + 1]):
  35. return str(sum(lv_list[:k + 1]) - lv)
  36. def check_rouge_ob_data(data):
  37. hero_data_dic = {
  38. "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1},
  39. "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}
  40. }
  41. err_cnt = 0
  42. for k, v in hero_data_dic.items():
  43. if k not in data.keys():
  44. data[k] = v
  45. err_cnt += 1
  46. print(f"缺失{k}数据, 正在补充...")
  47. if err_cnt > 0:
  48. save_encrypt_single_rouge_file(data, "rougeOB")
  49. class Menu:
  50. def __init__(self, screen, bg_image_path=None):
  51. self.screen = screen
  52. self.buttons = []
  53. self.particles = [] # 粒子列表
  54. self.current_hero = "Fox"
  55. self.current_difficulty = "Easy"
  56. self.is_random = False # 随机选择角色
  57. if bg_image_path:
  58. img = pygame.image.load(bg_image_path).convert()
  59. self.bg_image = pygame.transform.scale(img, screen.get_size())
  60. else:
  61. self.bg_image = None
  62. W.MENU = self
  63. self._init_data()
  64. self._create_buttons()
  65. def _init_data(self):
  66. with open("config.json", "r", encoding="utf-8") as json_file:
  67. mapsetdata = json.load(json_file)
  68. R.rouge_hero = mapsetdata["your_hero"]
  69. self.current_hero = mapsetdata["your_hero"]
  70. R.difficulty = mapsetdata["rogue_difficulty"]
  71. self.current_difficulty = mapsetdata["rogue_difficulty"]
  72. print(mapsetdata["rogue_difficulty"])
  73. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  74. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  75. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  76. rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径
  77. rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  78. old_file_path = os.path.join(qqtpve_folder, "rouge.json") # 构建文件路径
  79. old_achivements_file_path = os.path.join(qqtpve_folder, "rouge_achievement.json") # 构建成就文件路径
  80. rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径
  81. last_game_file_path = os.path.join(qqtpve_folder, "rougeOBLastGame.rougedata") # 构建存档文件路径
  82. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  83. # 杂项第一次打开
  84. if not os.path.exists(other_file_path):
  85. rougeOB_other_data = {"Bomb": [],
  86. "Pet": [],
  87. "Hat": [],
  88. "LastRandom": 0,
  89. "Other": []}
  90. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  91. # 正常打开
  92. else:
  93. rougeOB_other_data = load_rouge_data(other_file_path)
  94. if 'Cursor_Skin' not in rougeOB_other_data.keys():
  95. rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  96. R.cursor_skin = "fire_cursor"
  97. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  98. else:
  99. R.cursor_skin = rougeOB_other_data['Cursor_Skin']
  100. if 'Bomb_Skin' not in rougeOB_other_data.keys():
  101. rougeOB_other_data['Bomb_Skin'] = "bomb1"
  102. R.bomb_skin = "bomb1"
  103. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  104. else:
  105. R.bomb_skin = rougeOB_other_data['Bomb_Skin']
  106. # 第一次打开
  107. if not os.path.exists(rouge_task_file_path):
  108. rougeOB_task_data = {
  109. "1": {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  110. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  111. "2": {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  112. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  113. "3": {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970,
  114. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  115. "4": {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970,
  116. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  117. "5": {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  118. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  119. "6": {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  120. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  121. "7": {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  122. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  123. "8": {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  124. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  125. "9": {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  126. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  127. "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970,
  128. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  129. "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970,
  130. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  131. "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970,
  132. "reward_exp": 800, "hero": "Fox", "rewarded": True},
  133. "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1,
  134. "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}}
  135. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  136. # 正常打开
  137. else:
  138. rougeOB_task_data = load_rouge_data(rouge_task_file_path)
  139. now = datetime.now()
  140. # 格式化年月日
  141. year = now.strftime("%Y")
  142. month = now.strftime("%m")
  143. day = now.strftime("%d")
  144. # 移除月份和日期的前导零(如果有)
  145. month = month.lstrip("0")
  146. day = day.lstrip("0")
  147. R.today_datetime["year"] = int(year)
  148. R.today_datetime["month"] = int(month)
  149. R.today_datetime["day"] = int(day)
  150. try:
  151. if len(rougeOB_task_data[str(month)]["last_finish"]) > 4: # 防一手格式错误
  152. rougeOB_task_data[str(month)]["last_finish"] = rougeOB_task_data[str(month)]["last_finish"][0:4]
  153. except:
  154. pass
  155. if int(rougeOB_task_data[str(month)]["last_finish"]) < int(year):
  156. rougeOB_task_data[str(month)]["process"] = 0
  157. rougeOB_task_data[str(month)]["last_finish"] = year
  158. rougeOB_task_data[str(month)]["rewarded"] = False
  159. if rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day:
  160. rougeOB_task_data["today"]["process"] = 0
  161. rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day
  162. rougeOB_task_data["today"]["rewarded"] = False
  163. save_encrypt_single_rouge_file(rougeOB_task_data, "rougeOB_task")
  164. # 第一次打开
  165. if not os.path.exists(rouge_file_path):
  166. # 若参与过第一轮beta测试
  167. if os.path.exists(old_file_path):
  168. # 备份旧文件
  169. old_json = load_json(old_file_path)
  170. rougeOB_data = {"Fox": {"exp": old_json["Fox"]["exp"], "lv": old_json["Fox"]["lv"]},
  171. "Boboli": {"exp": old_json["Boboli"]["exp"], "lv": old_json["Boboli"]["exp"]},
  172. "Naruto_old": {"exp": 0, "lv": 1},
  173. "Asha": {"exp": old_json["Naruto_old"]["exp"], "lv": old_json["Naruto_old"]["exp"]},
  174. "Maria": {"exp": 0, "lv": 1},
  175. "Surprise": {"exp": 0, "lv": 1}}
  176. print("等级数据继承成功")
  177. else:
  178. rougeOB_data = {
  179. "Fox": {"exp": 0, "lv": 1},
  180. "Boboli": {"exp": 0, "lv": 1},
  181. "Naruto_old": {"exp": 0, "lv": 1},
  182. "Asha": {"exp": 0, "lv": 1},
  183. "Maria": {"exp": 0, "lv": 1},
  184. "Surprise": {"exp": 0, "lv": 1}
  185. }
  186. save_encrypt_single_rouge_file(rougeOB_data, "rougeOB")
  187. # 正常打开
  188. else:
  189. rougeOB_data = load_rouge_data(rouge_file_path)
  190. # =========================================================================================
  191. util.load_online_config()
  192. if G.UID == "" and G.USERNAME == "":
  193. # username = input("请输入昵称: ").strip()
  194. # password = input("请输入密码: ").strip()
  195. util.register()
  196. new_info = rougeOB_data
  197. new_info["record"] = "null"
  198. result = util.update_profile(G.UID, new_info, G.PASSWORD)
  199. print(result.get('message', '未知错误'))
  200. is_online = util.try_login()
  201. if is_online:
  202. rougeOB_data = util.get_online_data()
  203. # =========================================================================================
  204. check_rouge_ob_data(rougeOB_data)
  205. print(rougeOB_data)
  206. for hero in ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]:
  207. rougeOB_data[hero]["lv"] = R.current_lv(rougeOB_data[hero]["exp"])
  208. self.Fox_info = "小倩: 等级" + str(rougeOB_data["Fox"]["lv"]) + ", 升级还需经验:" + current_lv(
  209. rougeOB_data["Fox"]["exp"]) + "\n技能: 自身血量减少1则糖泡伤害增加" + str(R.FoxSkill(rougeOB_data["Fox"]["lv"]))
  210. self.Boboli_info = "波波丽: 等级" + str(rougeOB_data["Boboli"]["lv"]) + ", 升级还需经验:" + current_lv(
  211. rougeOB_data["Boboli"]["exp"]) + "\n技能: 每次攻击额外造成" + str(
  212. int(R.BoboliSkill(rougeOB_data["Boboli"]["lv"]) * 100)) + "%真实伤害"
  213. self.Naruto_old_info = "火影: 等级" + str(rougeOB_data["Naruto_old"]["lv"]) + ", 升级还需经验:" + current_lv(
  214. rougeOB_data["Naruto_old"]["exp"]) + "\n技能: 首次攻击每只怪物时攻击力变为" + str(
  215. int(R.Naruto_oldSkill(rougeOB_data["Naruto_old"]["lv"]) * 100)) + "%"
  216. self.Asha_info = "阿莎: 等级" + str(rougeOB_data["Asha"]["lv"]) + ", 升级还需经验:" + current_lv(
  217. rougeOB_data["Asha"]["exp"]) + "\n技能: 每次糖泡造成伤害恢复血量" + str(
  218. R.AshaSkill(rougeOB_data["Asha"]["lv"]) * 100) + "%"
  219. self.Maria_info = "玛莉亚: 等级" + str(rougeOB_data["Maria"]["lv"]) + ", 升级还需经验:" + current_lv(
  220. rougeOB_data["Maria"]["exp"]) + "\n技能: 每次造成伤害降低怪物近身" + str(
  221. R.MariaSkill(rougeOB_data["Maria"]["lv"]) * 100) + "%(最高50%)与" + str(
  222. R.MariaSkill2(rougeOB_data["Maria"]["lv"])) + "防御"
  223. DM.init_achievement()
  224. rougeOB_achievements = load_rouge_data(rouge_achivements_file_path)
  225. print(rougeOB_achievements)
  226. max_level = 0
  227. max_level_hero = "Fox"
  228. max_diff = "Easy"
  229. max_diff_num = 1
  230. self.hero_dic = {"Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚",
  231. "Surprise": "???"}
  232. self.diff_dic = {"Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  233. diff_num = {"Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  234. diff_status = {"Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  235. max_level = rougeOB_achievements["Highest"]["level"]
  236. max_level_hero = rougeOB_achievements["Highest"]["hero"]
  237. max_diff = rougeOB_achievements["Highest"]["diff"]
  238. max_diff_num = diff_num[max_diff]
  239. if max_level == 20:
  240. diff_status[max_diff] = 2
  241. if max_level > 0:
  242. self.record_text = f"最高挑战纪录: 通关<{self.diff_dic[max_diff]}{(max_level - 1) // 5 + 1}-{(max_level - 1) % 5 + 1}>; 使用英雄: {self.hero_dic[max_level_hero]}"
  243. else:
  244. self.record_text = "暂无挑战记录"
  245. if max_diff == "Hell+":
  246. R.pass_status["Easy"] = 1
  247. R.pass_status["Normal"] = 1
  248. R.pass_status["Hell"] = 1
  249. if max_level >= 15:
  250. R.pass_status["Hell+"] = 1
  251. elif max_diff == "Hell":
  252. R.pass_status["Easy"] = 1
  253. R.pass_status["Normal"] = 1
  254. # R.cursor_skin = "fire_cursor_kubi"
  255. if max_level >= 15:
  256. R.pass_status["Hell"] = 1
  257. # R.cursor_skin = "fire_cursor_gold_kubi"
  258. elif max_diff == "Normal":
  259. R.pass_status["Easy"] = 1
  260. # R.cursor_skin = "fire_cursor2"
  261. if max_level >= 15:
  262. R.pass_status["Normal"] = 1
  263. # R.cursor_skin = "fire_cursor_kubi"
  264. else:
  265. if max_level >= 15:
  266. R.pass_status["Easy"] = 1
  267. # R.cursor_skin = "fire_cursor2"
  268. for dif in ["Easy", "Normal", "Hell", "Hell+"]:
  269. if diff_status[dif] == 2:
  270. R.pass_status[dif] = 2
  271. def _create_buttons(self):
  272. # 主界面按钮
  273. self.buttons.clear()
  274. # "进入游戏"
  275. # self.buttons.append(PygameButton(self.screen, "进入游戏", 0.5, 0.29, 32, "#e1bd48", action=self._start_game, is_bold=True))
  276. 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'))
  277. # "继续游戏"
  278. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  279. 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'))
  280. # 任务系统
  281. 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'))
  282. # 陈列馆
  283. 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'))
  284. # 难度选择
  285. last_diff = {"Easy": "Easy", "Normal": "Easy", "Hell": "Normal", "Hell+": "Hell"}
  286. for diff, rel in [("Easy", 0.1), ("Normal", 0.18), ("Hell", 0.26), ("Hell+", 0.34)]:
  287. if diff == R.difficulty:
  288. text = f"★ 当前难度: {self.diff_dic[diff]}"
  289. color = "#c7a44f"
  290. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  291. else:
  292. enabled = R.pass_status.get(last_diff[diff], 0) > 0
  293. if diff == "Easy":
  294. text = f"● 选择{self.diff_dic[diff]}难度"
  295. color = "#99be7f"
  296. action = lambda d=diff: self._choose_diff(d)
  297. self.buttons.append(
  298. PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  299. else:
  300. text = f"● 选择{self.diff_dic[diff]}难度" if enabled else f"○ {self.diff_dic[diff]}难度(未解锁)"
  301. color = "#99be7f" if enabled else "#55516d"
  302. if enabled:
  303. action = lambda d=diff: self._choose_diff(d)
  304. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, action=action, anchor="topleft", is_bold=True, fix_shape=(120,15), bg_alpha=191))
  305. else:
  306. self.buttons.append(PygameButton(self.screen, text, 0.75, rel, 13, color, fg_color=(255, 255, 255), anchor="topleft", is_bold=False, fix_shape=(120,15), bg_alpha=63))
  307. # ================================= 英雄选择 =================================
  308. heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"]
  309. x_position = 0.1
  310. y_positions = [0.64, 0.70, 0.76, 0.82, 0.88, 0.49]
  311. for hero, y in zip(heroes, y_positions):
  312. if not self.is_random and hero == R.rouge_hero:
  313. text = f"★ 使用{self.hero_dic[hero]}"
  314. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#c7a44f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=191))
  315. else:
  316. text = f"● 选择{self.hero_dic[hero]}"
  317. self.buttons.append(PygameButton(self.screen, text, x_position, y, 12, "#99be7f", action=lambda h=hero: self._choose_hero(h), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  318. # 随机开局
  319. if self.is_random:
  320. self.buttons.append(PygameButton(self.screen, "★ 使用随机", x_position, 0.94, 12, "#c7a44f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  321. else:
  322. self.buttons.append(PygameButton(self.screen, "● 随机开局", x_position, 0.94, 12, "#99be7f", action=lambda: self._choose_hero("Random"), anchor="topleft", is_bold=True, fix_shape=(80,15), bg_alpha=127))
  323. # 英雄信息提示
  324. infos = [getattr(self, attr) for attr in ['Fox_info', 'Boboli_info', 'Naruto_old_info', 'Asha_info', 'Maria_info']]
  325. base_heroes = ["Fox", "Boboli", "Naruto_old", "Asha", "Maria"]
  326. if not self.is_random:
  327. for hero, info, y in zip(base_heroes, infos, y_positions):
  328. if hero == R.rouge_hero:
  329. self.buttons.append(PygameButton(self.screen, info, 0.32, y-0.03, 14, "#d7b8da", fg_color=(0, 0, 0), anchor="topleft", bg_alpha=127))
  330. # ==========================================================================
  331. # 最高记录
  332. record = getattr(self, 'record_text', "暂无挑战记录")
  333. self.buttons.append(PygameButton(self.screen, record, 0.5, 0.56, 14, "#7E354D", fg_color=(255, 255, 255), bg_alpha=191))
  334. def refresh(self):
  335. """ 外部接口 """
  336. self._create_buttons()
  337. def open_setting(self):
  338. self._open_setting()
  339. # 各个按钮动作方法
  340. def _start_game(self):
  341. rougeGen.main_func()
  342. game = Control(
  343. screen=self.screen,
  344. is_continue=False
  345. )
  346. game.update()
  347. def _continue_game(self):
  348. self.buttons.clear()
  349. last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  350. modification_time = os.path.getmtime(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  351. readable_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modification_time))
  352. lvl = ((last["current_level"] + 4) // 2 - 1) // 5 + 1
  353. stage = ((last["current_level"] + 4) // 2 - 1) % 5 + 1
  354. text_c = f"\n继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})\n{readable_time}"
  355. self.buttons.append(
  356. PygameButton(self.screen, text_c, 0.5, 0.4, 18, "#2a2a2a",
  357. fg_color=(215,220,217), action=lambda: self._continue_to_start(last),
  358. anchor="center", is_bold=True, fix_shape=(240,160), bg_alpha=159,
  359. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self)
  360. )
  361. 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'))
  362. def _continue_to_start(self, last):
  363. self.read_continue_data(last)
  364. game = rogue_control.Control(
  365. screen=self.screen,
  366. is_continue=True
  367. )
  368. game.update()
  369. def _open_task(self):
  370. self.buttons.clear()
  371. from game.ui.menu.task_menu import TaskPage
  372. page = TaskPage()
  373. page.draw()
  374. del page
  375. def _open_setting(self):
  376. self.buttons.clear()
  377. # try:
  378. # print("启动 Setting...")
  379. # from rougesetting import setting
  380. # t = threading.Thread(target=setting, daemon=True)
  381. # t.start()
  382. # except Exception as e:
  383. # print("启动 Setting 时出错:", e)
  384. from game.ui.menu.skin_menu import SkinPage
  385. page = SkinPage()
  386. page.draw()
  387. del page
  388. def _choose_diff(self, diff):
  389. R.difficulty = diff
  390. with open("config.json", "r", encoding="utf-8") as json_file:
  391. mapsetdata = json.load(json_file)
  392. mapsetdata["map_set"] = "rogueMapSet"
  393. mapsetdata["rogue_difficulty"] = diff
  394. with open("config.json", "w", encoding="utf-8") as json_file:
  395. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  396. self._create_buttons()
  397. def _choose_hero(self, hero):
  398. if hero == "Random":
  399. hero = random.choice(["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Surprise"])
  400. self.is_random = True
  401. else:
  402. self.is_random = False
  403. R.rouge_hero = hero
  404. self.current_hero = hero
  405. with open("config.json", "r", encoding="utf-8") as json_file:
  406. mapsetdata = json.load(json_file)
  407. mapsetdata["map_set"] = "rogueMapSet"
  408. mapsetdata["your_hero"] = hero
  409. with open("config.json", "w", encoding="utf-8") as json_file:
  410. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  411. self._create_buttons()
  412. def run(self):
  413. clock = pygame.time.Clock()
  414. spawn_timer = 0
  415. while True:
  416. dt = clock.tick(120)
  417. spawn_timer += dt
  418. # ================================= 处理鼠标事件 =====================================
  419. for event in pygame.event.get():
  420. if event.type == pygame.QUIT:
  421. pygame.quit()
  422. sys.exit()
  423. for btn in self.buttons:
  424. btn.handle_event(event)
  425. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  426. # 看看有没有按钮自己处理了这次点击
  427. if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
  428. sound_player.play("uiFail")
  429. else:
  430. sound_player.play("uiLeave")
  431. # ===================================================================================
  432. # 随机生成新粒子: 每200ms生成一个
  433. if spawn_timer > 200:
  434. spawn_timer = 0
  435. x = random.randint(0, self.screen.get_width())
  436. y = self.screen.get_height() + 10
  437. self.particles.append(Particle(x, y))
  438. # 更新和过滤粒子
  439. new_particles = []
  440. for p in self.particles:
  441. p.update()
  442. if p.is_alive():
  443. new_particles.append(p)
  444. self.particles = new_particles
  445. # ===================================== 绘制画面 ======================================
  446. # 绘制背景
  447. if self.bg_image:
  448. self.screen.blit(self.bg_image, (0, 0))
  449. else:
  450. self.screen.fill((60, 90, 60))
  451. # 绘制粒子
  452. for p in self.particles:
  453. p.draw(self.screen)
  454. # 绘制按钮
  455. for btn in self.buttons:
  456. btn.draw()
  457. pygame.display.flip()
  458. # 读取上次存档
  459. def read_continue_data(self, last_data):
  460. R.continuing_game = True
  461. self.current_hero = last_data["rouge_hero"]
  462. with open("config.json", "r", encoding="utf-8") as json_file:
  463. mapsetdata = json.load(json_file)
  464. mapsetdata["map_set"] = "rogueMapSet"
  465. mapsetdata["your_hero"] = last_data["rouge_hero"]
  466. with open("config.json", "w", encoding="utf-8") as json_file:
  467. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  468. # ===============================================================================
  469. G.CURRENT_LEVEL = last_data["current_level"]
  470. R.map_json_dic = last_data["map_json_dic"]
  471. R.central_mapset = last_data["central_mapset"]
  472. R.difficulty = last_data["difficulty"]
  473. R.today_datetime = last_data["today_datetime"]
  474. R.task_RougeTreasureDestinyElite = last_data["task_RougeTreasureDestinyElite"]
  475. R.task_MineCFireDragonBoss = last_data["task_MineCFireDragonBoss"]
  476. R.task_RougeTreasureDestinyWizard = last_data["task_RougeTreasureDestinyWizard"]
  477. R.task_combat = last_data["task_combat"]
  478. R.task_revival = last_data["task_revival"]
  479. R.rouge_data = last_data["rouge_data"]
  480. R.rouge_hero = last_data["rouge_hero"]
  481. R.rouge_lv = last_data["rouge_lv"]
  482. R.rouge_exp = last_data["rouge_exp"]
  483. R.game_exp = last_data["game_exp"]
  484. R.rouge_story = last_data["rouge_story"]
  485. R.rouge_theme_1 = last_data["rouge_theme_1"]
  486. R.rouge_theme_2 = last_data["rouge_theme_2"]
  487. R.rouge_theme_3 = last_data["rouge_theme_3"]
  488. R.rouge_theme_4 = last_data["rouge_theme_4"]
  489. R.rouge_destiny = last_data["rouge_destiny"]
  490. R.coin = last_data["coin"]
  491. R.general_mon_dic = last_data["general_mon_dic"]
  492. R.story_eden = last_data["story_eden"]
  493. R.story_destiny = last_data["story_destiny"]
  494. R.current_standard_HP = last_data["current_standard_HP"]
  495. R.current_standard_damage = last_data["current_standard_damage"]
  496. R.current_standard_speed = last_data["current_standard_speed"]
  497. R.current_standard_defense = last_data["current_standard_defense"]
  498. R.current_standard_bomb = last_data["current_standard_bomb"]
  499. R.se_district = last_data["se_district"]
  500. R.battle_district = last_data["battle_district"]
  501. R.monster_defense_delta = last_data["monster_defense_delta"]
  502. R.monster_HP_rate = last_data["monster_HP_rate"]
  503. R.player_bomb_self_damage_reduce_rate = last_data["player_bomb_self_damage_reduce_rate"]
  504. R.slow_immune = last_data["slow_immune"]
  505. R.reverse_immune = last_data["reverse_immune"]
  506. R.root_immune = last_data["root_immune"]
  507. R.stun_immune = last_data["stun_immune"]
  508. R.random_dmg = last_data["random_dmg"]
  509. R.show_cursor = last_data["show_cursor"]
  510. R.last_item = last_data["items"]
  511. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  512. os.remove(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  513. print("已读取,清除数据!!!!!!!!!!!!!")
  514. else:
  515. print("???")
  516. def show_prompt():
  517. """显示提示框,询问用户如何操作"""
  518. import tkinter as tk
  519. from tkinter import messagebox
  520. def close_existing():
  521. root.destroy()
  522. sys.exit()
  523. root = tk.Tk()
  524. root.withdraw() # 隐藏主窗口
  525. if messagebox.askyesno("进程已打开", "已有一个游戏进程正在运行。请关闭后再运行!"):
  526. close_existing()
  527. # 获取所有窗口句柄
  528. def get_all_windows():
  529. windows = []
  530. def enum_windows_proc(hwnd, _):
  531. if win32gui.IsWindowVisible(hwnd):
  532. window_text = win32gui.GetWindowText(hwnd)
  533. if window_text:
  534. windows.append(window_text)
  535. return True
  536. win32gui.EnumWindows(enum_windows_proc, None)
  537. return windows
  538. # 检测窗口是否存在
  539. def check_window_exists():
  540. windows = get_all_windows()
  541. # print(windows)
  542. for window in windows:
  543. if "QQTRogue" in window and "永恒" in window and "100の雨女" in window and "756422783" in window and "擅自售卖皆属剽窃" in window:
  544. return True
  545. return False
  546. class Launcher:
  547. def __init__(self):
  548. pygame.init()
  549. self.screen = pygame.display.set_mode(W.WINDOW_SIZE)
  550. pygame.display.set_caption(W.WINDOW_CAPTION)
  551. self.cfg_json = {}
  552. self.music_volume = 0.7
  553. self.display_flags = 0
  554. self.init_config()
  555. self.init_window()
  556. # 预加载资源
  557. # self.preload_resources()
  558. # 启动菜单
  559. music_loader.play("rogue_menu.mp3", self.music_volume)
  560. self.menu = Menu(self.screen, bg_image_path="res/ui/game/rogue_menu.png")
  561. self.menu.run()
  562. def init_config(self):
  563. try:
  564. with open("config.json", encoding="utf-8") as f:
  565. self.cfg_json = json.load(f)
  566. except json.JSONDecodeError:
  567. with open("config.json", encoding="utf-8_sig") as f:
  568. self.cfg_json = json.load(f)
  569. self.music_volume = self.cfg_json["music_volume"]
  570. if not self.cfg_json["frame_screen"]:
  571. self.display_flags = pygame.NOFRAME
  572. if self.cfg_json["full_screen"]:
  573. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  574. try:
  575. if self.cfg_json["v_sync"] and self.cfg_json["frame_screen"] and not self.cfg_json["full_screen"]:
  576. self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF
  577. # self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL
  578. elif self.cfg_json["v_sync"] and not self.cfg_json["frame_screen"]:
  579. self.display_flags |= pygame.HWSURFACE | pygame.DOUBLEBUF
  580. elif self.cfg_json["v_sync"] and self.cfg_json["full_screen"]:
  581. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  582. except Exception as e:
  583. print(e)
  584. def init_window(self):
  585. self.screen = pygame.display.set_mode(W.WINDOW_SIZE, flags=self.display_flags)
  586. pygame.display.set_icon(pygame.image.load("res/img/ui/icon.png").convert_alpha())
  587. for i in range(10):
  588. file_name = "itemNum_0_" + str(i) + ".png"
  589. img = pygame.image.load("res/img/ui/number/" + file_name).convert_alpha()
  590. G.NUMBER_IMG.append(img)
  591. def preload_resources(self):
  592. with concurrent.futures.ThreadPoolExecutor() as executor:
  593. executor.submit(Control.preload)
  594. if __name__ == "__main__":
  595. # # 定义日志文件路径
  596. # # log_file_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "program.log")
  597. # log_file_path = os.path.join(os.getcwd(), "program.log")
  598. # # 打开日志文件并重定向 stdout
  599. # log_file = open(log_file_path, 'a', encoding='utf-8') # 'a' 是追加模式
  600. # # 重定向 sys.stdout(print 函数输出)
  601. # sys.stdout = log_file
  602. # # 重定向 sys.stderr(报错信息)
  603. # sys.stderr = log_file
  604. print("=========== start ==============")
  605. if check_window_exists():
  606. show_prompt()
  607. Launcher()