NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

checklist_progress_window.py (5911B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\achievement_system\client\qa\checklist_progress_window.py
      2 import uthread2
      3 import uuid
      4 from achievement_system.client.api.repository import get_repository
      5 from achievement_system.client.model.definition.achievement.attributes import AchievementDefinitionAttributes
      6 from achievement_system.client.model.definition.achievement.identifier import AchievementDefinitionIdentifier
      7 from achievement_system.client.model.definition.contribution_method.attributes import ContributionMethodAttributes
      8 from achievement_system.client.model.definition.contribution_method.parameter.identifier import ContributionMethodParameterIdentifier
      9 from achievement_system.client.model.state.achievement import AchievementStateAttributes
     10 from achievement_system.client.model.state.checklist import Checklist
     11 from carbonui import Align, AxisAlignment, ButtonVariant, Density, uiconst
     12 from carbonui.button.group import ButtonGroup, ButtonSizeMode
     13 from carbonui.control.button import Button
     14 from carbonui.control.checkbox import Checkbox
     15 from carbonui.control.window import Window
     16 from carbonui.primitives.container import Container
     17 from carbonui.text.styles import TextHeader
     18 if False:
     19     from typing import List, Dict
     20 
     21 class AchievementChecklistProgressWindow(Window):
     22     default_windowID = 'AchievementChecklistProgressWindow'
     23     default_caption = 'Admin - Set Checklist Achievement Progress'
     24     default_fixedWidth = 515
     25     default_isMinimizable = False
     26     default_isStackable = False
     27     default_isCollapseable = False
     28 
     29     def __init__(self, contrib_method_definition, achievement_id, achievement_definition, achievement_state, *args, **kwargs):
     30         super(AchievementChecklistProgressWindow, self).__init__(*args, **kwargs)
     31         self._contrib_method_definition = contrib_method_definition
     32         self._achievement_id = achievement_id
     33         self._achievement_definition = achievement_definition
     34         self._achievement_state = achievement_state
     35         self._thread = None
     36         self._output_values = {}
     37         self.construct_layout()
     38 
     39     def Close(self, *args, **kwargs):
     40         try:
     41             self._kill_thread()
     42         finally:
     43             super(AchievementChecklistProgressWindow, self).Close(*args, **kwargs)
     44 
     45     def _kill_thread(self):
     46         if self._thread is not None:
     47             self._thread.kill()
     48             self._thread = None
     49 
     50     def construct_layout(self):
     51         self.content.padding = (32, 32, 32, 32)
     52         target_param = ContributionMethodParameterIdentifier(self._contrib_method_definition.progress_config.target_parameter)
     53         param_config = self._achievement_definition.contribution_method.get_parameter_config_by_identifier(target_param)
     54         state_checklist = self._achievement_state.checklist
     55         for value_type, values in param_config.values.items():
     56             value_type_container = Container(name='duration_container', parent=self.content, align=Align.TOTOP, height=32)
     57             TextHeader(name='duration_label', parent=value_type_container, align=Align.CENTERLEFT, text=self.format_value_type_label(value_type), bold=True)
     58             for value in values:
     59                 is_already_checked = state_checklist is not None and value_type in state_checklist.values and value in state_checklist.values[value_type]
     60                 value_checkbox = Checkbox(parent=self.content, align=Align.TOTOP, text=self.format_checkbox_label(value_type, value), callback=lambda c, x = value_type, y = value: self._on_checkbox(c, x, y))
     61                 value_checkbox.SetChecked(is_already_checked, report=False)
     62                 value_checkbox.enabled = not is_already_checked
     63 
     64         self.construct_buttons()
     65 
     66     def format_value_type_label(self, value_type):
     67         if value_type == 'achievement_id':
     68             return 'Achievements'
     69         return value_type
     70 
     71     def format_checkbox_label(self, value_type, value):
     72         if value_type == 'achievement_id':
     73             return get_repository().definitions.get_achievement(AchievementDefinitionIdentifier(identifier=uuid.UUID(value))).name_message.get_localized_text()
     74         return value
     75 
     76     def construct_buttons(self):
     77         button_group = ButtonGroup(name='button_group', parent=self.content, align=Align.TOBOTTOM, button_alignment=AxisAlignment.CENTER, density=Density.EXPANDED, button_size_mode=ButtonSizeMode.STRETCH)
     78         self.ok_button = Button(name='sell_button', label='Progress', variant=ButtonVariant.PRIMARY, func=self.on_ok_button)
     79         button_group.add_button(self.ok_button)
     80         self.cancel_button = Button(name='cancel_button', label='Cancel', variant=ButtonVariant.GHOST, func=self.on_cancel_button)
     81         button_group.add_button(self.cancel_button)
     82 
     83     def _on_checkbox(self, checkbox, value_type, value):
     84         if checkbox.checked:
     85             if value_type not in self._output_values:
     86                 self._output_values[value_type] = []
     87             if value not in self._output_values[value_type]:
     88                 self._output_values[value_type].append(value)
     89         elif value in self._output_values.get(value_type, []):
     90             self._output_values[value_type].remove(value)
     91 
     92     def on_ok_button(self, *args):
     93         self._kill_thread()
     94         self._thread = uthread2.StartTasklet(self._on_ok)
     95 
     96     def _on_ok(self):
     97         self.ok_button.busy = True
     98         self.ok_button.disabled = True
     99         try:
    100             checklist = Checklist(self._output_values)
    101             get_repository().admin_add_checklist_progress_to_achievement(self._achievement_id, checklist)
    102             self.SetModalResult(uiconst.ID_OK)
    103         except Exception as e:
    104             raise e
    105         finally:
    106             self._thread = None
    107             self.ok_button.busy = False
    108             self.ok_button.disabled = False
    109 
    110     def on_cancel_button(self, *args):
    111         self.SetModalResult(uiconst.ID_CANCEL)