Add editor for player promotion levels. Resolves #280
This commit is contained in:
@@ -278,6 +278,9 @@
|
|||||||
<Compile Include="Views\PluginBrowser.xaml.cs">
|
<Compile Include="Views\PluginBrowser.xaml.cs">
|
||||||
<DependentUpon>PluginBrowser.xaml</DependentUpon>
|
<DependentUpon>PluginBrowser.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Views\RoleEditor.xaml.cs">
|
||||||
|
<DependentUpon>RoleEditor.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Views\ThemeControl.xaml.cs">
|
<Compile Include="Views\ThemeControl.xaml.cs">
|
||||||
<DependentUpon>ThemeControl.xaml</DependentUpon>
|
<DependentUpon>ThemeControl.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -462,6 +465,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Views\RoleEditor.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="Views\SessionSettingsView.xaml">
|
<Page Include="Views\SessionSettingsView.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
@@ -99,6 +99,7 @@
|
|||||||
<TextBox Text="{Binding Administrators, Converter={StaticResource ListConverterString}}"
|
<TextBox Text="{Binding Administrators, Converter={StaticResource ListConverterString}}"
|
||||||
Margin="3"
|
Margin="3"
|
||||||
Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto" />
|
Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto" />
|
||||||
|
<Button Content="Edit Roles" Click="RoleEdit_Onlick" Margin="3"/>
|
||||||
<Label Content="Reserved Players" />
|
<Label Content="Reserved Players" />
|
||||||
<TextBox Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"
|
<TextBox Margin="3" Height="100" AcceptsReturn="true" VerticalScrollBarVisibility="Auto"
|
||||||
Style="{StaticResource ValidatedTextBox}">
|
Style="{StaticResource ValidatedTextBox}">
|
||||||
|
@@ -12,6 +12,7 @@ using Torch.API.Managers;
|
|||||||
using Torch.Server.Annotations;
|
using Torch.Server.Annotations;
|
||||||
using Torch.Server.Managers;
|
using Torch.Server.Managers;
|
||||||
using Torch.Server.ViewModels;
|
using Torch.Server.ViewModels;
|
||||||
|
using Torch.Views;
|
||||||
|
|
||||||
namespace Torch.Server.Views
|
namespace Torch.Server.Views
|
||||||
{
|
{
|
||||||
@@ -122,5 +123,13 @@ namespace Torch.Server.Views
|
|||||||
var c = new WorldGeneratorDialog(_instanceManager);
|
var c = new WorldGeneratorDialog(_instanceManager);
|
||||||
c.Show();
|
c.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RoleEdit_Onlick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
//var w = new RoleEditor(_instanceManager.DedicatedConfig.SelectedWorld);
|
||||||
|
//w.Show();
|
||||||
|
var d = new RoleEditor();
|
||||||
|
d.Edit(_instanceManager.DedicatedConfig.SelectedWorld.Checkpoint.PromotedUsers.Dictionary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
Torch.Server/Views/RoleEditor.xaml
Normal file
41
Torch.Server/Views/RoleEditor.xaml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<Window x:Class="Torch.Server.Views.RoleEditor"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Torch.Server.Views"
|
||||||
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||||
|
xmlns:modApi="clr-namespace:VRage.Game.ModAPI;assembly=VRage.Game"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="RoleEditor" Height="300" Width="300">
|
||||||
|
<Window.Resources>
|
||||||
|
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="GetEnumValues">
|
||||||
|
<ObjectDataProvider.MethodParameters>
|
||||||
|
<x:Type TypeName="modApi:MyPromoteLevel"/>
|
||||||
|
</ObjectDataProvider.MethodParameters>
|
||||||
|
</ObjectDataProvider>
|
||||||
|
</Window.Resources>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition />
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<DataGrid x:Name="ItemGrid" AutoGenerateColumns="false" CanUserAddRows="true" Grid.Row="0">
|
||||||
|
<DataGrid.Columns>
|
||||||
|
<DataGridTextColumn Width="5*" Header="Key" Binding="{Binding Key}"/>
|
||||||
|
<DataGridComboBoxColumn Width ="5*" Header="Value" ItemsSource="{Binding Source={StaticResource GetEnumValues}}" SelectedValueBinding="{Binding Value, Mode=TwoWay}"/>
|
||||||
|
</DataGrid.Columns>
|
||||||
|
</DataGrid>
|
||||||
|
<Button Grid.Row="1" Content="Add New" Margin="5" Click="AddNew_OnClick"></Button>
|
||||||
|
<Grid Grid.Row="2">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition />
|
||||||
|
<ColumnDefinition />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Button Grid.Column="0" Content="Cancel" Margin="5" Click="Cancel_OnClick" />
|
||||||
|
<Button Grid.Column="1" Content="OK" Margin="5" Click="Ok_OnClick" />
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Window>
|
||||||
|
|
110
Torch.Server/Views/RoleEditor.xaml.cs
Normal file
110
Torch.Server/Views/RoleEditor.xaml.cs
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using Torch.Server.Managers;
|
||||||
|
using Torch.Views;
|
||||||
|
using VRage.Game.ModAPI;
|
||||||
|
|
||||||
|
namespace Torch.Server.Views
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for RoleEditor.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class RoleEditor : Window
|
||||||
|
{
|
||||||
|
public RoleEditor()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
DataContext = Items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableCollection<IDictionaryItem> Items { get; } = new ObservableCollection<IDictionaryItem>();
|
||||||
|
private Type _itemType;
|
||||||
|
|
||||||
|
private Action _commitChanges;
|
||||||
|
|
||||||
|
public void Edit(IDictionary dict)
|
||||||
|
{
|
||||||
|
Items.Clear();
|
||||||
|
var dictType = dict.GetType();
|
||||||
|
_itemType = typeof(DictionaryItem<,>).MakeGenericType(dictType.GenericTypeArguments[0], dictType.GenericTypeArguments[1]);
|
||||||
|
|
||||||
|
foreach (var key in dict.Keys)
|
||||||
|
{
|
||||||
|
Items.Add((IDictionaryItem)Activator.CreateInstance(_itemType, key, dict[key]));
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemGrid.ItemsSource = Items;
|
||||||
|
|
||||||
|
_commitChanges = () =>
|
||||||
|
{
|
||||||
|
dict.Clear();
|
||||||
|
foreach (var item in Items)
|
||||||
|
{
|
||||||
|
dict[item.Key] = item.Value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Cancel_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Ok_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
_commitChanges?.Invoke();
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IDictionaryItem
|
||||||
|
{
|
||||||
|
object Key { get; set; }
|
||||||
|
object Value { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DictionaryItem<TKey, TValue> : ViewModel, IDictionaryItem
|
||||||
|
{
|
||||||
|
private TKey _key;
|
||||||
|
private TValue _value;
|
||||||
|
|
||||||
|
object IDictionaryItem.Key { get => _key; set => SetValue(ref _key, (TKey)value); }
|
||||||
|
object IDictionaryItem.Value { get => _value; set => SetValue(ref _value, (TValue)value); }
|
||||||
|
|
||||||
|
public TKey Key { get => _key; set => SetValue(ref _key, value); }
|
||||||
|
public TValue Value { get => _value; set => SetValue(ref _value, value); }
|
||||||
|
|
||||||
|
public DictionaryItem()
|
||||||
|
{
|
||||||
|
_key = default(TKey);
|
||||||
|
_value = default(TValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DictionaryItem(TKey key, TValue value)
|
||||||
|
{
|
||||||
|
_key = key;
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddNew_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Items.Add((IDictionaryItem)Activator.CreateInstance(_itemType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user