Skip to content

Commit 79302b9

Browse files
committed
Added font scale support and improved styling
- Added support for FontScale - Added transition when changing active view in stack view - Use semi-bold font instead of bold font style
1 parent e2b411e commit 79302b9

File tree

8 files changed

+138
-42
lines changed

8 files changed

+138
-42
lines changed

Assets/Resources/UITk/MainView.uxml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Unity.Samples.LetterSpell.StackView name="stackView" index="2" style="flex-grow: 1;">
77
<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;);"/>
88
<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;">
9+
<ui:VisualElement name="logo" class="lsp-logo"/>
910
<ui:Label text="What is your name?" class="title-text"/>
1011
<ui:TextField placeholder-text="Enter your name" name="TextField" style="flex-direction: column; min-width: 252px; width: 949px;">
1112
<Bindings>
@@ -15,18 +16,20 @@
1516
<ui:Button text="Next" name="loginButton" class="purple"/>
1617
</ui:VisualElement>
1718
<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;);">
18-
<ui:VisualElement style="flex-grow: 1; justify-content: center; align-items: center;">
19+
<ui:VisualElement name="logo" class="lsp-logo"/> <ui:VisualElement style="flex-grow: 1; justify-content: center; align-items: center;">
1920
<ui:VisualElement name="choiceButtonContainer" class="choice-button-container">
2021
<ui:Button text="Play Easy" name="easyButton" class="choice-button"/>
2122
<ui:Button text="Play Hard" name="hardButton" class="choice-button"/>
2223
<ui:VisualElement style="position: absolute; top: 100%; left: 0; right: 0; align-items: center;">
2324
<ui:Button text="Start Game" name="startGameButton" class="purple start-game-button"/>
2425
</ui:VisualElement>
2526
</ui:VisualElement>
27+
<ui:Button text="Options" name="settingsButton" style="position: absolute; right: 22px; top: 5px;"/>
2628
</ui:VisualElement>
2729
</ui:VisualElement>
2830
<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;);">
29-
<ui:Label text="#clue" name="clueLabel" class="title-text" style="-unity-text-align: middle-center; margin-top: 180px; margin-bottom: 40px;"/>
31+
<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;"/>
3033
<Unity.Samples.LetterSpell.CardListView name="letterCardContainer" style="flex-grow: 1;"/>
3134
<ui:VisualElement name="gameViewButtonContainer" style="flex-direction: row; padding-top: 4px; padding-right: 18px; padding-bottom: 18px; padding-left: 18px;">
3235
<ui:Button text="" name="pauseGameButton">
@@ -125,7 +128,6 @@
125128
</ui:ScrollView>
126129
</ui:VisualElement>
127130
</Unity.Samples.LetterSpell.StackView>
128-
<ui:Button text="Options" name="settingsButton" style="position: absolute; right: 22px; top: 5px; display: none;"/>
129131
</ui:VisualElement>
130132
<lsp:Popup name="exitGamePopup">
131133
<ui:Label text="Game Paused"/>
@@ -141,6 +143,5 @@
141143
<ui:Button text="Play Again" name="resultPlayAgainButton" class="purple"/>
142144
</ui:VisualElement>
143145
</lsp:Popup>
144-
<ui:VisualElement name="logo" class="lsp-logo" style="flex-grow: 1; display: none;"/>
145146
</ui:VisualElement>
146147
</ui:UXML>

Assets/Resources/UITk/Themes/GreenStyle/GreenStyle.tss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
border-width: 10px;
1717
border-color: black;
1818
border-radius: 30px;
19+
margin-top: -10px;
1920
}
2021

2122
.unity-base-dropdown__container-outer > .unity-scroll-view {
2223
border-radius: 20px;
23-
background-color: #63DD7F;
24+
background-color: white;
2425
}
2526

2627
.unity-base-dropdown__item {
2728
}
2829

2930
.unity-base-dropdown__item:hover:enabled {
30-
background-color: rgba(0, 0, 0, 0.7);
31+
background-color: #01C684;
3132
}
3233

