예제 #1
0
        // lineNumber == -1 signifies no line number
        public void Init(int lineNumber, Instruction instruction, Divider myDivider, CodeList codeList)
        {
            base.Init(myDivider, codeList);
            this.lineNumber  = lineNumber;
            this.instruction = instruction;

            draggable.onDragSuccess = (Draggable.Slot slot) =>
            {
                Insert(slot);
                // Reset frontend
                Destroy(gameObject);
                codeList.Program.BroadcastInstructionChange();
            };
            draggable.onDragTrash = (Draggable.Slot slot) =>
            {
                if (lineNumber != -1)
                {
                    Remove();
                    codeList.Program.BroadcastInstructionChange();
                }
                Destroy(gameObject);
            };

            // Configure text
            opCodeTM.text = instruction.opCode.ToString();

            // Configure color
            OpCategory category = InstructionMaps.opCodeOpCategoryMap[instruction.opCode];

            bg.color = opCategoryColorMap.map[category];

            // Configure tips
            string buffer;

            InstructionMaps.opDescriptiveNameMap.TryGetValue(instruction.opCode, out buffer);
            GetComponent <DisplaysTips>().Init(buffer);

            // Create argument fields
            ArgumentSpec[] argSpecs = InstructionMaps.opArgSpecMap[instruction.opCode];
            for (int argNum = 0; argNum < instruction.args.Length; ++argNum)
            {
                GameObject field;
                Argument   arg = instruction.args[argNum];

                if (argSpecs[argNum].regOnly || argSpecs[argNum].presets != null)
                {
                    field = Instantiate(dropdownFieldPrefab, transform);
                    field.GetComponent <DropdownField>().Init(argSpecs[argNum], arg, codeList);
                }
                else
                {
                    field = Instantiate(slotFieldPrefab, transform);
                    field.GetComponent <SlotField>().Init(arg, codeList);
                }
                field.GetComponent <DisplaysTips>().Init(argSpecs[argNum].name);
            }
        }
예제 #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);
            };
        }
예제 #3
0
        public void Init(ArgumentSpec argSpec, Argument arg, CodeList codeList)
        {
            this.arg = arg;

            // Configure dropdown options
            dropdown = GetComponent <TMP_Dropdown>();
            TextMeshProUGUI tm = GetComponentInChildren <TextMeshProUGUI>();

            float maxPreferredWidth = 0;

            if (argSpec.regOnly)
            {
                for (int regNum = 0; regNum < VirtualMachine.NUM_TOTAL_REGS; ++regNum)
                {
                    string regName = "R" + regNum;
                    dropdown.options.Add(new TMP_Dropdown.OptionData(regName));
                    maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(regName).x, maxPreferredWidth);
                }
            }
            else
            {
                foreach (string presetName in argSpec.presets)
                {
                    dropdown.options.Add(new TMP_Dropdown.OptionData(presetName));
                    maxPreferredWidth = Mathf.Max(tm.GetPreferredValues(presetName).x, maxPreferredWidth);
                }
            }

            // Register value change handlers
            Argument.Type argType = argSpec.regOnly ? Argument.Type.REGISTER : Argument.Type.IMMEDIATE;
            dropdown.onValueChanged.AddListener((int val) =>
            {
                if (selfChange.Value)
                {
                    return;
                }
                arg.val          = val;
                selfChange.Value = true;
                arg.BroadcastChange();
                codeList.Program.BroadcastArgumentChange();
            });
            arg.OnChange += HandleArgChange;

            // Init value
            HandleArgChange();

            // Resize to fit the max preferred width
            RectTransform dropdownRT = dropdown.GetComponent <RectTransform>();
            RectTransform labelRT    = tm.GetComponent <RectTransform>();

            dropdownRT.sizeDelta = new Vector2(maxPreferredWidth - labelRT.sizeDelta.x, dropdownRT.sizeDelta.y);
        }
예제 #4
0
        public void Init(Argument arg, CodeList codeList)
        {
            this.arg      = arg;
            this.codeList = codeList;
            codeList.SlotFields.Add(this);

            inputField.onEndEdit.AddListener((string val) =>
            {
                arg.val = int.Parse(val);
                arg.BroadcastChange();
                codeList.Program.BroadcastArgumentChange();
            });

            arg.OnChange += UpdateFrontend;
            UpdateFrontend();
            inputField.onValueChanged.AddListener(Resize);
        }
예제 #5
0
        public void Init(Label label, Divider myDivider, CodeList codeList)
        {
            base.Init(myDivider, codeList);
            this.label = label;

            string labelText = label.name + " (" + label.val + ")";

            GetComponentInChildren <TextMeshProUGUI>().text = labelText;

            Draggable draggable = GetComponent <Draggable>();

            draggable.onDragSuccess = Move;
            draggable.onDragTrash   = (Draggable.Slot slot) =>
            {
                codeList.Program.RemoveLabel(label);
                Destroy(gameObject);
            };
        }
예제 #6
0
        protected void Init(Divider myDivider, CodeList codeList)
        {
            this.myDivider = myDivider;
            this.codeList  = codeList;

            draggable.Init(codeList.Dividers, codeList.TrashSlots);
            draggable.filterFunc  = (Draggable.Slot slot) => slot == myDivider;
            draggable.onDragStart = () =>
            {
                myDivider?.gameObject.SetActive(false);
                bg.raycastTarget  = false;
                cg.blocksRaycasts = false;
                rt.sizeDelta      = new Vector2(collapsedWidth, rt.sizeDelta.y);
            };
            draggable.onDragEnd = () =>
            {
                myDivider?.gameObject.SetActive(true);
                bg.raycastTarget  = true;
                cg.blocksRaycasts = true;
            };
        }
예제 #7
0
 public void Init(CodeList codeList)
 {
     this.codeList = codeList;
 }