structureHackingResult.py (9446B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\structureHackingResult.py 2 import carbonui.uiconst as uiconst 3 import trinity 4 import uthread 5 from carbon.common.script.util.commonutils import StripTags 6 from carbon.common.script.util.format import FmtDate 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.layoutGrid import LayoutGrid 9 from carbonui.primitives.sprite import StreamingVideoSprite 10 from carbonui.util.color import Color 11 from eve.client.script.ui.control.eveLabel import Label 12 from carbonui.control.window import Window 13 from carbonui.uicore import uicore 14 from eve.client.script.ui.hacking.hackingUIConst import COLOR_WINDOW_BG 15 from eve.client.script.ui.structure.structureBrowser.controllers.reinforceTimersBundle import GetHourText 16 from localization import GetByLabel 17 from menu import MenuLabel 18 import random 19 import blue 20 HOUR_LABEL = GetByLabel('UI/Structures/ReinforcementHour') 21 NEW_HOUR_LABEL = GetByLabel('UI/Structures/NewReinforcementHour') 22 NEW_HOUR_SHORT_LABEL = GetByLabel('UI/Structures/NewReinforcementHourShort') 23 24 class StructureHackingResultWnd(Window): 25 default_name = 'structureHackingResultWnd' 26 default_windowID = 'structureHackingResultWnd' 27 default_width = 898 28 default_height = 631 29 default_fixedWidth = default_width 30 default_fixedHeight = default_height 31 default_isCollapseable = False 32 default_captionLabelPath = 'UI/Structures/StructureHackingResults' 33 34 def ApplyAttributes(self, attributes): 35 Window.ApplyAttributes(self, attributes) 36 self.SetMinSize([350, 270]) 37 innerMain = Container(name='innerMain', parent=self.sr.main, aling=uiconst.TOALL, padding=10) 38 self.centerCont = Container(name='centerCont', parent=innerMain, align=uiconst.CENTER, pos=(0, 0, 1, 1)) 39 self.labelLayoutGrid = LayoutGrid(parent=self.centerCont, margin=0, cellSpacing=(20, 0), columns=2, align=uiconst.CENTERLEFT) 40 self.backgroundVideo = StreamingVideoSprite(bgParent=innerMain, videoPath='res:/video/hacking/bgLoop_alpha.webm', videoLoop=True, spriteEffect=trinity.TR2_SFX_COPY, color=COLOR_WINDOW_BG) 41 self.resultLabelHour = self.GetLabel(name='resultLabelHour', align=uiconst.CENTERRIGHT, text=HOUR_LABEL) 42 self.resultLabelHourValue = self.GetLabel(name='resultLabelHourValue', align=uiconst.CENTERLEFT) 43 self.labelLayoutGrid.AddCell(cellObject=Container(pos=(0, 0, 0, 20), align=uiconst.TOPLEFT), colSpan=2) 44 self.resultLabelNextHour = self.GetLabel(name='resultLabelNextHour', align=uiconst.CENTERRIGHT, fontsize=20) 45 self.resultLabelNextHourValue = self.GetLabel(name='resultLabelNextHourValue', align=uiconst.CENTERLEFT, fontsize=20) 46 self.takesEffectLabel = self.GetLabel(name='takesEffect', align=uiconst.CENTERRIGHT, text=GetByLabel('UI/StructureBrowser/TakesEffect'), fontsize=20) 47 self.takesEffectLabelValue = self.GetLabel(name='takesEffectLabelValue', align=uiconst.CENTERLEFT, text='', fontsize=20) 48 self.allLabels = [self.resultLabelHour, 49 self.resultLabelHourValue, 50 self.takesEffectLabel, 51 self.takesEffectLabelValue, 52 self.resultLabelNextHour, 53 self.resultLabelNextHourValue] 54 self.leftWidth = self._GetTextWidth(self.resultLabelHour) + 20 55 self.structureID = attributes.structureID 56 self.structureTypeID = attributes.structureTypeID 57 self.reinforceTimers = attributes.reinforceTimers 58 if self.structureID and self.reinforceTimers: 59 self.LoadWndWithResult(self.structureID, self.reinforceTimers, self.structureTypeID) 60 61 def GetLabel(self, name, align, text = '', fontsize = 30): 62 label = Label(name=name, parent=self.labelLayoutGrid, align=align, text=text, bold=True, fontsize=fontsize, idx=0, color=Color.WHITE) 63 label.SetAlpha(0.75) 64 return label 65 66 def _GetTextWidth(self, label, text = None): 67 if text == None: 68 text = label.text 69 return uicore.font.GetTextWidth('<b>%s</b>' % text, label.fontsize) 70 71 def LoadWndWithResult(self, structureID, reinforceTimers, structureTypeID): 72 self.structureID = structureID 73 self.structureTypeID = structureTypeID 74 self.reinforceTimers = reinforceTimers 75 uicore.animations.FadeTo(self, 0, 1.0) 76 textHour = GetByLabel('UI/Structures/ReinforcementHour') 77 self.resultLabelHour.text = textHour 78 uthread.new(self.AnimateResults_thread, reinforceTimers) 79 self.SetWindowPosition() 80 81 def AnimateResults_thread(self, reinforceTimers): 82 resultHour = reinforceTimers.GetReinforceHour() 83 hourText = GetHourText(resultHour) 84 totalWidth = self.leftWidth 85 self.labelLayoutGrid.left = int(-totalWidth / 2) 86 isThereNewHour = self.IsNewHour(reinforceTimers, resultHour) 87 for each in self.allLabels: 88 each.display = False 89 90 self.resultLabelNextHour.text = ' ' if isThereNewHour else '' 91 self._AdjustTextLocation(reinforceTimers, isThereNewHour, hourText) 92 allLetters = GetByLabel('UI/Structures/AllLetters') 93 self.resultLabelHour.display = True 94 self._AnimateTime(hourText, self.resultLabelHourValue) 95 applyNext = reinforceTimers.GetNextApply() 96 if applyNext: 97 resultNextHour = reinforceTimers.GetNextReinforceHour() 98 nextHourText = GetHourText(resultNextHour) 99 if isThereNewHour: 100 self.resultLabelNextHour.display = True 101 text = NEW_HOUR_LABEL 102 self.resultLabelNextHour.text = text 103 self._AnimateTime(nextHourText, self.resultLabelNextHourValue) 104 self.takesEffectLabel.display = True 105 dateText = FmtDate(applyNext, 'ls') 106 self._AnimateWord(dateText, self.takesEffectLabelValue, allLetters='0123456789', sleep=30) 107 108 def IsNewHour(self, reinforceTimers, currentHour): 109 resultNextHour = reinforceTimers.GetNextReinforceHour() 110 return currentHour != resultNextHour 111 112 def _AdjustTextLocation(self, reinforceTimers, isThereNewHour, hourText): 113 leftTextWidths = [self._GetTextWidth(self.resultLabelHour)] 114 if isThereNewHour: 115 leftTextWidths.append(self._GetTextWidth(self.resultLabelNextHour, text=NEW_HOUR_LABEL)) 116 leftWidth = max(leftTextWidths) 117 rightTextWidths = [0] 118 applyNext = reinforceTimers.GetNextApply() 119 if applyNext: 120 dateText = FmtDate(applyNext, 'ls') 121 rightTextWidths.append(self._GetTextWidth(self.takesEffectLabelValue, text=dateText)) 122 rightWidth = max(rightTextWidths) 123 totalWidth = leftWidth + rightWidth + 20 124 self.labelLayoutGrid.left = int(-totalWidth / 2) 125 126 def _AnimateWord(self, dayName, dayLabel, allLetters, sleep = 50): 127 dayLabel.display = True 128 lenDayName = len(dayName) 129 for x in xrange(lenDayName * 2): 130 current = x / 2 131 dayRandomText = dayName[:current] 132 for _ in xrange(lenDayName - current): 133 nextChar = random.choice(allLetters) 134 if x == 0: 135 nextChar = nextChar.upper() 136 dayRandomText += nextChar 137 dayLabel.text = dayRandomText 138 139 blue.synchro.SleepWallclock(sleep) 140 141 dayLabel.text = dayName 142 143 def _AnimateTime(self, hourText, hourLabel): 144 hourLabel.display = True 145 for _ in xrange(5): 146 h = random.randint(0, 23) 147 m = random.randint(0, 59) 148 timeText = '%.2d:%.2d' % (h, m) 149 hourLabel.text = timeText 150 blue.synchro.SleepWallclock(100) 151 hourLabel.text = hourText 152 153 def _GetWindowPosition(self): 154 windowSizesAndPositions = settings.char.windows.Get('windowSizesAndPositions_1', {}).get('HackingWindow') 155 if windowSizesAndPositions: 156 return windowSizesAndPositions[:2] 157 dw, dh = uicore.desktop.width, uicore.desktop.height 158 return ((dw - self.width) / 2, (dh - self.height) / 2) 159 160 def PostApplyAttributes(self, attributes): 161 Window.PostApplyAttributes(self, attributes) 162 self.SetWindowPosition() 163 164 def SetWindowPosition(self): 165 l, t = self._GetWindowPosition() 166 self.left = l 167 self.top = t 168 169 def GetMenu(self, *args): 170 m = [(MenuLabel('UI/Fitting/FittingWindow/FittingManagement/ExportToClipboard'), self.CopyToClipboard)] 171 m += Window.GetMenu(self, *args) 172 return m 173 174 def CopyToClipboard(self, *args): 175 resultHour = self.reinforceTimers.GetReinforceHour() 176 hourText = GetHourText(resultHour) 177 structureInfo = sm.GetService('structureDirectory').GetStructureInfo(self.structureID) 178 results = [structureInfo.itemName, '%s\t%s' % (HOUR_LABEL, hourText)] 179 applyNext = self.reinforceTimers.GetNextApply() 180 if applyNext: 181 resultNextHour = self.reinforceTimers.GetNextReinforceHour() 182 nextHourText = GetHourText(resultNextHour) 183 effectText = GetByLabel('UI/StructureBrowser/TakesEffect') 184 dateText = FmtDate(applyNext, 'ls') 185 results += ['%s\t%s' % (NEW_HOUR_LABEL, nextHourText), '%s\t%s' % (effectText, dateText)] 186 resultText = '\n'.join(results) 187 strippedText = StripTags(resultText) 188 if strippedText: 189 blue.pyos.SetClipboardData(strippedText)