def _getBonuses(self): result = [] bonuses = sorted(self._extendedData.bonuses, cmp=_bonusCmp) item = self.context.buildItem() bonusExtractor = bonus_helper.BonusExtractor(item, bonuses, self.__paramName) hasSituational = False for bnsType, bnsId, pInfo in bonusExtractor.getBonusInfo(): isSituational = isSituationalBonus(bnsId) scheme = SITUATIONAL_SCHEME if isSituational else EXTRACTED_BONUS_SCHEME valueStr = param_formatter.formatParameterDelta(pInfo, scheme) if valueStr is not None: hasSituational = hasSituational or isSituational bonusName = _packBonusName(bnsType, bnsId) if isSituational: icon = icons.makeImageTag(RES_ICONS.MAPS_ICONS_TOOLTIP_ASTERISK_OPTIONAL, 16, 16, 0, 2) bonusName = param_formatter.packSituationalIcon(bonusName, icon) titlePadding = formatters.packPadding(left=8, top=-2) else: titlePadding = self.__titlePadding result.append(self.__packBonusField(bnsId, bonusName, value=_ms(TOOLTIPS.VEHICLEPARAMS_TITLE_VALUETEMPLATE, value=valueStr), padding=titlePadding)) possibleBonuses = sorted(self._extendedData.possibleBonuses, cmp=_bonusCmp) inactiveBonuses = self._extendedData.inactiveBonuses for bnsId, bnsType in possibleBonuses: isInactive = (bnsId, bnsType) in inactiveBonuses result.append(self.__packBonusField(bnsId, _packBonusName(bnsType, bnsId, enabled=False, inactive=isInactive), isDisabled=True)) return (result, hasSituational)
def getDeltaParams(self, paramName, paramValue): params = self.getParams() if paramName in params: pInfo = getParamExtendedData(paramName, params[paramName], paramValue) return formatters.formatParameterDelta(pInfo, _DELTA_PARAM_COLOR_SCHEME, _CMP_FORMAT_SETTINGS)
def getDeltaParams(self, paramName, paramValue): """ Calculates delta and return it in formatted HTML string :param paramName: parameter name as string ('damage', 'turretArmor', etc...) :param paramValue: parameter value :return: formatted HTML string """ params = self.getParams() if paramName in params: pInfo = getParamExtendedData(paramName, params[paramName], paramValue) return formatters.formatParameterDelta(pInfo, _DELTA_PARAM_COLOR_SCHEME, _CMP_FORMAT_SETTINGS)
def _formatParameters(paramType, paramName, moduleData, comparator): fmtValue = None if paramType == ParamTypes.CONST: paramVal = moduleData.constParams[paramName] fmtValue = _makeTxtForBetter(paramVal) else: paramInfo = comparator.getExtendedData(paramName) if paramType == ParamTypes.SIMPLE: fmtValue = params_formatters.formatParameter( paramName, paramInfo.value, paramInfo.state, _DELTA_SCHEME, _CMP_FORMAT_SETTINGS) elif paramType == ParamTypes.DELTA: fmtValue = params_formatters.formatParameterDelta( paramInfo, _DELTA_SCHEME, _CMP_FORMAT_DELTA_SETTINGS) return { 'value': str(fmtValue), 'description': _formatModuleParamName(paramName) } if fmtValue is not None else None
def getModuleParameters(module, vehicle, currentModule=None): moduleDescr = _getModuleDescr(module, vehicle) currModule = currentModule if currentModule is not None else _getCurrentModule( moduleDescr) comparator = _itemsComparator(moduleDescr.typeCD, moduleDescr.moduleParams, currModule, moduleDescr.vDescr) params = [] params.extend(getExtendedParameters(currModule, module, vehicle)) moduleData = getTreeModuleSettings(module) deltaParamsList = moduleData.deltaParams if moduleData is not None else tuple( ) for paramName in deltaParamsList: if paramName in moduleDescr.moduleParams: paramInfo = comparator.getExtendedData(paramName) fmtValue = params_formatters.formatParameterDelta( paramInfo, _DELTA_SCHEME, _CMP_FORMAT_DELTA_SETTINGS) if fmtValue is not None: params.append({ 'value': str(fmtValue), 'description': _formatModuleParamName(paramName) }) paramsList = moduleData.params if moduleData is not None else [] for paramName in paramsList: if paramName in moduleDescr.moduleParams: paramInfo = comparator.getExtendedData(paramName) fmtValue = params_formatters.formatParameter( paramName, paramInfo.value, paramInfo.state, _DELTA_SCHEME, _CMP_FORMAT_SETTINGS) if fmtValue is not None: params.append({ 'value': str(fmtValue), 'description': _formatModuleParamName(paramName) }) paramsDict = moduleData.constParams if moduleData else {} for paramName, paramVal in paramsDict.iteritems(): fmtValue = _makeTxtForBetter(paramVal) params.append({ 'value': str(fmtValue), 'description': _formatModuleParamName(paramName) }) return params