Skip to content

Commit

Permalink
Merge pull request #77 from Vivero/version-3
Browse files Browse the repository at this point in the history
Bug fix for missing VR hands (gloves)
  • Loading branch information
Vivero committed Jun 8, 2019
2 parents 3dc0262 + 4a5cc81 commit 1f474b0
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 240 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PROP
{
name = Primitive_BOX_Beveled_Black

MODEL
{
model = KerbalVR/Assets/Props/Misc/Primitives/Primitive_BOX_Beveled
texture = Primitive_Black,KerbalVR/Assets/Props/Misc/Primitives/Primitive_Black
}
}

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions KerbalVR/Assets/Settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"initOpenVrAtStartup": true,
"swapYawRollControls": false
}
File renamed without changes
3 changes: 1 addition & 2 deletions KerbalVR/Components/KVR_AvionicsComputer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class KVR_AvionicsComputer : MonoBehaviour
private Events.Action precisionModeUpdatedAction;

void Awake() {
Utils.Log("KVR_AvionicsComputer booting up.");

// start emitting signals to components
outputSignalsCoroutine = StartCoroutine(OutputSignals());

stageUpdatedAction = KerbalVR.Events.AvionicsIntAction("stage", OnStageInput);
Expand Down
2 changes: 1 addition & 1 deletion KerbalVR/Components/KVR_Cover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum FSMState {
try {
SoundEffect = ConfigUtils.SetupAudioClip(prop, configuration, "sound");
} catch (Exception e) {
Utils.LogWarning(e.ToString());
// specifying a sound should be optional, so catch the error but don't print any warnings.
}

// set initial state
Expand Down
5 changes: 3 additions & 2 deletions KerbalVR/KerbalVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="Components\KVR_Switch.cs" />
<Compile Include="Components\KVR_SwitchTwoState.cs" />
<Compile Include="Components\KVR_SwitchThreeState.cs" />
<Compile Include="KerbalVR_Configuration.cs" />
<Compile Include="KerbalVR_Core.cs" />
<Compile Include="KerbalVR_AppGUI.cs" />
<Compile Include="KerbalVR_AssetLoader.cs" />
Expand Down Expand Up @@ -119,8 +120,8 @@ robocopy "$(ProjectDir)lib" "$(TargetDir)\rel\GameData\KerbalVR\openvr" /E
robocopy "$(ProjectDir)Assets" "$(TargetDir)\rel\GameData\KerbalVR\Assets" /E

:: Copy release into KSP directory
if EXIST "C:\KSP_win64\" (
robocopy "$(TargetDir)\rel\GameData\KerbalVR" "C:\KSP_win64\GameData\KerbalVR" /E
if EXIST "C:\KSP_dev\" (
robocopy "$(TargetDir)\rel\GameData\KerbalVR" "C:\KSP_dev\GameData\KerbalVR" /E
)

:: Do NOT make robocopy the last command here. It gives a "bad" return value.
Expand Down
30 changes: 25 additions & 5 deletions KerbalVR/KerbalVR_AppGUI.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using UnityEngine;
using KSP.UI.Screens;
using System.Text.RegularExpressions;
using System;
using System.IO;
using System.Text.RegularExpressions;

namespace KerbalVR
{
Expand All @@ -23,7 +24,8 @@ private class TextFieldFloat {
GUILayout.Label(parameterName + ":", HighLogic.Skin.label);
valueStr = GUILayout.TextField(valueStr, HighLogic.Skin.textField);
if (GUI.changed) {
bool parseSuccess = System.Single.TryParse(valueStr, out float updatedValue);
float updatedValue;
bool parseSuccess = System.Single.TryParse(valueStr, out updatedValue);
if (parseSuccess) {
parameterCallback(updatedValue);
}
Expand All @@ -35,7 +37,8 @@ private class TextFieldFloat {
#region Constants
public static string AppButtonLogo {
get {
return Globals.KERBALVR_ASSETS_DIR + "app_button_logo";
string path = Path.Combine(Globals.KERBALVR_TEXTURES_DIR, "app_button_logo");
return path.Replace("\\", "/");
}
}

Expand Down Expand Up @@ -78,7 +81,7 @@ private class TextFieldFloat {
private bool appButtonGuiActive = false;
private bool appButtonGuiActiveLastState = false;

private Rect appGuiWindowRect = new Rect(Screen.width / 4, Screen.height / 4, 160, 100);
private Rect appGuiWindowRect = new Rect(Screen.width / 4, Screen.height / 4, 200, 100);

// text fields
private string worldScaleStr;
Expand Down Expand Up @@ -258,7 +261,8 @@ private class TextFieldFloat {
GUILayout.Label("World Scale:", HighLogic.Skin.label);
worldScaleStr = GUILayout.TextField(worldScaleStr, HighLogic.Skin.textField);
if (GUI.changed) {
bool parseSuccess = System.Single.TryParse(worldScaleStr, out float worldScale);
float worldScale;
bool parseSuccess = System.Single.TryParse(worldScaleStr, out worldScale);
if (parseSuccess &&
worldScale >= 0.1 &&
worldScale <= 10) {
Expand All @@ -267,6 +271,22 @@ private class TextFieldFloat {
}
GUILayout.EndHorizontal();

// init at startup toggle
GUILayout.BeginHorizontal();
bool initOpenVrAtStartup = GUILayout.Toggle(Configuration.Instance.InitOpenVrAtStartup, "Init OpenVR at startup", HighLogic.Skin.toggle);
if (GUI.changed) {
Configuration.Instance.InitOpenVrAtStartup = initOpenVrAtStartup;
}
GUILayout.EndHorizontal();

// swap control stick yaw and roll
GUILayout.BeginHorizontal();
bool swapYawRollControls = GUILayout.Toggle(Configuration.Instance.SwapYawRollControls, "Swap Yaw/Roll Controls", HighLogic.Skin.toggle);
if (GUI.changed) {
Configuration.Instance.SwapYawRollControls = swapYawRollControls;
}
GUILayout.EndHorizontal();


//------------------------------------------------------------------
GUILayout.EndVertical();
Expand Down
20 changes: 7 additions & 13 deletions KerbalVR/KerbalVR_AssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class AssetLoader : MonoBehaviour
public static string KERBALVR_ASSET_BUNDLE_PATH {
get {
string gameDataPath = Path.Combine(KSPUtil.ApplicationRootPath, "GameData");
string kvrAssetsPath = Path.Combine(gameDataPath, Globals.KERBALVR_ASSETS_DIR);
return Path.Combine(kvrAssetsPath, "kerbalvr.ksp");
string kvrAssetBundlesPath = Path.Combine(gameDataPath, Globals.KERBALVR_ASSETBUNDLES_DIR);
return Path.Combine(kvrAssetBundlesPath, "kerbalvr.ksp");
}
}
#endregion
Expand All @@ -30,15 +30,13 @@ public class AssetLoader : MonoBehaviour
private Dictionary<string, TMPro.TMP_FontAsset> fontsDictionary;

#region Singleton
// this is a singleton class, and there must be one DeviceManager in the scene
// this is a singleton class, and there must be one AssetLoader in the scene
private static AssetLoader _instance;
public static AssetLoader Instance {
get {
if (_instance == null) {
_instance = FindObjectOfType<AssetLoader>();
if (_instance == null) {
Utils.LogError("The scene needs to have one active GameObject with a AssetLoader script attached!");
} else {
if (_instance != null) {
_instance.Initialize();
}
}
Expand Down Expand Up @@ -72,7 +70,7 @@ public class AssetLoader : MonoBehaviour

private void LoadFonts() {
TMPro.TMP_FontAsset[] fonts = Resources.FindObjectsOfTypeAll(typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset[];
// Utils.Log("Found " + fonts.Length + " fonts");

for (int i = 0; i < fonts.Length; i++) {
TMPro.TMP_FontAsset font = fonts[i];
fontsDictionary.Add(font.name, font);
Expand All @@ -96,24 +94,20 @@ public class AssetLoader : MonoBehaviour
if (assetName.EndsWith(".prefab")) {
Utils.Log("Loading \"" + assetName + "\"");
GameObject assetGameObject = bundle.LoadAsset<GameObject>(assetName);

// Utils.Log("assetGameObject.name = " + assetGameObject.name);
gameObjectsDictionary.Add(assetGameObject.name, assetGameObject);
}
}
}

public TMPro.TMP_FontAsset GetFont(string fontName) {
TMPro.TMP_FontAsset font = null;
if (fontsDictionary.TryGetValue(fontName, out font)) {
if (fontsDictionary.TryGetValue(fontName, out TMPro.TMP_FontAsset font)) {
return font;
}
return null;
}

public GameObject GetGameObject(string gameObjectName) {
GameObject obj = null;
if (gameObjectsDictionary.TryGetValue(gameObjectName, out obj)) {
if (gameObjectsDictionary.TryGetValue(gameObjectName, out GameObject obj)) {
return obj;
}
return null;
Expand Down
126 changes: 126 additions & 0 deletions KerbalVR/KerbalVR_Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using System;
using System.IO;
using UnityEngine;

namespace KerbalVR
{
/// <summary>
/// A class to manage global configuration settings for KerbalVR.
/// </summary>
public class Configuration : MonoBehaviour
{
#region Constants
/// <summary>
/// Full path to the KerbalVR configuration settings file.
/// </summary>
public static string KERBALVR_SETTINGS_PATH {
get {
string gameDataPath = Path.Combine(KSPUtil.ApplicationRootPath, "GameData");
string kvrAssetsPath = Path.Combine(gameDataPath, Globals.KERBALVR_ASSETS_DIR);
return Path.Combine(kvrAssetsPath, "Settings.json");
}
}
#endregion


#region Properties
/// <summary>
/// If true, initializes OpenVR as soon as KSP starts. Otherwise, OpenVR
/// initializes on the first time VR is enabled.
/// </summary>
private bool _initOpenVrAtStartup;
public bool InitOpenVrAtStartup {
get {
return _initOpenVrAtStartup;
}
set {
_initOpenVrAtStartup = value;
SaveSettings();
}
}

/// <summary>
/// If true, the control stick controls craft pitch and yaw, instead of
/// pitch and roll.
/// </summary>
private bool _swapYawRollControls;
public bool SwapYawRollControls {
get {
return _swapYawRollControls;
}
set {
_swapYawRollControls = value;
SaveSettings();
}
}
#endregion


#region Private Members
#endregion


#region Singleton
// this is a singleton class, and there must be one Configuration in the scene
private static Configuration _instance;
public static Configuration Instance {
get {
if (_instance == null) {
_instance = FindObjectOfType<Configuration>();
if (_instance == null) {
Utils.LogError("The scene needs to have one active GameObject with a Configuration script attached!");
} else {
_instance.Initialize();
}
}
return _instance;
}
}
#endregion

// first-time initialization for this singleton class
private void Initialize() {

if (File.Exists(KERBALVR_SETTINGS_PATH)) {
// load the settings file if it exists
string kvrSettingsText = File.ReadAllText(KERBALVR_SETTINGS_PATH);
Settings kvrSettings = JsonUtility.FromJson<Settings>(kvrSettingsText);

// store the settings
this._initOpenVrAtStartup = kvrSettings.initOpenVrAtStartup;

#if DEBUG
Utils.Log("Loaded Configuration:");
Utils.Log("initOpenVrAtStartup = " + kvrSettings.initOpenVrAtStartup);
#endif

} else {
// if no settings file exists, create a default one
Settings kvrSettings = new Settings();
string kvrSettingsText = JsonUtility.ToJson(kvrSettings, true);

// write to file
File.WriteAllText(KERBALVR_SETTINGS_PATH, kvrSettingsText);
}
}

private void SaveSettings() {
Settings kvrSettings = new Settings();
kvrSettings.initOpenVrAtStartup = this.InitOpenVrAtStartup;
kvrSettings.swapYawRollControls = this.SwapYawRollControls;

// write to file
string kvrSettingsText = JsonUtility.ToJson(kvrSettings, true);
File.WriteAllText(KERBALVR_SETTINGS_PATH, kvrSettingsText);
}
}

/// <summary>
/// A serializable class to contain KerbalVR settings.
/// </summary>
[Serializable]
public class Settings {
public bool initOpenVrAtStartup = true;
public bool swapYawRollControls = false;
}
}
Loading

0 comments on commit 1f474b0

Please sign in to comment.