Skip to content

Commit be59429

Browse files
committed
Improved GameView. Change the SplashScreen to add other languages
- Use a VisualElement with image and text for the Success pill to support localization - Ensure that we do not create nodes for an ignored accessible element and its children - Top-Align cards - Fixed StackView not displaying its content in the Builder on start or UI rebuild
1 parent 79302b9 commit be59429

File tree

16 files changed

+642
-34
lines changed

16 files changed

+642
-34
lines changed

Assets/Resources/UITk/MainView.uxml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<ui:VisualElement name="root" style="flex-grow: 1;">
44
<ui:VisualElement name="background" style="flex-grow: 1; position: absolute; top: 0; left: 0; bottom: 0; right: 0; background-color: rgb(11, 163, 109);"/>
55
<ui:VisualElement name="viewContainer" style="flex-grow: 1;">
6-
<Unity.Samples.LetterSpell.StackView name="stackView" index="2" style="flex-grow: 1;">
7-
<ui:VisualElement name="splashView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Splash-Screen.png?fileID=4602334432413793429&amp;guid=364b68ded9ed04f07848b6c7de25fdad&amp;type=3#Intro Screen_0&quot;);"/>
6+
<Unity.Samples.LetterSpell.StackView name="stackView" index="0" style="flex-grow: 1;">
7+
<ui:VisualElement name="splashView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Splash-Screen.png?fileID=4602334432413793429&amp;guid=364b68ded9ed04f07848b6c7de25fdad&amp;type=3#Intro Screen_0&quot;);">
8+
<ui:Label text="A fun spelling game" name="splashSubTitle"/>
9+
</ui:VisualElement>
810
<ui:VisualElement name="loginView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Background-Intro.png?fileID=2800000&amp;guid=718087ba784b64abd9675b1452fc0095&amp;type=3#Background-Intro&quot;); align-items: center; justify-content: center;">
911
<ui:VisualElement name="logo" class="lsp-logo"/>
1012
<ui:Label text="What is your name?" class="title-text"/>
@@ -16,7 +18,8 @@
1618
<ui:Button text="Next" name="loginButton" class="purple"/>
1719
</ui:VisualElement>
1820
<ui:VisualElement name="levelChoiceView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Background-Intro.png?fileID=2800000&amp;guid=718087ba784b64abd9675b1452fc0095&amp;type=3#Background-Intro&quot;);">
19-
<ui:VisualElement name="logo" class="lsp-logo"/> <ui:VisualElement style="flex-grow: 1; justify-content: center; align-items: center;">
21+
<ui:VisualElement name="logo" class="lsp-logo"/>
22+
<ui:VisualElement style="flex-grow: 1; justify-content: center; align-items: center;">
2023
<ui:VisualElement name="choiceButtonContainer" class="choice-button-container">
2124
<ui:Button text="Play Easy" name="easyButton" class="choice-button"/>
2225
<ui:Button text="Play Hard" name="hardButton" class="choice-button"/>
@@ -29,7 +32,13 @@
2932
</ui:VisualElement>
3033
<ui:VisualElement name="gameView" style="flex-grow: 1; background-image: url(&quot;project://database/Assets/UI/Images/Background-Intro.png?fileID=2800000&amp;guid=718087ba784b64abd9675b1452fc0095&amp;type=3#Background-Intro&quot;);">
3134
<ui:VisualElement name="logo" class="lsp-logo"/>
32-
<ui:Label text="#clue" name="clueLabel" class="title-text" style="-unity-text-align: middle-center; margin-top: 170px; margin-bottom: 50px;"/>
35+
<ui:VisualElement name="clueContainer">
36+
<ui:Label text="#clue" name="clueLabel" class="title-text" style="-unity-text-align: middle-center;"/>
37+
<ui:VisualElement name="successPill">
38+
<ui:VisualElement name="successPillCheckmark"/>
39+
<ui:Label text="Correct" class="success-pill__label"/>
40+
</ui:VisualElement>
41+
</ui:VisualElement>
3342
<Unity.Samples.LetterSpell.CardListView name="letterCardContainer" style="flex-grow: 1;"/>
3443
<ui:VisualElement name="gameViewButtonContainer" style="flex-direction: row; padding-top: 4px; padding-right: 18px; padding-bottom: 18px; padding-left: 18px;">
3544
<ui:Button text="" name="pauseGameButton">
@@ -39,9 +48,6 @@
3948
<ui:VisualElement name="VisualElement" style="flex-grow: 1;"/>
4049
<ui:Button text="Next Word" name="nextWordButton" class="purple"/>
4150
</ui:VisualElement>
42-
<ui:VisualElement name="successImage" picking-mode="Ignore" style="flex-grow: 1; position: absolute; top: 0; left: 0; bottom: 0; right: 0; align-items: center; justify-content: center; transition-property: opacity; transition-duration: 400ms; transition-timing-function: ease-in-out;">
43-
<ui:VisualElement style="background-image: url(&quot;project://database/Assets/UI/Images/Image-Correct.png?fileID=-3206192116628772432&amp;guid=7480bb21c642e4319b9a422353096177&amp;type=3#Correct-Badge_0&quot;); width: 382px; height: 85px; margin-top: -277px;"/>
44-
</ui:VisualElement>
4551
</ui:VisualElement>
4652
<ui:VisualElement name="settingsView" style="flex-grow: 1; background-color: rgb(255, 251, 233);">
4753
<ui:VisualElement name="settingsHeader" style="flex-direction: row; flex-shrink: 0;">

