Skip to content

Commit

Permalink
feat: sdk pointer event toggle highlight (#2651)
Browse files Browse the repository at this point in the history
* Implemented support for new showHighlight property in the PBPointerEvents component, binding the highlight setup of entities to that property.
* Minor change on showFeedback usage to also avoid enabling the highlight if it's false, as the highlight is also the feedback
* Minor check to avoid enabling the hoverText if the component comes with that property with an empty string. Didn't touch the existent behaviour of not coming with that optional property that ends up using the default "Interact" hover text.
  • Loading branch information
pravusjif authored Nov 5, 2024
1 parent 2564940 commit d9c1978
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ private void ProcessRaycastResult(ref PlayerOriginRaycastResultForSceneEntities
if (candidateForHoverLeaveIsValid && newEntityWasHovered == false)
candidateForHoverLeaveIsValid = false;

SetupPointerEvents(raycastResultForSceneEntities, ref hoverFeedbackComponent, pbPointerEvents!, newEntityWasHovered, out bool isAtDistance);
SetupPointerEvents(entityInfo, raycastResultForSceneEntities, ref hoverFeedbackComponent, pbPointerEvents!, newEntityWasHovered, out bool isAtDistance);
hoverStateComponent.AssignCollider(raycastResultForSceneEntities.Collider, isAtDistance);
HighlightNewEntity(entityInfo, isAtDistance);
}

if (candidateForHoverLeaveIsValid)
Expand Down Expand Up @@ -129,6 +128,7 @@ private void ResetHighlightComponent(ref HighlightComponent highlightComponent)

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetupPointerEvents(
GlobalColliderSceneEntityInfo entityInfo,
in PlayerOriginRaycastResultForSceneEntities raycastResultForSceneEntities,
ref HoverFeedbackComponent hoverFeedbackComponent,
PBPointerEvents pbPointerEvents,
Expand All @@ -137,6 +137,7 @@ out bool isAtDistance
)
{
isAtDistance = false;
bool highlightEnabled = true;
var anyInputInfo = sdkInputActionsMap.Values.GatherAnyInputInfo();
pbPointerEvents.AppendPointerEventResultsIntent.Initialize(raycastResultForSceneEntities.RaycastHit, raycastResultForSceneEntities.OriginRay);

Expand All @@ -145,6 +146,10 @@ out bool isAtDistance
PBPointerEvents.Types.Entry pointerEvent = pbPointerEvents.PointerEvents[i]!;
PBPointerEvents.Types.Info info = pointerEvent.EventInfo!;

if (info is { HasShowFeedback: true, ShowFeedback: false }
or { HasShowHighlight: true, ShowHighlight: false })
highlightEnabled = false;

info.PrepareDefaultValues();

isAtDistance = InteractionInputUtils.IsQualifiedByDistance(raycastResultForSceneEntities, info);
Expand All @@ -155,10 +160,14 @@ out bool isAtDistance
pbPointerEvents.AppendPointerEventResultsIntent.TryAppendHoverInput(PointerEventType.PetHoverEnter, pointerEvent, i);

// Try Append Hover Feedback
HoverFeedbackUtils.TryAppendHoverFeedback(sdkInputActionsMap, pointerEvent,
ref hoverFeedbackComponent, anyInputInfo.AnyButtonIsPressed);
if (!info.HasHoverText || !string.IsNullOrEmpty(info.HoverText))
HoverFeedbackUtils.TryAppendHoverFeedback(sdkInputActionsMap, pointerEvent,
ref hoverFeedbackComponent, anyInputInfo.AnyButtonIsPressed);
}

if (highlightEnabled)
HighlightNewEntity(entityInfo, isAtDistance);

if (isAtDistance)

// Add all inputs that were pressed/unpressed this frame
Expand Down
76 changes: 65 additions & 11 deletions Explorer/Assets/Protocol/DecentralandProtocol/PointerEvents.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@ static PointerEventsReflection() {
"CjBkZWNlbnRyYWxhbmQvc2RrL2NvbXBvbmVudHMvcG9pbnRlcl9ldmVudHMu",
"cHJvdG8SG2RlY2VudHJhbGFuZC5zZGsuY29tcG9uZW50cxo1ZGVjZW50cmFs",
"YW5kL3Nkay9jb21wb25lbnRzL2NvbW1vbi9pbnB1dF9hY3Rpb24ucHJvdG8i",
"1AMKD1BCUG9pbnRlckV2ZW50cxJKCg5wb2ludGVyX2V2ZW50cxgBIAMoCzIy",
"hAQKD1BCUG9pbnRlckV2ZW50cxJKCg5wb2ludGVyX2V2ZW50cxgBIAMoCzIy",
"LmRlY2VudHJhbGFuZC5zZGsuY29tcG9uZW50cy5QQlBvaW50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1NDb21wb25lbnRz",
"YgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::DCL.ECSComponents.InputActionReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::DCL.ECSComponents.PBPointerEvents), global::DCL.ECSComponents.PBPointerEvents.Parser, new[]{ "PointerEvents" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::DCL.ECSComponents.PBPointerEvents.Types.Info), global::DCL.ECSComponents.PBPointerEvents.Types.Info.Parser, new[]{ "Button", "HoverText", "MaxDistance", "ShowFeedback" }, new[]{ "Button", "HoverText", "MaxDistance", "ShowFeedback" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::DCL.ECSComponents.PBPointerEvents), global::DCL.ECSComponents.PBPointerEvents.Parser, new[]{ "PointerEvents" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::DCL.ECSComponents.PBPointerEvents.Types.Info), global::DCL.ECSComponents.PBPointerEvents.Types.Info.Parser, new[]{ "Button", "HoverText", "MaxDistance", "ShowFeedback", "ShowHighlight" }, new[]{ "Button", "HoverText", "MaxDistance", "ShowFeedback", "ShowHighlight" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::DCL.ECSComponents.PBPointerEvents.Types.Entry), global::DCL.ECSComponents.PBPointerEvents.Types.Entry.Parser, new[]{ "EventType", "EventInfo" }, null, null, null, null)})
}));
}
Expand Down Expand Up @@ -289,6 +290,7 @@ public Info(Info other) : this() {
hoverText_ = other.hoverText_;
maxDistance_ = other.maxDistance_;
showFeedback_ = other.showFeedback_;
showHighlight_ = other.showHighlight_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

Expand Down Expand Up @@ -385,7 +387,7 @@ public void ClearMaxDistance() {
public const int ShowFeedbackFieldNumber = 4;
private bool showFeedback_;
/// <summary>
/// enable or disable hover text (default true)
/// enable or disable hover text and highlight (default true)
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
Expand All @@ -409,6 +411,34 @@ public void ClearShowFeedback() {
_hasBits0 &= ~4;
}

/// <summary>Field number for the "show_highlight" field.</summary>
public const int ShowHighlightFieldNumber = 5;
private bool showHighlight_;
/// <summary>
/// enable or disable hover highlight (default true)
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool ShowHighlight {
get { if ((_hasBits0 & 8) != 0) { return showHighlight_; } else { return false; } }
set {
_hasBits0 |= 8;
showHighlight_ = value;
}
}
/// <summary>Gets whether the "show_highlight" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasShowHighlight {
get { return (_hasBits0 & 8) != 0; }
}
/// <summary>Clears the value of the "show_highlight" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearShowHighlight() {
_hasBits0 &= ~8;
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
Expand All @@ -428,6 +458,7 @@ public bool Equals(Info other) {
if (HoverText != other.HoverText) return false;
if (!pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.Equals(MaxDistance, other.MaxDistance)) return false;
if (ShowFeedback != other.ShowFeedback) return false;
if (ShowHighlight != other.ShowHighlight) return false;
return Equals(_unknownFields, other._unknownFields);
}

Expand All @@ -439,6 +470,7 @@ public override int GetHashCode() {
if (HasHoverText) hash ^= HoverText.GetHashCode();
if (HasMaxDistance) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(MaxDistance);
if (HasShowFeedback) hash ^= ShowFeedback.GetHashCode();
if (HasShowHighlight) hash ^= ShowHighlight.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand Down Expand Up @@ -473,6 +505,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(32);
output.WriteBool(ShowFeedback);
}
if (HasShowHighlight) {
output.WriteRawTag(40);
output.WriteBool(ShowHighlight);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
Expand All @@ -499,6 +535,10 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(32);
output.WriteBool(ShowFeedback);
}
if (HasShowHighlight) {
output.WriteRawTag(40);
output.WriteBool(ShowHighlight);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
Expand All @@ -521,6 +561,9 @@ public int CalculateSize() {
if (HasShowFeedback) {
size += 1 + 1;
}
if (HasShowHighlight) {
size += 1 + 1;
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
Expand All @@ -545,6 +588,9 @@ public void MergeFrom(Info other) {
if (other.HasShowFeedback) {
ShowFeedback = other.ShowFeedback;
}
if (other.HasShowHighlight) {
ShowHighlight = other.ShowHighlight;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}

Expand Down Expand Up @@ -576,6 +622,10 @@ public void MergeFrom(pb::CodedInputStream input) {
ShowFeedback = input.ReadBool();
break;
}
case 40: {
ShowHighlight = input.ReadBool();
break;
}
}
}
#endif
Expand Down Expand Up @@ -607,6 +657,10 @@ public void MergeFrom(pb::CodedInputStream input) {
ShowFeedback = input.ReadBool();
break;
}
case 40: {
ShowHighlight = input.ReadBool();
break;
}
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@dcl/protocol": "^1.0.0-11406954347.commit-ba19c4f",
"@dcl/protocol": "^1.0.0-11599848164.commit-ef74edc",
"@protobuf-ts/protoc": "^2.8.2",
"@types/fs-extra": "^11.0.1",
"@types/glob": "^8.0.1",
Expand Down

0 comments on commit d9c1978

Please sign in to comment.