Add engineer info to blueprint tooltip

This commit is contained in:
Cmdr McDonald
2017-03-27 10:17:30 +01:00
parent 8a115f8323
commit b66baef998
7 changed files with 98 additions and 42 deletions

View File

@@ -9,7 +9,7 @@
* Fix issue with miner role where refinery would not be present in ships with class 5 slots but no class 4 * Fix issue with miner role where refinery would not be present in ships with class 5 slots but no class 4
* Ensure that boost value is set correctly when modifications to power distributor enable/disable boost * Ensure that boost value is set correctly when modifications to power distributor enable/disable boost
* Ensure that hull reinforcement modifications take the inherent resistance in to account when calculating modification percentages * Ensure that hull reinforcement modifications take the inherent resistance in to account when calculating modification percentages
* Add tooltip for blueprints providing details of the features they alter * Add tooltip for blueprints providing details of the features they alter, the components required for the blueprint and the engineer(s) who cam craft them
* Use opponent's saved pips if available * Use opponent's saved pips if available
* Ignore rounds per shot for EPS and HPS calculations; it's already factored in to the numbers * Ignore rounds per shot for EPS and HPS calculations; it's already factored in to the numbers
* Ensure that clip size modification imports result in whole numbers * Ensure that clip size modification imports result in whole numbers

View File

@@ -55,7 +55,7 @@ export default class HardpointSlot extends Slot {
modTT = ( modTT = (
<div> <div>
<div>{modTT}</div> <div>{modTT}</div>
{blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], m)} {blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], null, m)}
</div> </div>
); );
} }

View File

@@ -34,7 +34,7 @@ export default class InternalSlot extends Slot {
modTT = ( modTT = (
<div> <div>
<div>{modTT}</div> <div>{modTT}</div>
{blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], m)} {blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], null, m)}
</div> </div>
); );
} }

View File

@@ -50,11 +50,11 @@ export default class ModificationsMenu extends TranslatedComponent {
// Set up the blueprints // Set up the blueprints
let blueprints = []; let blueprints = [];
for (const blueprintName in Modifications.modules[m.grp].blueprints) { for (const blueprintName in Modifications.modules[m.grp].blueprints) {
for (const grade of Modifications.modules[m.grp].blueprints[blueprintName]) { for (const grade in Modifications.modules[m.grp].blueprints[blueprintName].grades) {
const close = this._blueprintSelected.bind(this, blueprintName, grade); const close = this._blueprintSelected.bind(this, blueprintName, grade);
const key = blueprintName + ':' + grade; const key = blueprintName + ':' + grade;
const blueprint = getBlueprint(blueprintName, m); const blueprint = getBlueprint(blueprintName, m);
const tooltipContent = blueprintTooltip(translate, blueprint.grades[grade]); const tooltipContent = blueprintTooltip(translate, blueprint.grades[grade], Modifications.modules[m.grp].blueprints[blueprintName].grades[grade].engineers);
blueprints.push(<div style={{ cursor: 'pointer' }} key={ key } onMouseOver={termtip.bind(null, tooltipContent)} onMouseOut={tooltip.bind(null, null)} onClick={ close }>{translate(blueprint.name + ' grade ' + grade)}</div>); blueprints.push(<div style={{ cursor: 'pointer' }} key={ key } onMouseOver={termtip.bind(null, tooltipContent)} onMouseOut={tooltip.bind(null, null)} onClick={ close }>{translate(blueprint.name + ' grade ' + grade)}</div>);
} }
} }
@@ -279,7 +279,7 @@ export default class ModificationsMenu extends TranslatedComponent {
if (m.blueprint && !isEmpty(m.blueprint)) { if (m.blueprint && !isEmpty(m.blueprint)) {
blueprintLabel = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; blueprintLabel = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade;
haveBlueprint = true; haveBlueprint = true;
blueprintTt = blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade]); blueprintTt = blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], Modifications.modules[m.grp].blueprints[m.blueprint.fdname].grades[m.blueprint.grade].engineers);
} }
let specialLabel; let specialLabel;

View File

@@ -57,7 +57,7 @@ export default class StandardSlot extends TranslatedComponent {
modTT = ( modTT = (
<div> <div>
<div>{modTT}</div> <div>{modTT}</div>
{blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], m)} {blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade], null, m)}
</div> </div>
); );
} }

View File

