Skip to content

Commit

Permalink
UI Added
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTylus committed May 21, 2019
1 parent 16a84c9 commit c4329fe
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 12 deletions.
13 changes: 13 additions & 0 deletions ALE-ShipFixer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<Reference Include="NLog">
<HintPath>..\..\Server\torch-server\NLog.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Sandbox.Common">
<HintPath>..\..\Server\torch-server\DedicatedServer64\Sandbox.Common.dll</HintPath>
</Reference>
Expand All @@ -60,6 +62,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -93,13 +96,23 @@
<Reference Include="VRage.Math">
<HintPath>..\..\Server\torch-server\DedicatedServer64\VRage.Math.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands.cs" />
<Compile Include="Control.xaml.cs">
<DependentUpon>Control.xaml</DependentUpon>
</Compile>
<Compile Include="CurrentCooldown.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShipFixerConfig.cs" />
<Compile Include="ShipFixerPlugin.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Control.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
14 changes: 7 additions & 7 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void FixShipPlayerGridName(string gridName) {

} else {

currentCooldown = new CurrentCooldown(Plugin.Cooldown);
currentCooldown = new CurrentCooldown();
currentCooldownMap.Add(playerId, currentCooldown);
}

Expand All @@ -150,7 +150,7 @@ public void FixShipPlayerGridName(string gridName) {
if (Plugin.fixShip(gridName, playerId, Context)) {

Log.Info("Cooldown for Player " + player + " started!");
currentCooldown.startCooldown(null);
currentCooldown.startCooldown(null, Plugin.Cooldown);
}

} catch (Exception e) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public void FixShipPlayerLookAt() {

} else {

currentCooldown = new CurrentCooldown(Plugin.Cooldown);
currentCooldown = new CurrentCooldown();
currentCooldownMap.Add(playerId, currentCooldown);
}

