def __init__(self, exclude=None):
     super(SearchUsersDataProvider, self).__init__(SearchUsersProcessor())
     self._converter = ContactConverter()
     if exclude is not None:
         self.__exclude = exclude
     else:
         self.__exclude = []
    def __makeTableData(self):
        ms = i18n.makeString
        result = []
        refSystem = game_control.g_instance.refSystem
        referrals = refSystem.getReferrals()
        numOfReferrals = len(referrals)
        for i, item in enumerate(referrals):
            referralNumber = text_styles.stats(ms('%d.' % (i + 1)))
            dbID = item.getAccountDBID()
            user = self.usersStorage.getUser(dbID)
            if not user:
                raise AssertionError('User must be defined')
                contactConverter = ContactConverter()
                contactData = contactConverter.makeVO(user)
                xpIcon = RES_ICONS.MAPS_ICONS_LIBRARY_NORMALXPICON
                icon = icons.makeImageTag(xpIcon, 16, 16, -3, 0)
                bonus, timeLeft = item.getBonus()
                if bonus == 1:
                    multiplier = '-'
                    multiplierTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_MULTIPLIER_X1
                    icon = ''
                else:
                    multiplier = 'x%s' % BigWorld.wg_getNiceNumberFormat(bonus)
                    multiplierTooltip = ''
                if timeLeft:
                    multiplierTime = text_styles.main(ms(item.getBonusTimeLeftStr()))
                    expMultiplierText = text_styles.standard(ms(MENU.REFERRALMANAGEMENTWINDOW_REFERRALSTABLE_LEFTTIME, time=multiplierTime))
                else:
                    expMultiplierText = ''
                multiplierFactor = text_styles.credits(multiplier)
                multiplierStr = ms(icon + '<nobr>' + multiplierFactor + ' ' + expMultiplierText)
                referralData = {'accID': dbID,
                 'fullName': user.getFullName(),
                 'userName': user.getName(),
                 'clanAbbrev': user.getClanAbbrev()}
                canInviteToSquad = self.prbFunctional.getEntityType() in (PREBATTLE_TYPE.NONE, PREBATTLE_TYPE.TRAINING) or self.prbFunctional.getEntityType() == PREBATTLE_TYPE.SQUAD and self.prbFunctional.getPermissions().canSendInvite()
                btnEnabled = canInviteToSquad or False
                btnTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_CREATESQUADBTN_DISABLED_SQUADISFULL
            else:
                btnEnabled = True
                btnTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_CREATESQUADBTN_ENABLED
            result.append({'isEmpty': False,
             'contactData': contactData,
             'referralNo': referralNumber,
             'referralVO': referralData,
             'exp': BigWorld.wg_getNiceNumberFormat(item.getXPPool()),
             'multiplier': multiplierStr,
             'multiplierTooltip': multiplierTooltip,
             'btnEnabled': btnEnabled,
             'btnTooltip': btnTooltip})

        if numOfReferrals < self.MIN_REF_NUMBER:
            for i in xrange(numOfReferrals, self.MIN_REF_NUMBER):
                referralNumber = text_styles.disabled(ms(MENU.REFERRALMANAGEMENTWINDOW_REFERRALSTABLE_EMPTYLINE, lineNo=str(i + 1)))
                result.append({'isEmpty': True,
                 'referralNo': referralNumber})

        self.as_setTableDataS(result)
Esempio n. 3
0
 def __init__(self, searchProcessor=None, exclude=None):
     if searchProcessor is None:
         searchProcessor = SearchUsersProcessor()
     super(SearchUsersDataProvider, self).__init__(searchProcessor)
     self._converter = ContactConverter()
     if exclude is not None:
         self.__exclude = exclude
     else:
         self.__exclude = []
     return
