Search in sources :

Example 6 with MiscType

use of megamek.common.MiscType in project megameklab by MegaMek.

the class AerospaceBuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    // locations, but only if those locations are make sense
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item = null;
        if (equipmentTable.getSelectedRowCount() > 1) {
            List<Mounted> list = new ArrayList<>();
            for (int row : equipmentTable.getSelectedRows()) {
                list.add((Mounted) equipmentTable.getModel().getValueAt(row, CriticalTableModel.EQUIPMENT));
            }
            for (BayWeaponCriticalTree l : arcViews) {
                // Aerodyne small craft and dropships skip the aft side arcs
                if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
                    continue;
                }
                if (list.stream().anyMatch(eq -> l.canAdd(eq))) {
                    item = new JMenuItem(l.getLocationName());
                    item.addActionListener(ev -> l.addToLocation(list));
                    popup.add(item);
                }
            }
        } else {
            final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
            Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
            for (BayWeaponCriticalTree l : arcViews) {
                // Aerodyne small craft and dropships skip the aft side arcs
                if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
                    continue;
                }
                if (getAero().usesWeaponBays()) {
                    JMenu menu = new JMenu(l.getLocationName());
                    for (Mounted bay : l.baysFor(eq)) {
                        if (eq.getType() instanceof AmmoType) {
                            final int shotCount = ((AmmoType) eq.getType()).getShots();
                            JMenu locMenu = new JMenu(bay.getName());
                            for (int shots = shotCount; shots <= eq.getUsableShotsLeft(); shots += shotCount) {
                                item = new JMenuItem("Add " + shots + ((shots > 1) ? " shots" : " shot"));
                                final int addShots = shots;
                                item.addActionListener(ev -> l.addAmmoToBay(bay, eq, addShots));
                                locMenu.add(item);
                            }
                            menu.add(locMenu);
                        } else {
                            item = new JMenuItem(bay.getName());
                            item.addActionListener(ev -> l.addToBay(bay, eq));
                            menu.add(item);
                        }
                    }
                    if (eq.getType() instanceof WeaponType) {
                        final EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
                        item = new JMenuItem("New " + bayType.getName());
                        item.addActionListener(ev -> l.addToNewBay(bayType, eq));
                        menu.add(item);
                    }
                    if (menu.getItemCount() > 0) {
                        popup.add(menu);
                    } else if ((eq.getType() instanceof MiscType) && l.canAdd(eq)) {
                        item = new JMenuItem(l.getLocationName());
                        item.addActionListener(ev -> l.addToLocation(eq));
                        popup.add(item);
                    }
                } else {
                    item = new JMenuItem(l.getLocationName());
                    item.addActionListener(ev -> l.addToLocation(eq));
                    popup.add(item);
                }
            }
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ListSelectionModel(javax.swing.ListSelectionModel) Weapon(megamek.common.weapons.Weapon) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) JMenuItem(javax.swing.JMenuItem) TitledBorder(javax.swing.border.TitledBorder) Mounted(megamek.common.Mounted) StringUtils(megameklab.com.util.StringUtils) BorderLayout(java.awt.BorderLayout) MouseListener(java.awt.event.MouseListener) AmmoType(megamek.common.AmmoType) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) AeroBayTransferHandler(megameklab.com.ui.util.AeroBayTransferHandler) JMenu(javax.swing.JMenu) IView(megameklab.com.util.IView) BorderFactory(javax.swing.BorderFactory) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) WeaponType(megamek.common.WeaponType) CriticalTableModel(megameklab.com.util.CriticalTableModel) MiscType(megamek.common.MiscType) JTable(javax.swing.JTable) Collections(java.util.Collections) Entity(megamek.common.Entity) BayWeaponCriticalTree(megameklab.com.ui.util.BayWeaponCriticalTree) RefreshListener(megameklab.com.util.RefreshListener) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BayWeaponCriticalTree(megameklab.com.ui.util.BayWeaponCriticalTree) EquipmentType(megamek.common.EquipmentType) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 7 with MiscType

use of megamek.common.MiscType in project megameklab by MegaMek.

the class EquipmentTab method removeHeatSinks.

