chooseNameSection.py (9527B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\steps\sections\chooseNameSection.py 2 import uthread2 3 import utillib 4 from carbonui import const as uiconst 5 from carbonui.control.button import Button 6 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.frame import Frame 11 from carbonui.uicore import uicore 12 from carbonui.util.color import Color 13 from charactercreator import const as ccConst 14 from eve.client.script.ui import eveColor 15 from eve.client.script.ui.control.eveIcon import Icon 16 from eve.client.script.ui.control.eveLabel import EveLabelMedium 17 from eve.client.script.ui.control.infoIcon import MoreInfoIcon 18 from eve.client.script.ui.login.charcreation.label import CCLabel 19 from eve.common.lib import appConst 20 from localization import GetByLabel 21 padding = 16 22 VALID = 1 23 invalidNameReasonNamesByID = {-1: 'UI/CharacterCreation/InvalidName/TooShort', 24 -2: 'UI/CharacterCreation/InvalidName/TooLong', 25 -5: 'UI/CharacterCreation/InvalidName/IllegalCharacter', 26 -6: 'UI/CharacterCreation/InvalidName/TooManySpaces', 27 -7: 'UI/CharacterCreation/InvalidName/ConsecutiveSpaces', 28 -101: 'UI/CharacterCreation/InvalidName/Unavailable', 29 -102: 'UI/CharacterCreation/InvalidName/Unavailable'} 30 31 class ChooseNameSection(ContainerAutoSize): 32 33 def ApplyAttributes(self, attributes): 34 super(ChooseNameSection, self).ApplyAttributes(attributes) 35 self.isCheckingName = False 36 self.namesChecked = {} 37 self.checkNameValidThread = None 38 if not uicore.layer.charactercreation.controller.CanChangeName(): 39 return 40 self.contentContainer = ContainerAutoSize(name='contentContainer', parent=self, align=uiconst.TOTOP, alignMode=uiconst.TOTOP, state=uiconst.UI_PICKCHILDREN, padding=padding) 41 self.contentContainer.isTopLevelWindow = True 42 self._ConstructBackground() 43 self._ConstructNameSelectionLabel() 44 self._ConstructInfoContainer() 45 self._ConstructNameEdit() 46 self._ConstructBottomCont() 47 if self.GetCharacterNameEntered(): 48 self.CheckAvailability() 49 50 def _ConstructBackground(self): 51 Frame(name='hiliteFrame', bgParent=self, frameConst=ccConst.MAINFRAME_INV) 52 Fill(name='fill', bgParent=self, color=(0.0, 0.0, 0.0, 0.5)) 53 54 def GetInfo(self): 55 return uicore.layer.charactercreation.controller.GetInfo() 56 57 def _ConstructInfoContainer(self): 58 infoCont = Container(name='infoContainer', parent=self.contentContainer, align=uiconst.TOTOP, height=16, top=2) 59 EveLabelMedium(name='fullNameLabel', parent=infoCont, align=uiconst.TOLEFT, opacity=0.75, text=GetByLabel('UI/CharacterCreation/FullName')) 60 MoreInfoIcon(name='moreInfoIcon', parent=infoCont, align=uiconst.TOLEFT, hint=GetByLabel('UI/CharacterCreation/NameConstraintsHint'), left=5) 61 62 def _ConstructNameSelectionLabel(self): 63 text = CCLabel(name='nameSelectionLabel', parent=self.contentContainer, text=GetByLabel('UI/CharacterCreation/NameSelection'), fontsize=20, align=uiconst.TOTOP, letterspace=1, top=-6, uppercase=1, color=eveColor.PRIMARY_BLUE, state=uiconst.UI_DISABLED) 64 65 def _ConstructNameEdit(self): 66 editContainer = Container(name='editContainer', parent=self.contentContainer, align=uiconst.TOTOP, height=30, top=3) 67 self.checkAvailabilityIcon = Icon(name='checkAvailabilityIcon', parent=Container(parent=editContainer, align=uiconst.TORIGHT, width=16, padLeft=8), align=uiconst.CENTER, pos=(0, 0, 20, 20), state=uiconst.UI_HIDDEN) 68 self.nameEdit = SingleLineEditText(name='nameEdit', setvalue=self.GetInfo().charName or '', parent=editContainer, maxLength=appConst.maximumCharacterNameLength, align=uiconst.TOALL, OnChange=self.OnTextEditChange, OnSetFocus=self.OnFirstNameFocus, color=(1.0, 1.0, 1.0, 1.0), hintText=GetByLabel('UI/CharacterCreation/FirstName'), fontsize=16, width=5, height=0) 69 self.nameEdit.OnReturn = self.CheckAvailability 70 self.nameEdit.OnAnyChar = self.OnCharInName 71 72 def _ConstructBottomCont(self): 73 bottomCont = Container(name='bottomCont', parent=self.contentContainer, align=uiconst.TOTOP, height=16, state=uiconst.UI_PICKCHILDREN, top=5, padRight=20) 74 self.checkAvailabilityLabel = EveLabelMedium(name='checkAvailabilityLabel', parent=bottomCont, align=uiconst.TOLEFT, width=300, state=uiconst.UI_DISABLED, color=Color.RED, opacity=0.75) 75 self.charCounterLabel = EveLabelMedium(name='charCounterLabel', parent=bottomCont, align=uiconst.CENTERRIGHT, opacity=0.75, text=self.CountRemainingCharacters()) 76 buttonCont = ContainerAutoSize(parent=self.contentContainer, align=uiconst.TOTOP, padTop=4) 77 Button(name='randomizeLastNameButton', parent=buttonCont, label=GetByLabel('UI/CharacterCreation/Randomize'), align=uiconst.TOPLEFT, func=self.RandomizeName) 78 79 def RandomizeName(self, *args): 80 name = sm.RemoteSvc('charUnboundMgr').GetValidRandomName(self.GetInfo().raceID) 81 self.CacheNameValid(name, True) 82 self.nameEdit.SetValue(name, docallback=False) 83 self.UpdateIsValidIconAndText(VALID) 84 uicore.layer.charactercreation.controller.metrics.last_name_randomized() 85 uicore.layer.charactercreation.controller.SetNameCallback(name) 86 self.charCounterLabel.SetText(self.CountRemainingCharacters()) 87 88 def OnTextEditChange(self, *args): 89 self.checkAvailabilityLabel.state = uiconst.UI_HIDDEN 90 self.checkAvailabilityIcon.state = uiconst.UI_HIDDEN 91 if self.checkNameValidThread: 92 self.checkNameValidThread.kill() 93 self.checkNameValidThread = uthread2.start_tasklet(self._CheckNameValidThread) 94 self.charCounterLabel.SetText(self.CountRemainingCharacters()) 95 96 def CountRemainingCharacters(self): 97 nameLength = len(self.nameEdit.GetText()) 98 remainingAllowedCharacters = appConst.maximumCharacterNameLength - nameLength 99 if remainingAllowedCharacters < 0: 100 return 0 101 return remainingAllowedCharacters 102 103 def _CheckNameValidThread(self): 104 uthread2.Sleep(1.0) 105 self.CheckAvailability() 106 107 def OnFirstNameFocus(self, *args): 108 uicore.layer.charactercreation.controller.metrics.first_name_focused() 109 110 def OnLastNameFocus(self, *args): 111 uicore.layer.charactercreation.controller.metrics.last_name_focused() 112 113 def OnCharInName(self, char, *args): 114 if char == uiconst.VK_SPACE: 115 allowedNumSpaces = 2 116 numSpaces = self.nameEdit.text.count(' ') 117 if numSpaces >= allowedNumSpaces: 118 return False 119 return True 120 121 def OnCharInLastName(self, char, *args): 122 if char == uiconst.VK_SPACE: 123 return False 124 return True 125 126 def CheckAvailability(self, *args): 127 if self.isCheckingName: 128 return 129 self.isCheckingName = True 130 try: 131 charName = self.GetCharacterNameEntered() 132 self.NotifyCCLayerOfAvailabilityCheck(charName) 133 isValidCode = self.IsNameValid(charName) 134 self.UpdateIsValidIconAndText(isValidCode) 135 isAvailable = utillib.KeyVal() 136 uicore.layer.charactercreation.controller.metrics.name_available_checked(isValidCode) 137 if isValidCode == VALID: 138 isAvailable.charName = charName 139 isAvailable.reason = '' 140 return isAvailable 141 isAvailable.charName = None 142 isAvailable.reason = self.GetIsValidText(isValidCode) 143 return isAvailable 144 finally: 145 self.isCheckingName = False 146 self.checkNameValidThread = None 147 148 def GetIsValidText(self, isValidCode): 149 if isValidCode == VALID: 150 return '' 151 reason = invalidNameReasonNamesByID.get(isValidCode, 'UI/CharacterCreation/InvalidName/IllegalCharacter') 152 return GetByLabel(reason) 153 154 def UpdateIsValidIconAndText(self, isValidCode): 155 self.checkAvailabilityIcon.state = uiconst.UI_DISABLED 156 self.checkAvailabilityLabel.state = uiconst.UI_DISABLED 157 if isValidCode == VALID: 158 texturePath = 'res:/UI/Texture/Icons/38_16_193.png' 159 self.checkAvailabilityIcon.SetRGBA(*Icon.default_color) 160 else: 161 texturePath = 'res:/UI/Texture/classes/Moonmining/warning.png' 162 self.checkAvailabilityIcon.SetRGBA(*Color.RED) 163 self.checkAvailabilityIcon.SetTexturePath(texturePath) 164 self.checkAvailabilityLabel.text = self.GetIsValidText(isValidCode) 165 166 def GetCharacterNameEntered(self): 167 charName = self.nameEdit.GetValue().strip() 168 self.nameEdit.CloseHistoryMenu() 169 uicore.layer.charactercreation.controller.SetNameCallback(charName) 170 return charName 171 172 def IsNameValid(self, charName): 173 if charName in self.namesChecked: 174 isValid = self.namesChecked[charName] 175 else: 176 isValid = sm.RemoteSvc('charUnboundMgr').ValidateNameEx(charName, len(self.namesChecked)) 177 self.CacheNameValid(charName, isValid) 178 return isValid 179 180 def CacheNameValid(self, charName, isValid): 181 self.namesChecked[charName] = isValid 182 183 def NotifyCCLayerOfAvailabilityCheck(self, name): 184 uicore.layer.charactercreation.controller.OnAvailabilityCheck(name)