예제 #1
0
 def _getPriceBlock(self, vehicle, configuration, valueWidth):
     block = []
     buyPrice = configuration.buyPrice
     if buyPrice:
         itemPrice = vehicle.buyPrices.itemPrice
         price = itemPrice.price
         actionPrc = itemPrice.getActionPrc()
         defaultPrice = itemPrice.defPrice
         currency = price.getCurrency()
         buyPriceValue = price.get(currency)
         oldPriceValue = defaultPrice.get(currency)
         block.append(
             self._makePriceBlock(oldPriceValue,
                                  CURRENCY_SETTINGS.getBuySetting(currency),
                                  percent=0,
                                  valueWidth=valueWidth))
         block.append(
             self._makePriceBlock(buyPriceValue,
                                  CURRENCY_SETTINGS.getBuySetting(currency),
                                  percent=actionPrc,
                                  valueWidth=valueWidth))
     return [
         formatters.packBuildUpBlockData(
             block, gap=2, padding=formatters.packPadding(top=-2))
     ]
예제 #2
0
    def __getBoosterPrice(self, booster):
        block = []
        money = self.itemsCache.items.stats.money
        showDelimiter = False
        leftPadding = 92
        for itemPrice in booster.buyPrices:
            currency = itemPrice.getCurrency()
            value = itemPrice.price.getSignValue(currency)
            defValue = itemPrice.defPrice.getSignValue(currency)
            needValue = value - money.getSignValue(currency)
            actionPercent = itemPrice.getActionPrc()
            if currency == Currency.GOLD and actionPercent > 0:
                leftActionPadding = 101 + self.leftPadding
            else:
                leftActionPadding = 81 + self.leftPadding
            if showDelimiter:
                block.append(
                    formatters.packTextBlockData(
                        text=text_styles.standard(
                            TOOLTIPS.VEHICLE_TEXTDELIMITER_OR),
                        padding=formatters.packPadding(
                            left=leftActionPadding)))
            block.append(
                makePriceBlock(value,
                               CURRENCY_SETTINGS.getBuySetting(currency),
                               needValue if needValue > 0 else None,
                               defValue if defValue > 0 else None,
                               actionPercent,
                               leftPadding=leftPadding))
            showDelimiter = True

        return block
예제 #3
0
    def _getPriceBlock(self, vehicle, configuration, valueWidth):
        block = []
        if vehicle.isRentAvailable and vehicle.isRentable:
            buyPrice = vehicle.buyPrices
            rentPackages = vehicle.rentPackages
            if buyPrice and rentPackages:
                itemPrice = vehicle.buyPrices.itemPrice
                price = itemPrice.price
                currency = price.getCurrency()
                buyPriceValue = price.get(currency)
                if vehicle.isDisabledForBuy is not True:
                    block.append(self._makePriceBlock(buyPriceValue, CURRENCY_SETTINGS.getBuySetting(currency), percent=itemPrice.getActionPrc(), valueWidth=valueWidth))
                for rent in rentPackages:
                    defaultPrice = rent.get('defaultRentPrice')
                    defaultPriceValue = defaultPrice.get(defaultPrice.getCurrency())
                    days = rent.get('days')
                    rentPrice = rent.get('rentPrice')
                    currency = rentPrice.getCurrency()
                    rentPriceValue = rentPrice.get(currency)
                    block.append(self.__makeRentBlock(rentPriceValue, CURRENCY_SETTINGS.getBuySetting(currency), days, percent=self._calcDiscountValue(rentPriceValue, defaultPriceValue)))

        return [formatters.packBuildUpBlockData(block, gap=2, padding=formatters.packPadding(top=-2))]
