File size: 5,444 Bytes
18a519f | 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 | using UnityEditor;
using UnityEngine;
using PlasticGui.WebApi.Responses;
using PlasticGui.WorkspaceWindow.NotificationBar;
namespace Unity.PlasticSCM.Editor.UI.StatusBar
{
class NotificationBar : INotificationBar
{
internal bool HasNotification { get; private set; }
internal bool IsVisible { get; private set; }
internal NotificationBar()
{
mSubscriptionPanel = new ActionPanel();
mContactPanel = new ActionPanel();
IsVisible = EditorPrefs.GetBool(
UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
true);
}
internal void SetVisibility(bool isVisible)
{
IsVisible = isVisible;
EditorPrefs.SetBool(
UnityConstants.SHOW_NOTIFICATION_KEY_NAME,
isVisible);
}
internal void OnGUI()
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal(UnityStyles.StatusBar.NotificationPanel);
if (mSubscriptionPanel.HasNotification)
mSubscriptionPanel.OnGUI();
GUILayout.FlexibleSpace();
if (mContactPanel.HasNotification)
mContactPanel.OnGUI();
DrawCloseButton(this);
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
void INotificationBar.SetActions(
CloudServerInfo cloudServerInfo,
CloudOrganizationHelpActionsResponse.Action subscriptionAction,
CloudOrganizationHelpActionsResponse.Action contactAction)
{
mSubscriptionPanel.SetAction(cloudServerInfo, subscriptionAction, false);
mContactPanel.SetAction(cloudServerInfo, contactAction, true);
HasNotification = mSubscriptionPanel.HasNotification || mContactPanel.HasNotification;
}
static void DrawCloseButton(NotificationBar notificationBar)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
if (GUILayout.Button(
new GUIContent(Images.GetCloseIcon()),
UnityStyles.StatusBar.NotificationPanelCloseButton))
{
notificationBar.SetVisibility(false);
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
class ActionPanel
{
internal bool HasNotification { get; private set; }
internal void SetAction(
CloudServerInfo cloudServerInfo,
CloudOrganizationHelpActionsResponse.Action action,
bool isContactSupportAction)
{
if (action == null)
{
HasNotification = false;
return;
}
mCloudServerInfo = cloudServerInfo;
mActionButton = action.Button;
mIsContactSupportAction = isContactSupportAction;
HasNotification = true;
mLabelText = action.Message;
SetButton(action.Button);
}
internal void OnGUI()
{
DrawLabel(mLabelText);
if (!mIsButtonVisible)
return;
DrawButton(
mCloudServerInfo, mActionButton.Url,
mIsContactSupportAction, mButtonText);
}
void SetButton(
CloudOrganizationHelpActionsResponse.ActionButton actionButton)
{
if (actionButton == null)
{
mButtonText = string.Empty;
mIsButtonVisible = false;
return;
}
mButtonText = actionButton.Caption;
mIsButtonVisible = true;
}
static void DrawLabel(string text)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.Label(
text,
UnityStyles.StatusBar.Label);
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
static void DrawButton(
CloudServerInfo cloudServerInfo,
string actionButtonUrl,
bool isContactSupportAction,
string buttonText)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
if (GUILayout.Button(
buttonText,
UnityStyles.StatusBar.LinkLabel))
{
LaunchNotificationAction.For(
cloudServerInfo,
actionButtonUrl,
isContactSupportAction);
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
bool mIsButtonVisible;
string mButtonText;
string mLabelText;
bool mIsContactSupportAction;
CloudOrganizationHelpActionsResponse.ActionButton mActionButton;
CloudServerInfo mCloudServerInfo;
}
ActionPanel mSubscriptionPanel;
ActionPanel mContactPanel;
}
} |