import React from 'react'; import SlotSection from './SlotSection'; import HardpointSlot from './HardpointSlot'; import { MountFixed, MountGimballed, MountTurret } from '../components/SvgIcons'; import { stopCtxPropagation } from '../utils/UtilityFunctions'; /** * Hardpoint slot section */ export default class HardpointSlotSection extends SlotSection { /** * Constructor * @param {Object} props React Component properties * @param {Object} context React Component context */ constructor(props, context) { super(props, context, 'hardpoints', 'hardpoints'); this._empty = this._empty.bind(this); this.selectedRefId = null; this.firstRefId = 'emptyall'; this.lastRefId = 'nl-F'; } /** * Handle focus when component updates * @param {Object} prevProps React Component properties */ componentDidUpdate(prevProps) { this._handleSectionFocus(prevProps,this.firstRefId, this.lastRefId); } /** * Empty all slots */ _empty() { this.selectedRefId = 'emptyall'; this.props.ship.emptyWeapons(); this.props.onChange(); this._close(); } /** * Fill slots with specified module * @param {string} group Group name * @param {string} mount Mount Type - F, G, T * @param {SyntheticEvent} event Event */ _fill(group, mount, event) { this.selectedRefId = group + '-' + mount; this.props.ship.useWeapon(group, mount, null, event.getModifierState('Alt')); this.props.onChange(); this._close(); } /** * Empty all on section header right click */ _contextMenu() { this._empty(); } /** * Generate the slot React Components * @return {Array} Array of Slots */ _getSlots() { let { ship, currentMenu } = this.props; let { originSlot, targetSlot } = this.state; let slots = []; let hardpoints = ship.hardpoints; let availableModules = ship.getAvailableModules(); for (let i = 0, l = hardpoints.length; i < l; i++) { let h = hardpoints[i]; if (h.maxClass) { slots.push( availableModules.getHps(h.maxClass)} onOpen={this._openMenu.bind(this, h)} onSelect={this._selectModule.bind(this, h)} onChange={this.props.onChange} selected={currentMenu == h} drag={this._drag.bind(this, h)} dragOver={this._dragOverSlot.bind(this, h)} drop={this._drop} dropClass={this._dropClass(h, originSlot, targetSlot)} ship={ship} m={h.m} enabled={h.enabled ? true : false} />); } } return slots; } /** * Generate the section drop-down menu * @param {Function} translate Translate function * @return {React.Component} Section menu */ _getSectionMenu(translate) { let _fill = this._fill; return
e.stopPropagation()} onContextMenu={stopCtxPropagation}>
{translate('pl')}
{translate('ul')}
{translate('bl')}
{translate('mc')}
{translate('c')}
{translate('fc')}
{translate('pa')}
{translate('rg')}
{translate('nl')}
{translate('rfl')}
; } }