industryWnd.py (20446B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\industry\industryWnd.py 2 from math import pi 3 from itertools import chain 4 from carbonui.primitives.containerAutoSize import ContainerAutoSize 5 from carbonui.control.buttonIcon import ButtonIcon 6 from carbonui.control.window import Window 7 from eve.client.script.ui.control.historyBuffer import HistoryBuffer 8 from eve.client.script.ui.shared.industry.views.baseView import BaseView 9 import evetypes 10 import industry 11 from localization import GetByLabel 12 import carbonui.const as uiconst 13 from carbonui.primitives.container import Container 14 from eve.client.script.ui.shared.industry.jobsStrip import JobsStrip 15 from carbonui.control.tabGroup import TabGroup, GetTabData 16 from eve.client.script.ui.shared.industry.browserBlueprints import BrowserBlueprints 17 from eve.client.script.ui.shared.industry.browserJobs import BrowserJobs 18 from eve.client.script.ui.shared.industry.browserFacilities import BrowserFacilities 19 from eve.client.script.ui.shared.industry.browserResearch import BrowserResearch 20 from eve.common.script.util import industryCommon 21 import localization 22 import telemetry 23 import uthread 24 import blue 25 from carbonui.uicore import uicore 26 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst 27 FIXED_HEIGHT = 550 28 VIEW_HEIGHT = 418 29 TOP_HEIGHT = 468 30 TAB_BLUEPRINTS = 0 31 TAB_FACILITIES = 1 32 TAB_JOBS = 2 33 34 class Industry(Window): 35 __guid__ = 'form.Industry' 36 __notifyevents__ = ['OnIndustryLeftOrRightKey', 37 'OnIndustryDropData', 38 'OnIndustryRemoveBlueprint', 39 'OnIndustryJobClient', 40 'OnBlueprintReload', 41 'OnFacilitiesReloaded', 42 'OnBlueprintEntryDblClicked'] 43 default_captionLabelPath = 'UI/Industry/Industry' 44 default_descriptionLabelPath = 'UI/Industry/IndustryTooltip' 45 default_caption = localization.GetByLabel('UI/Industry/Industry') 46 default_windowID = 'industryWnd' 47 default_iconNum = 'res:/UI/Texture/WindowIcons/Industry.png' 48 default_height = 800 49 default_isStackable = False 50 default_minSize = (1004, 650) 51 default_soundOpen = 'ind_windowOpened' 52 53 def ApplyAttributes(self, attributes): 54 Window.ApplyAttributes(self, attributes) 55 blueprintID = attributes.Get('blueprintID', None) 56 blueprintTypeID = attributes.Get('blueprintTypeID', None) 57 bpData = attributes.Get('bpData', None) 58 self.history = HistoryBuffer() 59 self.jobData = None 60 self.pendingBlueprint = None 61 self.loadBlueprintThread = None 62 self.topCont = Container(name='topCont', parent=self.sr.main, align=uiconst.TOTOP, height=TOP_HEIGHT, clipChildren=True) 63 self.currView = BaseView(parent=self.topCont, align=uiconst.TOTOP, height=VIEW_HEIGHT) 64 self.jobsStrip = JobsStrip(parent=self.topCont, align=uiconst.TOTOP, padding=(5, -1, 7, 2), callback=self.OnBlueprintsSelected) 65 self.bottomCont = Container(name='bottomCont', parent=self.sr.main, controller=self, height=0.4, padding=(4, 0, 4, 0), callback=self.OnBlueprintsSelected) 66 cont = ContainerAutoSize(name='historyArrowCont', parent=self.sr.main, align=uiconst.TOPRIGHT, height=16, left=3, top=1) 67 self.expandViewBtn = ButtonIcon(name='expandViewBtn', parent=cont, align=uiconst.TORIGHT, width=16, iconSize=7, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', func=self.OnExpandViewBtn) 68 self.goForwardBtn = ButtonIcon(name='goForwardBtn', parent=cont, align=uiconst.TORIGHT, width=16, iconSize=16, padRight=5, texturePath='res:/UI/Texture/icons/38_16_224.png', func=self.OnForward, hint=localization.GetByLabel('UI/Control/EveWindow/Next')) 69 self.goBackBtn = ButtonIcon(name='goBackBtn', parent=cont, align=uiconst.TORIGHT, width=16, iconSize=16, texturePath='res:/UI/Texture/icons/38_16_223.png', func=self.OnBack, hint=localization.GetByLabel('UI/Control/EveWindow/Previous')) 70 self.browserCont = Container(name='browserCont', parent=self.bottomCont, padding=(0, 2, 0, 2)) 71 self.browserBlueprints = BrowserBlueprints(parent=self.browserCont, callback=self.OnBlueprintsSelected) 72 self.browserFacilities = BrowserFacilities(parent=self.browserCont, callback=self.OnFacilitySelected) 73 self.browserJobs = BrowserJobs(parent=self.browserCont, callback=self.OnJobSelected) 74 self.browserResearch = BrowserResearch(parent=self.browserCont) 75 tabs = (GetTabData(label=GetByLabel('UI/Industry/Blueprints'), panel=self.browserBlueprints, tabID='blueprints', hint=GetByLabel('UI/Industry/TabBlueprints'), uniqueName=pConst.UNIQUE_NAME_INDUSTRY_BP_BTN), 76 GetTabData(label=GetByLabel('UI/Industry/Facilities'), panel=self.browserFacilities, tabID='facilities', hint=GetByLabel('UI/Industry/TabFacilities'), uniqueName=pConst.UNIQUE_NAME_INDUSTRY_FACILITIES_TAB), 77 GetTabData(label=GetByLabel('UI/Industry/Jobs'), panel=self.browserJobs, tabID='jobs', hint=GetByLabel('UI/Industry/TabJobs'), uniqueName=pConst.UNIQUE_NAME_INDUSTRY_JOBS_TAB), 78 GetTabData(label=GetByLabel('UI/Journal/JournalWindow/Agents/Research'), panel=self.browserResearch, tabID='research', hint=GetByLabel('UI/Journal/JournalWindow/Agents/ResearchHint'), uniqueName=pConst.UNIQUE_NAME_INDUSTRY_RESEARCH_TAB)) 79 self.tabs = TabGroup(parent=self.browserCont, tabs=tabs, height=26, labelPadding=12, idx=0, padLeft=0, groupID='IndustryWindowBrowsers', autoselecttab=not self.IsBrowserCollapsed()) 80 self.expandBottomBtn = ButtonIcon(name='expandBottomBtn', parent=self.bottomCont, align=uiconst.TOPRIGHT, pos=(2, -3, 16, 16), iconSize=7, texturePath='res:/UI/Texture/classes/Neocom/arrowDown.png', func=self.OnExpandBottomBtn) 81 if blueprintID or blueprintTypeID: 82 self.ShowBlueprint(blueprintID, blueprintTypeID, bpData=bpData) 83 if self.IsViewCollapsed(): 84 self.CollapseView(animate=False) 85 else: 86 self.expandViewBtn.SetRotation(-pi) 87 if self.IsBrowserCollapsed(): 88 self.CollapseBrowser(animate=False) 89 else: 90 self.expandBottomBtn.SetRotation(-pi) 91 92 def Close(self, *args, **kwargs): 93 sm.GetService('industrySvc').DisconnectJob(self.jobData) 94 Window.Close(self, *args, **kwargs) 95 96 @telemetry.ZONE_METHOD 97 def OnNewJobData(self, branchHistory = True): 98 if self.jobData: 99 settings.user.ui.Set('IndustryCurrentActivityID', self.jobData.activityID) 100 self.jobsStrip.OnNewJobData(self.jobData) 101 self.currView.OnNewJobData(self.jobData) 102 self.browserBlueprints.OnNewJobData(self.jobData) 103 if branchHistory and self.jobData: 104 self.history.Append((self.jobData.blueprintID, self.jobData.blueprint.blueprintTypeID, self.jobData.activityID)) 105 self.UpdateHistoryButtons() 106 107 @telemetry.ZONE_METHOD 108 def OnBlueprintsSelected(self, bpData, activityID = None, branchHistory = True): 109 self.pendingBlueprint = (bpData, activityID, branchHistory) 110 if not self.loadBlueprintThread: 111 self.loadBlueprintThread = uthread.new(self._OnBlueprintSelected) 112 113 def _OnBlueprintSelected(self): 114 try: 115 while self.pendingBlueprint: 116 while uicore.uilib.Key(uiconst.VK_UP) or uicore.uilib.Key(uiconst.VK_DOWN): 117 blue.synchro.Yield() 118 119 bpData, activityID, branchHistory = self.pendingBlueprint 120 self.pendingBlueprint = None 121 if bpData.blueprintID: 122 sm.ScatterEvent('OnClientEvent_BlueprintLoaded', bpData.blueprintTypeID) 123 if activityID is None: 124 activityID = self._GetDefaultActivityID(bpData) 125 if self.jobData and self.jobData.blueprint.IsSameBlueprint(bpData): 126 if activityID == self.jobData.activityID and self.jobData.status != industry.STATUS_DELIVERED: 127 break 128 self.jobData = None 129 if bpData.jobID is not None: 130 jobData = sm.GetService('industrySvc').GetJobByID(bpData.jobID) 131 if jobData.status < industry.STATUS_COMPLETED: 132 self.jobData = sm.GetService('industrySvc').JobDataWithBlueprint(jobData) 133 if not self.jobData: 134 self.jobData = self.CreateJob(bpData, activityID) 135 if not self.pendingBlueprint: 136 self.browserBlueprints.OnActivitySelected(self.jobData.blueprintID, activityID) 137 self.OnNewJobData(branchHistory) 138 blue.synchro.SleepWallclock(500) 139 140 finally: 141 self.loadBlueprintThread = None 142 143 @telemetry.ZONE_METHOD 144 def OnFacilitySelected(self, facilityData): 145 if self.jobData: 146 self.jobData.facility = facilityData 147 148 @telemetry.ZONE_METHOD 149 def OnJobSelected(self, jobData): 150 if jobData.status > industry.STATUS_COMPLETED: 151 jobData = sm.GetService('industrySvc').RecreateJob(jobData) 152 else: 153 jobData = sm.GetService('industrySvc').JobDataWithBlueprint(jobData) 154 if not jobData: 155 return 156 self.jobData = jobData 157 self.OnNewJobData(jobData) 158 self.UpdateBlueprintBrowserActivitySelected() 159 160 @telemetry.ZONE_METHOD 161 def UpdateBlueprintBrowserActivitySelected(self): 162 if self.jobData: 163 self.browserBlueprints.OnActivitySelected(self.jobData.blueprintID, self.jobData.activityID) 164 165 def OnBlueprintEntryDblClicked(self): 166 if self.IsViewCollapsed(): 167 self.ExpandView() 168 169 def _GetDefaultActivityID(self, bpData): 170 bpProductType = bpData.GetProductOrBlueprintTypeID() 171 for activityID in chain((settings.user.ui.Get('IndustryCurrentActivityID', None),), industry.ACTIVITIES): 172 if activityID in bpData.activities: 173 if not bpData.facility: 174 return activityID 175 if bpData.facility.CanDoActivity(activityID, bpProductType): 176 return activityID 177 178 try: 179 return bpData.activities.keys()[0] 180 except Exception: 181 return industry.MANUFACTURING 182 183 @telemetry.ZONE_METHOD 184 def CreateJob(self, bpData, activityID): 185 return sm.GetService('industrySvc').CreateJob(bpData, activityID, bpData.facilityID) 186 187 def ShowBlueprint(self, blueprintID = None, blueprintTypeID = None, activityID = None, branchHistory = True, bpData = None): 188 if not bpData: 189 if blueprintID: 190 bpData = sm.GetService('blueprintSvc').GetBlueprintItem(blueprintID) 191 else: 192 bpData = sm.GetService('blueprintSvc').GetBlueprintTypeCopy(blueprintTypeID) 193 self.OnBlueprintsSelected(bpData, activityID=activityID, branchHistory=branchHistory) 194 195 def ShowJob(self, jobID): 196 if jobID: 197 self.OnJobSelected(sm.GetService('industrySvc').GetJobByID(jobID)) 198 199 @classmethod 200 def OpenOrShowBlueprint(cls, blueprintID = None, blueprintTypeID = None, bpData = None): 201 wnd = cls.GetIfOpen() 202 if wnd: 203 wnd.Maximize() 204 wnd.ShowBlueprint(blueprintID, blueprintTypeID, bpData=bpData) 205 if wnd.IsViewCollapsed(): 206 wnd.ExpandView() 207 uicore.registry.SetFocus(wnd) 208 else: 209 wnd = cls.Open(blueprintID=blueprintID, blueprintTypeID=blueprintTypeID, bpData=bpData) 210 wnd.Maximize() 211 212 def OnExpandBottomBtn(self, *args): 213 if self.IsBrowserCollapsed(): 214 self.ExpandBrowser() 215 else: 216 self.CollapseBrowser() 217 218 def OnExpandViewBtn(self, *args): 219 if self.IsViewCollapsed(): 220 self.ExpandView() 221 else: 222 self.CollapseView() 223 224 def ExpandView(self, animate = True): 225 settings.user.ui.Set('industryWndIsViewCollapsed', False) 226 sm.ScatterEvent('OnIndustryViewExpandCollapse') 227 self.expandViewBtn.SetRotation(-pi) 228 self.expandViewBtn.Disable() 229 self.topCont.Show() 230 if animate: 231 uicore.animations.MorphScalar(self.topCont, 'height', self.topCont.height, TOP_HEIGHT, duration=0.3) 232 uicore.animations.FadeIn(self.topCont, duration=0.3, sleep=True) 233 else: 234 self.topCont.height = TOP_HEIGHT 235 self.topCont.opacity = 1.0 236 self.expandBottomBtn.Show() 237 self.expandViewBtn.Enable() 238 239 def CollapseView(self, animate = True): 240 settings.user.ui.Set('industryWndIsViewCollapsed', True) 241 sm.ScatterEvent('OnIndustryViewExpandCollapse') 242 self.expandViewBtn.Disable() 243 self.expandViewBtn.SetRotation(0) 244 self.expandBottomBtn.Hide() 245 if animate: 246 uicore.animations.MorphScalar(self.topCont, 'height', self.topCont.height, 0, duration=0.3) 247 uicore.animations.FadeOut(self.topCont, duration=0.3, sleep=True) 248 else: 249 self.topCont.height = 0 250 self.topCont.opacity = 0.0 251 self.topCont.Hide() 252 self.expandViewBtn.Enable() 253 254 def IsViewCollapsed(self): 255 return settings.user.ui.Get('industryWndIsViewCollapsed', False) 256 257 def ExpandBrowser(self, animate = True): 258 if self.tabs.GetSelectedIdx() is None: 259 self.tabs.AutoSelect() 260 settings.user.ui.Set('industryWndIsBrowserCollapsed', False) 261 self.expandBottomBtn.SetRotation(-pi) 262 self.expandBottomBtn.Disable() 263 height = settings.user.ui.Get('industryWndExpandedHeight', self.default_height) 264 self.browserCont.Show() 265 if animate: 266 uicore.animations.MorphScalar(self, 'height', self.height, height, duration=0.3) 267 uicore.animations.FadeIn(self.browserCont, duration=0.3, sleep=True) 268 else: 269 self.height = height 270 self.browserCont.opacity = 1.0 271 self.UnlockHeight() 272 self.expandViewBtn.Show() 273 self.expandBottomBtn.Enable() 274 275 def CollapseBrowser(self, animate = True): 276 if not self.IsBrowserCollapsed(): 277 settings.user.ui.Set('industryWndExpandedHeight', self.height) 278 settings.user.ui.Set('industryWndIsBrowserCollapsed', True) 279 self.expandBottomBtn.Disable() 280 self.expandBottomBtn.SetRotation(0) 281 self.expandViewBtn.Hide() 282 if animate: 283 uicore.animations.MorphScalar(self, 'height', self.height, FIXED_HEIGHT, duration=0.3) 284 uicore.animations.FadeOut(self.browserCont, duration=0.3, sleep=True) 285 else: 286 self.height = FIXED_HEIGHT 287 self.browserCont.opacity = 0.0 288 self.LockHeight(FIXED_HEIGHT) 289 self.browserCont.Hide() 290 self.expandBottomBtn.Enable() 291 292 def IsBrowserCollapsed(self): 293 return settings.user.ui.Get('industryWndIsBrowserCollapsed', False) 294 295 def OnBack(self): 296 historyID = self.history.GoBack() 297 if historyID: 298 if uicore.uilib.mouseOver != self.goBackBtn: 299 self.goBackBtn.Blink() 300 self.ShowBlueprint(branchHistory=False, *historyID) 301 self.UpdateHistoryButtons() 302 303 def OnForward(self): 304 historyID = self.history.GoForward() 305 if historyID: 306 if uicore.uilib.mouseOver != self.goForwardBtn: 307 self.goForwardBtn.Blink() 308 self.ShowBlueprint(branchHistory=False, *historyID) 309 self.UpdateHistoryButtons() 310 311 def UpdateHistoryButtons(self): 312 if self.history.IsBackEnabled(): 313 self.goBackBtn.Enable() 314 else: 315 self.goBackBtn.Disable() 316 if self.history.IsForwardEnabled(): 317 self.goForwardBtn.Enable() 318 else: 319 self.goForwardBtn.Disable() 320 321 def OnMouseWheel(self, *args): 322 sm.ScatterEvent('OnIndustryWndMouseWheel') 323 324 def OnClick(self, *args): 325 sm.ScatterEvent('OnIndustryWndClick') 326 327 def CloseByUser(self, *args): 328 sm.GetService('audio').SendUIEvent('ind_windowClosed') 329 Window.CloseByUser(self, *args) 330 331 def _GetCurrentActivities(self): 332 currActivities = sorted(self.jobData.blueprint.activities.keys(), key=lambda x: industry.ACTIVITIES.index(x)) 333 return currActivities 334 335 def SelectPreviousActivity(self): 336 if not self.jobData or self.jobData.IsInstalled(): 337 return 338 currActivities = self._GetCurrentActivities() 339 idx = currActivities.index(self.jobData.activityID) 340 if idx == 0: 341 return 342 activityID = currActivities[idx - 1] 343 self._SelectActivity(activityID) 344 345 def SelectNextActivity(self): 346 if not self.jobData or self.jobData.IsInstalled(): 347 return 348 currActivities = self._GetCurrentActivities() 349 idx = currActivities.index(self.jobData.activityID) 350 if idx == len(currActivities) - 1: 351 return 352 activityID = currActivities[idx + 1] 353 self._SelectActivity(activityID) 354 355 def _SelectActivity(self, activityID): 356 self.browserBlueprints.OnActivitySelected(self.jobData.blueprintID, activityID) 357 self.OnBlueprintsSelected(self.jobData.blueprint, activityID) 358 359 def OnIndustryLeftOrRightKey(self, key): 360 if key == uiconst.VK_LEFT: 361 self.SelectPreviousActivity() 362 elif key == uiconst.VK_RIGHT: 363 self.SelectNextActivity() 364 365 def OnDropData(self, dragSource, dragData): 366 if not dragData: 367 return 368 data = dragData[0] 369 bpData = getattr(data, 'bpData', None) 370 if getattr(data, 'item', None): 371 itemID = getattr(data.item, 'itemID', None) 372 typeID = data.item.typeID 373 else: 374 typeID = getattr(data, 'typeID', None) 375 itemID = getattr(data, 'itemID', None) 376 if itemID or typeID: 377 categoryID = evetypes.GetCategoryID(typeID) 378 if industryCommon.IsBlueprintCategory(categoryID): 379 Industry.OpenOrShowBlueprint(itemID, typeID, bpData) 380 else: 381 raise UserError('ItemNotBlueprint', {'itemname': typeID}) 382 383 def OnIndustryDropData(self, dragSource, dragData): 384 self.OnDropData(dragSource, dragData) 385 386 def OnIndustryRemoveBlueprint(self): 387 self.jobData = None 388 self.OnNewJobData() 389 390 @telemetry.ZONE_METHOD 391 def OnIndustryJobClient(self, jobID = None, blueprintID = None, status = None, successfulRuns = None, **kwargs): 392 if self.destroyed: 393 return 394 if self.jobData and self.jobData.jobID == jobID: 395 if status == industry.STATUS_CANCELLED: 396 self.jobData = None 397 else: 398 self.jobData.status = status 399 self.jobData.successfulRuns = successfulRuns 400 self.OnNewJobData() 401 elif self.jobData and self.jobData.blueprintID == blueprintID: 402 self.jobData = sm.GetService('industrySvc').GetJobByID(jobID) 403 self.OnNewJobData() 404 if status in (industry.STATUS_INSTALLED, industry.STATUS_READY): 405 if self.tabs.GetSelectedIdx() != TAB_JOBS: 406 self.tabs.BlinkPanelByName(localization.GetByLabel('UI/Industry/Jobs')) 407 if status == industry.STATUS_INSTALLED: 408 if self.tabs.GetSelectedIdx() == TAB_BLUEPRINTS: 409 self.browserBlueprints.SetFocus() 410 411 def OnBlueprintReload(self, ownerID): 412 if self.jobData and self.jobData.ownerID == ownerID: 413 self.Reload() 414 415 def OnFacilitiesReloaded(self, facilityIDs): 416 if facilityIDs is None: 417 self.Reload(force=True) 418 elif self.jobData: 419 if self.jobData.facilityID in facilityIDs: 420 self.Reload(force=True) 421 return 422 423 def Reload(self, force = False): 424 try: 425 jobData = self.jobData 426 if jobData: 427 if force: 428 self.jobData = None 429 if jobData.jobID: 430 self.ShowJob(jobData.jobID) 431 else: 432 self.ShowBlueprint(blueprintID=jobData.blueprint.blueprintID, blueprintTypeID=jobData.blueprint.blueprintTypeID, activityID=jobData.activityID, bpData=jobData.blueprint) 433 except UserError: 434 self.OnIndustryRemoveBlueprint() 435 436 def OnStartMinimize_(self, *args): 437 sm.ScatterEvent('OnIndustryWindowMinimized') 438 439 def Maximize(self, *args, **kwds): 440 sm.ScatterEvent('OnIndustryWindowMaximized') 441 Window.Maximize(self, *args, **kwds)