Beispiel #1
0
def makeVehicleVO(vehicle, levelsRange = None):
    if vehicle is None:
        return
    else:
        vState, vStateLvl = vehicle.getState()
        isReadyToFight = vehicle.isReadyToFight
        if vState == Vehicle.VEHICLE_STATE.UNDAMAGED or vState == Vehicle.VEHICLE_STATE.IN_PREBATTLE:
            vState = ''
            isReadyToFight = True
        elif vState == Vehicle.VEHICLE_STATE.IN_PREMIUM_IGR_ONLY:
            vState = makeHtmlString('html_templates:lobby', 'inPremiumIgrOnly')
        else:
            vState = i18n.makeString(MENU.tankcarousel_vehiclestates(vState))
        enabled, tooltip = True, None
        if levelsRange is not None and vehicle.level not in levelsRange:
            enabled, tooltip = False, TOOLTIPS.VEHICLESELECTOR_OVERFLOWLEVEL
        elif vehicle.isOnlyForEventBattles:
            enabled, tooltip = False, '#tooltips:redButton/disabled/vehicle/not_supported'
        return {'intCD': vehicle.intCD,
         'nationID': vehicle.nationID,
         'name': vehicle.name,
         'userName': vehicle.userName,
         'shortUserName': vehicle.shortUserName,
         'level': vehicle.level,
         'type': vehicle.type,
         'typeIndex': VEHICLE_TABLE_TYPES_ORDER_INDICES[vehicle.type],
         'smallIconPath': '../maps/icons/vehicle/small/{0}.png'.format(vehicle.name.replace(':', '-')),
         'isReadyToFight': isReadyToFight,
         'enabled': enabled,
         'tooltip': tooltip,
         'state': vState}
Beispiel #2
0
def getStatusStrings(vState,
                     vStateLvl=Vehicle.VEHICLE_STATE_LEVEL.INFO,
                     substitute='',
                     style=None,
                     ctx=None):
    """ Get status string for small and large slots.
    
    :param vState: one of VEHICLE_STATE
    :param vStateLvl: one of VEHICLE_STATE_LEVEL
    :param substitute: is provided, substitutes status string for small slot
                       (since it's too small to hold multiple strings)
    :param style: if provided, forces usage of this style
    :param ctx: keyword arguments for status text
    
    :return: tuple (status for small slot, status for large slot)
    """
    ctx = ctx or {}
    state = MENU.tankcarousel_vehiclestates(vState)
    status = ms(state, **ctx)
    if style is None:
        smallStyle, largeStyle = getStatusCountStyle(vStateLvl)
    else:
        smallStyle = largeStyle = style
    if status:
        return (smallStyle(status), largeStyle(status))
    elif substitute:
        return (text_styles.middleTitle(substitute), status)
    else:
        return (status, status)
 def _getVehicleDataVO(self, vehicle):
     vehicleData = super(FalloutCarouselDataProvider,
                         self)._getVehicleDataVO(vehicle)
     if not self._falloutCtrl.isSuitableVeh(vehicle):
         infoText = i18n.makeString(
             MENU.tankcarousel_vehiclestates(
                 Vehicle.VEHICLE_STATE.UNSUITABLE_TO_QUEUE))
         vehicleData.update(
             {'infoText': text_styles.vehicleStatusInfoText(infoText)})
     if vehicle.isFalloutSelected:
         selectButtonLabel = FALLOUT.TANKCAROUSELSLOT_DEACTIVATEBUTTON
         selected = True
         selectable = True
         visible = True
         enabled = True
     else:
         selectButtonLabel = FALLOUT.TANKCAROUSELSLOT_ACTIVATEBUTTON
         selected = False
         selectable = vehicle.isFalloutAvailable and not vehicle.isDisabledInPremIGR
         visible = bool(self._falloutCtrl.getEmptySlots(
         )) and self._falloutCtrl.getConfig().hasRequiredVehicles()
         enabled = self._falloutCtrl.canSelectVehicle(vehicle)
     vehicleData.update({
         'falloutCanBeSelected':
         selectable and visible,
         'falloutSelected':
         selected,
         'falloutButtonDisabled':
         not enabled,
         'selectButtonLabel':
         selectButtonLabel,
         'selectButtonTooltip':
         self._falloutCtrl.carouselSelectionButtonTooltip()
     })
     return vehicleData
