Search in sources :

Example 36 with CriticalSlot

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

the class CriticalView method refresh.

public void refresh() {
    laPanel.removeAll();
    raPanel.removeAll();
    llPanel.removeAll();
    rlPanel.removeAll();
    clPanel.removeAll();
    ltPanel.removeAll();
    rtPanel.removeAll();
    ctPanel.removeAll();
    headPanel.removeAll();
    clPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
    // the CritListCellRenderer has a default size of 110x15 and
    // the border has a width of 1 so this should make each one the right
    // size
    Dimension size = new Dimension(112, 182);
    Dimension legSize = new Dimension(112, 92);
    synchronized (getMech()) {
        for (int location = 0; location < getMech().locations(); location++) {
            // JPanel locationPanel = new JPanel();
            Vector<String> critNames = new Vector<String>(1, 1);
            for (int slot = 0; slot < getMech().getNumberOfCriticals(location); slot++) {
                CriticalSlot cs = getMech().getCritical(location, slot);
                if (cs == null) {
                    if (showEmpty) {
                        critNames.add(MtfFile.EMPTY);
                    }
                } else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
                    critNames.add(getMech().getSystemName(cs.getIndex()));
                } else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
                    try {
                        Mounted m = cs.getMount();
                        // Critical didn't get removed. Remove it now.
                        if (m == null) {
                            m = cs.getMount();
                            if (m == null) {
                                getMech().setCritical(location, slot, null);
                                if (showEmpty) {
                                    critNames.add(MtfFile.EMPTY);
                                }
                                continue;
                            }
                            cs.setMount(m);
                        }
                        StringBuffer critName = new StringBuffer(m.getName());
                        if (critName.length() > 25) {
                            critName.setLength(25);
                            critName.append("...");
                        }
                        if (m.isRearMounted()) {
                            critName.append(" (R)");
                        }
                        if (m.isMechTurretMounted()) {
                            critName.append(" (T)");
                        }
                        critNames.add(critName.toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            if (critNames.size() == 0) {
                critNames.add(MtfFile.EMPTY);
            }
            DropTargetCriticalList<String> criticalSlotList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
            criticalSlotList.setVisibleRowCount(critNames.size());
            criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
            criticalSlotList.setName(Integer.toString(location));
            criticalSlotList.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            switch(location) {
                case Mech.LOC_HEAD:
                    criticalSlotList.setSize(legSize);
                    criticalSlotList.setPreferredSize(legSize);
                    criticalSlotList.setMaximumSize(legSize);
                    headPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_LARM:
                    if (getMech() instanceof QuadMech) {
                        laPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Front Left Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                        criticalSlotList.setSize(legSize);
                        criticalSlotList.setPreferredSize(legSize);
                        criticalSlotList.setMaximumSize(legSize);
                    } else {
                        laPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Left Arm", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                        criticalSlotList.setSize(size);
                        criticalSlotList.setPreferredSize(size);
                        criticalSlotList.setMaximumSize(size);
                    }
                    laPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_RARM:
                    if (getMech() instanceof QuadMech) {
                        raPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Front Right Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                        criticalSlotList.setSize(legSize);
                        criticalSlotList.setPreferredSize(legSize);
                        criticalSlotList.setMaximumSize(legSize);
                    } else {
                        raPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Right Arm", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                        criticalSlotList.setSize(size);
                        criticalSlotList.setPreferredSize(size);
                        criticalSlotList.setMaximumSize(size);
                    }
                    raPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_CT:
                    criticalSlotList.setSize(size);
                    criticalSlotList.setPreferredSize(size);
                    criticalSlotList.setMaximumSize(size);
                    ctPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_LT:
                    criticalSlotList.setSize(size);
                    criticalSlotList.setPreferredSize(size);
                    criticalSlotList.setMaximumSize(size);
                    ltPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_RT:
                    criticalSlotList.setSize(size);
                    criticalSlotList.setPreferredSize(size);
                    criticalSlotList.setMaximumSize(size);
                    rtPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_LLEG:
                    if (getMech() instanceof QuadMech) {
                        llPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Rear Left Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                    } else {
                        llPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Left Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                    }
                    criticalSlotList.setSize(legSize);
                    criticalSlotList.setPreferredSize(legSize);
                    criticalSlotList.setMaximumSize(legSize);
                    llPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_RLEG:
                    if (getMech() instanceof QuadMech) {
                        rlPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Rear Right Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                    } else {
                        rlPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Right Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                    }
                    criticalSlotList.setSize(legSize);
                    criticalSlotList.setPreferredSize(legSize);
                    criticalSlotList.setMaximumSize(legSize);
                    rlPanel.add(criticalSlotList);
                    break;
                case Mech.LOC_CLEG:
                    clPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Center Leg", TitledBorder.TOP, TitledBorder.DEFAULT_POSITION));
                    criticalSlotList.setSize(legSize);
                    criticalSlotList.setPreferredSize(legSize);
                    criticalSlotList.setMaximumSize(legSize);
                    clPanel.add(criticalSlotList);
                    break;
            }
        }
        ctPanel.invalidate();
        raPanel.invalidate();
        headPanel.invalidate();
        laPanel.invalidate();
        ltPanel.invalidate();
        rtPanel.invalidate();
        llPanel.invalidate();
        rlPanel.invalidate();
        clPanel.invalidate();
        ctPanel.repaint();
        raPanel.repaint();
        headPanel.repaint();
        laPanel.repaint();
        ltPanel.repaint();
        rtPanel.repaint();
        llPanel.repaint();
        rlPanel.repaint();
        clPanel.invalidate();
    }
}
Also used : QuadMech(megamek.common.QuadMech) CriticalSlot(megamek.common.CriticalSlot) Dimension(java.awt.Dimension) Font(java.awt.Font) DropTargetCriticalList(megameklab.com.util.Mech.DropTargetCriticalList) Mounted(megamek.common.Mounted) Vector(java.util.Vector)

Example 37 with CriticalSlot

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

the class CriticalView method refresh.

public void refresh() {
    leftPanel.removeAll();
    rightPanel.removeAll();
    nosePanel.removeAll();
    aftPanel.removeAll();
    int[] availSpace = TestAero.availableSpace(getAero());
    if (availSpace == null) {
        // Shouldn't happen, since we only allow valid armor types to be
        // selected...
        System.err.println("Error in CriticalView: Invalid armor type!");
        return;
    }
    synchronized (getAero()) {
        // Aeros have 5 locs, the 5th is "wings" which should be ignored
        int numLocs = getAero().locations() - 1;
        for (int location = 0; location < numLocs; location++) {
            Vector<String> critNames = new Vector<String>(1, 1);
            int numWeapons = 0;
            for (int slot = 0; slot < getAero().getNumberOfCriticals(location); slot++) {
                CriticalSlot cs = getAero().getCritical(location, slot);
                if (cs == null) {
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
                    // Aeros shouldn't have system types
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
                    try {
                        Mounted m = cs.getMount();
                        // Critical didn't get removed. Remove it now.
                        if (m == null) {
                            m = cs.getMount();
                            if (m == null) {
                                getAero().setCritical(location, slot, null);
                                continue;
                            }
                            cs.setMount(m);
                        }
                        // Ignore weapon groups
                        if (m.isWeaponGroup()) {
                            continue;
                        }
                        if (m.getType() instanceof WeaponType) {
                            numWeapons++;
                        }
                        StringBuffer critName = new StringBuffer(m.getName());
                        if (critName.length() > 25) {
                            critName.setLength(25);
                            critName.append("...");
                        }
                        if (m.isRearMounted()) {
                            critName.append(" (R)");
                        }
                        if (m.isSponsonTurretMounted()) {
                            critName.append(" (ST)");
                        }
                        if (m.isPintleTurretMounted()) {
                            critName.append(" (PT)");
                        }
                        critName.append(":" + slot);
                        critNames.add(critName.toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            if (critNames.size() == 0) {
                critNames.add(MtfFile.EMPTY);
            }
            DropTargetCriticalList<String> criticalSlotList = null;
            DropTargetCriticalList<String> dropTargetCriticalList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
            criticalSlotList = dropTargetCriticalList;
            criticalSlotList.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            criticalSlotList.setVisibleRowCount(critNames.size());
            criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
            criticalSlotList.setName(Integer.toString(location));
            criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
            switch(location) {
                case Aero.LOC_NOSE:
                    nosePanel.add(criticalSlotList);
                    noseSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
                    break;
                case Aero.LOC_LWING:
                    leftPanel.add(criticalSlotList);
                    leftSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
                    break;
                case Aero.LOC_RWING:
                    rightPanel.add(criticalSlotList);
                    rightSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
                    break;
                case Aero.LOC_AFT:
                    aftPanel.add(criticalSlotList);
                    aftSpace.setText("Weapons: " + numWeapons + "/" + availSpace[location]);
                    break;
            }
        }
        leftPanel.add(leftSpace);
        leftPanel.add(Box.createVerticalStrut(8));
        rightPanel.add(rightSpace);
        rightPanel.add(Box.createVerticalStrut(8));
        nosePanel.add(noseSpace);
        nosePanel.add(Box.createVerticalStrut(8));
        aftPanel.add(aftSpace);
        aftPanel.add(Box.createVerticalStrut(8));
        nosePanel.repaint();
        leftPanel.repaint();
        rightPanel.repaint();
        aftPanel.repaint();
        nosePanel.invalidate();
        leftPanel.invalidate();
        rightPanel.invalidate();
        aftPanel.invalidate();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Font(java.awt.Font) DropTargetCriticalList(megameklab.com.util.Mech.DropTargetCriticalList) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) Vector(java.util.Vector)

Example 38 with CriticalSlot

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

the class UnitUtil method getShieldDamageAbsorption.

public static int getShieldDamageAbsorption(Mech mech, int location) {
    final String METHOD_NAME = "getShieldDamageAbsorption(Mech, int)";
    for (int slot = 0; slot < mech.getNumberOfCriticals(location); slot++) {
        CriticalSlot cs = mech.getCritical(location, slot);
        if (cs == null) {
            continue;
        }
        if (cs.getType() != CriticalSlot.TYPE_EQUIPMENT) {
            continue;
        }
        Mounted m = cs.getMount();
        if (m == null) {
            getLogger().log(UnitUtil.class, METHOD_NAME, LogLevel.ERROR, "Null Mount index: " + cs.getIndex());
            m = cs.getMount();
        }
        EquipmentType type = m.getType();
        if ((type instanceof MiscType) && ((MiscType) type).isShield()) {
            return m.getBaseDamageAbsorptionRate();
        }
    }
    return 0;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Aggregations

CriticalSlot (megamek.common.CriticalSlot)38 Mounted (megamek.common.Mounted)28 EntityLoadingException (megamek.common.loaders.EntityLoadingException)11 BattleArmor (megamek.common.BattleArmor)7 MiscType (megamek.common.MiscType)7 Vector (java.util.Vector)6 TestBattleArmor (megamek.common.verifier.TestBattleArmor)6 WeaponType (megamek.common.WeaponType)5 Font (java.awt.Font)4 ArrayList (java.util.ArrayList)4 EquipmentType (megamek.common.EquipmentType)4 LocationFullException (megamek.common.LocationFullException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 AmmoType (megamek.common.AmmoType)3 Dimension (java.awt.Dimension)2 Transferable (java.awt.datatransfer.Transferable)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 InputEvent (java.awt.event.InputEvent)2