use of megamek.common.verifier.BayData in project megameklab by MegaMek.
the class CVTransportView method initUI.
private void initUI() {
// $NON-NLS-1$
ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Views", new EncodeControl());
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
// $NON-NLS-1$
add(createLabel(resourceMap.getString("CVTransportView.lblFixed.text"), labelSize), gbc);
gbc.gridx = 2;
gbc.gridy = 0;
// $NON-NLS-1$
add(createLabel(resourceMap.getString("CVTransportView.lblPod.text"), labelSize), gbc);
gbc.gridx = 0;
gbc.gridy = 1;
// $NON-NLS-1$
add(createLabel(resourceMap.getString("CVTransportView.lblTroopSpace.text"), labelSizeLg), gbc);
gbc.gridx = 1;
setFieldSize(spnFixedTroop, editorSize);
add(spnFixedTroop, gbc);
spnFixedTroop.addChangeListener(this);
gbc.gridx = 2;
setFieldSize(spnPodTroop, editorSize);
add(spnPodTroop, gbc);
spnPodTroop.addChangeListener(this);
for (BayData bayType : BayData.values()) {
if (!bayType.isCargoBay()) {
continue;
}
String tooltip = String.format(resourceMap.getString("CVTransportView.bay.tooltipFormat"), 1 / bayType.getWeight());
gbc.gridx = 0;
gbc.gridy++;
add(createLabel(bayType.getDisplayName(), labelSizeLg), gbc);
gbc.gridx = 1;
SpinnerNumberModel model = new SpinnerNumberModel(0.0, 0.0, null, 0.5);
JSpinner spinner = new JSpinner(model);
spinner.setToolTipText(tooltip);
spinner.setName(bayType.toString());
setFieldSize(spinner, editorSize);
fixedSpinnerModels.put(bayType, model);
fixedSpinners.put(bayType, spinner);
add(spinner, gbc);
spinner.addChangeListener(this);
gbc.gridx = 2;
model = new SpinnerNumberModel(0.0, 0.0, null, 0.5);
spinner = new JSpinner(model);
spinner.setToolTipText(tooltip);
spinner.setName(bayType.toString());
setFieldSize(spinner, editorSize);
podSpinnerModels.put(bayType, model);
podSpinners.put(bayType, spinner);
add(spinner, gbc);
spinner.addChangeListener(this);
}
}
use of megamek.common.verifier.BayData in project megameklab by MegaMek.
the class TransportTab method actionPerformed.
public void actionPerformed(ActionEvent ev) {
if (ev.getSource() == btnAddBay) {
int selected = tblAvailable.getSelectedRow();
if (selected >= 0) {
BayData bayType = modelAvailable.getBayType(tblAvailable.convertRowIndexToModel(selected));
int num = 1;
while (getAero().getBayById(num) != null) {
num++;
}
Bay newBay = bayType.newBay(1.0, num);
if (doorsAvailable() > 0) {
newBay.setDoors(1);
}
addBay(newBay);
modelInstalled.refreshBays();
rebuildBays();
refresh();
}
} else if (ev.getSource() == btnRemoveBay) {
int selected = tblInstalled.getSelectedRow();
if (selected >= 0) {
Bay bay = modelInstalled.getBay(tblInstalled.convertRowIndexToModel(selected));
removeBay(bay);
modelInstalled.refreshBays();
rebuildBays();
refresh();
}
} else if (ev.getSource() == btnAddToCargo) {
double size = getAero().getWeight() - UnitUtil.getEntityVerifier(getAero()).calculateWeight();
if (size > 0) {
int selected = tblInstalled.getSelectedRow();
Bay bay = null;
int bayNum = 1;
if ((selected >= 0) && (modelInstalled.getBayType(tblInstalled.convertRowIndexToModel(selected)) == BayData.CARGO)) {
bay = modelInstalled.getBay(tblInstalled.convertRowIndexToModel(selected));
size += bay.getCapacity();
bayNum = bay.getBayNumber();
removeBay(bay);
} else {
while (getAero().getBayById(bayNum) != null) {
bayNum++;
}
}
bay = BayData.CARGO.newBay(size, bayNum);
addBay(bay);
refresh();
}
}
}
use of megamek.common.verifier.BayData in project megameklab by MegaMek.
the class CVTransportView method setFromEntity.
public void setFromEntity(Tank tank) {
double troops = tank.getTroopCarryingSpace();
double podTroops = tank.getPodMountedTroopCarryingSpace();
spnFixedTroop.setValue(troops - podTroops);
spnPodTroop.setValue(podTroops);
Map<BayData, Double> fixedCargo = new HashMap<>();
Map<BayData, Double> podCargo = new HashMap<>();
for (Bay b : tank.getTransportBays()) {
BayData bayType = BayData.getBayType(b);
if (null != bayType) {
if (tank.isPodMountedTransport(b)) {
podCargo.merge(bayType, b.getCapacity(), Double::sum);
} else {
fixedCargo.merge(bayType, b.getCapacity(), Double::sum);
}
}
}
for (Map.Entry<BayData, JSpinner> entry : fixedSpinners.entrySet()) {
entry.getValue().setValue(fixedCargo.getOrDefault(entry.getKey(), 0.0));
}
for (Map.Entry<BayData, JSpinner> entry : podSpinners.entrySet()) {
entry.getValue().setValue(podCargo.getOrDefault(entry.getKey(), 0.0));
}
setOmni(tank.isOmni());
}
use of megamek.common.verifier.BayData in project megameklab by MegaMek.
the class TransportTab method rebuildBays.
/**
* Removing bays can cause undesirable gaps in bay numbers, and it would be nice to let the
* user order the bays. Since bay numbers are immutable we have to instantiate a new bay to
* alter it.
*/
private void rebuildBays() {
int bayNum = 1;
List<Bay> newBayList = new ArrayList<>();
for (Iterator<Bay> iter = modelInstalled.getBays(); iter.hasNext(); ) {
final Bay bay = iter.next();
if (bay.getBayNumber() == bayNum) {
newBayList.add(bay);
} else {
BayData bayType = BayData.getBayType(bay);
Bay newBay = bayType.newBay(bay.getCapacity(), bayNum);
newBay.setDoors(bay.getDoors());
newBayList.add(newBay);
}
bayNum++;
}
for (Bay bay : getAero().getTransportBays()) {
if (bay.isQuarters()) {
newBayList.add(bay);
}
}
getAero().removeAllTransporters();
newBayList.forEach(b -> getAero().addTransporter(b));
modelInstalled.refreshBays();
}
use of megamek.common.verifier.BayData in project megameklab by MegaMek.
the class TransportTab method canAddSelectedBay.
private boolean canAddSelectedBay() {
int selected = tblAvailable.getSelectedRow();
if (selected < 0) {
return false;
}
BayData bayType = modelAvailable.getBayType(tblAvailable.convertRowIndexToModel(selected));
return (doorsAvailable() > 0) || (bayType == BayData.CARGO);
}
Aggregations