private Node GetNodeFromObd(ObjectBankData obd) { var nObd = new Node() { Text = obd.Name, Tag = obd, ContextMenu = ButtonItem_CM_Obd }; // Object Names var nObjs = new Node() { Text = "Objects", Name = "nObjs", ContextMenu = ButtonItem_CM_Objs, Tag = obd }; AddObjsToNode(nObjs, obd); nObd.Nodes.Add(nObjs); // Commands var nCmds = new Node() { Text = "Commands", Name = "nCmds", ContextMenu = ButtonItem_CM_Cmds, Tag = obd }; AddCmdsToNode(nCmds, obd); nObd.Nodes.Add(nCmds); return(nObd); }
protected void ChangeObjectBank(ObjectBankData oldObd, ObjectBankData newObd) { // Remove old commands if (oldObd is object) { foreach (ObjectBankDataCommand obdCmd in oldObd.Commands) { foreach (var cmd in Levelscript.Where(n => General.CompareTwoByteArrays(n.ToArray(), obdCmd.Command)).ToArray()) { cmd.Close(); Levelscript.Remove(cmd); } } } // Add new commands if (newObd is object) { foreach (ObjectBankDataCommand obdCmd in newObd.Commands) { int startIndex = Levelscript.IndexOfFirst(LevelscriptCommandTypes.x1D); if (!(obdCmd.CommandType == 0x1A || obdCmd.CommandType == 0x17)) { startIndex += 1; } var cmd = new LevelscriptCommand(obdCmd.Command); Levelscript.Insert(startIndex, cmd); startIndex += 1; } } }
private void AddCmdsToNode(Node nCmds, ObjectBankData obd) { foreach (ObjectBankDataCommand cmd in obd.Commands) { var nCmd = GetNodeFromCmd(cmd); nCmds.Nodes.Add(nCmd); } }
private void AddObjsToNode(Node nObjs, ObjectBankData obd) { for (int i = 0, loopTo = obd.Objects.Count - 1; i <= loopTo; i++) { string name = obd.Objects[i]; var nObj = GetNodeFromObj(name, i, obd); nObjs.Nodes.Add(nObj); } }
private Node GetNodeFromObj(string name, int index, ObjectBankData obd) { var nObj = new Node() { Text = name, Tag = new object[] { obd, index }, ContextMenu = ButtonItem_CM_Obj }; return(nObj); }
private void AddCmd(Node nCmds) { var bytesStartCount = default(int); bool allowOpenHexEditor = true; // Set start bytes count if (General.GetCurrentHexEditMode() == HexEditModes.BuildInHexEditor) { var valueInputDialog = new ValueInputDialog(); valueInputDialog.InfoLabel.Text = "Count of Bytes"; valueInputDialog.ValueTextBox.Text = Conversions.ToString(8); if (valueInputDialog.ShowDialog() == DialogResult.OK) { bytesStartCount = TextValueConverter.ValueFromText(valueInputDialog.ValueTextBox.Text); } allowOpenHexEditor = bytesStartCount > 0; } else { bytesStartCount = 0; } // Create Buffer var cmdBuf = new byte[bytesStartCount]; // Create new if (allowOpenHexEditor) { General.OpenHexEditor(ref cmdBuf); } if (cmdBuf?.Any() == true) { ObjectBankData obd = (ObjectBankData)nCmds.Tag; var cmd = new ObjectBankDataCommand(cmdBuf); var nCmd = GetNodeFromCmd(cmd); // Add cmd obd.Commands.Add(cmd); // Add node BeginTreeUpdate(); nCmds.Nodes.Add(nCmd); nCmds.Expand(); EndTreeUpdate(); // Raise event ChangedObjectBankDataCommand?.Invoke(obd); } }
private void RemoveCmd(Node nCmd) { var nCmds = nCmd.Parent; ObjectBankData obd = (ObjectBankData)nCmds.Tag; ObjectBankDataCommand cmd = (ObjectBankDataCommand)nCmd.Tag; // Remove Cmd obd.Commands.Remove(cmd); // Remove Node BeginTreeUpdate(); nCmds.Nodes.Remove(nCmd); EndTreeUpdate(); // Raise event ChangedObjectBankDataCommand?.Invoke(obd); }
private void RemoveObd(Node nObd) { var nObdList = nObd.Parent; KeyValuePair <byte, ObjectBankDataList> kvp = (KeyValuePair <byte, ObjectBankDataList>)nObdList.Tag; ObjectBankData obd = (ObjectBankData)nObd.Tag; // Remove list kvp.Value.Remove(obd); // Remove node BeginTreeUpdate(); nObdList.Nodes.Remove(nObd); EndTreeUpdate(); // Raise event RemovedObjectBankData?.Invoke(obd); }
private void RemoveObj(Node nObj) { var nObjs = nObj.Parent; object[] arr = nObj.Tag as object[]; ObjectBankData obd = (ObjectBankData)arr[0]; var list = obd.Objects; int index = Conversions.ToInteger(arr[1]); // Remove from list list.RemoveAt(index); // Re-add object nodes BeginTreeUpdate(); nObjs.Nodes.Clear(); AddObjsToNode(nObjs, obd); EndTreeUpdate(); }
private void EditCmd(Node nCmd) { var nCmds = nCmd.Parent; ObjectBankData obd = (ObjectBankData)nCmds.Tag; ObjectBankDataCommand cmd = (ObjectBankDataCommand)nCmd.Tag; // Edit cmd var argbuffer = cmd.Command; General.OpenHexEditor(ref argbuffer); cmd.Command = argbuffer; // Update ObdTree nCmd.Text = $"<font face=\"Consolas\">{SM64Lib.General.CommandByteArrayToString(cmd.Command)}</font>"; ObdTree.Refresh(); // Raise event ChangedObjectBankDataCommand?.Invoke(obd); }
private void ObdTree_AfterCellEdit(object sender, CellEditEventArgs e) { var tag = e.Cell.Tag; if (tag is object[]) { object[] arr = (object[])tag; if (arr.Length == 2 && arr[0] is ObjectBankData && arr[1] is int) { ObjectBankData obd = (ObjectBankData)arr[0]; int index = Conversions.ToInteger(arr[1]); obd.Objects[index] = e.NewText.Trim(); } } else if (tag is ObjectBankData) { ObjectBankData obd = (ObjectBankData)tag; obd.Name = e.NewText.Trim(); } }
private void AddObj(Node nObjs) { var input = new ValueInputDialog(); input.ValueTextBox.Text = "New Object"; if (input.ShowDialog() == DialogResult.OK) { ObjectBankData obd = (ObjectBankData)nObjs.Tag; string name = input.ValueTextBox.Text.Trim(); int index = obd.Objects.Count; var nObj = GetNodeFromObj(name, index, obd); // Add object obd.Objects.Add(name); // Add node BeginTreeUpdate(); nObjs.Nodes.Add(nObj); nObjs.Expand(); EndTreeUpdate(); } }
private void AddObd(Node nObdList) { var input = new ValueInputDialog(); input.ValueTextBox.Text = "New Object Bank Data"; if (input.ShowDialog() == DialogResult.OK) { ObjectBankDataList obdList = ((KeyValuePair <byte, ObjectBankDataList>)nObdList.Tag).Value; string name = input.ValueTextBox.Text.Trim(); var obd = new ObjectBankData(name); var nObd = GetNodeFromObd(obd); // Add object obdList.Add(obd); // Add node BeginTreeUpdate(); nObdList.Nodes.Add(nObd); nObdList.Expand(); EndTreeUpdate(); } }
public void ChangeObjectBankData(byte bankID, ObjectBankData newObd) { ChangeObjectBank(GetObjectBankData(bankID), newObd); MyObjectBanks[bankID] = newObd; }