From 71ddbdfe75350b7d72413156e8b9c3688b1c0a89 Mon Sep 17 00:00:00 2001 From: willyb321 Date: Mon, 23 Apr 2018 14:51:45 +1000 Subject: [PATCH] add specials tooltip --- src/app/components/ModificationsMenu.jsx | 31 ++++++++++-- src/app/utils/BlueprintFunctions.js | 64 ++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/src/app/components/ModificationsMenu.jsx b/src/app/components/ModificationsMenu.jsx index 29a85f67..e5ee6616 100644 --- a/src/app/components/ModificationsMenu.jsx +++ b/src/app/components/ModificationsMenu.jsx @@ -6,7 +6,14 @@ import { isEmpty, stopCtxPropagation } from '../utils/UtilityFunctions'; import cn from 'classnames'; import { Modifications } from 'coriolis-data/dist'; import Modification from './Modification'; -import { getBlueprint, blueprintTooltip, setPercent, getPercent, setRandom } from '../utils/BlueprintFunctions'; +import { + getBlueprint, + blueprintTooltip, + setPercent, + getPercent, + setRandom, + specialToolTip +} from '../utils/BlueprintFunctions' /** * Modifications menu @@ -86,7 +93,6 @@ export default class ModificationsMenu extends TranslatedComponent { const { m } = props; const { language, tooltip, termtip } = context; const translate = language.translate; - const specials = []; const specialsId = m.missile && Modifications.modules[m.grp]['specials_' + m.missile] ? 'specials_' + m.missile : 'specials'; if (Modifications.modules[m.grp][specialsId] && Modifications.modules[m.grp][specialsId].length > 0) { @@ -100,7 +106,20 @@ export default class ModificationsMenu extends TranslatedComponent { active: m.blueprint && m.blueprint.special && m.blueprint.special.edname == specialName }); const close = this._specialSelected.bind(this, specialName); - specials.push(
{translate(Modifications.specials[specialName].name)}
); + if (m.blueprint && m.blueprint.name) { + let tmp = {}; + if (m.blueprint.special) { + tmp = m.blueprint.special; + } else { + tmp = undefined; + } + m.blueprint.special = Modifications.specials[specialName]; + let specialTt = specialToolTip(translate, m.blueprint.grades[m.blueprint.grade], m.grp, m, specialName); + m.blueprint.special = tmp; + specials.push(
{translate(Modifications.specials[specialName].name)}
); + } else { + specials.push(
{translate(Modifications.specials[specialName].name)}
); + } } } return specials; @@ -251,8 +270,10 @@ export default class ModificationsMenu extends TranslatedComponent { } let specialLabel; + let specialTt; if (m.blueprint && m.blueprint.special) { specialLabel = m.blueprint.special.name; + specialTt = specialToolTip(translate, m.blueprint.grades[m.blueprint.grade], m.grp, m, m.blueprint.special.edname); } else { specialLabel = translate('PHRASE_SELECT_SPECIAL'); } @@ -276,7 +297,7 @@ export default class ModificationsMenu extends TranslatedComponent {
{blueprintLabel}
:
{translate('PHRASE_SELECT_BLUEPRINT')}
} { showBlueprintsMenu ? this._renderBlueprints(this.props, this.context) : null } - { showSpecial & !showSpecialsMenu ?
{specialLabel}
: null } + { showSpecial & !showSpecialsMenu ?
{specialLabel}
: null } { showSpecialsMenu ? specials : null } { showReset ?
{ translate('reset') }
: null } { showRolls ? @@ -285,7 +306,7 @@ export default class ModificationsMenu extends TranslatedComponent { { showRolls ? - { translate('roll') }: + { translate('roll') }: { translate('0%') } { translate('50%') } { translate('100%') } diff --git a/src/app/utils/BlueprintFunctions.js b/src/app/utils/BlueprintFunctions.js index 2367570b..996b796e 100644 --- a/src/app/utils/BlueprintFunctions.js +++ b/src/app/utils/BlueprintFunctions.js @@ -1,6 +1,70 @@ import React from 'react'; import { Modifications } from 'coriolis-data/dist'; +/** + * Generate a tooltip with details of a blueprint's specials + * @param {Object} translate The translate object + * @param {Object} blueprint The blueprint at the required grade + * @param {string} grp The group of the module + * @param {Object} m The module to compare with + * @param specialName + * @returns {Object} The react components + */ +export function specialToolTip(translate, blueprint, grp, m, specialName) { + const effects = []; + console.log(blueprint) + if (!blueprint || !blueprint.features) { + console.log('nah') + return undefined; + } + if (m) { + // We also add in any benefits from specials that aren't covered above + if (m.blueprint) { + for (const feature in Modifications.modifierActions[specialName]) { + // if (!blueprint.features[feature] && !m.mods.feature) { + const featureDef = Modifications.modifications[feature]; + if (featureDef && !featureDef.hidden) { + let symbol = ''; + if (feature === 'jitter') { + symbol = '°'; + } else if (featureDef.type === 'percentage') { + symbol = '%'; + } + const modifierActions = Modifications.modifierActions[specialName]; + let current = m.getModValue(feature) - m.getModValue(feature, true); + if (featureDef.type === 'percentage') { + current = Math.round(current / 10) / 10; + } else if (featureDef.type === 'numeric') { + current /= 100; + } + const currentIsBeneficial = isValueBeneficial(feature, current); + + effects.push( + + {translate(feature, grp)} +   + {current}{symbol} +   + + ); + } + } + + } + } + + return ( +
+ + + {effects} + +
+
+ ); +} + /** * Generate a tooltip with details of a blueprint's effects * @param {Object} translate The translate object