@@ -5,10 +5,11 @@ import { Modifications } from 'coriolis-data/dist';
* Generate a tooltip with details of a blueprint's effects * Generate a tooltip with details of a blueprint's effects
* @param {Object} translate The translate object * @param {Object} translate The translate object
* @param {Object} blueprint The blueprint at the required grade * @param {Object} blueprint The blueprint at the required grade
* @param {Array} engineers The engineers supplying this blueprint
* @param {Object} m The module to compare with * @param {Object} m The module to compare with
* @returns {Object} The react components * @returns {Object} The react components
*/ */
export function blueprintTooltip(translate, blueprint, m) { export function blueprintTooltip(translate, blueprint, engineers, m) {
const effects = []; const effects = [];
for (const feature in blueprint.features) { for (const feature in blueprint.features) {
const featureIsBeneficial = isBeneficial(feature, blueprint.features[feature]); const featureIsBeneficial = isBeneficial(feature, blueprint.features[feature]);
@@ -33,7 +34,9 @@ export function blueprintTooltip(translate, blueprint, m) {
let current = m.getModValue(feature); let current = m.getModValue(feature);
if (featureDef.type === 'percentage' || featureDef.name === 'burst' || featureDef.name === 'burstrof') { if (featureDef.type === 'percentage' || featureDef.name === 'burst' || featureDef.name === 'burstrof') {
current = Math.round(current / 10) / 10; current = Math.round(current / 10) / 10;
} } else if (featureDef.type === 'numeric') {
current /= 100;
}
const currentIsBeneficial = isValueBeneficial(feature, current); const currentIsBeneficial = isValueBeneficial(feature, current);
effects.push( effects.push(
<tr key={feature}> <tr key={feature}>
@@ -55,43 +58,96 @@ export function blueprintTooltip(translate, blueprint, m) {
} }
} }
} }
if (m) {
// Because we have a module add in any benefits that aren't part of the primary blueprint
for (const feature in m.mods) {
if (!blueprint.features[feature]) {
const featureDef = Modifications.modifications[feature];
let symbol = '';
if (feature === 'jitter') {
symbol = '°';
} else if (featureDef.type === 'percentage') {
symbol = '%';
}
let current = m.getModValue(feature);
if (featureDef.type === 'percentage' || featureDef.name === 'burst' || featureDef.name === 'burstrof') {
current = Math.round(current / 10) / 10;
} else if (featureDef.type === 'numeric') {
current /= 100;
}
const currentIsBeneficial = isValueBeneficial(feature, current);
effects.push(
<tr key={feature}>
<td style={{ textAlign: 'left' }}>{translate(feature)}</td>
<td>&nbsp;</td>
<td className={current === 0 ? '' : currentIsBeneficial ? 'secondary' : 'warning'} style={{ textAlign: 'right' }}>{current}{symbol}</td>
<td>&nbsp;</td>
</tr>
);
}
}
}
let components;
if (!m) {
components = [];
for (const component in blueprint.components) {
components.push(
<tr key={component}>
<td style={{ textAlign: 'left' }}>{translate(component)}</td>
<td style={{ textAlign: 'right' }}>{blueprint.components[component]}</td>
</tr>
);
}
}
const components = []; let engineersList;
for (const component in blueprint.components) { if (engineers) {
components.push( engineersList = [];
<tr key={component}> for (const engineer of engineers) {
<td style={{ textAlign: 'left' }}>{translate(component)}</td> engineersList.push(
<td style={{ textAlign: 'right' }}>{blueprint.components[component]}</td> <tr key={engineer}>
</tr> <td style={{ textAlign: 'left' }}>{engineer}</td>
); </tr>
);
}
} }
return ( return (
<div> <div>
<table width='100%'> <table width='100%'>
<thead> <thead>
<tr> <tr>
<td>{translate('feature')}</td> <td>{translate('feature')}</td>
<td>{translate('worst')}</td> <td>{translate('worst')}</td>
{m ? <td>{translate('current')}</td> : null } {m ? <td>{translate('current')}</td> : null }
<td>{translate('best')}</td> <td>{translate('best')}</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{effects} {effects}
</tbody> </tbody>
</table> </table>
{ m ? null : <table width='100%'> { components ? <table width='100%'>
<thead> <thead>
<tr> <tr>
<td>{translate('component')}</td> <td>{translate('component')}</td>
<td>{translate('amount')}</td> <td>{translate('amount')}</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{components} {components}
</tbody> </tbody>
</table> } </table> : null }
{ engineersList ? <table width='100%'>
<thead>
<tr>
<td>{translate('engineers')}</td>
</tr>
</thead>
<tbody>
{engineersList}
</tbody>
</table> : null }
</div> </div>
); );
} }

View File

@@ -243,7 +243,7 @@ export function diffDetails(language, m, mm) {
} }
} }
let mIntegrity = m.integrity; let mIntegrity = m.integrity || 0;
let mmIntegrity = mm ? mm.getIntegrity() || 0 : 0; let mmIntegrity = mm ? mm.getIntegrity() || 0 : 0;
if (mIntegrity != mmIntegrity) { if (mIntegrity != mmIntegrity) {
propDiffs.push(<div key='integrity'>{translate('integrity')}: <span className={diffClass(mmIntegrity, mIntegrity, true)}>{diff(formats.round, mIntegrity, mmIntegrity)}</span></div>); propDiffs.push(<div key='integrity'>{translate('integrity')}: <span className={diffClass(mmIntegrity, mIntegrity, true)}>{diff(formats.round, mIntegrity, mmIntegrity)}</span></div>);