Skip to content

Commit

Permalink
#373 Added Variable inputs to Button and Encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
DocMoebiuz committed Jul 18, 2021
1 parent 19d6f98 commit 5e3ab73
Show file tree
Hide file tree
Showing 15 changed files with 1,069 additions and 647 deletions.
10 changes: 8 additions & 2 deletions MobiFlight/ExecutionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,14 @@ private ConnectorValue ExecuteRead(OutputConfigItem cfg)
}
else if (cfg.SourceType == SourceType.VARIABLE)
{
result.type = FSUIPCOffsetType.Float;
result.Float64 = mobiFlightCache.GetMobiFlightVariable(cfg.MobiFlightVariable.Name).Number;
if (cfg.MobiFlightVariable.TYPE == MobiFlightVariable.TYPE_NUMBER) {
result.type = FSUIPCOffsetType.Float;
result.Float64 = mobiFlightCache.GetMobiFlightVariable(cfg.MobiFlightVariable.Name).Number;
} else if (cfg.MobiFlightVariable.TYPE == MobiFlightVariable.TYPE_STRING)
{
result.type = FSUIPCOffsetType.String;
result.String = mobiFlightCache.GetMobiFlightVariable(cfg.MobiFlightVariable.Name).Text;
}
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions MobiFlight/InputConfig/ButtonInputConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public void ReadXml(System.Xml.XmlReader reader)
onPress = new MSFS2020EventIdInputAction();
onPress.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onPress = new VariableInputAction();
onPress.ReadXml(reader);
break;
}
reader.Read(); // Closing onPress
}
Expand Down Expand Up @@ -130,6 +135,11 @@ public void ReadXml(System.Xml.XmlReader reader)
onRelease = new MSFS2020EventIdInputAction();
onRelease.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onRelease = new VariableInputAction();
onRelease.ReadXml(reader);
break;
}

reader.Read(); // closing onRelease
Expand Down
21 changes: 21 additions & 0 deletions MobiFlight/InputConfig/EncoderInputConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ public void ReadXml(System.Xml.XmlReader reader)
onLeft = new LuaMacroInputAction();
onLeft.ReadXml(reader);
break;

case MSFS2020EventIdInputAction.TYPE:
onLeft = new MSFS2020EventIdInputAction();
onLeft.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onLeft = new VariableInputAction();
onLeft.ReadXml(reader);
break;
}

reader.Read(); // advance to the next
Expand Down Expand Up @@ -111,6 +117,11 @@ public void ReadXml(System.Xml.XmlReader reader)
onLeftFast = new MSFS2020EventIdInputAction();
onLeftFast.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onLeftFast = new VariableInputAction();
onLeftFast.ReadXml(reader);
break;
}

reader.Read(); // advance to the next
Expand Down Expand Up @@ -154,6 +165,11 @@ public void ReadXml(System.Xml.XmlReader reader)
onRight = new MSFS2020EventIdInputAction();
onRight.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onRight = new VariableInputAction();
onRight.ReadXml(reader);
break;
}

reader.Read(); // advance to the next
Expand Down Expand Up @@ -197,6 +213,11 @@ public void ReadXml(System.Xml.XmlReader reader)
onRightFast = new MSFS2020EventIdInputAction();
onRightFast.ReadXml(reader);
break;

case VariableInputAction.TYPE:
onRightFast = new VariableInputAction();
onRightFast.ReadXml(reader);
break;
}

