Implement action bar.
This commit is contained in:
28
Assets/Cryville/Crtr/Browsing/UI/ActionBar.cs
Normal file
28
Assets/Cryville/Crtr/Browsing/UI/ActionBar.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Cryville.Crtr.Browsing.Actions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.UI {
|
||||
internal class ActionBar : MonoBehaviour {
|
||||
[SerializeField]
|
||||
ActionButton m_mainButton;
|
||||
|
||||
public void Load(ResourceBrowser browser, IReadOnlyCollection<IResourceAction> actions) {
|
||||
var enumerator = actions.OrderBy(i => i.Priority).GetEnumerator();
|
||||
if (enumerator.MoveNext()) {
|
||||
gameObject.SetActive(true);
|
||||
m_mainButton.Load(browser, enumerator.Current);
|
||||
// TODO Subactions
|
||||
}
|
||||
else {
|
||||
m_mainButton.Clear();
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Browsing/UI/ActionBar.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/ActionBar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2023a3c5fbf0e144588637193aabf286
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Cryville/Crtr/Browsing/UI/ActionButton.cs
Normal file
29
Assets/Cryville/Crtr/Browsing/UI/ActionButton.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Cryville.Crtr.Browsing.Actions;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.UI {
|
||||
internal class ActionButton : MonoBehaviour, IPointerClickHandler {
|
||||
[SerializeField]
|
||||
TextMeshProUGUI m_text;
|
||||
|
||||
ResourceBrowser _browser;
|
||||
IResourceAction _action;
|
||||
|
||||
public void Load(ResourceBrowser browser, IResourceAction action) {
|
||||
gameObject.SetActive(true);
|
||||
_browser = browser;
|
||||
_action = action;
|
||||
m_text.text = action.Name;
|
||||
}
|
||||
public void Clear() {
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData) {
|
||||
if (_action == null) return;
|
||||
_browser.InvokeAction(_action);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Cryville/Crtr/Browsing/UI/ActionButton.cs.meta
Normal file
11
Assets/Cryville/Crtr/Browsing/UI/ActionButton.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a8a3fbcb7ecfd941bcc43425f01cfef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -20,7 +20,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
[SerializeField]
|
||||
DetailPanel m_detailPanel;
|
||||
[SerializeField]
|
||||
GameObject m_actionBar;
|
||||
ActionBar m_actionBar;
|
||||
|
||||
IPathedResourceManager<ChartDetail> _manager;
|
||||
IResourceAction _importAction;
|
||||
@@ -77,6 +77,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
_items.Clear();
|
||||
m_itemContainer.ItemCount = _manager.Count;
|
||||
m_detailPanel.Clear();
|
||||
m_actionBar.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,8 +103,9 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
_selectedItems.Clear();
|
||||
_items[id].OnSelect();
|
||||
_selectedItems.Add(id);
|
||||
m_detailPanel.Load(_manager[id]);
|
||||
m_actionBar.SetActive(true);
|
||||
ChartDetail res = _manager[id];
|
||||
m_detailPanel.Load(res);
|
||||
m_actionBar.Load(this, Master.Actions.GetActions(res.GetType()));
|
||||
}
|
||||
|
||||
public void OnPathClicked(int index) {
|
||||
@@ -121,5 +123,19 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
if (result != 0) return;
|
||||
foreach (var item in _selectedItems.OrderByDescending(i => i)) _manager.RemoveAt(item);
|
||||
}
|
||||
|
||||
public override void InvokeAction(IResourceAction action) {
|
||||
if (_selectedItems.Count == 0) {
|
||||
Popup.Create("No item is selected.");
|
||||
return;
|
||||
}
|
||||
if (_selectedItems.Count > 1) {
|
||||
Popup.Create("Cannot run this action with multiple items.");
|
||||
return;
|
||||
}
|
||||
foreach (var i in _selectedItems) {
|
||||
action.Invoke(_manager.GetItemUri(i), _manager[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using Cryville.Crtr.Browsing.Actions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.UI {
|
||||
@@ -10,5 +11,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
protected void Init(ResourceBrowserMaster master) {
|
||||
Master = master;
|
||||
}
|
||||
|
||||
public abstract void InvokeAction(IResourceAction action);
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using Cryville.Crtr.Browsing.Actions;
|
||||
using Cryville.Crtr.Config;
|
||||
using Cryville.Crtr.Config.UI;
|
||||
|
||||
@@ -6,5 +7,6 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
protected virtual void Awake() {
|
||||
GetComponent<PropertyMasterPanel>().Adapter = new DefaultPropertyMasterAdapter(Settings.Default);
|
||||
}
|
||||
public override void InvokeAction(IResourceAction action) { }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user