Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Torch.API/ITorchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ public interface ITorchConfig
string ChatColor { get; set; }
string TestPlugin { get; set; }
bool DisconnectOnRestart { get; set; }
bool SaveWindowChanges { get; set; }
int WindowWidth { get; set; }
int WindowHeight { get; set; }
int WindowX { get; set; }
int WindowY { get; set; }
int FontSize { get; set; }
bool StartMinimized { get; set; }
bool MinimizeOnServerStart { get; set; }
UGCServiceType UgcServiceType { get; set; }
TorchBranchType BranchName { get; set; }
bool SendLogsToKeen { get; set; }
Expand Down
29 changes: 23 additions & 6 deletions Torch.Server/TorchConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
using System.ComponentModel;
using System.IO;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Xml.Serialization;
using Newtonsoft.Json;
using NLog;
using Torch.API;
using Torch.Views;
using VRage.Game;

namespace Torch.Server
{
Expand Down Expand Up @@ -37,8 +34,13 @@ public class TorchConfig : CommandLine, ITorchConfig, INotifyPropertyChanged
private string _chatColor = "Red";
private bool _enableWhitelist = false;
private List<ulong> _whitelist = new List<ulong>();
private int _windowWidth = 980;
private int _windowHeight = 588;
private bool _saveWindowChanges = true;
private bool _startMinimized = false;
private bool _minimizeOnServerStart = false;
private int _windowWidth;
private int _windowHeight;
private int _windowX;
private int _windowY;
private bool _independentConsole = false;
private bool _enableAsserts = false;
private int _fontSize = 16;
Expand Down Expand Up @@ -153,11 +155,26 @@ public string InstancePath
[Display(Name = "Whitelist", Description = "Collection of whitelisted steam ids.", GroupName = "In-Game")]
public List<ulong> Whitelist { get => _whitelist; set => Set(value, ref _whitelist); }

[Display(Name = "Save Window Changes", Description = "Save window size and location.", GroupName = "Window")]
public bool SaveWindowChanges { get => _saveWindowChanges; set => Set(value, ref _saveWindowChanges); }

[Display(Name = "Start Minimized", Description = "Start Torch minimized.", GroupName = "Window")]
public bool StartMinimized { get => _startMinimized; set => Set(value, ref _startMinimized); }

[Display(Name = "Minimize On Server Start", Description = "Minimize Torch window on server start.", GroupName = "Window")]
public bool MinimizeOnServerStart { get => _minimizeOnServerStart; set => Set(value, ref _minimizeOnServerStart); }

[Display(Name = "Width", Description = "Default window width.", GroupName = "Window")]
public int WindowWidth { get => _windowWidth; set => Set(value, ref _windowWidth); }

[Display(Name = "Height", Description = "Default window height", GroupName = "Window")]
public int WindowHeight { get => _windowHeight; set => Set(value, ref _windowHeight); }

[Display(Name = "WindowX", Description = "Default window X position", GroupName = "Window")]
public int WindowX { get => _windowX; set => Set(value, ref _windowX); }

[Display(Name = "WindowY", Description = "Default window Y position", GroupName = "Window")]
public int WindowY { get => _windowY; set => Set(value, ref _windowY); }

[Display(Name = "Font Size", Description = "Font size for logging text box. (default is 16)", GroupName = "Window")]
public int FontSize { get => _fontSize; set => Set(value, ref _fontSize); }
Expand All @@ -176,7 +193,7 @@ public TorchBranchType BranchName
set => Set(value, ref _torchBranch);
}

public string LastUsedTheme { get; set; } = "Torch Theme";
public string LastUsedTheme { get; set; } = "Torch Theme";

//Prevent reserved players being written to disk, but allow it to be read
//remove this when ReservedPlayers is removed
Expand Down
64 changes: 60 additions & 4 deletions Torch.Server/Views/TorchUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
Expand All @@ -22,7 +24,10 @@
using Torch.API.Managers;
using Torch.Patches;
using Torch.Server.Managers;
using MessageBox = System.Windows.MessageBox;
using MessageBoxResult = System.Windows.MessageBoxResult;
using Rectangle = System.Drawing.Rectangle;
using TextBox = System.Windows.Controls.TextBox;

namespace Torch.Server
{
Expand All @@ -41,12 +46,11 @@ public partial class TorchUI : Window
private System.Windows.Forms.Timer _scrollTimer;
public TorchUI(TorchServer server)
{
WindowStartupLocation = WindowStartupLocation.Manual;
_config = (TorchConfig)server.Config;
Width = _config.WindowWidth;
Height = _config.WindowHeight;
WindowStartupLocation = WindowStartupLocation.Manual;

_server = server;
//TODO: data binding for whole server
// TODO: data binding for whole server
DataContext = server;
InitializeComponent();

Expand Down Expand Up @@ -91,6 +95,58 @@ private void TorchUI_Loaded(object sender, RoutedEventArgs e)
_scrollTimer.Tick += ScrollIfNeed;
_scrollTimer.Interval = 120;
_scrollTimer.Start();

// Set the default window size if no position is saved
if ( _config.WindowWidth == 0 || _config.WindowHeight == 0)
{
Width = 980;
Height = 588;
}
else
{
Width = _config.WindowWidth;
Height = _config.WindowHeight;
}

// Only restore if visible on a screen, otherwise let windows position it.
const int tolerance = 10;
var rect = new Rectangle(_config.WindowX, _config.WindowY, _config.WindowWidth, _config.WindowHeight);
if (Screen.AllScreens.Any(s =>
{
Rectangle area = s.WorkingArea;
area.Inflate(tolerance, tolerance);
return area.Contains(rect);
}))
{
Left = _config.WindowX;
Top = _config.WindowY;
}

LocationChanged += (_, args) =>
{
if (!_config.SaveWindowChanges) return;
_config.WindowX = (int)Top;
_config.WindowY = (int)Left;
_config.Save();
};
SizeChanged += (_, args) =>
{
if (!_config.SaveWindowChanges) return;
_config.WindowHeight = (int)args.NewSize.Height;
_config.WindowWidth = (int)args.NewSize.Width;
};

if (_config.StartMinimized)
WindowState = WindowState.Minimized;

_server.GameStateChanged += (game, state) =>
{
if (state == TorchGameState.Loaded && _config.MinimizeOnServerStart)
BtnStart.Dispatcher.Invoke(() => // Cheap way to get to UI thread
{
WindowState = WindowState.Minimized;
});
};
}

private void ScrollIfNeed(object sender, EventArgs e)
Expand Down