all_ui_home.py (22091B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\Alliances\all_ui_home.py 2 import sys 3 import carbonui 4 import carbonui.text.styles 5 from carbon.common.script.util.format import FormatUrl 6 from carbonui import Align 7 from carbonui.control.scroll import Scroll 8 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.containerAutoSize import ContainerAutoSize 11 from carbonui.button.group import ButtonGroup 12 from carbonui.control.button import Button 13 from carbonui.control.radioButton import RadioButton 14 from eve.client.script.ui.control.entries.label_text import LabelTextSides, LabelTextSidesMoreInfo, LabelTextTop 15 from eve.client.script.ui.control.entries.util import GetFromClass 16 from eve.client.script.ui.control.eveEditPlainText import EditPlainText 17 from eve.client.script.ui.control.eveIcon import OwnerIcon 18 from eve.client.script.ui.control.eveLabel import EveLabelSmall 19 import blue 20 import uthread 21 from eve.client.script.ui.control import eveLabel 22 import log 23 import carbonui.const as uiconst 24 import localization 25 from carbonui.uicore import uicore 26 from carbonui.control.window import Window 27 from eve.client.script.ui.control.infoIcon import InfoIcon 28 from eve.client.script.ui.control.listgroup import ListGroup 29 from eve.client.script.ui.control.utilMenu import UtilMenu 30 from eve.client.script.ui.shared.neocom.corporation import corpUISignals 31 from eve.client.script.ui.shared.neocom.corporation.corp_ui_bulletins import BulletinsOrder 32 from eve.common.lib.appConst import allianceNameMaxLenSR, allianceNameMaxLenTQ 33 from eveprefs import boot 34 from eveservices.menu import GetMenuService 35 from evewar.warPermitUtil import GetLabelPathForAllowWar 36 from globalConfig.getFunctions import IsContentComplianceControlSystemActive 37 from localization import GetByLabel 38 from menucheckers import SessionChecker 39 ICON_SIZE = 128 40 41 class FormAlliancesHome(Container): 42 is_loaded = False 43 scroll = None 44 45 def Load(self, *args): 46 if not self.is_loaded: 47 self.is_loaded = True 48 self.top_cont = ContainerAutoSize(name='top_cont', align=Align.TOTOP, parent=self, padBottom=16) 49 self.reconstruct_top_cont() 50 self.toolbarContainer = ContainerAutoSize(name='toolbarContainer', align=uiconst.TOBOTTOM, parent=self) 51 self.construct_button_group() 52 self.scroll = Scroll(parent=self) 53 corpUISignals.on_alliance_changed.connect(self.OnAllianceChanged) 54 if session.allianceid is None: 55 corpNotInAllianceLabel = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CorporationNotInAlliance', corpName=cfg.eveowners.Get(session.corpid).ownerName) 56 self.scroll.Load(fixedEntryHeight=19, contentList=[], noContentHint=corpNotInAllianceLabel) 57 else: 58 self.LoadScroll() 59 60 def reconstruct_top_cont(self): 61 self.top_cont.Flush() 62 if session.allianceid is None: 63 return 64 OwnerIcon(ownerID=session.allianceid, parent=self.top_cont, align=uiconst.CENTERLEFT, pos=(0, 65 0, 66 ICON_SIZE, 67 ICON_SIZE)) 68 caption = carbonui.text.styles.TextHeadline(text=cfg.eveowners.Get(session.allianceid).ownerName, parent=self.top_cont, align=uiconst.CENTERLEFT, left=ICON_SIZE + 8) 69 InfoIcon(typeID=const.typeAlliance, itemID=session.allianceid, parent=self.top_cont, left=caption.left + caption.width + 6, top=2, state=uiconst.UI_NORMAL, align=uiconst.CENTERLEFT) 70 71 def construct_button_group(self): 72 buttons = [] 73 if session.allianceid is None: 74 corporation = sm.GetService('corp').GetCorporation(session.corpid) 75 if corporation.ceoID == session.charid: 76 buttons.append(Button(label=localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CreateAlliance'), func=self.CreateAllianceForm)) 77 elif SessionChecker(session, None).IsCorpDirector(): 78 buttons.append(Button(label=localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/EditAlliance'), func=self.EditAllianceForm, enabled=not IsContentComplianceControlSystemActive(sm.GetService('machoNet')))) 79 buttons.append(Button(label=localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/DeclareWar'), func=self.DeclareWarForm)) 80 if len(buttons): 81 ButtonGroup(parent=self.toolbarContainer, align=uiconst.TOBOTTOM, buttons=buttons, padTop=8) 82 83 def LoadScroll(self): 84 if not self.scroll: 85 return 86 try: 87 scrolllist = [] 88 self.ShowMyAllianceDetails(scrolllist) 89 self.scroll.Load(contentList=scrolllist) 90 except: 91 log.LogException() 92 sys.exc_clear() 93 94 def ShowMyAllianceDetails(self, scrolllist): 95 scrolllist.append(GetFromClass(ListGroup, {'GetSubContent': self.ShowDetails, 96 'label': localization.GetByLabel('UI/Common/Details'), 97 'groupItems': None, 98 'id': ('alliance', 'details'), 99 'tabs': [], 100 'state': 'locked', 101 'showicon': 'hide'})) 102 uicore.registry.SetListGroupOpenState(('alliance', 'details'), 1) 103 104 def SetHint(self, hintstr = None): 105 if self.scroll: 106 self.scroll.ShowHint(hintstr) 107 108 def ShowDetails(self, *args): 109 scrolllist = [] 110 hint = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/NoDetailsFound') 111 if self is None or self.destroyed: 112 log.LogInfo('ShowMembers Destroyed or None') 113 hint = '' 114 elif session.allianceid is None: 115 hint = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CorporationNotInAllianceATM', corpName=cfg.eveowners.Get(session.corpid).ownerName) 116 else: 117 rec = sm.GetService('alliance').GetAlliance() 118 owners = [rec.allianceID, rec.creatorCorpID, rec.creatorCharID] 119 if rec.executorCorpID is not None: 120 owners.append(rec.executorCorpID) 121 if len(owners): 122 cfg.eveowners.Prime(owners) 123 label = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/AllianceName') 124 text = cfg.eveowners.Get(rec.allianceID).ownerName 125 scrolllist.append(GetFromClass(LabelTextSides, {'line': 1, 126 'label': label, 127 'text': text, 128 'typeID': const.typeAlliance, 129 'itemID': rec.allianceID})) 130 executor = cfg.eveowners.GetIfExists(rec.executorCorpID) 131 label = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/Executor') 132 if executor is not None: 133 params = {'line': 1, 134 'label': label, 135 'text': executor.ownerName, 136 'typeID': const.typeCorporation, 137 'itemID': rec.executorCorpID} 138 else: 139 params = {'line': 1, 140 'label': label, 141 'text': '-'} 142 scrolllist.append(GetFromClass(LabelTextSides, params)) 143 label = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/ShortName') 144 params = {'line': 1, 145 'label': label, 146 'text': rec.shortName} 147 scrolllist.append(GetFromClass(LabelTextSides, params)) 148 label = localization.GetByLabel('UI/Common/URL') 149 if rec.url is not None: 150 params = {'line': 1, 151 'label': label, 152 'text': '<url=%s>%s</url>' % (rec.url, rec.url)} 153 scrolllist.append(GetFromClass(LabelTextSides, params)) 154 scrolllist.append(GetFromClass(LabelTextTop, {'line': 1, 155 'label': localization.GetByLabel('UI/Common/Description'), 156 'text': rec.description})) 157 scrolllist.append(GetFromClass(LabelTextSides, {'line': 1, 158 'label': localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CreatedByCorporation'), 159 'text': cfg.eveowners.Get(rec.creatorCorpID).ownerName, 160 'typeID': const.typeCorporation, 161 'itemID': rec.creatorCorpID})) 162 scrolllist.append(GetFromClass(LabelTextSides, {'line': 1, 163 'label': localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CreatedBy'), 164 'text': cfg.eveowners.Get(rec.creatorCharID).ownerName, 165 'typeID': const.typeCharacter, 166 'itemID': rec.creatorCharID})) 167 scrolllist.append(GetFromClass(LabelTextSides, {'line': 1, 168 'label': localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/Dictatorial'), 169 'text': localization.GetByLabel('UI/Common/Buttons/Yes') if rec.dictatorial else localization.GetByLabel('UI/Common/Buttons/No')})) 170 scrolllist.append(GetFromClass(LabelTextSidesMoreInfo, {'line': 1, 171 'label': localization.GetByLabel('UI/WarPermit/WarPermitStatus'), 172 'text': localization.GetByLabel(GetLabelPathForAllowWar(rec.allowWar)), 173 'moreInfoHint': localization.GetByLabel('UI/WarPermit/WarPermitExplanation')})) 174 self.scroll.adjustableColumns = 1 175 self.scroll.sr.id = 'alliances_members' 176 if not scrolllist: 177 self.SetHint(hint) 178 return scrolllist 179 180 def GetTabHint(self): 181 eHint = '' 182 if session.allianceid is None: 183 corporation = sm.GetService('corp').GetCorporation(session.corpid) 184 if corporation.ceoID != session.charid: 185 eHint = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CEODeclareWarOnlyHint') 186 if not SessionChecker(session, None).IsCorpDirector(): 187 eHint = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/DirectorsCanEdit') 188 return eHint 189 190 def OnAllianceChanged(self, allianceID, change): 191 if session.allianceid != allianceID: 192 return 193 if self.state != uiconst.UI_NORMAL: 194 return 195 if self.scroll is None: 196 return 197 self.ShowDetails() 198 self.reconstruct_top_cont() 199 200 def CreateAllianceForm(self, *args): 201 wnd = CreateAllianceWnd.Open() 202 203 def EditAllianceForm(self, *args): 204 wnd = EditAllianceWnd.Open() 205 206 def DeclareWarForm(self, *args): 207 GetMenuService().DeclareWar() 208 209 210 class FormAlliancesBulletins(Container): 211 is_loaded = False 212 213 def Load(self, *args): 214 if not self.is_loaded: 215 self.is_loaded = True 216 self.construct_layout() 217 if session.allianceid is not None: 218 self.LoadBulletins() 219 220 def construct_layout(self): 221 self.toolbarContainer = ContainerAutoSize(name='toolbarContainer', align=uiconst.TOBOTTOM, parent=self) 222 self.construct_button_group() 223 bulletinParent = Container(name='bulletinParent', parent=self, align=uiconst.TOALL, pos=(0, 0, 0, 0)) 224 if session.allianceid and SessionChecker(session, None).IsCorpDirector(): 225 self.sr.sortOrderCont = Container(name='sortOrderCont', parent=bulletinParent, align=uiconst.TOTOP, height=20) 226 UtilMenu(menuAlign=uiconst.TOPRIGHT, parent=self.sr.sortOrderCont, align=uiconst.CENTERRIGHT, texturePath='res:/UI/Texture/Icons/77_32_49.png', pos=(4, 0, 20, 20), GetUtilMenu=self.GetSortOrderMenu, iconSize=24) 227 Container(name='push', parent=bulletinParent, align=uiconst.TOLEFT, width=const.defaultPadding) 228 self.messageArea = Scroll(parent=bulletinParent) 229 230 def construct_button_group(self): 231 btns = [] 232 if session.allianceid is None: 233 corporation = sm.GetService('corp').GetCorporation(session.corpid) 234 if corporation.ceoID == session.charid: 235 createAllianceLabel = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/CreateAlliance') 236 btns.append([createAllianceLabel, 237 self.CreateAllianceForm, 238 None, 239 None]) 240 elif SessionChecker(session, None).IsCorpDirector() and not IsContentComplianceControlSystemActive(sm.GetService('machoNet')): 241 addBulletinLabel = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/AddBulletin') 242 btns.append([addBulletinLabel, 243 self.AddBulletin, 244 None, 245 None]) 246 if len(btns): 247 ButtonGroup(btns=btns, parent=self.toolbarContainer) 248 249 def AddBulletin(self, *args): 250 sm.GetService('corp').EditBulletin(None, isAlliance=True) 251 252 def LoadBulletins(self): 253 scrollEntries = sm.GetService('corp').GetBulletinEntries(isAlliance=True) 254 if self.sr.sortOrderCont: 255 self.sr.sortOrderCont.display = len(scrollEntries) > 1 256 self.messageArea.LoadContent(contentList=scrollEntries, noContentHint=localization.GetByLabel('UI/Corporations/BaseCorporationUI/NoBulletins')) 257 258 def GetSortOrderMenu(self, menuParent): 259 cont = menuParent.AddContainer(align=uiconst.TOTOP, height=50, padding=const.defaultPadding) 260 bulletins = sm.GetService('corp').GetBulletins(True) 261 orderCont = BulletinsOrder(parent=cont, align=uiconst.TOTOP, bulletins=bulletins, saveFunc=self.SaveSortOrder) 262 orderContContentWidth = orderCont.GetContentWidth() 263 cont.GetEntryWidth = lambda mc = cont: orderContContentWidth 264 265 def SaveSortOrder(self, sortOrder): 266 sm.GetService('alliance').UpdateBulletinOrder(sortOrder) 267 self.LoadBulletins() 268 269 270 class CreateAllianceWnd(Window): 271 __guid__ = 'form.CreateAllianceWnd' 272 default_fixedWidth = 350 273 default_fixedHeight = 380 274 default_windowID = 'CreateAllianceWindow' 275 default_captionLabelPath = 'UI/Corporations/CorporationWindow/Alliances/Home/CreateAlliance' 276 277 def ApplyAttributes(self, attributes): 278 super(CreateAllianceWnd, self).ApplyAttributes(attributes) 279 self.DefineButtons(uiconst.OKCANCEL, okFunc=self.Confirm, cancelFunc=self.Cancel) 280 self.ConstructLayout() 281 282 def ConstructLayout(self): 283 cont = Container(parent=self.sr.main, align=uiconst.TOALL) 284 if boot.region == 'optic': 285 nameValue = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/NameAlliance', allianceName=cfg.eveowners.Get(session.corpid).ownerName) 286 else: 287 nameValue = localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/NameAlliance', languageID=localization.const.LOCALE_SHORT_ENGLISH, allianceName=cfg.eveowners.Get(session.corpid).ownerName) 288 maxLength = allianceNameMaxLenSR if boot.region == 'optic' else allianceNameMaxLenTQ 289 self.nameEdit = SingleLineEditText(parent=cont, label=localization.GetByLabel('UI/Common/Name'), align=uiconst.TOTOP, maxLength=maxLength, padTop=16, setvalue=nameValue) 290 shortNameCont = Container(parent=cont, align=uiconst.TOTOP, height=Button.default_height, padTop=24) 291 Button(parent=shortNameCont, align=uiconst.TORIGHT, label=localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/SuggestCommand'), func=self.GetSuggestedTickerNames, padLeft=4) 292 self.shortNameEdit = SingleLineEditText(parent=shortNameCont, label=localization.GetByLabel('UI/Corporations/CorporationWindow/Alliances/Home/ShortName'), align=uiconst.TOTOP, maxLength=5) 293 self.urlEdit = SingleLineEditText(parent=cont, label=localization.GetByLabel('UI/Common/URL'), align=uiconst.TOTOP, maxLenght=2048, padTop=24) 294 eveLabel.EveLabelSmall(parent=cont, text=localization.GetByLabel('UI/Common/Description'), height=16, align=uiconst.TOTOP, padTop=8) 295 self.descriptionEdit = EditPlainText(parent=cont, align=uiconst.TOALL, maxLength=5000, padBottom=8) 296 297 def GetSuggestedTickerNames(self, *args): 298 wnd = SetShortNameWnd.Open(allianceName=self.nameEdit.GetValue()) 299 if wnd.ShowModal() == 1: 300 retval = wnd.result 301 else: 302 retval = None 303 if retval is None: 304 return 305 self.shortNameEdit.SetValue(retval) 306 307 def Confirm(self, *args): 308 allianceName = self.nameEdit.GetValue() 309 shortName = self.shortNameEdit.GetValue() 310 url = self.urlEdit.GetValue() 311 description = self.descriptionEdit.GetValue() 312 uthread.new(self.Confirm_thread, allianceName, shortName, description, url) 313 314 def Confirm_thread(self, allianceName, shortName, description, url): 315 sm.GetService('sessionMgr').PerformSessionChange('alliance.addalliance', sm.GetService('corp').CreateAlliance, allianceName, shortName, description, url) 316 self.Close() 317 318 def Cancel(self, *args): 319 self.Close() 320 321 322 class SetShortNameWnd(Window): 323 __guid__ = 'form.SetShortNameWnd' 324 default_fixedWidth = 300 325 default_windowID = 'SetShortNameWindow' 326 default_captionLabelPath = 'UI/Corporations/CorporationWindow/Alliances/Home/SelectShortName' 327 default_isMinimizable = False 328 329 def ApplyAttributes(self, attributes): 330 Window.ApplyAttributes(self, attributes) 331 self.allianceName = attributes.get('allianceName') 332 self.checkBoxes = [] 333 self.DefineButtons(uiconst.OKCANCEL, okFunc=self.Confirm, cancelFunc=self.Cancel) 334 self.ConstructLayout() 335 self.UpdateFixedHeight() 336 337 def ConstructLayout(self): 338 self.checkBoxCont = ContainerAutoSize(parent=self.sr.main, name='checkBoxCont', align=uiconst.TOTOP, callback=self.UpdateFixedHeight) 339 shortNames = sm.GetService('corp').GetSuggestedAllianceShortNames(self.allianceName) 340 checked = True 341 for shortNameRow in shortNames: 342 shortName = shortNameRow.shortName 343 if shortName is None: 344 continue 345 checkBox = RadioButton(text=shortName, parent=self.checkBoxCont, settingsKey='shortNames', retval=shortName, checked=checked, groupname='state', align=uiconst.TOTOP, height=19) 346 self.checkBoxes.append(checkBox) 347 checked = False 348 349 def UpdateFixedHeight(self, *args): 350 _, height = self.GetWindowSizeForContentSize(height=self.checkBoxCont.height + self.sr.bottom.height) 351 self.SetFixedHeight(height) 352 353 def Confirm(self, *args): 354 self.result = self.checkBoxes[0].GetGroupValue() 355 self.SetModalResult(1) 356 357 def Cancel(self, *args): 358 self.result = None 359 self.SetModalResult(0) 360 361 362 class EditAllianceWnd(Window): 363 __guid__ = 'form.EditAllianceWnd' 364 default_width = 420 365 default_height = 300 366 default_minSize = (default_width, default_height) 367 default_windowID = 'EditAllianceWindow' 368 default_captionLabelPath = 'UI/Corporations/CorporationWindow/Alliances/Home/UpdateAlliance' 369 370 def ApplyAttributes(self, attributes): 371 Window.ApplyAttributes(self, attributes) 372 self.ConstructLayout() 373 374 def ConstructLayout(self): 375 alliance = sm.GetService('alliance').GetAlliance() 376 self.sr.bottom = ContainerAutoSize(parent=self.content, align=uiconst.TOBOTTOM, padTop=16) 377 self.DefineButtons(uiconst.OKCANCEL, okFunc=self.Confirm, cancelFunc=self.Cancel) 378 eveLabel.EveLabelSmall(parent=self.content, align=uiconst.TOTOP, padTop=0, padBottom=4, text=localization.GetByLabel('UI/Common/URL')) 379 self.urlEdit = SingleLineEditText(parent=self.content, align=uiconst.TOTOP, maxLength=2048, setvalue=alliance.url) 380 eveLabel.EveLabelSmall(parent=self.content, align=uiconst.TOTOP, padding=(0, 16, 0, 4), text=localization.GetByLabel('UI/Common/Description')) 381 self.descriptionEdit = EditPlainText(parent=self.content, align=uiconst.TOALL, maxLength=5000, setvalue=alliance.description) 382 383 def Confirm(self, *args): 384 url = self.urlEdit.GetValue() 385 if url: 386 url = FormatUrl(url) 387 description = self.descriptionEdit.GetValue() 388 self.result = (url, description) 389 sm.GetService('alliance').UpdateAlliance(description, url) 390 sm.GetService('corpui').ResetWindow(bShowIfVisible=1) 391 self.Close() 392 393 def Cancel(self, *args): 394 self.Close() 395 396 397 class PrimeTimeHourEntryHorizontal(LabelTextSides): 398 __guid__ = 'listentry.PrimeTimeHourEntryHorizontal' 399 400 def Startup(self, *args): 401 LabelTextSides.Startup(self, args) 402 self.primeTimeInfo = None 403 404 def Load(self, node): 405 self.primeTimeInfo = node.primeTimeInfo 406 text, infoText = self.GetText() 407 node.text = text 408 LabelTextSides.Load(self, node) 409 if infoText: 410 self.sr.infoLabel = EveLabelSmall(text=infoText, parent=self, top=6, state=uiconst.UI_DISABLED, align=uiconst.CENTERRIGHT, left=8) 411 self.sr.text.top = -6 412 413 def GetCurrentPrimeHour(self): 414 currentPrimeHour = 0 415 if self.primeTimeInfo and self.primeTimeInfo.currentPrimeHour is not None: 416 currentPrimeHour = self.primeTimeInfo.currentPrimeHour 417 return currentPrimeHour 418 419 def GetText(self): 420 infoText = '' 421 if self.primeTimeInfo is None or self.primeTimeInfo.currentPrimeHour is None: 422 text = localization.GetByLabel('UI/Common/Unknown') 423 else: 424 newPrimeHour = self.primeTimeInfo.newPrimeHour 425 validAfter = self.primeTimeInfo.newPrimeHourValidAfter 426 now = blue.os.GetWallclockTime() 427 if newPrimeHour and now < validAfter: 428 text = localization.GetByLabel('UI/Sovereignty/VulnerabilityTimerChangesTime', hour=self.primeTimeInfo.currentPrimeHour, newHour=self.primeTimeInfo.newPrimeHour) 429 infoText = localization.GetByLabel('UI/Sovereignty/VulnerabilityTimerChangesInfo', validAfterDate=self.primeTimeInfo.newPrimeHourValidAfter) 430 else: 431 currentPrimeHour = self.GetCurrentPrimeHour() 432 text = localization.GetByLabel('UI/Sovereignty/VulnerabilityTime', hour=currentPrimeHour) 433 return (text, infoText)