Skip to content

Commit

Permalink
Merge pull request #127 from amazingalek/dev
Browse files Browse the repository at this point in the history
Input, VR, Steam
  • Loading branch information
Raicuparta authored Jun 28, 2020
2 parents 81f7164 + fbb3165 commit bd3f7cc
Show file tree
Hide file tree
Showing 59 changed files with 2,633 additions and 138 deletions.
1 change: 1 addition & 0 deletions OWML.Common/IModHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IModHelper
IModManifest Manifest { get; }
IModConfig Config { get; }
IOwmlConfig OwmlConfig { get; }
IModInputHandler Input { get; }
IModInteraction Interaction { get; }
}
}
20 changes: 20 additions & 0 deletions OWML.Common/IModInputCombination.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.ObjectModel;
using UnityEngine;

namespace OWML.Common
{
public interface IModInputCombination
{
float LastPressedMoment { get; }
float PressDuration { get; }
string ModName { get; }
string Name { get; }
string FullName { get; }
ReadOnlyCollection<KeyCode> Singles { get; }
ReadOnlyCollection<long> Hashes { get; }
bool IsFirst { get; }

void InternalSetPressed(bool isPressed = true);
}
}
16 changes: 16 additions & 0 deletions OWML.Common/IModInputHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace OWML.Common
{
public interface IModInputHandler
{
IModInputCombination RegisterCombination(IModBehaviour mod, string name, string combination);
void UnregisterCombination(IModInputCombination combo);
bool IsPressedExact(IModInputCombination combo);
bool IsNewlyPressedExact(IModInputCombination combo);
bool WasTappedExact(IModInputCombination combo);
bool WasNewlyReleasedExact(IModInputCombination combo);
bool IsPressed(IModInputCombination combo);
bool IsNewlyPressed(IModInputCombination combo);
bool WasTapped(IModInputCombination combo);
bool WasNewlyReleased(IModInputCombination combo);
}
}
1 change: 1 addition & 0 deletions OWML.Common/IOwmlConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IOwmlConfig
string OutputFilePath { get; }
string LogFilePath { get; }
bool Verbose { get; }
bool BlockInput { get; }
}
}
8 changes: 8 additions & 0 deletions OWML.Common/Menus/IModComboInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OWML.Common.Menus
{
public interface IModComboInput : IModInput<string>
{
IModComboInput Copy();
IModComboInput Copy(string key);
}
}
2 changes: 1 addition & 1 deletion OWML.Common/Menus/IModConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public interface IModConfigMenu : IModPopupMenu
IModData ModData { get; }
IModBehaviour Mod { get; }

void Initialize(Menu modMenuCopy, IModToggleInput toggleTemplate, IModSliderInput sliderTemplate, IModTextInput textInputTemplate, IModNumberInput numberInputTemplate);
void Initialize(Menu modMenuCopy, IModToggleInput toggleTemplate, IModSliderInput sliderTemplate, IModTextInput textInputTemplate, IModNumberInput numberInputTemplate, IModComboInput comboInputTemplate);
}
}
33 changes: 33 additions & 0 deletions OWML.Common/Menus/IModLayoutButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using UnityEngine;
using UnityEngine.UI;

namespace OWML.Common.Menus
{
public interface IModLayoutButton
{
event Action OnClick;
HorizontalLayoutGroup LayoutGroup { get; }
int Index { get; set; }
Button Button { get; }
void UpdateState();
void Initialize(IModMenu menu);

IModLayoutButton Copy();
IModLayoutButton Copy(int index);

IModLayoutButton Duplicate();
IModLayoutButton Duplicate(int index);

IModLayoutButton Replace();
IModLayoutButton Replace(int index);

void Show();
void Hide();

void SetControllerCommand(SingleAxisCommand inputCommand);

void AddText(string text);
void AddPicture(Texture2D texture, float scale = 1.0f);
}
}
2 changes: 2 additions & 0 deletions OWML.Common/Menus/IModMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface IModMenu
IModButton GetButton(string title);
IModButton AddButton(IModButton button);
IModButton AddButton(IModButton button, int index);
IModLayoutButton AddLayoutButton(IModLayoutButton button);
IModLayoutButton AddLayoutButton(IModLayoutButton button, int index);

