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

rewardsview.py (2852B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\agentinteraction\rewardsview.py
      2 from agentinteraction.reward import RewardType, get_test_rewards
      3 from agentinteraction.rewardcont import RewardTypeCont, BonusRewardTypeCont
      4 from carbonui import const as uiconst
      5 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      6 from carbonui.primitives.flowcontainer import FlowContainer
      7 from carbonui import TextColor
      8 REWARD_CLASS_BY_TYPE = {RewardType.NORMAL: RewardTypeCont,
      9  RewardType.BONUS: BonusRewardTypeCont}
     10 REWARD_TYPES = [RewardType.NORMAL, RewardType.BONUS]
     11 
     12 class RewardsView(ContainerAutoSize):
     13     USE_TEST_REWARDS = False
     14 
     15     def ApplyAttributes(self, attributes):
     16         super(RewardsView, self).ApplyAttributes(attributes)
     17         self.subcontainer_rewards_by_type = {}
     18         self.title_color = TextColor.HIGHLIGHT
     19         self.flow_cont = FlowContainer(name='flow_cont', parent=self, align=uiconst.TOTOP, contentSpacing=(25, 25))
     20         for reward_type in REWARD_TYPES:
     21             self.subcontainer_rewards_by_type[reward_type] = None
     22 
     23     def update_normal_rewards(self, rewards):
     24         if self.USE_TEST_REWARDS:
     25             rewards = get_test_rewards()
     26         self._update_rewards(rewards, RewardType.NORMAL)
     27 
     28     def update_bonus_rewards(self, rewards):
     29         if self.USE_TEST_REWARDS:
     30             rewards = get_test_rewards()
     31         self._update_rewards(rewards, RewardType.BONUS)
     32 
     33     def clear_rewards(self):
     34         for reward_type, cont in self.subcontainer_rewards_by_type.iteritems():
     35             if cont and not cont.destroyed:
     36                 cont.clear_current_rewards()
     37 
     38     def _update_rewards(self, rewards, reward_type):
     39         reward_cont = self.subcontainer_rewards_by_type[reward_type]
     40         current_rewards = reward_cont.get_current_rewards() if reward_cont else set()
     41         new_rewards = set([ (reward.type_id, reward.reward_type) for reward in rewards ])
     42         if new_rewards != current_rewards:
     43             reward_cont = self._build_reward_type_container(reward_type)
     44             self._clear_container(container=reward_cont)
     45             reward_cont.add_rewards(rewards, reward_type)
     46 
     47     def _build_reward_type_container(self, reward_type):
     48         cont = self.subcontainer_rewards_by_type[reward_type]
     49         if not cont or cont.destroyed:
     50             reward_cont_class = REWARD_CLASS_BY_TYPE[reward_type]
     51             cont = reward_cont_class(name='subcontainer_%s_rewards' % reward_type, parent=self.flow_cont, align=uiconst.TOPLEFT, reward_type=reward_type, title_color=self.title_color)
     52         self.subcontainer_rewards_by_type[reward_type] = cont
     53         return cont
     54 
     55     def _clear_container(self, container):
     56         if isinstance(container, RewardTypeCont) and not getattr(container, 'destroyed', False):
     57             container.flush_content()