Skip to content

Commit

Permalink
Improved the input interface's "IsActive" values (#3). Updated the st…
Browse files Browse the repository at this point in the history
…ate classes accordingly.
  • Loading branch information
zachkinstner committed Feb 2, 2015
1 parent 2f9ba05 commit fac4483
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 110 deletions.
31 changes: 15 additions & 16 deletions Unity/Assets/Hovercast/Core/Display/UiArc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,28 @@ internal void Build(ArcState pArc, ISettings pSettings) {
vSettings = pSettings;

vArcState.OnLevelChange += HandleLevelChange;
vArcState.OnIsLeftChange += HandleIsLeftChange;
HandleIsLeftChange();
UpdateAfterSideChange();
}

/*--------------------------------------------------------------------------------------------*/
public void Update() {
UpdateItemChangeAnim();
}

/*--------------------------------------------------------------------------------------------*/
internal void UpdateAfterSideChange() {
vPrevLevelObj = vCurrLevelObj;
DestroyPrevLevel();

vCurrLevelObj = new GameObject("CurrLevel");
vCurrLevelObj.transform.SetParent(gameObject.transform, false);
vCurrLevelObj.transform.localScale = Vector3.one;

UiArcLevel arcLevel = vCurrLevelObj.AddComponent<UiArcLevel>();
arcLevel.Build(vArcState, vSettings);
arcLevel.HandleChangeAnimation(true, 0, 1);
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand All @@ -61,20 +74,6 @@ private void HandleLevelChange(int pDirection) {
vChangeDir = pDirection;
UpdateItemChangeAnim();
}

/*--------------------------------------------------------------------------------------------*/
private void HandleIsLeftChange() {
vPrevLevelObj = vCurrLevelObj;
DestroyPrevLevel();

vCurrLevelObj = new GameObject("CurrLevel");
vCurrLevelObj.transform.SetParent(gameObject.transform, false);
vCurrLevelObj.transform.localScale = Vector3.one;

UiArcLevel arcLevel = vCurrLevelObj.AddComponent<UiArcLevel>();
arcLevel.Build(vArcState, vSettings);
arcLevel.HandleChangeAnimation(true, 0, 1);
}

/*--------------------------------------------------------------------------------------------*/
private void DestroyPrevLevel() {
Expand Down
4 changes: 2 additions & 2 deletions Unity/Assets/Hovercast/Core/Display/UiCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ internal void Build(ArcState pArcState, CursorState pCursorState, ISettings pSet

/*--------------------------------------------------------------------------------------------*/
public void Update() {
if ( vCursorState.Position == null || vArcState.DisplayStrength <= 0 ) {
if ( !vCursorState.IsActive || vArcState.DisplayStrength <= 0 ) {
vRendererObj.SetActive(false);
return;
}

vRendererObj.SetActive(true);

Transform tx = gameObject.transform;
tx.localPosition = (Vector3)vCursorState.Position;
tx.localPosition = vCursorState.Position;
tx.localRotation = Quaternion.identity;
tx.localScale = Vector3.one*(vArcState.Size*UiMenu.ScaleArcSize);

Expand Down
12 changes: 11 additions & 1 deletion Unity/Assets/Hovercast/Core/Display/UiMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Hovercast.Core.Display {
/*================================================================================================*/
public class UiMenu : MonoBehaviour {

public static readonly float ScaleArcSize = 1.1f;
public const float ScaleArcSize = 1.1f;

private MenuState vMenuState;
private ArcState vArcState;
Expand Down Expand Up @@ -38,6 +38,8 @@ internal void Build(MenuState pMenuState, ISettings pSettings) {
arcObj.transform.SetParent(gameObject.transform, false);
vUiArc = arcObj.AddComponent<UiArc>();
vUiArc.Build(vArcState, vSettings);

vMenuState.OnSideChange += HandleSideChange;
}

/*--------------------------------------------------------------------------------------------*/
Expand All @@ -57,6 +59,14 @@ public void Update() {
vUiPalm.gameObject.transform.localRotation = (isLeft ? vLeftRot : vRightRot);
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
private void HandleSideChange() {
vUiPalm.UpdateAfterSideChange();
vUiArc.UpdateAfterSideChange();
}

}

}
26 changes: 11 additions & 15 deletions Unity/Assets/Hovercast/Core/Display/UiPalm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class UiPalm : MonoBehaviour {
private GameObject vRendererObj;
private IUiPalmRenderer vRenderer;

private bool? vPrevIsLeft;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
Expand All @@ -29,23 +27,12 @@ internal void Build(ArcState pArc, ISettings pSettings) {
vRendererHold.transform.SetParent(gameObject.transform, false);
vRendererHold.transform.localPosition = UiArcLevel.PushFromHand;

vArcState.OnIsLeftChange += HandleIsLeftChange;
vArcState.OnLevelChange += HandleLevelChange;

HandleIsLeftChange();
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
private void HandleLevelChange(int pDirection) {
NavItem parNavItem = vArcState.GetLevelParentItem();
var arcSegSett = vSettings.GetArcSegmentSettings(parNavItem);
vRenderer.SetSettings(arcSegSett);
UpdateAfterSideChange();
}

/*--------------------------------------------------------------------------------------------*/
private void HandleIsLeftChange() {
internal void UpdateAfterSideChange() {
if ( vRendererObj != null ) {
vRendererObj.SetActive(false);
Destroy(vRendererObj);
Expand All @@ -65,6 +52,15 @@ private void HandleIsLeftChange() {
HandleLevelChange(0);
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
private void HandleLevelChange(int pDirection) {
NavItem parNavItem = vArcState.GetLevelParentItem();
var arcSegSett = vSettings.GetArcSegmentSettings(parNavItem);
vRenderer.SetSettings(arcSegSett);
}

}

}
1 change: 1 addition & 0 deletions Unity/Assets/Hovercast/Core/Input/IInputCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Hovercast.Core.Input {
public interface IInputCursor {

bool IsLeft { get; }
bool IsActive { get; }

Vector3 Position { get; }
Quaternion Rotation { get; }
Expand Down
1 change: 1 addition & 0 deletions Unity/Assets/Hovercast/Core/Input/IInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Hovercast.Core.Input {
public interface IInputMenu {

bool IsLeft { get; }
bool IsActive { get; }

Vector3 Position { get; }
Quaternion Rotation { get; }
Expand Down
1 change: 0 additions & 1 deletion Unity/Assets/Hovercast/Core/Input/IInputSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
public interface IInputSide {

bool IsLeft { get; }
bool IsActive { get; }

IInputMenu Menu { get; }
IInputCursor Cursor { get; }
Expand Down
52 changes: 15 additions & 37 deletions Unity/Assets/Hovercast/Core/State/ArcState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ namespace Hovercast.Core.State {
public class ArcState {

public delegate void LevelChangeHandler(int pDirection);
public delegate void IsLeftChangeHandler();

public event LevelChangeHandler OnLevelChange;
public event IsLeftChangeHandler OnIsLeftChange;

public bool IsActive { get; private set; }
public bool IsLeft { get; private set; }
Expand All @@ -25,7 +22,6 @@ public class ArcState {
public float NavBackStrength { get; private set; }
public ArcSegmentState NearestSegment { get; private set; }

private readonly IInputProvider vInputProv;
private readonly NavigationProvider vNavProv;
private readonly IList<ArcSegmentState> vSegments;
private readonly InteractionSettings vSettings;
Expand All @@ -34,17 +30,14 @@ public class ArcState {

////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public ArcState(IInputProvider pInputProv, NavigationProvider pNavProv,
InteractionSettings pSettings) {
vInputProv = pInputProv;
public ArcState(NavigationProvider pNavProv, InteractionSettings pSettings) {
vNavProv = pNavProv;
vSegments = new List<ArcSegmentState>();
vSettings = pSettings;

IsLeft = vSettings.IsMenuOnLeftSide;

OnLevelChange += (d => {});
OnIsLeftChange += (() => {});

vNavProv.OnLevelChange += HandleLevelChange;
HandleLevelChange(0);
Expand All @@ -71,42 +64,27 @@ public string GetLevelTitle() {

////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
internal void UpdateAfterInput() {
if ( vSettings.IsMenuOnLeftSide != IsLeft ) {
IsLeft = vSettings.IsMenuOnLeftSide;
OnIsLeftChange();
}

IInputSide inputSide = vInputProv.GetSide(IsLeft);
IsActive = inputSide.IsActive;

if ( !IsActive ) {
Center = Vector3.zero;
Rotation = Quaternion.identity;
Size = 0;
DisplayStrength = 0;
NavBackStrength = 0;
return;
}

IInputMenu inputMenu = inputSide.Menu;

Center = inputMenu.Position;
Rotation = inputMenu.Rotation;
Size = inputMenu.Radius;
DisplayStrength = inputMenu.DisplayStrength;
NavBackStrength = inputMenu.NavigateBackStrength;

CheckGrabGesture(inputMenu);
internal void UpdateAfterInput(IInputMenu pInputMenu) {
IsActive = pInputMenu.IsActive;
IsLeft = pInputMenu.IsLeft;
Center = pInputMenu.Position;
Rotation = pInputMenu.Rotation;
Size = pInputMenu.Radius;
DisplayStrength = pInputMenu.DisplayStrength;
NavBackStrength = pInputMenu.NavigateBackStrength;

CheckGrabGesture(pInputMenu);
}

/*--------------------------------------------------------------------------------------------*/
internal void UpdateWithCursor(CursorState pCursor) {
bool allowSelect = (pCursor != null && DisplayStrength > 0);
bool allowSelect = (pCursor.IsActive && DisplayStrength > 0);
Vector3? cursorPos = (pCursor.IsActive ? pCursor.Position : (Vector3?)null);

NearestSegment = null;

foreach ( ArcSegmentState seg in vSegments ) {
seg.UpdateWithCursor(pCursor != null ? pCursor.Position : null);
seg.UpdateWithCursor(cursorPos);

if ( !allowSelect ) {
continue;
Expand Down
28 changes: 8 additions & 20 deletions Unity/Assets/Hovercast/Core/State/CursorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,28 @@ namespace Hovercast.Core.State {
/*================================================================================================*/
public class CursorState {

public bool IsActive { get; private set; }
public bool IsLeft { get; private set; }
//public Vector3 PalmDirection { get; private set; }
public Vector3? Position { get; private set; }
public Vector3 Position { get; private set; }

private readonly IInputProvider vInputProv;
private readonly InteractionSettings vSettings;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public CursorState(IInputProvider pInputProv, InteractionSettings pSettings) {
vInputProv = pInputProv;
public CursorState(InteractionSettings pSettings) {
vSettings = pSettings;

IsLeft = vSettings.IsMenuOnLeftSide;
//PalmDirection = vInputProv.PalmDirection;
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
internal void UpdateAfterInput() {
IsLeft = !vSettings.IsMenuOnLeftSide;

IInputSide inputSide = vInputProv.GetSide(IsLeft);
IInputCursor inputCursor = inputSide.Cursor;

if ( inputCursor == null ) {
Position = null;
return;
}
internal void UpdateAfterInput(IInputCursor pInputCursor) {
IsLeft = pInputCursor.IsLeft;
IsActive = pInputCursor.IsActive;

Position = inputCursor.Position+
inputCursor.Rotation*Vector3.back*vSettings.CursorForwardDistance;
Position = pInputCursor.Position+
pInputCursor.Rotation*Vector3.back*vSettings.CursorForwardDistance;
}

}
Expand Down
28 changes: 23 additions & 5 deletions Unity/Assets/Hovercast/Core/State/MenuState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,49 @@ namespace Hovercast.Core.State {
/*================================================================================================*/
public class MenuState {

public delegate void SideChangeHandler();
public event SideChangeHandler OnSideChange;

public IInputProvider InputProvider { get; private set; }
public NavigationProvider NavProv { get; private set; }
public ArcState Arc { get; private set; }
public CursorState Cursor { get; private set; }

private readonly InteractionSettings vSettings;
private bool? vCurrIsMenuOnLeftSide;


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public MenuState(IInputProvider pInputProv, NavigationProvider pNavProv,
InteractionSettings pSettings) {
InputProvider = pInputProv;
NavProv = pNavProv;

vSettings = pSettings;

Arc = new ArcState(NavProv, vSettings);
Cursor = new CursorState(vSettings);

Arc = new ArcState(pInputProv, NavProv, pSettings);
Cursor = new CursorState(pInputProv, pSettings);
OnSideChange += (() => {});
}


////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
public void UpdateAfterInput() {
//TODO: find the corrent InputSide here, and pass them as parameters
Arc.UpdateAfterInput();
Cursor.UpdateAfterInput();
bool isMenuOnLeft = vSettings.IsMenuOnLeftSide;
IInputSide cursorSide = InputProvider.GetSide(!isMenuOnLeft);
IInputSide menuSide = InputProvider.GetSide(isMenuOnLeft);

Cursor.UpdateAfterInput(cursorSide.Cursor);
Arc.UpdateAfterInput(menuSide.Menu);
Arc.UpdateWithCursor(Cursor);

if ( isMenuOnLeft != vCurrIsMenuOnLeftSide ) {
vCurrIsMenuOnLeftSide = isMenuOnLeft;
OnSideChange();
}
}

}
Expand Down
Loading

0 comments on commit fac4483

Please sign in to comment.