podGuideUI.py (14053B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\podGuide\podGuideUI.py 2 import carbonui.const as uiconst 3 import localization 4 from carbonui.control.scrollContainer import ScrollContainer 5 from carbonui.primitives.fill import Fill 6 from carbonui.primitives.flowcontainer import FlowContainer 7 from carbonui.primitives.sprite import Sprite 8 from localization import GetByMessageID 9 from eve.client.script.ui.control.eveEditPlainText import EditPlainText 10 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveCaptionMedium, EveCaptionLarge, EveLabelLargeBold 11 from carbonui.control.window import Window 12 from carbonui.primitives.container import Container 13 from eve.client.script.ui.podGuide.podGuideUtil import GetTerms, GetTermByID, GetCategories 14 from eve.client.script.ui.control.historyBuffer import HistoryBuffer 15 from carbonui.uicore import uicore 16 17 class PodGuideWindow(Window): 18 default_windowID = 'PodGuideWindow' 19 default_iconNum = 'res:/UI/Texture/icons/38_16_224.png' 20 21 def ApplyAttributes(self, attributes): 22 Window.ApplyAttributes(self, attributes) 23 self.sr.clippedIcon = Sprite(parent=self.sr.iconClipper, name='windowIcon', pos=(-22, -36, 150, 150), texturePath='res:/ui/Texture/WindowIcons/help.png', opacity=0.1) 24 termID = attributes.termID 25 self.history = HistoryBuffer() 26 self.headerCont = Container(name='headerCont', parent=self.sr.main, align=uiconst.TOTOP, height=70) 27 categories = GetCategories() 28 self.podGuideNavigation = PodGuideNavigation(name='podGuideNavigation', parent=self.headerCont, align=uiconst.TOALL, categories=categories, callback=self.LoadPanelByID) 29 self.CustomizeHeader() 30 self.contentCont = ScrollContainer(name='contentCont', parent=self.sr.main, align=uiconst.TOALL, padding=4) 31 self.SetupContentPanel() 32 self.InitializeData() 33 if termID: 34 self.LoadPanelByID(termID) 35 36 def CustomizeHeader(self): 37 self.sr.headerParent.display = False 38 self.sr.caption = EveCaptionMedium(text='Pod Guide', parent=self.podGuideNavigation, left=18, top=22, state=uiconst.UI_DISABLED) 39 40 def SetupContentPanel(self): 41 self.podGuideContent = PodGuideContent(parent=self.contentCont, align=uiconst.TOTOP) 42 self.navigationButtons = NavigationButtons(parent=self.podGuideContent, left=0, top=0, align=uiconst.TOPRIGHT, buttonSize=19, idx=0, backBtnFunc=self.OnBackButtonCallback, forwardBtnFunc=self.OnForwardButtonCallback, padTop=8) 43 self.UpdateHistoryButtons() 44 45 def UpdateHistoryButtons(self): 46 historyBuffer = self.history 47 if historyBuffer.IsBackEnabled(): 48 self.navigationButtons.EnableBackBtn() 49 else: 50 self.navigationButtons.DisableBackBtn() 51 if historyBuffer.IsForwardEnabled(): 52 self.navigationButtons.EnableForwardBtn() 53 else: 54 self.navigationButtons.DisableForwardBtn() 55 56 def InitializeData(self): 57 self.allInfo = GetTerms() 58 59 def LoadPanelByID(self, termID, storeInHistory = True): 60 termInfo = GetTermByID(termID) 61 self.LoadPanel(termInfo) 62 if storeInHistory: 63 self.history.Append(termInfo.termID) 64 self.UpdateHistoryButtons() 65 66 def LoadPanel(self, termInfo): 67 self.podGuideContent.LoadContent(termInfo) 68 69 def OnBack(self): 70 wasClicked = self.navigationButtons.OnBackBtnClicked() 71 if wasClicked: 72 self.navigationButtons.AnimateBackBtn() 73 74 def OnBackButtonCallback(self): 75 previousTermID = self.history.GoBack() 76 if previousTermID: 77 self.LoadPanelByID(previousTermID, storeInHistory=False) 78 79 def OnForward(self): 80 wasClicked = self.navigationButtons.OnForwardBtnClicked() 81 if wasClicked: 82 self.navigationButtons.AnimateForwardBtn() 83 84 def OnForwardButtonCallback(self): 85 nextTermID = self.history.GoForward() 86 if nextTermID: 87 self.LoadPanelByID(nextTermID, storeInHistory=False) 88 89 def UpdateHistoryData(self, termInfo): 90 self.history.UpdateCurrent(termInfo.termID) 91 92 93 class PodGuideNavigation(Container): 94 clipChildren = True 95 96 def ApplyAttributes(self, attributes): 97 Container.ApplyAttributes(self, attributes) 98 Fill(bgParent=self, color=(1, 1, 1, 0.03)) 99 categories = attributes.categories 100 self.callback = attributes.callback 101 self.flowCont = FlowContainer(name='flowCont', parent=self, align=uiconst.TOBOTTOM, autoHeight=True, centerContent=True, contentSpacing=(10, 0)) 102 self.LoadCategories(categories) 103 104 def LoadCategories(self, categories, *args): 105 self.flowCont.Flush() 106 tempAllTerms = GetTerms() 107 for eachCategorID, eachCategoryInfo in categories.iteritems(): 108 catInfo = eachCategoryInfo['categoryInfo'] 109 categoryNameID = catInfo.groupName 110 categoryName = GetByMessageID(categoryNameID) 111 megaMenuOptions = [] 112 for eachSubGroup in eachCategoryInfo.get('subgroups', []): 113 groupNameID = eachSubGroup.groupName 114 groupName = GetByMessageID(groupNameID) 115 termsInGroup = tempAllTerms.get(eachSubGroup.groupID, []) 116 termsInfoList = [] 117 for eachTerm in termsInGroup: 118 termTitleID = eachTerm.termTitleID 119 termName = GetByMessageID(termTitleID) 120 termsInfoList.append({'text': termName, 121 'callback': self.callback, 122 'args': eachTerm.termID}) 123 124 megaMenuGroup = {'headerInfo': {'groupName': groupName}, 125 'entryInfoList': termsInfoList} 126 megaMenuOptions.append(megaMenuGroup) 127 128 NavigationButtonInWindow(parent=self.flowCont, megaMenuOptions=megaMenuOptions, categoryInfo={'categoryName': categoryName}) 129 130 def Close(self, *args): 131 Container.Close(self, *args) 132 uicore.megaMenuManager.CloseMegaMenu() 133 134 135 class NavigationButtonBase(Container): 136 default_align = uiconst.NOALIGN 137 default_height = 20 138 textPadding = 10 139 default_state = uiconst.UI_DISABLED 140 141 def ApplyAttributes(self, attributes): 142 Container.ApplyAttributes(self, attributes) 143 self.categoryInfo = attributes.categoryInfo 144 text = self.categoryInfo['categoryName'] 145 textLabel = EveLabelLargeBold(parent=self, text=str(text), align=uiconst.CENTER) 146 self.width = textLabel.textwidth + 2 * self.textPadding 147 self.hiliteFill = Fill(bgParent=self, opacity=0.0) 148 149 150 class NavigationButtonInWindow(NavigationButtonBase): 151 default_state = uiconst.UI_NORMAL 152 153 def ApplyAttributes(self, attributes): 154 NavigationButtonBase.ApplyAttributes(self, attributes) 155 self.megaMenuOptions = attributes.megaMenuOptions 156 157 def OnMouseEnter(self, *args): 158 uicore.megaMenuManager.CloseMegaMenu() 159 al, at, ah, aw = self.GetAbsolute() 160 uicore.megaMenuManager.ShowMegaMenu(options=self.megaMenuOptions, categoryInfo=self.categoryInfo, pos=(al, 161 at, 162 0, 163 0), openingButtonClass=NavigationButtonBase) 164 165 def OnMouseExit(self, *args): 166 self.hiliteFill.opacity = 0.0 167 currentMegaMenu = uicore.megaMenuManager.GetCurrentMegaMenu() 168 isMouseOverMegaMenu = currentMegaMenu.IsMouseOverMenu() 169 if not isMouseOverMegaMenu: 170 uicore.megaMenuManager.CloseMegaMenu() 171 172 173 class PodGuideContent(Container): 174 MIN_RIGHT_SIDE_WIDTH = 100 175 176 def ApplyAttributes(self, attributes): 177 Container.ApplyAttributes(self, attributes) 178 padding = 30 179 self.termHeaderLabel = EveCaptionLarge(name='termHeaderLabel', parent=self, align=uiconst.TOTOP, text='', padLeft=padding + 4, padTop=20) 180 self.contentRightCont = Container(name='contentRightCont', parent=self, align=uiconst.TORIGHT, width=128, padRight=36) 181 self.height = 300 182 self.longTextEdit = EditPlainText(name='longTextEdit', parent=self, align=uiconst.TOTOP, readonly=True, setvalue='abc', padding=(padding, 183 0, 184 padding, 185 0)) 186 self.longTextEdit.sr.maincontainer.padding = 0 187 self.longTextEdit.DisableScrolling() 188 self.longTextEdit.EnableAutoSize() 189 self.longTextEdit.OnContentSizeChanged = self.OnContentChanged 190 self.longTextEdit.HideBackground() 191 self.longTextEdit.RemoveActiveFrame() 192 self.termSpriteCont = Container(name='termSpriteCont', parent=self.contentRightCont, pos=(0, 0, 128, 128), align=uiconst.TOTOP) 193 self.termSprite = Sprite(name='termSprite', parent=self.termSpriteCont, pos=(0, 0, 128, 128), texturePath='res:/UI/Texture/Classes/ShipTree/groupIcons/frigate.png', align=uiconst.CENTER) 194 self.loreTextLabel = EveLabelMedium(name='termNameLabel', text='', parent=self.contentRightCont, align=uiconst.TOTOP) 195 196 def LoadContent(self, termInfo): 197 self.termHeaderLabel.text = GetByMessageID(termInfo.termTitleID) 198 self.loreTextLabel.text = '<i>%s</i>' % GetByMessageID(termInfo.loreTextID) 199 self.LoadAndWaitForIconSizeChange(termInfo.texturePath) 200 self.longTextEdit.SetValue('<font size=14>%s</font>' % GetByMessageID(termInfo.longTextID)) 201 202 def OnContentChanged(self, width, height, *args): 203 self.height = self.termHeaderLabel.padTop + self.termHeaderLabel.textheight + max(height, self.termSprite.height + self.loreTextLabel.textheight) 204 205 def LoadAndWaitForIconSizeChange(self, texturePath): 206 self.termSprite.LoadTexture(texturePath) 207 if not texturePath: 208 return 209 import blue 210 counter = 0 211 while self.termSprite.renderObject.texturePrimary.atlasTexture.width == 0 and counter < 20: 212 counter += 1 213 blue.synchro.Yield() 214 215 atlasTexture = self.termSprite.renderObject.texturePrimary.atlasTexture 216 self.termSprite.width = atlasTexture.width 217 self.termSprite.height = atlasTexture.height 218 self.termSpriteCont.height = atlasTexture.height 219 self.contentRightCont.width = max(self.MIN_RIGHT_SIDE_WIDTH, atlasTexture.width) 220 221 222 class NavigationButtons(Container): 223 default_height = 19 224 default_width = 38 225 default_buttonSize = 19 226 default_align = uiconst.TOPLEFT 227 default_alphaNormal = 0.7 228 default_alphaOver = 1.0 229 default_alphaDisabled = 0.1 230 231 def ApplyAttributes(self, attributes): 232 Container.ApplyAttributes(self, attributes) 233 buttonSize = attributes.get('buttonSize', self.default_buttonSize) 234 self.alphaOver = attributes.alphaOver or self.default_alphaOver 235 self.alphaNormal = attributes.alphaOver or self.default_alphaNormal 236 self.alphaDisabled = attributes.get('alphaDisabled', self.default_alphaDisabled) 237 backBtnHint = attributes.get('backBtnHint', localization.GetByLabel('UI/Control/EveWindow/Next')) 238 forwardBtnHint = attributes.get('forwardBtnHint', localization.GetByLabel('UI/Control/EveWindow/Previous')) 239 self.backBtnFunc = attributes.get('backBtnFunc') 240 self.forwardBtnFunc = attributes.get('forwardBtnFunc') 241 self.backBtn = backBtn = Sprite(name='backBtn', texturePath='res:/UI/Texture/classes/ButtonIcon/navigationPrevLarge.png', parent=self, pos=(0, 242 0, 243 buttonSize, 244 buttonSize), align=uiconst.CENTERLEFT, hint=backBtnHint, opacity=self.default_alphaNormal) 245 self.backBtn.OnClick = self.OnBackBtnClicked 246 self.forwardBtn = forwardkBtn = Sprite(name='forwardkBtn', texturePath='res:/UI/Texture/classes/ButtonIcon/navigationNextLarge.png', parent=self, pos=(0, 247 0, 248 buttonSize, 249 buttonSize), align=uiconst.CENTERRIGHT, hint=forwardBtnHint) 250 self.forwardBtn.OnClick = self.OnForwardBtnClicked 251 for eachBtn in (forwardkBtn, backBtn): 252 eachBtn.OnMouseDown = (self.OnMouseDownOnBtn, eachBtn) 253 eachBtn.OnMouseUp = (self.OnMouseUpOnBtn, eachBtn) 254 eachBtn.OnMouseEnter = (self.OnMouseEnterButton, eachBtn) 255 eachBtn.OnMouseExit = (self.OnMouseExitButton, eachBtn) 256 257 def GetBackBtn(self): 258 return self.backBtn 259 260 def GetForwardBtn(self): 261 return self.forwardBtn 262 263 def OnBackBtnClicked(self, *args): 264 if self.backBtn.state != uiconst.UI_DISABLED: 265 self.backBtnFunc() 266 return True 267 return False 268 269 def OnForwardBtnClicked(self, *args): 270 if self.forwardBtn.state != uiconst.UI_DISABLED: 271 self.forwardBtnFunc() 272 return True 273 return False 274 275 def OnMouseDownOnBtn(self, button, mouseButton, *args): 276 if mouseButton != uiconst.MOUSELEFT: 277 return 278 button.top = 2 279 280 def OnMouseUpOnBtn(self, button, *args): 281 button.top = 0 282 283 def OnMouseEnterButton(self, button, *args): 284 self.SetOpacity(self.alphaOver) 285 286 def OnMouseExitButton(self, button, *args): 287 self.SetOpacity(self.alphaNormal) 288 289 def EnableBackBtn(self): 290 return self.EnableBtn(btn=self.backBtn) 291 292 def DisableBackBtn(self): 293 return self.DisableBtn(btn=self.backBtn) 294 295 def EnableForwardBtn(self): 296 return self.EnableBtn(btn=self.forwardBtn) 297 298 def DisableForwardBtn(self): 299 return self.DisableBtn(btn=self.forwardBtn) 300 301 def EnableBtn(self, btn): 302 uicore.animations.BlinkIn(btn, startVal=btn.opacity, endVal=self.alphaNormal, duration=0.1, loops=1) 303 btn.state = uiconst.UI_NORMAL 304 305 def DisableBtn(self, btn): 306 uicore.animations.BlinkIn(btn, startVal=btn.opacity, endVal=self.alphaDisabled, duration=0.1, loops=1) 307 btn.state = uiconst.UI_DISABLED 308 309 def AnimateBackBtn(self): 310 return self.AnimateBtn(self.backBtn) 311 312 def AnimateForwardBtn(self): 313 return self.AnimateBtn(self.forwardBtn) 314 315 def AnimateBtn(self, btn): 316 uicore.animations.SpGlowFadeIn(btn, glowColor=(0.8, 0.8, 1.0, 0.3), glowFactor=0.1, glowExpand=0.5, duration=0.2, loops=1, curveType=uiconst.ANIM_WAVE)