Esempio n. 4
0
class SearchUsersDataProvider(SearchDataProvider):

    def __init__(self, searchProcessor=None, exclude=None):
        if searchProcessor is None:
            searchProcessor = SearchUsersProcessor()
        super(SearchUsersDataProvider, self).__init__(searchProcessor)
        self._converter = ContactConverter()
        if exclude is not None:
            self.__exclude = exclude
        else:
            self.__exclude = []
        return

    def buildList(self, result):
        self._list = []
        result = sorted(result, cmp=self._getSearchComparator)
        for item in result:
            if item.getID() not in self.__exclude:
                self._list.append(self._converter.makeVO(item))

    def emptyItem(self):
        return None

    def init(self, flashObject, exHandlers=None):
        super(SearchUsersDataProvider, self).init(flashObject, exHandlers)
        g_messengerEvents.users.onUserActionReceived += self.__onUserActionReceived
        g_messengerEvents.users.onUserStatusUpdated += self.__onUserStatusUpdated

    def fini(self):
        super(SearchUsersDataProvider, self).fini()
        g_messengerEvents.users.onUserActionReceived -= self.__onUserActionReceived
        g_messengerEvents.users.onUserStatusUpdated -= self.__onUserStatusUpdated

    def _getSearchComparator(self, user, other):
        return cmp(user.getName().lower(), other.getName().lower())

    def __onUserActionReceived(self, _, user, shadowMode):
        self.__updateUserInSearch(user)

    def __onUserStatusUpdated(self, user):
        self.__updateUserInSearch(user)

    def __updateUserInSearch(self, user):
        for idx, item in enumerate(self._list):
            if item['dbID'] == user.getID():
                newItem = self._converter.makeVO(user)
                newItem['userProps']['clanAbbrev'] = item['userProps']['clanAbbrev']
                self._list[idx] = newItem
                break

        self.refresh()
class SearchUsersDataProvider(SearchDataProvider):

    def __init__(self, searchProcessor = None, exclude = None):
        if searchProcessor is None:
            searchProcessor = SearchUsersProcessor()
        super(SearchUsersDataProvider, self).__init__(searchProcessor)
        self._converter = ContactConverter()
        if exclude is not None:
            self.__exclude = exclude
        else:
            self.__exclude = []
        return

    def buildList(self, result):
        self._list = []
        result = sorted(result, cmp=self._getSearchComparator)
        for item in result:
            if item.getID() not in self.__exclude:
                self._list.append(self._converter.makeVO(item))

    def emptyItem(self):
        return None

    def init(self, flashObject, exHandlers = None):
        super(SearchUsersDataProvider, self).init(flashObject, exHandlers)
        g_messengerEvents.users.onUserActionReceived += self.__onUserActionReceived
        g_messengerEvents.users.onUserStatusUpdated += self.__onUserStatusUpdated

    def fini(self):
        super(SearchUsersDataProvider, self).fini()
        g_messengerEvents.users.onUserActionReceived -= self.__onUserActionReceived
        g_messengerEvents.users.onUserStatusUpdated -= self.__onUserStatusUpdated

    def _getSearchComparator(self, user, other):
        return cmp(user.getName().lower(), other.getName().lower())

    def __onUserActionReceived(self, _, user):
        self.__updateUserInSearch(user)

    def __onUserStatusUpdated(self, user):
        self.__updateUserInSearch(user)

    def __updateUserInSearch(self, user):
        for idx, item in enumerate(self._list):
            if item['dbID'] == user.getID():
                newItem = self._converter.makeVO(user)
                newItem['userProps']['clanAbbrev'] = item['userProps']['clanAbbrev']
                self._list[idx] = newItem
                break

        self.refresh()
Esempio n. 6
0
 def __init__(self, exclude = None):
     super(SearchUsersDataProvider, self).__init__(SearchUsersProcessor())
     self._converter = ContactConverter()
     if exclude is not None:
         self.__exclude = exclude
     else:
         self.__exclude = []
 def __init__(self, searchProcessor = None, exclude = None):
     if searchProcessor is None:
         searchProcessor = SearchUsersProcessor()
     super(SearchUsersDataProvider, self).__init__(searchProcessor)
     self._converter = ContactConverter()
     if exclude is not None:
         self.__exclude = exclude
     else:
         self.__exclude = []
     return
Esempio n. 8
0
 def sendData(self, data):
     self._dbID = long(data.dbID)
     userEntity = self.usersStorage.getUser(self._dbID)
     if userEntity is None:
         userProps = {'userName': data.name}
     else:
         userProps = ContactConverter.makeBaseUserProps(userEntity)
     scheme = g_settings.getColorScheme('contacts')
     userProps['rgb'] = scheme.getColors('clanMember')[0]
     self.as_setUserPropsS(userProps)
     return