예제 #4
0
파일: shell.py 프로젝트: kusaku/wot_scripts
    def construct(self):
        block = []
        shell = self.shell
        configuration = self.configuration
        buyPrice = configuration.buyPrice
        sellPrice = configuration.sellPrice
        if buyPrice and sellPrice:
            LOG_ERROR('You are not allowed to use buyPrice and sellPrice at the same time')
            return
        else:
            notEnoughMoney = False
            showDelimiter = False
            shop = self.itemsCache.items.shop
            money = self.itemsCache.items.stats.money
            if buyPrice and shell.buyPrices:
                for itemPrice in shell.buyPrices.iteritems(directOrder=False):
                    if not isItemBuyPriceAvailable(shell, itemPrice, shop) or not itemPrice.price:
                        continue
                    currency = itemPrice.getCurrency()
                    value = itemPrice.price.getSignValue(currency)
                    defValue = itemPrice.defPrice.getSignValue(currency)
                    actionPercent = itemPrice.getActionPrc()
                    needValue = value - money.getSignValue(currency)
                    if needValue > 0:
                        notEnoughMoney = True
                    else:
                        needValue = None
                    if showDelimiter:
                        block.append(formatters.packTextBlockData(text=text_styles.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=81 + self.leftPadding)))
                    block.append(makePriceBlock(value, CURRENCY_SETTINGS.getBuySetting(currency), needValue, defValue if defValue > 0 else None, actionPercent, valueWidth=self._valueWidth))
                    showDelimiter = True

            if sellPrice and shell.sellPrices:
                block.append(makePriceBlock(shell.sellPrices.itemPrice.price.credits, CURRENCY_SETTINGS.SELL_PRICE, oldPrice=shell.sellPrices.itemPrice.defPrice.credits, percent=shell.sellPrices.itemPrice.getActionPrc(), valueWidth=self._valueWidth))
            inventoryCount = shell.inventoryCount
            if inventoryCount:
                block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_INVENTORYCOUNT), value=text_styles.stats(inventoryCount), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5)))
            hasAction = shell.buyPrices.itemPrice.isActionPrice() or shell.sellPrices.itemPrice.isActionPrice()
            return (block, notEnoughMoney or hasAction)
    def __getInventoryBlock(self, booster, showPrice, showInventoryCount):
        block = []
        money = self.itemsCache.items.stats.money
        if showPrice:
            showDelimiter = False
            leftPadding = 92
            for itemPrice in booster.buyPrices:
                currency = itemPrice.getCurrency()
                value = itemPrice.price.getSignValue(currency)
                defValue = itemPrice.defPrice.getSignValue(currency)
                needValue = value - money.getSignValue(currency)
                actionPercent = itemPrice.getActionPrc()
                if currency == Currency.GOLD and actionPercent > 0:
                    leftActionPadding = 101 + self.leftPadding
                else:
                    leftActionPadding = 81 + self.leftPadding
                if showDelimiter:
                    block.append(formatters.packTextBlockData(text=_ts.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=leftActionPadding)))
                block.append(makePriceBlock(value, CURRENCY_SETTINGS.getBuySetting(currency), needValue if needValue > 0 else None, defValue if defValue > 0 else None, actionPercent, leftPadding=leftPadding))
                showDelimiter = True

        if showInventoryCount:
            block.append(formatters.packTitleDescParameterWithIconBlockData(title=_ts.main(TOOLTIPS.VEHICLE_INVENTORYCOUNT), value=_ts.stats(booster.count), icon=RES_ICONS.MAPS_ICONS_LIBRARY_STORAGE_ICON, padding=formatters.packPadding(left=104), titlePadding=formatters.packPadding(), iconPadding=formatters.packPadding(top=-2, left=-2)))
        return block
