Skip to content

Commit a3116dc

Browse files
committed
Implemented "navigate back" button that appears on the palm.
1 parent 138ce91 commit a3116dc

File tree

13 files changed

+473
-28
lines changed

13 files changed

+473
-28
lines changed

Core/Solution/Hover.Cast/Custom/Standard/HovercastItemVisualSettingsStandard.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Hover.Cast.Display.Standard;
55
using Hover.Common.Custom;
66
using Hover.Common.Items;
7+
using Hover.Common.Items.Groups;
78
using Hover.Common.Items.Types;
89
using UnityEngine;
910

@@ -59,6 +60,10 @@ protected override IItemVisualSettings GetSettingsInner(IBaseItem pItem,
5960
////////////////////////////////////////////////////////////////////////////////////////////////
6061
/*--------------------------------------------------------------------------------------------*/
6162
private static Type GetRendererForItem(IBaseItem pItem) {
63+
if ( pItem != null && pItem.Id == ItemHierarchy.NavigateBackItemId ) {
64+
return typeof(UiPalmNavBackRenderer);
65+
}
66+
6267
if ( (pItem as IParentItem) != null ) {
6368
return typeof(UiItemParentRenderer);
6469
}

Core/Solution/Hover.Cast/Display/Standard/UiHoverMeshSlice.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace Hover.Cast.Display.Standard {
1111
public class UiHoverMeshSlice : UiHoverMesh {
1212

1313
public const float AngleInset = 0.0012f;
14+
public const float EdgeThick = 0.01f;
15+
16+
public bool DrawOuterEdge { get; set; }
1417

1518
private readonly bool vBackgroundOnly;
1619

@@ -85,8 +88,9 @@ protected override void UpdateMesh(MeshType pType, Mesh pMesh, float pAmount=1)
8588
}
8689

8790
if ( pType == MeshType.Edge ) {
88-
MeshUtil.BuildRingMesh(EdgeMesh, vRadInner-0.01f, vRadInner,
89-
vAngle0, vAngle1, vMeshSteps);
91+
float edgeInner = (DrawOuterEdge ? vRadOuter : vRadInner-EdgeThick);
92+
float edgeOuter = (DrawOuterEdge ? vRadOuter+EdgeThick : vRadInner);
93+
MeshUtil.BuildRingMesh(EdgeMesh, edgeInner, edgeOuter, vAngle0, vAngle1, vMeshSteps);
9094
return;
9195
}
9296

Core/Solution/Hover.Cast/Display/Standard/UiItemSelectRenderer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ namespace Hover.Cast.Display.Standard {
1212
/*================================================================================================*/
1313
public class UiItemSelectRenderer : MonoBehaviour, IUiItemRenderer {
1414

15+
public const float Thickness = 0.5f;
16+
public const float InnerRadius = 1;
17+
public const float OuterRadius = InnerRadius+Thickness;
1518
public const float ArcCanvasThickness = 250;
1619
public const float ArcCanvasScale = 0.002f;
1720

@@ -37,7 +40,7 @@ public virtual void Build(MenuState pMenuState, IBaseItemState pItemState,
3740
////
3841

3942
vHoverSlice = new UiHoverMeshSlice(gameObject);
40-
vHoverSlice.Resize(1, 1.5f, pArcAngle);
43+
vHoverSlice.Resize(InnerRadius, OuterRadius, pArcAngle);
4144

4245
////
4346

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using System;
2+
using Hover.Cast.Custom.Standard;
3+
using Hover.Cast.State;
4+
using Hover.Common.Custom;
5+
using Hover.Common.Items;
6+
using Hover.Common.State;
7+
using UnityEngine;
8+
9+
namespace Hover.Cast.Display.Standard {
10+
11+
/*================================================================================================*/
12+
public class UiPalmNavBackRenderer : MonoBehaviour, IUiItemRenderer {
13+
14+
public const float InnerRadius = 0;
15+
public const float OuterRadius = UiPalmRenderer.InnerRadius-UiHoverMeshSlice.EdgeThick-0.005f;
16+
17+
private static readonly Texture2D IconTex = Resources.Load<Texture2D>("Parent");
18+
19+
protected MenuState vMenuState;
20+
protected IBaseItemState vItemState;
21+
protected ItemVisualSettingsStandard vSettings;
22+
23+
protected UiHoverMeshSlice vHoverSlice;
24+
protected GameObject vIcon;
25+
26+
27+
////////////////////////////////////////////////////////////////////////////////////////////////
28+
/*--------------------------------------------------------------------------------------------*/
29+
public virtual void Build(MenuState pMenuState, IBaseItemState pItemState,
30+
float pArcAngle, IItemVisualSettings pSettings) {
31+
vMenuState = pMenuState;
32+
vItemState = pItemState;
33+
vSettings = (ItemVisualSettingsStandard)pSettings;
34+
35+
////
36+
37+
vHoverSlice = new UiHoverMeshSlice(gameObject);
38+
vHoverSlice.DrawOuterEdge = true;
39+
vHoverSlice.Resize(InnerRadius, OuterRadius, pArcAngle);
40+
41+
////
42+
43+
vIcon = GameObject.CreatePrimitive(PrimitiveType.Quad);
44+
vIcon.name = "Icon";
45+
vIcon.transform.SetParent(gameObject.transform, false);
46+
vIcon.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, Vector3.up)*
47+
Quaternion.FromToRotation(Vector3.right, Vector3.up);
48+
vIcon.renderer.sharedMaterial = new Material(Shader.Find("Unlit/AlphaSelfIllum"));
49+
vIcon.renderer.sharedMaterial.color = Color.clear;
50+
vIcon.renderer.sharedMaterial.mainTexture = IconTex;
51+
}
52+
53+
/*--------------------------------------------------------------------------------------------*/
54+
public virtual void Update() {
55+
ISelectableItem selItem = (vItemState.Item as ISelectableItem);
56+
57+
float high = vItemState.MaxHighlightProgress;
58+
bool showEdge = (vItemState.IsNearestHighlight && !vItemState.IsSelectionPrevented &&
59+
selItem != null && selItem.AllowSelection);
60+
float edge = (showEdge ? high : 0);
61+
float select = 1-(float)Math.Pow(1-vItemState.SelectionProgress, 1.5f);
62+
float alpha = Math.Max(0, 1-(float)Math.Pow(1-vMenuState.DisplayStrength, 2));
63+
64+
if ( vMenuState.NavBackStrength > select ) {
65+
select = vMenuState.NavBackStrength;
66+
}
67+
68+
Color colBg = vSettings.BackgroundColor;
69+
Color colEdge = vSettings.EdgeColor;
70+
Color colHigh = vSettings.HighlightColor;
71+
Color colSel = vSettings.SelectionColor;
72+
Color colIcon = vSettings.ArrowIconColor;
73+
74+
colBg.a *= alpha*(vItemState.Item.IsEnabled ? 1 : 0.333f);
75+
colEdge.a *= edge*alpha;
76+
colHigh.a *= high*alpha;
77+
colSel.a *= select*alpha;
78+
colIcon.a *= (vItemState.MaxHighlightProgress*0.75f + 0.25f)*alpha*
79+
(vItemState.Item.IsEnabled ? 1 : 0);
80+
81+
vHoverSlice.UpdateBackground(colBg);
82+
vHoverSlice.UpdateEdge(colEdge);
83+
vHoverSlice.UpdateHighlight(colHigh, high);
84+
vHoverSlice.UpdateSelect(colSel, select);
85+
86+
vIcon.renderer.sharedMaterial.color = colIcon;
87+
vIcon.transform.localScale = Vector3.one*vSettings.TextSize*0.75f*
88+
UiItemSelectRenderer.ArcCanvasScale;
89+
}
90+
91+
/*--------------------------------------------------------------------------------------------*/
92+
public virtual void HandleChangeAnimation(bool pFadeIn, int pDirection, float pProgress) {
93+
//do nothing...
94+
}
95+
96+
/*--------------------------------------------------------------------------------------------*/
97+
public void UpdateHoverPoints(IBaseItemPointsState pPointsState, Vector3 pCursorWorldPos) {
98+
vHoverSlice.UpdateHoverPoints(pPointsState);
99+
}
100+
101+
}
102+
103+
}

Core/Solution/Hover.Cast/Display/Standard/UiPalmRenderer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ namespace Hover.Cast.Display.Standard {
1111
/*================================================================================================*/
1212
public class UiPalmRenderer : MonoBehaviour, IUiPalmRenderer {
1313

14+
public const float InnerRadius = 0.13f;
15+
public const float OuterRadius = InnerRadius+UiItemSelectRenderer.Thickness;
16+
1417
protected MenuState vMenuState;
1518
protected float vAngle0;
1619
protected float vAngle1;
1720
protected int vMeshSteps;
1821

19-
protected float vInnerRadius;
2022
protected float vMainAlpha;
2123
private ItemVisualSettingsStandard vSettings;
2224

@@ -33,7 +35,6 @@ public virtual void Build(MenuState pMenuState, IItemVisualSettings pSettings,
3335
vAngle0 = pAngle0;
3436
vAngle1 = pAngle1;
3537
vMeshSteps = (int)Math.Round(Math.Max(2, (vAngle1-vAngle0)/Math.PI*60));
36-
vInnerRadius = 0.17f;
3738

3839
////
3940

@@ -51,7 +52,7 @@ public virtual void Build(MenuState pMenuState, IItemVisualSettings pSettings,
5152

5253
var labelObj = new GameObject("Label");
5354
labelObj.transform.SetParent(gameObject.transform, false);
54-
labelObj.transform.localPosition = new Vector3(0, 0, vInnerRadius);
55+
labelObj.transform.localPosition = new Vector3(0, 0, InnerRadius);
5556
labelObj.transform.localRotation = Quaternion.FromToRotation(Vector3.back, Vector3.right);
5657
labelObj.transform.localScale = new Vector3((vMenuState.IsOnLeftSide ? 1 : -1), 1, 1);
5758

@@ -93,7 +94,7 @@ public virtual void Update() {
9394
////////////////////////////////////////////////////////////////////////////////////////////////
9495
/*--------------------------------------------------------------------------------------------*/
9596
private void BuildMesh(Mesh pMesh) {
96-
MeshUtil.BuildRingMesh(pMesh, vInnerRadius, vInnerRadius+0.5f, vAngle0, vAngle1,vMeshSteps);
97+
MeshUtil.BuildRingMesh(pMesh, InnerRadius, OuterRadius, vAngle0, vAngle1, vMeshSteps);
9798
}
9899

99100
}

Core/Solution/Hover.Cast/Display/UiPalm.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System;
12
using Hover.Cast.Custom;
23
using Hover.Cast.State;
34
using Hover.Common.Custom;
45
using Hover.Common.Items;
6+
using Hover.Common.State;
57
using UnityEngine;
68

79
namespace Hover.Cast.Display {
@@ -29,6 +31,19 @@ internal void Build(MenuState pMenu, IItemVisualSettingsProvider pVisualSettings
2931
vRendererHold.transform.SetParent(gameObject.transform, false);
3032
vRendererHold.transform.localRotation = Quaternion.AngleAxis(170, Vector3.up);
3133

34+
////
35+
36+
BaseItemState itemState = pMenu.GetPalmItem();
37+
IItemVisualSettings visualSett = pVisualSettingsProv.GetSettings(itemState.Item);
38+
39+
var itemObj = new GameObject("BackItem");
40+
itemObj.transform.SetParent(vRendererHold.transform, false);
41+
42+
UiItem uiItem = itemObj.AddComponent<UiItem>();
43+
uiItem.Build(vMenuState, itemState, (float)Math.PI*2, visualSett);
44+
45+
////
46+
3247
vMenuState.OnLevelChange += HandleLevelChange;
3348
Rebuild();
3449
}

Core/Solution/Hover.Cast/Hover.Cast.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Display\Standard\UiItemBaseToggleRenderer.cs" />
6161
<Compile Include="Display\Standard\UiItemCheckboxRenderer.cs" />
6262
<Compile Include="Display\Standard\UiHoverMeshSlice.cs" />
63+
<Compile Include="Display\Standard\UiPalmNavBackRenderer.cs" />
6364
<Compile Include="Display\Standard\UiPalmRenderer.cs" />
6465
<Compile Include="Display\Standard\UiItemParentRenderer.cs" />
6566
<Compile Include="Display\Standard\UiItemRadioRenderer.cs" />
@@ -110,7 +111,5 @@
110111
<Target Name="AfterBuild">
111112
</Target>
112113
-->
113-
<ItemGroup>
114-
<Folder Include="Input\Transform\" />
115-
</ItemGroup>
114+
<ItemGroup />
116115
</Project>

Core/Solution/Hover.Cast/State/MenuState.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,24 @@ public class MenuState : IHovercastMenuState {
2828

2929
private readonly IItemHierarchy vItemHierarchy;
3030
private readonly InteractionSettings vInteractSettings;
31+
private readonly IList<BaseItemState> vAllItems;
3132
private readonly IList<BaseItemState> vItems;
33+
private readonly BaseItemState vPalmItem;
3234

3335
private ICursorState[] vCurrentCursors;
34-
private bool vIsGrabbing;
36+
private bool vIsNavigateBackStarted;
3537

3638

3739
////////////////////////////////////////////////////////////////////////////////////////////////
3840
/*--------------------------------------------------------------------------------------------*/
3941
public MenuState(IItemHierarchy pItemHierarchy, InteractionSettings pInteractSettings) {
4042
vItemHierarchy = pItemHierarchy;
4143
vInteractSettings = pInteractSettings;
44+
45+
vAllItems = new List<BaseItemState>();
4246
vItems = new List<BaseItemState>();
4347
vCurrentCursors = new ICursorState[0];
48+
vPalmItem = new BaseItemState(vItemHierarchy.NavigateBackItem, pInteractSettings);
4449

4550
OnLevelChange += (d => {});
4651

@@ -60,6 +65,11 @@ public IBaseItemState[] GetLevelItems() {
6065
return vItems.Cast<IBaseItemState>().ToArray();
6166
}
6267

68+
/*--------------------------------------------------------------------------------------------*/
69+
public BaseItemState GetPalmItem() {
70+
return vPalmItem;
71+
}
72+
6373
/*--------------------------------------------------------------------------------------------*/
6474
public IBaseItem GetLevelParentItem() {
6575
IItemGroup parGroup = vItemHierarchy.ParentLevel;
@@ -85,22 +95,22 @@ internal void UpdateAfterInput(IInputMenu pInputMenu, ICursorState[] pCursors) {
8595
DisplayStrength = pInputMenu.DisplayStrength;
8696
NavBackStrength = pInputMenu.NavigateBackStrength;
8797

88-
CheckGrabGesture(pInputMenu);
98+
CheckNavigateBackAction(pInputMenu);
8999

90100
foreach ( ICursorState cursor in vCurrentCursors ) {
91101
UpdateWithCursor(cursor);
92102
}
93103

94-
foreach ( BaseItemState item in vItems ) {
104+
foreach ( BaseItemState item in vAllItems ) {
95105
if ( item.UpdateSelectionProcess() ) { //returns true if selection occurred
96-
break; //exit loop, since the vItems list changes after a selection
106+
break; //exit loop, since the items list changes after a selection
97107
}
98108
}
99109
}
100110

101111
/*--------------------------------------------------------------------------------------------*/
102112
public void ResetAllItemCursorInteractions() {
103-
foreach ( BaseItemState item in vItems ) {
113+
foreach ( BaseItemState item in vAllItems ) {
104114
item.ResetAllCursorInteractions();
105115
}
106116
}
@@ -116,7 +126,7 @@ private void UpdateWithCursor(ICursorState pCursor) {
116126

117127
NearestItem = null;
118128

119-
foreach ( BaseItemState item in vItems ) {
129+
foreach ( BaseItemState item in vAllItems ) {
120130
item.UpdateWithCursor(cursorType, cursorWorldPos);
121131

122132
if ( !allowSelect ) {
@@ -133,42 +143,45 @@ private void UpdateWithCursor(ICursorState pCursor) {
133143
nearestDist = itemDist;
134144
}
135145

136-
foreach ( BaseItemState item in vItems ) {
146+
foreach ( BaseItemState item in vAllItems ) {
137147
item.SetAsNearestItem(cursorType, (item == NearestItem));
138148
}
139149
}
140150

141151
/*--------------------------------------------------------------------------------------------*/
142-
private void CheckGrabGesture(IInputMenu pInputMenu) {
152+
private void CheckNavigateBackAction(IInputMenu pInputMenu) {
143153
if ( pInputMenu == null ) {
144-
vIsGrabbing = false;
154+
vIsNavigateBackStarted = false;
145155
return;
146156
}
147157

148-
if ( vIsGrabbing && pInputMenu.NavigateBackStrength <= 0 ) {
149-
vIsGrabbing = false;
158+
if ( vIsNavigateBackStarted && pInputMenu.NavigateBackStrength <= 0 ) {
159+
vIsNavigateBackStarted = false;
150160
return;
151161
}
152162

153-
if ( vIsGrabbing || pInputMenu.NavigateBackStrength < 1 ) {
163+
if ( vIsNavigateBackStarted || pInputMenu.NavigateBackStrength < 1 ) {
154164
return;
155165
}
156166

157-
vIsGrabbing = true;
167+
vIsNavigateBackStarted = true;
158168
vItemHierarchy.Back();
159169
}
160170

161171
/*--------------------------------------------------------------------------------------------*/
162172
private void HandleLevelChange(int pDirection) {
173+
vAllItems.Clear();
163174
vItems.Clear();
164175

165176
IBaseItem[] items = vItemHierarchy.CurrentLevel.Items;
166177

167178
foreach ( IBaseItem item in items ) {
168179
var seg = new BaseItemState(item, vInteractSettings);
180+
vAllItems.Add(seg);
169181
vItems.Add(seg);
170182
}
171183

184+
vAllItems.Add(vPalmItem);
172185
OnLevelChange(pDirection);
173186
}
174187

Core/Solution/Hover.Common/Items/Groups/IItemHierarchy.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Hover.Common.Items.Groups {
1+
using Hover.Common.Items.Types;
2+
3+
namespace Hover.Common.Items.Groups {
24

35
/*================================================================================================*/
46
public interface IItemHierarchy {
@@ -10,6 +12,7 @@ public interface IItemHierarchy {
1012
IItemGroup CurrentLevel { get; }
1113
IItemGroup ParentLevel { get; }
1214
string CurrentLevelTitle { get; }
15+
SelectorItem NavigateBackItem { get; }
1316

1417

1518
////////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)