private void btnSave_Click(object sender, EventArgs e) { if (Edit) { CavebotAction cbAction = Cavebot.Script.FindLast(x => x.Position.X == position.X && x.Position.Y == position.Y && x.Position.Z == position.Z && x.Action == actionTypes); cbAction.Name = txtName.Text; cbAction.Position = new PXG.Position(int.Parse(txtX.Text), int.Parse(txtY.Text), int.Parse(txtZ.Text)); cbAction.Action = (ActionTypes)Enum.Parse(typeof(ActionTypes), cmbActionTypes.SelectedItem.ToString().Replace(" ", "")); } else { int id = Cavebot.Script.Count; if (ID != -1) { id = ID + 1; foreach (CavebotAction action in Cavebot.Script) { if (action.ID >= id) { action.ID += 1; } } } Console.WriteLine("id added: " + id); CavebotAction cbAction = new CavebotAction(id, new PXG.Position(int.Parse(txtX.Text), int.Parse(txtY.Text), int.Parse(txtZ.Text)), (ActionTypes)Enum.Parse(typeof(ActionTypes), cmbActionTypes.SelectedItem.ToString().Replace(" ", "")), name: txtName.Text); Cavebot.Script.Add(cbAction); } this.Close(); }
private void btnAddWaypointFast_Click(object sender, EventArgs e) { try { CavebotAction cavebotAction = new CavebotAction(Cavebot.Script.Count, new PXG.Position(Character.X, Character.Y, Character.Z), ActionTypes.Walk); Cavebot.Script.Add(cavebotAction); AddTreeNode(cavebotAction); } catch (Exception ex) { MessageBox.Show("Error: btnAddWaypoint: " + ex.Message); } }
private void btnOpenScript_Click(object sender, EventArgs e) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "JSON Files (*.json)|*.json"; ofd.FilterIndex = 0; ofd.DefaultExt = "json"; if (ofd.ShowDialog() == DialogResult.OK) { if (!String.Equals(Path.GetExtension(ofd.FileName), ".json", StringComparison.OrdinalIgnoreCase)) { MessageBox.Show("The type of the selected file is not supported by this application. You must select an JSON file.", "Invalid File Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string fullPath = ofd.FileName; Console.WriteLine("Path: " + fullPath); string json = File.ReadAllText(fullPath); dynamic script = JArray.Parse(json)[0]; JArray waypoints = script.Waypoints; JavaScriptSerializer jss = new JavaScriptSerializer(); Cavebot.Script.Clear(); for (int i = 0; i < waypoints.Count; i++) { var waypoint = jss.Deserialize <dynamic>(waypoints[i].ToString()); string name = ""; try { name = waypoint["name"]; } catch (Exception) { name = ""; } string[] position = waypoint["position"].Split(','); ActionTypes action = Enum.Parse(typeof(ActionTypes), waypoint["action"]); CavebotAction cavebotAction = new CavebotAction(Cavebot.Script.Count, new PXG.Position(int.Parse(position[0]), int.Parse(position[1]), int.Parse(position[2])), action, name); Cavebot.Script.Add(cavebotAction); } Cavebot.Index = 0; UpdateCavebotTree(); } } } catch (Exception ex) { MessageBox.Show("Error: btnOpenScript: " + ex.Message); } }
private void AddTreeNode(CavebotAction cbAction) { try { string name = ""; if (cbAction.Name != "") { name = "'" + cbAction.Name + "' "; } string position = "<" + cbAction.Position.X + "," + cbAction.Position.Y + "," + cbAction.Position.Z + ">"; TreeNode node = new TreeNode(cbAction.ID + ": " + name + position + "; " + cbAction.Action); CavebotTree.Nodes.Add(node); } catch (Exception ex) { MessageBox.Show("Error: AddTreeNode: " + ex.Message); } }
private void btnDeleteWaypoint_Click(object sender, EventArgs e) { try { if (CavebotTree.SelectedNode != null) { string[] values = CavebotTree.SelectedNode.ToString().Replace("TreeNode:", "").Split(';'); int ID = int.Parse(values[0].Split(':')[0].Replace(" ", "").Replace(">", "")); string[] pos = values[0].Split('<')[1].Replace(">", "").Split(','); PXG.Position position = new PXG.Position(int.Parse(pos[0]), int.Parse(pos[1]), int.Parse(pos[2])); ActionTypes actionTypes = (ActionTypes)Enum.Parse(typeof(ActionTypes), values[1]); CavebotAction cbAction = Cavebot.Script.FindLast(x => x.ID == ID && x.Position.X == int.Parse(pos[0]) && x.Position.Y == int.Parse(pos[1]) && x.Position.Z == int.Parse(pos[2]) && x.Action == actionTypes); Cavebot.Script.Remove(cbAction); UpdateCavebotTree(); } } catch (Exception ex) { MessageBox.Show("Error: btnDeleteWaypoint: " + ex.Message); } }