Assets/Resources/UITk/Themes/LetterSpellTheme.uss

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
.unity-button:hover {
2727
background-color: rgb(220, 180, 0);
2828
}
29-
/*
30-
:root {
31-
font-size: 64px;
32-
}*/
3329

3430
.unity-label {
3531
}
@@ -94,7 +90,6 @@
9490
}
9591

9692
.choice-button {
97-
/*font-size: 75px;*/
9893
padding-top: 140px;
9994
padding-right: 100px;
10095
padding-bottom: 140px;
@@ -120,7 +115,6 @@
120115
border-right-width: 10px;
121116
border-bottom-width: 10px;
122117
border-left-width: 10px;
123-
/*font-size: 130px;*/
124118
width: 208px;
125119
height: 208px;
126120
border-top-left-radius: 30px;
@@ -530,12 +524,60 @@
530524
margin-left: 80px;
531525
}
532526

533-
534527
.lsp-stack-view-Transition {
535528
position: absolute;
536529
top: 0;
537530
left: 0;
538531
width: 100%;
539532
height: 100%;
540-
background-color: #02C584;
541-
}
533+
background-color: rgb(2, 197, 132);
534+
}
535+
536+
#splashSubTitle {
537+
position: absolute;
538+
top: 50%;
539+
left: 0;
540+
right: 0;
541+
-unity-text-align: upper-center;
542+
margin-top: 70px;
543+
color: rgb(255, 255, 255);
544+
}
545+
546+
#successPill {
547+
background-color: rgb(255, 255, 255);
548+
border-top-left-radius: 38px;
549+
border-top-right-radius: 38px;
550+
border-bottom-right-radius: 38px;
551+
border-bottom-left-radius: 38px;
552+
padding-right: 38px;
553+
padding-left: 38px;
554+
padding-top: 4px;
555+
padding-bottom: 4px;
556+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
557+
flex-direction: row;
558+
justify-content: center;
559+
align-items: center;
560+
}
561+
562+
#successPillCheckmark {
563+
width: 52px;
564+
height: 47px;
565+
background-image: url("project://database/Assets/UI/Images/Success-Check.png?fileID=2800000&guid=8eb6e6371b15149a7b6e3cd6117749c1&type=3#Success-Check");
566+
margin-right: 15px;
567+
}
568+
569+
.success-pill__label {
570+
padding-top: 2px;
571+
padding-bottom: 2px;
572+
margin-top: 0;
573+
margin-bottom: 0;
574+
}
575+
576+
#clueContainer {
577+
align-items: center;
578+
padding-top: 168px;
579+
padding-bottom: 30px;
580+
}
581+
582+
#clueLabel {
583+
}

Assets/Scripts/Closed Captions/SubtitleViewer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Unity.Samples.ScreenReader;
12
using UnityEngine;
23
using UnityEngine.UIElements;
34

@@ -148,7 +149,7 @@ void UpdateRootVisualElement()
148149
{
149150
CreateSubtitleView();
150151
}
151-
152+
m_CachedRootVisualElement.GetOrCreateAccessibleProperties().ignored = true;
152153
m_CachedRootVisualElement.Add(m_SubtitleView);
153154
}
154155
}

Assets/Scripts/Screen Reader/UITk/Handlers/TextFieldHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using UnityEngine.Accessibility;
12
using UnityEngine.Scripting;
23
using UnityEngine.UIElements;
34

