Skip to content

Commit a34ccb8

Browse files
committed
Added control
1 parent 89386c1 commit a34ccb8

File tree

5 files changed

+131
-5
lines changed

5 files changed

+131
-5
lines changed

StaticMarker/MarkerConfig.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Torch;
7+
8+
namespace StaticMarker
9+
{
10+
public class MarkerConfig : ViewModel
11+
{
12+
private bool _sendMarkerOnJoin = true;
13+
public bool SendMarkerOnJoin { get => _sendMarkerOnJoin; set => SetValue(ref _sendMarkerOnJoin, value); }
14+
}
15+
}

StaticMarker/MarkerControl.xaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<UserControl x:Class="StaticMarker.MarkerControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:StaticMarker"
7+
mc:Ignorable="d"
8+
d:DesignHeight="890" d:DesignWidth="800">
9+
<StackPanel>
10+
<CheckBox Content="Test" Margin="3" IsChecked="{Binding SendMarkerOnJoin}" />
11+
12+
<Label Height="20">
13+
<LineBreak/>
14+
</Label>
15+
<StackPanel Orientation="Horizontal">
16+
<Button Width="180" Content="Save Config" Click="SaveConfig_OnClick" Margin="3" />
17+
</StackPanel>
18+
</StackPanel>
19+
</UserControl>

StaticMarker/MarkerControl.xaml.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Data;
6+
7+
namespace StaticMarker
8+
{
9+
/// <summary>
10+
/// Interaktionslogik für RoleControl.xaml
11+
/// </summary>
12+
public partial class MarkerControl : UserControl
13+
{
14+
private MarkerPlugin Plugin { get; }
15+
16+
public MarkerControl()
17+
{
18+
InitializeComponent();
19+
}
20+
21+
public MarkerControl(MarkerPlugin plugin) : this()
22+
{
23+
Plugin = plugin;
24+
DataContext = plugin.Config;
25+
}
26+
27+
private void SaveConfig_OnClick(object sender, RoutedEventArgs e)
28+
{
29+
Plugin.Save();
30+
}
31+
}
32+
33+
public class RadioBoolToIntConverter : IValueConverter
34+
{
35+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
36+
{
37+
int integer = (int)value;
38+
if (integer == int.Parse(parameter.ToString()))
39+
return true;
40+
else
41+
return false;
42+
}
43+
44+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
45+
{
46+
return parameter;
47+
}
48+
}
49+
}

StaticMarker/MarkerPlugin.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,37 @@
44
using Sandbox.ModAPI;
55
using System;
66
using System.IO;
7+
using System.Windows.Controls;
78
using Torch;
89
using Torch.API;
910
using Torch.API.Managers;
11+
using Torch.API.Plugins;
1012
using Torch.API.Session;
1113
using Torch.Session;
1214

1315
namespace StaticMarker
1416
{
15-
public class MarkerPlugin : TorchPluginBase
17+
public class MarkerPlugin : TorchPluginBase, IWpfPlugin
1618
{
17-
const string ConfigMarkers = "StaticMarkerEntries.cfg";
19+
const string ConfigFile = "StaticMarkerEntries.cfg";
20+
const string ConfigMarkersFile = "StaticMarkerEntries.cfg";
1821

22+
private MarkerControl _control;
1923
private TorchSessionManager _sessionManager;
2024
private IMultiplayerManagerBase _multibase;
25+
private Persistent<MarkerConfig> _config;
2126
private MarkerEntriesConfig _entriesConfig;
2227

2328
public static readonly Logger Log = LogManager.GetCurrentClassLogger();
29+
public MarkerConfig Config => _config?.Data;
2430

2531
/// <inheritdoc />
26-
public override void Init(ITorchBase torch)
32+
public UserControl GetControl() => _control ?? (_control = new MarkerControl(this));
33+
34+
public void Save() => _config.Save();
35+
36+
/// <inheritdoc />
37+
public override void Init(ITorchBase torch)
2738
{
2839
base.Init(torch);
2940

@@ -33,6 +44,19 @@ public override void Init(ITorchBase torch)
3344
else
3445
Log.Warn("No session manager loaded!");
3546

47+
var configFile = Path.Combine(StoragePath, ConfigFile);
48+
try
49+
{
50+
_config = Persistent<MarkerConfig>.Load(configFile);
51+
}
52+
catch (Exception e)
53+
{
54+
Log.Warn(e);
55+
}
56+
57+
if (_config?.Data == null)
58+
_config = new Persistent<MarkerConfig>(configFile, new MarkerConfig());
59+
3660
LoadConfig();
3761
}
3862

@@ -57,7 +81,7 @@ private void SessionChanged(ITorchSession session, TorchSessionState state)
5781
internal bool LoadConfig()
5882
{
5983
var success = false;
60-
var configFile = Path.Combine(StoragePath, ConfigMarkers);
84+
var configFile = Path.Combine(StoragePath, ConfigMarkersFile);
6185
try
6286
{
6387
_entriesConfig = Persistent<MarkerEntriesConfig>.Load(configFile).Data;
@@ -67,6 +91,10 @@ internal bool LoadConfig()
6791
{
6892
Log.Warn(e);
6993
}
94+
95+
if (_config?.Data == null)
96+
_entriesConfig = new Persistent<MarkerEntriesConfig>(configFile, new MarkerEntriesConfig()).Data;
97+
7098
return success;
7199
}
72100

@@ -80,7 +108,8 @@ private void _multibase_PlayerJoined(IPlayer obj)
80108
return;
81109
}
82110

83-
SendGPSEntries(idendity);
111+
if (Config.SendMarkerOnJoin)
112+
SendGPSEntries(idendity);
84113
}
85114

86115
internal void SendGPSEntries(long identityId)

StaticMarker/StaticMarker.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<Reference Include="NLog">
3535
<HintPath>..\TorchBinaries\NLog.dll</HintPath>
3636
</Reference>
37+
<Reference Include="PresentationCore" />
38+
<Reference Include="PresentationFramework" />
3739
<Reference Include="Sandbox.Common">
3840
<HintPath>..\GameBinaries\Sandbox.Common.dll</HintPath>
3941
</Reference>
@@ -42,6 +44,7 @@
4244
</Reference>
4345
<Reference Include="System" />
4446
<Reference Include="System.Core" />
47+
<Reference Include="System.Xaml" />
4548
<Reference Include="System.Xml.Linq" />
4649
<Reference Include="System.Data.DataSetExtensions" />
4750
<Reference Include="Microsoft.CSharp" />
@@ -63,12 +66,23 @@
6366
<Reference Include="VRage.Math">
6467
<HintPath>..\GameBinaries\VRage.Math.dll</HintPath>
6568
</Reference>
69+
<Reference Include="WindowsBase" />
6670
</ItemGroup>
6771
<ItemGroup>
6872
<Compile Include="MarkerCommands.cs" />
73+
<Compile Include="MarkerConfig.cs" />
6974
<Compile Include="MarkerEntriesConfig.cs" />
7075
<Compile Include="MarkerPlugin.cs" />
7176
<Compile Include="Properties\AssemblyInfo.cs" />
77+
<Compile Include="MarkerControl.xaml.cs">
78+
<DependentUpon>MarkerControl.xaml</DependentUpon>
79+
</Compile>
80+
</ItemGroup>
81+
<ItemGroup>
82+
<Page Include="MarkerControl.xaml">
83+
<Generator>MSBuild:Compile</Generator>
84+
<SubType>Designer</SubType>
85+
</Page>
7286
</ItemGroup>
7387
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7488
</Project>

0 commit comments

Comments
 (0)