gate sub-categories
This commit is contained in:
@@ -8,8 +8,9 @@ namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
#region Unity Properties
|
||||
|
||||
public SVGImage closedImage;
|
||||
public SVGImage openImage;
|
||||
|
||||
#endregion
|
||||
@@ -20,39 +21,47 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private SVGImage Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_image == null)
|
||||
_image = GetComponentInChildren<SVGImage>();
|
||||
return _image;
|
||||
}
|
||||
}
|
||||
|
||||
private SVGImage _image;
|
||||
private Sprite _closedSprite;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_image = GetComponent<SVGImage>();
|
||||
_closedSprite = _image.sprite;
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
_image.sprite = openImage.sprite;
|
||||
Image.sprite = openImage.sprite;
|
||||
PointerManager.Instance.DeleteOnRelease = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_image.sprite = _closedSprite;
|
||||
Image.sprite = closedImage.sprite;
|
||||
PointerManager.Instance.DeleteOnRelease = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
private void OnEnable()
|
||||
{
|
||||
Image.sprite = closedImage.sprite;
|
||||
}
|
||||
|
||||
#region Public Methods
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Public Methods
|
||||
|
||||
#region Private Methods
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Unity.VectorGraphics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIFolder : UIToolbarButton
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
public SVGImage folderImage;
|
||||
public SVGImage backImage;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public bool IsBack { get; set; }
|
||||
public string Name
|
||||
{
|
||||
set
|
||||
{
|
||||
Text.text = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Image.sprite = IsBack ? backImage.sprite : folderImage.sprite;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc88317bf8def394099cd222acc35347
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+20
-33
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VectorGraphics;
|
||||
@@ -9,48 +10,34 @@ using UntitledLogicGame.Workspace;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIGate : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
public class UIGate : UIToolbarButton
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public Gate GatePrefab
|
||||
{
|
||||
set
|
||||
{
|
||||
_gatePrefab = value;
|
||||
var sprite = _gatePrefab.GetComponentInChildren<SpriteRenderer>().sprite;
|
||||
var subimage = GetComponentInChildren<SVGImage>();
|
||||
subimage.sprite = sprite;
|
||||
subimage.GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 100 * sprite.rect.width / 700f); // TODO get max width from UIManager
|
||||
gameObject.name = "UI_" + _gatePrefab.Definition.Name;
|
||||
GetComponentInChildren<TextMeshProUGUI>().text = _gatePrefab.Definition.Name;
|
||||
}
|
||||
}
|
||||
public Gate GatePrefab
|
||||
{
|
||||
set
|
||||
{
|
||||
var sprite = value.GetComponentInChildren<SpriteRenderer>().sprite;
|
||||
Image.sprite = sprite;
|
||||
Image.GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 100 * sprite.rect.width / 700f); // TODO get max width from UIManager
|
||||
gameObject.name = "UI_" + value.Definition.Name;
|
||||
Text.text = value.Definition.Name;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private Gate _gatePrefab;
|
||||
#region Private Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
GameManager.Instance.CreateGate(_gatePrefab);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UntitledLogicGame.Workspace.Gates;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
@@ -15,41 +17,45 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
[Header("Prefabs")]
|
||||
public UIGate UIGatePrefab;
|
||||
public UIFolder UIFolderPrefab;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public GateCategory GateBarState
|
||||
{
|
||||
get => _gateBarState;
|
||||
set
|
||||
{
|
||||
_gateBarState = value;
|
||||
UpdateGateBar();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private bool _lastMouseInteracting;
|
||||
private GateCategory _gateBarState;
|
||||
private Dictionary<GateCategory, GameObject> _gateBarSateList;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private IEnumerator Start()
|
||||
private IEnumerator Start()
|
||||
{
|
||||
yield return new WaitUntil(() => GameManager.Instance != null);
|
||||
// TODO calculate max width
|
||||
var currentPos = 0f;
|
||||
foreach(var gatePrefab in GameManager.Instance.GatePrefabs)
|
||||
{
|
||||
var uiGate = Instantiate(UIGatePrefab, GateBar.transform);
|
||||
uiGate.GatePrefab = gatePrefab;
|
||||
uiGate.GetComponent<RectTransform>().anchoredPosition = new Vector2(currentPos, 0);
|
||||
currentPos += 100f;
|
||||
}
|
||||
|
||||
MovingBar.SetActive(false);
|
||||
}
|
||||
CreateGateBar();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateUI();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -70,6 +76,74 @@ namespace UntitledLogicGame.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateGateBar()
|
||||
{
|
||||
_gateBarSateList = new Dictionary<GateCategory, GameObject>();
|
||||
|
||||
var allCategories = Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>();
|
||||
|
||||
foreach (var category in allCategories)
|
||||
{
|
||||
var parent = new GameObject(category.ToString(), typeof(RectTransform));
|
||||
parent.transform.parent = GateBar.transform;
|
||||
var rect = parent.GetComponent<RectTransform>();
|
||||
rect.anchorMin = Vector2.zero;
|
||||
rect.anchorMax = new Vector2(1, 1);
|
||||
rect.position = Vector2.zero;
|
||||
rect.offsetMin = Vector2.zero;
|
||||
parent.SetActive(false);
|
||||
if(category == GateCategory.None)
|
||||
{
|
||||
var currentPos = 0f;
|
||||
foreach (var subCategory in allCategories)
|
||||
{
|
||||
if(subCategory != GateCategory.None)
|
||||
{
|
||||
var uiFolder = Instantiate(UIFolderPrefab, parent.transform);
|
||||
uiFolder.Rect.anchoredPosition = new Vector2(currentPos, 0);
|
||||
uiFolder.Name = subCategory.ToString();
|
||||
uiFolder.OnClick = () =>
|
||||
{
|
||||
GateBarState = subCategory;
|
||||
};
|
||||
currentPos += 100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var uiFolder = Instantiate(UIFolderPrefab, parent.transform);
|
||||
uiFolder.Name = "Back";
|
||||
uiFolder.IsBack = true;
|
||||
uiFolder.OnClick = () =>
|
||||
{
|
||||
GateBarState = GateCategory.None;
|
||||
};
|
||||
var currentPos = 100f;
|
||||
var possibleGateTypes = GateDefinition.TypeCategoryList[category];
|
||||
foreach (var gatePrefab in GameManager.Instance.GatePrefabs.Where(g => possibleGateTypes.Contains(g.GateType)))
|
||||
{
|
||||
var uiGate = Instantiate(UIGatePrefab, parent.transform);
|
||||
uiGate.GatePrefab = gatePrefab;
|
||||
uiGate.Rect.anchoredPosition = new Vector2(currentPos, 0);
|
||||
uiGate.OnClick = () => {
|
||||
GameManager.Instance.CreateGate(gatePrefab);
|
||||
};
|
||||
currentPos += 100f;
|
||||
}
|
||||
}
|
||||
_gateBarSateList[category] = parent;
|
||||
}
|
||||
UpdateGateBar();
|
||||
}
|
||||
|
||||
private void UpdateGateBar()
|
||||
{
|
||||
//TODO animate ?
|
||||
foreach (var category in Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>())
|
||||
_gateBarSateList[category].SetActive(category == GateBarState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VectorGraphics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIToolbarButton : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public SVGImage Image
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_image == null)
|
||||
_image = GetComponentInChildren<SVGImage>();
|
||||
return _image;
|
||||
}
|
||||
}
|
||||
public TextMeshProUGUI Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null)
|
||||
_text = GetComponentInChildren<TextMeshProUGUI>();
|
||||
return _text;
|
||||
}
|
||||
}
|
||||
public RectTransform Rect
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rect == null)
|
||||
_rect = GetComponent<RectTransform>();
|
||||
return _rect;
|
||||
}
|
||||
}
|
||||
public Action OnClick { get; set; }
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
|
||||
private SVGImage _image;
|
||||
private TextMeshProUGUI _text;
|
||||
private RectTransform _rect;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (OnClick != null)
|
||||
OnClick();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ba7b67ac81cbb241bf0184566a7d00b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,9 +8,18 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
{
|
||||
// Static properties
|
||||
private static Dictionary<GateType, GateDefinition> Definitions;
|
||||
public static Dictionary<GateCategory, List<GateType>> TypeCategoryList =>
|
||||
Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>()
|
||||
.ToDictionary(
|
||||
c => c,
|
||||
c => Enum.GetValues(typeof(GateType)).Cast<GateType>()
|
||||
.Where(t => (GateCategory)((int)t / 100) == c).ToList()
|
||||
);
|
||||
|
||||
// Public properties
|
||||
public string Name { get; internal set; }
|
||||
public GateType Type { get; private set; }
|
||||
public GateCategory Category => (GateCategory)((int)Type / 100);
|
||||
public string Name => Type.ToString();
|
||||
public bool HasState => false;
|
||||
public Dictionary<InputState, OutputState> TruthTable { get; private set; } = new Dictionary<InputState, OutputState>();
|
||||
|
||||
@@ -27,9 +36,9 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
Definitions = new Dictionary<GateType, GateDefinition>();
|
||||
foreach (var gateType in Enum.GetValues(typeof(GateType)).Cast<GateType>())
|
||||
{
|
||||
var t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true);
|
||||
var t = System.Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true);
|
||||
Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]);
|
||||
Definitions[gateType].Name = gateType.ToString();
|
||||
Definitions[gateType].Type = gateType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
public enum GateType
|
||||
{
|
||||
// 000 - Technical
|
||||
NONE = 000,
|
||||
// 100 - Special
|
||||
None = 000,
|
||||
// 100 - I/O
|
||||
IN = 100,
|
||||
OUT = 110,
|
||||
// 200 - Basic
|
||||
@@ -28,7 +28,7 @@
|
||||
// 500 - Arithmetic
|
||||
HalfAdd = 500,
|
||||
FullAdd = 510,
|
||||
HalSub = 520,
|
||||
HalfSub = 520,
|
||||
FullSub = 530,
|
||||
// 600 - Data
|
||||
Mux = 610,
|
||||
@@ -45,4 +45,17 @@
|
||||
Counter2b = 800,
|
||||
Counter4b = 810
|
||||
}
|
||||
|
||||
public enum GateCategory
|
||||
{
|
||||
None = 00,
|
||||
IO = 01,
|
||||
Basic = 02,
|
||||
Latches = 03,
|
||||
FlipFlops = 04,
|
||||
Arithmetic = 05,
|
||||
Data = 06,
|
||||
Registers = 07,
|
||||
Counters = 08
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user