예제 #6
0
 def construct(self):
     xp = self.configuration.xp
     dailyXP = self.configuration.dailyXP
     buyPrice = self.configuration.buyPrice
     sellPrice = self.configuration.sellPrice
     unlockPrice = self.configuration.unlockPrice
     techTreeNode = self.configuration.node
     minRentPrice = self.configuration.minRentPrice
     rentals = self.configuration.rentals
     paddings = formatters.packPadding(left=-4)
     neededValue = 0
     actionPrc = 0
     if buyPrice and sellPrice:
         LOG_ERROR('You are not allowed to use buyPrice and sellPrice at the same time')
         return
     else:
         block = []
         isUnlocked = self.vehicle.isUnlocked
         isInInventory = self.vehicle.isInInventory
         isNextToUnlock = False
         parentCD = None
         if techTreeNode is not None:
             isNextToUnlock = bool(int(techTreeNode.state) & NODE_STATE.NEXT_2_UNLOCK)
             parentCD = techTreeNode.unlockProps.parentID
         if xp:
             xpValue = self.vehicle.xp
             if xpValue:
                 xPText = text_styles.expText(_int(xpValue))
                 icon = ICON_TEXT_FRAMES.FREE_XP if self.vehicle.isPremium else ICON_TEXT_FRAMES.XP
                 block.append(formatters.packTextParameterWithIconBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_XP), value=xPText, icon=icon, valueWidth=self._valueWidth, padding=paddings))
         if dailyXP:
             attrs = g_itemsCache.items.stats.attributes
             if attrs & constants.ACCOUNT_ATTR.DAILY_MULTIPLIED_XP and self.vehicle.dailyXPFactor > 0:
                 dailyXPText = text_styles.main(text_styles.expText('x' + _int(self.vehicle.dailyXPFactor)))
                 block.append(formatters.packTextParameterWithIconBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_DAILYXPFACTOR), value=dailyXPText, icon=ICON_TEXT_FRAMES.DOUBLE_XP_FACTOR, valueWidth=self._valueWidth, padding=paddings))
         if unlockPrice:
             isAvailable, cost, need = getUnlockPrice(self.vehicle.intCD, parentCD)
             if cost > 0:
                 neededValue = None
                 if isAvailable and not isUnlocked and need > 0 and techTreeNode is not None:
                     neededValue = need
                 block.append(makePriceBlock(cost, CURRENCY_SETTINGS.UNLOCK_PRICE, neededValue, valueWidth=self._valueWidth))
         if buyPrice and not (self.vehicle.isDisabledForBuy or self.vehicle.isPremiumIGR or self.vehicle.isTelecom):
             price = self.vehicle.buyPrice
             money = g_itemsCache.items.stats.money
             actionPrc = self.vehicle.actionPrc
             defaultPrice = self.vehicle.defaultPrice
             currency = price.getCurrency()
             buyPriceText = price.get(currency)
             oldPrice = defaultPrice.get(currency)
             neededValue = price.get(currency) - money.get(currency)
             neededValue = neededValue if neededValue > 0 else None
             if isInInventory or not isInInventory and not isUnlocked and not isNextToUnlock:
                 neededValue = None
             block.append(makePriceBlock(buyPriceText, CURRENCY_SETTINGS.getBuySetting(currency), neededValue, oldPrice, actionPrc, valueWidth=self._valueWidth))
         if sellPrice and not self.vehicle.isTelecom:
             sellPrice = self.vehicle.sellPrice
             if sellPrice.isSet(Currency.GOLD):
                 sellPriceText = text_styles.gold(_int(sellPrice.gold))
                 sellPriceIcon = ICON_TEXT_FRAMES.GOLD
             else:
                 sellPriceText = text_styles.credits(_int(sellPrice.credits))
                 sellPriceIcon = ICON_TEXT_FRAMES.CREDITS
             block.append(formatters.packTextParameterWithIconBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_SELL_PRICE), value=sellPriceText, icon=sellPriceIcon, valueWidth=self._valueWidth, padding=paddings))
         if minRentPrice and not self.vehicle.isPremiumIGR:
             minRentPricePackage = self.vehicle.getRentPackage()
             if minRentPricePackage:
                 minRentPriceValue = Money(*minRentPricePackage['rentPrice'])
                 minDefaultRentPriceValue = Money(*minRentPricePackage['defaultRentPrice'])
                 actionPrc = self.vehicle.getRentPackageActionPrc(minRentPricePackage['days'])
                 money = g_itemsCache.items.stats.money
                 currency = minRentPriceValue.getCurrency()
                 price = minRentPriceValue.get(currency)
                 oldPrice = minDefaultRentPriceValue.get(currency)
                 neededValue = minRentPriceValue.get(currency) - money.get(currency)
                 neededValue = neededValue if neededValue > 0 else None
                 block.append(makePriceBlock(price, CURRENCY_SETTINGS.getRentSetting(currency), neededValue, oldPrice, actionPrc, valueWidth=self._valueWidth))
         if rentals and not self.vehicle.isPremiumIGR:
             rentFormatter = RentLeftFormatter(self.vehicle.rentInfo)
             rentLeftInfo = rentFormatter.getRentLeftStr('#tooltips:vehicle/rentLeft/%s', formatter=lambda key, countType, count, _ = None: {'left': count,
              'descr': i18n.makeString(key % countType)})
             if rentLeftInfo:
                 block.append(formatters.packTextParameterWithIconBlockData(name=text_styles.main(rentLeftInfo['descr']), value=text_styles.main(rentLeftInfo['left']), icon=ICON_TEXT_FRAMES.RENTALS, valueWidth=self._valueWidth, padding=formatters.packPadding(left=-4, bottom=-16)))
         notEnoughMoney = neededValue > 0
         hasAction = actionPrc > 0
         return (block, notEnoughMoney or hasAction)
