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.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
import javax.swing.ButtonGroup;
|
||||||
@ -45,6 +46,8 @@ public class IgnitionSelectionDialog extends JDialog {
|
|||||||
private IgnitionEvent startIgnitionEvent;
|
private IgnitionEvent startIgnitionEvent;
|
||||||
private double startIgnitionDelay;
|
private double startIgnitionDelay;
|
||||||
|
|
||||||
|
private boolean isOverrideDefault;
|
||||||
|
|
||||||
public IgnitionSelectionDialog(Window parent, final FlightConfigurationId curFCID, MotorMount _mount) {
|
public IgnitionSelectionDialog(Window parent, final FlightConfigurationId curFCID, MotorMount _mount) {
|
||||||
super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
curMount = _mount;
|
curMount = _mount;
|
||||||
@ -62,15 +65,16 @@ public class IgnitionSelectionDialog extends JDialog {
|
|||||||
Rocket rkt = ((RocketComponent)_mount).getRocket();
|
Rocket rkt = ((RocketComponent)_mount).getRocket();
|
||||||
str = str.replace("{0}", descriptor.format(rkt, curFCID));
|
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");
|
panel.add(overrideButton, "span, gapleft para, wrap para");
|
||||||
|
|
||||||
ButtonGroup buttonGroup = new ButtonGroup();
|
ButtonGroup buttonGroup = new ButtonGroup();
|
||||||
buttonGroup.add(defaultButton);
|
buttonGroup.add(defaultButton);
|
||||||
buttonGroup.add(overrideButton);
|
buttonGroup.add(overrideButton);
|
||||||
|
|
||||||
// Select the button based on current configuration. If the configuration is overridden
|
// Select the button based on current configuration. If the configuration is overridden the overrideButton is selected.
|
||||||
// The the overrideButton is selected.
|
|
||||||
boolean isOverridden = !isDefault;
|
boolean isOverridden = !isDefault;
|
||||||
if (isOverridden) {
|
if (isOverridden) {
|
||||||
overrideButton.setSelected(true);
|
overrideButton.setSelected(true);
|
||||||
@ -114,18 +118,11 @@ public class IgnitionSelectionDialog extends JDialog {
|
|||||||
// and change all remaining configs
|
// 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)
|
// 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();
|
Iterator<MotorConfiguration> iter = curMount.getMotorIterator();
|
||||||
while( iter.hasNext() ){
|
while(iter.hasNext() ) {
|
||||||
MotorConfiguration next = iter.next();
|
MotorConfiguration next = iter.next();
|
||||||
next.setIgnitionDelay( cid);
|
next.setIgnitionDelay(cid);
|
||||||
next.setIgnitionEvent( cie);
|
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);
|
IgnitionSelectionDialog.this.setVisible(false);
|
||||||
}
|
}
|
||||||
@ -150,5 +147,14 @@ public class IgnitionSelectionDialog extends JDialog {
|
|||||||
this.setContentPane(panel);
|
this.setContentPane(panel);
|
||||||
|
|
||||||
GUIUtil.setDisposableDialogOptions(this, okButton);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean update = false;
|
|
||||||
MotorMount initMount = mounts.get(0);
|
MotorMount initMount = mounts.get(0);
|
||||||
FlightConfigurationId initFcId = fcIds.get(0);
|
FlightConfigurationId initFcId = fcIds.get(0);
|
||||||
|
|
||||||
@ -381,25 +380,34 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
|
|||||||
initFcId,
|
initFcId,
|
||||||
initMount);
|
initMount);
|
||||||
ignitionDialog.setVisible(true);
|
ignitionDialog.setVisible(true);
|
||||||
|
boolean isOverrideDefault = ignitionDialog.isOverrideDefault();
|
||||||
|
|
||||||
if (!initialIgnitionEvent.equals(initConfig.getIgnitionEvent()) || (initialIgnitionDelay != initConfig.getIgnitionDelay())) {
|
boolean update = !initialIgnitionEvent.equals(initConfig.getIgnitionEvent()) ||
|
||||||
update = true;
|
(initialIgnitionDelay != initConfig.getIgnitionDelay());
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < mounts.size(); i++) {
|
for (MotorMount mount : mounts) {
|
||||||
for (int j = 0; j < fcIds.size(); j++) {
|
for (FlightConfigurationId fcId : fcIds) {
|
||||||
if ((i == 0) && (j == 0)) break;
|
if ((mount == initMount) && (fcId == initFcId))
|
||||||
|
continue;
|
||||||
|
|
||||||
MotorConfiguration config = mounts.get(i).getMotorConfig(fcIds.get(j));
|
MotorConfiguration currentConfig = mount.getMotorConfig(fcId);
|
||||||
initialIgnitionEvent = config.getIgnitionEvent();
|
|
||||||
initialIgnitionDelay = config.getIgnitionDelay();
|
|
||||||
|
|
||||||
config.setIgnitionEvent(initConfig.getIgnitionEvent());
|
// It could be that the current config is the default config, but the user has selected to override it.
|
||||||
config.setIgnitionDelay(initConfig.getIgnitionDelay());
|
if (isOverrideDefault && !mount.getMotorConfigurationSet().containsId(fcId)) {
|
||||||
|
mount.getMotorConfigurationSet().set(fcId, mount.getMotorConfigurationSet().getDefault().clone());
|
||||||
if (!initialIgnitionEvent.equals(config.getIgnitionEvent()) || (initialIgnitionDelay != config.getIgnitionDelay())) {
|
|
||||||
update = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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