List<IModToggleInput> ToggleInputs { get; }
IModToggleInput GetToggleInput(string title);
Expand Down
2 changes: 1 addition & 1 deletion OWML.Common/Menus/IModPauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface IModPauseMenu : IModPopupMenu
{
IModTabbedMenu OptionsMenu { get; }

IModButton ResumeButton { get; }
IModButton OptionsButton { get; }
IModButton QuitButton { get; }
Expand Down
4 changes: 4 additions & 0 deletions OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
<Compile Include="IHarmonyHelper.cs" />
<Compile Include="IModAssets.cs" />
<Compile Include="IModAsset.cs" />
<Compile Include="IModInputCombination.cs" />
<Compile Include="IModInputHandler.cs" />
<Compile Include="IModInteraction.cs" />
<Compile Include="Menus\IModLayoutButton.cs" />
<Compile Include="Menus\IModComboInput.cs" />
<Compile Include="Menus\InputType.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="IModConfig.cs" />
Expand Down
4 changes: 2 additions & 2 deletions OWML.GameFinder/PathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public PathFinder(IOwmlConfig config, IModConsole writer)
public string FindGamePath()
{
return FindPathWith<CurrentPathFinder>() ??
FindPathWith<DefaultLocationFinder>() ??
FindPathWith<EpicGameFinder>() ??
FindPathWith<SteamGameFinder>() ??
FindPathWith<EpicGameFinder>() ??
FindPathWith<DefaultLocationFinder>() ??
FindPathWith<PromptGameFinder>();
}

Expand Down
9 changes: 8 additions & 1 deletion OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@ private void PatchGame(IList<IModData> mods)
var vrMod = mods.FirstOrDefault(x => x.Config.RequireVR && x.Config.Enabled);
var enableVR = vrMod != null;
_writer.WriteLine(enableVR ? $"{vrMod.Manifest.UniqueName} requires VR." : "No mods require VR.");
_vrPatcher.PatchVR(enableVR);
try
{
_vrPatcher.PatchVR(enableVR);
}
catch (Exception ex)
{
_writer.WriteLine($"Error while applying VR patch: {ex}");
}
}

private void StartGame(string[] args)
Expand Down
5 changes: 3 additions & 2 deletions OWML.Launcher/OWML.Config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"gamePath": "C:/Program Files/Epic Games/OuterWilds",
"verbose": false
}
"verbose": false,
"combinationsBlockInput" : false
}
2 changes: 1 addition & 1 deletion OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "0.3.56",
"version": "0.3.57",
"description": "The mod loader and mod framework for Outer Wilds"
}
2 changes: 1 addition & 1 deletion OWML.ModHelper.Events/ModEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ModEvents : IModEvents
private readonly IHarmonyHelper _harmonyHelper;
private readonly IModConsole _console;
private readonly IModLogger _logger;

public ModEvents(IModLogger logger, IModConsole console, IHarmonyHelper harmonyHelper)
{
_logger = logger;
Expand Down
59 changes: 59 additions & 0 deletions OWML.ModHelper.Input/BindingChangeListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using OWML.Common;
using UnityEngine;

namespace OWML.ModHelper.Input
{
public class BindingChangeListener : MonoBehaviour
{
private ModInputHandler _inputHandler;
private bool _updateInputsNext, _updateInputs;

internal void Initialize(ModInputHandler inputHandler, IModEvents events)
{
_inputHandler = inputHandler;
events.Subscribe<TitleScreenManager>(Common.Events.AfterStart);
events.OnEvent += OnEvent;
}

private void OnEvent(MonoBehaviour behaviour, Common.Events ev)
{
if (behaviour.GetType() == typeof(TitleScreenManager) && ev == Common.Events.AfterStart)
{
_updateInputsNext = true;
}
}

private void Start()
{
DontDestroyOnLoad(gameObject);
GlobalMessenger.AddListener("KeyBindingsChanged", new Callback(PrepareForUpdate));
}

private void PrepareForUpdate()
{
_updateInputsNext = true;
}

private void Update()
{
if (_updateInputs)
{
_updateInputs = false;
UpdateInputs();
}
if (_updateInputsNext)
{
_updateInputs = true;
_updateInputsNext = false;
}
}

public void UpdateInputs()
{
_inputHandler.UpdateGamesBindings();
}
}
}
74 changes: 74 additions & 0 deletions OWML.ModHelper.Input/InputInterceptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using UnityEngine;
using System.Collections.Generic;

namespace OWML.ModHelper.Input
{
internal class InputInterceptor
{
public static void SingleAxisUpdatePost(
SingleAxisCommand __instance,
ref float ____value,
List<KeyCode> ____posKeyCodes,
List<KeyCode> ____negKeyCodes
)
{
foreach (var key in ____posKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value = 0f;
}
}
foreach (var key in ____negKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value = 0f;
}
}
}

public static void DoubleAxisUpdatePost(
DoubleAxisCommand __instance,
ref Vector2 ____value,
List<KeyCode> ____posXKeyCodes,
List<KeyCode> ____negXKeyCodes,
List<KeyCode> ____posYKeyCodes,
List<KeyCode> ____negYKeyCodes
)
{
if (OWInput.UsingGamepad())
{
return;
}
foreach (var key in ____posXKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value.x = 0f;
}
}
foreach (var key in ____negXKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value.x = 0f;
}
}
foreach (var key in ____posYKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value.y = 0f;
}
}
foreach (var key in ____negYKeyCodes)
{
if (ModInputHandler.Instance.IsPressedAndIgnored(key))
{
____value.y = 0f;
}
}
}
}
}
Loading

0 comments on commit bd3f7cc

Please sign in to comment.