2022-11-24 22:37:24 +01:00
|
|
|
using static CommonHelpers.Log;
|
|
|
|
|
|
2022-11-25 10:56:17 +01:00
|
|
|
namespace SteamController
|
2022-11-24 22:37:24 +01:00
|
|
|
{
|
2022-11-25 10:56:17 +01:00
|
|
|
public partial class Context : IDisposable
|
2022-11-24 22:37:24 +01:00
|
|
|
{
|
|
|
|
|
public const double JoystickToMouseSensitivity = 1200;
|
2022-11-25 10:56:17 +01:00
|
|
|
public const double PadToMouseSensitivity = 150;
|
2022-11-25 07:48:01 +01:00
|
|
|
public const double PadToWhellSensitivity = 4;
|
2022-11-27 15:32:23 +01:00
|
|
|
public const double ThumbToWhellSensitivity = 20;
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
public Devices.SteamController Steam { get; private set; }
|
|
|
|
|
public Devices.Xbox360Controller X360 { get; private set; }
|
|
|
|
|
public Devices.KeyboardController Keyboard { get; private set; }
|
|
|
|
|
public Devices.MouseController Mouse { get; private set; }
|
|
|
|
|
|
2022-11-25 10:56:17 +01:00
|
|
|
public List<Profiles.Profile> Profiles { get; } = new List<Profiles.Profile>();
|
|
|
|
|
public List<Managers.Manager> Managers { get; } = new List<Managers.Manager>();
|
|
|
|
|
|
2022-11-28 10:14:05 +01:00
|
|
|
private List<Profiles.Profile>? orderedProfiles;
|
2022-11-24 22:37:24 +01:00
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
public bool RequestEnable { get; set; } = true;
|
2022-11-24 22:37:24 +01:00
|
|
|
public bool RequestDesktopMode { get; set; } = true;
|
2022-11-27 13:41:28 +01:00
|
|
|
public bool SteamUsesX360Controller { get; set; } = false;
|
|
|
|
|
public bool SteamUsesSteamInput { get; set; } = false;
|
2022-11-25 07:48:01 +01:00
|
|
|
|
2022-11-26 14:27:21 +01:00
|
|
|
public event Action<Profiles.Profile> ProfileChanged;
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
public bool Enabled
|
|
|
|
|
{
|
2022-11-25 10:56:17 +01:00
|
|
|
get { return RequestEnable; }
|
2022-11-25 07:48:01 +01:00
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
public bool DesktopMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return RequestDesktopMode || !X360.Valid || !Mouse.Valid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 10:56:17 +01:00
|
|
|
public List<Profiles.Profile> OrderedProfiles
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (orderedProfiles == null)
|
|
|
|
|
orderedProfiles = Profiles.ToList();
|
|
|
|
|
return orderedProfiles;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
public Context()
|
|
|
|
|
{
|
|
|
|
|
Steam = new Devices.SteamController();
|
|
|
|
|
X360 = new Devices.Xbox360Controller();
|
|
|
|
|
Keyboard = new Devices.KeyboardController();
|
|
|
|
|
Mouse = new Devices.MouseController();
|
2022-11-26 14:27:21 +01:00
|
|
|
|
|
|
|
|
ProfileChanged += (_) => X360.Beep();
|
2022-11-24 22:37:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
using (Steam) { }
|
|
|
|
|
using (X360) { }
|
|
|
|
|
using (Keyboard) { }
|
|
|
|
|
using (Mouse) { }
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
public void Tick()
|
|
|
|
|
{
|
|
|
|
|
X360.Tick();
|
|
|
|
|
|
2022-11-25 10:56:17 +01:00
|
|
|
foreach (var manager in Managers)
|
2022-11-25 07:48:01 +01:00
|
|
|
{
|
2022-11-25 10:56:17 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
manager.Tick(this);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2022-11-27 15:32:23 +01:00
|
|
|
TraceLine("Manager: {0}. Exception: {1}", manager, e);
|
2022-11-25 10:56:17 +01:00
|
|
|
}
|
2022-11-25 07:48:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 21:28:43 +01:00
|
|
|
public Profiles.Profile? GetCurrentProfile()
|
|
|
|
|
{
|
|
|
|
|
foreach (var profile in OrderedProfiles)
|
|
|
|
|
{
|
|
|
|
|
if (profile.Selected(this))
|
|
|
|
|
{
|
|
|
|
|
return profile;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
public bool Update()
|
|
|
|
|
{
|
|
|
|
|
Steam.BeforeUpdate();
|
|
|
|
|
X360.BeforeUpdate();
|
|
|
|
|
Keyboard.BeforeUpdate();
|
|
|
|
|
Mouse.BeforeUpdate();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-11-25 21:28:43 +01:00
|
|
|
var profile = GetCurrentProfile();
|
|
|
|
|
if (profile is not null)
|
2022-11-24 22:37:24 +01:00
|
|
|
{
|
2022-11-25 21:28:43 +01:00
|
|
|
profile.Run(this);
|
2022-11-24 22:37:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
TraceLine("Controller: Exception: {0}", e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Steam.Update();
|
|
|
|
|
X360.Update();
|
|
|
|
|
Keyboard.Update();
|
|
|
|
|
Mouse.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-25 10:56:17 +01:00
|
|
|
|
|
|
|
|
public Profiles.Profile? FindProfile(String name)
|
|
|
|
|
{
|
|
|
|
|
return Profiles.Find((profile) => profile.Name == name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SelectProfile(String name, bool enable = true)
|
|
|
|
|
{
|
|
|
|
|
var profile = FindProfile(name);
|
|
|
|
|
if (profile is null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var list = OrderedProfiles;
|
|
|
|
|
list.Remove(profile);
|
|
|
|
|
list.Insert(0, profile);
|
2022-11-25 21:28:43 +01:00
|
|
|
RequestDesktopMode = profile.IsDesktop;
|
2022-11-26 14:27:21 +01:00
|
|
|
|
|
|
|
|
if (profile.Selected(this))
|
|
|
|
|
ProfileChanged(profile);
|
2022-11-25 10:56:17 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SelectNext()
|
|
|
|
|
{
|
|
|
|
|
bool firstSelected = false;
|
|
|
|
|
|
|
|
|
|
var list = OrderedProfiles;
|
|
|
|
|
foreach (var profile in list)
|
|
|
|
|
{
|
|
|
|
|
if (!profile.Selected(this))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!firstSelected)
|
|
|
|
|
{
|
|
|
|
|
firstSelected = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.Remove(profile);
|
|
|
|
|
list.Insert(0, profile);
|
2022-11-26 14:27:21 +01:00
|
|
|
ProfileChanged(profile);
|
2022-11-25 10:56:17 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-11-25 21:28:43 +01:00
|
|
|
|
2022-11-26 14:27:21 +01:00
|
|
|
public void ToggleDesktopMode(bool? forceState = null)
|
2022-11-25 21:28:43 +01:00
|
|
|
{
|
2022-11-26 14:27:21 +01:00
|
|
|
var oldProfile = GetCurrentProfile();
|
|
|
|
|
if (forceState is null)
|
|
|
|
|
RequestDesktopMode = !RequestDesktopMode;
|
|
|
|
|
else
|
|
|
|
|
RequestDesktopMode = forceState.Value;
|
|
|
|
|
|
|
|
|
|
var newProfile = GetCurrentProfile();
|
|
|
|
|
if (oldProfile != newProfile && newProfile is not null)
|
|
|
|
|
ProfileChanged(newProfile);
|
2022-11-25 21:28:43 +01:00
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
}
|
|
|
|
|
}
|