Пример #1
0
        public void Init(Argument initArg, bool renamable = false)
        {
            arg            = initArg;
            this.renamable = renamable;

            // Configure text
            if (arg.type == Argument.Type.REGISTER)
            {
                inputField.text = "R" + arg.val.ToString();
            }
            else
            {
                inputField.text = arg.label.name;
            }

            // Configure token color
            ArgTokenColorMap.Type tokenType = arg.type == Argument.Type.REGISTER
                ? ArgTokenColorMap.Type.REGISTER
                : arg.label.type == Label.Type.BRANCH
                ? ArgTokenColorMap.Type.BRANCH_LABEL
                : ArgTokenColorMap.Type.CONST_LABEL;
            image.color = argTokenColorMap.map[tokenType];

            // Resize to fit the preferred width
            Resize();

            // Configure callbacks n' stuff
            draggable.Init(Globals.slotFields, Globals.trashSlots);
            draggable.onDragStart = () =>
            {
                image.raycastTarget = false;
                cg.blocksRaycasts   = false;
            };
            draggable.onDragEnd = () =>
            {
                image.raycastTarget = true;
                cg.blocksRaycasts   = true;
            };
            draggable.onDragSuccess = (Draggable.Slot slot) =>
            {
                if (slotField != null)
                {
                    arg = slotField.ReleaseArg();
                }
                ((SlotField)slot).InsertArg(arg, gameObject);
            };
            draggable.onDragTrash = (Draggable.Slot slot) =>
            {
                slotField?.ReleaseArg();
                Destroy(gameObject);
            };

            inputField.onDeselect.AddListener(RenameLabel);
            inputField.onSubmit.AddListener((string val) => EventSystem.current.SetSelectedGameObject(null));
            inputField.onValueChanged.AddListener((string newVal) => Resize());
            inputField.onValidateInput = ValidateInput;
        }
Пример #2
0
        public void Init(Argument initArg, CodeList codeList, SlotField slotField)
        {
            arg            = initArg;
            this.codeList  = codeList;
            this.slotField = slotField;

            // Configure text
            if (arg.type == Argument.Type.REGISTER)
            {
                inputField.text = "R" + arg.val.ToString();
            }
            else
            {
                inputField.text = arg.label.name;
            }

            // Configure token color
            ArgTokenColorMap.Type tokenType = arg.type == Argument.Type.REGISTER
                ? arg.val < VirtualMachine.NUM_LOCAL_REGS
                ? ArgTokenColorMap.Type.LOCAL_REGISTER
                : ArgTokenColorMap.Type.SHARED_REGISTER
                : arg.label.type == Label.Type.BRANCH
                ? ArgTokenColorMap.Type.BRANCH_LABEL
                : ArgTokenColorMap.Type.CONST_LABEL;
            image.color = argTokenColorMap.map[tokenType];

            // Configure callbacks n' stuff
            draggable.Init(codeList.SlotFields, codeList.TrashSlots);
            draggable.onDragStart = () =>
            {
                image.raycastTarget = false;
                cg.blocksRaycasts   = false;
            };
            draggable.onDragEnd = () =>
            {
                image.raycastTarget = true;
                cg.blocksRaycasts   = true;
            };
            draggable.onDragSuccess = (Draggable.Slot slot) =>
            {
                if (slotField != null)
                {
                    arg = slotField.ReleaseArg();
                }
                ((SlotField)slot).InsertArg(arg);
                if (slotField == null)
                {
                    Destroy(gameObject);
                }
            };
            draggable.onDragTrash = (Draggable.Slot slot) =>
            {
                slotField?.ReleaseArg();
                Destroy(gameObject);
            };
        }