예제 #7
0
    def construct(self):
        block = []
        module = self.module
        slotIdx = self.configuration.slotIdx
        vehicle = self.configuration.vehicle
        sellPrice = self.configuration.sellPrice
        buyPrice = self.configuration.buyPrice
        unlockPrice = self.configuration.unlockPrice
        inventoryCount = self.configuration.inventoryCount
        vehiclesCount = self.configuration.vehiclesCount
        researchNode = self.configuration.node
        if buyPrice and sellPrice:
            LOG_ERROR('You are not allowed to use buyPrice and sellPrice at the same time')
            return
        else:

            def checkState(state):
                if researchNode is not None:
                    return bool(int(researchNode.state) & state)
                else:
                    return False

            isEqOrDev = module.itemTypeID in GUI_ITEM_TYPE.ARTEFACTS
            isNextToUnlock = checkState(NODE_STATE_FLAGS.NEXT_2_UNLOCK)
            isInstalled = checkState(NODE_STATE_FLAGS.INSTALLED)
            isInInventory = checkState(NODE_STATE_FLAGS.IN_INVENTORY)
            isUnlocked = checkState(NODE_STATE_FLAGS.UNLOCKED)
            isAutoUnlock = checkState(NODE_STATE_FLAGS.AUTO_UNLOCKED)
            items = self.itemsCache.items
            money = items.stats.money
            itemPrice = MONEY_UNDEFINED
            if module is not None:
                itemPrice = module.buyPrices.itemPrice.price
            isMoneyEnough = money >= itemPrice
            leftPadding = 92
            if unlockPrice and not isEqOrDev:
                parentCD = vehicle.intCD if vehicle is not None else None
                isAvailable, cost, need = getUnlockPrice(module.intCD, parentCD)
                neededValue = None
                if not isUnlocked and isNextToUnlock and need > 0:
                    neededValue = need
                if cost > 0:
                    block.append(makePriceBlock(cost, CURRENCY_SETTINGS.UNLOCK_PRICE, neededValue, leftPadding=leftPadding, valueWidth=self._valueWidth))
            notEnoughMoney = False
            hasAction = False
            if buyPrice and not isAutoUnlock:
                shop = self.itemsCache.items.shop
                money = self.itemsCache.items.stats.money
                rootInInv = vehicle is not None and vehicle.isInInventory
                if researchNode:
                    showNeeded = rootInInv and not isMoneyEnough and (isNextToUnlock or isUnlocked) and not (isInstalled or isInInventory)
                else:
                    isModuleUnlocked = module.isUnlocked
                    isModuleInInventory = module.isInInventory
                    showNeeded = not isModuleInInventory and isModuleUnlocked
                showDelimiter = False
                leftPadding = 92
                for itemPrice in module.buyPrices.iteritems(directOrder=False):
                    if not isItemBuyPriceAvailable(module, itemPrice, shop):
                        continue
                    currency = itemPrice.getCurrency()
                    value = itemPrice.price.getSignValue(currency)
                    defValue = itemPrice.defPrice.getSignValue(currency)
                    actionPercent = itemPrice.getActionPrc()
                    if isEqOrDev or showNeeded:
                        needValue = value - money.getSignValue(currency)
                        if needValue > 0:
                            notEnoughMoney = True
                        else:
                            needValue = None
                    else:
                        needValue = None
                    if currency == Currency.GOLD and actionPercent > 0:
                        leftActionPadding = 101 + self.leftPadding
                    else:
                        leftActionPadding = 81 + self.leftPadding
                    if actionPercent > 0:
                        hasAction = True
                    if showDelimiter:
                        block.append(formatters.packTextBlockData(text=text_styles.standard(TOOLTIPS.VEHICLE_TEXTDELIMITER_OR), padding=formatters.packPadding(left=leftActionPadding)))
                    block.append(makePriceBlock(value, CURRENCY_SETTINGS.getBuySetting(currency), needValue, defValue if defValue > 0 else None, actionPercent, valueWidth=self._valueWidth, leftPadding=leftPadding))
                    showDelimiter = True

            if sellPrice and module.sellPrices:
                block.append(makePriceBlock(module.sellPrices.itemPrice.price.credits, CURRENCY_SETTINGS.SELL_PRICE, oldPrice=module.sellPrices.itemPrice.defPrice.credits, percent=module.sellPrices.itemPrice.getActionPrc(), valueWidth=self._valueWidth, leftPadding=leftPadding))
            if inventoryCount:
                count = module.inventoryCount
                if count > 0:
                    block.append(self._getInventoryBlock(count))
            if vehiclesCount:
                inventoryVehicles = items.getVehicles(REQ_CRITERIA.INVENTORY)
                count = len(module.getInstalledVehicles(inventoryVehicles.itervalues()))
                if count > 0:
                    block.append(formatters.packTextParameterBlockData(name=text_styles.main(TOOLTIPS.VEHICLE_VEHICLECOUNT), value=text_styles.stats(count), valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5)))
            isOptionalDevice = module.itemTypeID == GUI_ITEM_TYPE.OPTIONALDEVICE
            if isOptionalDevice and not module.isRemovable and not self.configuration.isAwardWindow:
                removalPrice = module.getRemovalPrice(self.itemsCache.items)
                removalPriceCurrency = removalPrice.getCurrency()
                currencyTextFormatter = getattr(text_styles, removalPriceCurrency, text_styles.gold)
                block.append(formatters.packTextParameterWithIconBlockData(name=text_styles.main(TOOLTIPS.MODULEFITS_NOT_REMOVABLE_DISMANTLING_PRICE), value=currencyTextFormatter(removalPrice.price.get(removalPriceCurrency)), icon=removalPriceCurrency, valueWidth=self._valueWidth, padding=formatters.packPadding(left=-5)))
            hasAction |= module.sellPrices.itemPrice.isActionPrice()
            return (block, notEnoughMoney or hasAction)
