def __makeVacationData(self): alertMessage = '' blockBtnEnabled = True daysBeforeVacation = -1 fort = self.fortCtrl.getFort() isVacationEnabled = fort.isVacationEnabled() inProcess, inCooldown = fort.getVacationProcessing() _, vacationEnd = fort.getVacationDate() blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNENABLED descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONDESCRIPTION conditionPostfix = text_styles.standard( i18n.makeString(FORTIFICATIONS. SETTINGSWINDOW_BLOCKCONDITION_VACATIONNOTPLANNED)) if inProcess or inCooldown: blockBtnEnabled = False if fort.isOnVacation(): blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLED daysBeforeVacation = -1 elif time_utils.getTimeDeltaFromNow(vacationEnd) != 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLED else: cooldownEnd = vacationEnd + g_fortCache.vacationCooldownTime daysBeforeVacation = time_utils.getTimeDeltaFromNow( cooldownEnd) / time_utils.ONE_DAY + 1 if daysBeforeVacation == 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDSBLDLESSADAY daysBeforeVacation = -1 else: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLEDNOTPLANNED isVacationEnabled = False if isVacationEnabled: vacation = fort.getVacationDateTimeStr() if not self._isFortFrozen(): if not fort.isOnVacation(): conditionPostfix = text_styles.neutral(vacation) else: conditionPostfix = text_styles.success(vacation) else: conditionPostfix = text_styles.standard(vacation) conditionPrefix = text_styles.main( i18n.makeString( FORTIFICATIONS.settingswindow_blockcondition('vacation'))) blockDescr = text_styles.standard( i18n.makeString( FORTIFICATIONS.settingswindow_blockdescr('vacation'))) if alertMessage: alertMessage = icons.alert() + ' ' + alertMessage return { 'blockBtnEnabled': blockBtnEnabled, 'blockDescr': blockDescr, 'blockCondition': conditionPrefix + ' ' + conditionPostfix, 'alertMessage': alertMessage, 'blockBtnToolTip': blockBtnToolTip, 'daysBeforeVacation': daysBeforeVacation, 'descriptionTooltip': descriptionTooltip }
def __processDefencePeriodCallback(self): self.__cancelDefencePeriodCallback() fort = self.getFort() self._listeners.notify('onDefenceHourStateChanged') start, finish = fort.getClosestDefencePeriod() if fort.isOnDefenceHour(): timer = time_utils.getTimeDeltaFromNow(finish) else: timer = time_utils.getTimeDeltaFromNow(start) if timer > 0: self.__defencePeriodCallback = BigWorld.callback(timer, self.__processDefencePeriodCallback)
def __processDefencePeriodCallback(self): self.__cancelDefencePeriodCallback() fort = self.getFort() self._listeners.notify('onDefenceHourStateChanged') start, finish = fort.getClosestDefencePeriod() if fort.isOnDefenceHour(): timer = time_utils.getTimeDeltaFromNow(finish) else: timer = time_utils.getTimeDeltaFromNow(start) if timer > 0: self.__defencePeriodCallback = BigWorld.callback( timer, self.__processDefencePeriodCallback)
def __makeVacationData(self): alertMessage = "" blockBtnEnabled = True daysBeforeVacation = -1 fort = self.fortCtrl.getFort() isVacationEnabled = fort.isVacationEnabled() inProcess, inCooldown = fort.getVacationProcessing() _, vacationEnd = fort.getVacationDate() blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNENABLED descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONDESCRIPTION conditionPostfix = text_styles.standard( i18n.makeString(FORTIFICATIONS.SETTINGSWINDOW_BLOCKCONDITION_VACATIONNOTPLANNED) ) if inProcess or inCooldown: blockBtnEnabled = False if fort.isOnVacation(): blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLED daysBeforeVacation = -1 elif time_utils.getTimeDeltaFromNow(vacationEnd) != 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLED else: cooldownEnd = vacationEnd + g_fortCache.vacationCooldownTime daysBeforeVacation = time_utils.getTimeDeltaFromNow(cooldownEnd) / time_utils.ONE_DAY + 1 if daysBeforeVacation == 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDSBLDLESSADAY daysBeforeVacation = -1 else: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLEDNOTPLANNED isVacationEnabled = False if isVacationEnabled: vacation = fort.getVacationDateTimeStr() if not self._isFortFrozen(): if not fort.isOnVacation(): conditionPostfix = text_styles.neutral(vacation) else: conditionPostfix = text_styles.success(vacation) else: conditionPostfix = text_styles.standard(vacation) conditionPrefix = text_styles.main(i18n.makeString(FORTIFICATIONS.settingswindow_blockcondition("vacation"))) blockDescr = text_styles.standard(i18n.makeString(FORTIFICATIONS.settingswindow_blockdescr("vacation"))) if alertMessage: alertMessage = icons.alert() + " " + alertMessage return { "blockBtnEnabled": blockBtnEnabled, "blockDescr": blockDescr, "blockCondition": conditionPrefix + " " + conditionPostfix, "alertMessage": alertMessage, "blockBtnToolTip": blockBtnToolTip, "daysBeforeVacation": daysBeforeVacation, "descriptionTooltip": descriptionTooltip, }
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0): disableTTHeader = '' disableTTBody = '' if isPremiumAccount: if not premiumExpiryTime > 0: raise AssertionError deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString('#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString('#menu:header/account/premium/hours') buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric, 'timeLeft': timeLeft}) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy') disableTTHeader = canUpdatePremium or i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_HEADER) disableTTBody = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_BODY, number=time_utils.ONE_YEAR / time_utils.ONE_DAY) self.as_doDisableHeaderButtonS(self.BUTTONS.PREM, canUpdatePremium) self.as_setPremiumParamsS(isPremiumAccount, premiumBtnLbl, buyPremiumLabel, canUpdatePremium, disableTTHeader, disableTTBody)
def __getTillTimeString(self, endTime): timeDelta = time_utils.getTimeDeltaFromNow(endTime) if timeDelta > time_utils.ONE_DAY: formatter = text_styles.neutral else: formatter = text_styles.alert return formatter(time_utils.getTillTimeString(timeDelta, RANKED_BATTLES.STATUS_TIMELEFT))
def getProductionCooldown(self): productionTime = self.orderInProduction.get('timeFinish') if productionTime: return time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(productionTime)) else: return 0
def __getClosestTankmanUpdateTime(self): if len(self.__tankmenList) > 0: timeOfClosestDeletion = self.__tankmenList[ -1].dismissedAt + self.__tankmanLiveTime return time_utils.getTimeDeltaFromNow(timeOfClosestDeletion) + 1 else: return 0
def getTimeLeft(self): if self.rentExpiryTime != float('inf'): expiryTime = max(self.rentExpiryTime, self._getSeasonExpiryTime()) return float( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(expiryTime))) return float('inf')
def __canBuyPremium(self): if self.__isPremiumAccount(): premiumExpiryTime = self.itemsCache.items.stats.premiumExpiryTime else: premiumExpiryTime = 0 deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) return deltaInSeconds < time_utils.ONE_YEAR
def __makePeripheryData(self): fort = self.fortCtrl.getFort() optionsList = g_preDefinedHosts.getSimpleHostsList(g_preDefinedHosts.hostsWithRoaming()) servername = None for key, name, csisStatus, peripheryID in optionsList: if fort.peripheryID == peripheryID: servername = name if servername is None: servername = connectionManager.serverUserName _, inCooldown = fort.getPeripheryProcessing() timestamp, _, _ = fort.events.get(FORT_EVENT_TYPE.PERIPHERY_COOLDOWN, (0, 0, 0)) buttonEnabled = not inCooldown buttonToolTip = self.__makePeripheryBtnToolTip( buttonEnabled, time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(timestamp)) ) descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_PERIPHERYDESCRIPTION if self._isFortFrozen(): peripheryName = text_styles.standard(str(servername)) else: peripheryName = text_styles.neutral(str(servername)) return { "peripheryTitle": text_styles.main(i18n.makeString(FORTIFICATIONS.SETTINGSWINDOW_PEREPHERYTITLE)), "peripheryName": peripheryName, "buttonEnabled": buttonEnabled, "buttonToolTip": buttonToolTip, "descriptionTooltip": descriptionTooltip, }
def __startRentTimeNotifyCallback(self): if not self.itemsCache.isSynced(): return self.__vehiclesForUpdate = [] rentedVehicles = self.itemsCache.items.getVehicles(REQ_CRITERIA.VEHICLE.RENT ^ REQ_CRITERIA.VEHICLE.RENT_PROMOTION).values() notificationList = [] for vehicle in rentedVehicles: delta = vehicle.rentLeftTime if delta > 0: notificationList.append((vehicle.intCD, self.getDeltaPeriod(delta), vehicle.isRentPromotion)) nextRentNotification = maxint if notificationList: _, nextRentNotification, forceUpdate = min(notificationList, key=itemgetter(1)) for item in notificationList: if item[1] == nextRentNotification or forceUpdate: self.__vehiclesForUpdate.append(item[0]) nextRentNotification = max(nextRentNotification, 0) for seasonType in SEASON_NAME_BY_TYPE: currentSeason = self.seasonsController.getCurrentSeason(seasonType) if currentSeason: now = time_utils.getCurrentLocalServerTimestamp() if currentSeason.hasActiveCycle(now): nextCycleChange = currentSeason.getCycleEndDate() else: nextCycleChange = currentSeason.getCycleStartDate() delta = int(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(nextCycleChange))) if delta > 0: nextRentNotification = min(nextRentNotification, self.getDeltaPeriod(delta)) + 1 if not notificationList and nextRentNotification == maxint: return self.__rentNotifyTimeCallback = BigWorld.callback(nextRentNotification, self.__notifyRentTime)
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0): disableTTHeader = '' disableTTBody = '' isNavigationEnabled = True if self.prbDispatcher: isNavigationEnabled = not self.prbDispatcher.getFunctionalState().isNavigationDisabled() if isPremiumAccount: if not premiumExpiryTime > 0: raise AssertionError deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString('#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString('#menu:header/account/premium/hours') buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric, 'timeLeft': timeLeft}) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy') if not canUpdatePremium: disableTTHeader = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_HEADER) disableTTBody = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_BODY, number=time_utils.ONE_YEAR / time_utils.ONE_DAY) self.as_doDisableHeaderButtonS(self.BUTTONS.PREM, canUpdatePremium and isNavigationEnabled) hasPersonalDiscount = len(g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0 tooltip = canUpdatePremium or {'header': disableTTHeader, 'body': disableTTBody} else: tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND if isPremiumAccount else TOOLTIPS.HEADER_PREMIUM_BUY self.as_setPremiumParamsS(isPremiumAccount, premiumBtnLbl, buyPremiumLabel, canUpdatePremium, disableTTHeader, disableTTBody, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
def __canBuyPremium(self): if self.__isPremiumAccount(): premiumExpiryTime = self._items.stats.premiumExpiryTime else: premiumExpiryTime = 0 deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) return deltaInSeconds < time_utils.ONE_YEAR
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0): if isPremiumAccount: if not premiumExpiryTime > 0: raise AssertionError deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString('#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString('#menu:header/account/premium/hours') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric, 'timeLeft': timeLeft}) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR buyPremiumLabel = '' if canUpdatePremium: buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium') else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy') hasPersonalDiscount = len(g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0 tooltip = canUpdatePremium or formatters.getLimitExceededPremiumTooltip() elif isPremiumAccount: tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND else: tooltip = TOOLTIPS.HEADER_PREMIUM_BUY self.as_setPremiumParamsS(premiumBtnLbl, buyPremiumLabel, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime=0): if not (isPremiumAccount and premiumExpiryTime > 0): raise AssertionError deltaInSeconds = float( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString( '#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString( '#menu:header/account/premium/hours') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', { 'timeMetric': timeMetric, 'timeLeft': timeLeft }) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR buyPremiumLabel = self._getPremiumLabelText(True, canUpdatePremium) else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = self._getPremiumLabelText(False, False) hasPersonalDiscount = self.__hasPremiumPacketDiscount() tooltip = self._getPremiumTooltipText(isPremiumAccount, canUpdatePremium) self.as_setPremiumParamsS(premiumBtnLbl, buyPremiumLabel, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime = 0): disableTTHeader = '' disableTTBody = '' if isPremiumAccount: assert premiumExpiryTime > 0 deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString('#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString('#menu:header/account/premium/hours') buyPremiumLabel = i18n.makeString('#menu:headerButtons/doLabel/premium') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', {'timeMetric': timeMetric, 'timeLeft': timeLeft}) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy') if not canUpdatePremium: disableTTHeader = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_HEADER) disableTTBody = i18n.makeString(TOOLTIPS.LOBBY_HEADER_BUYPREMIUMACCOUNT_DISABLED_BODY, number=time_utils.ONE_YEAR / time_utils.ONE_DAY) self.as_doDisableHeaderButtonS(self.BUTTONS.PREM, canUpdatePremium) hasPersonalDiscount = len(g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0 if not canUpdatePremium: tooltip = {'header': disableTTHeader, 'body': disableTTBody} else: tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND if isPremiumAccount else TOOLTIPS.HEADER_PREMIUM_BUY self.as_setPremiumParamsS(isPremiumAccount, premiumBtnLbl, buyPremiumLabel, canUpdatePremium, disableTTHeader, disableTTBody, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
def _getPremiumLabelText(self, timeDelta): if settings.main[PREMIUM.PREMIUM_TIME]: delta = float(getTimeDeltaFromNow(makeLocalServerTime(timeDelta))) self.macros["days"], delta = divmod(delta, ONE_DAY) self.macros["hours"], delta = divmod(delta, ONE_HOUR) self.macros["minutes"], self.macros["seconds"] = divmod( delta, ONE_MINUTE) return settings.main[PREMIUM.PREMIUM_FORMAT] % self.macros
def getClosestDefencePeriod(self): if not self.isDefenceHourEnabled(): return (None, None) timestampStart = time_utils.getTimeTodayForUTC(self.defenceHour) if time_utils.getTimeDeltaFromNow(timestampStart) < time_utils.ONE_HOUR: timestampStart += time_utils.ONE_DAY timestampFinish = timestampStart + time_utils.ONE_HOUR return (timestampStart, timestampFinish)
def __canUpdatePremium(self): if self.__isPremiumAccount(): deltaInSeconds = float( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime( self._items.stats.premiumExpiryTime))) return deltaInSeconds < time_utils.ONE_YEAR return True
def getTillTimeString(timeStamp): timeLeft = time_utils.getTimeDeltaFromNow(timeStamp) modeStrBase = R.strings.menu.headerButtons.battle.types.mapbox.availability if timeLeft < time_utils.ONE_HOUR: res = backport.text(modeStrBase.lessThanHour()) else: res = backport.backport_time_utils.getTillTimeStringByRClass( timeLeft, modeStrBase) return res
def __getAttentionText(self): key = RANKED_BATTLES.RANKEDBATTLEVIEW_STATUSBLOCK_CALENDARPOPOVER_ATTENTIONTEXT cycleNumber = self.__seasonInfo.getCycleOrdinalNumber() timeDelta = time_utils.getTimeDeltaFromNow(self.__seasonInfo.getCycleEndDate()) endTimeStr = time_utils.getTillTimeString(timeDelta, RANKED_BATTLES.STATUS_TIMELEFT) if timeDelta <= time_utils.ONE_HOUR: formatter = text_styles.alert else: formatter = text_styles.neutral return formatter(i18n.makeString(key, cycleNumber=cycleNumber, timeLeft=endTimeStr))
def __packMainBlock(self): header = backport.text(R.strings.tooltips.battleTypes.battleRoyale.header()) body = backport.text(R.strings.tooltips.battleTypes.battleRoyale.body2()) currentCycleInfo = self._battleController.getCurrentCycleInfo() if currentCycleInfo[1]: timeLeft = time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(currentCycleInfo[0])) scheduleStr = ' '.join((backport.text(R.strings.tooltips.battleTypes.battleRoyale.tillEnd()), backport.getTillTimeStringByRClass(timeLeft, R.strings.menu.headerButtons.battle.types.ranked.availability))) body = '{}\n\n\n{}'.format(scheduleStr, backport.text(R.strings.tooltips.battleTypes.battleRoyale.body2())) background = backport.image(R.images.gui.maps.icons.battleRoyale.backgrounds.widget_tooltip_background()) return formatters.packImageTextBlockData(title=text_styles.middleTitle(header), txtPadding=formatters.packPadding(top=16, left=20), desc=text_styles.main(body), descPadding=formatters.packPadding(top=16, left=20), txtOffset=1, txtGap=-1, img=background)
def _packBlocks(self, *args): items = super(RankedSelectorTooltip, self)._packBlocks() items.append(self._packHeaderBlock()) items.append(self._packTimeTableBlock()) items.append( self._getTillEndBlock( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime( self._battleController.getCurrentSeason( ).getCycleEndDate())))) return items
def __makeVacationData(self): alertMessage = '' blockBtnEnabled = True daysBeforeVacation = -1 fort = self.fortCtrl.getFort() isVacationEnabled = fort.isVacationEnabled() inProcess, inCooldown = fort.getVacationProcessing() _, vacationEnd = fort.getVacationDate() blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNENABLED descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONDESCRIPTION conditionPostfix = self.app.utilsManager.textManager.getText(TEXT_MANAGER_STYLES.STANDARD_TEXT, i18n.makeString(FORTIFICATIONS.SETTINGSWINDOW_BLOCKCONDITION_VACATIONNOTPLANNED)) if inProcess or inCooldown: blockBtnEnabled = False cooldownEnd = vacationEnd + g_fortCache.vacationCooldownTime if fort.isOnVacation(): blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLEDNOTPLANNED daysBeforeVacation = time_utils.getTimeDeltaFromNow(cooldownEnd) / time_utils.ONE_DAY elif time_utils.getTimeDeltaFromNow(vacationEnd) != 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLED else: daysBeforeVacation = time_utils.getTimeDeltaFromNow(cooldownEnd) / time_utils.ONE_DAY if daysBeforeVacation == 0: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDSBLDLESSADAY daysBeforeVacation = -1 else: blockBtnToolTip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_VACATIONBTNDISABLEDNOTPLANNED if isVacationEnabled: textColor = TEXT_MANAGER_STYLES.NEUTRAL_TEXT if not fort.isOnVacation() else TEXT_MANAGER_STYLES.SUCCESS_TEXT textColor = textColor if not self._isFortFrozen() else TEXT_MANAGER_STYLES.STANDARD_TEXT conditionPostfix = self.app.utilsManager.textManager.getText(textColor, fort.getVacationDateTimeStr()) conditionPrefix = self.app.utilsManager.textManager.getText(TEXT_MANAGER_STYLES.MAIN_TEXT, i18n.makeString(FORTIFICATIONS.settingswindow_blockcondition('vacation'))) blockDescr = self.app.utilsManager.textManager.getText(TEXT_MANAGER_STYLES.STANDARD_TEXT, i18n.makeString(FORTIFICATIONS.settingswindow_blockdescr('vacation'))) if alertMessage: alertMessage = self.app.utilsManager.textManager.getIcon(TextIcons.ALERT_ICON) + ' ' + alertMessage return {'blockBtnEnabled': blockBtnEnabled, 'blockDescr': blockDescr, 'blockCondition': conditionPrefix + ' ' + conditionPostfix, 'alertMessage': alertMessage, 'blockBtnToolTip': blockBtnToolTip, 'daysBeforeVacation': daysBeforeVacation, 'descriptionTooltip': descriptionTooltip}
def _packBlocks(self, *args): items = [] if self._battleController.isFrozen() or not self._battleController.isEnabled(): items.append(self.__packFrozenBlock()) else: items.append(self.__packMainBlock()) currentSeason = self._battleController.getCurrentSeason() or self._battleController.getNextSeason() seasonIsStarted = self._battleController.getCurrentSeason() if self._battleController.getCurrentCycleInfo()[1]: items.append(self._packTimeTableBlock()) currentCycle = currentSeason.getCycleInfo() items.append(getTillBlock(seasonIsStarted, True, time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(currentCycle.endDate)))) elif currentSeason is not None: nextCycle = currentSeason.getNextByTimeCycle(time_utils.getCurrentLocalServerTimestamp()) if nextCycle: items.append(getTillBlock(seasonIsStarted, False, time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(nextCycle.startDate)))) else: wait = backport.text(R.strings.menu.headerButtons.battle.types.battleRoyale.extra.finished()) items.append(formatters.packTitleDescBlock(title=text_styles.main(wait))) items.append(packPerformanceWarningBlock(self._battleController.getPerformanceGroup())) return items
def __startPremiumTimeNotifyCallback(self): self.__clearPremiumTimeNotifyCallback() premiumTime = time_utils.makeLocalServerTime(g_itemsCache.items.stats.premiumExpiryTime) delta = time_utils.getTimeDeltaFromNow(premiumTime) if delta > time_utils.ONE_DAY: period = time_utils.ONE_DAY elif delta > time_utils.ONE_HOUR: period = time_utils.ONE_HOUR else: return nextNotification = delta % period or period self.__premiumTimeCallback = BigWorld.callback(nextNotification, self.__notifyPremiumTime)
def __formatActiveStateString(self, item): if not isValueAvailable(getter=item.getCreatedAt): return _ms(CLANS.CLANINVITESWINDOW_STATUS_MINUTESLEFT, min=formatField(getter=item.getCreatedAt)) createdAt = item.getCreatedAt() delta = time_utils.getTimeDeltaFromNow(createdAt + ACTIVE_INVITE_LIFE_TIME) if delta >= time_utils.ONE_DAY: state = _ms(CLANS.CLANINVITESWINDOW_STATUS_DAYSLEFT, days=int(math.ceil(float(delta) / time_utils.ONE_DAY))) elif delta >= time_utils.ONE_HOUR: state = _ms(CLANS.CLANINVITESWINDOW_STATUS_HOURSLEFT, hours=int(math.ceil(float(delta) / time_utils.ONE_HOUR))) else: mins = max(1, int(delta / time_utils.ONE_MINUTE)) state = _ms(CLANS.CLANINVITESWINDOW_STATUS_MINUTESLEFT, min=mins) return state
def _handleError(self, response): if response.isRequestLimitExceeded: with self.viewModel.transaction() as model: message = loc( rAccCompletion.emailOverlay.error.codeAlreadySent()) errorTime = max( RESTRICTED_REQUEST_MIN_TIME, getTimeDeltaFromNow(response.requestRestrictedUntilTime)) model.email.setErrorMessage(message) model.email.setErrorTime(errorTime) elif response.isAccountAlreadyHasEmail: showAccountAlreadyHasEmail(self.viewModel) else: super(SteamAddEmailOverlayView, self)._handleError(response)
def getAvailability(self): from ClientFortifiedRegion import ATTACK_PLAN_RESULT maxPreorderLimit = FORTIFICATION_ALIASES.ACTIVE_EVENTS_FUTURE_LIMIT * time_utils.ONE_DAY initialTime = time_utils.getTimeTodayForLocal(*self.getLocalDefHour()) availableTimestamp = initialTime while not self.__fort.canPlanAttackOn(availableTimestamp, self) == ATTACK_PLAN_RESULT.OK: if time_utils.getTimeDeltaFromNow(availableTimestamp) <= maxPreorderLimit: availableTimestamp += time_utils.ONE_DAY else: availableTimestamp = initialTime break currentDayStart, _ = time_utils.getDayTimeBoundsForLocal() availableDayStart, _ = time_utils.getDayTimeBoundsForLocal(availableTimestamp) return availableTimestamp
def _processQueue(self): if self.__isStarted is False: return else: if self.__bwCbId is None: while len(self.__queue): task = self.__queue[0] delta = time_utils.getTimeDeltaFromNow(task.getTime()) if delta > 0: self._registerBigWorldCb(delta) break else: self._removeTask(task.getId()) task.execute() return
def _packBlocks(self, *args): items = super(EpicMetaGameUnavailableTooltip, self)._packBlocks() items.append(self._packHeaderBlock()) timeTableBlocks = [self._packTimeTableHeaderBlock()] primeTime = self.epicController.getPrimeTimes().get( self.connectionMgr.peripheryID, None) if primeTime is None or self.epicController.hasAnySeason() is None: return items else: todayStart, todayEnd = time_utils.getDayTimeBoundsForLocal() todayEnd += 1 tomorrowStart, tomorrowEnd = todayStart + time_utils.ONE_DAY, todayEnd + time_utils.ONE_DAY todayPeriods = () tomorrowPeriods = () time, status = self.epicController.getSeasonEndTime() if status: todayPeriods = primeTime.getPeriodsBetween( todayStart, min(todayEnd, time)) if tomorrowStart < time: tomorrowPeriods = primeTime.getPeriodsBetween( tomorrowStart, min(tomorrowEnd, time)) todayStr = self._packPeriods(todayPeriods) timeTableBlocks.append( self._packTimeBlock(message=text_styles.main( EPIC_BATTLE. SELECTORTOOLTIP_EPICBATTLE_DISABLED_TIMETABLE_TODAY), timeStr=text_styles.bonusPreviewText( todayStr))) tomorrowStr = self._packPeriods(tomorrowPeriods) timeTableBlocks.append( self._packTimeBlock(message=text_styles.main( EPIC_BATTLE. SELECTORTOOLTIP_EPICBATTLE_DISABLED_TIMETABLE_TOMORROW ), timeStr=text_styles.stats( tomorrowStr))) items.append( formatters.packBuildUpBlockData( timeTableBlocks, 7, BLOCKS_TOOLTIP_TYPES. TOOLTIP_BUILDUP_BLOCK_WHITE_BG_LINKAGE)) items.append( self._getTillEndBlock( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(time)))) return items
def getDisplayableData(self, *args): qLabels, qProgress = [], [] premVehQuests = [] if game_control.g_instance.igr.getRoomType() in (constants.IGR_TYPE.PREMIUM, constants.IGR_TYPE.BASE): quests = g_eventsCache.getQuests() for q in quests.itervalues(): if game_control.g_instance.igr.getRoomType() == constants.IGR_TYPE.PREMIUM: template = g_htmlTemplates['html_templates:lobby/tooltips']['igr_quest'] if q.accountReqs.hasIGRCondition() and not q.hasPremIGRVehBonus(): metaList = q.getBonuses('meta') if len(metaList): qLabels.append(metaList[0].format()) winCond = None if q.postBattleCond.getConditions().getName() == 'and': winCond = q.postBattleCond.getConditions().find('win') isWin = winCond.getValue() if winCond is not None else False battlesCond = q.bonusCond.getConditions().find('battles') if battlesCond is not None: curBattles, totalBattles = (0, 0) progress = battlesCond.getProgressPerGroup() if None in progress: curBattles, totalBattles, _, _ = progress[None] qProgress.append([curBattles, totalBattles, i18n.makeString('#quests:igr/tooltip/winsLabel') if isWin else i18n.makeString('#quests:igr/tooltip/battlesLabel')]) if q.hasPremIGRVehBonus(): metaList = q.getBonuses('meta') leftTime = time_utils.getTimeDeltaFromNow(q.getFinishTime()) if len(metaList) and leftTime > 0: header = makeHtmlString('html_templates:lobby/tooltips', 'prem_igr_veh_quest_header', ctx={'qLabel': metaList[0].format()}) text = i18n.makeString('#tooltips:vehicleIgr/specialAbility') localization = '#tooltips:vehicleIgr/%s' actionLeft = getRentLeftTimeStr(localization, leftTime, timeStyle=TextType.STATS_TEXT) text += '\n' + actionLeft premVehQuests.append({'header': header, 'descr': text}) descriptionTemplate = 'igr_description' if len(qLabels) == 0 else 'igr_description_with_quests' igrPercent = (game_control.g_instance.igr.getXPFactor() - 1) * 100 igrType = game_control.g_instance.igr.getRoomType() icon = makeHtmlString('html_templates:igr/iconBig', 'premium' if igrType == constants.IGR_TYPE.PREMIUM else 'basic') return {'title': i18n.makeString(TOOLTIPS.IGR_TITLE, igrIcon=icon), 'description': makeHtmlString('html_templates:lobby/tooltips', descriptionTemplate, {'igrValue': '{0}%'.format(BigWorld.wg_getIntegralFormat(igrPercent))}), 'quests': map(lambda i: i.format(**template.ctx), qLabels), 'progressHeader': makeHtmlString('html_templates:lobby/tooltips', 'igr_progress_header', {}), 'progress': qProgress, 'premVehQuests': premVehQuests}
def getDeltaTimeHelper(config, data): if not config or not data: _logger.error('Incorrect config or data given') return 0 lastSmashTimestamp = data.get('lastSmashTimestamp', 0) cycleLength = config.get('cycleLength', 0) cycleStartTime = config.get('cycleStartTime', 0) if cycleLength <= 0: return 0 if lastSmashTimestamp <= cycleStartTime: openTime = cycleStartTime else: openTime = cycleStartTime + ( (lastSmashTimestamp - cycleStartTime) / cycleLength + 1) * cycleLength openTime += PiggyBankConstants.SMASH_MAX_DELAY return time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(openTime))
def _packBlocks(self, *args): items = super(RankedSelectorTooltip, self)._packBlocks() items.append(self._packHeaderBlock()) timeTableBlocks = [self._packTimeTableHeaderBlock()] primeTime = self.rankedController.getPrimeTimes().get( self.connectionMgr.peripheryID) currentCycleEnd = self.rankedController.getCurrentSeason( ).getCycleEndDate() todayStart, todayEnd = time_utils.getDayTimeBoundsForLocal() todayEnd += 1 tomorrowStart, tomorrowEnd = todayStart + time_utils.ONE_DAY, todayEnd + time_utils.ONE_DAY tomorrowEnd += 1 todayPeriods = () tomorrowPeriods = () if primeTime is not None: todayPeriods = primeTime.getPeriodsBetween( todayStart, min(todayEnd, currentCycleEnd)) if tomorrowStart < currentCycleEnd: tomorrowPeriods = primeTime.getPeriodsBetween( tomorrowStart, min(tomorrowEnd, currentCycleEnd)) todayStr = self._packPeriods(todayPeriods) timeTableBlocks.append( self._packTimeBlock( message=text_styles.main( backport.text(R.strings.ranked_battles.selectorTooltip. timeTable.today())), timeStr=text_styles.bonusPreviewText(todayStr))) tomorrowStr = self._packPeriods(tomorrowPeriods) timeTableBlocks.append( self._packTimeBlock(message=text_styles.main( backport.text(R.strings.ranked_battles.selectorTooltip. timeTable.tomorrow())), timeStr=text_styles.stats(tomorrowStr))) items.append( formatters.packBuildUpBlockData( timeTableBlocks, 7, BLOCKS_TOOLTIP_TYPES.TOOLTIP_BUILDUP_BLOCK_WHITE_BG_LINKAGE)) items.append( self._getTillEndBlock( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(currentCycleEnd)))) return items
def __makePeripheryData(self): fort = self.fortCtrl.getFort() optionsList = g_preDefinedHosts.getSimpleHostsList(g_preDefinedHosts.hostsWithRoaming()) servername = None for key, name, csisStatus, peripheryID in optionsList: if fort.peripheryID == peripheryID: servername = name if servername is None: servername = connectionManager.serverUserName _, inCooldown = fort.getPeripheryProcessing() timestamp, _, _ = fort.events.get(FORT_EVENT_TYPE.PERIPHERY_COOLDOWN, (0, 0, 0)) buttonEnabled = not inCooldown buttonToolTip = self.__makePeripheryBtnToolTip(buttonEnabled, time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(timestamp))) descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_PERIPHERYDESCRIPTION return {'peripheryTitle': self.app.utilsManager.textManager.getText(TextType.MAIN_TEXT, i18n.makeString(FORTIFICATIONS.SETTINGSWINDOW_PEREPHERYTITLE)), 'peripheryName': self.app.utilsManager.textManager.getText(TextType.NEUTRAL_TEXT, str(servername)), 'buttonEnabled': buttonEnabled, 'buttonToolTip': buttonToolTip, 'descriptionTooltip': descriptionTooltip}
def __setAccountsAttrs(self, isPremiumAccount, premiumExpiryTime=0): if isPremiumAccount: if not premiumExpiryTime > 0: raise AssertionError deltaInSeconds = float( time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(premiumExpiryTime))) if deltaInSeconds > time_utils.ONE_DAY: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_DAY) timeMetric = i18n.makeString( '#menu:header/account/premium/days') else: timeLeft = math.ceil(deltaInSeconds / time_utils.ONE_HOUR) timeMetric = i18n.makeString( '#menu:header/account/premium/hours') premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'premium-account-label', { 'timeMetric': timeMetric, 'timeLeft': timeLeft }) canUpdatePremium = deltaInSeconds < time_utils.ONE_YEAR buyPremiumLabel = '' if canUpdatePremium: buyPremiumLabel = i18n.makeString( '#menu:headerButtons/doLabel/premium') else: canUpdatePremium = True premiumBtnLbl = makeHtmlString('html_templates:lobby/header', 'base-account-label') buyPremiumLabel = i18n.makeString('#menu:common/premiumBuy') hasPersonalDiscount = len( g_itemsCache.items.shop.personalPremiumPacketsDiscounts) > 0 tooltip = canUpdatePremium or formatters.getLimitExceededPremiumTooltip( ) elif isPremiumAccount: tooltip = TOOLTIPS.HEADER_PREMIUM_EXTEND else: tooltip = TOOLTIPS.HEADER_PREMIUM_BUY self.as_setPremiumParamsS(premiumBtnLbl, buyPremiumLabel, hasPersonalDiscount, tooltip, TOOLTIP_TYPES.COMPLEX)
def __makePeripheryData(self): fort = self.fortCtrl.getFort() optionsList = g_preDefinedHosts.getSimpleHostsList( g_preDefinedHosts.hostsWithRoaming()) servername = None for key, name, csisStatus, peripheryID in optionsList: if fort.peripheryID == peripheryID: servername = name if servername is None: servername = connectionManager.serverUserName _, inCooldown = fort.getPeripheryProcessing() timestamp, _, _ = fort.events.get(FORT_EVENT_TYPE.PERIPHERY_COOLDOWN, (0, 0, 0)) buttonEnabled = not inCooldown buttonToolTip = self.__makePeripheryBtnToolTip( buttonEnabled, time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(timestamp))) descriptionTooltip = TOOLTIPS.FORTIFICATION_FORTSETTINGSWINDOW_PERIPHERYDESCRIPTION if self._isFortFrozen(): peripheryName = text_styles.standard(str(servername)) else: peripheryName = text_styles.neutral(str(servername)) return { 'peripheryTitle': text_styles.main( i18n.makeString(FORTIFICATIONS.SETTINGSWINDOW_PEREPHERYTITLE)), 'peripheryName': peripheryName, 'buttonEnabled': buttonEnabled, 'buttonToolTip': buttonToolTip, 'descriptionTooltip': descriptionTooltip }
def __updateWarning(self): timeLeft = time_utils.getTimeDeltaFromNow(self.__extra.startTime) self.__cancelWargningCallback() self.__showWarning(timeLeft)
def __updateTimer(self): timeLeft = time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.__extra.startTime)) self.__cancelTimerCallback() self.__showTimer(timeLeft)
def getProductionLeftTime(self): if self.productionTime is not None: return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.productionTime)) else: return 0
def __getClosestPremiumNotification(self): return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self._stats.premiumExpiryTime))
def getUsageLeftTime(self): return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.finishTime)) if self.finishTime is not None else 0
def __getClosestPremiumNotification(self): premiumTime = time_utils.makeLocalServerTime(g_itemsCache.items.stats.premiumExpiryTime) return time_utils.getTimeDeltaFromNow(premiumTime)
def __canUpdatePremium(self): if self.__isPremiumAccount(): deltaInSeconds = float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self._items.stats.premiumExpiryTime))) return deltaInSeconds < time_utils.ONE_YEAR return True
def getRoundStartTimeLeft(self): return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.getRoundStartTime()))
def __getClosestTankmanUpdateTime(self): if len(self.__tankmenList) > 0: timeOfClosestDeletion = self.__tankmenList[-1].dismissedAt + self.__tankmanLiveTime return time_utils.getTimeDeltaFromNow(timeOfClosestDeletion) + 1 else: return 0
def timeLeft(self): return float(time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.rentExpiryTime)))
def __getClosestPremiumNotification(cls): return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(_stats().premiumExpiryTime))
def getProductionLeftTime(self): if self.productionTime is not None: return time_utils.getTimeDeltaFromNow( time_utils.makeLocalServerTime(self.productionTime)) return 0
def getUsageLeftTime(self): if self.finishTime is not None: return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.finishTime)) else: return 0
def getEstimatedCooldown(self): if self.timeTransportCooldown > 0: return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(self.timeTransportCooldown)) else: return 0
def getProductionCooldown(self): productionTime = self.orderInProduction.get('timeFinish') if productionTime: return time_utils.getTimeDeltaFromNow(time_utils.makeLocalServerTime(productionTime)) else: return 0