launcher.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. import random
  2. import json
  3. import os
  4. import win32gui
  5. import sys
  6. import time
  7. import logging
  8. import pygame
  9. import requests
  10. import threading
  11. import concurrent.futures
  12. from datetime import datetime, timedelta
  13. from game import rogue_control
  14. from game.rogue_control import Control
  15. from game.algo import rougeGen
  16. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  17. from game.algo import utils as util
  18. from game.algo import rougeGen as RG
  19. from game.const import window as W, color as C, game as G
  20. from game.const import rouge as R
  21. from game.const.rouge import current_lv
  22. from game.const.task import read_task_json
  23. from game.music import music_loader
  24. from game.sound import sound_player
  25. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle, PygameIMG
  26. from game.utils import local_data_manager as DM
  27. current_folder_path = os.getcwd()
  28. def check_rouge_ob_data(data):
  29. hero_data_dic = {
  30. "Fox": {"exp": 0, "lv": 1}, "Boboli": {"exp": 0, "lv": 1}, "Naruto_old": {"exp": 0, "lv": 1},
  31. "Asha": {"exp": 0, "lv": 1}, "Maria": {"exp": 0, "lv": 1}, "Chunli": {"exp": 0, "lv": 1},
  32. "Titan": {"exp": 0, "lv": 1}, "Chris": {"exp": 0, "lv": 1}, "SeaPrince_old": {"exp": 0, "lv": 1},
  33. "Witch": {"exp": 0, "lv": 1}, "Surprise": {"exp": 0, "lv": 1}
  34. }
  35. err_cnt = 0
  36. for k, v in hero_data_dic.items():
  37. if k not in data.keys():
  38. data[k] = v
  39. err_cnt += 1
  40. print(f"缺失{k}数据, 正在补充...")
  41. if err_cnt > 0:
  42. save_encrypt_single_rouge_file(data, "rougeOB")
  43. return data
  44. class Menu:
  45. def __init__(self, screen, bg_image_path=None):
  46. self.screen = screen
  47. self.buttons = []
  48. self.particles = [] # 粒子列表
  49. self.current_hero = "Fox"
  50. self.current_difficulty = "Easy"
  51. self.is_random = False # 随机选择角色
  52. if bg_image_path:
  53. img = pygame.image.load(bg_image_path).convert()
  54. self.bg_image = pygame.transform.scale(img, screen.get_size())
  55. else:
  56. self.bg_image = None
  57. W.MENU = self
  58. self._init_data()
  59. self._create_buttons()
  60. def _init_data(self):
  61. with open("config.json", "r", encoding="utf-8") as json_file:
  62. mapsetdata = json.load(json_file)
  63. R.rouge_hero = mapsetdata["your_hero"]
  64. self.current_hero = mapsetdata["your_hero"]
  65. R.difficulty = mapsetdata["rogue_difficulty"]
  66. self.current_difficulty = mapsetdata["rogue_difficulty"]
  67. print(mapsetdata["rogue_difficulty"])
  68. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  69. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  70. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  71. rouge_file_path = os.path.join(qqtpve_folder, "rougeOB.rougedata") # 构建文件路径
  72. rouge_achivements_file_path = os.path.join(qqtpve_folder, "rougeOB_achievement.rougedata") # 构建成就文件路径
  73. old_file_path = os.path.join(qqtpve_folder, "rouge.json") # 构建文件路径
  74. old_achivements_file_path = os.path.join(qqtpve_folder, "rouge_achievement.json") # 构建成就文件路径
  75. rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径
  76. last_game_file_path = os.path.join(qqtpve_folder, "rougeOBLastGame.rougedata") # 构建存档文件路径
  77. other_file_path = os.path.join(qqtpve_folder, "rougeOBOther.rougedata") # 构建其他文件路径
  78. # 杂项第一次打开
  79. if not os.path.exists(other_file_path):
  80. rougeOB_other_data = {
  81. "Bomb": [],
  82. "Pet": [],
  83. "Hat": [],
  84. "LastRandom": 0,
  85. "Other": []
  86. }
  87. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  88. # 正常打开
  89. else:
  90. rougeOB_other_data = load_rouge_data(other_file_path)
  91. if 'Cursor_Skin' not in rougeOB_other_data.keys():
  92. rougeOB_other_data['Cursor_Skin'] = "fire_cursor"
  93. R.cursor_skin = "fire_cursor"
  94. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  95. else:
  96. R.cursor_skin = rougeOB_other_data['Cursor_Skin']
  97. if 'Bomb_Skin' not in rougeOB_other_data.keys():
  98. rougeOB_other_data['Bomb_Skin'] = "bomb1"
  99. R.bomb_skin = "bomb1"
  100. save_encrypt_single_rouge_file(rougeOB_other_data, "rougeOBOther")
  101. else:
  102. R.bomb_skin = rougeOB_other_data['Bomb_Skin']
  103. # 第一次打开
  104. if not os.path.exists(rouge_file_path):
  105. rougeOB_data = {
  106. "Fox": {"exp": 0, "lv": 1},
  107. "Boboli": {"exp": 0, "lv": 1},
  108. "Naruto_old": {"exp": 0, "lv": 1},
  109. "Asha": {"exp": 0, "lv": 1},
  110. "Maria": {"exp": 0, "lv": 1},
  111. "Chunli": {"exp": 0, "lv": 1},
  112. "Titan": {"exp": 0, "lv": 1},
  113. "Chris": {"exp": 0, "lv": 1},
  114. "SeaPrince_old": {"exp": 0, "lv": 1},
  115. "Witch": {"exp": 0, "lv": 1},
  116. "Surprise": {"exp": 0, "lv": 1}
  117. }
  118. save_encrypt_single_rouge_file(rougeOB_data, "rougeOB")
  119. # 正常打开
  120. else:
  121. rougeOB_data = load_rouge_data(rouge_file_path)
  122. print(f"local rougeOB_data: {rougeOB_data}")
  123. # task
  124. read_task_json()
  125. # =========================================================================================
  126. if not G.IS_ONLINE:
  127. is_online = util.load_online_config()
  128. if is_online:
  129. if G.UID == "" and G.USERNAME == "":
  130. util.register()
  131. new_info = rougeOB_data
  132. new_info["record"] = "null"
  133. result = util.update_profile(G.UID, new_info, G.PASSWORD)
  134. print(result.get('message', '未知错误'))
  135. is_online = util.try_login()
  136. online_data = util.get_online_data()
  137. if online_data is not None:
  138. rougeOB_data = online_data
  139. # =========================================================================================
  140. rougeOB_data = check_rouge_ob_data(rougeOB_data)
  141. print(f"online rougeOB_data: {rougeOB_data}")
  142. for hero in ["Fox", "Boboli", "Naruto_old", "Asha", "Maria", "Chunli", "Titan", "Chris", "SeaPrince_old", "Witch", "Surprise"]:
  143. rougeOB_data[hero]["lv"] = R.current_lv(rougeOB_data[hero]["exp"])
  144. DM.init_achievement()
  145. rougeOB_achievements = load_rouge_data(rouge_achivements_file_path)
  146. print(rougeOB_achievements)
  147. max_level = 0
  148. max_level_hero = "Fox"
  149. max_diff = "Easy"
  150. self.hero_dic = {
  151. "Fox": "小倩", "Boboli": "波波丽", "Naruto_old": "火影", "Asha": "阿莎", "Maria": "玛莉亚",
  152. "Chunli": "春丽", "Titan": "泰坦", "Chris": "克莉斯", "SeaPrince_old": "海王子",
  153. "Witch": "嫦娥", "Surprise": "???"
  154. }
  155. self.diff_dic = {"Baby": "练习", "Easy": "简单", "Normal": "困难", "Hell": "炼狱", "Hell+": "炼狱+"}
  156. diff_num = {"Baby": 0, "Easy": 1, "Normal": 2, "Hell": 3, "Hell+": 4}
  157. diff_status = {"Baby": 1, "Easy": 0, "Normal": 0, "Hell": 0, "Hell+": 0}
  158. if rougeOB_achievements["Highest"]["level"] != "":
  159. max_level = rougeOB_achievements["Highest"]["level"]
  160. if rougeOB_achievements["Highest"]["hero"] != "":
  161. max_level_hero = rougeOB_achievements["Highest"]["hero"]
  162. if rougeOB_achievements["Highest"]["diff"] != "":
  163. max_diff = rougeOB_achievements["Highest"]["diff"]
  164. if max_level == 20:
  165. diff_status[max_diff] = 2
  166. if max_diff == "Hell+":
  167. R.pass_status["Easy"] = 1
  168. R.pass_status["Normal"] = 1
  169. R.pass_status["Hell"] = 1
  170. if max_level >= 15:
  171. R.pass_status["Hell+"] = 1
  172. elif max_diff == "Hell":
  173. R.pass_status["Easy"] = 1
  174. R.pass_status["Normal"] = 1
  175. if max_level >= 15:
  176. R.pass_status["Hell"] = 1
  177. elif max_diff == "Normal":
  178. R.pass_status["Easy"] = 1
  179. if max_level >= 15:
  180. R.pass_status["Normal"] = 1
  181. else:
  182. if max_level >= 15:
  183. R.pass_status["Easy"] = 1
  184. for dif in ["Easy", "Normal", "Hell", "Hell+"]:
  185. if diff_status[dif] == 2:
  186. R.pass_status[dif] = 2
  187. def _create_buttons(self):
  188. # 主界面按钮
  189. self.buttons.clear()
  190. # 进入游戏
  191. 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'))
  192. # 继续游戏
  193. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  194. 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'))
  195. # 任务系统
  196. 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'))
  197. # 陈列馆
  198. 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'))
  199. # 最高记录
  200. 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'))
  201. # 关于我们
  202. 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'))
  203. # 酬谢
  204. self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.78, 0.26, "res/ui/button/thanks.png", "res/ui/button/thanks_press.png", action=self._open_thanks, anchor='center'))
  205. # 探险指南
  206. 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'))
  207. # 酷比网络
  208. self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.22, 0.74, "res/ui/button/online.png", "res/ui/button/online_press.png", action=self._open_online, anchor='center'))
  209. def refresh(self):
  210. """ 外部接口 """
  211. if W.PAGE is W.Page.GAME:
  212. from game.ui.menu.choose_hero_menu import reload_data
  213. W.PAGE = W.Page.HOME
  214. self._init_data()
  215. reload_data()
  216. self._create_buttons()
  217. def open_setting(self):
  218. self._open_setting()
  219. def open_task(self):
  220. self._open_task()
  221. # 各个按钮动作方法
  222. def _start_game(self):
  223. self.buttons.clear()
  224. from game.ui.menu.choose_hero_menu import ChoosePage
  225. page = ChoosePage()
  226. page.draw()
  227. del page
  228. def start(self):
  229. rougeGen.main_func()
  230. game = Control(
  231. screen=self.screen,
  232. is_continue=False
  233. )
  234. game.update()
  235. def _continue_game(self):
  236. self.buttons.clear()
  237. last = load_rouge_data(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  238. modification_time = os.path.getmtime(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  239. readable_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(modification_time))
  240. lvl = ((last["current_level"] + 4) // 2 - 1) // 5 + 1
  241. stage = ((last["current_level"] + 4) // 2 - 1) % 5 + 1
  242. text_c = f"\n继续游戏 (关卡: {lvl}-{stage}) \n (难度: {self.diff_dic[last['difficulty']]}; 英雄: {self.hero_dic[last['rouge_hero']]})\n{readable_time}"
  243. self.buttons.append(
  244. PygameButton(self.screen, text_c, 0.5, 0.4, 18, "#2a2a2a",
  245. fg_color=(215,220,217), action=lambda: self._continue_to_start(last),
  246. anchor="center", is_bold=True, fix_shape=(240,160), bg_alpha=159,
  247. frosted_glass=True, blur_radius=8, glass_alpha=8, background=self)
  248. )
  249. 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'))
  250. def _continue_to_start(self, last):
  251. self.read_continue_data(last)
  252. game = rogue_control.Control(
  253. screen=self.screen,
  254. is_continue=True
  255. )
  256. game.update()
  257. def _open_task(self):
  258. self.buttons.clear()
  259. from game.ui.menu.task_menu import TaskPage
  260. page = TaskPage()
  261. page.draw()
  262. del page
  263. def _open_setting(self):
  264. self.buttons.clear()
  265. from game.ui.menu.skin_menu import SkinPage
  266. page = SkinPage()
  267. page.draw()
  268. del page
  269. def _open_record(self):
  270. self.buttons.clear()
  271. from game.ui.menu.record_menu import RecordPage
  272. page = RecordPage()
  273. page.draw()
  274. del page
  275. def _open_about_us(self):
  276. self.buttons.clear()
  277. text = f"\n QQTRogue是100の雨女基于永恒QQTPVE底座 " \
  278. f"\n 开发的全新roguelike地牢游戏。玩家可以选" \
  279. f"\n 择各有特色的英雄进行每一次都不同的探险。" \
  280. f"\n" \
  281. f"\n 本作品为免费游戏,唯一官方群945126520" \
  282. f"\n 免费下载; 擅自售卖皆属剽窃!" \
  283. f"\n" \
  284. f"\n 特约赞助" \
  285. f"\n QQTPVE, 永恒, KY系应届生, 各位玩家" \
  286. f"\n 打赏支持请通过以下二维码(备注: 打赏+昵称)" \
  287. f"\n 感谢您的赞助, 我们将会在官网进行展示"
  288. self.buttons.append(
  289. PygameButton(
  290. self.screen, text, 0.5, 0.35, 18, "#2a2a2a",
  291. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(480, 330), bg_alpha=159,
  292. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21),
  293. background=self
  294. )
  295. )
  296. self.buttons.append(
  297. PygameIMG(self, self.screen, 0.38, 0.78, py_img=pygame.image.load(r"res/ui/button/support_us.png"), anchor='center')
  298. )
  299. 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'))
  300. def _open_thanks(self):
  301. self.buttons.clear()
  302. text = f"\n 打赏氪金榜 " \
  303. f"\n 感谢以下玩家对肉鸽和PVE的支持 " \
  304. f"\n --------------------------------- " \
  305. f"\n xydhr1124 "
  306. self.buttons.append(
  307. PygameButton(
  308. self.screen, text, 0.5, 0.38, 18, "#2a2a2a",
  309. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(420,330), bg_alpha=159,
  310. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21),
  311. background=self
  312. )
  313. )
  314. self.buttons.append(PygameButtonBackIMG(self, self.screen, 0.5, 0.75, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self._create_buttons, anchor='center'))
  315. def _open_help(self):
  316. self.buttons.clear()
  317. from game.ui.menu.guide_menu import GuidePage
  318. page = GuidePage()
  319. page.draw()
  320. del page
  321. def _open_online(self):
  322. util.kubi_online()
  323. def run(self):
  324. clock = pygame.time.Clock()
  325. spawn_timer = 0
  326. while True:
  327. dt = clock.tick(120)
  328. spawn_timer += dt
  329. # ================================= 处理鼠标事件 =====================================
  330. for event in pygame.event.get():
  331. if event.type == pygame.QUIT:
  332. pygame.quit()
  333. sys.exit()
  334. for btn in self.buttons:
  335. btn.handle_event(event)
  336. if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
  337. # 看看有没有按钮自己处理了这次点击
  338. if not any(btn.bg_rect.collidepoint(event.pos) for btn in self.buttons):
  339. sound_player.play("uiFail")
  340. else:
  341. sound_player.play("uiLeave")
  342. # ===================================================================================
  343. # 随机生成新粒子: 每200ms生成一个
  344. if spawn_timer > 200:
  345. spawn_timer = 0
  346. x = random.randint(0, self.screen.get_width())
  347. y = self.screen.get_height() + 10
  348. self.particles.append(Particle(x, y))
  349. # 更新和过滤粒子
  350. new_particles = []
  351. for p in self.particles:
  352. p.update()
  353. if p.is_alive():
  354. new_particles.append(p)
  355. self.particles = new_particles
  356. # ===================================== 绘制画面 ======================================
  357. # 绘制背景
  358. if self.bg_image:
  359. self.screen.blit(self.bg_image, (0, 0))
  360. else:
  361. self.screen.fill((60, 90, 60))
  362. # 绘制粒子
  363. for p in self.particles:
  364. p.draw(self.screen)
  365. # 绘制按钮
  366. for btn in self.buttons:
  367. btn.draw()
  368. pygame.display.flip()
  369. # 读取上次存档
  370. def read_continue_data(self, last_data):
  371. R.continuing_game = True
  372. self.current_hero = last_data["rouge_hero"]
  373. with open("config.json", "r", encoding="utf-8") as json_file:
  374. mapsetdata = json.load(json_file)
  375. mapsetdata["map_set"] = "rogueMapSet"
  376. mapsetdata["your_hero"] = last_data["rouge_hero"]
  377. with open("config.json", "w", encoding="utf-8") as json_file:
  378. json.dump(mapsetdata, json_file, indent=4, ensure_ascii=False)
  379. # ===============================================================================
  380. G.CURRENT_LEVEL = last_data["current_level"]
  381. R.map_json_dic = last_data["map_json_dic"]
  382. R.central_mapset = last_data["central_mapset"]
  383. R.difficulty = last_data["difficulty"]
  384. R.today_datetime = last_data["today_datetime"]
  385. R.task_RougeTreasureDestinyElite = last_data["task_RougeTreasureDestinyElite"]
  386. R.task_MineCFireDragonBoss = last_data["task_MineCFireDragonBoss"]
  387. R.task_RougeTreasureDestinyWizard = last_data["task_RougeTreasureDestinyWizard"]
  388. R.task_combat = last_data["task_combat"]
  389. R.task_revival = last_data["task_revival"]
  390. R.rouge_data = last_data["rouge_data"]
  391. R.rouge_hero = last_data["rouge_hero"]
  392. R.rouge_lv = last_data["rouge_lv"]
  393. R.extra_lv = last_data["extra_lv"]
  394. R.rouge_exp = last_data["rouge_exp"]
  395. R.game_exp = last_data["game_exp"]
  396. R.rouge_story = last_data["rouge_story"]
  397. R.rouge_theme_1 = last_data["rouge_theme_1"]
  398. R.rouge_theme_2 = last_data["rouge_theme_2"]
  399. R.rouge_theme_3 = last_data["rouge_theme_3"]
  400. R.rouge_theme_4 = last_data["rouge_theme_4"]
  401. R.rouge_destiny = last_data["rouge_destiny"]
  402. R.coin = last_data["coin"]
  403. R.general_mon_dic = last_data["general_mon_dic"]
  404. R.story_eden = last_data["story_eden"]
  405. R.story_destiny = last_data["story_destiny"]
  406. R.story_ocean = last_data["story_ocean"]
  407. R.story_skyland = last_data["story_skyland"]
  408. R.current_standard_HP = last_data["current_standard_HP"]
  409. R.current_standard_damage = last_data["current_standard_damage"]
  410. R.current_standard_speed = last_data["current_standard_speed"]
  411. R.current_standard_defense = last_data["current_standard_defense"]
  412. R.current_standard_bomb = last_data["current_standard_bomb"]
  413. R.se_district = last_data["se_district"]
  414. R.battle_district = last_data["battle_district"]
  415. R.monster_defense_delta = last_data["monster_defense_delta"]
  416. R.monster_HP_rate = last_data["monster_HP_rate"]
  417. R.player_bomb_self_damage_reduce_rate = last_data["player_bomb_self_damage_reduce_rate"]
  418. R.slow_immune = last_data["slow_immune"]
  419. R.reverse_immune = last_data["reverse_immune"]
  420. R.root_immune = last_data["root_immune"]
  421. R.stun_immune = last_data["stun_immune"]
  422. R.random_dmg = last_data["random_dmg"]
  423. R.show_cursor = last_data["show_cursor"]
  424. R.last_item = last_data["items"]
  425. G.ITEM = last_data["item_use_num"]
  426. G.ALL_CLEAR = last_data["is_all_clear"]
  427. R.last_pass_theme_num = last_data["last_pass_theme_num"]
  428. R.coin_borrow = last_data["coin_borrow"]
  429. R.has_loan = last_data["has_loan"]
  430. if os.path.exists(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata")):
  431. os.remove(os.path.join(os.path.expanduser("~\\Documents"), "QQTPVE", "rougeOBLastGame.rougedata"))
  432. print("已读取,清除数据!!!!!!!!!!!!!")
  433. else:
  434. print("???")
  435. def show_prompt():
  436. """显示提示框,询问用户如何操作"""
  437. import tkinter as tk
  438. from tkinter import messagebox
  439. def close_existing():
  440. root.destroy()
  441. sys.exit()
  442. root = tk.Tk()
  443. root.withdraw() # 隐藏主窗口
  444. if messagebox.askyesno("进程已打开", "已有一个游戏进程正在运行。请关闭后再运行!"):
  445. close_existing()
  446. # 获取所有窗口句柄
  447. def get_all_windows():
  448. windows = []
  449. def enum_windows_proc(hwnd, _):
  450. if win32gui.IsWindowVisible(hwnd):
  451. window_text = win32gui.GetWindowText(hwnd)
  452. if window_text:
  453. windows.append(window_text)
  454. return True
  455. win32gui.EnumWindows(enum_windows_proc, None)
  456. return windows
  457. # 检测窗口是否存在
  458. def check_window_exists():
  459. windows = get_all_windows()
  460. # print(windows)
  461. for window in windows:
  462. if "QQTRogue" in window and "永恒" in window and "100の雨女" in window and "756422783" in window and "擅自售卖皆属剽窃" in window:
  463. return True
  464. return False
  465. class Launcher:
  466. def __init__(self):
  467. pygame.init()
  468. self.screen = pygame.display.set_mode(W.WINDOW_SIZE)
  469. pygame.display.set_caption(W.WINDOW_CAPTION)
  470. self.cfg_json = {}
  471. self.music_volume = 0.7
  472. self.display_flags = 0
  473. self.init_config()
  474. self.init_window()
  475. # 预加载资源
  476. # self.preload_resources()
  477. # 启动菜单
  478. music_loader.play("rogue_menu.mp3", self.music_volume)
  479. self.menu = Menu(self.screen, bg_image_path="res/ui/game/rogue_menu.png")
  480. self.menu.run()
  481. def init_config(self):
  482. try:
  483. with open("config.json", encoding="utf-8") as f:
  484. self.cfg_json = json.load(f)
  485. except json.JSONDecodeError:
  486. with open("config.json", encoding="utf-8_sig") as f:
  487. self.cfg_json = json.load(f)
  488. self.music_volume = self.cfg_json["music_volume"]
  489. if not self.cfg_json["frame_screen"]:
  490. self.display_flags = pygame.NOFRAME
  491. if self.cfg_json["full_screen"]:
  492. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  493. try:
  494. if self.cfg_json["v_sync"] and self.cfg_json["frame_screen"] and not self.cfg_json["full_screen"]:
  495. self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF
  496. # self.display_flags = pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL
  497. elif self.cfg_json["v_sync"] and not self.cfg_json["frame_screen"]:
  498. self.display_flags |= pygame.HWSURFACE | pygame.DOUBLEBUF
  499. elif self.cfg_json["v_sync"] and self.cfg_json["full_screen"]:
  500. self.display_flags = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF
  501. except Exception as e:
  502. print(e)
  503. def init_window(self):
  504. self.screen = pygame.display.set_mode(W.WINDOW_SIZE, flags=self.display_flags)
  505. pygame.display.set_icon(pygame.image.load("res/img/ui/icon.png").convert_alpha())
  506. for i in range(10):
  507. file_name = "itemNum_0_" + str(i) + ".png"
  508. img = pygame.image.load("res/img/ui/number/" + file_name).convert_alpha()
  509. G.NUMBER_IMG.append(img)
  510. def preload_resources(self):
  511. with concurrent.futures.ThreadPoolExecutor() as executor:
  512. executor.submit(Control.preload)
  513. if __name__ == "__main__":
  514. # # 定义日志文件路径
  515. # # log_file_path = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "program.log")
  516. # log_file_path = os.path.join(os.getcwd(), "program.log")
  517. # # 打开日志文件并重定向 stdout
  518. # log_file = open(log_file_path, 'a', encoding='utf-8') # 'a' 是追加模式
  519. # # 重定向 sys.stdout(print 函数输出)
  520. # sys.stdout = log_file
  521. # # 重定向 sys.stderr(报错信息)
  522. # sys.stderr = log_file
  523. print("=========== start ==============")
  524. if check_window_exists():
  525. show_prompt()
  526. Launcher()