Esempio n. 9
0
 def sendData(self, data):
     self._dbID = long(data.dbID)
     userEntity = self.usersStorage.getUser(self._dbID)
     if userEntity is None:
         userProps = {'userName': data.name}
     else:
         userProps = ContactConverter.makeBaseUserProps(userEntity)
     scheme = g_settings.getColorScheme('contacts')
     userProps['rgb'] = scheme.getColors('clanMember')[0]
     self._note = userEntity.getNote() if userEntity else ''
     if self._note:
         self.as_setInputTextS(self._note)
     self.as_setUserPropsS(userProps)
Esempio n. 10
0
 def __init__(self, ctx=None):
     super(SendInvitesWindow, self).__init__()
     self._onlineMode = True
     self._ctx = ctx
     self._converter = ContactConverter()
     if 'ctrlType' in ctx:
         self._ctrlType = ctx['ctrlType']
     else:
         self._ctrlType = CTRL_ENTITY_TYPE.UNKNOWN
         LOG_ERROR('Control type is not defined', ctx)
     if 'prbName' in ctx:
         self._prbName = ctx['prbName']
     else:
         self._prbName = 'prebattle'
     if 'showClanOnly' in ctx:
         self._showClanOnly = ctx['showClanOnly']
     else:
         self._showClanOnly = False
     if 'invites' in ctx:
         self._invites = ctx['invites']
     else:
         self._invites = ()
 def _makeVO(self, memberData):
     memberDBID = memberData.getDbID()
     contactEntity = self.userStorage.getUser(memberDBID)
     if contactEntity:
         userVO = ContactConverter().makeVO(contactEntity)
         userVO['userProps']['clanAbbrev'] = ''
     else:
         userVO = {'userProps': {'userName': self.__getMemberName(memberData)}}
     return {'dbID': memberDBID,
      'userName': self.__getMemberName(memberData),
      'post': items.formatField(getter=memberData.getRoleString),
      'postIcon': memberData.getRoleIcon(),
      'personalRating': items.formatField(getter=memberData.getGlobalRating, formatter=BigWorld.wg_getIntegralFormat),
      'battlesCount': items.formatField(getter=memberData.getBattlesCount, formatter=BigWorld.wg_getIntegralFormat),
      'wins': items.formatField(getter=memberData.getBattlesPerformanceAvg, formatter=lambda x: BigWorld.wg_getNiceNumberFormat(x) + '%'),
      'awgExp': items.formatField(getter=memberData.getBattleXpAvg, formatter=BigWorld.wg_getIntegralFormat),
      'daysInClan': items.formatField(getter=memberData.getDaysInClan, formatter=BigWorld.wg_getIntegralFormat),
      'canShowContextMenu': memberDBID != getAccountDatabaseID(),
      'contactItem': userVO}
Esempio n. 12
0
 def __init__(self, ctx=None):
     super(PrbSendInvitesWindow, self).__init__()
     self._onlineMode = True
     self._ctx = ctx
     self._converter = ContactConverter()
     if "ctrlType" in ctx:
         self._ctrlType = ctx["ctrlType"]
     else:
         self._ctrlType = CTRL_ENTITY_TYPE.UNKNOWN
         LOG_ERROR("Control type is not defined", ctx)
     if "prbName" in ctx:
         self._prbName = ctx["prbName"]
     else:
         self._prbName = "prebattle"
     if "showClanOnly" in ctx:
         self._showClanOnly = ctx["showClanOnly"]
     else:
         self._showClanOnly = False
     if "invites" in ctx:
         self._invites = ctx["invites"]
     else:
         self._invites = ()
Esempio n. 13
0
 def __init__(self, ctx = None):
     super(SendInvitesWindow, self).__init__()
     self._onlineMode = True
     self._ctx = ctx
     self._converter = ContactConverter()
     if 'ctrlType' in ctx:
         self._ctrlType = ctx['ctrlType']
     else:
         self._ctrlType = CTRL_ENTITY_TYPE.UNKNOWN
         LOG_ERROR('Control type is not defined', ctx)
     if 'prbName' in ctx:
         self._prbName = ctx['prbName']
     else:
         self._prbName = 'prebattle'
     if 'showClanOnly' in ctx:
         self._showClanOnly = ctx['showClanOnly']
     else:
         self._showClanOnly = False
     if 'invites' in ctx:
         self._invites = ctx['invites']
     else:
         self._invites = ()
