class VehicleCompareView(LobbySubView, VehicleCompareViewMeta): __background_alpha__ = 0.0 itemsCache = dependency.descriptor(IItemsCache) comparisonBasket = dependency.descriptor(IVehicleComparisonBasket) def __init__(self, ctx=None): super(VehicleCompareView, self).__init__(ctx) self.__vehDP = None self.__paramsCache = None self.__backAlias = ctx.get('previewAlias', VIEW_ALIAS.LOBBY_HANGAR) return def closeView(self): self.onBackClick() def onSelectModulesClick(self, vehicleID, index): tutorStorage = getTutorialGlobalStorage() if tutorStorage: tutorStorage.setValue(OnceOnlyHints.VEH_COMPARE_CONFIG_HINT, False) event = g_entitiesFactories.makeLoadEvent(VIEW_ALIAS.VEHICLE_COMPARE_MAIN_CONFIGURATOR, ctx={'index': int(index)}) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) def onRemoveAllVehicles(self): self.comparisonBasket.removeAllVehicles() def onRemoveVehicle(self, index): self.comparisonBasket.removeVehicleByIdx(int(index)) def onRevertVehicle(self, index): self.comparisonBasket.revertVehicleByIdx(int(index)) def onGoToPreviewClick(self, slotID): cmpVehicle = self.comparisonBasket.getVehicleAt(int(slotID)) vehicleStrCD = cmpVehicle.getVehicleStrCD() vehicleIntCD = cmpVehicle.getVehicleCD() vehicle = self.itemsCache.items.getItemByCD(vehicleIntCD) if vehicle.isPreviewAllowed(): showVehiclePreview(vehicleIntCD, VIEW_ALIAS.VEHICLE_COMPARE, vehStrCD=vehicleStrCD) else: SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.VEHICLECOMPARE_PREVIEWNOTALLOWED, vehicle=vehicle.userName, type=SystemMessages.SM_TYPE.Error) def onGoToHangarClick(self, vehicleID): selectVehicleInHangar(int(vehicleID)) def onParamDeltaRequested(self, index, paramID): deltas = self.__paramsCache.getParametersDelta(int(index), paramID) self.as_setParamsDeltaS({'paramID': paramID, 'deltas': deltas}) self.__updateDifferenceAttention() def onBackClick(self): event = g_entitiesFactories.makeLoadEvent(self.__backAlias) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) def _populate(self): super(VehicleCompareView, self)._populate() self.as_setStaticDataS({'header': self.__getHeaderData()}) self.as_setVehicleParamsDataS(getAllParametersTitles()) self._setViewData() self.comparisonBasket.onChange += self.__updateUI self.comparisonBasket.onSwitchChange += self.__onVehCmpBasketStateChanged self.comparisonBasket.onParametersChange += self.__onVehicleParamsChanged self.comparisonBasket.onNationChange += self._setViewData def _setViewData(self): self.__vehDP = VehiclesDataProvider() self.__vehDP.setFlashObject(self.as_getVehiclesDPS()) self.__clearParamsCache() self.__paramsCache = VehCompareBasketParamsCache(self.__vehDP) self.__updateUI() def _dispose(self): super(VehicleCompareView, self)._dispose() self.comparisonBasket.onChange -= self.__updateUI self.comparisonBasket.onSwitchChange -= self.__onVehCmpBasketStateChanged self.comparisonBasket.onParametersChange -= self.__onVehicleParamsChanged self.comparisonBasket.onNationChange -= self._setViewData self.__clearParamsCache() self.__vehDP.fini() self.__vehDP = None self.comparisonBasket.writeCache() return def __clearParamsCache(self): if self.__paramsCache is not None: self.__paramsCache.dispose() self.__paramsCache = None return def __updateUI(self, *data): self.as_setVehiclesCountTextS(text_styles.main(_ms(VEH_COMPARE.VEHICLECOMPAREVIEW_TOPPANEL_VEHICLESCOUNT, count=text_styles.stats(self.comparisonBasket.getVehiclesCount())))) self.__updateDifferenceAttention() def __onVehCmpBasketStateChanged(self): if not self.comparisonBasket.isEnabled(): self.destroy() def __getHeaderData(self): key = _BACK_BTN_LABELS.get(self.__backAlias, 'hangar') backBtnDescrLabel = '#veh_compare:header/backBtn/descrLabel/{}'.format(key) return {'closeBtnLabel': VEH_COMPARE.HEADER_CLOSEBTN_LABEL, 'backBtnLabel': VEH_COMPARE.HEADER_BACKBTN_LABEL, 'backBtnDescrLabel': backBtnDescrLabel, 'titleText': text_styles.promoSubTitle(VEH_COMPARE.VEHICLECOMPAREVIEW_HEADER)} def __updateDifferenceAttention(self): vehiclesCount = self.comparisonBasket.getVehiclesCount() if vehiclesCount > 1 and len(set(self.comparisonBasket.getVehiclesCDs())) > 1: comparisonDataIter = self.comparisonBasket.getVehiclesPropertiesIter(lambda vehCmpData: (vehCmpData.getConfigurationType(), vehCmpData.getCrewData())) prevModuleType, prevCrewData = next(comparisonDataIter) for moduleType, crewData in comparisonDataIter: if prevModuleType != moduleType or prevCrewData != crewData: break prevModuleType, prevCrewData = moduleType, crewData def __onVehicleParamsChanged(self, _): self.__updateDifferenceAttention()
class VehicleCompareView(LobbySubView, VehicleCompareViewMeta): __background_alpha__ = 0.0 def __init__(self, ctx = None): super(VehicleCompareView, self).__init__(ctx) self.__vehDP = None self.__paramsCache = None self.__backAlias = ctx.get('previewAlias', VIEW_ALIAS.LOBBY_HANGAR) return def closeView(self): self.onBackClick() def onSelectModulesClick(self, vehicleID, index): g_eventBus.handleEvent(events.LoadViewEvent(VEHICLE_COMPARE_CONSTANTS.VEHICLE_MODULES_WINDOW, ctx={'vehCD': int(vehicleID), 'index': int(index)}), EVENT_BUS_SCOPE.LOBBY) def onRemoveAllVehicles(self): getVehicleComparisonBasketCtrl().removeAllVehicles() def onRemoveVehicle(self, index): getVehicleComparisonBasketCtrl().removeVehicleByIdx(int(index)) def onCrewLevelChanged(self, index, crewLevelID): getVehicleComparisonBasketCtrl().setVehicleCrew(int(index), int(crewLevelID)) def onGoToPreviewClick(self, vehicleID): showVehiclePreview(int(vehicleID), VIEW_ALIAS.VEHICLE_COMPARE) def onGoToHangarClick(self, vehicleID): selectVehicleInHangar(int(vehicleID)) def onParamDeltaRequested(self, index, paramID): deltas = self.__paramsCache.getParametersDelta(int(index), paramID) self.as_setParamsDeltaS({'paramID': paramID, 'deltas': deltas}) def onBackClick(self): event = g_entitiesFactories.makeLoadEvent(self.__backAlias) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) def _populate(self): super(VehicleCompareView, self)._populate() self.as_setStaticDataS({'header': self.__getHeaderData()}) self.as_setVehicleParamsDataS(getAllParametersTitles()) self.__vehDP = VehiclesDataProvider() self.__vehDP.setFlashObject(self.as_getVehiclesDPS()) self.__paramsCache = VehCompareBasketParamsCache(self.__vehDP) self.__updateUI() comparisonBasket = getVehicleComparisonBasketCtrl() comparisonBasket.onChange += self.__updateUI comparisonBasket.onSwitchChange += self.__onComparingDisabled def _dispose(self): super(VehicleCompareView, self)._dispose() comparisonBasket = getVehicleComparisonBasketCtrl() comparisonBasket.onChange -= self.__updateUI comparisonBasket.onSwitchChange -= self.__onComparingDisabled self.__paramsCache.dispose() self.__paramsCache = None self.__vehDP.fini() self.__vehDP = None return def __updateUI(self, *data): self.as_setVehiclesCountTextS(text_styles.main(_ms(VEH_COMPARE.VEHICLECOMPAREVIEW_TOPPANEL_VEHICLESCOUNT, count=text_styles.stats(getVehicleComparisonBasketCtrl().getVehiclesCount())))) def __onComparingDisabled(self): """ gui.game_control.VehComparisonBasket.onSwitchChange event handler """ self.destroy() def __getHeaderData(self): key = _BACK_BTN_LABELS.get(self.__backAlias, 'hangar') backBtnDescrLabel = '#veh_compare:header/backBtn/descrLabel/{}'.format(key) return {'closeBtnLabel': VEH_COMPARE.HEADER_CLOSEBTN_LABEL, 'backBtnLabel': VEH_COMPARE.HEADER_BACKBTN_LABEL, 'backBtnDescrLabel': backBtnDescrLabel, 'titleText': text_styles.promoTitle(VEH_COMPARE.VEHICLECOMPAREVIEW_HEADER)}
class VehicleCompareView(LobbySubView, VehicleCompareViewMeta): __background_alpha__ = 0.0 def __init__(self, ctx=None): super(VehicleCompareView, self).__init__(ctx) self.__vehDP = None self.__paramsCache = None self.__backAlias = ctx.get('previewAlias', VIEW_ALIAS.LOBBY_HANGAR) return def closeView(self): self.onBackClick() def onSelectModulesClick(self, vehicleID, index): g_eventBus.handleEvent( events.LoadViewEvent( VEHICLE_COMPARE_CONSTANTS.VEHICLE_MODULES_WINDOW, ctx={ 'vehCD': int(vehicleID), 'index': int(index) }), EVENT_BUS_SCOPE.LOBBY) def onRemoveAllVehicles(self): getVehicleComparisonBasketCtrl().removeAllVehicles() def onRemoveVehicle(self, index): getVehicleComparisonBasketCtrl().removeVehicleByIdx(int(index)) def onCrewLevelChanged(self, index, crewLevelID): getVehicleComparisonBasketCtrl().setVehicleCrew( int(index), int(crewLevelID)) def onGoToPreviewClick(self, vehicleID): showVehiclePreview(int(vehicleID), VIEW_ALIAS.VEHICLE_COMPARE) def onGoToHangarClick(self, vehicleID): selectVehicleInHangar(int(vehicleID)) def onParamDeltaRequested(self, index, paramID): deltas = self.__paramsCache.getParametersDelta(int(index), paramID) self.as_setParamsDeltaS({'paramID': paramID, 'deltas': deltas}) def onBackClick(self): event = g_entitiesFactories.makeLoadEvent(self.__backAlias) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) def _populate(self): super(VehicleCompareView, self)._populate() self.as_setStaticDataS({'header': self.__getHeaderData()}) self.as_setVehicleParamsDataS(getAllParametersTitles()) self.__vehDP = VehiclesDataProvider() self.__vehDP.setFlashObject(self.as_getVehiclesDPS()) self.__paramsCache = VehCompareBasketParamsCache(self.__vehDP) self.__updateUI() comparisonBasket = getVehicleComparisonBasketCtrl() comparisonBasket.onChange += self.__updateUI comparisonBasket.onSwitchChange += self.__onComparingDisabled def _dispose(self): super(VehicleCompareView, self)._dispose() comparisonBasket = getVehicleComparisonBasketCtrl() comparisonBasket.onChange -= self.__updateUI comparisonBasket.onSwitchChange -= self.__onComparingDisabled self.__paramsCache.dispose() self.__paramsCache = None self.__vehDP.fini() self.__vehDP = None return def __updateUI(self, *data): self.as_setVehiclesCountTextS( text_styles.main( _ms(VEH_COMPARE.VEHICLECOMPAREVIEW_TOPPANEL_VEHICLESCOUNT, count=text_styles.stats( getVehicleComparisonBasketCtrl().getVehiclesCount())))) def __onComparingDisabled(self): """ gui.game_control.VehComparisonBasket.onSwitchChange event handler """ self.destroy() def __getHeaderData(self): key = _BACK_BTN_LABELS.get(self.__backAlias, 'hangar') backBtnDescrLabel = '#veh_compare:header/backBtn/descrLabel/{}'.format( key) return { 'closeBtnLabel': VEH_COMPARE.HEADER_CLOSEBTN_LABEL, 'backBtnLabel': VEH_COMPARE.HEADER_BACKBTN_LABEL, 'backBtnDescrLabel': backBtnDescrLabel, 'titleText': text_styles.promoTitle(VEH_COMPARE.VEHICLECOMPAREVIEW_HEADER) }
class VehicleCompareView(LobbySubView, VehicleCompareViewMeta): __background_alpha__ = 0.0 comparisonBasket = dependency.descriptor(IVehicleComparisonBasket) def __init__(self, ctx = None): super(VehicleCompareView, self).__init__(ctx) self.__vehDP = None self.__paramsCache = None self.__backAlias = ctx.get('previewAlias', VIEW_ALIAS.LOBBY_HANGAR) return def closeView(self): self.onBackClick() def onSelectModulesClick(self, vehicleID, index): g_eventBus.handleEvent(events.LoadViewEvent(VEHICLE_COMPARE_CONSTANTS.VEHICLE_MODULES_WINDOW, ctx={'vehCD': int(vehicleID), 'index': int(index)}), EVENT_BUS_SCOPE.LOBBY) def onRemoveAllVehicles(self): self.comparisonBasket.removeAllVehicles() def onRemoveVehicle(self, index): self.comparisonBasket.removeVehicleByIdx(int(index)) def onCrewLevelChanged(self, index, crewLevelID): self.comparisonBasket.setVehicleCrew(int(index), int(crewLevelID)) self.__updateDifferenceAttention() def onGoToPreviewClick(self, vehicleID): intVehicleID = int(vehicleID) vehicle = g_itemsCache.items.getItemByCD(intVehicleID) if vehicle.isPreviewAllowed(): showVehiclePreview(intVehicleID, VIEW_ALIAS.VEHICLE_COMPARE) else: SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.VEHICLECOMPARE_PREVIEWNOTALLOWED, vehicle=vehicle.userName, type=SystemMessages.SM_TYPE.Error) def onGoToHangarClick(self, vehicleID): selectVehicleInHangar(int(vehicleID)) def onParamDeltaRequested(self, index, paramID): deltas = self.__paramsCache.getParametersDelta(int(index), paramID) self.as_setParamsDeltaS({'paramID': paramID, 'deltas': deltas}) self.__updateDifferenceAttention() def onBackClick(self): event = g_entitiesFactories.makeLoadEvent(self.__backAlias) self.fireEvent(event, scope=EVENT_BUS_SCOPE.LOBBY) def _populate(self): super(VehicleCompareView, self)._populate() self.as_setStaticDataS({'header': self.__getHeaderData()}) self.as_setVehicleParamsDataS(getAllParametersTitles()) self.__vehDP = VehiclesDataProvider() self.__vehDP.setFlashObject(self.as_getVehiclesDPS()) self.__paramsCache = VehCompareBasketParamsCache(self.__vehDP) self.__updateUI() self.comparisonBasket.onChange += self.__updateUI self.comparisonBasket.onSwitchChange += self.__onComparingDisabled self.comparisonBasket.onParametersChange += self.__onVehicleParamsChanged def _dispose(self): super(VehicleCompareView, self)._dispose() self.comparisonBasket.onChange -= self.__updateUI self.comparisonBasket.onSwitchChange -= self.__onComparingDisabled self.comparisonBasket.onParametersChange -= self.__onVehicleParamsChanged self.__paramsCache.dispose() self.__paramsCache = None self.__vehDP.fini() self.__vehDP = None self.comparisonBasket.writeCache() return def __updateUI(self, *data): self.as_setVehiclesCountTextS(text_styles.main(_ms(VEH_COMPARE.VEHICLECOMPAREVIEW_TOPPANEL_VEHICLESCOUNT, count=text_styles.stats(self.comparisonBasket.getVehiclesCount())))) self.__updateDifferenceAttention() def __onComparingDisabled(self): """ gui.game_control.VehComparisonBasket.onSwitchChange event handler """ self.destroy() def __getHeaderData(self): key = _BACK_BTN_LABELS.get(self.__backAlias, 'hangar') backBtnDescrLabel = '#veh_compare:header/backBtn/descrLabel/{}'.format(key) return {'closeBtnLabel': VEH_COMPARE.HEADER_CLOSEBTN_LABEL, 'backBtnLabel': VEH_COMPARE.HEADER_BACKBTN_LABEL, 'backBtnDescrLabel': backBtnDescrLabel, 'titleText': text_styles.promoTitle(VEH_COMPARE.VEHICLECOMPAREVIEW_HEADER)} def __updateDifferenceAttention(self): """ Show/hide difference attention icon(WOTD-68988). Two or more different tanks have difference crew or modules -> show icon, otherwise - hide """ vehiclesCount = self.comparisonBasket.getVehiclesCount() show = False if vehiclesCount > 1 and len(set(self.comparisonBasket.getVehiclesCDs())) > 1: show = True comparisonDataIter = self.comparisonBasket.getVehiclesPropertiesIter(lambda vehCmpData: (vehCmpData.getModulesType(), vehCmpData.getCrewLevel())) prevModuleType, prevCrewLevel = next(comparisonDataIter) for moduleType, crewLevel in comparisonDataIter: if prevModuleType != moduleType or prevCrewLevel != crewLevel: break prevModuleType, prevCrewLevel = moduleType, crewLevel else: show = False self.as_setAttentionVisibleS(show) def __onVehicleParamsChanged(self, _): self.__updateDifferenceAttention()