207 lines
7.0 KiB
C#
207 lines
7.0 KiB
C#
![]() |
using UnityEngine;
|
|||
|
using UnityEngine.UIElements;
|
|||
|
|
|||
|
namespace AlicizaX.PackageManager.Editor
|
|||
|
{
|
|||
|
internal class PackageInfoView : VisualElement
|
|||
|
{
|
|||
|
private VisualElement _mainContainer;
|
|||
|
private VisualElement _headContainer;
|
|||
|
private Label _displayName;
|
|||
|
private Label _versionWithDate;
|
|||
|
private Label _authorLabel;
|
|||
|
private Label _packageNameLabel;
|
|||
|
private Label _projectDescription;
|
|||
|
private Label _btnLinkHtml;
|
|||
|
|
|||
|
|
|||
|
private VisualElement packageBtnContainer;
|
|||
|
|
|||
|
|
|||
|
private Button _btnUpdate;
|
|||
|
private Button _btnInstall;
|
|||
|
private Button _btnRemove;
|
|||
|
|
|||
|
|
|||
|
private RepositoryPackageData _selectRepositoryPackageData;
|
|||
|
|
|||
|
public PackageInfoView()
|
|||
|
{
|
|||
|
style.flexShrink = 1;
|
|||
|
style.height = Length.Percent(100);
|
|||
|
|
|||
|
_mainContainer = new VisualElement()
|
|||
|
{
|
|||
|
name = "MainContainer"
|
|||
|
};
|
|||
|
_mainContainer.style.flexShrink = 1;
|
|||
|
_mainContainer.style.height = Length.Percent(100);
|
|||
|
|
|||
|
|
|||
|
_headContainer = new VisualElement()
|
|||
|
{
|
|||
|
name = "HeadContainer"
|
|||
|
};
|
|||
|
_headContainer.style.flexShrink = 1;
|
|||
|
_headContainer.style.height = Length.Percent(35);
|
|||
|
_headContainer.style.paddingLeft = 10;
|
|||
|
_headContainer.style.paddingTop = 10;
|
|||
|
|
|||
|
_mainContainer.Add(_headContainer);
|
|||
|
|
|||
|
|
|||
|
_displayName = new Label()
|
|||
|
{
|
|||
|
name = "DisplayName"
|
|||
|
};
|
|||
|
_displayName.style.fontSize = 19;
|
|||
|
_displayName.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|||
|
|
|||
|
_versionWithDate = new Label()
|
|||
|
{
|
|||
|
name = "VersionWithDate"
|
|||
|
};
|
|||
|
_versionWithDate.style.fontSize = 13;
|
|||
|
_versionWithDate.style.unityFontStyleAndWeight = FontStyle.Bold;
|
|||
|
_versionWithDate.style.paddingTop = 5;
|
|||
|
|
|||
|
|
|||
|
_authorLabel = new Label()
|
|||
|
{
|
|||
|
name = "AuthorLabel"
|
|||
|
};
|
|||
|
_authorLabel.style.fontSize = 12;
|
|||
|
_authorLabel.style.paddingTop = 5;
|
|||
|
_authorLabel.style.unityFontStyleAndWeight = FontStyle.Italic;
|
|||
|
|
|||
|
_packageNameLabel = new Label()
|
|||
|
{
|
|||
|
name = "PackageName"
|
|||
|
};
|
|||
|
_packageNameLabel.style.fontSize = 12;
|
|||
|
_packageNameLabel.style.paddingTop = 5;
|
|||
|
_packageNameLabel.style.unityFontStyleAndWeight = FontStyle.Italic;
|
|||
|
|
|||
|
_projectDescription = new Label()
|
|||
|
{
|
|||
|
name = "ProjectDescription"
|
|||
|
};
|
|||
|
_projectDescription.style.fontSize = 12;
|
|||
|
_projectDescription.style.paddingTop = 5;
|
|||
|
|
|||
|
|
|||
|
_btnLinkHtml = new Label()
|
|||
|
{
|
|||
|
name = "BtnLink"
|
|||
|
};
|
|||
|
|
|||
|
_btnLinkHtml.text = "Source Code";
|
|||
|
_btnLinkHtml.style.fontSize = 12;
|
|||
|
_btnLinkHtml.style.paddingTop = 5;
|
|||
|
_btnLinkHtml.style.marginLeft = 0;
|
|||
|
_btnLinkHtml.style.paddingLeft = 0;
|
|||
|
_btnLinkHtml.style.flexGrow = 0;
|
|||
|
_btnLinkHtml.style.minWidth = new Length(20, LengthUnit.Pixel);
|
|||
|
_btnLinkHtml.style.maxWidth = new Length(300, LengthUnit.Pixel);
|
|||
|
_btnLinkHtml.style.color = new Color(0.2980392f, 0.498f, 1f);
|
|||
|
_btnLinkHtml.style.backgroundColor = Color.clear;
|
|||
|
_btnLinkHtml.RegisterCallback<ClickEvent>(OnBtnLinkClick);
|
|||
|
|
|||
|
packageBtnContainer = new VisualElement()
|
|||
|
{
|
|||
|
name = "PackageBtnContainer"
|
|||
|
};
|
|||
|
|
|||
|
packageBtnContainer.style.flexShrink = 1;
|
|||
|
packageBtnContainer.style.height = Length.Percent(100);
|
|||
|
packageBtnContainer.style.flexDirection = FlexDirection.Row;
|
|||
|
packageBtnContainer.style.paddingTop = 10;
|
|||
|
|
|||
|
|
|||
|
_headContainer.Add(_displayName);
|
|||
|
_headContainer.Add(_versionWithDate);
|
|||
|
_headContainer.Add(_authorLabel);
|
|||
|
_headContainer.Add(_packageNameLabel);
|
|||
|
_headContainer.Add(_projectDescription);
|
|||
|
_headContainer.Add(_btnLinkHtml);
|
|||
|
_headContainer.Add(packageBtnContainer);
|
|||
|
|
|||
|
_btnUpdate = new Button(OnBtnUpdate)
|
|||
|
{
|
|||
|
name = "BtnUpdate"
|
|||
|
};
|
|||
|
_btnUpdate.text = "Update";
|
|||
|
_btnUpdate.style.width = new Length(90, LengthUnit.Pixel);
|
|||
|
_btnUpdate.style.height = new Length(24, LengthUnit.Pixel);
|
|||
|
_btnUpdate.style.marginLeft = 0;
|
|||
|
|
|||
|
_btnInstall = new Button(OnBtnInstall)
|
|||
|
{
|
|||
|
name = "BtnInstall"
|
|||
|
};
|
|||
|
_btnInstall.text = "Install";
|
|||
|
_btnInstall.style.width = new Length(90, LengthUnit.Pixel);
|
|||
|
_btnInstall.style.height = new Length(24, LengthUnit.Pixel);
|
|||
|
_btnInstall.style.marginLeft = 0;
|
|||
|
|
|||
|
_btnRemove = new Button(OnBtnRemove)
|
|||
|
{
|
|||
|
name = "BtnRemove"
|
|||
|
};
|
|||
|
_btnRemove.text = "Remove";
|
|||
|
_btnRemove.style.width = new Length(90, LengthUnit.Pixel);
|
|||
|
_btnRemove.style.height = new Length(24, LengthUnit.Pixel);
|
|||
|
_btnRemove.style.marginLeft = 0;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
packageBtnContainer.Add(_btnInstall);
|
|||
|
packageBtnContainer.Add(_btnUpdate);
|
|||
|
packageBtnContainer.Add(_btnRemove);
|
|||
|
|
|||
|
Add(_mainContainer);
|
|||
|
RefreshView(_selectRepositoryPackageData);
|
|||
|
}
|
|||
|
|
|||
|
public void RefreshView(RepositoryPackageData repositoryPackageData)
|
|||
|
{
|
|||
|
if (repositoryPackageData == null)
|
|||
|
{
|
|||
|
_mainContainer.visible = false;
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
_selectRepositoryPackageData = repositoryPackageData;
|
|||
|
|
|||
|
_mainContainer.visible = true;
|
|||
|
_displayName.text = repositoryPackageData.displayName;
|
|||
|
_versionWithDate.text = $"{repositoryPackageData.version}· {repositoryPackageData.updatedAt}";
|
|||
|
_authorLabel.text = $"Author: {repositoryPackageData.authorName}";
|
|||
|
_packageNameLabel.text = repositoryPackageData.name;
|
|||
|
_projectDescription.text = string.IsNullOrEmpty(repositoryPackageData.description) ? "Description:TODO" : repositoryPackageData.description;
|
|||
|
|
|||
|
|
|||
|
_btnInstall.style.display = repositoryPackageData.PackageState == PackageState.UnInstall ? DisplayStyle.Flex : DisplayStyle.None;
|
|||
|
_btnUpdate.style.display = repositoryPackageData.PackageState == PackageState.Update ? DisplayStyle.Flex : DisplayStyle.None;
|
|||
|
_btnRemove.style.display = repositoryPackageData.PackageState == PackageState.Update || repositoryPackageData.PackageState == PackageState.Install ? DisplayStyle.Flex : DisplayStyle.None;
|
|||
|
}
|
|||
|
|
|||
|
private void OnBtnLinkClick(ClickEvent e)
|
|||
|
{
|
|||
|
Application.OpenURL(_selectRepositoryPackageData.htmlUrl);
|
|||
|
}
|
|||
|
|
|||
|
private void OnBtnUpdate()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void OnBtnInstall()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void OnBtnRemove()
|
|||
|
{
|
|||
|
}
|
|||
|
}
|
|||
|
}
|