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

standingsBar.py (27372B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\standings\standingsBar.py
      2 import math
      3 from carbonui import uiconst
      4 from carbonui.primitives.container import Container
      5 from carbonui.primitives.fill import Fill
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.uianimations import animations
      8 from carbonui.uicore import uicore
      9 from carbonui.util.color import Color
     10 from eve.client.script.ui.control import tooltips
     11 from eve.client.script.ui.control.eveLabel import EveLabelSmall
     12 from eve.client.script.ui.control.glowSprite import GlowSprite
     13 from eve.client.script.ui.control.themeColored import FillThemeColored, SpriteThemeColored
     14 from eve.client.script.ui.shared.info import infoConst
     15 from eve.client.script.ui.shared.standings import standingsUIUtil, standingUIConst
     16 from eve.client.script.ui.shared.standings.standingData import StandingData
     17 from eve.client.script.ui.shared.standings.standingUIConst import THRESHOLD_ATTACKEDINSPACE
     18 from eve.client.script.ui.shared.standings.standingsUIUtil import GetStandingColor, GetStationServiceRestrictionsForThreshold
     19 from eve.client.script.ui.station.agents import agentUtil
     20 from eve.client.script.ui.station.agents.agentUtil import GetAgentDerivedStanding, GetNPCCorpDerivedStanding
     21 from eve.client.script.ui.tooltips.tooltipsWrappers import TooltipBaseWrapper
     22 from eve.common.lib.appConst import factionTriglavian, factionEDENCOM
     23 from eve.common.script.sys import idCheckers
     24 from eve.common.script.util.standingUtil import OpenStandingsPanelOnOwnerByID
     25 from localization import GetByLabel
     26 from utillib import KeyVal
     27 OPACITY_BAR = 0.5
     28 OPACITY_ARROWSPRITE = 0.3
     29 ICONSIZE_THRESHOLD = 32
     30 PADDING_THRESHOLD_ICON = 2
     31 OPACITY_ICON_ENABLED = 1.0
     32 OPACITY_ICON_DISABLED = 0.2
     33 
     34 class StandingsBar(Container):
     35     default_name = 'StandingBar'
     36     default_state = uiconst.UI_NORMAL
     37     default_hasTopThresholdIcons = True
     38     default_hasBottomLabels = True
     39     default_hasBarAnimation = True
     40     default_barHeight = 20
     41 
     42     def ApplyAttributes(self, attributes):
     43         Container.ApplyAttributes(self, attributes)
     44         self.hasTopThresholdIcons = attributes.get('hasTopThresholdIcons', self.default_hasTopThresholdIcons)
     45         self.hasBottomLabels = attributes.get('hasBottomLabels', self.default_hasBottomLabels)
     46         self.hasBarAnimation = attributes.get('hasBarAnimation', self.default_hasBarAnimation)
     47         self.barHeight = attributes.get('barHeight', self.default_barHeight)
     48         self.thresholdIconsByID = {}
     49         self.hideZeroAxisLabel = False
     50         self.thresholdIconCont = Container(name='thresholdIconCont', parent=self, padding=(-ICONSIZE_THRESHOLD / 2,
     51          0,
     52          -ICONSIZE_THRESHOLD / 2,
     53          1))
     54         mainCont = Container(name='mainCont', parent=self)
     55         self.mainBarCont = Container(name='mainBarCont', parent=mainCont, align=uiconst.TOTOP, top=self.barHeight + 6, height=self.barHeight)
     56         self.barCont = Container(name='barCont', parent=self.mainBarCont)
     57         self.barBGCont = Container(name='bgCont', parent=self.mainBarCont)
     58         self.axisLabelCont = Container(name='axisLabelCont', parent=mainCont, align=uiconst.TOTOP, height=12, padTop=1, opacity=1.0 if self.hasBottomLabels else 0.0)
     59         self.ConstructBar()
     60         self.ConstructBarSecondary()
     61         self.ConstructBarIncrease()
     62         self.ConstructBackground()
     63         self.ConstructAxisLabels()
     64 
     65     def ConstructBackground(self):
     66         FillThemeColored(bgParent=self.barBGCont, colorType=uiconst.COLORTYPE_UIBASECONTRAST, opacity=0.9)
     67         opacity = 0.15
     68         SpriteThemeColored(name='bgArrowSprite', parent=self.barBGCont, align=uiconst.TOLEFT_PROP, colorType=uiconst.COLORTYPE_UIBASE, width=0.5, texturePath='res:/UI/Texture/Classes/Standings/barArrowBG.png', opacity=opacity, tileX=True)
     69         SpriteThemeColored(name='bgArrowSprite', parent=self.barBGCont, align=uiconst.TOALL, colorType=uiconst.COLORTYPE_UIBASE, texturePath='res:/UI/Texture/Classes/Standings/barArrowBG.png', opacity=opacity, tileX=True, rotation=math.pi)
     70 
     71     def ConstructAxisLabels(self):
     72         opacity = 0.6
     73         EveLabelSmall(parent=self.axisLabelCont, text='-10.0', align=uiconst.TOPLEFT, opacity=opacity)
     74         self.zeroAxisLabel = EveLabelSmall(parent=self.axisLabelCont, text='0.0', align=uiconst.CENTERTOP, opacity=opacity)
     75         EveLabelSmall(parent=self.axisLabelCont, text='10.0', align=uiconst.TOPRIGHT, opacity=opacity)
     76 
     77     def ConstructBar(self):
     78         self.bar = Container(name='bar', parent=self.barCont, align=uiconst.TOLEFT_PROP, state=uiconst.UI_NORMAL, width=0.0, left=0.5, clipChildren=True)
     79         self.bar.OnClick = self.OnBarClick
     80         self.arrowSprite = Sprite(name='arrowSprite', bgParent=self.bar, texturePath='res:/UI/Texture/Classes/Standings/arrows_20.png', opacity=0.2, tileX=True)
     81         self.barFill = Fill(name='barFill', bgParent=self.bar, opacity=0.7)
     82 
     83     def OnBarClick(self):
     84         OpenStandingsPanelOnOwnerByID(self.standingData.GetOwnerID2())
     85 
     86     def SetTooltips(self):
     87         self.bar.tooltipPanelClassInfo = StandingsBarTooltip(text=self.GetBarHint())
     88         self.barSecondary.tooltipPanelClassInfo = StandingsBarTooltip(text=self.GetSecondaryBarHint())
     89         self.barIncrease.tooltipPanelClassInfo = StandingsBarTooltip(text=self.GetIncreaseBarHint())
     90 
     91     def GetBarHint(self):
     92         if idCheckers.IsCorporation(self.standingData.GetOwnerID1()):
     93             return GetByLabel('UI/Standings/StandingsBarHintToCorp', owner=self.standingData.GetOwnerID2(), corpName=self.standingData.GetOwner1Name(), standing=round(self.standingData.GetStanding2To1(), 2))
     94         else:
     95             return GetByLabel('UI/Standings/StandingsBarHint', owner=self.standingData.GetOwnerID2(), standing=round(self.standingData.GetStanding2To1(), 2))
     96 
     97     def GetSecondaryBarHint(self):
     98         standing, ownerID = self.GetStandingUsed()
     99         if idCheckers.IsCorporation(self.standingData.GetOwnerID1()):
    100             return GetByLabel('UI/Standings/StandingsBarHintToCorp', owner=ownerID, corpName=self.standingData.GetOwner1Name(), standing=round(standing, 2))
    101         else:
    102             return GetByLabel('UI/Standings/StandingsBarHint', owner=ownerID, standing=round(standing, 2))
    103 
    104     def ConstructBarSecondary(self):
    105         self.barSecondary = Container(name='barSecondary', parent=self.barCont, align=uiconst.TOLEFT_PROP, state=uiconst.UI_NORMAL, width=0.0, clipChildren=True)
    106         self.barSecondary.OnClick = self.OnSecondaryBarClick
    107         self.arrowSpriteSecondary = Sprite(name='arrowSpriteSecondary', bgParent=self.barSecondary, texturePath='res:/UI/Texture/Classes/Standings/arrows_20.png', opacity=0.2, tileX=True)
    108         self.barFillSecondary = Fill(name='barFillSecondary', bgParent=self.barSecondary, opacity=0.7)
    109 
    110     def OnSecondaryBarClick(self):
    111         _, ownerID = self.GetStandingUsed()
    112         OpenStandingsPanelOnOwnerByID(ownerID)
    113 
    114     def ConstructBarIncrease(self):
    115         self.barIncrease = Container(name='barIncrease', parent=self.barCont, align=uiconst.TOLEFT_PROP, state=uiconst.UI_NORMAL, width=0.0, left=0.5, clipChildren=True)
    116         self.arrowSpriteIncrease = Sprite(name='arrowSpriteIncrease', bgParent=self.barIncrease, texturePath='res:/UI/Texture/Classes/Standings/arrows_20.png', opacity=0.2, tileX=True)
    117         self.barFillIncrease = Fill(name='barFillIncrease', bgParent=self.barIncrease, opacity=0.7)
    118 
    119     def GetIncreaseBarHint(self):
    120         standing, ownerID = self.GetStandingUsed()
    121         standingsIncrease = self.GetStandingIncrease()
    122         increment = standingsIncrease - standing
    123         return GetByLabel('UI/Common/StandingsGain', standing=round(increment, 2))
    124 
    125     def UpdateThresholdIcons(self):
    126         fromID = self.standingData.GetOwnerID2()
    127         thresholdIDs = standingsUIUtil.GetStandingThresholdIDs(fromID=fromID, toID=self.standingData.GetOwnerID1())
    128         self._HideThresholdIconsNotPresent(thresholdIDs)
    129         self.iconsByStandingValue = {}
    130         self.hideZeroAxisLabel = False
    131         for thresholdTypeID, thresholdValueID in thresholdIDs:
    132             self._UpdateThresholdIcon(fromID, thresholdValueID, thresholdTypeID)
    133 
    134         if self.hideZeroAxisLabel:
    135             self.zeroAxisLabel.state = uiconst.UI_HIDDEN
    136         else:
    137             self.zeroAxisLabel.state = uiconst.UI_DISABLED
    138 
    139     def _UpdateThresholdIcon(self, fromID, thresholdValueID, thresholdTypeID):
    140         icon = self.GetThresholdIcon(thresholdTypeID, thresholdValueID)
    141         standingThreshold = self.GetThresholdValue(fromID, thresholdTypeID, thresholdValueID)
    142         isDuplicate = standingThreshold in self.iconsByStandingValue
    143         if isDuplicate and standingThreshold == 0:
    144             self.hideZeroAxisLabel = True
    145         self.iconsByStandingValue[standingThreshold] = icon
    146         if icon.standingThreshold != standingThreshold:
    147             self.AnimateThresholdIconPosition(icon, standingThreshold)
    148         func = self.GetFunctionByThresholdID(thresholdTypeID, fromID, thresholdValueID)
    149         standing, _ = self.GetStandingUsed()
    150         icon.Update(standing=standing, ownerID=fromID, standingThreshold=standingThreshold, func=func, isDuplicate=isDuplicate)
    151 
    152     def GetThresholdValue(self, fromID, thresholdTypeID, thresholdValueID):
    153         if idCheckers.IsNPCCharacter(fromID) and thresholdTypeID == standingUIConst.THRESHOLD_AGENTOFFERSMISSIONS:
    154             return self._GetThresholdValueForAgent(fromID)
    155         elif thresholdTypeID == standingUIConst.THRESHOLD_EPICARCUNLOCK:
    156             thresholdValue = self._GetThresholdValueForAgent(thresholdValueID)
    157             return max(thresholdValue, 0.0)
    158         elif thresholdTypeID == THRESHOLD_ATTACKEDINSPACE and fromID in (factionTriglavian, factionEDENCOM):
    159             return 0.0
    160         elif thresholdTypeID in (standingUIConst.THRESHOLD_STATIONSERVICE, standingUIConst.THRESHOLD_STATIONSERVICE_CORPORATION):
    161             return thresholdValueID
    162         else:
    163             return standingUIConst.THRESHOLD_VALUES_BY_THRESHOLDTYPE.get(thresholdTypeID)
    164 
    165     def _GetThresholdValueForAgent(self, agentID):
    166         agent = sm.GetService('agents').GetAgentByID(agentID)
    167         return agentUtil.GetAgentStandingThreshold(agent.level)
    168 
    169     def _HideThresholdIconsNotPresent(self, thresholdIDs):
    170         for thresholdID, icon in self.thresholdIconsByID.iteritems():
    171             if thresholdID not in thresholdIDs:
    172                 icon.StopAnimations()
    173                 icon.FadeOut()
    174 
    175     def AnimateThresholdIconPosition(self, icon, standingThreshold):
    176         left = self._GetIconLeftValue(standingThreshold)
    177         if icon.opacity > 0.1:
    178             animations.MorphScalar(icon, 'left', icon.left, left, duration=0.6)
    179         else:
    180             icon.StopAnimations()
    181             icon.left = left
    182 
    183     def GetStandingUsed(self):
    184         ownerID = self.standingData.GetOwnerID2()
    185         if idCheckers.IsNPCCharacter(ownerID):
    186             return GetAgentDerivedStanding(ownerID)
    187         if idCheckers.IsNPCCorporation(ownerID):
    188             if not standingsUIUtil.IsResourceWarsCorporation(ownerID):
    189                 return GetNPCCorpDerivedStanding(ownerID)
    190             else:
    191                 return (sm.GetService('standing').GetStandingWithSkillBonus(ownerID, session.charid), ownerID)
    192         else:
    193             return (self.standingData.GetStanding2To1(), ownerID)
    194 
    195     def GetStandingIncrease(self):
    196         return self.standingData.GetStandingIncrease()
    197 
    198     def _ConstructThresholdIcon(self, thresholdID):
    199         return ThresholdIcon(parent=self.thresholdIconCont, align=uiconst.TOPLEFT_PROP, width=ICONSIZE_THRESHOLD, height=ICONSIZE_THRESHOLD, thresholdID=thresholdID, padTop=-0.1, hasTopThresholdIcons=self.hasTopThresholdIcons, lineHeight=self.barHeight)
    200 
    201     def GetThresholdIcon(self, thresholdTypeID, thresholdValueID):
    202         thresholdID = (thresholdTypeID, thresholdValueID)
    203         if thresholdID not in self.thresholdIconsByID:
    204             icon = self._ConstructThresholdIcon(thresholdID)
    205             self.thresholdIconsByID[thresholdID] = icon
    206         return self.thresholdIconsByID[thresholdID]
    207 
    208     def _GetIconLeftValue(self, standingThreshold):
    209         return (standingThreshold + 10.0) / 20.0
    210 
    211     def GetFunctionByThresholdID(self, thresholdTypeID, fromID, thresholdValueID):
    212         if thresholdTypeID == standingUIConst.THRESHOLD_ATTACKEDINSPACE:
    213             return self.OnThresholdAttackedInSpace
    214         if thresholdTypeID == standingUIConst.THRESHOLD_NOACCESSTOAGENTS:
    215             return self.OnThresholdNoAccessToAgents
    216         if thresholdTypeID == standingUIConst.THRESHOLD_EPICARCUNLOCK:
    217             return lambda : self.OnThresholdEpicArcUnlock(thresholdValueID)
    218         if thresholdTypeID == standingUIConst.THRESHOLD_FACTIONALWARFARE:
    219             return self.OnThresholdFactionalWarfare
    220         if thresholdTypeID == standingUIConst.THRESHOLD_AGENTOFFERSMISSIONS:
    221             return self.OnThresholdAgentOffersMissions
    222         if thresholdTypeID == standingUIConst.THRESHOLD_NOACCESSTOAGENT:
    223             return self.OnThresholdNoAccessToAgent
    224         if thresholdTypeID in (standingUIConst.THRESHOLD_AGENTSLVL2,
    225          standingUIConst.THRESHOLD_AGENTSLVL3,
    226          standingUIConst.THRESHOLD_AGENTSLVL4,
    227          standingUIConst.THRESHOLD_AGENTSLVL5):
    228             if idCheckers.IsFaction(fromID):
    229                 return self.OnThresholdFactionAgents
    230             else:
    231                 return lambda : self.OnThresholdCorpAgents(standingUIConst.AGENT_LEVEL_BY_THRESHOLD_ID[thresholdTypeID])
    232         elif thresholdTypeID in standingUIConst.THRESHOLDS_RESOURCE_WARS:
    233             if standingsUIUtil.IsResourceWarsCorporation(fromID):
    234                 return self.OnThresholdResourceWars
    235         elif thresholdTypeID == standingUIConst.THRESHOLD_STATIONSERVICE:
    236             return self.OnThresholdStationService
    237 
    238     def OnThresholdNoAccessToAgent(self):
    239         self._ShowInfoForThisOwner(infoConst.TAB_AGENTINFO)
    240 
    241     def OnThresholdAgentOffersMissions(self):
    242         self._ShowInfoForThisOwner(infoConst.TAB_AGENTINFO)
    243 
    244     def OnThresholdFactionAgents(self):
    245         self._ShowInfoForThisOwner(infoConst.TAB_MEMBERS)
    246 
    247     def OnThresholdCorpAgents(self, agentLvl):
    248         self._ShowInfoForThisOwner(infoConst.TAB_AGENTS, abstractinfo=KeyVal(selectedLevel=agentLvl))
    249 
    250     def OnThresholdFactionalWarfare(self):
    251         factionID = self.standingData.GetOwnerID2() if session.warfactionid is None else None
    252         uicore.cmd.OpenMilitia(faction_id=factionID)
    253 
    254     def OnThresholdEpicArcUnlock(self, agentID):
    255         sm.GetService('agents').OpenDialogueWindow(agentID)
    256 
    257     def OnThresholdNoAccessToAgents(self):
    258         if idCheckers.IsFaction(self.standingData.GetOwnerID2()):
    259             self._ShowInfoForThisOwner(infoConst.TAB_MEMBEROFCORPS)
    260         else:
    261             self._ShowInfoForThisOwner(infoConst.TAB_AGENTS)
    262 
    263     def OnThresholdAttackedInSpace(self):
    264         self._ShowInfoForThisOwner(infoConst.TAB_SYSTEMS)
    265 
    266     def OnThresholdResourceWars(self):
    267         self._ShowInfoForThisOwner(infoConst.TAB_STANDINGS)
    268 
    269     def OnThresholdStationService(self):
    270         self._ShowInfoForThisOwner(infoConst.TAB_STATIONS)
    271 
    272     def _ShowInfoForThisOwner(self, tabID = None, abstractinfo = None):
    273         sm.GetService('info').ShowInfo(self.standingData.GetOwner2TypeID(), self.standingData.GetOwnerID2(), selectTabType=tabID, abstractinfo=abstractinfo)
    274 
    275     def Update(self, fromID, toID = None):
    276         if toID is None:
    277             toID = session.charid
    278         standing = sm.GetService('standing').GetStanding(fromID, toID)
    279         self.UpdateWithStandings(fromID, toID, standing)
    280 
    281     def UpdateWithStandings(self, fromID, toID, standing, increase = None):
    282         self.standingData = StandingData(toID, fromID, standing2to1=standing, standingIncrease=increase)
    283         self.UpdateThresholdIcons()
    284         self.Animate()
    285         self.SetTooltips()
    286 
    287     def Animate(self):
    288         standing = self.standingData.GetStanding2To1()
    289         duration = 0.3
    290         derivedStanding, _ = self.GetStandingUsed()
    291         self.AnimateBar(duration, standing, derivedStanding)
    292         if derivedStanding != standing and derivedStanding > 0.0:
    293             self.barSecondary.Show()
    294             self.AnimateSecondaryBar(duration, standing, derivedStanding)
    295         else:
    296             self.AnimateBarHide(self.barSecondary, duration)
    297         standingsIncrease = self.GetStandingIncrease()
    298         if standingsIncrease > standing:
    299             self.barIncrease.Show()
    300             self.AnimateIncreaseBar(standing, standingsIncrease, duration)
    301         else:
    302             self.AnimateBarHide(self.barIncrease, duration)
    303 
    304     def AnimateBarHide(self, bar, duration):
    305         if self.hasBarAnimation:
    306             animations.MorphScalar(bar, 'width', bar.width, 0.0, duration=duration)
    307         else:
    308             bar.width = 0.0
    309 
    310     def AnimateSecondaryBar(self, duration, standing, standingSecondary):
    311         width = self.GetSecondaryBarWidth(standing, standingSecondary)
    312         color = self.GetSecondaryBarColor(standingSecondary)
    313         if self.hasBarAnimation:
    314             animations.MorphScalar(self.barSecondary, 'width', self.barSecondary.width, width, duration=duration)
    315             animations.FadeTo(self.barSecondary, 1.0, OPACITY_BAR, curveType=uiconst.ANIM_WAVE, duration=duration * 2)
    316             animations.SpColorMorphTo(self.barFillSecondary, endColor=color[:3], duration=duration)
    317             animations.FadeTo(self.arrowSpriteSecondary, 0.0, OPACITY_ARROWSPRITE, duration=duration * 2, curveType=uiconst.ANIM_OVERSHOT2, timeOffset=duration / 2.0)
    318         else:
    319             self.barSecondary.width = width
    320             self.barSecondary.opacity = OPACITY_BAR
    321             self.barFillSecondary.color = color[:3]
    322             self.arrowSpriteSecondary.opacity = OPACITY_ARROWSPRITE
    323 
    324     def AnimateIncreaseBar(self, standing, standingsIncrease, duration):
    325         left, width = self.GetIncreaseBarLeftWidth(standing, standingsIncrease)
    326         color = standingUIConst.COLOR_INCREASE
    327         self.barIncrease.left = left
    328         animations.MorphScalar(self.barIncrease, 'width', self.barIncrease.width, width, duration=duration)
    329         animations.FadeTo(self.barIncrease, 1.0, OPACITY_BAR, curveType=uiconst.ANIM_WAVE, duration=duration * 2)
    330         animations.SpColorMorphTo(self.barFillIncrease, endColor=color[:3], duration=duration)
    331         animations.FadeTo(self.arrowSpriteIncrease, 0.0, OPACITY_ARROWSPRITE, duration=duration * 2, curveType=uiconst.ANIM_OVERSHOT2, timeOffset=duration / 2.0)
    332 
    333     def GetSecondaryBarColor(self, standingSecondary):
    334         return standingsUIUtil.GetStandingColor(standingSecondary)
    335 
    336     def GetBarColor(self, standing, standingSecondary):
    337         if standingSecondary and standingSecondary > standing:
    338             return Color.GRAY5
    339         else:
    340             return standingsUIUtil.GetStandingColor(standing)
    341 
    342     def GetSecondaryBarWidth(self, standing, standingSecondary):
    343         if standing < 0.0:
    344             return (standingSecondary + 10.0) / 40.0
    345         else:
    346             return (standingSecondary - standing) / 20.0
    347 
    348     def GetIncreaseBarLeftWidth(self, standing, standingsIncrease):
    349         left, width = self.GetBarLeftWidth(standing)
    350         increaseWidth = standingsIncrease / 20.0 if standingsIncrease > 0.05 else 0.0
    351         return (left, max(0.0, increaseWidth - width))
    352 
    353     def AnimateBar(self, duration, standing, standingSecondary):
    354         left, width = self.GetBarLeftWidth(standing)
    355         color = self.GetBarColor(standing, standingSecondary)
    356         self.arrowSprite.rotation = 0.0 if standing > 0.0 else math.pi
    357         if self.hasBarAnimation:
    358             animations.MorphScalar(self.bar, 'width', self.bar.width, width, duration=duration)
    359             animations.MorphScalar(self.bar, 'left', self.bar.left, left, duration=duration)
    360             animations.FadeTo(self.bar, 1.0, OPACITY_BAR, curveType=uiconst.ANIM_WAVE, duration=duration * 2)
    361             animations.SpColorMorphTo(self.barFill, endColor=color[:3], duration=duration)
    362             animations.FadeTo(self.arrowSprite, 0.0, OPACITY_ARROWSPRITE, duration=duration * 2, curveType=uiconst.ANIM_OVERSHOT4, timeOffset=duration / 2.0)
    363         else:
    364             self.bar.width = width
    365             self.bar.left = left
    366             self.bar.opacity = OPACITY_BAR
    367             self.barFill.color = color[:3]
    368             self.arrowSprite.opacity = OPACITY_ARROWSPRITE
    369 
    370     def GetBarLeftWidth(self, standing):
    371         width = standing / 20.0
    372         if width != 0.0:
    373             width = math.fabs(width)
    374         else:
    375             width = 1e-17
    376         left = 0.5 if standing > 0.0 else 0.5 - width
    377         return (left, width)
    378 
    379 
    380 class ThresholdIcon(Container):
    381     default_name = 'ThresholdIcon'
    382     default_state = uiconst.UI_NORMAL
    383     default_opacity = 0.0
    384     default_hasTopThresholdIcons = True
    385     default_lineHeight = 20
    386 
    387     def ApplyAttributes(self, attributes):
    388         Container.ApplyAttributes(self, attributes)
    389         thresholdID = attributes.thresholdID
    390         self.thresholdTypeID = thresholdID[0]
    391         self.hasTopThresholdIcons = attributes.get('hasTopThresholdIcons', self.default_hasTopThresholdIcons)
    392         self.lineHeight = attributes.get('lineHeight', self.default_lineHeight)
    393         self.standingThreshold = None
    394         self.ownerID = None
    395         self.func = None
    396         self.texturePath = standingsUIUtil.GetStandingThresholdIcon(thresholdID)
    397         self.glowSprite = GlowSprite(name='icon', parent=self, align=uiconst.TOALL, texturePath=self.texturePath, iconClass=Sprite)
    398         if not self.hasTopThresholdIcons:
    399             self.glowSprite.Hide()
    400             self.Disable()
    401         self.lineContainer = Container(name='DashedLineContainer', parent=self, align=uiconst.TOBOTTOM, left=-1, top=-self.lineHeight + 2, height=self.lineHeight)
    402         self.line = Sprite(name='DashedLine', parent=self.lineContainer, align=uiconst.CENTER, texturePath='res:/UI/Texture/Classes/Standings/thresholdLine.png', width=3, height=self.lineHeight, opacity=0.7, state=uiconst.UI_DISABLED)
    403 
    404     def Update(self, standing, ownerID, standingThreshold = None, func = None, isDuplicate = False):
    405         if standingThreshold is not None:
    406             self.standingThreshold = standingThreshold
    407         self.ownerID = ownerID
    408         self.func = func
    409         color, opacity = self.GetColorAndOpacity(standing)
    410         self.Enable()
    411         if self.hasTopThresholdIcons or isDuplicate:
    412             self.glowSprite.OnClick = self.func
    413             self.glowSprite.tooltipPanelClassInfo = self._BuildTooltip(color)
    414             animations.SpColorMorphTo(self.glowSprite.icon, endColor=color, duration=0.3)
    415         else:
    416             self.lineContainer.OnClick = self.func
    417             self.lineContainer.tooltipPanelClassInfo = self._BuildTooltip(color)
    418             self.SetState(uiconst.UI_PICKCHILDREN)
    419             self.lineContainer.SetState(uiconst.UI_NORMAL)
    420             self.height = ICONSIZE_THRESHOLD + self.lineHeight - PADDING_THRESHOLD_ICON
    421             self.lineContainer.top = 13
    422         animations.FadeTo(self, self.opacity, opacity, duration=0.3)
    423         if isDuplicate:
    424             self.top = 45
    425             self.line.Hide()
    426         else:
    427             self.top = 0
    428             self.line.Show()
    429 
    430     def GetColorAndOpacity(self, standing):
    431         if self.IsUnlocked(standing):
    432             opacity = OPACITY_ICON_ENABLED
    433             color = standingsUIUtil.GetStandingColor(standing)
    434         else:
    435             opacity = OPACITY_ICON_DISABLED
    436             color = Color.WHITE
    437         return (color, opacity)
    438 
    439     def _BuildTooltip(self, color):
    440         if self.thresholdTypeID in (standingUIConst.THRESHOLD_STATIONSERVICE, standingUIConst.THRESHOLD_STATIONSERVICE_CORPORATION):
    441             tooltipClass = ThresholdTooltipStationService
    442         else:
    443             tooltipClass = ThresholdTooltip
    444         return tooltipClass(self.texturePath, self.thresholdTypeID, self.ownerID, self.standingThreshold, color)
    445 
    446     def IsUnlocked(self, standing):
    447         if self.thresholdTypeID not in standingUIConst.THRESHOLDS_ACTIVATE_AT_LESS_THAN:
    448             isUnlocked = standing >= self.standingThreshold
    449         else:
    450             isUnlocked = standing <= self.standingThreshold
    451         return isUnlocked
    452 
    453     def FadeOut(self):
    454         self.Disable()
    455         opacity = 0.0
    456         animations.FadeTo(self, self.opacity, opacity, duration=0.3)
    457 
    458     def OnClick(self, *args):
    459         self.func()
    460 
    461 
    462 class ThresholdTooltip(TooltipBaseWrapper):
    463 
    464     def __init__(self, iconPath, thresholdTypeID, ownerID, standingThreshold, color):
    465         super(ThresholdTooltip, self).__init__()
    466         self.iconPath = iconPath
    467         self.thresholdTypeID = thresholdTypeID
    468         self.ownerID = ownerID
    469         self.standingThreshold = standingThreshold
    470         self.iconColor = color
    471 
    472     def CreateTooltip(self, parent, owner, idx):
    473         self.tooltipPanel = tooltips.TooltipPanel(parent=parent, owner=owner, idx=idx)
    474         self.tooltipPanel.state = uiconst.UI_NORMAL
    475         self.tooltipPanel.LoadGeneric2ColumnTemplate()
    476         self.tooltipPanel.AddSpriteLabel(texturePath=self.iconPath, label=GetByLabel(standingUIConst.LABELS_BY_THRESHOLDTYPEID[self.thresholdTypeID]), colSpan=2, bold=True, iconColor=self.iconColor)
    477         self.tooltipPanel.AddSpacer(1, 4, 2)
    478         self.tooltipPanel.AddLabelMedium(text='<b>%s</b>' % self.standingThreshold, color=GetStandingColor(self.standingThreshold), colSpan=2)
    479         self.tooltipPanel.AddSpacer(1, 4, 2)
    480         ownerName = cfg.eveowners.Get(self.ownerID).ownerName
    481         hint = standingUIConst.HINTS_BY_THRESHOLDTYPEID[self.thresholdTypeID]
    482         text = GetByLabel(hint, ownerName=ownerName)
    483         self.tooltipPanel.AddLabelMedium(text=text, colSpan=2, wrapWidth=200)
    484         return self.tooltipPanel
    485 
    486 
    487 class ThresholdTooltipStationService(ThresholdTooltip):
    488 
    489     def CreateTooltip(self, parent, owner, idx):
    490         self.tooltipPanel = tooltips.TooltipPanel(parent=parent, owner=owner, idx=idx)
    491         self.tooltipPanel.LoadGeneric4ColumnTemplate()
    492         self.tooltipPanel.AddSpriteLabel(texturePath=self.iconPath, label=GetByLabel(standingUIConst.LABELS_BY_THRESHOLDTYPEID[self.thresholdTypeID]), colSpan=4, bold=True, iconColor=self.iconColor)
    493         self.tooltipPanel.AddSpacer(1, 4, 4)
    494         self.tooltipPanel.AddLabelMedium(text=GetByLabel(standingUIConst.HINTS_BY_THRESHOLDTYPEID[self.thresholdTypeID]), colSpan=4, wrapWidth=200)
    495         values = GetStationServiceRestrictionsForThreshold(self.ownerID, self.standingThreshold, self.thresholdTypeID)
    496         for standingsValue, serviceID in values:
    497             self.tooltipPanel.AddSpacer(1, 4, 4)
    498             self.tooltipPanel.AddLabelMedium(text='<b>%s</b>' % standingsValue, color=GetStandingColor(standingsValue), colSpan=1)
    499             self.tooltipPanel.AddLabelMedium(text=standingsUIUtil.GetStationServiceLabel(serviceID), colSpan=3)
    500 
    501         return self.tooltipPanel
    502 
    503 
    504 class StandingsBarTooltip(TooltipBaseWrapper):
    505 
    506     def __init__(self, text):
    507         super(StandingsBarTooltip, self).__init__()
    508         self.text = text
    509 
    510     def CreateTooltip(self, parent, owner, idx):
    511         self.tooltipPanel = tooltips.TooltipPanel(parent=parent, owner=owner, idx=idx)
    512         self.tooltipPanel.LoadGeneric1ColumnTemplate()
    513         self.tooltipPanel.AddLabelMedium(text=self.text)
    514         return self.tooltipPanel