task_menu.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. from game.file_loader.fileLoader import load_json, load_png, save_encrypt_single_rouge_file, load_rouge_data
  2. import json
  3. import os
  4. from game.const import game as G
  5. from game.const import window as W
  6. from game.const import rouge as R
  7. from datetime import datetime
  8. from game.ui.menu.component import PygameButton, PygameButtonBackIMG, Particle
  9. current_folder_path = os.getcwd()
  10. class TaskPage:
  11. def __init__(self):
  12. self.screen = W.MENU
  13. self.now = datetime.now()
  14. self.year = "1970"
  15. self.month = "1"
  16. self.day = "1"
  17. user_documents_folder = os.path.expanduser("~\\Documents") # 获取用户的"文档"文件夹路径
  18. qqtpve_folder = os.path.join(user_documents_folder, "QQTPVE") # 构建QQTPVE文件夹路径
  19. os.makedirs(qqtpve_folder, exist_ok=True) # 确保QQTPVE文件夹存在,如果不存在则创建
  20. self.rouge_task_file_path = os.path.join(qqtpve_folder, "rougeOB_task.rougedata") # 构建任务文件路径
  21. self.rougeOB_task_data = {}
  22. self.init_task()
  23. def init_task(self):
  24. # 第一次打开
  25. if not os.path.exists(self.rouge_task_file_path):
  26. self.rougeOB_task_data = {
  27. "1": {"task": "击杀5只命运维系者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  28. "2": {"task": "击杀3只渊烬龙王", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  29. "3": {"task": "到达3-1十次", "reward": "800经验", "process": 0, "finish": 10, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  30. "4": {"task": "击杀5只因果阅律者", "reward": "800经验", "process": 0, "finish": 5, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  31. "5": {"task": "完成20次挑衅敌人", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  32. "6": {"task": "使用小倩到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  33. "7": {"task": "使用波波丽到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  34. "8": {"task": "使用火影到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  35. "9": {"task": "使用阿莎到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  36. "10": {"task": "使用玛莉亚到达3-5三次", "reward": "800经验", "process": 0, "finish": 3, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  37. "11": {"task": "到达4-1一次", "reward": "800经验", "process": 0, "finish": 1, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  38. "12": {"task": "累积使用20次复活卡", "reward": "800经验", "process": 0, "finish": 20, "last_finish": 1970, "reward_exp": 800, "hero": "Fox", "rewarded": True},
  39. "today": {"task": "进行一盘游戏并到达2-1", "reward": "50经验", "process": 0, "finish": 1, "last_finish": "1970-1-1", "reward_exp": 50, "hero": "Fox", "rewarded": True}
  40. }
  41. save_encrypt_single_rouge_file(self.rougeOB_task_data, "rougeOB_task")
  42. # 正常打开
  43. else:
  44. self.rougeOB_task_data = load_rouge_data(self.rouge_task_file_path)
  45. # 格式化年月日
  46. year = self.now.strftime("%Y")
  47. month = self.now.strftime("%m")
  48. day = self.now.strftime("%d")
  49. # 移除月份和日期的前导零(如果有)
  50. month = month.lstrip("0")
  51. day = day.lstrip("0")
  52. self.year = str(year)
  53. self.month = str(month)
  54. self.day = str(day)
  55. if int(self.rougeOB_task_data[str(month)]["last_finish"]) < int(year):
  56. self.rougeOB_task_data[str(month)]["process"] = 0
  57. self.rougeOB_task_data[str(month)]["last_finish"] = year
  58. self.rougeOB_task_data[str(month)]["rewarded"] = False
  59. if self.rougeOB_task_data["today"]["last_finish"] != year + "-" + month + "-" + day:
  60. self.rougeOB_task_data["today"]["process"] = 0
  61. self.rougeOB_task_data["today"]["last_finish"] = year + "-" + month + "-" + day
  62. self.rougeOB_task_data["today"]["rewarded"] = False
  63. save_encrypt_single_rouge_file(self.rougeOB_task_data, "rougeOB_task")
  64. def draw(self):
  65. """
  66. # ============================================= 月常任务 =============================================
  67. if self.rougeOB_task_data[self.month]["process"] < self.rougeOB_task_data[self.month]["finish"]:
  68. # 若还未完成
  69. text = f"○月度征召\n{self.rougeOB_task_data[self.month]['task']} \n酬谢: {self.rougeOB_task_data[self.month]['reward']}\n进度: {self.rougeOB_task_data[self.month]['process']}/{self.rougeOB_task_data[self.month]['finish']}"
  70. self.screen.buttons.append(
  71. PygameButton(self.screen.screen, text, 0.3, 0.35, 18, "#2a2a2a",
  72. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
  73. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
  74. )
  75. else:
  76. text = f"○月度征召\n{self.rougeOB_task_data[self.month]['task']} \n酬谢: {self.rougeOB_task_data[self.month]['reward']}\n\n by {R.hero_name[self.rougeOB_task_data['today']['hero']]}"
  77. self.screen.buttons.append(
  78. PygameButton(self.screen.screen, text, 0.3, 0.35, 18, "#2a2a2a",
  79. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
  80. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
  81. )
  82. self.screen.buttons.append(PygameButtonBackIMG(
  83. self.screen, self.screen.screen, 0.3, 0.41, "res/ui/button/task_finish.png", "res/ui/button/task_finish.png", anchor='center')
  84. )
  85. # ============================================= 日常任务 =============================================
  86. print(self.rougeOB_task_data["today"]["process"], self.rougeOB_task_data["today"]["finish"])
  87. if self.rougeOB_task_data["today"]["process"] < self.rougeOB_task_data["today"]["finish"]:
  88. # 若还未完成
  89. text = f"○日常委托\n{self.rougeOB_task_data['today']['task']} \n酬谢: {self.rougeOB_task_data['today']['reward']}\n进度: {self.rougeOB_task_data['today']['process']}/{self.rougeOB_task_data['today']['finish']}"
  90. self.screen.buttons.append(
  91. PygameButton(self.screen.screen, text, 0.7, 0.35, 18, "#2a2a2a",
  92. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
  93. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
  94. )
  95. else:
  96. text = f"○日常委托\n{self.rougeOB_task_data['today']['task']} \n酬谢: {self.rougeOB_task_data['today']['reward']}\n\n by {R.hero_name[self.rougeOB_task_data['today']['hero']]}"
  97. self.screen.buttons.append(
  98. PygameButton(self.screen.screen, text, 0.7, 0.35, 18, "#2a2a2a",
  99. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
  100. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21), background=self.screen)
  101. )
  102. self.screen.buttons.append(PygameButtonBackIMG(
  103. self.screen, self.screen.screen, 0.7, 0.41, "res/ui/button/task_finish.png", "res/ui/button/task_finish.png", anchor='center')
  104. )
  105. """
  106. text = f"\n\n任务系统升级中.."
  107. self.screen.buttons.append(
  108. PygameButton(self.screen.screen, text, 0.5, 0.35, 18, "#2a2a2a",
  109. fg_color=(215,220,217), anchor="center", is_bold=True, fix_shape=(280,160), bg_alpha=159,
  110. frosted_glass=True, blur_radius=12, glass_alpha=127, frame_radius=4, glass_surf_color=(41,34,21),
  111. background=self.screen)
  112. )
  113. # 返回主界面
  114. self.screen.buttons.append(PygameButtonBackIMG(
  115. self.screen, self.screen.screen, 0.66, 0.72, "res/ui/button/return.png", "res/ui/button/return_press.png", action=self.screen.refresh, anchor='center')
  116. )