launcher.py 36 KB

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