Example #1
0
 def __startBuild(self, vDesc, vState):
     self.__curBuildInd += 1
     self.__vDesc = vDesc
     self.__resources = {}
     self.__stickers = []
     self.__componentIDs = {
         'chassis': vDesc.chassis['models'][vState],
         'hull': vDesc.hull['models'][vState],
         'turret': vDesc.turret['models'][vState],
         'gun': vDesc.gun['models'][vState],
         'camouflageExclusionMask': vDesc.type.camouflageExclusionMask
     }
     customization = items.vehicles.g_cache.customization(
         vDesc.type.customizationNationID)
     if customization is not None and vDesc.camouflages is not None:
         camouflageID = vDesc.camouflages[g_tankActiveCamouflage.get(
             vDesc.type.compactDescr, 0)][0]
         camouflageDesc = customization['camouflages'].get(camouflageID)
         if camouflageDesc is not None:
             self.__componentIDs['camouflageTexture'] = camouflageDesc[
                 'texture']
     if vState == 'undamaged':
         self.__emblemsAlpha = _CFG['emblems_alpha_undamaged']
         self.__isVehicleDestroyed = False
     else:
         self.__emblemsAlpha = _CFG['emblems_alpha_damaged']
         self.__isVehicleDestroyed = True
     resources = self.__componentIDs.values()
     BigWorld.loadResourceListBG(
         tuple(resources),
         partial(self.__onResourcesLoaded, self.__curBuildInd))
     return
 def __startBuild(self, vDesc, vState):
     self.setModelsQuality(0)
     self.__curBuildInd += 1
     self.__vDesc = vDesc
     self.__vState = vState
     self.__resources = {}
     self.__vehicleStickers = None
     self.__componentIDs = {'chassis': vDesc.chassis['models'][vState],
      'hull': vDesc.hull['models'][vState],
      'turret': vDesc.turret['models'][vState],
      'gun': vDesc.gun['models'][vState],
      'camouflageExclusionMask': vDesc.type.camouflageExclusionMask}
     self.setModelsQuality(1)
     customization = items.vehicles.g_cache.customization(vDesc.type.customizationNationID)
     if customization is not None and vDesc.camouflages is not None:
         activeCamo = g_tankActiveCamouflage['historical'].get(vDesc.type.compactDescr)
         if activeCamo is None:
             activeCamo = g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)
         camouflageID = vDesc.camouflages[activeCamo][0]
         camouflageDesc = customization['camouflages'].get(camouflageID)
         if camouflageDesc is not None:
             self.__componentIDs['camouflageTexture'] = camouflageDesc['texture']
     if vState == 'undamaged':
         self.__emblemsAlpha = _CFG['emblems_alpha_undamaged']
         self.__isVehicleDestroyed = False
     else:
         self.__emblemsAlpha = _CFG['emblems_alpha_damaged']
         self.__isVehicleDestroyed = True
     resources = self.__componentIDs.values()
     splineDesc = vDesc.chassis['splineDesc']
     if splineDesc is not None:
         resources.extend(splineDesc.values())
     BigWorld.loadResourceListBG(tuple(resources), partial(self.__onResourcesLoaded, self.__curBuildInd))
