Skip to content

Commit 36cdcbd

Browse files
author
Bianca Marina Stana
committed
Merge branch 'unite2025/lsp-uitk' into unite2025/screen-reader-improvements
2 parents 4faf4eb + e95ed02 commit 36cdcbd

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

Assets/Scripts/Gameplay/GameViewController.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ bool OnLetterCardSelected()
169169
AccessibilityManager.GetService<UGuiAccessibilityService>()?.ActivateOtherAccessibilityNodes(false, letterCardContainer);
170170

171171
letterCard.SetDraggingVisuals(true);
172-
SetLetterCardsAccessibilityLabel(false);
172+
173+
var element = m_AccessibilityFocusedCard.GetComponent<AccessibleElement>();
174+
// TODO: This should be localized.
175+
element.hint = "Navigate left or right to move. Submit to unselect.";
176+
element.SetNodeProperties();
173177
}
174178
else
175179
{
@@ -178,7 +182,10 @@ bool OnLetterCardSelected()
178182
AccessibilityManager.GetService<UGuiAccessibilityService>()?.ActivateOtherAccessibilityNodes(true, letterCardContainer);
179183

180184
letterCard.SetDraggingVisuals(false);
181-
SetLetterCardsAccessibilityLabel(true);
185+
186+
var element = m_AccessibilityFocusedCard.GetComponent<AccessibleElement>();
187+
element.hint = LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "LETTER_CARD_HINT");
188+
element.SetNodeProperties();
182189
}
183190

184191
return true;
@@ -192,6 +199,9 @@ void MoveAccessibilityFocusOnClue()
192199

193200
public void OnWordReorderingCompleted()
194201
{
202+
m_AccessibilitySelectedCard.SetDraggingVisuals(false);
203+
m_AccessibilitySelectedCard = null;
204+
195205
StartCoroutine(DelayWordReorderingCompleted());
196206
return;
197207

@@ -276,17 +286,6 @@ void MoveSelectedCard()
276286
}
277287
}
278288