Beispiel #4
0
 def getHangarMessage(self):
     if not self.isPresent():
         return (Vehicle.VEHICLE_STATE.NOT_PRESENT,
                 MENU.CURRENTVEHICLESTATUS_NOTPRESENT,
                 Vehicle.VEHICLE_STATE_LEVEL.CRITICAL)
     state, stateLvl = self.item.getState()
     if state == Vehicle.VEHICLE_STATE.IN_PREMIUM_IGR_ONLY:
         icon = icons.premiumIgrBig()
         if self.item.isRented:
             rentLeftStr = getTimeLeftStr('#menu:vehicle/igrRentLeft/%s',
                                          self.item.rentInfo.getTimeLeft())
             message = i18n.makeString('#menu:currentVehicleStatus/' +
                                       state,
                                       icon=icon,
                                       time=rentLeftStr)
         else:
             message = i18n.makeString(
                 '#menu:tankCarousel/vehicleStates/inPremiumIgrOnly',
                 icon=icon)
         return (state, message, stateLvl)
     if self.falloutCtrl and self.falloutCtrl.isSelected():
         if not self.item.isFalloutAvailable or self.item.getCustomState(
         ) == Vehicle.VEHICLE_STATE.UNSUITABLE_TO_QUEUE:
             message = i18n.makeString(
                 MENU.tankcarousel_vehiclestates(
                     Vehicle.VEHICLE_STATE.UNSUITABLE_TO_QUEUE))
             return (state, message, Vehicle.VEHICLE_STATE_LEVEL.WARNING)
     message = '#menu:currentVehicleStatus/' + state
     return (state, message, stateLvl)
Beispiel #5
0
def _getVehicleInfo(vehicle):
    vState, vStateLvl = vehicle.getState()
    if vState not in Vehicle.CAN_SELL_STATES:
        infoTextStyle = text_styles.vehicleStatusCriticalText if vStateLvl == Vehicle.VEHICLE_STATE_LEVEL.CRITICAL else text_styles.vehicleStatusInfoText
        stateText = infoTextStyle(_ms(MENU.tankcarousel_vehiclestates(vState)))
        stateIcon = getVehicleStateIcon(vState)
        return (stateIcon, stateText)
    else:
        return (None, None)
Beispiel #6
0
def makeVehicleVO(vehicle, levelsRange = None, vehicleTypes = None, isFallout = None, isCreator = False):
    if vehicle is None:
        return
    else:
        vState, vStateLvl = vehicle.getState()
        isReadyToFight = vehicle.isReadyToFight
        isNotValidFallout = isFallout is not None and isFallout != vehicle.isEvent
        if vState == Vehicle.VEHICLE_STATE.UNDAMAGED or vState == Vehicle.VEHICLE_STATE.IN_PREBATTLE:
            if isNotValidFallout:
                vState = i18n.makeString(MENU.tankcarousel_vehiclestates(Vehicle.VEHICLE_STATE.NOT_SUITABLE))
                isReadyToFight = False
            else:
                vState = ''
                isReadyToFight = True
        elif vState == Vehicle.VEHICLE_STATE.IN_PREMIUM_IGR_ONLY:
            vState = makeHtmlString('html_templates:lobby', 'inPremiumIgrOnly')
        else:
            vState = i18n.makeString(MENU.tankcarousel_vehiclestates(vState))
        enabled, tooltip = True, None
        if levelsRange is not None and vehicle.level not in levelsRange:
            enabled, tooltip = False, TOOLTIPS.VEHICLESELECTOR_OVERFLOWLEVEL
        elif vehicleTypes is not None and vehicle.type not in vehicleTypes:
            enabled, tooltip = False, TOOLTIPS.VEHICLESELECTOR_INCOMPATIBLETYPE
        elif isNotValidFallout:
            enabled = False
            if isCreator:
                tooltip = makeTooltip(TOOLTIPS.SQUADWINDOW_TEAMMATE_NOTVALIDVEHICLE_HEADER, TOOLTIPS.SQUADWINDOW_TEAMMATE_NOTVALIDVEHICLE_BODY)
            else:
                tooltip = makeTooltip(TOOLTIPS.SQUADWINDOW_DEMANDFORVEHICLE_NOTVALIDVEHICLE_HEADER, TOOLTIPS.SQUADWINDOW_DEMANDFORVEHICLE_NOTVALIDVEHICLE_BODY)
        return {'intCD': vehicle.intCD,
         'nationID': vehicle.nationID,
         'name': vehicle.name,
         'userName': vehicle.userName,
         'shortUserName': vehicle.shortUserName,
         'level': vehicle.level,
         'type': vehicle.type,
         'typeIndex': VEHICLE_TABLE_TYPES_ORDER_INDICES[vehicle.type],
         'smallIconPath': '../maps/icons/vehicle/small/{0}.png'.format(vehicle.name.replace(':', '-')),
         'isReadyToFight': isReadyToFight,
         'enabled': enabled,
         'tooltip': tooltip,
         'state': vState,
         'isFalloutVehicle': vehicle.isEvent}
