mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 06:43:24 +00:00
Add tooltips for blueprints
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
* Reset old modification values when a new roll is applied
|
* Reset old modification values when a new roll is applied
|
||||||
* 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
|
||||||
|
|
||||||
#2.2.19
|
#2.2.19
|
||||||
* Power management panel now displays modules in descending order of power usage by default
|
* Power management panel now displays modules in descending order of power usage by default
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
*/
|
*/
|
||||||
_initState(props, context) {
|
_initState(props, context) {
|
||||||
let { m } = props;
|
let { m } = props;
|
||||||
const { language } = context;
|
const { language, tooltip, termtip } = context;
|
||||||
const translate = language.translate;
|
const translate = language.translate;
|
||||||
|
|
||||||
// Set up the blueprints
|
// Set up the blueprints
|
||||||
@@ -52,7 +52,8 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
for (const grade of Modifications.modules[m.grp].blueprints[blueprintName]) {
|
for (const grade of Modifications.modules[m.grp].blueprints[blueprintName]) {
|
||||||
const close = this._blueprintSelected.bind(this, Modifications.blueprints[blueprintName].id, grade);
|
const close = this._blueprintSelected.bind(this, Modifications.blueprints[blueprintName].id, grade);
|
||||||
const key = blueprintName + ':' + grade;
|
const key = blueprintName + ':' + grade;
|
||||||
blueprints.push(<div style={{ cursor: 'pointer' }} key={ key } onClick={ close }>{translate(Modifications.blueprints[blueprintName].name + ' grade ' + grade)}</div>);
|
const tooltipContent = this._blueprintTooltip(translate, Modifications.blueprints[blueprintName].grades[grade].features);
|
||||||
|
blueprints.push(<div style={{ cursor: 'pointer' }} key={ key } onMouseOver={termtip.bind(null, tooltipContent)} onMouseOut={tooltip.bind(null, null)} onClick={ close }>{translate(Modifications.blueprints[blueprintName].name + ' grade ' + grade)}</div>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +77,51 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
return { blueprintMenuOpened, blueprints, modifications, specialMenuOpened, specials };
|
return { blueprintMenuOpened, blueprints, modifications, specialMenuOpened, specials };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a tooltip with details of a blueprint's effects
|
||||||
|
* @param {Object} features The features of the blueprint
|
||||||
|
* @returns {Object} The react components
|
||||||
|
*/
|
||||||
|
_blueprintTooltip(translate, features)
|
||||||
|
{
|
||||||
|
const results = [];
|
||||||
|
for (const feature in features) {
|
||||||
|
const featureIsBeneficial = this._isBeneficial(feature, features[feature]);
|
||||||
|
const featureDef = Modifications.modifications[feature];
|
||||||
|
if (!featureDef.hidden) {
|
||||||
|
let symbol = '';
|
||||||
|
if (feature === 'jitter') {
|
||||||
|
symbol = '°';
|
||||||
|
} else if (featureDef.type === 'percentage') {
|
||||||
|
symbol = '%';
|
||||||
|
}
|
||||||
|
let lowerBound = features[feature][0];
|
||||||
|
let upperBound = features[feature][1];
|
||||||
|
if (featureDef.type === 'percentage') {
|
||||||
|
lowerBound = Math.round(lowerBound * 1000) / 10;
|
||||||
|
upperBound = Math.round(upperBound * 1000) / 10;
|
||||||
|
}
|
||||||
|
const range = `${lowerBound}${symbol} - ${upperBound}${symbol}`;
|
||||||
|
results.push(<tr key={feature} className={featureIsBeneficial ? 'secondary' : 'warning'}><td style={{ textAlign: 'left' }}>{translate(feature)}</td><td style={{ textAlign: 'right' }}>{lowerBound}{symbol}</td><td style={{ textAlign: 'right' }}>{upperBound}{symbol}</td></tr>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>{translate('effect')}</td>
|
||||||
|
<td>{translate('worst')}</td>
|
||||||
|
<td>{translate('best')}</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{results}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the modifications
|
* Initialise the modifications
|
||||||
* @param {Object} props React Component properties
|
* @param {Object} props React Component properties
|
||||||
@@ -244,6 +290,19 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
this.props.onChange();
|
this.props.onChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this feature beneficial?
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
_isBeneficial(feature, values) {
|
||||||
|
const fact = (values[0] < 0 || (values[0] === 0 && values[1] < 0));
|
||||||
|
if (Modifications.modifications[feature].higherbetter) {
|
||||||
|
return !fact;
|
||||||
|
} else {
|
||||||
|
return fact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset modification information
|
* Reset modification information
|
||||||
*/
|
*/
|
||||||
@@ -276,11 +335,11 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
|
|
||||||
let blueprintLabel;
|
let blueprintLabel;
|
||||||
let haveBlueprint = false;
|
let haveBlueprint = false;
|
||||||
|
let blueprintTooltip;
|
||||||
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;
|
||||||
} else {
|
blueprintTooltip = this._blueprintTooltip(translate, m.blueprint.grades[m.blueprint.grade].features);
|
||||||
blueprintLabel = translate('PHRASE_SELECT_BLUEPRINT');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let specialLabel;
|
let specialLabel;
|
||||||
@@ -291,7 +350,7 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const showBlueprintsMenu = blueprintMenuOpened;
|
const showBlueprintsMenu = blueprintMenuOpened;
|
||||||
const showSpecial = haveBlueprint && this.state.specials.length > 0;
|
const showSpecial = haveBlueprint && this.state.specials.length > 0 && !blueprintMenuOpened;
|
||||||
const showSpecialsMenu = specialMenuOpened;
|
const showSpecialsMenu = specialMenuOpened;
|
||||||
const showRolls = haveBlueprint && !blueprintMenuOpened && !specialMenuOpened;
|
const showRolls = haveBlueprint && !blueprintMenuOpened && !specialMenuOpened;
|
||||||
const showReset = !blueprintMenuOpened && !specialMenuOpened;
|
const showReset = !blueprintMenuOpened && !specialMenuOpened;
|
||||||
@@ -303,7 +362,10 @@ export default class ModificationsMenu extends TranslatedComponent {
|
|||||||
onClick={(e) => e.stopPropagation() }
|
onClick={(e) => e.stopPropagation() }
|
||||||
onContextMenu={stopCtxPropagation}
|
onContextMenu={stopCtxPropagation}
|
||||||
>
|
>
|
||||||
<div className={ cn('section-menu', { selected: blueprintMenuOpened })} style={{ cursor: 'pointer' }} onClick={_toggleBlueprintsMenu}>{blueprintLabel}</div>
|
{ haveBlueprint ?
|
||||||
|
<div className={ cn('section-menu', { selected: blueprintMenuOpened })} style={{ cursor: 'pointer' }} onMouseOver={termtip.bind(null, blueprintTooltip)} onMouseOut={tooltip.bind(null, null)} onClick={_toggleBlueprintsMenu}>{blueprintLabel}</div>
|
||||||
|
:
|
||||||
|
<div className={ cn('section-menu', { selected: blueprintMenuOpened })} style={{ cursor: 'pointer' }} onClick={_toggleBlueprintsMenu}>{translate('PHRASE_SELECT_BLUEPRINT')}</div> }
|
||||||
{ showBlueprintsMenu ? this.state.blueprints : null }
|
{ showBlueprintsMenu ? this.state.blueprints : null }
|
||||||
{ showSpecial ? <div className={ cn('section-menu', { selected: specialMenuOpened })} style={{ cursor: 'pointer' }} onClick={_toggleSpecialsMenu}>{specialLabel}</div> : null }
|
{ showSpecial ? <div className={ cn('section-menu', { selected: specialMenuOpened })} style={{ cursor: 'pointer' }} onClick={_toggleSpecialsMenu}>{specialLabel}</div> : null }
|
||||||
{ showSpecialsMenu ? this.state.specials : null }
|
{ showSpecialsMenu ? this.state.specials : null }
|
||||||
|
|||||||
Reference in New Issue
Block a user