initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,85 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.UIElements
|
||||
{
|
||||
internal class LoadingSpinner : VisualElement
|
||||
{
|
||||
internal LoadingSpinner()
|
||||
{
|
||||
mStarted = false;
|
||||
|
||||
// add child elements to set up centered spinner rotation
|
||||
mSpinner = new VisualElement();
|
||||
Add(mSpinner);
|
||||
|
||||
mSpinner.style.backgroundImage = Images.GetImage(Images.Name.Loading);
|
||||
mSpinner.style.position = Position.Absolute;
|
||||
mSpinner.style.width = 16;
|
||||
mSpinner.style.height = 16;
|
||||
mSpinner.style.left = -8;
|
||||
mSpinner.style.top = -8;
|
||||
|
||||
style.position = Position.Relative;
|
||||
style.width = 16;
|
||||
style.height = 16;
|
||||
style.left = 8;
|
||||
style.top = 8;
|
||||
}
|
||||
|
||||
internal void Dispose()
|
||||
{
|
||||
if (mStarted)
|
||||
EditorApplication.update -= UpdateProgress;
|
||||
}
|
||||
|
||||
internal void Start()
|
||||
{
|
||||
if (mStarted)
|
||||
return;
|
||||
|
||||
mRotation = 0;
|
||||
mLastRotationTime = EditorApplication.timeSinceStartup;
|
||||
|
||||
EditorApplication.update += UpdateProgress;
|
||||
|
||||
mStarted = true;
|
||||
}
|
||||
|
||||
internal void Stop()
|
||||
{
|
||||
if (!mStarted)
|
||||
return;
|
||||
|
||||
EditorApplication.update -= UpdateProgress;
|
||||
|
||||
mStarted = false;
|
||||
}
|
||||
|
||||
void UpdateProgress()
|
||||
{
|
||||
double currentTime = EditorApplication.timeSinceStartup;
|
||||
double deltaTime = currentTime - mLastRotationTime;
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
mSpinner.transform.rotation = Quaternion.Euler(0, 0, mRotation);
|
||||
#else
|
||||
transform.rotation = Quaternion.Euler(0, 0, mRotation);
|
||||
#endif
|
||||
|
||||
mRotation += (int)(ROTATION_SPEED * deltaTime);
|
||||
mRotation = mRotation % 360;
|
||||
if (mRotation < 0) mRotation += 360;
|
||||
|
||||
mLastRotationTime = currentTime;
|
||||
}
|
||||
|
||||
int mRotation;
|
||||
double mLastRotationTime;
|
||||
bool mStarted;
|
||||
VisualElement mSpinner;
|
||||
|
||||
const int ROTATION_SPEED = 360; // Euler degrees per second
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4664c2d6dd034f04eb60d4190ee2ffb7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,161 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using PlasticGui;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.UIElements
|
||||
{
|
||||
class ProgressControlsForDialogs :
|
||||
VisualElement,
|
||||
IProgressControls
|
||||
{
|
||||
internal class Data
|
||||
{
|
||||
internal bool IsWaitingAsyncResult;
|
||||
internal float ProgressPercent;
|
||||
internal string ProgressMessage;
|
||||
|
||||
internal MessageType StatusType;
|
||||
internal string StatusMessage;
|
||||
|
||||
internal void CopyInto(Data other)
|
||||
{
|
||||
other.IsWaitingAsyncResult = IsWaitingAsyncResult;
|
||||
other.ProgressPercent = ProgressPercent;
|
||||
other.ProgressMessage = ProgressMessage;
|
||||
other.StatusType = StatusType;
|
||||
other.StatusMessage = StatusMessage;
|
||||
}
|
||||
}
|
||||
|
||||
internal Data ProgressData { get { return mData; } }
|
||||
|
||||
internal void ForcedUpdateProgress()
|
||||
{
|
||||
if (mData.IsWaitingAsyncResult)
|
||||
{
|
||||
mUndefinedProgress.RemoveFromClassList("display-none");
|
||||
mPercentageLabel.RemoveFromClassList("display-none");
|
||||
mLoadingSpinner.Start();
|
||||
EditorApplication.update += UpdatePercent;
|
||||
}
|
||||
else
|
||||
{
|
||||
mUndefinedProgress.AddToClassList("display-none");
|
||||
mPercentageLabel.AddToClassList("display-none");
|
||||
mLoadingSpinner.Stop();
|
||||
EditorApplication.update -= UpdatePercent;
|
||||
}
|
||||
|
||||
mStatusLabel.text = mData.StatusMessage;
|
||||
mProgressLabel.text = mData.ProgressMessage;
|
||||
}
|
||||
|
||||
internal void UpdatePercent()
|
||||
{
|
||||
if (mData.ProgressPercent >= 0)
|
||||
mPercentageLabel.text = string.Format("({0}%)", (int)(mData.ProgressPercent * 100));
|
||||
else
|
||||
mPercentageLabel.text = "";
|
||||
}
|
||||
|
||||
internal ProgressControlsForDialogs(
|
||||
VisualElement[] actionControls)
|
||||
{
|
||||
mActionControls = actionControls;
|
||||
|
||||
InitializeLayoutAndStyles();
|
||||
|
||||
BuildComponents();
|
||||
}
|
||||
|
||||
internal void EnableActionControls(bool enable)
|
||||
{
|
||||
if (mActionControls != null)
|
||||
foreach (var control in mActionControls)
|
||||
if (control != null)
|
||||
control.SetEnabled(enable);
|
||||
}
|
||||
|
||||
void IProgressControls.HideProgress()
|
||||
{
|
||||
EnableActionControls(true);
|
||||
|
||||
mData.IsWaitingAsyncResult = false;
|
||||
mData.ProgressMessage = string.Empty;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void IProgressControls.ShowProgress(string message)
|
||||
{
|
||||
EnableActionControls(false);
|
||||
|
||||
CleanStatusMessage(mData);
|
||||
|
||||
mData.IsWaitingAsyncResult = true;
|
||||
mData.ProgressPercent = -1f;
|
||||
mData.ProgressMessage = message;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void IProgressControls.ShowError(string message)
|
||||
{
|
||||
mData.StatusMessage = message;
|
||||
mData.StatusType = MessageType.Error;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void IProgressControls.ShowNotification(string message)
|
||||
{
|
||||
mData.StatusMessage = message;
|
||||
mData.StatusType = MessageType.Info;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void IProgressControls.ShowSuccess(string message)
|
||||
{
|
||||
mData.StatusMessage = message;
|
||||
mData.StatusType = MessageType.Info;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void IProgressControls.ShowWarning(string message)
|
||||
{
|
||||
mData.StatusMessage = message;
|
||||
mData.StatusType = MessageType.Warning;
|
||||
ForcedUpdateProgress();
|
||||
}
|
||||
|
||||
void BuildComponents()
|
||||
{
|
||||
mUndefinedProgress = this.Q<VisualElement>("UndefinedProgress");
|
||||
mProgressLabel = this.Q<Label>("Progress");
|
||||
mStatusLabel = this.Q<Label>("Status");
|
||||
mPercentageLabel = this.Q<Label>("Percentage");
|
||||
|
||||
mLoadingSpinner = new LoadingSpinner();
|
||||
mUndefinedProgress.Add(mLoadingSpinner);
|
||||
}
|
||||
|
||||
void InitializeLayoutAndStyles()
|
||||
{
|
||||
this.LoadLayout(typeof(ProgressControlsForDialogs).Name);
|
||||
|
||||
this.LoadStyle(typeof(ProgressControlsForDialogs).Name);
|
||||
}
|
||||
|
||||
static void CleanStatusMessage(Data data)
|
||||
{
|
||||
data.StatusMessage = string.Empty;
|
||||
data.StatusType = MessageType.None;
|
||||
}
|
||||
|
||||
Data mData = new Data();
|
||||
VisualElement mUndefinedProgress;
|
||||
Label mProgressLabel;
|
||||
Label mStatusLabel;
|
||||
Label mPercentageLabel;
|
||||
VisualElement[] mActionControls;
|
||||
|
||||
LoadingSpinner mLoadingSpinner;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f213e847b2dfa264ea3243bef42fbef0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,90 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
using Unity.PlasticSCM.Editor;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.UIElements
|
||||
{
|
||||
internal class TabView : VisualElement
|
||||
{
|
||||
internal TabView()
|
||||
{
|
||||
InitializeLayoutAndStyles();
|
||||
|
||||
BuildComponents();
|
||||
}
|
||||
|
||||
internal Button AddTab(string name, VisualElement content)
|
||||
{
|
||||
mTabs.Add(name, content);
|
||||
|
||||
Button newButton = new Button()
|
||||
{
|
||||
text = name,
|
||||
name = name
|
||||
};
|
||||
newButton.AddToClassList("tab-button");
|
||||
|
||||
mButtons.Add(name, newButton);
|
||||
|
||||
newButton.clickable.clickedWithEventInfo += OnClickButton;
|
||||
|
||||
mTabArea.Add(newButton);
|
||||
|
||||
if (mTabs.Count == 1)
|
||||
ButtonClicked(newButton);
|
||||
|
||||
return newButton;
|
||||
}
|
||||
|
||||
internal void SwitchContent(VisualElement content)
|
||||
{
|
||||
mContentArea.Clear();
|
||||
mContentArea.Add(content);
|
||||
|
||||
foreach (Button button in mButtons.Values)
|
||||
button.RemoveFromClassList("active");
|
||||
}
|
||||
|
||||
void OnClickButton(EventBase eventBase)
|
||||
{
|
||||
ButtonClicked((Button)eventBase.target);
|
||||
}
|
||||
|
||||
void ButtonClicked(Button clickedButton)
|
||||
{
|
||||
VisualElement content;
|
||||
mTabs.TryGetValue(clickedButton.text, out content);
|
||||
|
||||
mContentArea.Clear();
|
||||
mContentArea.Add(content);
|
||||
|
||||
foreach (Button button in mButtons.Values)
|
||||
button.RemoveFromClassList("active");
|
||||
|
||||
clickedButton.AddToClassList("active");
|
||||
}
|
||||
|
||||
void BuildComponents()
|
||||
{
|
||||
mTabArea = this.Query<VisualElement>("TabArea").First();
|
||||
mContentArea = this.Query<VisualElement>("ContentArea").First();
|
||||
}
|
||||
|
||||
void InitializeLayoutAndStyles()
|
||||
{
|
||||
name = "TabView";
|
||||
|
||||
this.LoadLayout(typeof(TabView).Name);
|
||||
|
||||
this.LoadStyle(typeof(TabView).Name);
|
||||
}
|
||||
|
||||
VisualElement mContentArea;
|
||||
VisualElement mTabArea;
|
||||
|
||||
Dictionary<string, VisualElement> mTabs = new Dictionary<string, VisualElement>();
|
||||
Dictionary<string, Button> mButtons = new Dictionary<string, Button>();
|
||||
}
|
||||
}
|
11
Library/PackageCache/com.unity.collab-proxy@1.17.7/Editor/PlasticSCM/UI/UIElements/TabView.cs.meta
generated
Normal file
11
Library/PackageCache/com.unity.collab-proxy@1.17.7/Editor/PlasticSCM/UI/UIElements/TabView.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3800274d3c9ba2b4b984d8b076a504b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,121 @@
|
|||
using System.IO;
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
using PlasticGui;
|
||||
using Unity.PlasticSCM.Editor.AssetUtils;
|
||||
|
||||
namespace Unity.PlasticSCM.Editor.UI.UIElements
|
||||
{
|
||||
internal static class UIElementsExtensions
|
||||
{
|
||||
internal static void LoadLayout(
|
||||
this VisualElement element,
|
||||
string className)
|
||||
{
|
||||
string uxmlRelativePath = Path.Combine(
|
||||
AssetsPath.GetLayoutsFolderRelativePath(),
|
||||
string.Format("{0}.uxml", className));
|
||||
|
||||
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
uxmlRelativePath);
|
||||
|
||||
if (visualTree == null)
|
||||
{
|
||||
UnityEngine.Debug.LogErrorFormat(
|
||||
"Layout {0} not found at path {1}",
|
||||
className,
|
||||
uxmlRelativePath);
|
||||
return;
|
||||
}
|
||||
|
||||
visualTree.CloneTree(element);
|
||||
}
|
||||
|
||||
internal static void LoadStyle(
|
||||
this VisualElement element,
|
||||
string className)
|
||||
{
|
||||
string ussRelativePath = Path.Combine(
|
||||
AssetsPath.GetStylesFolderRelativePath(),
|
||||
string.Format("{0}.uss", className));
|
||||
|
||||
StyleSheet sheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(
|
||||
ussRelativePath);
|
||||
|
||||
if (sheet != null)
|
||||
{
|
||||
element.styleSheets.Add(sheet);
|
||||
}
|
||||
|
||||
string ussSkinRelativePath = Path.Combine(
|
||||
AssetsPath.GetStylesFolderRelativePath(),
|
||||
string.Format("{0}.{1}.uss",
|
||||
className, EditorGUIUtility.isProSkin ? "dark" : "light"));
|
||||
|
||||
StyleSheet skinSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(
|
||||
ussSkinRelativePath);
|
||||
|
||||
if (skinSheet == null)
|
||||
return;
|
||||
|
||||
element.styleSheets.Add(skinSheet);
|
||||
}
|
||||
|
||||
internal static void FocusOnceLoaded(
|
||||
this TextField elem)
|
||||
{
|
||||
// Really weird behavior from UIElements, apperently in order
|
||||
// to focus a text field you have to wait for it to attach to
|
||||
// the panel and then focus it's TextInputBaseField child
|
||||
// control rather than the TextField itself. For more see:
|
||||
// https://forum.unity.com/threads/focus-doesnt-seem-to-work.901130/
|
||||
elem.RegisterCallback<AttachToPanelEvent>(
|
||||
_ => elem.Q(TextInputBaseField<string>.textInputUssName).Focus());
|
||||
}
|
||||
|
||||
internal static void FocusWorkaround(this TextField textField)
|
||||
{
|
||||
// https://issuetracker.unity3d.com/issues/uielements-textfield-is-not-focused-and-you-are-not-able-to-type-in-characters-when-using-focus-method
|
||||
textField.Q("unity-text-input").Focus();
|
||||
}
|
||||
|
||||
internal static void SetControlImage(
|
||||
this VisualElement element,
|
||||
string name,
|
||||
Images.Name imageName)
|
||||
{
|
||||
Image imageElem = element.Query<Image>(name).First();
|
||||
imageElem.image = Images.GetImage(imageName);
|
||||
}
|
||||
|
||||
internal static void SetControlImage(
|
||||
this VisualElement element,
|
||||
string name,
|
||||
PlasticGui.Help.HelpImage imageName)
|
||||
{
|
||||
Image imageElem = element.Query<Image>(name).First();
|
||||
imageElem.image = Images.GetHelpImage(imageName);
|
||||
imageElem.image.wrapMode = UnityEngine.TextureWrapMode.Clamp;
|
||||
}
|
||||
|
||||
internal static void SetControlText<T>(
|
||||
this VisualElement element,
|
||||
string name, PlasticLocalization.Name fieldName,
|
||||
params string[] format) where T : VisualElement
|
||||
{
|
||||
dynamic control = element.Query<T>(name).First();
|
||||
string str = PlasticLocalization.GetString(fieldName);
|
||||
control.text = format.Length > 0 ? string.Format(str, format) : str;
|
||||
}
|
||||
|
||||
internal static void SetControlLabel<T>(
|
||||
this VisualElement element,
|
||||
string name, PlasticLocalization.Name fieldName) where T : VisualElement
|
||||
{
|
||||
dynamic control = element.Query<T>(name).First();
|
||||
control.label = PlasticLocalization.GetString(fieldName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: daa34ff7d97bebd41866fd45e507c80e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue