A game about forced loneliness, made by TACStudios
1using UnityEditor;
2using UnityEngine;
3
4using Codice.Client.Common.WebApi.Responses;
5using PlasticGui.WorkspaceWindow.NotificationBar;
6
7namespace Unity.PlasticSCM.Editor.UI.StatusBar
8{
9 class NotificationBar : INotificationBar
10 {
11 internal bool HasNotification { get; private set; }
12 internal bool IsVisible { get; private set; }
13
14 internal NotificationBar()
15 {
16 mSubscriptionPanel = new ActionPanel();
17 mContactPanel = new ActionPanel();
18
19 IsVisible = EditorPrefs.GetBool(
20 UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
21 true);
22 }
23
24 internal void SetVisibility(bool isVisible)
25 {
26 IsVisible = isVisible;
27
28 EditorPrefs.SetBool(
29 UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
30 isVisible);
31 }
32
33 internal void OnGUI()
34 {
35 GUILayout.BeginVertical();
36
37 GUILayout.FlexibleSpace();
38 GUILayout.BeginHorizontal(UnityStyles.StatusBar.NotificationPanel);
39
40 if (mSubscriptionPanel.HasNotification)
41 mSubscriptionPanel.OnGUI();
42
43 GUILayout.FlexibleSpace();
44
45 if (mContactPanel.HasNotification)
46 mContactPanel.OnGUI();
47
48 DrawCloseButton(this);
49
50 GUILayout.EndHorizontal();
51 GUILayout.FlexibleSpace();
52
53 GUILayout.EndVertical();
54 }
55
56 void INotificationBar.SetActions(
57 CloudServerInfo cloudServerInfo,
58 CloudOrganizationHelpActionsResponse.Action subscriptionAction,
59 CloudOrganizationHelpActionsResponse.Action contactAction)
60 {
61 mSubscriptionPanel.SetAction(cloudServerInfo, subscriptionAction, false);
62 mContactPanel.SetAction(cloudServerInfo, contactAction, true);
63
64 HasNotification = mSubscriptionPanel.HasNotification || mContactPanel.HasNotification;
65 }
66
67 void INotificationBar.CleanActions()
68 {
69 HasNotification = false;
70
71 mSubscriptionPanel.SetAction(null, null, false);
72 mContactPanel.SetAction(null, null, false);
73 }
74
75 static void DrawCloseButton(NotificationBar notificationBar)
76 {
77 GUILayout.BeginVertical();
78 GUILayout.FlexibleSpace();
79
80 if (GUILayout.Button(
81 new GUIContent(Images.GetCloseIcon()),
82 UnityStyles.StatusBar.NotificationPanelCloseButton))
83 {
84 notificationBar.SetVisibility(false);
85 }
86
87 GUILayout.FlexibleSpace();
88 GUILayout.EndVertical();
89 }
90
91 class ActionPanel
92 {
93 internal bool HasNotification { get; private set; }
94
95 internal void SetAction(
96 CloudServerInfo cloudServerInfo,
97 CloudOrganizationHelpActionsResponse.Action action,
98 bool isContactSupportAction)
99 {
100 if (action == null)
101 {
102 HasNotification = false;
103 return;
104 }
105
106 mCloudServerInfo = cloudServerInfo;
107 mActionButton = action.Button;
108 mIsContactSupportAction = isContactSupportAction;
109
110 HasNotification = true;
111 mLabelText = action.Message;
112 SetButton(action.Button);
113 }
114
115 internal void OnGUI()
116 {
117 DrawLabel(mLabelText);
118
119 if (!mIsButtonVisible)
120 return;
121
122 DrawButton(
123 mCloudServerInfo, mActionButton.Url,
124 mIsContactSupportAction, mButtonText);
125 }
126
127 void SetButton(
128 CloudOrganizationHelpActionsResponse.ActionButton actionButton)
129 {
130 if (actionButton == null)
131 {
132 mButtonText = string.Empty;
133 mIsButtonVisible = false;
134 return;
135 }
136
137 mButtonText = actionButton.Caption;
138 mIsButtonVisible = true;
139 }
140
141 static void DrawLabel(string text)
142 {
143 GUILayout.BeginVertical();
144 GUILayout.FlexibleSpace();
145
146 GUILayout.Label(
147 text,
148 UnityStyles.StatusBar.Label);
149
150 GUILayout.FlexibleSpace();
151 GUILayout.EndVertical();
152 }
153
154 static void DrawButton(
155 CloudServerInfo cloudServerInfo,
156 string actionButtonUrl,
157 bool isContactSupportAction,
158 string buttonText)
159 {
160 GUILayout.BeginVertical();
161 GUILayout.FlexibleSpace();
162
163 if (GUILayout.Button(
164 buttonText,
165 UnityStyles.StatusBar.LinkLabel))
166 {
167 LaunchNotificationAction.For(
168 cloudServerInfo,
169 actionButtonUrl,
170 isContactSupportAction);
171 }
172
173 GUILayout.FlexibleSpace();
174 GUILayout.EndVertical();
175 }
176
177 bool mIsButtonVisible;
178 string mButtonText;
179 string mLabelText;
180
181 bool mIsContactSupportAction;
182 CloudOrganizationHelpActionsResponse.ActionButton mActionButton;
183 CloudServerInfo mCloudServerInfo;
184 }
185
186 ActionPanel mSubscriptionPanel;
187 ActionPanel mContactPanel;
188 }
189}