reader.Read(); // advance to the next
Expand Down
17 changes: 15 additions & 2 deletions MobiFlight/InputConfig/VariableInputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void execute(FSUIPC.FSUIPCCacheInterface fsuipcCache,
if (result.Contains("$"))
{
MobiFlightVariable variable = moduleCache.GetMobiFlightVariable(Variable.Name);
Tuple<string, string> replacement = new Tuple<string, string>("$", variable.TYPE == "number" ? variable.Number.ToString() : variable.Text);
Tuple<string, string> replacement = new Tuple<string, string>("$", variable.TYPE == MobiFlightVariable.TYPE_NUMBER ? variable.Number.ToString() : variable.Text);
replacements.Add(replacement);
}

Expand All @@ -70,7 +70,20 @@ public override void execute(FSUIPC.FSUIPCCacheInterface fsuipcCache,
}

result = Replace(result, replacements);
Variable.Number = double.Parse(result);

if (Variable.TYPE == MobiFlightVariable.TYPE_NUMBER)
{
try
{
Variable.Number = double.Parse(result);
}
catch (Exception)
{


}
}

Variable.Text = result;
moduleCache.SetMobiFlightVariable(Variable);
}
Expand Down
5 changes: 4 additions & 1 deletion MobiFlight/MobiFlightVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ namespace MobiFlight
{
public class MobiFlightVariable
{
public string TYPE = "number";
public const string TYPE_NUMBER = "number";
public const string TYPE_STRING = "string";

public string TYPE = TYPE_NUMBER;
public string Name = "MyVar";
public double Number;
public string Text = "";
Expand Down
3 changes: 3 additions & 0 deletions MobiFlightConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,9 @@
<EmbeddedResource Include="UI\Panels\Config\TransformOptionsGroup.resx">
<DependentUpon>TransformOptionsGroup.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Panels\Config\VariablePanel.de.resx">
<DependentUpon>VariablePanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Panels\Config\VariablePanel.resx">
<DependentUpon>VariablePanel.cs</DependentUpon>
</EmbeddedResource>
Expand Down
29 changes: 26 additions & 3 deletions UI/Panels/Action/VariableInputPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@ public VariableInputPanel()
{
InitializeComponent();
InitWithVariable(new MobiFlightVariable());

List<ListItem> options = new List<ListItem>();
options.Add(new ListItem() { Value = MobiFlightVariable.TYPE_NUMBER, Label = "Number" });
options.Add(new ListItem() { Value = MobiFlightVariable.TYPE_STRING, Label = "String" });

TypeComboBox.DisplayMember = "Label";
TypeComboBox.ValueMember = "Value";
TypeComboBox.DataSource = options;
TypeComboBox.SelectedIndex = 0;
}

private void InitWithVariable(MobiFlightVariable Variable)
{
ComboBoxHelper.SetSelectedItem(TypeComboBox, Variable.TYPE);
try
{
TypeComboBox.SelectedValue = Variable.TYPE;
}
catch (Exception)
{
TypeComboBox.SelectedValue = MobiFlightVariable.TYPE_NUMBER;
}
NameTextBox.Text = Variable.Name;
ValueTextBox.Text = Variable.Expression;
}
Expand All @@ -30,15 +46,22 @@ internal void syncFromConfig(InputConfig.VariableInputAction inputAction)
{
if (inputAction == null) inputAction = new InputConfig.VariableInputAction();

ComboBoxHelper.SetSelectedItem(TypeComboBox, inputAction.Variable.TYPE);
try
{
TypeComboBox.SelectedValue = inputAction.Variable.TYPE;
}
catch (Exception)
{
TypeComboBox.SelectedValue = MobiFlightVariable.TYPE_NUMBER;
}
NameTextBox.Text = inputAction.Variable.Name;
ValueTextBox.Text = inputAction.Variable.Expression;
}

internal InputConfig.InputAction ToConfig()
{
MobiFlight.InputConfig.VariableInputAction result = new InputConfig.VariableInputAction();
result.Variable.TYPE = TypeComboBox.Text;
result.Variable.TYPE = TypeComboBox.SelectedValue.ToString();
result.Variable.Name = NameTextBox.Text;
result.Variable.Expression = ValueTextBox.Text;
return result;
Expand Down
22 changes: 11 additions & 11 deletions UI/Panels/Config/FsuipcConfigPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions UI/Panels/Config/FsuipcConfigPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private void updateByteSizeComboBox()
{
string selectedText = fsuipcSizeComboBox.Text;
fsuipcSizeComboBox.Items.Clear();
fsuipcSizeLabel.Visible = true;
fsuipcSizeComboBox.Enabled = true;
fsuipcSizeComboBox.Visible = true;
maskAndBcdPanel.Visible = true;
Expand Down Expand Up @@ -208,6 +209,7 @@ private void updateByteSizeComboBox()
// by the zero-termination
// this makes it easier for the user
// because s/he doesn't have to care about it.
fsuipcSizeLabel.Visible = false;
fsuipcSizeComboBox.Enabled = false;
fsuipcSizeComboBox.Visible = false;

Expand Down
Loading

0 comments on commit 5e3ab73

Please sign in to comment.