Fix multi-comp motor ignition editing
This commit is contained in:
parent
532e94838f
commit
a396518ae8
@ -4,6 +4,7 @@ import java.awt.Dialog;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
@ -44,6 +45,8 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
|
||||
private IgnitionEvent startIgnitionEvent;
|
||||
private double startIgnitionDelay;
|
||||
|
||||
private boolean isOverrideDefault;
|
||||
|
||||
public IgnitionSelectionDialog(Window parent, final FlightConfigurationId curFCID, MotorMount _mount) {
|
||||
super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||
@ -62,15 +65,16 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
Rocket rkt = ((RocketComponent)_mount).getRocket();
|
||||
str = str.replace("{0}", descriptor.format(rkt, curFCID));
|
||||
|
||||
final JRadioButton overrideButton = new JRadioButton(str, !isDefault);
|
||||
final JRadioButton overrideButton = new JRadioButton(str);
|
||||
overrideButton.addItemListener(e -> isOverrideDefault = e.getStateChange() == ItemEvent.SELECTED);
|
||||
overrideButton.setSelected(!isDefault);
|
||||
panel.add(overrideButton, "span, gapleft para, wrap para");
|
||||
|
||||
ButtonGroup buttonGroup = new ButtonGroup();
|
||||
buttonGroup.add(defaultButton);
|
||||
buttonGroup.add(overrideButton);
|
||||
|
||||
// Select the button based on current configuration. If the configuration is overridden
|
||||
// The the overrideButton is selected.
|
||||
// Select the button based on current configuration. If the configuration is overridden the overrideButton is selected.
|
||||
boolean isOverridden = !isDefault;
|
||||
if (isOverridden) {
|
||||
overrideButton.setSelected(true);
|
||||
@ -114,18 +118,11 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
// and change all remaining configs
|
||||
// this seems like odd behavior to me, but it matches the text on the UI dialog popup. -teyrana (equipoise@gmail.com)
|
||||
Iterator<MotorConfiguration> iter = curMount.getMotorIterator();
|
||||
while( iter.hasNext() ){
|
||||
while(iter.hasNext() ) {
|
||||
MotorConfiguration next = iter.next();
|
||||
next.setIgnitionDelay( cid);
|
||||
next.setIgnitionEvent( cie);
|
||||
next.setIgnitionDelay(cid);
|
||||
next.setIgnitionEvent(cie);
|
||||
}
|
||||
|
||||
// System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: ");
|
||||
// System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent().name+" w/delay: "+defaultMotorInstance.getIgnitionDelay());
|
||||
// }else {
|
||||
// System.err.println("setting motor ignition to.... new values: ");
|
||||
// //destMotorInstance.setIgnitionEvent((IgnitionEvent)eventBox.getSelectedItem());
|
||||
// System.err.println(" "+curMotorInstance.getIgnitionEvent()+" w/ "+curMotorInstance.getIgnitionDelay());
|
||||
}
|
||||
IgnitionSelectionDialog.this.setVisible(false);
|
||||
}
|
||||
@ -150,5 +147,14 @@ public class IgnitionSelectionDialog extends JDialog {
|
||||
this.setContentPane(panel);
|
||||
|
||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
||||
GUIUtil.installEscapeCloseButtonOperation(this, okButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this dialog was used to override the default configuration.
|
||||
* @return true if this dialog was used to override the default configuration.
|
||||
*/
|
||||
public boolean isOverrideDefault() {
|
||||
return isOverrideDefault;
|
||||
}
|
||||
}
|
||||
|
@ -365,7 +365,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
return;
|
||||
}
|
||||
|
||||
boolean update = false;
|
||||
MotorMount initMount = mounts.get(0);
|
||||
FlightConfigurationId initFcId = fcIds.get(0);
|
||||
|
||||
@ -381,25 +380,34 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
||||
initFcId,
|
||||
initMount);
|
||||
ignitionDialog.setVisible(true);
|
||||
boolean isOverrideDefault = ignitionDialog.isOverrideDefault();
|
||||
|
||||
if (!initialIgnitionEvent.equals(initConfig.getIgnitionEvent()) || (initialIgnitionDelay != initConfig.getIgnitionDelay())) {
|
||||
update = true;
|
||||
}
|
||||
boolean update = !initialIgnitionEvent.equals(initConfig.getIgnitionEvent()) ||
|
||||
(initialIgnitionDelay != initConfig.getIgnitionDelay());
|
||||
|
||||
for (int i = 0; i < mounts.size(); i++) {
|
||||
for (int j = 0; j < fcIds.size(); j++) {
|
||||
if ((i == 0) && (j == 0)) break;
|
||||
for (MotorMount mount : mounts) {
|
||||
for (FlightConfigurationId fcId : fcIds) {
|
||||
if ((mount == initMount) && (fcId == initFcId))
|
||||
continue;
|
||||
|
||||
MotorConfiguration config = mounts.get(i).getMotorConfig(fcIds.get(j));
|
||||
initialIgnitionEvent = config.getIgnitionEvent();
|
||||
initialIgnitionDelay = config.getIgnitionDelay();
|
||||
MotorConfiguration currentConfig = mount.getMotorConfig(fcId);
|
||||
|
||||
config.setIgnitionEvent(initConfig.getIgnitionEvent());
|
||||
config.setIgnitionDelay(initConfig.getIgnitionDelay());
|
||||
|
||||
if (!initialIgnitionEvent.equals(config.getIgnitionEvent()) || (initialIgnitionDelay != config.getIgnitionDelay())) {
|
||||
update = true;
|
||||
// It could be that the current config is the default config, but the user has selected to override it.
|
||||
if (isOverrideDefault && !mount.getMotorConfigurationSet().containsId(fcId)) {
|
||||
mount.getMotorConfigurationSet().set(fcId, mount.getMotorConfigurationSet().getDefault().clone());
|
||||
}
|
||||
|
||||
initialIgnitionEvent = currentConfig.getIgnitionEvent();
|
||||
initialIgnitionDelay = currentConfig.getIgnitionDelay();
|
||||
|
||||
if (initialIgnitionEvent.equals(currentConfig.getIgnitionEvent()) && (initialIgnitionDelay != currentConfig.getIgnitionDelay())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
update = true;
|
||||
|
||||
currentConfig.setIgnitionEvent(initConfig.getIgnitionEvent());
|
||||
currentConfig.setIgnitionDelay(initConfig.getIgnitionDelay());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user