private void removeHeatSinks() {
    int location = 0;
    for (; location < equipmentList.getRowCount(); ) {
        Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
        EquipmentType eq = mount.getType();
        if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
            try {
                equipmentList.removeCrit(location);
            } catch (ArrayIndexOutOfBoundsException aioobe) {
                return;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            location++;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType) LocationFullException(megamek.common.LocationFullException)

Example 8 with MiscType

use of megamek.common.MiscType in project megameklab by MegaMek.

the class BuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item;
        final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
        Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
        final int totalCrits = UnitUtil.getCritsUsed(getMech(), eq.getType());
        String[] locations = getMech().getLocationNames();
        String[] abbrLocations = getMech().getLocationAbbrs();
        if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getMech() instanceof LandAirMech)) {
            int[] critSpace = UnitUtil.getHighestContinuousNumberOfCritsArray(getMech());
            if ((critSpace[Mech.LOC_RT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RT)) {
                JMenu rtMenu = new JMenu(locations[Mech.LOC_RT]);
                if (critSpace[Mech.LOC_RT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_RT, selectedRow);
                        }
                    });
                    rtMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_RARM, Mech.LOC_RLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_RT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_RT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    rtMenu.add(subMenu);
                }
                popup.add(rtMenu);
            }
            if ((critSpace[Mech.LOC_RARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RARM, Mech.LOC_RARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
            if ((critSpace[Mech.LOC_LT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LT)) {
                JMenu ltMenu = new JMenu(locations[Mech.LOC_LT]);
                if (critSpace[Mech.LOC_LT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_LT, selectedRow);
                        }
                    });
                    ltMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_LARM, Mech.LOC_LLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_LT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_LT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    ltMenu.add(subMenu);
                }
                popup.add(ltMenu);
            }
            if ((critSpace[Mech.LOC_LARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LARM, Mech.LOC_LARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
        } else {
            for (int location = 0; location < getMech().locations(); location++) {
                if ((UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location) >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), location)) {
                    item = new JMenuItem("Add to " + locations[location]);
                    final int loc = location;
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(loc, selectedRow);
                        }
                    });
                    popup.add(item);
                }
            }
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) ActionEvent(java.awt.event.ActionEvent) MiscType(megamek.common.MiscType) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) LandAirMech(megamek.common.LandAirMech)

Example 9 with MiscType

use of megamek.common.MiscType in project megameklab by MegaMek.

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getAero())) {
            mount = UnitUtil.updateTC(getAero(), equip);
            if (null != mount) {
                equipmentList.addCrit(mount);
            }
        }
    } else {
        int count = (Integer) spnAddCount.getValue();
        if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
            Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
            if (null != aMount) {
                aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
                return;
            } else {
                mount = new Mounted(getAero(), equip);
                mount.setShotsLeft(((AmmoType) equip).getShots() * count);
                try {
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                } catch (LocationFullException lfe) {
                // this can't happen, we add to Entity.LOC_NONE
                }
            }
        } else {
            try {
                for (int i = 0; i < count; i++) {
                    mount = new Mounted(getAero(), equip);
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                }
            } catch (LocationFullException lfe) {
            // this can't happen, we add to Entity.LOC_NONE
            }
        }
    }
}
Also used : AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 10 with MiscType

use of megamek.common.MiscType in project megameklab by MegaMek.

the class EquipmentTab method removeHeatSinks.

private void removeHeatSinks() {
    int location = 0;
    for (; location < equipmentList.getRowCount(); ) {
        Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
        EquipmentType eq = mount.getType();
        if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
            try {
                equipmentList.removeCrit(location);
            } catch (ArrayIndexOutOfBoundsException aioobe) {
                return;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            location++;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType) LocationFullException(megamek.common.LocationFullException)

Aggregations

MiscType (megamek.common.MiscType)37 Mounted (megamek.common.Mounted)33 AmmoType (megamek.common.AmmoType)14 EquipmentType (megamek.common.EquipmentType)13 LocationFullException (megamek.common.LocationFullException)12 WeaponType (megamek.common.WeaponType)11 Vector (java.util.Vector)9 CriticalSlot (megamek.common.CriticalSlot)7 ArrayList (java.util.ArrayList)6 Weapon (megamek.common.weapons.Weapon)6 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)5 JMenuItem (javax.swing.JMenuItem)4 JPopupMenu (javax.swing.JPopupMenu)4 BattleArmor (megamek.common.BattleArmor)4 Entity (megamek.common.Entity)4 Dimension (java.awt.Dimension)3 ActionEvent (java.awt.event.ActionEvent)3 MouseEvent (java.awt.event.MouseEvent)3 MouseListener (java.awt.event.MouseListener)3 List (java.util.List)3