Esempio n. 14
0
class SendInvitesWindow(SendInvitesWindowMeta, ISearchHandler):

    def __init__(self, ctx = None):
        super(SendInvitesWindow, self).__init__()
        self._onlineMode = True
        self._ctx = ctx
        self._converter = ContactConverter()
        if 'ctrlType' in ctx:
            self._ctrlType = ctx['ctrlType']
        else:
            self._ctrlType = CTRL_ENTITY_TYPE.UNKNOWN
            LOG_ERROR('Control type is not defined', ctx)
        if 'prbName' in ctx:
            self._prbName = ctx['prbName']
        else:
            self._prbName = 'prebattle'
        if 'showClanOnly' in ctx:
            self._showClanOnly = ctx['showClanOnly']
        else:
            self._showClanOnly = False
        if 'invites' in ctx:
            self._invites = ctx['invites']
        else:
            self._invites = ()

    def getAllAvailableContacts(self):
        return self.pyTree.getMainDP().getContactsList()

    @storage_getter('users')
    def usersStorage(self):
        return None

    @prbDispatcherProperty
    def prbDispatcher(self):
        pass

    @property
    def pyTree(self):
        tree = None
        if CONTACTS_ALIASES.CONTACTS_TREE in self.components:
            tree = self.components[CONTACTS_ALIASES.CONTACTS_TREE]
        return tree

    def showError(self, value):
        SystemMessages.pushI18nMessage(value, type=SystemMessages.SM_TYPE.Error)

    def setOnlineFlag(self, value):
        if value is False:
            self._onlineMode = None
        else:
            self._onlineMode = True
        tree = self.pyTree
        if tree:
            tree.showContacts(onlineMode=self._onlineMode, showEmptyGroups=False, showFriends=not self._showClanOnly, showGroupMenu=False)
        return

    def _getTitle(self):
        return i18n.makeString(DIALOGS.SENDINVITES_COMMON_TITLE)

    def sendInvites(self, accountsToInvite, comment):
        functional = self.prbDispatcher.getFunctional(self._ctrlType)
        if functional:
            functional.request(SendInvitesCtx(accountsToInvite, comment))
            self.__showSentInviteMessages(accountsToInvite)
        else:
            LOG_ERROR('Functional is not found', self._ctrlType)

    def onWindowClose(self):
        self.destroy()

    def _onRegisterFlashComponent(self, viewPy, alias):
        super(SendInvitesWindow, self)._onRegisterFlashComponent(viewPy, alias)
        if alias == CONTACTS_ALIASES.CONTACTS_TREE:
            tree = viewPy
            tree.onListStateChanged += self.__onTreeListStateChanged
            tree.showContacts(onlineMode=self._onlineMode, showEmptyGroups=False, showFriends=not self._showClanOnly, showGroupMenu=False)

    def _populate(self):
        super(SendInvitesWindow, self)._populate()
        usersEvents = g_messengerEvents.users
        usersEvents.onUserActionReceived += self.__onUserDataChanged
        usersEvents.onUserStatusUpdated += self.__onUserStatusUpdated
        self._initCooldown()
        self.as_setWindowTitleS(self._getTitle())
        self.as_setDefaultOnlineFlagS(self._onlineMode)

    def _dispose(self):
        self.pyTree.onListStateChanged -= self.__onTreeListStateChanged
        usersEvents = g_messengerEvents.users
        usersEvents.onUserActionReceived -= self.__onUserDataChanged
        usersEvents.onUserStatusUpdated -= self.__onUserStatusUpdated
        self._finiCooldown()
        super(SendInvitesWindow, self)._dispose()

    def _initCooldown(self):
        self.addListener(events.CoolDownEvent.PREBATTLE, self._handleSetCoolDown, scope=EVENT_BUS_SCOPE.LOBBY)

    def _finiCooldown(self):
        self.removeListener(events.CoolDownEvent.PREBATTLE, self._handleSetCoolDown, scope=EVENT_BUS_SCOPE.LOBBY)

    def _handleSetCoolDown(self, event):
        if event.requestID is REQUEST_TYPE.SEND_INVITE:
            self.as_onReceiveSendInvitesCooldownS(event.coolDown)

    def __onUserDataChanged(self, _, user):
        self.as_onContactUpdatedS(self._converter.makeVO(user))

    def __onUserStatusUpdated(self, user):
        self.as_onContactUpdatedS(self._converter.makeVO(user))

    def __onTreeListStateChanged(self, state, isEmpty):
        if state == ContactsTreeComponent.LIST_EMPTY_STATE:
            self.as_onListStateChangedS(isEmpty)

    def __showSentInviteMessages(self, accountsToInvite):
        getUser = self.usersStorage.getUser
        for dbID in accountsToInvite:
            user = getUser(dbID)
            showSentInviteMessage(user)