@@ -6,6 +7,11 @@ namespace Unity.Samples.ScreenReader
67
[Preserve]
78
class TextFieldFieldHandler : BaseFieldHandler<string>
89
{
10+
public override AccessibilityRole GetRole()
11+
{
12+
return AccessibilityRole.TextField;
13+
}
14+
915
public TextFieldFieldHandler()
1016
{
1117
OnSelect += () =>

Assets/Scripts/Screen Reader/UITk/VisualTreeAccessibilityUpdater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,7 @@ void UpdateAccessibilityHierarchyRecursively(VisualElement element,
580580
{
581581
accElement = CreateHandler(element, parentAccessible);
582582
}
583-
584-
if (element.ClassListContains(GenericDropdownMenu.ussClassName))
585-
OnScreenDebug.Log("Menu " + element.name + " visible:" + visible + " acc:" + (accElement != null) + " model " + accElement?.isModal);
583+
586584
bool shouldBeIgnored = !visible;
587585
bool modal = false;
588586

@@ -635,9 +633,11 @@ void UpdateAccessibilityHierarchyRecursively(VisualElement element,
635633
currentModalElement = null;
636634
}
637635

636+
// Note that we still travers the children even if the parent is ignored.
637+
// It is possible that nodes for children were created and has to be destroyed and the handlers cleaned up.
638638
foreach (var child in element.hierarchy.Children())
639639
{
640-
UpdateAccessibilityHierarchyRecursively(child, parentAccessible, forced, visible);
640+
UpdateAccessibilityHierarchyRecursively(child, parentAccessible, forced, visible && !shouldBeIgnored);
641641
}
642642
}
643643

Assets/Scripts/UITk/Card.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public void DoLayout()
561561
child.style.left = startX + i * cardSize + (i + 1) *spacing;
562562
child.style.width = cardSize;
563563
child.style.height = cardSize;
564-
child.style.top = (layout.height - cardSize)/2;
564+
child.style.top = 0;//DONT CENTER ANYMORE, (layout.height - cardSize)/2;
565565
i++;
566566

567567
}

Assets/Scripts/UITk/Controls/Popup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public PopupOverlay()
4545
style.backgroundColor = new Color(0, 0, 0, 0.7f);
4646

4747
m_ContentContainer = new PopupContent();
48+
m_ContentContainer.GetOrCreateAccessibleProperties().modal = true;
4849
hierarchy.Add(m_ContentContainer);
4950

5051
var styleSheet = Resources.Load<StyleSheet>("UITk/Themes/LetterSpellTheme");
@@ -62,12 +63,11 @@ void OnPointerDown(PointerDownEvent evt)
6263
}
6364
}
6465

65-
class PopupContent : AccessibleVisualElement
66+
class PopupContent : VisualElement
6667
{
6768
public PopupContent()
6869
{
6970
AddToClassList("lsp-popup");
70-
accessible.modal = true;
7171
}
7272
}
7373

Assets/Scripts/UITk/Controls/StackView.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,49 @@ public partial class StackView : VisualElement
1616

1717
public override VisualElement contentContainer => m_ContentContainer;
1818

19+
int m_Index = -1;
20+
1921
[UxmlAttribute]
2022
public int index
2123
{
22-
get => m_ActiveView != null ? IndexOf(m_ActiveView) : -1;
24+
get => m_Index;
2325
set
2426
{
25-
if (value > this.childCount - 1)
27+
if (m_Index == value)
2628
return;
27-
activeView = value >= 0 ? this[value] : null;
29+
30+
m_Index = value;
31+
UpdateActiveViewFromIndex();
32+
indexChanged?.Invoke(m_Index);
2833
}
2934
}
35+
36+
void UpdateActiveViewFromIndex()
37+
{
38+
if (m_Index < 0 || m_Index >= childCount)
39+
{
40+
activeView = null;
41+
return;
42+
}
43+
activeView = this[m_Index];
44+
}
3045

3146
public VisualElement activeView
3247
{
33-
get => m_ActiveView;
48+
get
49+
{
50+
// Ensure the active view is valid. This is because children can be added/removed without being notified.
51+
bool needToEnsureValid = false;
52+
53+
if (m_ActiveView == null && m_Index != -1 && childCount > 0)
54+
needToEnsureValid = true;
55+
else if (m_ActiveView != null && (!Contains(m_ActiveView) || IndexOf(m_ActiveView) != m_Index))
56+
needToEnsureValid = true;
57+
58+
if (needToEnsureValid)
59+
UpdateActiveViewFromIndex();
60+
return m_ActiveView;
61+
}
3462
set
3563
{
3664
var oldView = m_ActiveView;
@@ -44,10 +72,12 @@ public VisualElement activeView
4472
else
4573
UpdateViews();
4674

75+
index = IndexOf(m_ActiveView);
4776
activeViewChanged?.Invoke();
4877
}
4978
}
5079

