import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import Persist from '../stores/Persist'; import TranslatedComponent from './TranslatedComponent'; import { diffDetails } from '../utils/SlotFunctions'; import AvailableModulesMenu from './AvailableModulesMenu'; import ModificationsMenu from './ModificationsMenu'; import * as ModuleUtils from '../shipyard/ModuleUtils'; import { ListModifications, Modified } from './SvgIcons'; import { Modifications } from 'coriolis-data/dist'; import { stopCtxPropagation } from '../utils/UtilityFunctions'; import { blueprintTooltip } from '../utils/BlueprintFunctions'; /** * Standard Slot */ export default class StandardSlot extends TranslatedComponent { static propTypes = { slot: PropTypes.object, modules: PropTypes.array.isRequired, onSelect: PropTypes.func.isRequired, onOpen: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, ship: PropTypes.object.isRequired, selected: PropTypes.bool, warning: PropTypes.func, }; /** * Construct the slot * @param {object} props Object properties */ constructor(props) { super(props); this._modificationsSelected = false; this._keyDown = this._keyDown.bind(this); this.modButton = null; this.slotDiv = null; } /** * Handle Enter key * @param {SyntheticEvent} event KeyDown event */ _keyDown(event) { if (event.key == 'Enter') { if(event.target.className == 'r') { this._toggleModifications(); } this.props.onOpen(event); } } /** * Render the slot * @return {React.Component} Slot component */ render() { let { termtip, tooltip } = this.context; let { translate, formats, units } = this.context.language; let { modules, slot, selected, warning, onSelect, onChange, ship } = this.props; let m = slot.m; let classRating = m.class + m.rating; let menu; let validMods = m == null || !Modifications.modules[m.grp] ? [] : (Modifications.modules[m.grp].modifications || []); if (m && m.name && m.name === 'Guardian Hybrid Power Plant') { validMods = []; } if (m && m.name && m.name === 'Guardian Power Distributor') { validMods = []; } let showModuleResistances = Persist.showModuleResistances(); let mass = m.getMass() || m.cargo || m.fuel || 0; // Modifications tooltip shows blueprint and grade, if available let modTT = translate('modified'); if (m && m.blueprint && m.blueprint.name) { modTT = translate(m.blueprint.name) + ' ' + translate('grade') + ' ' + m.blueprint.grade; if (m.blueprint.special && m.blueprint.special.id >= 0) { modTT += ', ' + translate(m.blueprint.special.name); } modTT = (