3334
.unity-base-dropdown__checkmark {

Assets/Resources/UITk/Themes/LetterSpellTheme.uss

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
border-bottom-color: rgb(0, 0, 0);
1818
margin-top: 30px;
1919
background-color: rgb(255, 255, 255);
20-
-unity-font-style: bold;
2120
margin-bottom: 30px;
2221
margin-right: 30px;
2322
margin-left: 30px;
23+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
2424
}
2525

2626
.unity-button:hover {
2727
background-color: rgb(220, 180, 0);
2828
}
29-
29+
/*
3030
:root {
3131
font-size: 64px;
32-
}
32+
}*/
3333

3434
.unity-label {
3535
}
@@ -94,7 +94,7 @@
9494
}
9595

9696
.choice-button {
97-
font-size: 75px;
97+
/*font-size: 75px;*/
9898
padding-top: 140px;
9999
padding-right: 100px;
100100
padding-bottom: 140px;
@@ -120,8 +120,7 @@
120120
border-right-width: 10px;
121121
border-bottom-width: 10px;
122122
border-left-width: 10px;
123-
font-size: 130px;
124-
-unity-font-style: bold;
123+
/*font-size: 130px;*/
125124
width: 208px;
126125
height: 208px;
127126
border-top-left-radius: 30px;
@@ -130,6 +129,7 @@
130129
border-bottom-left-radius: 30px;
131130
align-items: center;
132131
justify-content: center;
132+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
133133
}
134134

135135
.lsp-letter-card.selected {
@@ -143,7 +143,6 @@
143143
}
144144