예제 #8
0
 def construct(self):
     xp = self.configuration.xp
     dailyXP = self.configuration.dailyXP
     buyPrice = self.configuration.buyPrice
     sellPrice = self.configuration.sellPrice
     unlockPrice = self.configuration.unlockPrice
     techTreeNode = self.configuration.node
     minRentPrice = self.configuration.minRentPrice
     rentals = self.configuration.rentals
     futureRentals = self.configuration.futureRentals
     paddings = formatters.packPadding(left=-4)
     neededValue = 0
     actionPrc = 0
     if buyPrice and sellPrice:
         LOG_ERROR(
             'You are not allowed to use buyPrice and sellPrice at the same time'
         )
         return
     else:
         block = []
         isUnlocked = self.vehicle.isUnlocked
         isInInventory = self.vehicle.isInInventory
         isNextToUnlock = False
         parentCD = None
         if techTreeNode is not None:
             isNextToUnlock = bool(
                 int(techTreeNode.state) & NODE_STATE_FLAGS.NEXT_2_UNLOCK)
             parentCD = techTreeNode.unlockProps.parentID
         if xp:
             xpValue = self.vehicle.xp
             if xpValue:
                 xPText = text_styles.expText(_int(xpValue))
                 icon = ICON_TEXT_FRAMES.FREE_XP if self.vehicle.isPremium else ICON_TEXT_FRAMES.XP
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(TOOLTIPS.VEHICLE_XP),
                         value=xPText,
                         icon=icon,
                         valueWidth=self._valueWidth,
                         padding=paddings))
         if dailyXP:
             attrs = g_itemsCache.items.stats.attributes
             if attrs & constants.ACCOUNT_ATTR.DAILY_MULTIPLIED_XP and self.vehicle.dailyXPFactor > 0:
                 dailyXPText = text_styles.main(
                     text_styles.expText('x' +
                                         _int(self.vehicle.dailyXPFactor)))
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(
                             TOOLTIPS.VEHICLE_DAILYXPFACTOR),
                         value=dailyXPText,
                         icon=ICON_TEXT_FRAMES.DOUBLE_XP_FACTOR,
                         valueWidth=self._valueWidth,
                         padding=paddings))
         if unlockPrice:
             isAvailable, cost, need = getUnlockPrice(
                 self.vehicle.intCD, parentCD)
             if cost > 0:
                 neededValue = None
                 if isAvailable and not isUnlocked and need > 0 and techTreeNode is not None:
                     neededValue = need
                 block.append(
                     makePriceBlock(cost,
                                    CURRENCY_SETTINGS.UNLOCK_PRICE,
                                    neededValue,
                                    valueWidth=self._valueWidth))
         if buyPrice:
             if self.vehicle.isRestorePossible():
                 price = self.vehicle.restorePrice
                 defaultPrice = price
                 currency = price.getCurrency()
                 buyPriceText = price.get(currency)
                 oldPrice = defaultPrice.get(currency)
                 neededValue = _getNeedValue(price, currency)
                 if isInInventory or not isInInventory and not isUnlocked and not isNextToUnlock:
                     neededValue = None
                 block.append(
                     makePriceBlock(buyPriceText,
                                    CURRENCY_SETTINGS.RESTORE_PRICE,
                                    neededValue,
                                    oldPrice,
                                    actionPrc,
                                    valueWidth=self._valueWidth))
                 if self.vehicle.hasLimitedRestore():
                     timeKey, formattedTime = getTimeLeftInfo(
                         self.vehicle.restoreInfo.getRestoreTimeLeft(),
                         None)
                     block.append(
                         formatters.packTextParameterWithIconBlockData(
                             name=text_styles.main(
                                 '#tooltips:vehicle/restoreLeft/%s' %
                                 timeKey),
                             value=text_styles.main(formattedTime),
                             icon=ICON_TEXT_FRAMES.ALERT if timeKey
                             == 'hours' else ICON_TEXT_FRAMES.EMPTY,
                             valueWidth=self._valueWidth,
                             padding=formatters.packPadding(left=-4)))
             elif not (self.vehicle.isDisabledForBuy or
                       self.vehicle.isPremiumIGR or self.vehicle.isTelecom):
                 price = self.vehicle.buyPrice
                 actionPrc = self.vehicle.actionPrc
                 defaultPrice = self.vehicle.defaultPrice
                 currency = price.getCurrency()
                 buyPriceText = price.get(currency)
                 oldPrice = defaultPrice.get(currency)
                 neededValue = _getNeedValue(price, currency)
                 if isInInventory or not isInInventory and not isUnlocked and not isNextToUnlock:
                     neededValue = None
                 block.append(
                     makePriceBlock(
                         buyPriceText,
                         CURRENCY_SETTINGS.getBuySetting(currency),
                         neededValue,
                         oldPrice,
                         0,
                         valueWidth=self._valueWidth))
         if sellPrice and not self.vehicle.isTelecom:
             sellPrice = self.vehicle.sellPrice
             if sellPrice.isSet(Currency.GOLD):
                 sellPriceText = text_styles.gold(_int(sellPrice.gold))
                 sellPriceIcon = ICON_TEXT_FRAMES.GOLD
             else:
                 sellPriceText = text_styles.credits(_int(
                     sellPrice.credits))
                 sellPriceIcon = ICON_TEXT_FRAMES.CREDITS
             block.append(
                 formatters.packTextParameterWithIconBlockData(
                     name=text_styles.main(TOOLTIPS.VEHICLE_SELL_PRICE),
                     value=sellPriceText,
                     icon=sellPriceIcon,
                     valueWidth=self._valueWidth,
                     padding=paddings))
         if minRentPrice and not self.vehicle.isPremiumIGR:
             minRentPricePackage = self.vehicle.getRentPackage()
             if minRentPricePackage:
                 minRentPriceValue = Money(
                     *minRentPricePackage['rentPrice'])
                 minDefaultRentPriceValue = Money(
                     *minRentPricePackage['defaultRentPrice'])
                 actionPrc = self.vehicle.getRentPackageActionPrc(
                     minRentPricePackage['days'])
                 currency = minRentPriceValue.getCurrency()
                 price = minRentPriceValue.get(currency)
                 oldPrice = minDefaultRentPriceValue.get(currency)
                 neededValue = _getNeedValue(minRentPriceValue, currency)
                 block.append(
                     makePriceBlock(
                         price,
                         CURRENCY_SETTINGS.getRentSetting(currency),
                         neededValue,
                         oldPrice,
                         actionPrc,
                         valueWidth=self._valueWidth))
                 if not self.vehicle.isRented or self.vehicle.rentalIsOver:
                     block.append(
                         formatters.packTextParameterWithIconBlockData(
                             name=text_styles.main(
                                 '#tooltips:vehicle/rentAvailable'),
                             value='',
                             icon=ICON_TEXT_FRAMES.RENTALS,
                             valueWidth=self._valueWidth,
                             padding=paddings))
         if rentals and not self.vehicle.isPremiumIGR:
             if futureRentals:
                 rentLeftKey = '#tooltips:vehicle/rentLeftFuture/%s'
                 rentInfo = RentalInfoProvider(time=self._rentExpiryTime,
                                               isRented=True)
             else:
                 rentLeftKey = '#tooltips:vehicle/rentLeft/%s'
                 rentInfo = self.vehicle.rentInfo
             rentFormatter = RentLeftFormatter(rentInfo)
             rentLeftInfo = rentFormatter.getRentLeftStr(
                 rentLeftKey,
                 formatter=lambda key, countType, count, _=None: {
                     'left': count,
                     'descr': i18n.makeString(key % countType)
                 })
             if rentLeftInfo:
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(rentLeftInfo['descr']),
                         value=text_styles.main(rentLeftInfo['left']),
                         icon=ICON_TEXT_FRAMES.RENTALS,
                         valueWidth=self._valueWidth,
                         padding=formatters.packPadding(left=-4,
                                                        bottom=-16)))
         notEnoughMoney = neededValue > 0
         hasAction = actionPrc > 0
         return (block, notEnoughMoney or hasAction)
