names in toolbar
This commit is contained in:
+12
-12
@@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using Unity.VectorGraphics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
@@ -16,23 +17,17 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Gate GatePrefab {
|
||||
public Gate GatePrefab
|
||||
{
|
||||
set
|
||||
{
|
||||
_gatePrefab = value;
|
||||
var sprite = _gatePrefab.GetComponentInChildren<SpriteRenderer>().sprite;
|
||||
GetComponent<SVGImage>().sprite = sprite;
|
||||
RectTransform.sizeDelta = new Vector2(100 * sprite.rect.width / 700f, 100); // TODO get max width from UIManager
|
||||
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.GateType.ToString();
|
||||
}
|
||||
}
|
||||
public RectTransform RectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rectTransform == null)
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
return _rectTransform;
|
||||
GetComponentInChildren<TextMeshProUGUI>().text = _gatePrefab.GateType.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +42,11 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
GameManager.Instance.CreateGate(_gatePrefab);
|
||||
|
||||
@@ -39,8 +39,8 @@ namespace UntitledLogicGame.UI
|
||||
{
|
||||
var uiGate = Instantiate(UIGatePrefab, GateBar.transform);
|
||||
uiGate.GatePrefab = gatePrefab;
|
||||
uiGate.RectTransform.anchoredPosition = new Vector2(currentPos, 0);
|
||||
currentPos += uiGate.RectTransform.sizeDelta.x;
|
||||
uiGate.GetComponent<RectTransform>().anchoredPosition = new Vector2(currentPos, 0);
|
||||
currentPos += 100f;
|
||||
}
|
||||
|
||||
MovingBar.SetActive(false);
|
||||
|
||||
@@ -9,15 +9,21 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
{
|
||||
public enum GateType
|
||||
{
|
||||
None,
|
||||
Buffer,
|
||||
NOTGate,
|
||||
ANDGate,
|
||||
ORGate,
|
||||
XORGate,
|
||||
NANDGate,
|
||||
NORGate,
|
||||
XNORGate
|
||||
// 000 Technical
|
||||
NONE = 000,
|
||||
// 100 Special
|
||||
IN = 100,
|
||||
OUT = 110,
|
||||
// 200 Basic
|
||||
BUF = 200,
|
||||
AND = 210,
|
||||
OR = 220,
|
||||
XOR = 230,
|
||||
// 300 Inverted Basic
|
||||
NOT = 300,
|
||||
NAND = 310,
|
||||
NOR = 320,
|
||||
XNOR = 330,
|
||||
}
|
||||
|
||||
public abstract class GateDefinition
|
||||
@@ -32,8 +38,16 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
Definitions = new Dictionary<GateType, GateDefinition>();
|
||||
foreach (var gateType in Enum.GetValues(typeof(GateType)).Cast<GateType>())
|
||||
{
|
||||
Type t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}", true);
|
||||
Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]);
|
||||
try
|
||||
{
|
||||
Type t = Type.GetType($"{typeof(GateDefinition).Namespace}.{gateType}Gate", true);
|
||||
Definitions[gateType] = (GateDefinition)t.GetConstructor(new Type[0]).Invoke(new object[0]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Definitions[gateType] = (GateDefinition)typeof(NoneGate).GetConstructor(new Type[0]).Invoke(new object[0]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +150,7 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
|
||||
#region Gates
|
||||
|
||||
internal class None : GateDefinition
|
||||
internal class NoneGate : GateDefinition
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { };
|
||||
public override string[] Outputs { get; } = new string[] { };
|
||||
@@ -145,7 +159,7 @@ namespace UntitledLogicGame.Workspace.Gates
|
||||
};
|
||||
}
|
||||
|
||||
internal class Buffer : GateDefinition
|
||||
internal class BufferGate : GateDefinition
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "A" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q" };
|
||||
|
||||
Reference in New Issue
Block a user