forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralProjectSettings.cs
More file actions
214 lines (184 loc) · 9.28 KB
/
Copy pathGeneralProjectSettings.cs
File metadata and controls
214 lines (184 loc) · 9.28 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;
namespace UnityEditor.Connect
{
/// <summary>
/// The general section of the CloudServices project settings (actually simply called Services in the ProjectSettings)
/// Uses a simple state machine to keep track of current state.
/// </summary>
internal class GeneralProjectSettings : ServicesProjectSettings
{
const string k_ProjectSettingsPath = "Project/Services";
const string k_TemplatePath = "UXML/ServicesWindow/GeneralProjectSettingsStateBound.uxml";
const string k_ScrollContainerClassName = "scroll-container";
const string k_KeywordOrganization = "organization";
const string k_KeywordProject = "project";
const string k_KeywordUnlink = "unlink";
const string k_KeywordMembers = "members";
const string k_KeywordDashboard = "dashboard";
const string k_KeywordId = "id";
const string k_GeneralLabel = "General";
const string k_ProjectNameBlockName = "ProjectName";
const string k_OrganizationBlockName = "Organization";
const string k_ProjectIdBlockName = "ProjectId";
const string k_DashboardBlockName = "Dashboard";
const string k_ProjectIdSubmitButtonName = "ProjectIdSubmit";
const string k_EditButtonClassName = "edit-button";
const string k_CancelButtonClassName = "cancel-button";
const string k_FieldValueClassName = "field-value";
const string k_ReadModeClassName = "read-mode";
const string k_EditModeClassName = "edit-mode";
const string k_UnlinkProjectDialogTitle = "Unlink Project";
const string k_UnlinkProjectDialogMessage = "Are you sure you want to unlink this project?";
const string k_ProjectUnlinkSuccessMessage = "Project was unlinked successfully.";
const string k_Yes = "Yes";
const string k_No = "No";
public static string generalProjectSettingsPath => k_ProjectSettingsPath;
protected override bool sendNotificationForNonStandardStates => false;
CoppaManager m_CoppaManager;
[SettingsProvider]
public static SettingsProvider CreateServicesProvider()
{
return new GeneralProjectSettings(k_ProjectSettingsPath, SettingsScope.Project, new List<string>()
{
L10n.Tr(k_KeywordOrganization),
L10n.Tr(k_KeywordProject),
L10n.Tr(k_KeywordUnlink),
L10n.Tr(k_KeywordMembers),
L10n.Tr(k_KeywordDashboard),
L10n.Tr(k_KeywordId)
});
}
GeneralProjectSettings(string path, SettingsScope scopes, IEnumerable<string> keywords = null)
: base(path, scopes, k_GeneralLabel, keywords) {}
protected override Notification.Topic[] notificationTopicsToSubscribe => new[]
{
Notification.Topic.AdsService,
Notification.Topic.AnalyticsService,
Notification.Topic.BuildService,
Notification.Topic.CollabService,
Notification.Topic.CoppaCompliance,
Notification.Topic.CrashService,
Notification.Topic.ProjectBind,
Notification.Topic.PurchasingService
};
protected override SingleService serviceInstance => null;
protected override string serviceUssClassName => "general";
protected override void ToggleRestrictedVisualElementsAvailability(bool enable)
{
}
protected override void ActivateAction(string searchContext)
{
// Must reset properties every time this is activated
rootVisualElement.Add(m_GeneralTemplate.CloneTree().contentContainer);
//If we haven't received new bound info, fetch them
var projectInfoOnBind = new ProjectInfoData(UnityConnect.instance.projectInfo.organizationId,
UnityConnect.instance.projectInfo.organizationName,
UnityConnect.instance.projectInfo.projectName,
UnityConnect.instance.projectInfo.projectGUID,
UnityConnect.instance.projectInfo.projectId);
var generalTemplate = EditorGUIUtility.Load(k_TemplatePath) as VisualTreeAsset;
var scrollContainer = rootVisualElement.Q(className: k_ScrollContainerClassName);
scrollContainer.Clear();
scrollContainer.Add(generalTemplate.CloneTree().contentContainer);
SetupCoppaManager(scrollContainer);
//Collect Field Blocks entry points and initialize them
var projectNameFieldBlock = rootVisualElement.Q(k_ProjectNameBlockName);
var organizationFieldBlock = rootVisualElement.Q(k_OrganizationBlockName);
var projectIdFieldBlock = rootVisualElement.Q(k_ProjectIdBlockName);
var dashboardFieldBlock = rootVisualElement.Q(k_DashboardBlockName);
InitializeFieldBlock(projectNameFieldBlock, projectInfoOnBind.name);
InitializeFieldBlock(organizationFieldBlock, projectInfoOnBind.organizationName);
InitializeFieldBlock(projectIdFieldBlock, projectInfoOnBind.guid);
InitializeFieldBlock(dashboardFieldBlock);
//Setup dashboard link
var dashboardClickable = new Clickable(() =>
{
ServicesConfiguration.instance.RequestBaseDashboardurl(OpenDashboardOrgAndProjectIds);
});
rootVisualElement.Q(k_DashboardBlockName).AddManipulator(dashboardClickable);
projectIdFieldBlock.Q<Button>(k_ProjectIdSubmitButtonName).clicked += UnbindProject;
HandlePermissionRestrictedControls();
}
void SetupCoppaManager(VisualElement parentContainer)
{
//remove old version if any
parentContainer.Q(CoppaManager.coppaContainerName)?.parent?.RemoveFromHierarchy();
m_CoppaManager = new CoppaManager(parentContainer)
{
exceptionCallback = (compliance, exception) =>
{
NotificationManager.instance.Publish(Notification.Topic.CoppaCompliance, Notification.Severity.Error,
L10n.Tr(exception.Message));
}
};
var coppaContainer = rootVisualElement.Q(CoppaManager.coppaContainerName);
var editModeContainer = coppaContainer?.Q(className: k_ClassNameEditMode);
editModeContainer?.SetEnabled(false);
}
protected override void DeactivateAction()
{
}
static void InitializeFieldBlock(VisualElement fieldBlock, string fieldValue = null)
{
if (fieldBlock != null)
{
ToggleModeVisibility(fieldBlock, true);
var editButton = fieldBlock.Q<Button>(className: k_EditButtonClassName);
if (editButton != null)
{
editButton.clicked += () => { ToggleModeVisibility(fieldBlock, false); };
}
var cancelButton = fieldBlock.Q<Button>(className: k_CancelButtonClassName);
if (cancelButton != null)
{
cancelButton.clicked += () => { ToggleModeVisibility(fieldBlock, true); };
}
if (fieldValue != null)
{
var valueLabel = fieldBlock.Q<Label>(className: k_FieldValueClassName);
if (valueLabel != null)
{
valueLabel.text = fieldValue;
}
var valueTextField = fieldBlock.Q<TextField>(className: k_FieldValueClassName);
valueTextField?.SetValueWithoutNotify(fieldValue);
}
}
}
static void ToggleModeVisibility(VisualElement fieldBlock, bool showRead)
{
var readMode = fieldBlock.Q(className: k_ReadModeClassName);
if (readMode != null)
{
readMode.style.display = showRead ? DisplayStyle.Flex : DisplayStyle.None;
}
var editMode = fieldBlock.Q(className: k_EditModeClassName);
if (editMode != null)
{
editMode.style.display = showRead ? DisplayStyle.None : DisplayStyle.Flex;
}
}
void UnbindProject()
{
if (EditorUtility.DisplayDialog(L10n.Tr(k_UnlinkProjectDialogTitle),
L10n.Tr(k_UnlinkProjectDialogMessage),
L10n.Tr(k_Yes),
L10n.Tr(k_No)))
{
ServicesRepository.DisableAllServices(shouldUpdateApiFlag: false);
string cachedProjectName = UnityConnect.instance.projectInfo.projectName;
UnityConnect.instance.UnbindProject();
EditorAnalytics.SendProjectServiceBindingEvent(new ProjectBindManager.ProjectBindState() { bound = false, projectName = cachedProjectName });
NotificationManager.instance.Publish(Notification.Topic.ProjectBind, Notification.Severity.Info, L10n.Tr(k_ProjectUnlinkSuccessMessage));
ReinitializeSettings();
}
}
}
}