Skip to content

Commit

Permalink
Fix #116: add tutorial GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Jan 1, 2023
1 parent f56049a commit cbf31aa
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 8 deletions.
1 change: 1 addition & 0 deletions FreeIva/FreeIva.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="ColliderUtil.cs" />
<Compile Include="CutParameter.cs" />
<Compile Include="Experimental\ColliderManipulator.cs" />
<Compile Include="Gui\GuiTutorial.cs" />
<Compile Include="InternalModules\B9PSConditionalProp.cs" />
<Compile Include="InternalModules\DeleteInternalObject.cs" />
<Compile Include="InternalModules\DisableCollider.cs" />
Expand Down
81 changes: 81 additions & 0 deletions FreeIva/Gui/GuiTutorial.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace FreeIva
{
internal static class GuiTutorial
{
private static Rect windowPos = new Rect(Screen.width * 0.75f, Screen.height * 0.5f, 10, 10);
public static bool Active = false;

public static void Gui(int instanceId)
{
if (Active && Settings.ShowTutorial && !KerbalIvaAddon.Instance.buckled)
{
windowPos = GUILayout.Window(instanceId, windowPos, WindowGui, "FreeIva", GUILayout.Width(250), GUILayout.Height(200));
}
}

static void WindowGui(int windowID)
{
GUILayout.BeginVertical();

GuiUtils.label("Mouse Look", Mouse.Buttons.Right + " Click");
GuiUtils.label("Forward", Settings.ForwardKey);
GuiUtils.label("Backward", Settings.BackwardKey);
GuiUtils.label("Strafe Left", Settings.LeftKey);
GuiUtils.label("Strafe Right", Settings.RightKey);

if (KerbalIvaAddon.KerbalIva.IsOnLadder || (!KerbalIvaAddon.KerbalIva.UseRelativeMovement() || KerbalIvaAddon.KerbalIva.KerbalCollisionTracker.RailColliderCount > 0))
{
GuiUtils.label("Move Up", Settings.UpKey);
GuiUtils.label("Move Down", Settings.DownKey);
}

if (KerbalIvaAddon.KerbalIva.UseRelativeMovement())
{
GuiUtils.label("Crouch", Settings.CrouchKey);

if (KerbalIvaAddon.KerbalIva.IsOnLadder)
{
GuiUtils.label("Release Ladder", Settings.JumpKey);
}
else
{
GuiUtils.label("Jump", Settings.JumpKey);
}
}
else
{
GuiUtils.label("Roll CCW", Settings.RollCCWKey);
GuiUtils.label("Roll CW", Settings.RollCWKey);
}

GuiUtils.label("Return to Seat", GameSettings.CAMERA_MODE.primary.code);

if (KerbalIvaAddon.KerbalIva.UseRelativeMovement() || !KerbalIvaAddon.Gravity)
{
GuiUtils.label("Toggle Gravity", GameSettings.MODIFIER_KEY.primary.code + " + " + Settings.ToggleGravityKey);
}

GUILayout.BeginHorizontal();
if (GUILayout.Button("Close"))
{
Active = false;
}
if (GUILayout.Button("Close Forever"))
{
Active = false;
Settings.ShowTutorial = false;
}
GUILayout.EndHorizontal();

GUILayout.EndVertical();
GUI.DragWindow();
}
}
}
10 changes: 10 additions & 0 deletions FreeIva/KerbalIvaAddon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ void OnDestroy()
_instance = null;
}

void OnGUI()
{
GuiTutorial.Gui(GetInstanceID());
}

public void Update()
{
if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(Settings.ToggleGravityKey))
Expand Down Expand Up @@ -97,12 +102,17 @@ public void Update()
{
ActiveKerbal = null;
FreeIva.CurrentPart = null;
GuiTutorial.Active = false;
}
else
{
// In IVA.
if (_lastCameraMode != CameraManager.CameraMode.IVA)
{
GuiTutorial.Active = true;

ScreenMessages.PostScreenMessage($"Unbuckle [{Settings.UnbuckleKey}]", 2f, ScreenMessageStyle.LOWER_CENTER);

// Switching to IVA.
FreeIva.EnableInternals();
UpdateActiveKerbal();//false);
Expand Down
26 changes: 18 additions & 8 deletions FreeIva/KerbalIvaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,28 @@ public void DoFixedUpdate(KerbalIvaAddon.IVAInput input)

// if we're not in a centrifuge, see if we're trying to grab a rail in one
// TODO: can we handle *clicking* on one of these rails too?
if (currentCentrifuge == null && (input.Jump || input.MovementThrottle.y < 0) && KerbalCollisionTracker.RailColliderCount > 0)
if (currentCentrifuge == null && KerbalCollisionTracker.RailColliderCount > 0)
{
currentCentrifuge = InternalModuleFreeIva.GetForModel(KerbalCollisionTracker.CurrentInternalModel)?.Centrifuge;
var centrifuge = InternalModuleFreeIva.GetForModel(KerbalCollisionTracker.CurrentInternalModel)?.Centrifuge;

if (currentCentrifuge != null)
if (centrifuge != null && Mathf.Abs(centrifuge.CurrentSpinRate) > 0)
{
transform.SetParent(currentCentrifuge.IVARotationRoot, true);
KerbalIvaAddon.Instance.JumpLatched = true;
input.Jump = false;
ScreenMessages.PostScreenMessage($"Grab [{Settings.JumpKey}]", 0.1f, ScreenMessageStyle.LOWER_CENTER);

if ((input.Jump || input.MovementThrottle.y < 0))
{
currentCentrifuge = centrifuge;

if (currentCentrifuge != null)
{
transform.SetParent(currentCentrifuge.IVARotationRoot, true);
KerbalIvaAddon.Instance.JumpLatched = true;
input.Jump = false;

aimCamera = true;
oldCameraRotation = CameraAnchor.rotation;
aimCamera = true;
oldCameraRotation = CameraAnchor.rotation;
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions FreeIva/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static class Settings
// should force the kerbal back to their seat to recover from falling through the part.
public static float MaxVelocityRelativeToPart = 20f;

public static bool ShowTutorial = true;

public static void LoadSettings()
{
Debug.Log("[FreeIVA] Loading settings...");
Expand Down Expand Up @@ -106,6 +108,8 @@ public static void LoadSettings()
// Misc.
if (settings.HasValue("HeadSize")) HelmetSize = float.Parse(settings.GetValue("HeadSize"));
if (settings.HasValue("NoHelmetSize")) NoHelmetSize = float.Parse(settings.GetValue("NoHelmetSize"));

settings.TryGetValue(nameof(ShowTutorial), ref ShowTutorial);
}
}
}

0 comments on commit cbf31aa

Please sign in to comment.