Example #3
0
 def init(self):
     if not g_currentVehicle.isPresent():
         raise SoftException(
             'There is not vehicle in hangar for customization.')
     self._autoRentEnabled = g_currentVehicle.item.isAutoRentStyle
     self._vehicleAnchorsUpdater = VehicleAnchorsUpdater(self.service, self)
     self._vehicleAnchorsUpdater.startUpdater(
         self.settingsCore.interfaceScale.get())
     if self.hangarSpace.spaceInited:
         self._c11CameraManager = C11nHangarCameraManager(
             self.hangarSpace.space.getCameraManager())
         self._c11CameraManager.init()
     self.settingsCore.interfaceScale.onScaleExactlyChanged += self.__onInterfaceScaleChanged
     self.service.onOutfitChanged += self.__onOutfitChanged
     self.itemsCache.onSyncCompleted += self.__onCacheResync
     self.carveUpOutfits()
     currVehSeasonType = g_tankActiveCamouflage.get(
         g_currentVehicle.item.intCD, SeasonType.SUMMER)
     self._currentSeason = currVehSeasonType
     if self._originalStyle:
         self._mode = C11nMode.STYLE
         self._tabIndex = C11nTabs.STYLE
     else:
         self._mode = C11nMode.CUSTOM
         self._tabIndex = C11nTabs.PAINT
         notInst = all([
             not self._originalOutfits[season].isInstalled()
             for season in SeasonType.COMMON_SEASONS
         ])
         if notInst and not self.isOutfitsEmpty(
                 self._modifiedOutfits) and not self._modifiedStyle:
             self._mode = C11nMode.STYLE
     self._originalMode = self._mode
     self.refreshOutfit()
 def _getActiveOutfit(self, vDesc):
     if g_currentPreviewVehicle.isPresent(
     ) and not g_currentPreviewVehicle.isHeroTank:
         vehicleCD = g_currentPreviewVehicle.item.descriptor.makeCompactDescr(
         )
         return self.customizationService.getEmptyOutfitWithNationalEmblems(
             vehicleCD=vehicleCD)
     elif not g_currentVehicle.isPresent():
         if vDesc is not None:
             vehicleCD = vDesc.makeCompactDescr()
             outfit = self.customizationService.getEmptyOutfitWithNationalEmblems(
                 vehicleCD=vehicleCD)
         else:
             _logger.error(
                 'Failed to get base vehicle outfit. VehicleDescriptor is None.'
             )
             outfit = self.itemsFactory.createOutfit()
         return outfit
     else:
         vehicle = g_currentVehicle.item
         season = g_tankActiveCamouflage.get(vehicle.intCD,
                                             SeasonType.UNDEFINED)
         if season == SeasonType.UNDEFINED:
             season = vehicle.getAnyOutfitSeason()
         g_tankActiveCamouflage[vehicle.intCD] = season
         outfit = vehicle.getOutfit(season)
         if not outfit:
             vehicleCD = vehicle.descriptor.makeCompactDescr()
             outfit = self.customizationService.getEmptyOutfitWithNationalEmblems(
                 vehicleCD=vehicleCD)
         return outfit
    def __setInstalledRawItems(self, curVehDescr):
        installedRawItems = {'camouflages': list(curVehDescr.camouflages),
         'emblems': list(curVehDescr.playerEmblems),
         'inscriptions': list(curVehDescr.playerInscriptions)}
        for key in installedRawItems.keys():
            for installedRawItem in installedRawItems[key]:
                installedItemID = installedRawItem[0]
                if installedRawItem[2] == 0 and installedItemID is not None and (TYPE_NAME[key] != CUSTOMIZATION_TYPE.EMBLEM or TYPE_NAME[key] == CUSTOMIZATION_TYPE.EMBLEM) and installedItemID not in self.__itemGroups[CUSTOMIZATION_TYPE.EMBLEM]['auto'][0]:
                    self.__notMigratedItems[TYPE_NAME[key]].add(installedItemID)

        if self.__displayIgrItems:
            vehicleId = g_currentVehicle.item.invID
            igrLayout = g_itemsCache.items.inventory.getIgrCustomizationsLayout()
            igrRoomType = getIGRCtrl().getRoomType()
            igrVehDescr = []
            if vehicleId in igrLayout:
                if igrRoomType in igrLayout[vehicleId]:
                    igrVehDescr = igrLayout[vehicleId][igrRoomType]
            for key in igrVehDescr:
                for index in igrVehDescr[key]:
                    replacedItemID = installedRawItems[key][index][0]
                    replacedItemDaysLeft = installedRawItems[key][index][2]
                    if replacedItemID is not None:
                        self.__igrReplacedItems[TYPE_NAME[key]][replacedItemID] = replacedItemDaysLeft
                    installedRawItems[key][index] = igrVehDescr[key][index]

        activeCamouflage = g_tankActiveCamouflage['historical'].get(curVehDescr.type.compactDescr)
        if activeCamouflage is None:
            activeCamouflage = g_tankActiveCamouflage.get(curVehDescr.type.compactDescr, 0)
        camouflageID = curVehDescr.camouflages[activeCamouflage][0]
        self.__initialViewModel = (camouflageID, installedRawItems['emblems'], installedRawItems['inscriptions'])
        self.viewModel = [camouflageID, copy.deepcopy(installedRawItems['emblems']), copy.deepcopy(installedRawItems['inscriptions'])]
        return installedRawItems
