-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataPluginDemo.cs
108 lines (95 loc) · 4.01 KB
/
DataPluginDemo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using GameReaderCommon;
using SimHub.Plugins;
using System;
using System.Windows.Media;
namespace User.PluginSdkDemo
{
[PluginDescription("My plugin description")]
[PluginAuthor("Author")]
[PluginName("Demo plugin")]
public class DataPluginDemo : IPlugin, IDataPlugin, IWPFSettingsV2
{
public DataPluginDemoSettings Settings;
/// <summary>
/// Instance of the current plugin manager
/// </summary>
public PluginManager PluginManager { get; set; }
/// <summary>
/// Gets the left menu icon. Icon must be 24x24 and compatible with black and white display.
/// </summary>
public ImageSource PictureIcon => this.ToIcon(Properties.Resources.sdkmenuicon);
/// <summary>
/// Gets a short plugin title to show in left menu. Return null if you want to use the title as defined in PluginName attribute.
/// </summary>
public string LeftMenuTitle => "Demo plugin";
/// <summary>
/// Called one time per game data update, contains all normalized game data,
/// raw data are intentionnally "hidden" under a generic object type (A plugin SHOULD NOT USE IT)
///
/// This method is on the critical path, it must execute as fast as possible and avoid throwing any error
///
/// </summary>
/// <param name="pluginManager"></param>
/// <param name="data">Current game data, including current and previous data frame.</param>
public void DataUpdate(PluginManager pluginManager, ref GameData data)
{
// Define the value of our property (declared in init)
if (data.GameRunning)
{
if (data.OldData != null && data.NewData != null)
{
if (data.OldData.SpeedKmh < Settings.SpeedWarningLevel && data.OldData.SpeedKmh >= Settings.SpeedWarningLevel)
{
// Trigger an event
this.TriggerEvent("SpeedWarning");
}
}
}
}
/// <summary>
/// Called at plugin manager stop, close/dispose anything needed here !
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void End(PluginManager pluginManager)
{
// Save settings
this.SaveCommonSettings("GeneralSettings", Settings);
}
/// <summary>
/// Returns the settings control, return null if no settings control is required
/// </summary>
/// <param name="pluginManager"></param>
/// <returns></returns>
public System.Windows.Controls.Control GetWPFSettingsControl(PluginManager pluginManager)
{
return new SettingsControlDemo(this);
}
/// <summary>
/// Called once after plugins startup
/// Plugins are rebuilt at game change
/// </summary>
/// <param name="pluginManager"></param>
public void Init(PluginManager pluginManager)
{
SimHub.Logging.Current.Info("Starting plugin");
// Load settings
Settings = this.ReadCommonSettings<DataPluginDemoSettings>("GeneralSettings", () => new DataPluginDemoSettings());
// Declare a property available in the property list, this gets evaluated "on demand" (when shown or used in formulas)
this.AttachDelegate("CurrentDateTime", () => DateTime.Now);
// Declare an event
this.AddEvent("SpeedWarning");
// Declare an action which can be called
this.AddAction("IncrementSpeedWarning",(a, b) =>
{
Settings.SpeedWarningLevel++;
SimHub.Logging.Current.Info("Speed warning changed");
});
// Declare an action which can be called
this.AddAction("DecrementSpeedWarning", (a, b) =>
{
Settings.SpeedWarningLevel--;
});
}
}
}