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

changesWarning.py (6001B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\sov\sovHub\changesWarning.py
      2 import carbonui
      3 import carbonui.text.styles
      4 import eveformat
      5 import eveicon
      6 import evetypes
      7 import mathext
      8 from carbonui import TextColor
      9 from carbonui.control.scrollContainer import ScrollContainer
     10 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     11 from carbonui.primitives.layoutGrid import LayoutGrid
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.text.custom import TextCustom
     14 from eve.client.script.ui import eveColor
     15 from localization import GetByLabel
     16 from sovereignty.client.sovHub.hubUtil import GetPowerStateNameFromState, GetIconTexturePathForReagent
     17 from sovereignty.client.sovHub.upgradeChanges import GetChanges, GetPriorityChanges, GetStartupCost
     18 from sovereignty.upgrades.const import POWER_STATE_OFFLINE, POWER_STATE_ONLINE
     19 
     20 def LoadSaveBtnTooltipPanel(tooltipPanel, hubController):
     21     tooltipPanel.columns = 1
     22     content = _GetTooltipContent(hubController.installedUpgradesSimulated, hubController.originalInstalledUpgradeData, tooltipPanel)
     23     tooltipPanel.LoadStandardSpacing()
     24     if content is None:
     25         hint = GetByLabel('UI/Sovereignty/SovHub/HubWnd/NoChangesToSave')
     26         tooltipPanel.AddLabelMedium(text=hint, wrapWidth=240)
     27         return
     28     tooltipPanel.margin = (8, 16, 8, 16)
     29 
     30 
     31 def _GetTooltipContent(currentUpgrades, originalUpgrades, parent):
     32     changesInOnline, newlyAdded, powerStateChanges = GetChanges(currentUpgrades, originalUpgrades, False)
     33     priorityChanges = GetPriorityChanges(currentUpgrades, originalUpgrades)
     34     if not changesInOnline and not newlyAdded and not powerStateChanges and not priorityChanges:
     35         return
     36     newlyPowerStateByTypeID = {x[0]:x[1] for x in newlyAdded}
     37     powerStateChangesByTypeID = {x[0]:x for x in powerStateChanges}
     38     priorityChangesByTypeID = {x[0]:x for x in priorityChanges}
     39     layoutGrid = LayoutGrid(parent=parent, columns=4, cellPadding=(8, 0), cellSpacing=(0, 8))
     40     for idx, nUpgrade in enumerate(currentUpgrades):
     41         nTypeID = nUpgrade.typeID
     42         stateTextList = []
     43         if nTypeID in newlyPowerStateByTypeID:
     44             powerState = newlyPowerStateByTypeID[nTypeID]
     45             stateTextList = ['New,', GetPowerStateText(powerState)]
     46         elif nTypeID in powerStateChangesByTypeID:
     47             _, oldState, newState = powerStateChangesByTypeID[nTypeID]
     48             stateTextList = [GetPowerStateText(oldState), u'\u2192', GetPowerStateText(newState)]
     49         prioChange = priorityChangesByTypeID.get(nTypeID, None)
     50         diffText, texturePath = GetDiffTextAndTexturePath(prioChange)
     51         if texturePath:
     52             sprite = Sprite(parent=layoutGrid, name='arrowSprite', align=carbonui.Align.CENTERLEFT, pos=(0, 0, 16, 16), texturePath=texturePath, color=eveColor.TUNGSTEN_GREY)
     53             TextCustom(text=diffText, parent=sprite.parent, left=-5, align=carbonui.Align.CENTERLEFT, color=TextColor.SECONDARY, fontsize=10)
     54         else:
     55             layoutGrid.AddCell()
     56         carbonui.text.styles.TextBody(text=idx + 1, parent=layoutGrid, align=carbonui.Align.CENTERLEFT)
     57         carbonui.text.styles.TextBody(text=evetypes.GetName(nTypeID), parent=layoutGrid, align=carbonui.Align.CENTERLEFT)
     58         text = ' '.join(stateTextList)
     59         carbonui.text.styles.TextBody(text=text, parent=layoutGrid, align=carbonui.Align.CENTERLEFT)
     60 
     61     startupCosts = GetStartupCost(currentUpgrades, originalUpgrades)
     62     added = False
     63     for typeID, cost in startupCosts:
     64         if added:
     65             text = ''
     66         else:
     67             label = carbonui.text.styles.TextBody(text=' ', align=carbonui.Align.CENTERLEFT)
     68             layoutGrid.AddCell(label, colSpan=layoutGrid.columns)
     69             text = GetByLabel('UI/Sovereignty/SovHub/HubWnd/ColumnStartupCost')
     70         label = carbonui.text.styles.TextBody(text=text, align=carbonui.Align.CENTERLEFT)
     71         layoutGrid.AddCell(label, colSpan=layoutGrid.columns - 1)
     72         cont = ContainerAutoSize(align=carbonui.Align.CENTERRIGHT)
     73         Sprite(parent=cont, name='reagentSprite', align=carbonui.Align.CENTERLEFT, pos=(0, 0, 16, 16), texturePath=GetIconTexturePathForReagent(typeID), color=eveColor.TUNGSTEN_GREY)
     74         carbonui.text.styles.TextBody(parent=cont, text=cost, left=16, align=carbonui.Align.CENTERLEFT)
     75         layoutGrid.AddCell(cont, colSpan=layoutGrid.columns)
     76         added = True
     77 
     78     return layoutGrid
     79 
     80 
     81 def GetDiffTextAndTexturePath(prioChange):
     82     texturePath = None
     83     diffText = ''
     84     if prioChange:
     85         _, beforeIdx, afterIdx = prioChange
     86         diff = afterIdx - beforeIdx
     87         if diff > 0:
     88             texturePath = eveicon.chevron_down
     89         elif diff < 0:
     90             texturePath = eveicon.chevron_up
     91         diffText = beforeIdx + 1
     92     return (diffText, texturePath)
     93 
     94 
     95 def GetPowerStateText(powerState):
     96     powerStateName = GetPowerStateNameFromState(powerState)
     97     if powerState == POWER_STATE_ONLINE:
     98         return powerStateName
     99     if powerState == POWER_STATE_OFFLINE:
    100         return eveformat.color(powerStateName, eveColor.GUNMETAL_HEX)
    101     return eveformat.color(powerStateName, eveColor.DANGER_RED)
    102 
    103 
    104 class ConfirmSovHubChanges(ScrollContainer):
    105     default_align = carbonui.Align.TOALL
    106     setWidth = True
    107 
    108     def ApplyAttributes(self, attributes):
    109         self._contentWidth = 0
    110         self._contentHeight = 0
    111         super(ConfirmSovHubChanges, self).ApplyAttributes(attributes)
    112         self.align = carbonui.Align.TOALL
    113         currentUpgrades = attributes.messageData['currentUpgrades']
    114         originalUpgrades = attributes.messageData['originalUpgrades']
    115         content = _GetTooltipContent(currentUpgrades, originalUpgrades, self)
    116         self._contentWidth, self._contentHeight = content.GetAbsoluteSize()
    117 
    118     def GetContentHeight(self):
    119         return mathext.clamp(self._contentHeight, 100, 300)
    120 
    121     def GetContentWidth(self):
    122         return mathext.clamp(self._contentWidth + 20, 300, 600)