public void Init(Program program, CodeList codeList, Func <Program, int, string, bool> handleRename) { this.program = program; this.codeList = codeList; rn.onRename = (string name) => handleRename(program, transform.GetSiblingIndex(), name); inputField.text = program.name; }
public void Init(Argument initArg, CodeList codeList) { arg = initArg; this.codeList = codeList; // 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, gameObject); }; draggable.onDragTrash = (Draggable.Slot slot) => { slotField?.ReleaseArg(); Destroy(gameObject); }; }
// 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]; // 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); } } }
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); }; }
public void Init(ArgumentSpec argSpec, Argument arg, CodeList codeList) { // Configure dropdown options TMP_Dropdown 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); } } dropdown.value = arg.val; // Register value change handler Argument.Type argType = argSpec.regOnly ? Argument.Type.REGISTER : Argument.Type.IMMEDIATE; dropdown.onValueChanged.AddListener((int val) => { arg.val = val; codeList.Program.BroadcastArgumentChange(); }); // 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); }
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; }; }
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); codeList.Program.BroadcastArgumentChange(); }); if (arg.type == Argument.Type.IMMEDIATE) { inputField.text = arg.val.ToString(); Resize(); } else { InsertArg(arg); inputField.text = "0"; } inputField.onValueChanged.AddListener(Resize); }
public void Init(CodeList codeList) { this.codeList = codeList; }