80+
public event Action<int> indexChanged;
5181
public event Action activeViewChanged;
5282

5383
public StackView()
@@ -58,7 +88,7 @@ public StackView()
5888
m_ContentContainer.AddToClassList("lsp-stack-view__content-container");
5989
m_ContentContainer.style.flexGrow = 1;
6090
hierarchy.Add(m_ContentContainer);
61-
RegisterCallback<GeometryChangedEvent>((e)=>UpdateViews());
91+
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
6292
}
6393

6494
void StartTransition(VisualElement from, VisualElement to)
@@ -100,8 +130,21 @@ void StartTransition(VisualElement from, VisualElement to)
100130
};
101131
}
102132

133+
bool firstGeometryChange = true;
134+
135+
void OnGeometryChanged(GeometryChangedEvent evt)
136+
{
137+
if (firstGeometryChange )
138+
{
139+
firstGeometryChange = false;
140+
UpdateViews();
141+
UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
142+
}
143+
}
144+
103145
public void UpdateViews()
104146
{
147+
UpdateActiveViewFromIndex();
105148
foreach (var view in Children())
106149
{
107150
if (m_ActiveView != view)

Assets/Scripts/UITk/MainView.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class MainView : MonoBehaviour
194194

195195
private VisualElement m_GameView;
196196
private Label m_ClueLabel;
197-
private VisualElement m_SuccessImage;
197+
private VisualElement m_SuccessPill;
198198
private CardListView m_LetterCardContainer;
199199
private Button m_PauseGameButton;
200200
private Button m_NextWordButtton;
@@ -289,6 +289,8 @@ void SetupUI()
289289
//m_Logo.style.display = DisplayStyle.None;
290290
m_StackView = root.Q<StackView>();
291291
m_SplashView = m_StackView.Q("splashView");
292+
// Disable screen reader for the label in the spash screen.
293+
m_SplashView.Q<Label>().GetOrCreateAccessibleProperties().ignored = true;
292294
m_LoginView = m_StackView.Q("loginView");
293295
m_LoginView.dataSource = m_PlayerSettings;
294296
m_LoginButton = m_LoginView.Q<Button>("loginButton");
@@ -305,9 +307,10 @@ void SetupUI()
305307

306308
m_GameView = m_StackView.Q("gameView");
307309
m_ClueLabel = m_GameView.Q<Label>("clueLabel");
308-
m_SuccessImage = m_GameView.Q("successImage");
310+
m_SuccessPill = m_GameView.Q("successPill");
311+
m_SuccessPill.GetOrCreateAccessibleProperties().ignored = true;
309312
//m_SuccessImage.style.display = DisplayStyle.None;
310-
m_SuccessImage.style.opacity = 0;
313+
m_SuccessPill.style.opacity = 0;
311314
m_LetterCardContainer = m_GameView.Q<LetterSpell.CardListView>("letterCardContainer");
312315
m_PauseGameButton = m_GameView.Q<Button>("pauseGameButton");
313316
m_PauseGameButton.clicked += ShowExitGamePopup;
@@ -410,7 +413,7 @@ void OnGameStateChanged(Gameplay.State state)
410413
public void ShowNextWord()
411414
{
412415
//m_SuccessImage.style.display = DisplayStyle.None;
413-
m_SuccessImage.style.opacity = 0;
416+
m_SuccessPill.style.opacity = 0;
414417
//if (gameplay.IsGameComplete())
415418
if (gameplay.IsShowingLastWord())
416419
{
@@ -535,7 +538,7 @@ public void OnWordReorderingCompleted()
535538

536539
void FadeSuccessImageIn()
537540
{
538-
m_SuccessImage.style.opacity = 1;
541+
m_SuccessPill.style.opacity = 1;
539542
// m_SuccessImage.style.display = DisplayStyle.Flex;
540543
m_MainView.schedule.Execute((t) => FadeSuccessImageOut()).ExecuteLater(3000);
541544
}

Assets/UI/Images/Splash-Screen.png

2.89 KB
Loading

0 commit comments

Comments
 (0)