Skip to content

Commit

Permalink
#373 - Improved MobiFlight Variables, they are working for inputs and…
Browse files Browse the repository at this point in the history
… outputs.
  • Loading branch information
DocMoebiuz committed Jul 18, 2021
1 parent 07cfc28 commit fca9192
Show file tree
Hide file tree
Showing 15 changed files with 716 additions and 455 deletions.
11 changes: 11 additions & 0 deletions MobiFlight/ExecutionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ private ConnectorValue ExecuteRead(OutputConfigItem cfg)
result = ExecuteReadFloat(cfg);
}
}
else if (cfg.SourceType == SourceType.VARIABLE)
{
result.type = FSUIPCOffsetType.Float;
result.Float64 = mobiFlightCache.GetMobiFlightVariable(cfg.MobiFlightVariable.Name).Number;
}
else
{
result.type = FSUIPCOffsetType.Float;
Expand Down Expand Up @@ -1425,6 +1430,12 @@ void mobiFlightCache_OnButtonPressed(object sender, InputEventArgs e)
foreach (Tuple<InputConfigItem, DataGridViewRow> tuple in inputCache[inputKey])
{
if ((tuple.Item2.DataBoundItem as DataRowView) == null)
{
Log.Instance.log("mobiFlightCache_OnButtonPressed: tuple.Item2.DataBoundItem is NULL", LogSeverity.Debug);
continue;
}

DataRow row = (tuple.Item2.DataBoundItem as DataRowView).Row;

if (!(bool)row["active"]) continue;
Expand Down
11 changes: 9 additions & 2 deletions MobiFlight/InputConfig/VariableInputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ public override void execute(FSUIPC.FSUIPCCacheInterface fsuipcCache,

List<Tuple<string, string>> replacements = new List<Tuple<string, string>>();

if (result.Contains("@"))
{
Tuple<string, string> replacement = new Tuple<string, string>("@", args.Value.ToString());
replacements.Add(replacement);
}

if (result.Contains("$"))
{
Tuple<string, string> replacement = new Tuple<string, string>("$", args.Value.ToString());
MobiFlightVariable variable = moduleCache.GetMobiFlightVariable(Variable.Name);
Tuple<string, string> replacement = new Tuple<string, string>("$", variable.TYPE == "number" ? variable.Number.ToString() : variable.Text);
replacements.Add(replacement);
}


foreach (ConfigRefValue item in configRefs)
{
Tuple<string, string> replacement = new Tuple<string, string>(item.ConfigRef.Placeholder, item.Value);
Expand Down
5 changes: 5 additions & 0 deletions MobiFlight/MobiFlightCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,10 @@ public MobiFlightVariable GetMobiFlightVariable(String name)

return variables[name];
}

public List<String> GetMobiFlightVariableNames()
{
return variables.Keys.ToList();
}
}
}
21 changes: 20 additions & 1 deletion MobiFlight/MobiFlightVariable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace MobiFlight
using System;
using System.Xml;

namespace MobiFlight
{
public class MobiFlightVariable
{
Expand All @@ -19,5 +22,21 @@ public object Clone()

return clone;
}


public void ReadXml(System.Xml.XmlReader reader)
{
TYPE = reader["varType"];
Name = reader["varName"];
Expression = reader["varExpression"];
}

public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteAttributeString("type", "Variable");
writer.WriteAttributeString("varType", TYPE);
writer.WriteAttributeString("varName", Name);
writer.WriteAttributeString("varExpression", Expression);
}
}
}
14 changes: 13 additions & 1 deletion MobiFlight/OutputConfigItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class OutputConfigItem : IBaseConfigItem, IFsuipcConfigItem, IXmlSerializ
public SimConnectValue
SimConnectValue { get; set; }

public MobiFlightVariable
MobiFlightVariable { get; set; }

public Transformation
Transform { get; set; }
public string Value { get; set; }
Expand Down Expand Up @@ -90,6 +93,7 @@ public OutputConfigItem()
SourceType = SourceType.FSUIPC;
FSUIPC = new FsuipcOffset();
SimConnectValue = new SimConnectValue();
MobiFlightVariable = new MobiFlightVariable();

Transform = new Transformation();

