def _onLoading(self, *args, **kwargs): super(OfferRewardWindow, self)._onLoading(*args, **kwargs) with self._viewModel.transaction() as model: if self._gift.fromCdn: title = self._cdnTitle description = self._cdnDescription icon = self._cdnIcon else: title = self._gift.title description = self._gift.description icon = '' bonusData = self._gift.bonus.displayedBonusData if self._gift.bonus else {} formattedBonuses = getRewardsBonuses(bonusData) formattedBonus = shared_utils.first(formattedBonuses) if formattedBonus is not None: icon = getGfImagePath( formattedBonus.get('imgSource')) or '' self._tooltipData = TooltipData( tooltip=formattedBonus.get('tooltip', None), isSpecial=formattedBonus.get('isSpecial', False), specialAlias=formattedBonus.get('specialAlias', ''), specialArgs=formattedBonus.get('specialArgs', None)) model.setCount(self._gift.giftCount) model.setHightlightType(self._gift.highlight) model.setName(title) model.setIcon(icon) model.setTooltipTitle(stripAllTags(title)) model.setTooltipDescription(stripAllTags(description)) bonusType = self._gift.bonusType if bonusType is not None: model.setBonusType(bonusType) return
def _onLoading(self, *args, **kwargs): super(OfferGiftsWindow, self)._onLoading(*args, **kwargs) offerItem = self._offerItem if offerItem is not None: result = yield self.syncOfferResources() if result != CachePrefetchResult.SUCCESS: yield awaitNextFrame() event_dispatcher.showStorage( defaultSection=STORAGE_CONSTANTS.OFFERS) self.destroyWindow() return self._offersNovelty.saveAsSeen(self._offerID) with self._viewModel.transaction() as model: model.setKey(random.randint(0, 1000)) model.setId(offerItem.id) localization = ResMgr.openSection( self._offersProvider.getCdnResourcePath( offerItem.cdnLocFilePath, relative=False)) title = localization.readString('name') if localization else '' model.setName(title) model.setBackground( getGfImagePath( self._offersProvider.getCdnResourcePath( offerItem.cdnGiftsBackgroundPath))) self._setDynamicInfo(model) self._generateGifts(model) return
def _onGiftClicked(self, args): giftID = args.get('index') gift = self._offerItem.getGift(giftID) if gift is None: _logger.error('Unknown gift id=%s for offer id=%s', giftID, self._offerID) return else: localization = ResMgr.openSection( self._offersProvider.getCdnResourcePath(gift.cdnLocFilePath, relative=False)) onGiftConfirm = partial( self._onGiftConfirm, self._offerID, giftID, cdnTitle=localization.readString('name') if localization else '', cdnDescription=localization.readString('description') if localization else '', cdnIcon=getGfImagePath( self._offersProvider.getCdnResourcePath(gift.cdnIconPath))) if gift.isVehicle: event_dispatcher.showOfferGiftVehiclePreview( offerID=self._offerID, giftID=giftID, confirmCallback=onGiftConfirm) self.destroyWindow() else: onGiftConfirm() return
def getImageData(self, tID, callback=None): purchase = yield self.__purchaseCache.requestPurchaseByID( self._productID) tokenData = purchase.getTokenData(tID) iconSmallPath = '' if tokenData.imgSmall: smallImglocalPath = yield WebImageHelper( _LOCAL_FOLDER_NAME).getLocalPath(tokenData.imgSmall) if smallImglocalPath: iconSmallPath = getGfImagePath( getWebCache().getRelativeFromAbsolute(smallImglocalPath)) iconBigPath = '' if tokenData.imgBig: bigImglocalPath = yield WebImageHelper( _LOCAL_FOLDER_NAME).getLocalPath(tokenData.imgBig) if bigImglocalPath: iconBigPath = getGfImagePath( getWebCache().getRelativeFromAbsolute(bigImglocalPath)) callback((iconSmallPath, iconBigPath))
def _onLoading(self, *args, **kwargs): super(OfferBannerWindowView, self)._onLoading(*args, **kwargs) offer = self._offersProvider.getOffer(self._offerID) if offer is None: return else: localization = ResMgr.openSection(self._offersProvider.getCdnResourcePath(offer.cdnLocFilePath, relative=False)) with self.viewModel.transaction() as model: model.setTitle(R.strings.offers.banner.title()) model.setDescription(localization.readString('bannerDescription', default='')) model.setName(localization.readString('nameInBanner', default='')) model.setIcon(getGfImagePath(self._offersProvider.getCdnResourcePath(offer.cdnBannerLogoPath, relative=True))) return
def _getGiftResources(self, gift): if gift.fromCdn: locFile = ResMgr.openSection(self._offersProvider.getCdnResourcePath(gift.cdnLocFilePath, relative=False)) title = locFile.readString('name') if locFile else '' description = locFile.readString('description') if locFile else '' icon = self._offersProvider.getCdnResourcePath(gift.cdnImagePath) count = 0 else: title = gift.title description = gift.description icon = gift.icon count = gift.giftCount if gift.bonusType not in BONUSES_WITHOUT_COUNTER else 0 return (title, description, getGfImagePath(icon), count)
def changeHangarSpace(self, spaceName, waitingMessage=None, backgroundImage=None): if not spaceName: _logger.error('Invalid space name: the name cannot be empty.') return False elif self.__loadingSpacePath is not None: _logger.error( 'Failed to load space "%s", because another space is loading: %s', spaceName, self.__loadingSpacePath) return False elif not self.hangarSpace.spaceInited or self.hangarSpace.spaceLoading( ): _logger.error( 'Failed to load space "%s", because another space is loading.', spaceName) return False else: hangarSpacePath = self.hangarSpace.spacePath if hangarSpacePath is None: _logger.error( 'Abnormal behaviour: hangarSpace.spacePath is not initialized' ) return False spacePath = spaceName if spaceName.startswith( 'space') else 'spaces/{}'.format(spaceName) if spacePath == hangarSpacePath: _logger.warning( 'No need to load space "%s", because it is already loaded', spaceName) return False self.__loadingSpacePath = spacePath self.__waitingMessage = waitingMessage if waitingMessage: Waiting.show(waitingMessage, isAlwaysOnTop=True, backgroundImage=getGfImagePath(backgroundImage)) visibilityMask = self.__visibilityMaskCache.get( self.__loadingSpacePath) return self.__changeHangarSpace(self.__loadingSpacePath, visibilityMask)
def _generateGifts(self, model): giftsContainer = model.gifts.getItems() giftsContainer.clear() sortedGifts = sorted(self._offerItem.availableGifts, key=lambda item: item.id) giftsContainer.reserve(len(sortedGifts)) for gift in sortedGifts: giftModel = GiftModel() title, description, icon, count = self._getGiftResources(gift) giftModel.setId(gift.id) giftModel.setRentType(RENT_TYPE_TO_MODEL_CONSTANT[gift.rentType]) giftModel.setRentValue(gift.rentValue) giftModel.setInventoryCount(gift.inventoryCount) giftModel.setIsDisabled(gift.isDisabled) giftModel.setCount(count) giftModel.setTitle(title) giftModel.setDescription(description) giftModel.setIcon(icon) giftModel.setNationFlag(getGfImagePath(gift.nationFlag)) giftModel.setHighlight(gift.highlight) giftModel.setButtonLabel(gift.buttonLabel) giftsContainer.addViewModel(giftModel) model.gifts.onItemClicked += self._onGiftClicked giftsContainer.invalidate()
def _generateGifts(self, model): giftsContainer = model.gifts.getItems() giftsContainer.clear() sortedGifts = sorted(self._offerItem.availableGifts, key=lambda item: item.id) giftsContainer.reserve(len(sortedGifts)) for gift in sortedGifts: giftModel = GiftModel() title, description, icon, count, price = self._getGiftResources( gift) giftModel.setId(gift.id) giftModel.setRentType(RENT_TYPE_TO_MODEL_CONSTANT[gift.rentType]) giftModel.setRentValue(gift.rentValue) giftModel.setInventoryCount(gift.isVehicle and gift.inventoryCount) giftModel.setCount(count) giftModel.setTitle(title) giftModel.setDescription(description) giftModel.setIcon(icon) giftModel.setHighlight(gift.highlight) giftModel.setButtonLabel(gift.buttonLabel) if gift.nationFlag: giftModel.setNationFlag(getGfImagePath(gift.nationFlag)) if self._offerItem.showPrice: giftModel.setPrice(price) notEnoughTokens = self._offerItem.availableTokens < price giftModel.setIsNotEnoughMoney(notEnoughTokens) giftCount = self._offerItem.getGiftAvailabelCount(gift.id) giftDisabled = notEnoughTokens or gift.isDisabled or not giftCount giftModel.setIsDisabled(giftDisabled) if giftCount > 0: giftModel.setAvailableCount(not gift.isVehicle and giftCount) giftsContainer.addViewModel(giftModel) model.gifts.onItemClicked += self._onGiftClicked model.setKey(random.randint(0, 1000)) giftsContainer.invalidate()
def icon(self): return getGfImagePath(self.bonus.getOfferIcon() ) if not self.fromCdn and self.bonus else ''