145145
.lsp-letter-card__button-container {
146-
font-size: 12px;
147146
position: absolute;
148147
top: 100%;
149148
padding: 5px;
@@ -164,7 +163,7 @@
164163
.lsp-letter-card__button {
165164
margin: 0;
166165
padding: 6px;
167-
-unity-font-style: bold;
166+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
168167
}
169168

170169
.lsp-letter-card__button--first {
@@ -213,14 +212,10 @@
213212
rotate: 20deg;
214213
}
215214

216-
.lsp-letter-card.dragged.dragging--right{
215+
.lsp-letter-card.dragged.dragging--right {
217216
rotate: -20deg;
218217
}
219218

220-
.settings-header-label {
221-
margin-top: 10px;
222-
}
223-
224219
#settingsView {
225220
padding-top: 60px;
226221
padding-right: 70px;
@@ -247,7 +242,7 @@
247242

248243
.settings-header-label {
249244
margin-top: 70px;
250-
-unity-font-style: bold;
245+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
251246
margin-bottom: 30px;
252247
}
253248

@@ -274,8 +269,8 @@
274269
}
275270

276271
.unity-radio-button__checkmark {
277-
width: 38px;
278-
height: 38px;
272+
width: 39px;
273+
height: 39.5px;
279274
border-top-left-radius: 20px;
280275
border-top-right-radius: 20px;
281276
border-bottom-right-radius: 20px;
@@ -387,7 +382,7 @@
387382
}
388383

389384
.title-text {
390-
-unity-font-style: bold;
385+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
391386
margin-top: 30px;
392387
margin-bottom: 30px;
393388
color: rgb(255, 255, 255);
@@ -429,7 +424,7 @@
429424

430425
.lsp-popup .unity-label {
431426
-unity-text-align: middle-center;
432-
-unity-font-style: bold;
427+
-unity-font-definition: url("project://database/Assets/UI/Fonts/Inter-SemiBold.ttf?fileID=12800000&guid=3b458681b475c476ea29f3244c5c85da&type=3#Inter-SemiBold");
433428
margin-top: 30px;
434429
margin-bottom: 65px;
435430
}
@@ -439,10 +434,6 @@
439434
color: rgb(255, 255, 255);
440435
}
441436

442-
.settings-section__title {
443-
-unity-font-style: bold;
444-
}
445-
446437
.unity-base-field {
447438
margin-top: 30px;
448439
margin-bottom: 30px;
@@ -538,3 +529,13 @@
538529
.unity-base-dropdown__item > .unity-base-dropdown__item-content > .unity-base-dropdown__label {
539530
margin-left: 80px;
540531
}
532+
533+
534+
.lsp-stack-view-Transition {
535+
position: absolute;
536+
top: 0;
537+
left: 0;
538+
width: 100%;
539+
height: 100%;
540+
background-color: #02C584;
541+
}

Assets/Scripts/UITk/Card.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,21 @@ public void UpdateButtonEnableState()
390390
[UxmlElement]
391391
partial class CardListView : VisualElement
392392
{
393+
static public int defaultCardSize = 208;
394+
static public float s_FontScale = 1.0f;
393395
static public int cardSize = 208;
396+
397+
public float fontScale
398+
{
399+
get => s_FontScale;
400+
set
401+
{
402+
s_FontScale = value;
403+
style.fontSize = value * 130;
404+
cardSize = (int)(defaultCardSize * value);
405+
}
406+
}
407+
394408
public int spacing = 30;
395409
private VisualElement m_InsertionPlaceholder;
396410

Assets/Scripts/UITk/Controls/StackView.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ namespace Unity.Samples.LetterSpell
1010
[UxmlElement]
1111
public partial class StackView : VisualElement
1212
{
13+
private VisualElement m_ContentContainer;
1314
private VisualElement m_ActiveView;
15+
private VisualElement m_TransitionElement;
1416

17+
public override VisualElement contentContainer => m_ContentContainer;
18+
1519
[UxmlAttribute]
1620
public int index
1721
{
@@ -29,10 +33,17 @@ public VisualElement activeView
2933
get => m_ActiveView;
3034
set
3135
{
36+
var oldView = m_ActiveView;
37+
3238
if (m_ActiveView == value)
3339
return;
3440
m_ActiveView = value;
35-
UpdateViews();
41+
42+
if (panel != null)
43+
StartTransition(oldView, m_ActiveView);
44+
else
45+
UpdateViews();
46+
3647
activeViewChanged?.Invoke();
3748
}
3849
}
@@ -41,9 +52,54 @@ public VisualElement activeView
4152

4253
public StackView()
4354
{
55+
AddToClassList("lsp-stack-view");
56+
57+
m_ContentContainer = new VisualElement();
58+
m_ContentContainer.AddToClassList("lsp-stack-view__content-container");
59+
m_ContentContainer.style.flexGrow = 1;
60+
hierarchy.Add(m_ContentContainer);
4461
RegisterCallback<GeometryChangedEvent>((e)=>UpdateViews());
4562
}
63+
64+
void StartTransition(VisualElement from, VisualElement to)
65+
{
66+
if (m_TransitionElement == null)
67+
{
68+
m_TransitionElement ??= new VisualElement();
69+
m_TransitionElement.AddToClassList("lsp-stack-view-Transition");
70+
}
71+
m_TransitionElement.style.opacity = 0;
72+
hierarchy.Add(m_TransitionElement);
4673

74+
var fadeIn = m_TransitionElement.experimental.animation.Start(
75+
(element) => element.style.opacity.value,
76+
1f, 400, (element, value) =>
77+
{
78+
element.style.opacity = value;
79+
Debug.Log("op = " + value);
80+
});
81+
fadeIn.onAnimationCompleted += () =>
82+
{
83+
// Hide the old view
84+
if (from != null)
85+
from.style.display = DisplayStyle.None;
86+
87+
// Show the new view
88+
if (to != null)
89+
{
90+
to.style.display = DisplayStyle.Flex;
91+
}
92+
93+
var fadeOut = m_TransitionElement.experimental.animation.Start(
94+
(element) => element.style.opacity.value,
95+
0, 400, (element, value) => element.style.opacity = value);
96+
fadeOut.onAnimationCompleted += () =>
97+
{
98+
m_TransitionElement.RemoveFromHierarchy();
99+
};
100+
};
101+
}
102+
47103
public void UpdateViews()
48104
{
49105
foreach (var view in Children())

0 commit comments

Comments
 (0)