Expand All @@ -208,7 +208,7 @@ public void FixShipPlayerLookAt() {
if (Plugin.fixShip(character, playerId, Context)) {

Log.Info("Cooldown for Player " + player + " started!");
currentCooldown.startCooldown(null);
currentCooldown.startCooldown(null, Plugin.Cooldown);
}

} catch (Exception e) {
Expand All @@ -232,7 +232,7 @@ private bool checkConformation(long executingPlayerId, long playerId, string gri
return false;

Context.Respond("Are you sure you want to continue? Enter the command again within " + Plugin.CooldownConfirmationSeconds + " seconds to confirm.");
confirmationCooldown.startCooldown(gridName);
confirmationCooldown.startCooldown(gridName, Plugin.CooldownConfirmation);
return false;
}

Expand All @@ -242,12 +242,12 @@ private bool checkConformation(long executingPlayerId, long playerId, string gri
if (!checkGridFound(playerId, gridName, character))
return false;

confirmationCooldown = new CurrentCooldown(Plugin.CooldownConfirmation);
confirmationCooldown = new CurrentCooldown();
confirmationCooldownMap.Add(executingPlayerId, confirmationCooldown);

Context.Respond("Are you sure you want to continue? Enter the command again within " + Plugin.CooldownConfirmationSeconds + " seconds to confirm.");

confirmationCooldown.startCooldown(gridName);
confirmationCooldown.startCooldown(gridName, Plugin.CooldownConfirmation);
return false;
}

Expand Down
48 changes: 48 additions & 0 deletions Control.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<UserControl x:Class="ALE_ShipFixer.Control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="Labels"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="Buttons"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Grid.Column="0" Grid.Row ="0" VerticalAlignment="Center" Text="ALE Shipfixer" FontWeight="Bold" FontSize="16" Grid.ColumnSpan="2" Margin="5"/>

<TextBlock Grid.Column="0" Grid.Row ="1" VerticalAlignment="Center" Text="Command cooldown for player (seconds)" Margin="5"/>
<TextBox Name="CommandCooldown" Grid.Column="1" Grid.Row ="1" Grid.ColumnSpan="2" Margin="5" Text="{Binding CooldownInSeconds}"/>

<TextBlock Grid.Column="0" Grid.Row ="2" VerticalAlignment="Center" Text="Confirmaton cooldown (seconds)" Margin="5"/>
<TextBox Name="ConfirmationCooldown" Grid.Column="1" Grid.Row ="2" Grid.ColumnSpan="2" Margin="5" Text="{Binding ConfirmationInSeconds}"/>

<Button Grid.Column="2" Grid.Row="3" Content="Save Config" Margin="5" Click="SaveButton_OnClick"></Button>

<TextBlock Grid.Column="0" Grid.Row ="4" VerticalAlignment="Center" Grid.ColumnSpan="2" Text="Commands" Margin="5" FontWeight="Bold" />
<TextBlock Grid.Column="0" Grid.Row ="5" VerticalAlignment="Center" Text="!fixship" Margin="5" />
<TextBlock Grid.Column="1" Grid.Row ="5" VerticalAlignment="Center" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="Cuts and pastes ship you are looking at (accessible to all)" Margin="5"/>
<TextBlock Grid.Column="0" Grid.Row ="6" VerticalAlignment="Center" Text="!fixship &lt;shipname&gt;" Margin="5"/>
<TextBlock Grid.Column="1" Grid.Row ="6" VerticalAlignment="Center" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="Cuts and pastes ship you are looking at by given name (accessible to all)" Margin="5"/>
<TextBlock Grid.Column="0" Grid.Row ="7" VerticalAlignment="Center" Text="!fixshipmod" Margin="5"/>
<TextBlock Grid.Column="1" Grid.Row ="7" VerticalAlignment="Center" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="Cuts and pastes ship you are looking at while ignoring coolodnws (accessible to moderator and above)" Margin="5"/>
<TextBlock Grid.Column="0" Grid.Row ="8" VerticalAlignment="Center" Text="!fixshipmod &lt;shipname&gt;" Margin="5"/>
<TextBlock Grid.Column="1" Grid.Row ="8" VerticalAlignment="Center" Grid.ColumnSpan="2" TextWrapping="Wrap" Text="Cuts and pastes ship by given name while ignoring coolodnws (accessible to moderator and above)" Margin="5"/>
</Grid>
</UserControl>
35 changes: 35 additions & 0 deletions Control.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;

namespace ALE_ShipFixer {

public partial class Control : UserControl {

private ShipFixerPlugin Plugin { get; }

public Control() {
InitializeComponent();
}

public Control(ShipFixerPlugin plugin) : this() {
Plugin = plugin;
DataContext = plugin.Config;
}

private void SaveButton_OnClick(object sender, RoutedEventArgs e) {
Plugin.Save();
}
}
}
5 changes: 1 addition & 4 deletions CurrentCooldown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ public class CurrentCooldown {

private String command;

public CurrentCooldown(long cooldown) {
public void startCooldown(string command, long cooldown) {
this._currentCooldown = cooldown;
}

public void startCooldown(String command) {
this.command = command;
this._startTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
}
Expand Down
17 changes: 16 additions & 1 deletion ShipFixerPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
using System.IO;
using System;
using System.Linq;
using Torch.API.Plugins;
using System.Windows.Controls;

namespace ALE_ShipFixer {

public class ShipFixerPlugin : TorchPluginBase {
public class ShipFixerPlugin : TorchPluginBase, IWpfPlugin {

public static readonly Logger Log = LogManager.GetCurrentClassLogger();

private Dictionary<long, CurrentCooldown> _currentCooldownMap = new Dictionary<long, CurrentCooldown>();
private Dictionary<long, CurrentCooldown> _confirmations = new Dictionary<long, CurrentCooldown>();

private Control _control;
public UserControl GetControl() => _control ?? (_control = new Control(this));


private Persistent<ShipFixerConfig> _config;
public ShipFixerConfig Config => _config?.Data;

Expand Down Expand Up @@ -60,7 +66,16 @@ public override void Init(ITorchBase torch) {
Log.Info("Create Default Config, because none was found!");

_config = new Persistent<ShipFixerConfig>(configFile, new ShipFixerConfig());
Save();
}
}

public void Save() {
try {
_config.Save();
Log.Info("Configuration Saved.");
} catch (IOException) {
Log.Warn("Configuration failed to save");
}
}

Expand Down

0 comments on commit c4329fe

Please sign in to comment.