예제 #9
0
 def construct(self):
     xp = self.configuration.xp
     dailyXP = self.configuration.dailyXP
     buyPrice = self.configuration.buyPrice
     sellPrice = self.configuration.sellPrice
     unlockPrice = self.configuration.unlockPrice
     techTreeNode = self.configuration.node
     minRentPrice = self.configuration.minRentPrice
     rentals = self.configuration.rentals
     futureRentals = self.configuration.futureRentals
     paddings = formatters.packPadding(left=-4)
     neededValue = 0
     actionPrc = 0
     if buyPrice and sellPrice:
         LOG_ERROR("You are not allowed to use buyPrice and sellPrice at the same time")
         return
     else:
         block = []
         isUnlocked = self.vehicle.isUnlocked
         isInInventory = self.vehicle.isInInventory
         isNextToUnlock = False
         parentCD = None
         if techTreeNode is not None:
             isNextToUnlock = bool(int(techTreeNode.state) & NODE_STATE_FLAGS.NEXT_2_UNLOCK)
             parentCD = techTreeNode.unlockProps.parentID
         if xp:
             xpValue = self.vehicle.xp
             if xpValue:
                 xPText = text_styles.expText(_int(xpValue))
                 icon = ICON_TEXT_FRAMES.FREE_XP if self.vehicle.isPremium else ICON_TEXT_FRAMES.XP
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(TOOLTIPS.VEHICLE_XP),
                         value=xPText,
                         icon=icon,
                         valueWidth=self._valueWidth,
                         padding=paddings,
                     )
                 )
         if dailyXP:
             attrs = g_itemsCache.items.stats.attributes
             if attrs & constants.ACCOUNT_ATTR.DAILY_MULTIPLIED_XP and self.vehicle.dailyXPFactor > 0:
                 dailyXPText = text_styles.main(text_styles.expText("x" + _int(self.vehicle.dailyXPFactor)))
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(TOOLTIPS.VEHICLE_DAILYXPFACTOR),
                         value=dailyXPText,
                         icon=ICON_TEXT_FRAMES.DOUBLE_XP_FACTOR,
                         valueWidth=self._valueWidth,
                         padding=paddings,
                     )
                 )
         if unlockPrice:
             isAvailable, cost, need = getUnlockPrice(self.vehicle.intCD, parentCD)
             if cost > 0:
                 neededValue = None
                 if isAvailable and not isUnlocked and need > 0 and techTreeNode is not None:
                     neededValue = need
                 block.append(
                     makePriceBlock(cost, CURRENCY_SETTINGS.UNLOCK_PRICE, neededValue, valueWidth=self._valueWidth)
                 )
         if buyPrice:
             if self.vehicle.isRestorePossible():
                 price = self.vehicle.restorePrice
                 defaultPrice = price
                 currency = price.getCurrency()
                 buyPriceText = price.get(currency)
                 oldPrice = defaultPrice.get(currency)
                 neededValue = _getNeedValue(price, currency)
                 if isInInventory or not isInInventory and not isUnlocked and not isNextToUnlock:
                     neededValue = None
                 block.append(
                     makePriceBlock(
                         buyPriceText,
                         CURRENCY_SETTINGS.RESTORE_PRICE,
                         neededValue,
                         oldPrice,
                         actionPrc,
                         valueWidth=self._valueWidth,
                     )
                 )
                 if self.vehicle.hasLimitedRestore():
                     timeKey, formattedTime = getTimeLeftInfo(self.vehicle.restoreInfo.getRestoreTimeLeft(), None)
                     block.append(
                         formatters.packTextParameterWithIconBlockData(
                             name=text_styles.main("#tooltips:vehicle/restoreLeft/%s" % timeKey),
                             value=text_styles.main(formattedTime),
                             icon=ICON_TEXT_FRAMES.ALERT if timeKey == "hours" else ICON_TEXT_FRAMES.EMPTY,
                             valueWidth=self._valueWidth,
                             padding=formatters.packPadding(left=-4),
                         )
                     )
             elif not (self.vehicle.isDisabledForBuy or self.vehicle.isPremiumIGR or self.vehicle.isTelecom):
                 price = self.vehicle.buyPrice
                 actionPrc = self.vehicle.actionPrc
                 defaultPrice = self.vehicle.defaultPrice
                 currency = price.getCurrency()
                 buyPriceText = price.get(currency)
                 oldPrice = defaultPrice.get(currency)
                 neededValue = _getNeedValue(price, currency)
                 if isInInventory or not isInInventory and not isUnlocked and not isNextToUnlock:
                     neededValue = None
                 block.append(
                     makePriceBlock(
                         buyPriceText,
                         CURRENCY_SETTINGS.getBuySetting(currency),
                         neededValue,
                         oldPrice,
                         0,
                         valueWidth=self._valueWidth,
                     )
                 )
         if sellPrice and not self.vehicle.isTelecom:
             sellPrice = self.vehicle.sellPrice
             if sellPrice.isSet(Currency.GOLD):
                 sellPriceText = text_styles.gold(_int(sellPrice.gold))
                 sellPriceIcon = ICON_TEXT_FRAMES.GOLD
             else:
                 sellPriceText = text_styles.credits(_int(sellPrice.credits))
                 sellPriceIcon = ICON_TEXT_FRAMES.CREDITS
             block.append(
                 formatters.packTextParameterWithIconBlockData(
                     name=text_styles.main(TOOLTIPS.VEHICLE_SELL_PRICE),
                     value=sellPriceText,
                     icon=sellPriceIcon,
                     valueWidth=self._valueWidth,
                     padding=paddings,
                 )
             )
         if minRentPrice and not self.vehicle.isPremiumIGR:
             minRentPricePackage = self.vehicle.getRentPackage()
             if minRentPricePackage:
                 minRentPriceValue = Money(*minRentPricePackage["rentPrice"])
                 minDefaultRentPriceValue = Money(*minRentPricePackage["defaultRentPrice"])
                 actionPrc = self.vehicle.getRentPackageActionPrc(minRentPricePackage["days"])
                 currency = minRentPriceValue.getCurrency()
                 price = minRentPriceValue.get(currency)
                 oldPrice = minDefaultRentPriceValue.get(currency)
                 neededValue = _getNeedValue(minRentPriceValue, currency)
                 block.append(
                     makePriceBlock(
                         price,
                         CURRENCY_SETTINGS.getRentSetting(currency),
                         neededValue,
                         oldPrice,
                         actionPrc,
                         valueWidth=self._valueWidth,
                     )
                 )
                 if not self.vehicle.isRented or self.vehicle.rentalIsOver:
                     block.append(
                         formatters.packTextParameterWithIconBlockData(
                             name=text_styles.main("#tooltips:vehicle/rentAvailable"),
                             value="",
                             icon=ICON_TEXT_FRAMES.RENTALS,
                             valueWidth=self._valueWidth,
                             padding=paddings,
                         )
                     )
         if rentals and not self.vehicle.isPremiumIGR:
             if futureRentals:
                 rentLeftKey = "#tooltips:vehicle/rentLeftFuture/%s"
                 rentInfo = RentalInfoProvider(time=self._rentExpiryTime, isRented=True)
             else:
                 rentLeftKey = "#tooltips:vehicle/rentLeft/%s"
                 rentInfo = self.vehicle.rentInfo
             rentFormatter = RentLeftFormatter(rentInfo)
             rentLeftInfo = rentFormatter.getRentLeftStr(
                 rentLeftKey,
                 formatter=lambda key, countType, count, _=None: {
                     "left": count,
                     "descr": i18n.makeString(key % countType),
                 },
             )
             if rentLeftInfo:
                 block.append(
                     formatters.packTextParameterWithIconBlockData(
                         name=text_styles.main(rentLeftInfo["descr"]),
                         value=text_styles.main(rentLeftInfo["left"]),
                         icon=ICON_TEXT_FRAMES.RENTALS,
                         valueWidth=self._valueWidth,
                         padding=formatters.packPadding(left=-4, bottom=-16),
                     )
                 )
         notEnoughMoney = neededValue > 0
         hasAction = actionPrc > 0
         return (block, notEnoughMoney or hasAction)