Expand Down Expand Up @@ -138,6 +142,10 @@ public virtual void ReadXml(XmlReader reader)
if (reader["type"]=="SimConnect") {
SourceType = SourceType.SIMCONNECT;
this.SimConnectValue.ReadXml(reader);
} else if (reader["type"] == "Variable")
{
SourceType = SourceType.VARIABLE;
this.MobiFlightVariable.ReadXml(reader);
}
else
{
Expand Down Expand Up @@ -378,6 +386,8 @@ public virtual void WriteXml(XmlWriter writer)
writer.WriteStartElement("source");
if(SourceType==SourceType.FSUIPC)
this.FSUIPC.WriteXml(writer);
else if (SourceType == SourceType.VARIABLE)
this.MobiFlightVariable.WriteXml(writer);
else
this.SimConnectValue.WriteXml(writer);
writer.WriteEndElement();
Expand Down Expand Up @@ -481,6 +491,7 @@ public object Clone()
clone.SourceType = this.SourceType;
clone.FSUIPC = this.FSUIPC.Clone() as FsuipcOffset;
clone.SimConnectValue = this.SimConnectValue.Clone() as SimConnectValue;
clone.MobiFlightVariable = this.MobiFlightVariable.Clone() as MobiFlightVariable;

clone.Transform = this.Transform.Clone() as Transformation;
clone.ComparisonActive = this.ComparisonActive;
Expand Down Expand Up @@ -543,6 +554,7 @@ public object Clone()
public enum SourceType
{
FSUIPC,
SIMCONNECT
SIMCONNECT,
VARIABLE
}
}
9 changes: 9 additions & 0 deletions MobiFlightConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@
<Compile Include="UI\Panels\Action\MSFS2020InputPanel.Designer.cs">
<DependentUpon>MSFS2020InputPanel.cs</DependentUpon>
</Compile>
<Compile Include="UI\Panels\Config\VariablePanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\Panels\Config\VariablePanel.Designer.cs">
<DependentUpon>VariablePanel.cs</DependentUpon>
</Compile>
<Compile Include="UI\Panels\Device\MFAnalogPanel.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -779,6 +785,9 @@
<EmbeddedResource Include="UI\Panels\Config\TransformOptionsGroup.resx">
<DependentUpon>TransformOptionsGroup.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Panels\Config\VariablePanel.resx">
<DependentUpon>VariablePanel.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Panels\Device\MFAnalogPanel.de.resx">
<DependentUpon>MFAnalogPanel.cs</DependentUpon>
</EmbeddedResource>
Expand Down
66 changes: 37 additions & 29 deletions UI/Dialogs/ConfigWizard.Designer.cs

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

14 changes: 11 additions & 3 deletions UI/Dialogs/ConfigWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,12 @@ private void _syncFsuipcTabFromConfig(OutputConfigItem config)
{
OffsetTypeFsuipRadioButton.Checked = (config.SourceType == SourceType.FSUIPC);
OffsetTypeSimConnectRadioButton.Checked = (config.SourceType == SourceType.SIMCONNECT);
OffsetTypeVariableRadioButton.Checked = (config.SourceType == SourceType.VARIABLE);

fsuipcConfigPanel.syncFromConfig(config);

simConnectPanel1.syncFromConfig(config);
variablePanel1.syncFromConfig(config);
configRefPanel.syncFromConfig(config);
}

Expand All @@ -458,12 +461,16 @@ private void _addEmptyNodeToTreeView()
/// <returns></returns>
protected bool _syncFormToConfig()
{
config.SourceType = OffsetTypeFsuipRadioButton.Checked ? SourceType.FSUIPC : SourceType.SIMCONNECT;
config.SourceType = SourceType.FSUIPC;
if (OffsetTypeSimConnectRadioButton.Checked) config.SourceType = SourceType.SIMCONNECT;
if (OffsetTypeVariableRadioButton.Checked) config.SourceType = SourceType.VARIABLE;

if(config.SourceType==SourceType.FSUIPC)
if (config.SourceType == SourceType.FSUIPC)
fsuipcConfigPanel.syncToConfig(config);
else
else if (config.SourceType == SourceType.SIMCONNECT)
simConnectPanel1.syncToConfig(config);
else if (config.SourceType == SourceType.VARIABLE)
variablePanel1.syncToConfig(config);

configRefPanel.syncToConfig(config);

Expand Down Expand Up @@ -1362,6 +1369,7 @@ private void OffsetTypeFsuipRadioButton_CheckedChanged(object sender, EventArgs
{
FsuipcSettingsPanel.Visible = (sender as RadioButton) == OffsetTypeFsuipRadioButton;
simConnectPanel1.Visible = (sender as RadioButton) == OffsetTypeSimConnectRadioButton;
variablePanel1.Visible = (sender as RadioButton) == OffsetTypeVariableRadioButton;
}

private void ConfigWizard_FormClosing(object sender, FormClosingEventArgs e)
Expand Down
Loading

0 comments on commit fca9192

Please sign in to comment.