petitionWindow.py (19240B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\neocom\petitionWindow.py 2 import localization 3 import player_messaging.client.ui_message 4 import uthread 5 from carbonui import uiconst 6 from carbonui.primitives.container import Container 7 from carbonui.primitives.containerAutoSize import ContainerAutoSize 8 from carbonui.uicore import uicore 9 from eve.client.script.ui.control import eveLabel 10 from carbonui.control.window import Window 11 from eve.client.script.ui.control.themeColored import SpriteThemeColored 12 from eve.client.script.ui.shared import messagebox 13 from eve.client.script.ui.util import searchUtil 14 from eve.client.script.ui.util.form import FormWnd 15 from eve.common.lib import appConst 16 from eve.common.script.search.const import ResultType 17 from eveservices.xmppchat import GetChatService 18 from evepetitions.data import get_property_description_id, get_property_input_info, get_property_input_type, get_property_name, get_property_required_int 19 from player_messaging.client.ui_message import prompt_player, prompt_player_fsd_dialog 20 21 class PetitionWindow(Window): 22 __guid__ = 'form.PetitionWindow' 23 billingCategories = {} 24 default_windowID = 'petitionwindow' 25 default_iconNum = 'res:/ui/Texture/WindowIcons/help.png' 26 default_captionLabelPath = 'UI/Neocom/Petition/CreateNew' 27 28 def ApplyAttributes(self, attributes): 29 Window.ApplyAttributes(self, attributes) 30 self.mainCont = ContainerAutoSize(name='mainCont', align=uiconst.TOTOP, parent=self.sr.main, callback=self.UpdateMinHeight) 31 self.formWindow = FormWnd(name='form', align=uiconst.TOTOP, parent=self.mainCont) 32 self.mainText = eveLabel.EveLabelMedium(name='mainText', parent=self.mainCont, align=uiconst.TOTOP, state=uiconst.UI_NORMAL, padTop=8) 33 self.mainCont.SetSizeAutomatically() 34 _, height = self.GetWindowSizeForContentSize(height=self.mainCont.height) 35 self.SetMinSize((350, height)) 36 self.CategoryScreen() 37 38 def ConstructTopParent(self): 39 topParent = Container(name='topParent', parent=self.mainCont, align=uiconst.TOTOP, height=62, clipChildren=True) 40 SpriteThemeColored(name='mainicon', parent=topParent, state=uiconst.UI_DISABLED, pos=(0, -3, 64, 64), texturePath=self.iconNum, colorType=uiconst.COLORTYPE_UIHILIGHTGLOW) 41 self.sr.mainCaption = eveLabel.CaptionLabel(text=localization.GetByLabel('UI/Neocom/Petition/CreateNew'), parent=topParent, align=uiconst.RELATIVE, left=64, top=16) 42 43 def CategoryScreen(self): 44 self.formWindow.Flush() 45 self.mainText.SetText('') 46 format = [{'type': 'push', 47 'frame': 0}] 48 self.GetFromSelect = 0 49 self.OocCharacterID = None 50 if not session.charid: 51 if self.OocCharacterID == None: 52 chars = sm.RemoteSvc('charUnboundMgr').GetCharacterInfo() 53 first = 1 54 self.GetFromSelect = 1 55 format.append({'type': 'text', 56 'text': localization.GetByLabel('UI/CharacterSelection/SelectCharacter'), 57 'frame': 0}) 58 for char in chars: 59 format.append({'type': 'checkbox', 60 'required': 1, 61 'group': 'OocCharacter', 62 'height': 16, 63 'setvalue': first, 64 'key': char.characterID, 65 'label': '', 66 'text': char.characterName, 67 'frame': 0}) 68 first = 0 69 70 format.append({'type': 'push', 71 'frame': 0}) 72 format.append({'type': 'push', 73 'frame': 0}) 74 self.superCategories, self.childCategories, self.descriptions = self.GetCategories() 75 if len(self.superCategories) < 2 or len(self.childCategories) < 1: 76 self.superCategories, self.childCategories, self.descriptions = self.GetCategories(forcedLanguage=localization.const.LOCALE_SHORT_ENGLISH) 77 format.append({'type': 'combo', 78 'required': 1, 79 'frame': 0, 80 'key': 'superCategoryID', 81 'label': localization.GetByLabel('UI/Inventory/ItemGroup'), 82 'options': self.superCategories, 83 'callback': self.SuperCategorySelection}) 84 format.append({'type': 'push', 85 'frame': 0}) 86 format.append({'type': 'combo', 87 'required': 1, 88 'frame': 0, 89 'key': 'subCategory', 90 'label': localization.GetByLabel('UI/Common/Category'), 91 'options': [[localization.GetByLabel('UI/Neocom/Petition/SelectGroup'), None]], 92 'callback': self.SubCategorySelection}) 93 format.append({'type': 'btnonly', 94 'frame': 0, 95 'uniSize': False, 96 'buttons': [{'caption': localization.GetByLabel('UI/Help/OpenHelpCenter'), 97 'function': self.OpenHelpCenter}, {'caption': localization.GetByLabel('UI/Common/Buttons/Select'), 98 'function': self.ConfirmCategory}]}) 99 format.append({'type': 'push', 100 'frame': 0}) 101 format.append({'type': 'push'}) 102 self.sr.formData = sm.GetService('form').GetForm(format, self.formWindow) 103 Container(name='push', parent=self.formWindow, align=uiconst.TOLEFT, width=6) 104 Container(name='push', parent=self.formWindow, align=uiconst.TORIGHT, width=6) 105 category = self.sr.formData[0].sr.subCategory.GetValue() 106 if category: 107 text = self.descriptions[category][0] 108 else: 109 text = '' 110 self.mainText.SetText(text) 111 try: 112 self.selectBtn = self.sr.formData[0].FindChild('%s_Btn' % localization.GetByLabel('UI/Common/Buttons/Select')) 113 self.helpDeskBtn = self.sr.formData[0].FindChild('%s_Btn' % localization.GetByLabel('UI/Help/OpenHelpCenter')) 114 self.helpDeskBtn.display = False 115 self.helpDeskBtn.align = uiconst.TOPRIGHT 116 except Exception: 117 pass 118 119 def OpenHelpCenter(self, *args): 120 import webbrowser 121 if prompt_player_fsd_dialog('HelpCenterOpenWarning', {}, uiconst.OKCANCEL) == uiconst.ID_OK: 122 webbrowser.open_new(sm.RemoteSvc('petitioner').GetZendeskJwtLink()) 123 self.Close() 124 125 def SubCategorySelection(self, combo, header, value, *args): 126 if value != None: 127 if combo.name == 'subCategory': 128 ops = self.descriptions[value[0]] 129 self.mainText.SetText(ops) 130 131 def UpdateMinHeight(self): 132 _, mh = self.GetWindowSizeForContentSize(height=self.mainCont.height) 133 self.SetMinSize((self.width, mh), refresh=True) 134 135 def SuperCategorySelection(self, combo, header, value, *args): 136 if combo.name == 'superCategoryID' and value is not None: 137 try: 138 if value == 29 and sm.RemoteSvc('petitioner').IsZendeskEnabled() and session.languageID.lower() == 'en': 139 self.mainText.SetText(localization.GetByLabel('UI/Help/MovedToHelpCenter')) 140 self.sr.formData[0].sr.subCategory.parent.display = False 141 self.selectBtn.display = False 142 self.helpDeskBtn.display = True 143 else: 144 ops = self.childCategories[value] 145 hints = {} 146 for k, v in ops: 147 hints[k] = self.descriptions[v[0]] 148 149 self.sr.formData[0].sr.subCategory.LoadOptions(ops, hints=hints) 150 current = self.sr.formData[0].sr.subCategory.GetValue() 151 ops = self.descriptions[current[0]] 152 self.mainText.SetText(ops) 153 self.sr.formData[0].sr.subCategory.parent.display = True 154 self.selectBtn.display = True 155 self.helpDeskBtn.display = False 156 except Exception: 157 ops = self.childCategories[value] 158 hints = {} 159 for k, v in ops: 160 hints[k] = self.descriptions[v[0]] 161 162 self.sr.formData[0].sr.subCategory.LoadOptions(ops, hints=hints) 163 current = self.sr.formData[0].sr.subCategory.GetValue() 164 ops = self.descriptions[current[0]] 165 self.mainText.SetText(ops) 166 167 def ConfirmCategory(self, *args): 168 result = sm.GetService('form').ProcessForm(self.sr.formData[1], self.sr.formData[2]) 169 catCountry = sm.RemoteSvc('petitioner').GetUserCatalogCountry() 170 if result: 171 if (result['subCategory'][0], catCountry) in self.billingCategories: 172 url, messageLabel = self.billingCategories[result['subCategory'][0], catCountry] 173 result = prompt_player(localization.GetByLabel(messageLabel), result['subCategory'][1], options=uiconst.YESNO)[0] 174 if result == uiconst.ID_YES: 175 uicore.cmd.OpenBrowser(url=url, newTab=True) 176 self.Close() 177 return 178 else: 179 self.Close() 180 return 181 self.category = result['subCategory'] 182 if self.GetFromSelect: 183 self.OocCharacterID = result['OocCharacter'] 184 uthread.new(self.InputPetition) 185 186 def InputPetition(self, *args): 187 categoryID = self.category[0] 188 categoryName = self.category[1] 189 OocCharacterID = self.OocCharacterID 190 can = sm.RemoteSvc('petitioner').MayPetition(categoryID, OocCharacterID) 191 if can < 0: 192 if can == -1: 193 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition1')}) 194 return 195 if can == -2: 196 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition2')}) 197 return 198 if can == -3: 199 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition3')}) 200 return 201 if can == -4: 202 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition4')}) 203 return 204 if can == -6: 205 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition6')}) 206 return 207 if can == -7: 208 prompt_player_fsd_dialog('CannotPostPetition', {'text': localization.GetByLabel('UI/Neocom/Petition/CannotPostPetition7')}) 209 return 210 self.formWindow.Flush() 211 self.mainText.SetText('') 212 format = [] 213 format.append({'type': 'header', 214 'text': categoryName, 215 'frame': 0, 216 'hideLine': True}) 217 format.append({'type': 'push', 218 'frame': 0}) 219 self.properties = sm.RemoteSvc('petitioner').GetCategoryProperties(self.category[0]) 220 for propertyID in self.properties: 221 required = get_property_required_int(propertyID) 222 descriptionID = get_property_description_id(propertyID) 223 inputType = get_property_input_type(propertyID) 224 propertyName = get_property_name(propertyID) 225 inputInfo = get_property_input_info(propertyID) 226 format.append({'type': 'labeltext', 227 'text': localization.GetByMessageID(descriptionID), 228 'frame': 0}) 229 if inputType == 'DropDown': 230 populationInfo = sm.RemoteSvc('petitioner').PropertyPopulationInfo(inputInfo, self.OocCharacterID) 231 populationInfo = self.FormatForDropDown(populationInfo) 232 format.append({'type': 'combo', 233 'required': required, 234 'frame': 0, 235 'key': propertyName, 236 'options': populationInfo}) 237 if inputType == 'Picker': 238 format.append({'type': 'edit', 239 'key': propertyName, 240 'maxLength': 200, 241 'height': 28, 242 'required': required, 243 'frame': 0}) 244 format.append({'type': 'labeltext', 245 'frame': 0, 246 'text': localization.GetByLabel('UI/Neocom/Petition/Search')}) 247 format.append({'type': 'btnonly', 248 'frame': 0, 249 'buttons': [{'caption': localization.GetByLabel('UI/Neocom/Petition/Search'), 250 'function': self.PopulatePicker, 251 'args': propertyName}]}) 252 if inputType == 'EditBox': 253 format.append({'type': 'edit', 254 'key': propertyName, 255 'setvalue': inputInfo, 256 'maxLength': 200, 257 'height': 28, 258 'required': required, 259 'frame': 0}) 260 format.append({'type': 'push', 261 'frame': 0}) 262 263 format.append({'type': 'push', 264 'frame': 0}) 265 format.append({'type': 'edit', 266 'key': 'subject', 267 'label': localization.GetByLabel('UI/Neocom/Petition/Subject'), 268 'maxLength': 200, 269 'required': 1, 270 'frame': 0}) 271 format.append({'type': 'textedit', 272 'key': 'petition', 273 'label': localization.GetByLabel('UI/Neocom/Petition/Text'), 274 'maxLength': 10000, 275 'height': 300, 276 'required': 1, 277 'frame': 0}) 278 format.append({'type': 'btnonly', 279 'frame': 0, 280 'buttons': [{'caption': localization.GetByLabel('UI/Generic/Submit'), 281 'function': self.CreatePetition}, {'caption': localization.GetByLabel('UI/Commands/Back'), 282 'function': self.GoBack}]}) 283 format.append({'type': 'push', 284 'frame': 0}) 285 self.mainText.SetText(self.descriptions[categoryID]) 286 self.sr.formData = sm.GetService('form').GetForm(format, self.formWindow) 287 self.lockPetitioning = False 288 289 def GoBack(self, *args): 290 ret = prompt_player_fsd_dialog('AskAreYouSure', {'cons': localization.GetByLabel('UI/Neocom/Petition/LoseInfo')}, uiconst.YESNO, default=uiconst.ID_NO) 291 if ret == uiconst.ID_YES: 292 self.CategoryScreen() 293 294 def PopulatePicker(self, *args): 295 elementName = args[0] 296 filterString = sm.GetService('form').ProcessForm(self.sr.formData[1], [])[elementName] 297 if len(filterString) >= 1: 298 if elementName == 'StarbaseLocation': 299 resList = searchUtil.GetResultsList(filterString, [ResultType.solar_system]) 300 populationRecords = [] 301 for x in resList: 302 populationRecords.append((cfg.evelocations.Get(x).name, x)) 303 304 elif elementName == 'Agents': 305 resList = searchUtil.GetResultsList(filterString, [ResultType.agent]) 306 populationRecords = [] 307 for x in resList: 308 populationRecords.append((cfg.eveowners.Get(x).name, x)) 309 310 else: 311 populationRecords = sm.RemoteSvc('petitioner').GetClientPickerInfo(filterString, elementName) 312 if len(populationRecords) >= 25: 313 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Neocom/Petition/NarrowSearch')}) 314 picker = self.sr.formData[0].sr.Get(elementName) 315 if len(populationRecords) > 0: 316 picker.LoadCombo(elementName, populationRecords, None, None) 317 picker.SetValue(str(populationRecords[0][1])) 318 picker.SetText(populationRecords[0][0]) 319 else: 320 picker.SetText(localization.GetByLabel('UI/Neocom/Petition/ReportInfoNotFound')) 321 else: 322 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Neocom/Petition/PleaseType3Letters')}) 323 324 def FormatForDropDown(self, entryList): 325 newList = [] 326 for entry in entryList: 327 entryID, entryText = entry 328 if isinstance(entryText, tuple): 329 entryText = cfg.FormatConvert(*entryText) 330 newList.append([entryText, entryID]) 331 332 return newList 333 334 def CreatePetition(self, *args): 335 if self.lockPetitioning: 336 return 337 self.lockPetitioning = True 338 propertyList = [] 339 resultDict = sm.GetService('form').ProcessForm(self.sr.formData[1], self.sr.formData[2]) 340 combatLog = None 341 chatLog = None 342 categoryID = self.category[0] 343 if resultDict: 344 chatLog = GetChatService().GetChannelMessages() 345 combatLog = sm.GetService('logger').GetLog() 346 if chatLog: 347 chatLog = chatLog[-appConst.petitionMaxChatLogSize:] 348 if combatLog: 349 combatLog = combatLog[-appConst.petitionMaxCombatLogSize:] 350 for propertyID in self.properties: 351 propertyName = get_property_name(propertyID) 352 inputType = get_property_input_type(propertyID) 353 if inputType == 'Picker': 354 value = self.sr.formData[0].sr.Get(propertyName).GetComboValue() 355 propertyList.append([propertyID, value]) 356 else: 357 propertyList.append([propertyID, resultDict[propertyName]]) 358 359 subject = resultDict['subject'] 360 petition = resultDict['petition'] 361 sm.RemoteSvc('petitioner').CreatePetition(subject, petition, categoryID, None, self.OocCharacterID, chatLog, combatLog, propertyList) 362 sm.ScatterEvent('OnPetitionCreated') 363 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Neocom/Petition/Created')}) 364 self.CloseByUser() 365 else: 366 self.lockPetitioning = False 367 368 def GetCategories(self, forcedLanguage = None): 369 parentCategoryDict, childCategoryDict, descriptionDict, self.billingCategories = sm.RemoteSvc('petitioner').GetCategoryHierarchicalInfo() 370 parentCategories = [[localization.GetByLabel('UI/Neocom/Petition/SelectParentCategory'), None]] 371 childCategoryRetDict = {} 372 descriptions = [] 373 if forcedLanguage is not None: 374 myLanguage = forcedLanguage 375 else: 376 myLanguage = localization.util.GetLanguageID() 377 for parentID, catAndLanguage in parentCategoryDict.iteritems(): 378 cat, languageID = catAndLanguage 379 if languageID != myLanguage: 380 continue 381 parentCategories.append((cat, parentID)) 382 383 for childGroupID, childGroupDict in childCategoryDict.iteritems(): 384 childCategories = [] 385 for childID, childnameAndLanguage in childGroupDict.iteritems(): 386 childName, languageID = childnameAndLanguage 387 if languageID != myLanguage: 388 continue 389 childCategories.append((childName, (childID, childName))) 390 391 if len(childCategories) > 0: 392 childCategoryRetDict[childGroupID] = childCategories 393 394 return (parentCategories, childCategoryRetDict, descriptionDict)