Esempio n. 15
0
class ContactTooltipData(ToolTipBaseData):

    def __init__(self, context):
        super(ContactTooltipData, self).__init__(context, TOOLTIP_TYPE.CONTACT)
        self.__converter = ContactConverter()

    @storage_getter('users')
    def usersStorage(self):
        return None

    def getDisplayableData(self, dbID, defaultName):
        userEntity = self.usersStorage.getUser(dbID)
        if userEntity is None:
            return {'userProps': {'userName': defaultName}}
        else:
            commonGuiData = self.__converter.makeVO(userEntity, False)
            statusDescription = ''
            tags = userEntity.getTags()
            if userEntity.isOnline():
                if USER_TAG.PRESENCE_DND in tags:
                    statusDescription = makeString(TOOLTIPS.CONTACT_STATUS_INBATTLE)
                else:
                    statusDescription = makeString(TOOLTIPS.CONTACT_STATUS_ONLINE)
            commonGuiData['statusDescription'] = statusDescription
            units = []
            currentUnit = ''
            region = g_lobbyContext.getRegionCode(userEntity.getID())
            if region is not None:
                currentUnit += self.__makeUnitStr(TOOLTIPS.CONTACT_UNITS_HOMEREALM, region)
            clanAbbrev = userEntity.getClanAbbrev()
            if clanAbbrev:
                currentUnit += self.__addBR(currentUnit)
                currentUnit += self.__makeUnitStr(TOOLTIPS.CONTACT_UNITS_CLAN, '[{0}]'.format(clanAbbrev))
            if currentUnit != '':
                units.append(currentUnit)
            currentUnit = ''
            if USER_TAG.IGNORED in tags:
                currentUnit += self.__makeIconUnitStr('contactIgnored.png', TOOLTIPS.CONTACT_UNITS_STATUS_DESCRIPTION_IGNORED)
            elif USER_TAG.SUB_TO not in tags and (userEntity.isFriend() or USER_TAG.SUB_PENDING_IN in tags):
                currentUnit += self.__addBR(currentUnit)
                currentUnit += self.__makeIconUnitStr('contactConfirmNeeded.png', TOOLTIPS.CONTACT_UNITS_STATUS_DESCRIPTION_PENDINGFRIENDSHIP)
            if USER_TAG.REFERRER in tags:
                currentUnit += self.__addBR(currentUnit)
                currentUnit += self.__makeReferralStr(TOOLTIPS.CONTACT_UNITS_STATUS_DESCRIPTION_RECRUITER)
            elif USER_TAG.REFERRAL in tags:
                currentUnit += self.__addBR(currentUnit)
                currentUnit += self.__makeReferralStr(TOOLTIPS.CONTACT_UNITS_STATUS_DESCRIPTION_RECRUIT)
            if currentUnit != '':
                units.append(currentUnit)
            groupsStr = ''
            userGroups = userEntity.getGroups()
            if len(userGroups) > 0:
                groupsStr += ', '.join(userGroups)
            if clanAbbrev:
                groupsStr += self.__addComma(groupsStr)
                groupsStr += self.__converter.getClanFullName(clanAbbrev)
            if USER_TAG.IGNORED in tags:
                groupsStr += self.__addComma(groupsStr)
                groupsStr += makeString(MESSENGER.MESSENGER_CONTACTS_MAINGROPS_OTHER_IGNORED)
            if USER_TAG.SUB_PENDING_IN in tags:
                groupsStr += self.__addComma(groupsStr)
                groupsStr += makeString(MESSENGER.MESSENGER_CONTACTS_MAINGROPS_OTHER_FRIENDSHIPREQUEST)
            if groupsStr != '':
                units.append(self.__makeUnitStr(TOOLTIPS.CONTACT_UNITS_GROUPS, groupsStr + '.'))
            if len(units) > 0:
                commonGuiData['units'] = units
            return commonGuiData

    def __makeUnitStr(self, descr, val):
        return makeHtmlString('html_templates:contacts/contact', 'tooltipUnitTxt', {'descr': makeString(descr),
         'value': val})

    def __makeIconUnitStr(self, icon, descr):
        return self.__converter.makeIconTag(iconPath=icon) + ' ' + makeHtmlString('html_templates:contacts/contact', 'tooltipSimpleTxt', {'descr': makeString(descr)})

    def __makeReferralStr(self, descr):
        return self.__converter.makeIconTag(key='referrTag') + ' ' + makeHtmlString('html_templates:contacts/contact', 'tooltipSimpleTxt', {'descr': makeString(descr)})

    def __addBR(self, currentUnit):
        if currentUnit != '':
            return '<br/>'
        return ''

    def __addComma(self, currStr):
        if currStr != '':
            return ', '
        return ''