Example #6
0
 def __startBuild(self, vDesc, vState):
     self.__curBuildInd += 1
     self.__vDesc = vDesc
     self.__vState = vState
     self.__resources = {}
     self.__vehicleStickers = None
     camouflageResources = {'camouflageExclusionMask': vDesc.type.camouflageExclusionMask}
     customization = items.vehicles.g_cache.customization(vDesc.type.customizationNationID)
     if customization is not None and vDesc.camouflages is not None:
         activeCamo = g_tankActiveCamouflage['historical'].get(vDesc.type.compactDescr)
         if activeCamo is None:
             activeCamo = g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)
         camouflageID = vDesc.camouflages[activeCamo][0]
         camouflageDesc = customization['camouflages'].get(camouflageID)
         if camouflageDesc is not None:
             camouflageResources['camouflageTexture'] = camouflageDesc['texture']
     if vState == 'undamaged':
         self.__emblemsAlpha = _CFG['emblems_alpha_undamaged']
         self.__isVehicleDestroyed = False
     else:
         self.__emblemsAlpha = _CFG['emblems_alpha_damaged']
         self.__isVehicleDestroyed = True
     resources = camouflageResources.values()
     splineDesc = vDesc.chassis['splineDesc']
     if splineDesc is not None:
         resources.extend(splineDesc.values())
     from vehicle_systems import model_assembler
     resources.append(model_assembler.prepareCompoundAssembler(self.__vDesc, self.__vState, self.__spaceId))
     BigWorld.loadResourceListBG(tuple(resources), partial(self.__onResourcesLoaded, self.__curBuildInd))
     return
 def _onInventoryUpdate(self, invDiff):
     vehsDiff = invDiff.get(GUI_ITEM_TYPE.VEHICLE, {})
     isVehicleSold = False
     isVehicleDescrChanged = False
     if 'compDescr' in vehsDiff and self.__vehInvID in vehsDiff['compDescr']:
         isVehicleSold = vehsDiff['compDescr'][self.__vehInvID] is None
         isVehicleDescrChanged = not isVehicleSold
     if isVehicleSold or self.__vehInvID == 0:
         self.selectVehicle()
     else:
         isRepaired = 'repair' in vehsDiff and self.__vehInvID in vehsDiff[
             'repair']
         customizationDiff = invDiff.get(GUI_ITEM_TYPE.CUSTOMIZATION, {})
         isCustomizationChanged = CustomizationInvData.OUTFITS in customizationDiff
         if isCustomizationChanged and self.item is not None:
             season = g_tankActiveCamouflage.get(
                 self.item.intCD, self.item.getAnyOutfitSeason())
             vehicleOutfitDiff = customizationDiff[
                 CustomizationInvData.OUTFITS].get(self.item.intCD, {})
             if vehicleOutfitDiff is not None:
                 isCustomizationChanged = season in vehicleOutfitDiff or SeasonType.ALL in vehicleOutfitDiff
         isComponentsChanged = GUI_ITEM_TYPE.TURRET in invDiff or GUI_ITEM_TYPE.GUN in invDiff
         isVehicleChanged = any((self.__vehInvID in hive
                                 or (self.__vehInvID, '_r') in hive
                                 for hive in vehsDiff.itervalues()))
         if isComponentsChanged or isRepaired or isCustomizationChanged:
             self.refreshModel()
         elif isVehicleDescrChanged:
             self.updateVehicleDescriptorInModel()
         if isVehicleChanged or isRepaired or isCustomizationChanged:
             self._updateVehicle()
     return
Example #8
0
 def __getStyleProgressionOutfitData(self, outfit):
     vehicle = None
     if g_currentVehicle.isPresent():
         vehicle = g_currentVehicle.item
     elif g_currentPreviewVehicle.isPresent():
         vehicle = g_currentPreviewVehicle.item
     if vehicle:
         season = g_tankActiveCamouflage.get(vehicle.intCD, vehicle.getAnyOutfitSeason())
         progressionOutfit = camouflages.getStyleProgressionOutfit(outfit, outfit.progressionLevel, season)
         if progressionOutfit:
             return progressionOutfit
     return outfit
 def _getActiveOutfit(self):
     if g_currentPreviewVehicle.isPresent() or not g_currentVehicle.isPresent():
         return self.itemsFactory.createOutfit()
     else:
         vehicle = g_currentVehicle.item
         if not vehicle:
             return None
         season = g_tankActiveCamouflage.get(vehicle.intCD, SeasonType.UNDEFINED)
         if season == SeasonType.UNDEFINED or not vehicle.hasOutfitWithItems(season):
             season = vehicle.getAnyOutfitSeason()
         g_tankActiveCamouflage[vehicle.intCD] = season
         return vehicle.getOutfit(season)
Example #10
0
    def __getCurrentCamouflage(self):
        if self.__vDesc.camouflages is not None:
            activeCamo = g_tankActiveCamouflage['historical'].get(self.__vDesc.type.compactDescr)
            if activeCamo is None:
                activeCamo = g_tankActiveCamouflage.get(self.__vDesc.type.compactDescr, 0)
            camouflageID = self.__vDesc.camouflages[activeCamo][0]
        if camouflageID is None:
            for camouflageData in self.__vDesc.camouflages:
                if camouflageData[0] is not None:
                    camouflageID = camouflageData[0]
                    break

        return camouflageID
Example #11
0
def new_reload(base, self, vDesc, vState, outfit):
    if vState != 'undamaged':
        return base(self, vDesc, vState, outfit)
    manager = ServicesLocator.appLoader.getDefLobbyApp().containerManager
    if manager is not None:
        container = manager.getContainer(ViewTypes.LOBBY_SUB)
        if container is not None:
            c11nView = container.getView()
            if c11nView is not None and hasattr(c11nView, 'service'):
                outfit = c11nView.service.getCtx().currentOutfit
                return base(self, vDesc, vState, outfit)
    if (not g_config.data['enabled'] or vDesc.name in g_config.disable
            or (vDesc.type.hasCustomDefaultCamouflage
                and g_config.data['disableWithDefault'])):
        return base(self, vDesc, vState, outfit)
    for descr in g_currentPreviewVehicle, g_currentVehicle:
        if descr.isPresent() and descr.item.descriptor.name == vDesc.name:
            vehicle = descr.item
            break
    else:
        vehicle = None
    nation, vehicleName = vDesc.name.split(':')
    intCD = vDesc.type.compactDescr
    season = g_tankActiveCamouflage.get(intCD, SeasonType.EVENT)
    if g_config.data['hangarCamoKind'] < 3:
        g_tankActiveCamouflage[intCD] = SeasonType.fromArenaKind(
            g_config.data['hangarCamoKind'])
    elif season in (SeasonType.UNDEFINED, SeasonType.EVENT):
        active = [
            s for s in SeasonType.SEASONS
            if vehicle and vehicle.hasOutfitWithItems(s)
        ]
        g_tankActiveCamouflage[intCD] = random.choice(
            active) if active else SeasonType.SUMMER
    if season not in (g_tankActiveCamouflage[intCD], SeasonType.UNDEFINED,
                      SeasonType.EVENT):
        season = g_tankActiveCamouflage[intCD]
        if vehicle:
            outfit = vehicle.getOutfit(season)
    outfit = outfit.copy() if outfit else Outfit()
    seasonName = SEASON_TYPE_TO_NAME[g_tankActiveCamouflage[intCD]]
    seasonCache = g_config.hangarCamoCache.setdefault(nation, {}).setdefault(
        vehicleName, {}).setdefault(seasonName, {})
    outfit = applyOutfitInfo(outfit, seasonName, vDesc, seasonCache)
    return base(self, vDesc, vState, outfit)