279-
void SetLetterCardsAccessibilityLabel(bool hasLabel)
280-
{
281-
foreach (Transform letterCardTransform in letterCardContainer)
282-
{
283-
var element = letterCardTransform.GetComponent<AccessibleElement>();
284-
element.label = hasLabel ? letterCardTransform.name : null;
285-
element.hint = hasLabel ? LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "LETTER_CARD_HINT") : null;
286-
element.SetNodeProperties();
287-
}
288-
}
289-
290289
void MoveCard(bool shouldMoveLeft, int count)
291290
{
292291
var draggable = m_AccessibilitySelectedCard;

Assets/Scripts/UITk/Card.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine.Accessibility;
55
using UnityEngine.UIElements;
66
using Unity.Samples.ScreenReader;
7+
using UnityEngine.Localization.Settings;
78

89
namespace Unity.Samples.LetterSpell
910
{
@@ -68,15 +69,8 @@ public void Select()
6869
{
6970
cardListView.selectedCard = this;
7071

71-
// Check whether the card is focused or not.
72-
var focused = focusController?.focusedElement == this;
73-
7472
// TODO: This should be localized.
75-
accessible.hint = focused ? "Submit to unselect." : "Submit to select.";
76-
77-
// TODO: These should be localized.
78-
AssistiveSupport.notificationDispatcher.SendAnnouncement($"Card {text} selected. Navigate left or " +
79-
"right to move the card." + (focused ? "Submit to unselect it." : ""));
73+
accessible.hint = "Navigate left or right to move. Submit to unselect.";
8074

8175
OnScreenDebug.Log("Selected card: " + text);
8276
}
@@ -86,16 +80,10 @@ public void Unselect()
8680
{
8781
if (this == cardListView.selectedCard)
8882
{
89-
// Check whether the card is focused or not.
90-
var focused = focusController?.focusedElement == this;
9183
cardListView.selectedCard = null;
9284

93-
// TODO: This should be localized.
94-
accessible.hint = focused ? "Submit to unselect." : "Submit to select.";
95-
96-
// TODO: These should be localized.
97-
AssistiveSupport.notificationDispatcher.SendAnnouncement($"Card {text} selected. Navigate left or " +
98-
"right to move the card." + (focused ? "Submit to unselect it." : ""));
85+
// TODO: Change to "Submit to select, then navigate left or right to move."
86+
accessible.hint = LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "LETTER_CARD_HINT");
9987
}
10088
}
10189

@@ -115,6 +103,8 @@ public UITkLetterCard()
115103

116104
// Accessibility
117105
m_TextElement.GetOrCreateAccessibleProperties().ignored = true;
106+
107+
accessible.hint = LocalizationSettings.StringDatabase.GetLocalizedString("Game Text", "LETTER_CARD_HINT");
118108
accessible.selected += () =>
119109
{
120110
if (!selected)

Assets/Scripts/UITk/MainView.cs

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ UITkLetterCard accessibilityFocusedCard
247247
set
248248
{
249249
if (m_AccessibilityFocusedCard == value)
250+
{
250251
return;
252+
}
251253

252254
m_AccessibilityFocusedCard?.Blur();
253255

@@ -262,12 +264,14 @@ UITkLetterCard accessibilityFocusedCard
262264
// Note: we don't want to steal the focus if the user is dragging a card.
263265
OnScreenDebug.Log("In Acc Focus " + (m_AccessibilityFocusedCard != null ? m_AccessibilityFocusedCard.name : "null") +
264266
" selected " + (m_LetterCardContainer.selectedCard != null ? m_LetterCardContainer.selectedCard.name : "null"));
267+
265268
if (m_AccessibilityFocusedCard != null && m_LetterCardContainer.selectedCard == null)
269+
{
266270
m_AccessibilityFocusedCard.Focus();
271+
}
267272

268273
OnScreenDebug.Log("After Acc Focus " + (m_AccessibilityFocusedCard != null ? m_AccessibilityFocusedCard.name : "null") +
269274
" selected " + (m_LetterCardContainer.selectedCard != null ? m_LetterCardContainer.selectedCard.name : "null"));
270-
271275
}
272276
}
273277

@@ -623,6 +627,7 @@ void StateTheLetters()
623627
public void OnWordReorderingCompleted()
624628
{
625629
m_LetterCardContainer.canPlayCards = false;
630+
m_LetterCardContainer.selectedCard.Unselect();
626631

627632
m_MainView.schedule.Execute(_ => AnnounceCorrectWord()).ExecuteLater(2000);
628633

@@ -650,18 +655,17 @@ void FadeSuccessImageOut()
650655

651656
void OnNodeFocusChanged(AccessibilityNode node)
652657
{
653-
if (node != null)
658+
if (node == null)
654659
{
655-
var service = AccessibilityManager.GetService<UITkAccessibilityService>();
656-
var element = service.GetVisualElementForNode(m_MainView.panel, node);
657-
658-
accessibilityFocusedCard = element as UITkLetterCard;
659-
MoveSelectedCardOnAssistedFocus();
660-
}
661-
else
662-
{
663-
accessibilityFocusedCard = null;
660+
return;
664661
}
662+
663+
var service = AccessibilityManager.GetService<UITkAccessibilityService>();
664+
var element = service.GetVisualElementForNode(m_MainView.panel, node);
665+
666+
accessibilityFocusedCard = element as UITkLetterCard;
667+
668+
MoveSelectedCardOnAssistedFocus();
665669
}
666670

667671
void MoveSelectedCardOnAssistedFocus()
@@ -716,28 +720,35 @@ void MoveCard(bool shouldMoveLeft, int count = 1)
716720

717721
// OnScreenDebug.Log("MoveCard " + (shouldMoveLeft ? "left" : "right" + " count " + count));
718722

723+
var updater = m_LetterCardContainer.selectedCard.panel.GetAccessibilityUpdater();
724+
var node = updater.GetNodeForVisualElement(m_LetterCardContainer.selectedCard);
725+
726+
var selectedCardText = m_LetterCardContainer.selectedCard.text;
727+
728+
var index = m_LetterCardContainer.IndexOf(m_LetterCardContainer.selectedCard);
729+
var otherCardIndex = shouldMoveLeft ? index - 1 : index + 1;
730+
var otherCard = m_LetterCardContainer[otherCardIndex] as UITkLetterCard;
731+
var otherCardText = otherCard?.text;
732+
719733
var moved = shouldMoveLeft ?
720734
m_LetterCardContainer.selectedCard.MoveLeft(count) :
721735
m_LetterCardContainer.selectedCard.MoveRight(count);
722736

737+
m_MainView.schedule.Execute(() =>
738+
AssistiveSupport.notificationDispatcher.SendLayoutChanged(node)
739+
).ExecuteLater(50);
740+
723741
if (moved)
724742
{
725-
var index = m_LetterCardContainer.IndexOf(m_LetterCardContainer.selectedCard);
726-
var otherCardIndex = shouldMoveLeft ? index + 1 : index - 1;
727-
var otherCard = m_LetterCardContainer[otherCardIndex] as UITkLetterCard;
728-
729743
// TODO: This should be localized.
730-
var message = $"Moved {m_LetterCardContainer.selectedCard.text} {(shouldMoveLeft ? "before" : "after")} {otherCard?.text}";
744+
var message = $"Moved {selectedCardText} {(shouldMoveLeft ? "before" : "after")} {otherCardText}";
731745

732746
// Announce that the card was moved.
733-
AssistiveSupport.notificationDispatcher.SendAnnouncement(message);
747+
m_MainView.schedule.Execute(() =>
748+
AssistiveSupport.notificationDispatcher.SendAnnouncement(message)
749+
).ExecuteLater(100);
734750
}
735751

736-
var updater = m_LetterCardContainer.selectedCard.panel.GetAccessibilityUpdater();
737-
var node = updater.GetNodeForVisualElement(m_LetterCardContainer.selectedCard);
738-
739-
AssistiveSupport.notificationDispatcher.SendLayoutChanged(node);
740-
741752
/*var accElement = draggable.transform.GetComponent<AccessibleElement>();
742753
743754
if (shouldMoveLeft ? draggable.MoveLeft() : draggable.MoveRight())

0 commit comments

Comments
 (0)