Esempio n. 16
0
class SendInvitesWindow(SendInvitesWindowMeta, ISearchHandler):
    def __init__(self, ctx=None):
        super(SendInvitesWindow, self).__init__()
        self._onlineMode = True
        self._ctx = ctx
        self._converter = ContactConverter()
        if 'ctrlType' in ctx:
            self._ctrlType = ctx['ctrlType']
        else:
            self._ctrlType = CTRL_ENTITY_TYPE.UNKNOWN
            LOG_ERROR('Control type is not defined', ctx)
        if 'prbName' in ctx:
            self._prbName = ctx['prbName']
        else:
            self._prbName = 'prebattle'
        if 'showClanOnly' in ctx:
            self._showClanOnly = ctx['showClanOnly']
        else:
            self._showClanOnly = False
        if 'invites' in ctx:
            self._invites = ctx['invites']
        else:
            self._invites = ()

    def getAllAvailableContacts(self):
        return self.pyTree.getMainDP().getContactsList()

    @storage_getter('users')
    def usersStorage(self):
        return None

    @prbDispatcherProperty
    def prbDispatcher(self):
        pass

    @prbEntityProperty
    def prbEntity(self):
        pass

    @property
    def pyTree(self):
        tree = None
        if CONTACTS_ALIASES.CONTACTS_TREE in self.components:
            tree = self.components[CONTACTS_ALIASES.CONTACTS_TREE]
        return tree

    def showError(self, value):
        SystemMessages.pushI18nMessage(value,
                                       type=SystemMessages.SM_TYPE.Error)

    def setOnlineFlag(self, value):
        if value is False:
            self._onlineMode = None
        else:
            self._onlineMode = True
        tree = self.pyTree
        if tree:
            tree.showContacts(onlineMode=self._onlineMode,
                              showEmptyGroups=False,
                              showFriends=not self._showClanOnly,
                              showGroupMenu=False)
        return

    def _getTitle(self):
        return i18n.makeString(DIALOGS.SENDINVITES_COMMON_TITLE)

    def sendInvites(self, accountsToInvite, comment):
        self.prbEntity.request(SendInvitesCtx(accountsToInvite, comment))

    def onWindowClose(self):
        self.destroy()

    def _onRegisterFlashComponent(self, viewPy, alias):
        super(SendInvitesWindow, self)._onRegisterFlashComponent(viewPy, alias)
        if alias == CONTACTS_ALIASES.CONTACTS_TREE:
            tree = viewPy
            tree.onListStateChanged += self.__onTreeListStateChanged
            tree.showContacts(onlineMode=self._onlineMode,
                              showEmptyGroups=False,
                              showFriends=not self._showClanOnly,
                              showGroupMenu=False)

    def _populate(self):
        super(SendInvitesWindow, self)._populate()
        usersEvents = g_messengerEvents.users
        usersEvents.onUserActionReceived += self.__onUserDataChanged
        usersEvents.onUserStatusUpdated += self.__onUserStatusUpdated
        self._initCooldown()
        self.as_setWindowTitleS(self._getTitle())
        self.as_setDefaultOnlineFlagS(self._onlineMode)

    def _dispose(self):
        self.pyTree.onListStateChanged -= self.__onTreeListStateChanged
        usersEvents = g_messengerEvents.users
        usersEvents.onUserActionReceived -= self.__onUserDataChanged
        usersEvents.onUserStatusUpdated -= self.__onUserStatusUpdated
        self._finiCooldown()
        super(SendInvitesWindow, self)._dispose()

    def _initCooldown(self):
        self.addListener(events.CoolDownEvent.PREBATTLE,
                         self._handleSetCoolDown,
                         scope=EVENT_BUS_SCOPE.LOBBY)

    def _finiCooldown(self):
        self.removeListener(events.CoolDownEvent.PREBATTLE,
                            self._handleSetCoolDown,
                            scope=EVENT_BUS_SCOPE.LOBBY)

    def _handleSetCoolDown(self, event):
        if event.requestID is REQUEST_TYPE.SEND_INVITE:
            self.as_onReceiveSendInvitesCooldownS(event.coolDown)

    def __onUserDataChanged(self, _, user):
        self.as_onContactUpdatedS(self._converter.makeVO(user))

    def __onUserStatusUpdated(self, user):
        self.as_onContactUpdatedS(self._converter.makeVO(user))

    def __onTreeListStateChanged(self, state, isEmpty):
        if state == ContactsTreeComponent.LIST_EMPTY_STATE:
            self.as_onListStateChangedS(isEmpty)
