StartPageView.cs
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using JetBrains.Annotations;
using Unity.Cloud.Collaborate.Assets;
using Unity.Cloud.Collaborate.Components;
using Unity.Cloud.Collaborate.Presenters;
using Unity.Cloud.Collaborate.UserInterface;
using UnityEditor;
using UnityEngine.UIElements;
namespace Unity.Cloud.Collaborate.Views
{
internal class StartPageView : PageComponent, IStartView
{
public const string UssClassName = "start-page-view";
public const string UssTitleClassName = UssClassName + "__title";
public const string UssButtonClassName = UssClassName + "__button";
static readonly string k_LayoutPath = $"{CollaborateWindow.LayoutPath}/{nameof(StartPageView)}.uxml";
static readonly string k_StylePath = $"{CollaborateWindow.StylePath}/{nameof(StartPageView)}.uss";
IStartPresenter m_Presenter;
readonly Label m_Text;
readonly Button m_Button;
public StartPageView()
{
AddToClassList(UssClassName);
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(k_LayoutPath).CloneTree(this);
styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>(k_StylePath));
m_Text = this.Q<Label>(className: UssTitleClassName);
m_Button = this.Q<Button>(className: UssButtonClassName);
}
/// <inheritdoc />
public IStartPresenter Presenter
{
set
{
m_Presenter = value;
SetupEvents();
// If page active before presenter has been added, call start once we have it.
if (Active)
{
m_Presenter.Start();
}
}
}
/// <inheritdoc />
protected override void SetActive()
{
m_Presenter?.Start();
}
/// <inheritdoc />
protected override void SetInactive()
{
m_Presenter?.Stop();
}
void SetupEvents()
{
m_Button.clickable.clicked += m_Presenter.RequestStart;
}
/// <inheritdoc />
public string Text
{
set => m_Text.text = value;
}
/// <inheritdoc />
public string ButtonText
{
set => m_Button.text = value;
}
/// <inheritdoc />
public void SetButtonVisible(bool isVisible)
{
if (isVisible)
{
m_Button.RemoveFromClassList(UiConstants.ussHidden);
}
else
{
m_Button.AddToClassList(UiConstants.ussHidden);
}
}
[UsedImplicitly]
public new class UxmlFactory : UxmlFactory<StartPageView> { }
}
}