Example #12
0
    def buildList(self):
        customization = vehicles.g_cache.customization(self._nationID)
        result = []
        compactDescr = g_currentVehicle.item.descriptor.type.compactDescr
        activeGroup = g_tankActiveCamouflage['historical'].get(compactDescr)
        if activeGroup is None:
            activeGroup = g_tankActiveCamouflage.get(compactDescr, 0)
        if customization is not None:
            groups = customization.get('camouflageGroups', {})
            for name, info in groups.iteritems():
                isHasNew = self._hasNewItems(CUSTOMIZATION_ITEM_TYPE.CAMOUFLAGE_TYPE, info.get('ids', []))
                if name in CAMOUFLAGE_KINDS:
                    groupId = CAMOUFLAGE_KINDS.get(name)
                    result.append({'name': name,
                     'userString': info.get('userString', name),
                     'hasNew': isHasNew,
                     'kind': groupId,
                     'enabled': True,
                     'selected': activeGroup == groupId})

        self._list = sorted(result, cmp=self.__comparator)
    def updateCamouflage(self, camouflageID = None):
        texture = ''
        colors = [0,
         0,
         0,
         0]
        gloss = 0
        weights = Math.Vector4(1, 0, 0, 0)
        camouflagePresent = True
        vDesc = self.__vDesc
        if vDesc is None:
            return
        if camouflageID is None and vDesc.camouflages is not None:
            activeCamo = g_tankActiveCamouflage['historical'].get(vDesc.type.compactDescr)
            if activeCamo is None:
                activeCamo = g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)
            camouflageID = vDesc.camouflages[activeCamo][0]
        if camouflageID is None:
            for camouflageData in vDesc.camouflages:
                if camouflageData[0] is not None:
                    camouflageID = camouflageData[0]
                    break

        customization = items.vehicles.g_cache.customization(vDesc.type.customizationNationID)
        defaultTiling = None
        if camouflageID is not None and customization is not None:
            camouflage = customization['camouflages'].get(camouflageID)
            if camouflage is not None:
                camouflagePresent = True
                texture = camouflage['texture']
                colors = camouflage['colors']
                gloss = camouflage['gloss'].get(vDesc.type.compactDescr)
                if gloss is None:
                    gloss = 0
                metallic = camouflage['metallic'].get(vDesc.type.compactDescr)
                if metallic is None:
                    metallic = 0
                weights = Math.Vector4(*[ (c >> 24) / 255.0 for c in colors ])
                colors = [ colors[i] & 16777215 | metallic << (3 - i) * 8 & 4278190080L for i in range(0, 4) ]
                defaultTiling = camouflage['tiling'].get(vDesc.type.compactDescr)
 def changeStyleProgressionLevelPreview(self, level):
     entity = self.hangarSpace.getVehicleEntity()
     if not entity or not level or not entity.isVehicleLoaded:
         return 1
     else:
         outfit = entity.appearance.outfit
         if not outfit.style or not outfit.style.isProgression:
             return 1
         if g_currentPreviewVehicle.isPresent():
             vehicle = g_currentPreviewVehicle.item
             if vehicle:
                 season = g_tankActiveCamouflage.get(
                     vehicle.intCD, vehicle.getAnyOutfitSeason())
                 resOutfit = getStyleProgressionOutfit(
                     outfit, level, season)
                 self.tryOnOutfit(resOutfit)
                 if self.__customizationCtx is not None:
                     slotID = C11nId(areaId=Area.MISC,
                                     slotType=GUI_ITEM_TYPE.STYLE,
                                     regionIdx=0)
                     self.__customizationCtx.events.onComponentChanged(
                         slotID, True)
                 return resOutfit.progressionLevel
         return 1