Esempio n. 17
0
 def __init__(self, context):
     super(ContactTooltipData, self).__init__(context, TOOLTIP_TYPE.CONTACT)
     self.__converter = ContactConverter()
    def __makeTableData(self):
        ms = i18n.makeString
        result = []
        referrals = self.refSystem.getReferrals()
        numOfReferrals = len(referrals)
        for i, item in enumerate(referrals):
            referralNumber = text_styles.stats(ms('%d.' % (i + 1)))
            dbID = item.getAccountDBID()
            user = self.usersStorage.getUser(dbID)
            if not user:
                raise AssertionError('User must be defined')
                contactConverter = ContactConverter()
                contactData = contactConverter.makeVO(user)
                xpIcon = RES_ICONS.MAPS_ICONS_LIBRARY_NORMALXPICON
                icon = icons.makeImageTag(xpIcon, 16, 16, -3, 0)
                bonus, timeLeft = item.getBonus()
                if bonus == 1:
                    multiplier = '-'
                    multiplierTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_MULTIPLIER_X1
                    icon = ''
                else:
                    multiplier = 'x%s' % BigWorld.wg_getNiceNumberFormat(bonus)
                    multiplierTooltip = ''
                if timeLeft:
                    multiplierTime = text_styles.main(
                        ms(item.getBonusTimeLeftStr()))
                    expMultiplierText = text_styles.standard(
                        ms(MENU.
                           REFERRALMANAGEMENTWINDOW_REFERRALSTABLE_LEFTTIME,
                           time=multiplierTime))
                else:
                    expMultiplierText = ''
                multiplierFactor = text_styles.credits(multiplier)
                multiplierStr = ms(icon + '<nobr>' + multiplierFactor + ' ' +
                                   expMultiplierText)
                referralData = {
                    'accID': dbID,
                    'fullName': user.getFullName(),
                    'userName': user.getName(),
                    'clanAbbrev': user.getClanAbbrev()
                }
                permissions = self.prbEntity.getPermissions()
                canInviteToSquad = permissions.canCreateSquad(
                ) or self.prbEntity.getEntityType(
                ) == PREBATTLE_TYPE.SQUAD and permissions.canSendInvite()
                btnEnabled = canInviteToSquad or False
                btnTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_CREATESQUADBTN_DISABLED_SQUADISFULL
            else:
                btnEnabled = True
                btnTooltip = TOOLTIPS.REFERRALMANAGEMENTWINDOW_CREATESQUADBTN_ENABLED
            result.append({
                'isEmpty':
                False,
                'contactData':
                contactData,
                'referralNo':
                referralNumber,
                'referralVO':
                referralData,
                'exp':
                BigWorld.wg_getNiceNumberFormat(item.getXPPool()),
                'multiplier':
                multiplierStr,
                'multiplierTooltip':
                multiplierTooltip,
                'btnEnabled':
                btnEnabled,
                'btnTooltip':
                btnTooltip
            })

        if numOfReferrals < self.MIN_REF_NUMBER:
            for i in xrange(numOfReferrals, self.MIN_REF_NUMBER):
                referralNumber = text_styles.disabled(
                    ms(MENU.REFERRALMANAGEMENTWINDOW_REFERRALSTABLE_EMPTYLINE,
                       lineNo=str(i + 1)))
                result.append({'isEmpty': True, 'referralNo': referralNumber})

        self.as_setTableDataS(result)