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

resultwindow.py (17482B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\projectdiscovery\client\projects\subcellular\resultwindow.py
      2 from __future__ import absolute_import
      3 import math
      4 import localization
      5 from carbon.common.script.util.format import FmtAmt
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.transform import Transform
      9 from carbonui.uianimations import animations
     10 from .categoryselector import CategorySelector
     11 from eve.client.script.ui.control import eveLabel, themeColored
     12 from carbonui.control.button import Button
     13 from eve.client.script.ui.control.eveLabel import *
     14 from eve.client.script.ui.control.tooltips import TooltipPanel
     15 from eve.client.script.ui.tooltips.tooltipsWrappers import TooltipBaseWrapper
     16 from .info import INFO as PROJECT_INFO
     17 from projectdiscovery.client import const
     18 from projectdiscovery.client.projects.subcellular import nested_categories_from_json
     19 
     20 class ResultWindow(Container):
     21 
     22     def ApplyAttributes(self, attributes):
     23         super(ResultWindow, self).ApplyAttributes(attributes)
     24         self.isTrainingPhase = attributes.get('isTrainingPhase')
     25         self.starting_scale = attributes.get('starting_scale')
     26         self.bottom_container = attributes.get('bottom_container')
     27         self.projectdiscoverySvc = sm.RemoteSvc('ProjectDiscovery')
     28         self.finishedTraining = False
     29         self.result = None
     30         self.audio_service = sm.GetService('audio')
     31         self.setup_layout()
     32         self.categories_selected.cascade_categories_out()
     33         self.disable_ui()
     34 
     35     def setup_layout(self):
     36         self.left_main_container = Container(name='left_main_container', parent=self, align=uiconst.TOLEFT_PROP, width=0.5, clipChildren=True, top=20)
     37         self.task_label = themeColored.LabelThemeColored(parent=self.left_main_container, align=uiconst.CENTERTOP, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/WindowHeaderText'), top=40, fontsize=28)
     38         self.category_container = Container(name='category_container', parent=self, align=uiconst.TOLEFT_PROP, width=0.5, padTop=45, clipChildren=True)
     39         self.categories_selected = CategorySelector(categories=nested_categories_from_json(PROJECT_INFO['info']['classes']), parent=self.category_container, state=uiconst.UI_DISABLED, starting_scale=self.starting_scale)
     40         self.legend_container = Container(name='legendContainer', parent=self.category_container, width=100, height=28, align=uiconst.BOTTOMRIGHT, opacity=0, top=93, left=-5, idx=0)
     41         self.legend_icon = LegendIcon(name='legendIcon', parent=self.legend_container, texturePath='res:/UI/Texture/classes/ProjectDiscovery/helpTooltipUp.png', align=uiconst.TOLEFT, width=28, height=28)
     42         self.legend_label = eveLabel.Label(parent=self.legend_container, align=uiconst.CENTERLEFT, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/LegendIconLabel'), left=30, height=15)
     43         self.main_button_container = Container(name='ResultMainContinueButtonContainer', parent=self.bottom_container, align=uiconst.CENTERBOTTOM, width=355, height=53, bgTexturePath='res:/UI/Texture/classes/ProjectDiscovery/footerBG.png', state=uiconst.UI_DISABLED, opacity=0)
     44         self.continue_button_container = Container(name='ResultContinueButtonContainer', parent=self.main_button_container, width=250, align=uiconst.CENTER, height=40, top=5)
     45         self.continue_button = Button(name='resultContinueButton', parent=self.continue_button_container, align=uiconst.CENTER, label=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/ContinueButtonLabel'), fontsize=18, fixedwidth=170, fixedheight=30, func=lambda x: self.close())
     46         Sprite(parent=self.continue_button_container, align=uiconst.CENTERLEFT, width=34, height=20, texturePath='res:/UI/Texture/classes/ProjectDiscovery/submitArrow.png', opacity=0.7)
     47         Sprite(parent=Transform(parent=self.continue_button_container, align=uiconst.CENTERRIGHT, width=34, height=20, rotation=math.pi), align=uiconst.CENTERRIGHT, width=34, height=20, texturePath='res:/UI/Texture/classes/ProjectDiscovery/submitArrow.png', opacity=0.7)
     48 
     49     def close(self):
     50         if not self.result:
     51             sm.ScatterEvent(const.Events.ContinueFromReward)
     52         elif self.isTrainingPhase:
     53             sm.ScatterEvent(const.Events.ContinueFromTrainingResult)
     54             self.audio_service.SendUIEvent(const.Sounds.RewardsWindowLoopStop)
     55             self.audio_service.SendUIEvent(const.Sounds.RewardsWindowClosePlay)
     56             self.audio_service.SendUIEvent(const.Sounds.MainImageLoopPlay)
     57         else:
     58             sm.ScatterEvent(const.Events.CloseResult, self.result)
     59             sm.ScatterEvent(const.Events.ContinueFromResult)
     60         animations.FadeOut(self, duration=0.4)
     61         self.categories_selected.cascade_categories_out()
     62         self.categories_selected.reset_categories()
     63         self.legend_container.SetOpacity(0)
     64         self.disable_ui()
     65 
     66     def assign_result(self, result):
     67         self.result = result
     68         if self._is_solution_known():
     69             task_label_path = 'UI/ProjectDiscovery/Subcellular/ResultScreen/WindowHeaderText'
     70         else:
     71             task_label_path = 'UI/ProjectDiscovery/Subcellular/ResultScreen/WindowHeaderTextUnknown'
     72         self.task_label.SetText(localization.GetByLabel(task_label_path))
     73         self.legend_icon.tooltipPanelClassInfo = LegendTooltipWrapper(known_solution=self._is_solution_known())
     74         for super_cat in self.categories_selected.super_categories:
     75             for subcat in super_cat.sub_categories:
     76                 subcat.set_available()
     77                 if self._is_solution_known():
     78                     self._show_known_solution(subcat)
     79                 else:
     80                     self._show_unknown_solution(subcat)
     81                 subcat.exclude_texture.state = uiconst.UI_HIDDEN
     82                 subcat.category['selected'] = False
     83                 subcat.set_unclickable()
     84 
     85     def open(self):
     86         animations.FadeIn(self, callback=self.enable_button)
     87         animations.FadeIn(self.main_button_container)
     88 
     89     def show_result(self):
     90         self.enable_ui()
     91         self.categories_selected.cascade_categories_in()
     92         self.legend_container.SetOpacity(1)
     93 
     94     def enable_ui(self):
     95         self.state = uiconst.UI_NORMAL
     96         self.enable_button()
     97         self.main_button_container.SetState(uiconst.UI_NORMAL)
     98         if self.result:
     99             self.enable_categories()
    100 
    101     def disable_ui(self):
    102         self.state = uiconst.UI_DISABLED
    103         self.disable_categories()
    104         self.disable_button()
    105         self.main_button_container.SetState(uiconst.UI_DISABLED)
    106         self.main_button_container.SetOpacity(0)
    107 
    108     def _show_known_solution(self, subcat):
    109         subcat.hide_percentage_and_color_overlay()
    110         if subcat.category['id'] not in self.result['playerSelection'] and subcat.category['id'] not in self.result['task']['solution']:
    111             subcat.set_unavailable()
    112         elif subcat.category['id'] in self.result['playerSelection'] and subcat.category['id'] in self.result['task']['solution']:
    113             subcat.correct_texture.opacity = 1
    114         elif subcat.category['id'] in self.result['playerSelection'] and subcat.category['id'] not in self.result['task']['solution']:
    115             subcat.unmatched_texture.opacity = 1
    116         elif subcat.category['id'] not in self.result['playerSelection'] and subcat.category['id'] in self.result['task']['solution']:
    117             subcat.missed_texture.opacity = 1
    118         subcat.set_unselected()
    119 
    120     def _show_unknown_solution(self, subcat):
    121         subcat.hide_percentage_and_color_overlay()
    122         subcat.set_unavailable()
    123         if subcat.category['id'] in self.result['playerSelection']:
    124             subcat.set_selected()
    125             subcat.set_available()
    126             subcat.set_percentage(str(0))
    127             subcat.show_percentage_and_color_overlay()
    128         else:
    129             subcat.set_unselected()
    130         if self._is_solution_voted():
    131             for vote in self.result['task']['votes']:
    132                 if subcat.category['id'] == vote['result']:
    133                     if vote['percentage'] > 0.01 or subcat.category['id'] in self.result['playerSelection']:
    134                         subcat.show_percentage_and_color_overlay()
    135                         subcat.set_percentage(FmtAmt(vote['percentage'] * 100, showFraction=0))
    136                         color = subcat.lerp_color(vote['percentage'], 1)
    137                         subcat.color_overlay.SetRGBA(color[0], color[1], color[2], 1)
    138                         subcat.set_available()
    139                     else:
    140                         subcat.hide_percentage_and_color_overlay()
    141                         subcat.set_unavailable()
    142 
    143     def enable_categories(self):
    144         self.category_container.state = uiconst.UI_NORMAL
    145         self.categories_selected.state = uiconst.UI_NORMAL
    146 
    147     def disable_categories(self):
    148         self.category_container.state = uiconst.UI_DISABLED
    149         self.categories_selected.state = uiconst.UI_DISABLED
    150 
    151     def enable_button(self):
    152         self.continue_button.SetState(uiconst.UI_NORMAL)
    153 
    154     def disable_button(self):
    155         self.continue_button.SetState(uiconst.UI_DISABLED)
    156 
    157     def kill(self):
    158         self.main_button_container.Close()
    159         self.Close()
    160 
    161     def _is_solution_known(self):
    162         return self.result and 'task' in self.result.keys() and 'solution' in self.result['task'] and self.result['task']['solution']
    163 
    164     def _is_solution_voted(self):
    165         return self.result and 'task' in self.result.keys() and 'votes' in self.result['task'] and self.result['task']['votes']
    166 
    167 
    168 class LegendIcon(Sprite):
    169 
    170     def OnMouseEnter(self, *args):
    171         self.SetTexturePath('res:/UI/Texture/classes/ProjectDiscovery/helpTooltipOver.png')
    172 
    173     def OnMouseExit(self, *args):
    174         self.SetTexturePath('res:/UI/Texture/classes/ProjectDiscovery/helpTooltipUp.png')
    175 
    176 
    177 class LegendTooltipWrapper(TooltipBaseWrapper):
    178 
    179     def __init__(self, known_solution):
    180         self._knownSolution = known_solution
    181 
    182     def CreateTooltip(self, parent, owner, idx):
    183         self.tooltipPanel = TooltipPanel(parent=parent, owner=owner, idx=idx)
    184         self.tooltipPanel.LoadGeneric1ColumnTemplate()
    185         self.legend_container = Container(name='legendContainer', align=uiconst.TOPLEFT, height=220, width=210)
    186         if self._knownSolution:
    187             self.create_known_solution_tooltip()
    188         else:
    189             self.create_unknown_solution_tooltip()
    190         self.tooltipPanel.AddCell(self.legend_container, cellPadding=(0, 5, 0, -10))
    191         return self.tooltipPanel
    192 
    193     def create_unknown_solution_tooltip(self):
    194         self.selection_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    195         self.selection_sprite = Sprite(parent=Container(parent=self.selection_legend_container, align=uiconst.TOLEFT, width=55), height=51, width=54, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/ProjectDiscovery/categorySelected.png')
    196         self.selection_legend_label_container = Container(parent=Container(parent=self.selection_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.TOLEFT, width=50)
    197         self.selection_legend_label_header = EveLabelMediumBold(parent=self.selection_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/SelectionLegendLabelHeader'), align=uiconst.TOPLEFT, top=20, left=5)
    198         self.popular_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    199         self.popular_sprite_container = Container(parent=self.popular_legend_container, align=uiconst.TOLEFT, width=55)
    200         self.popular_other_hex = Sprite(parent=self.popular_sprite_container, texturePath='res:/UI/Texture/classes/ProjectDiscovery/hexOutline.png', height=40, width=44, align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, color=(0.32, 0.32, 0.32, 1))
    201         self.popular_other_sprite = Sprite(parent=self.popular_sprite_container, height=32, width=36, top=4, align=uiconst.CENTERTOP, texturePath='res:/UI/Texture/classes/ProjectDiscovery/hexMask.png')
    202         self.popular_other_sprite.SetRGBA(0.33, 0.49, 0.26, 1)
    203         self.popular_legend_label_container = Container(parent=Container(parent=self.popular_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.CENTERLEFT, width=50, height=65, top=-5)
    204         self.popular_legend_label_header = EveLabelMediumBold(parent=self.popular_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/PopularLegendLabelHeader'), align=uiconst.TOPLEFT)
    205         self.popular_legend_label = eveLabel.Label(parent=self.popular_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/PopularLegendLabel'), align=uiconst.CENTERLEFT, width=200)
    206         self.unpopular_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    207         self.unpopular_sprite_container = Container(parent=self.unpopular_legend_container, align=uiconst.TOLEFT, width=55)
    208         self.unpopular_other_hex = Sprite(parent=self.unpopular_sprite_container, texturePath='res:/UI/Texture/classes/ProjectDiscovery/hexOutline.png', height=40, width=44, align=uiconst.CENTERTOP, state=uiconst.UI_DISABLED, color=(0.32, 0.32, 0.32, 1))
    209         self.unpopular_other_sprite = Sprite(parent=self.unpopular_sprite_container, height=32, width=36, top=4, align=uiconst.CENTERTOP, texturePath='res:/UI/Texture/classes/ProjectDiscovery/hexMask.png')
    210         self.unpopular_other_sprite.SetRGBA(0.5, 0.22, 0.17, 1)
    211         self.unpopular_legend_label_container = Container(parent=Container(parent=self.unpopular_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.CENTERLEFT, width=50, height=65, top=-5)
    212         self.unpopular_legend_label_header = EveLabelMediumBold(parent=self.unpopular_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/UnpopularLegendLabelHeader'), align=uiconst.TOPLEFT)
    213         self.unpopular_legend_label = eveLabel.Label(parent=self.unpopular_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/UnpopularLegendLabel'), align=uiconst.CENTERLEFT, width=150)
    214 
    215     def create_known_solution_tooltip(self):
    216         self.correct_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    217         self.correct_legend_sprite = Sprite(parent=Container(parent=self.correct_legend_container, align=uiconst.TOLEFT, width=55), height=51, width=54, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/ProjectDiscovery/categoryMatch.png')
    218         self.correct_legend_label_container = Container(parent=Container(parent=self.correct_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.CENTERLEFT, width=50, height=65)
    219         self.correct_legend_label_header = EveLabelMediumBold(parent=self.correct_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/CorrectLegendLabelHeader'), align=uiconst.TOPLEFT)
    220         self.correct_legend_label = eveLabel.Label(parent=self.correct_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/CorrectLegendLabel'), align=uiconst.CENTERLEFT, width=200)
    221         self.missed_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    222         self.missed_legend_sprite = Sprite(parent=Container(parent=self.missed_legend_container, align=uiconst.TOLEFT, width=55), height=51, width=54, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/ProjectDiscovery/categoryMissed.png')
    223         self.missed_legend_label_container = Container(parent=Container(parent=self.missed_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.CENTERLEFT, width=50, height=65)
    224         self.missed_legend_label_header = EveLabelMediumBold(parent=self.missed_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/MissedLegendLabelHeader'), align=uiconst.TOPLEFT)
    225         self.missed_legend_label = eveLabel.Label(parent=self.missed_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/MissedLegendLabel'), align=uiconst.CENTERLEFT, width=150)
    226         self.unmatched_legend_container = Container(parent=self.legend_container, align=uiconst.TOTOP, height=70)
    227         self.unmatched_legend_sprite = Sprite(parent=Container(parent=self.unmatched_legend_container, align=uiconst.TOLEFT, width=55), height=51, width=54, align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/ProjectDiscovery/categoryWrong.png')
    228         self.unmatched_legend_label_container = Container(parent=Container(parent=self.unmatched_legend_container, align=uiconst.TOLEFT, width=145), align=uiconst.CENTERLEFT, width=50, height=65)
    229         self.unmatched_legend_label_header = EveLabelMediumBold(parent=self.unmatched_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/UnmatchedLegendLabelHeader'), align=uiconst.TOPLEFT)
    230         self.unmatched_legend_label = eveLabel.Label(parent=self.unmatched_legend_label_container, text=localization.GetByLabel('UI/ProjectDiscovery/Subcellular/ResultScreen/UnmatchedLegendLabel'), align=uiconst.CENTERLEFT, width=150, top=5)