Example #15
0
    def updateCamouflage(self, camouflageID=None):
        texture = ''
        colors = [0, 0, 0, 0]
        weights = Math.Vector4(1, 0, 0, 0)
        camouflagePresent = True
        vDesc = self.__vDesc
        if vDesc is None:
            return
        else:
            if camouflageID is None and vDesc.camouflages is not None:
                camouflageID = vDesc.camouflages[g_tankActiveCamouflage.get(
                    vDesc.type.compactDescr, 0)][0]
            if camouflageID is None:
                for camouflageData in vDesc.camouflages:
                    if camouflageData[0] is not None:
                        camouflageID = camouflageData[0]
                        break

            customization = items.vehicles.g_cache.customization(
                vDesc.type.customizationNationID)
            defaultTiling = None
            if camouflageID is not None and customization is not None:
                camouflage = customization['camouflages'].get(camouflageID)
                if camouflage is not None:
                    camouflagePresent = True
                    texture = camouflage['texture']
                    colors = camouflage['colors']
                    weights = Math.Vector4(
                        (colors[0] >> 24) / 255.0, (colors[1] >> 24) / 255.0,
                        (colors[2] >> 24) / 255.0, (colors[3] >> 24) / 255.0)
                    defaultTiling = camouflage['tiling'].get(
                        vDesc.type.compactDescr)
            if self.__isVehicleDestroyed:
                weights *= 0.1
            if vDesc.camouflages is not None:
                _, camStartTime, camNumDays = vDesc.camouflages[
                    g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)]
                if camNumDays > 0:
                    timeAmount = (time.time() - camStartTime) / (camNumDays *
                                                                 86400)
                    if timeAmount > 1.0:
                        weights *= _CAMOUFLAGE_MIN_INTENSITY
                    elif timeAmount > 0:
                        weights *= (1.0 - timeAmount) * (
                            1.0 - _CAMOUFLAGE_MIN_INTENSITY
                        ) + _CAMOUFLAGE_MIN_INTENSITY
            for model in self.__models:
                exclusionMap = vDesc.type.camouflageExclusionMask
                tiling = defaultTiling
                if tiling is None:
                    tiling = vDesc.type.camouflageTiling
                tgDesc = None
                if model == self.__models[2]:
                    tgDesc = vDesc.turret
                elif model == self.__models[3]:
                    tgDesc = vDesc.gun
                if tgDesc is not None:
                    coeff = tgDesc.get('camouflageTiling')
                    if coeff is not None:
                        if tiling is not None:
                            tiling = (tiling[0] * coeff[0],
                                      tiling[1] * coeff[1],
                                      tiling[2] * coeff[2],
                                      tiling[3] * coeff[3])
                        else:
                            tiling = coeff
                    if tgDesc.has_key('camouflageExclusionMask'):
                        exclusionMap = tgDesc['camouflageExclusionMask']
                if not camouflagePresent or exclusionMap == '' or texture == '':
                    if hasattr(model, 'wg_fashion'):
                        delattr(model, 'wg_fashion')
                else:
                    if not hasattr(model, 'wg_fashion'):
                        if model == self.__models[0]:
                            tracksCfg = vDesc.chassis['tracks']
                            fashion = BigWorld.WGVehicleFashion()
                            fashion.setTracks(tracksCfg['leftMaterial'],
                                              tracksCfg['rightMaterial'],
                                              tracksCfg['textureScale'])
                            model.wg_fashion = fashion
                        else:
                            model.wg_fashion = BigWorld.WGBaseFashion()
                    model.wg_fashion.setCamouflage(texture, exclusionMap,
                                                   tiling, colors[0],
                                                   colors[1], colors[2],
                                                   colors[3], weights)

            return