def getStatusStrings(vState, vStateLvl=Vehicle.VEHICLE_STATE_LEVEL.INFO, substitute='', style=None, ctx=None):
    ctx = ctx or {}
    state = MENU.tankcarousel_vehiclestates(vState)
    status = ms(state, **ctx)
    if style is None:
        smallStyle, largeStyle = getStatusCountStyle(vStateLvl)
    else:
        smallStyle = largeStyle = style
    if status:
        return (smallStyle(status), largeStyle(status))
    else:
        return (text_styles.middleTitle(substitute), status) if substitute else (status, status)
Beispiel #8
0
    def requestTableData(self, nation, type, filter):
        Waiting.show('updateInventory')
        AccountSettings.setFilter('inventory_current', (nation, type))
        AccountSettings.setFilter('inventory_' + type, filter)
        nation = int(nation) if nation >= 0 else None
        if nation is not None:
            nation = getNationIndex(nation)
        filter = list(filter)
        requestType = [type]
        checkFits = None
        checkFitsArtefacts = None
        checkExtra = False
        modulesFits = {}
        vehicleFits = []
        extra = []
        modulesAllVehicle = []
        if type == self._MODULE:
            typeSize = int(filter.pop(0))
            requestType = filter[0:typeSize]
            filter = filter[typeSize:]
            fitsType = filter.pop(0)
            fitsVehicle = getItemByCompact(filter.pop(0))
            checkExtra = True
            extra = filter[:]
            checkFits = True if fitsType != 'otherVehicles' else False
            myVehicles = yield Requester(self._VEHICLE).getFromInventory()
            modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType)
            if fitsType == 'myVehicle':
                if fitsVehicle:
                    for rType in requestType:
                        modulesFits.update(_getComponentsByType(fitsVehicle, ITEM_TYPE_INDICES[rType]))

            else:
                for vehicle in myVehicles:
                    for rType in requestType:
                        modulesFits.update(_getComponentsByType(vehicle, ITEM_TYPE_INDICES[rType]))

            filter = requestType
        elif type == self._SHELL:
            filterSize = int(filter.pop(0))
            fitsType = filter.pop(filterSize)
            fitsVehicle = getItemByCompact(filter.pop(filterSize))
            checkFits = True if fitsType != 'otherGuns' else False
            if fitsType == 'myVehicleGun':
                for shoot in fitsVehicle.descriptor.gun['shots']:
                    modulesFits[shoot[self._SHELL]['compactDescr']] = True

            elif fitsType == 'myInventoryGuns':
                myGuns = yield Requester('vehicleGun').getFromInventory()
                for gun in myGuns:
                    for shoot in gun.descriptor['shots']:
                        modulesFits[shoot[self._SHELL]['compactDescr']] = True

            else:
                myGuns = yield Requester('vehicleGun').getFromInventory()
                for gun in myGuns:
                    for shoot in gun.descriptor['shots']:
                        modulesFits[shoot[self._SHELL]['compactDescr']] = True

                myVehicles = yield Requester(self._VEHICLE).getFromInventory()
                for vehicle in myVehicles:
                    for shoot in vehicle.descriptor.gun['shots']:
                        modulesFits[shoot[self._SHELL]['compactDescr']] = True

        elif type == self._VEHICLE:
            filterSize = int(filter.pop(0))
            extra = filter[filterSize:]
            checkExtra = True
            filter = filter[0:filterSize]
        else:
            fitsType = filter.pop(0)
            compact = filter.pop(0)
            fitsVehicle = getItemByCompact(compact)
            extra = filter
            checkExtra = type in (self._OPTIONAL_DEVICE, self._EQUIPMENT)
            checkFitsArtefacts = True if fitsType != 'otherVehicles' else False
            myVehicles = yield Requester(self._VEHICLE).getFromInventory()
            modulesAllVehicle = VehicleItemsRequester(myVehicles).getItems(requestType)
            if fitsType == 'myVehicle':
                vehicleFits = [fitsVehicle]
            else:
                vehicleFits = myVehicles
            filter = requestType
        filter = map(lambda w: w.lower(), filter)
        modulesAll = list()
        modulesShop = list()
        for rType in requestType:
            inv = yield Requester(rType).getFromInventory()
            shp = yield Requester(rType).getFromShop()
            modulesShop.extend(shp)
            modulesAll.extend(inv)

        vehPrices = {}
        if type == self._VEHICLE:
            compactDescrs = [ v.compactDescr for v in modulesAll ]
            vehPrices = yield StatsRequester().getVehiclesPrices(compactDescrs)
            vehPrices = dict(zip(compactDescrs, vehPrices))
        if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT):
            for vehModule in modulesAllVehicle:
                if vehModule not in modulesAll:
                    if modulesShop.count(vehModule) != 0:
                        modulesAll.append(vehModule)

        self.__clearTableData()
        self.__tableData = [type]
        excludeModules = []
        for module in modulesAll:
            if modulesShop.count(module) != 0:
                module.priceOrder = modulesShop[modulesShop.index(module)].priceOrder
            elif constants.IS_DEVELOPMENT:
                excludeModules.append(module)
                LOG_ERROR("Not found module %s '%s' (%r) in shop." % (module.type, module.unicName, module.compactDescr))

        modulesAll.sort()
        shopRqs = yield ShopRequester().request()
        for module in modulesAll:
            extraModuleInfo = None
            if module in excludeModules:
                continue
            if nation is not None:
                if module.nation != nation and module.nation != nations.NONE_INDEX:
                    continue
                if module.type.lower() not in filter:
                    continue
                if checkFits is not None:
                    if (module.compactDescr in modulesFits.keys()) != checkFits:
                        continue
                if module.isClipGun():
                    extraModuleInfo = CLIP_ICON_PATH
                if checkFitsArtefacts is not None:
                    compatible = False
                    for veh in vehicleFits:
                        if nation is not None and veh.nation != nation:
                            continue
                        compatible |= module.descriptor.checkCompatibilityWithVehicle(veh.descriptor)[0]

                    if compatible != checkFitsArtefacts:
                        continue
                inventoryCount = 0
                vehicleCount = 0
                if isinstance(module, VehicleItem):
                    vehicleCount = module.count
                else:
                    inventoryCount = module.count
                    if type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and module in modulesAllVehicle:
                        vehModule = modulesAllVehicle[modulesAllVehicle.index(module)]
                        vehicleCount = vehModule.count
                if checkExtra:
                    if type == self._VEHICLE and 'brocken' not in extra:
                        if module.repairCost > 0:
                            continue
                    if type == self._VEHICLE and 'locked' not in extra:
                        if module.lock != 0:
                            continue
                    if 'onVehicle' not in extra:
                        if vehicleCount > 0 and inventoryCount == 0:
                            continue
                disable = ''
                if type == self._VEHICLE and not module.canSell:
                    disable = makeString(MENU.tankcarousel_vehiclestates(module.getState()))
                elif type in (self._MODULE, self._OPTIONAL_DEVICE, self._EQUIPMENT) and isinstance(module, VehicleItem):
                    if type == self._OPTIONAL_DEVICE:
                        if not module.descriptor['removable']:
                            disable = makeString(MENU.INVENTORY_DEVICE_ERRORS_NOT_REMOVABLE)
                        else:
                            disable = makeString(MENU.INVENTORY_DEVICE_ERRORS_RESERVED)
                    else:
                        disable = makeString(MENU.INVENTORY_ERRORS_RESERVED)
                sellPrice = isinstance(module, InventoryVehicle) and vehPrices.get(module.compactDescr, (0, 0))
            else:
                sellPrice = (0, 0)
                item = g_itemsCache.items.getItemByCD(module.compactDescr)
                if item is not None:
                    sellPrice = item.sellPrice
            valueElement = {'id': compactItem(module),
             'name': module.name if type in (self._OPTIONAL_DEVICE, self._EQUIPMENT) else module.longName,
             'desc': getShortDescr(module.tableName),
             'inventoryId': module.inventoryId if isinstance(module, InventoryVehicle) else None,
             'inventoryCount': inventoryCount,
             'vehicleCount': vehicleCount,
             'credits': sellPrice[0],
             'gold': sellPrice[1],
             'price': sellPrice,
             'currency': 'credits' if sellPrice[1] == 0 else 'gold',
             'level': module.level,
             'nation': module.nation,
             'type': module.itemTypeName if type not in (self._VEHICLE,
                      self._OPTIONAL_DEVICE,
                      self._SHELL,
                      self._EQUIPMENT) else module.icon,
             'disabled': disable,
             'statusLevel': module.getStateLevel() if isinstance(module, InventoryVehicle) else InventoryVehicle.STATE_LEVEL.INFO,
             'removable': module.descriptor['removable'] if type == self._OPTIONAL_DEVICE else True,
             'tankType': module.type if type == self._VEHICLE else type,
             'isPremium': module.isPremium if type == self._VEHICLE else False,
             'isElite': self.app.tooltipManager.isVehicleElite(module) if type == self._VEHICLE else False,
             'itemTypeName': module.itemTypeName,
             'goldShellsForCredits': shopRqs.isEnabledBuyingGoldShellsForCredits,
             'goldEqsForCredits': shopRqs.isEnabledBuyingGoldEqsForCredits,
             EXTRA_MODULE_INFO: extraModuleInfo}
            self.__tableData.append(valueElement)

        requester = yield StatsRequesterr().request()
        self._table.as_setGoldS(requester.gold)
        self._table.as_setCreditsS(requester.credits)
        self._table.as_setTableS(self.__tableData)
        Waiting.hide('updateInventory')
        return