Example #16
0
def new_assembleModel(base, self, *a, **kw):
    result = base(self, *a, **kw)
    if not self._HangarVehicleAppearance__isVehicleDestroyed:
        manager = g_appLoader.getDefLobbyApp().containerManager
        if manager is not None:
            container = manager.getContainer(ViewTypes.LOBBY_SUB)
            if container is not None:
                c11nView = container.getView()
                if c11nView is not None and hasattr(c11nView,
                                                    'getCurrentOutfit'):
                    outfit = c11nView.getCurrentOutfit(
                    )  # fix for HangarFreeCam
                    self.updateCustomization(outfit)
                    return result
        if g_currentPreviewVehicle.isPresent():
            vehicle = g_currentPreviewVehicle.item
        elif g_currentVehicle.isPresent():
            vehicle = g_currentVehicle.item
        else:
            vehicle = None
        vDesc = self._HangarVehicleAppearance__vDesc
        if g_config.data[
                'enabled'] and vDesc.name not in g_config.disable and not (
                    vDesc.type.hasCustomDefaultCamouflage
                    and g_config.data['disableWithDefault']):
            nationName, vehicleName = vDesc.name.split(':')
            intCD = vDesc.type.compactDescr
            if g_config.data['hangarCamoKind'] < 3:
                idx = g_config.data['hangarCamoKind']
                season = SeasonType.fromArenaKind(idx)
                outfit = vehicle.getOutfit(season).copy(
                ) if vehicle else self.itemsFactory.createOutfit()
                g_tankActiveCamouflage[intCD] = season
            else:
                outfit = self._getActiveOutfit().copy()
                if g_tankActiveCamouflage.get(
                        intCD, SeasonType.EVENT) == SeasonType.EVENT:
                    active = []
                    for season in SeasonType.SEASONS:
                        if vehicle and vehicle.hasOutfitWithItems(season):
                            active.append(season)
                    g_tankActiveCamouflage[intCD] = random.choice(
                        active) if active else SeasonType.SUMMER
            if not g_config.data['useBought']:
                outfit = self.itemsFactory.createOutfit()
            seasonName = SEASON_TYPE_TO_NAME[g_tankActiveCamouflage[intCD]]
            vehCache = g_config.outfitCache.get(nationName,
                                                {}).get(vehicleName, {})
            applyPlayerCache(outfit, vehicleName, vehCache.get(seasonName, {}))
            applied, cleaned = applyCamoCache(
                outfit, vehicleName,
                vehCache.get(seasonName, {}).get('camo', {}))
            if cleaned:
                vehCache.get(seasonName, {}).pop('camo', None)
            if not vehCache.get(seasonName, None):
                vehCache.pop(seasonName, None)
            if g_config.data['doRandom'] and (not applied or cleaned or
                                              g_config.data['fillEmptySlots']):
                seasonCache = g_config.hangarCamoCache.setdefault(
                    nationName, {}).setdefault(vehicleName,
                                               {}).setdefault(seasonName, {})
                processRandomCamouflages(
                    outfit,
                    seasonName,
                    seasonCache,
                    isGunCarriage=vDesc.turret.isGunCarriage)
                applyCamoCache(outfit, vehicleName, seasonCache)
            self._HangarVehicleAppearance__outfit = outfit
            self.updateCustomization(outfit)
    return result
    def updateCamouflage(self, camouflageID = None):
        texture = ''
        colors = [0,
         0,
         0,
         0]
        weights = Math.Vector4(1, 0, 0, 0)
        camouflagePresent = True
        vDesc = self.__vDesc
        if vDesc is None:
            return
        else:
            if camouflageID is None and vDesc.camouflages is not None:
                camouflageID = vDesc.camouflages[g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)][0]
            if camouflageID is None:
                for camouflageData in vDesc.camouflages:
                    if camouflageData[0] is not None:
                        camouflageID = camouflageData[0]
                        break

            customization = items.vehicles.g_cache.customization(vDesc.type.customizationNationID)
            defaultTiling = None
            if camouflageID is not None and customization is not None:
                camouflage = customization['camouflages'].get(camouflageID)
                if camouflage is not None:
                    camouflagePresent = True
                    texture = camouflage['texture']
                    colors = camouflage['colors']
                    weights = Math.Vector4((colors[0] >> 24) / 255.0, (colors[1] >> 24) / 255.0, (colors[2] >> 24) / 255.0, (colors[3] >> 24) / 255.0)
                    defaultTiling = camouflage['tiling'].get(vDesc.type.compactDescr)
            if self.__isVehicleDestroyed:
                weights *= 0.1
            if vDesc.camouflages is not None:
                _, camStartTime, camNumDays = vDesc.camouflages[g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)]
                if camNumDays > 0:
                    timeAmount = (time.time() - camStartTime) / (camNumDays * 86400)
                    if timeAmount > 1.0:
                        weights *= _CAMOUFLAGE_MIN_INTENSITY
                    elif timeAmount > 0:
                        weights *= (1.0 - timeAmount) * (1.0 - _CAMOUFLAGE_MIN_INTENSITY) + _CAMOUFLAGE_MIN_INTENSITY
            for model in self.__models:
                exclusionMap = vDesc.type.camouflageExclusionMask
                tiling = defaultTiling
                if tiling is None:
                    tiling = vDesc.type.camouflageTiling
                tgDesc = None
                if model == self.__models[2]:
                    tgDesc = vDesc.turret
                elif model == self.__models[3]:
                    tgDesc = vDesc.gun
                if tgDesc is not None:
                    coeff = tgDesc.get('camouflageTiling')
                    if coeff is not None:
                        if tiling is not None:
                            tiling = (tiling[0] * coeff[0],
                             tiling[1] * coeff[1],
                             tiling[2] * coeff[2],
                             tiling[3] * coeff[3])
                        else:
                            tiling = coeff
                    if tgDesc.has_key('camouflageExclusionMask'):
                        exclusionMap = tgDesc['camouflageExclusionMask']
                if not camouflagePresent or exclusionMap == '' or texture == '':
                    if hasattr(model, 'wg_fashion'):
                        delattr(model, 'wg_fashion')
                else:
                    if not hasattr(model, 'wg_fashion'):
                        if model == self.__models[0]:
                            tracksCfg = vDesc.chassis['tracks']
                            fashion = BigWorld.WGVehicleFashion()
                            fashion.setTracks(tracksCfg['leftMaterial'], tracksCfg['rightMaterial'], tracksCfg['textureScale'])
                            model.wg_fashion = fashion
                        else:
                            model.wg_fashion = BigWorld.WGBaseFashion()
                    model.wg_fashion.setCamouflage(texture, exclusionMap, tiling, colors[0], colors[1], colors[2], colors[3], weights)

            return
Example #18
0
def installSelectedCamo():
    if g_currentPreviewVehicle.isPresent():
        vDesc = g_currentPreviewVehicle.item.descriptor
    elif g_currentVehicle.isPresent():
        vDesc = g_currentVehicle.item.descriptor
    else:
        return
    nationName, vehName = vDesc.name.split(':')
    nationID = vDesc.type.customizationNationID
    compDescr = vDesc.type.compactDescr
    assert nations.NAMES[nationID] == nationName, (nationName, nations.NAMES[nationID])
    if g_customizationController.slots.currentSlotsData is None:
        activeCamo = g_tankActiveCamouflage['historical'].get(compDescr)
        if activeCamo is None:
            activeCamo = g_tankActiveCamouflage.get(compDescr, 0)
        customization = items.vehicles.g_cache.customization(nationID)
        if _config.activePreviewCamo is not None:
            camoNames = {camouflage['name']: camoID for camoID, camouflage in customization['camouflages'].items()}
            camoID = camoNames[_config.activePreviewCamo]
            if compDescr in _config.hangarCamoCache:
                del _config.hangarCamoCache[compDescr]
        elif compDescr in _config.hangarCamoCache:
            camoID = _config.hangarCamoCache[compDescr][activeCamo][0]
        else:
            return
        camouflage = customization['camouflages'][camoID]
        camoName = camouflage['name']
        nationConf = _config.camouflages.get(nations.NAMES[nationID])
        interConf = _config.camouflages.get('international', {})
        camoKindNums = (camouflage['kind'],)
        if camoName in _config.camouflages['modded']:
            camoKindNames = filter(None, _config.camouflages['modded'].get(camoName, {}).get('kinds', '').split(','))
            camoKindNums = tuple(CAMOUFLAGE_KINDS[name] for name in camoKindNames)
        elif camoName in interConf:
            kindsStr = interConf.get(camoName, {}).get('kinds')
            if kindsStr is not None:
                camoKindNames = filter(None, kindsStr.split(','))
                camoKindNums = tuple(CAMOUFLAGE_KINDS[name] for name in camoKindNames)
        elif nationConf is not None:
            kindsStr = nationConf.get(camoName, {}).get('kinds')
            if kindsStr is not None:
                camoKindNames = filter(None, kindsStr.split(','))
                camoKindNums = tuple(CAMOUFLAGE_KINDS[name] for name in camoKindNames)
        for camoKindNum in camoKindNums:
            if _config.camouflagesCache.get(nationName, {}).get(vehName, {}).get(
                    CAMOUFLAGE_KIND_INDICES[camoKindNum]) == camoName:
                SystemMessages.pushMessage('PYmods_SM' + _config.i18n['UI_installCamouflage_already'].format(
                    name=camoName, kind=_config.i18n['UI_setting_hangarCamo_%s' % CAMOUFLAGE_KIND_INDICES[camoKindNum]]),
                                           SystemMessages.SM_TYPE.CustomizationForGold)
                continue
            _config.camouflagesCache.setdefault(nationName, {}).setdefault(vehName, {})[
                CAMOUFLAGE_KIND_INDICES[camoKindNum]] = camoName
            SystemMessages.pushMessage('PYmods_SM' + _config.i18n['UI_installCamouflage'].format(
                name=camoName, kind=_config.i18n['UI_setting_hangarCamo_%s' % CAMOUFLAGE_KIND_INDICES[camoKindNum]]),
                                       SystemMessages.SM_TYPE.CustomizationForGold)
            PYmodsCore.loadJson(_config.ID, 'camouflagesCache', _config.camouflagesCache, _config.configPath, True)
        return
    camoCache = list(vDesc.camouflages)
    for item in g_customizationController.cart.items:
        if item['type'] != CUSTOMIZATION_TYPE.CAMOUFLAGE:
            continue
        camoKindNum = item['object']._rawData['kind']
        camoName = item['object']._rawData['name']
        _config.camouflagesCache.setdefault(nationName, {}).setdefault(vehName, {})[
            CAMOUFLAGE_KIND_INDICES[camoKindNum]] = camoName
        camoCache[camoKindNum] = (item['object'].getID(), int(time.time()), 7)
    selectedKinds = []
    for camoKind in _config.camouflagesCache.get(nationName, {}).get(vehName, {}):
        selectedKinds.append(CAMOUFLAGE_KINDS[camoKind])
    slotList = heapq.nsmallest(1, selectedKinds, key=lambda x: abs(x - g_customizationController.slots.currentSlotIdx))
    slotIdx = slotList[0] if slotList else 0
    g_tankActiveCamouflage[compDescr] = slotIdx
    vDesc.camouflages = tuple(camoCache)
    _config.hangarCamoCache[compDescr] = tuple(camoCache)
    if vehName in _config.camouflagesCache.get(nationName, {}) and not _config.camouflagesCache[nationName][vehName]:
        del _config.camouflagesCache[nationName][vehName]
    if nationName in _config.camouflagesCache and not _config.camouflagesCache[nationName]:
        del _config.camouflagesCache[nationName]
    PYmodsCore.loadJson(_config.ID, 'camouflagesCache', _config.camouflagesCache, _config.configPath, True)
    PYmodsCore.refreshCurrentVehicle()
    SystemMessages.pushMessage('PYmods_SM' + _config.i18n['UI_camouflageSelect'],
                               SystemMessages.SM_TYPE.CustomizationForGold)
         camouflagePresent = True
         texture = camouflage['texture']
         colors = camouflage['colors']
         gloss = camouflage['gloss'].get(vDesc.type.compactDescr)
         if gloss is None:
             gloss = 0
         metallic = camouflage['metallic'].get(vDesc.type.compactDescr)
         if metallic is None:
             metallic = 0
         weights = Math.Vector4(*[ (c >> 24) / 255.0 for c in colors ])
         colors = [ colors[i] & 16777215 | metallic << (3 - i) * 8 & 4278190080L for i in range(0, 4) ]
         defaultTiling = camouflage['tiling'].get(vDesc.type.compactDescr)
 if self.__isVehicleDestroyed:
     weights *= 0.1
 if vDesc.camouflages is not None:
     _, camStartTime, camNumDays = vDesc.camouflages[g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)]
     if camNumDays > 0:
         timeAmount = (time.time() - camStartTime) / (camNumDays * 86400)
         if timeAmount > 1.0:
             weights *= _CAMOUFLAGE_MIN_INTENSITY
         elif timeAmount > 0:
             weights *= (1.0 - timeAmount) * (1.0 - _CAMOUFLAGE_MIN_INTENSITY) + _CAMOUFLAGE_MIN_INTENSITY
 for model in self.__models:
     exclusionMap = vDesc.type.camouflageExclusionMask
     tiling = defaultTiling
     if tiling is None:
         tiling = vDesc.type.camouflageTiling
     if model == self.__models[0]:
         compDesc = vDesc.chassis
     elif model == self.__models[1]:
         compDesc = vDesc.hull
    def updateCamouflage(self, camouflageID = None):
        texture = ''
        colors = [0,
         0,
         0,
         0]
        weights = Math.Vector4(1, 0, 0, 0)
        camouflagePresent = True
        vDesc = self.__vDesc
        if vDesc is None:
            return
        else:
            if camouflageID is None and vDesc.camouflages is not None:
                activeCamo = g_tankActiveCamouflage['historical'].get(vDesc.type.compactDescr)
                if activeCamo is None:
                    activeCamo = g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)
                camouflageID = vDesc.camouflages[activeCamo][0]
            if camouflageID is None:
                for camouflageData in vDesc.camouflages:
                    if camouflageData[0] is not None:
                        camouflageID = camouflageData[0]
                        break

            customization = items.vehicles.g_cache.customization(vDesc.type.customizationNationID)
            defaultTiling = None
            if camouflageID is not None and customization is not None:
                camouflage = customization['camouflages'].get(camouflageID)
                if camouflage is not None:
                    camouflagePresent = True
                    texture = camouflage['texture']
                    colors = camouflage['colors']
                    weights = Math.Vector4(*[ (c >> 24) / 255.0 for c in colors ])
                    defaultTiling = camouflage['tiling'].get(vDesc.type.compactDescr)
            if self.__isVehicleDestroyed:
                weights *= 0.1
            if vDesc.camouflages is not None:
                _, camStartTime, camNumDays = vDesc.camouflages[g_tankActiveCamouflage.get(vDesc.type.compactDescr, 0)]
                if camNumDays > 0:
                    timeAmount = (time.time() - camStartTime) / (camNumDays * 86400)
                    if timeAmount > 1.0:
                        weights *= _CAMOUFLAGE_MIN_INTENSITY
                    elif timeAmount > 0:
                        weights *= (1.0 - timeAmount) * (1.0 - _CAMOUFLAGE_MIN_INTENSITY) + _CAMOUFLAGE_MIN_INTENSITY
            for model in self.__models:
                exclusionMap = vDesc.type.camouflageExclusionMask
                tiling = defaultTiling
                if tiling is None:
                    tiling = vDesc.type.camouflageTiling
                if model == self.__models[0]:
                    compDesc = vDesc.chassis
                elif model == self.__models[1]:
                    compDesc = vDesc.hull
                elif model == self.__models[2]:
                    compDesc = vDesc.turret
                elif model == self.__models[3]:
                    compDesc = vDesc.gun
                else:
                    compDesc = None
                if compDesc is not None:
                    coeff = compDesc.get('camouflageTiling')
                    if coeff is not None:
                        if tiling is not None:
                            tiling = (tiling[0] * coeff[0],
                             tiling[1] * coeff[1],
                             tiling[2] * coeff[2],
                             tiling[3] * coeff[3])
                        else:
                            tiling = coeff
                    if compDesc.get('camouflageExclusionMask'):
                        exclusionMap = compDesc['camouflageExclusionMask']
                useCamouflage = camouflagePresent and texture
                fashion = None
                if hasattr(model, 'wg_fashion'):
                    fashion = model.wg_fashion
                elif hasattr(model, 'wg_gunRecoil'):
                    fashion = model.wg_gunRecoil
                elif useCamouflage:
                    fashion = model.wg_baseFashion = BigWorld.WGBaseFashion()
                elif hasattr(model, 'wg_baseFashion'):
                    delattr(model, 'wg_baseFashion')
                if fashion is not None:
                    if useCamouflage:
                        fashion.setCamouflage(texture, exclusionMap, tiling, colors[0], colors[1], colors[2], colors[3], weights)
                    else:
                        fashion.removeCamouflage()

            return