123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937 |
- // At some point add in the option to use either MoveToLocation()
- // or MovementLoopAddLocation() for looping or for one time path
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows.Forms;
- using System.Text;
- namespace Movement_Loop_Generator_2._0
- {
- public partial class Form1 : Form
- {
- float x;
- float y;
- float z;
- int rowNumber;
- List<DataStruct> dataLoc = new List<DataStruct>();
- Dictionary<string, string> NPCList = new Dictionary<string, string>();
- private OpenFileDialog file_dialog = new OpenFileDialog();
- FileStream fileStream;
- private long LastLengthLocation = -1;
- private String LastErrMsg = "";
- private Exception LastExceptionMsg = null;
- private bool suppress = false;
- public Form1()
- {
- InitializeComponent();
- userToolStripMenuItem.Text = Properties.Settings.Default.Author;
- //Thread.CurrentThread.CurrentCulture = new CultureInfo("eu-fr");
- }
- /*********************************************************************************************************************************
- * Drag and Drop handler
- *********************************************************************************************************************************/
- private void Form1_DragEnter(object sender, DragEventArgs e)
- {
- if (e.Data.GetDataPresent(DataFormats.FileDrop))
- e.Effect = DragDropEffects.All;
- else
- e.Effect = DragDropEffects.None;
- }
- private void Form1_DragDrop(object sender, DragEventArgs e)
- {
- string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, true);
- string filename = Path.GetFullPath(FileList[0]);
- ResetListView(true);
- ResetTextBoxes();
- NPCList.Clear();
- listBox_NPCs.Items.Clear();
- dataLoc.Clear();
- richTextBox_OutputView.Clear();
- this.textBox_LogFile.Text = filename;
-
- //richTextBox_OutputView.Text = "Clearing listview, textboxes, and location data.\nGetting spawn and author information.\nGetting spawn location data.\n" +
- //"Loading list with spawn location data.\n";
- if (checkBox_ReversePath.Checked == true)
- {
- checkBox_ReversePath.Checked = false;
- }
- ParseNPC();
- ListviewLoad();
- }
- /*********************************************************************************************************************************
- * Load DataStruct List
- *********************************************************************************************************************************/
- private void ParseData()
- {
- if (listBox_NPCs.SelectedIndex < 0)
- {
- return;
- }
- checkBox_ReversePath.Visible = true;
- bool found = false;
- int npcname_count = 0;
- string [] split = NPCList[listBox_NPCs.SelectedItem.ToString()].Split(' ');
- string npcname = split[0];
- if (split.Length > 1)
- {
- Int32.TryParse(split[1], out npcname_count);
- }
-
- string line;
- string locSpeed = "'loc_speed ";
- string locDelay = "'loc_delay ";
- string locStart = "'loc_start ";
- string locEnd = "'";
- string locStop = "'loc_stop'";
- int namecount = 0;
- int count = 0;
- int setSpeed = 0;
- int index;
- int setDelay = 0;
- int delindex;
- dataLoc = new List<DataStruct>();
- ResetListView(true);
- // Parse button throws an exception Unhandled if the logfile text box is empty
- LastLengthLocation = -1;
- try
- {
- while (OpenReadLine(out line))
- {
- if (line.Contains(locSpeed))
- {
- index = line.IndexOf("Unknown command: 'loc_speed") + 28;
- setSpeed = Convert.ToInt32(line.Substring(index, (line.Length - index) - 1));
- }
- if (line.Contains(locDelay))
- {
- delindex = line.IndexOf("Unknown command: 'loc_delay") + 28;
- setDelay = Convert.ToInt32(line.Substring(delindex, (line.Length - delindex) - 1));
- }
- // Test to see if I can advanced to the next name and get the loc from the second collect
- if (line.Contains(locStart + npcname + locEnd) && npcname_count < 1)
- {
- found = true;
- count++;
- }
- if (line.Contains(locStart + npcname + locEnd) && npcname_count >= 1)
- {
- if (npcname_count == namecount)
- {
- found = true;
- count++;
- namecount = 0;
- }
- else
- {
- found = false;
- namecount++;
- }
- }
- if (line.Contains(locStop))
- {
- if (count >= 1)
- {
- return;
- }
- else
- {
- found = false;
- }
- }
- if (found)
- {
- if (line.Contains("Your location is"))
- {
- Match matchPosition = Regex.Match(line, @"Your location is.*Your orientation is", RegexOptions.IgnoreCase);
- string[] location = matchPosition.Value.Replace(@"Your location is ", "").Replace(@". Your orientation is", "").Split(',');
- if (location.Count() == 3)
- {
- x = float.Parse(location[0].Trim(), CultureInfo.InvariantCulture);
- y = float.Parse(location[1].Trim(), CultureInfo.InvariantCulture);
- z = float.Parse(location[2].Trim(), CultureInfo.InvariantCulture);
- DataStruct locData;
- if (npcname_count >= 1)
- {
- locData.Name = npcname + "_" + npcname_count.ToString();
- }
- else
- {
- locData.Name = npcname;
- }
-
- locData.Author = Properties.Settings.Default.Author;
- locData.XLoc = x;
- locData.YLoc = y;
- locData.ZLoc = z;
- if (setSpeed > 0)
- {
- locData.Speed = setSpeed;
- setSpeed = 0;
- }
- else
- {
- locData.Speed = 2;
- }
- if (setDelay > 0)
- {
- locData.Delay = setDelay;
- setDelay = 0;
- }
- else
- {
- locData.Delay = 0;
- }
- locData.Function = textBox_Function.Text;
- dataLoc.Add(locData);
- }
- }
- }
- }
- }
- catch
- {
- MessageBox.Show("Cannot read log file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- private void ParseNPC()
- {
- string line;
- string locStart = "'loc_start ";
- int index = 0;
- int multipleNPC = 0;
- LastLengthLocation = -1;
- while (OpenReadLine(out line))
- {
- if (line.Contains(locStart))
- {
- index = line.IndexOf(locStart) + 11;
- string npc_name = line.Substring(index, (line.Length - index) - 1);
- if (NPCList.ContainsKey(npc_name))
- {
- multipleNPC++;
- string newNPCName = npc_name + " " + Convert.ToString(multipleNPC);
-
- NPCList.Add(newNPCName, newNPCName);
- listBox_NPCs.Items.Add(newNPCName);
- }
- else
- {
- NPCList.Add(npc_name, npc_name);
- listBox_NPCs.Items.Add(npc_name);
- }
-
- }
- }
- }
- /*********************************************************************************************************************************
- * List View & Rich TextBox Load
- *********************************************************************************************************************************/
- private void ListviewLoad()
- {
- foreach(DataStruct locData in dataLoc)
- {
- ListViewItem loc = new ListViewItem();
- loc.SubItems.Add(locData.XLoc.ToString(CultureInfo.InvariantCulture));
- loc.SubItems.Add(locData.YLoc.ToString(CultureInfo.InvariantCulture));
- loc.SubItems.Add(locData.ZLoc.ToString(CultureInfo.InvariantCulture));
- loc.SubItems.Add(locData.Speed.ToString(CultureInfo.InvariantCulture));
- loc.SubItems.Add(locData.Delay.ToString(CultureInfo.InvariantCulture));
- loc.SubItems.Add(locData.Function);
- listView_Loaded.Items.Add(loc);
- }
- }
- private void RTBLoad()
- {
- foreach (DataStruct locData in dataLoc)
- {
- string Output;
- string name = locData.Name;
- string author = locData.Author;
- string x = locData.XLoc.ToString();
- string y = locData.YLoc.ToString();
- string z = locData.ZLoc.ToString();
- string speed = locData.Speed.ToString();
- string delay = locData.Delay.ToString();
- string function = locData.Function;
- if (string.IsNullOrEmpty(function))
- {
- Output = "MovementLoopAddLocation(NPC, " + x + ", " + y + ", " + z + ", " + speed + ", " + delay + ")" + System.Environment.NewLine;
- this.richTextBox_OutputView.Text += Output;
- }
- else
- {
- Output = "MovementLoopAddLocation(NPC, " + x + ", " + y + ", " + z + ", " + speed + ", " + delay + ", " + function + ")" + System.Environment.NewLine;
- this.richTextBox_OutputView.Text += Output;
- }
-
- }
- }
- /*********************************************************************************************************************************
- * ListView Select Loads TextBoxes
- *********************************************************************************************************************************/
- private void listView_Loaded_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
- {
- ResetListView(false);
- return;
- }
- ListViewItem loc = listView_Loaded.Items[listView_Loaded.SelectedIndices[0]];
- textBox_XLOC.Text = loc.SubItems[1].Text;
- textBox_YLOC.Text = loc.SubItems[2].Text;
- textBox_ZLOC.Text = loc.SubItems[3].Text;
- textBox_Speed.Text = loc.SubItems[4].Text;
- textBox_Delay.Text = loc.SubItems[5].Text;
- textBox_Function.Text = loc.SubItems[6].Text;
- rowNumber = listView_Loaded.FocusedItem.Index;
- richTextBox_OutputView.Clear();
- richTextBox_OutputView.Text = "Data Loaded";
- button_InsertAbove.Enabled = true;
- button_InsertBelow.Enabled = true;
- button_Update.Enabled = true;
- button_Remove.Enabled = true;
- button_Reset.Enabled = true;
- }
- /*********************************************************************************************************************************
- * Reset ListView & TextBoxes
- *********************************************************************************************************************************/
- private void ResetListView(bool include_listview)
- {
- if (include_listview)
- listView_Loaded.Items.Clear();
- }
- private void ResetTextBoxes()
- {
- textBox_XLOC.Clear();
- textBox_YLOC.Clear();
- textBox_ZLOC.Clear();
- textBox_Speed.Clear();
- textBox_Delay.Clear();
- textBox_Function.Clear();
- }
- /*********************************************************************************************************************************
- * Buttons
- *********************************************************************************************************************************/
- private void btn_Browse_Click(object sender, EventArgs e)
- {
- file_dialog.Title = "Load Log File";
- file_dialog.Filter = "Text|*.txt|All|*.*";
- if (this.file_dialog.ShowDialog() == DialogResult.OK)
- {
- CloseFile();
- this.textBox_LogFile.Text = this.file_dialog.FileName;
- ResetListView(true);
- ResetTextBoxes();
- NPCList.Clear();
- listBox_NPCs.Items.Clear();
- dataLoc.Clear();
- //richTextBox_OutputView.Text = "Clearing listview, textboxes, and location data.\nGetting spawn and author information.\nGetting spawn location data.\n" +
- //"Loading list with spawn location data.\n";
- rowNumber = 0; // resetting since setting reversepath to false calls this as part of the [] iterator
- if (checkBox_ReversePath.Checked == true)
- {
- checkBox_ReversePath.Checked = false;
- }
- ParseNPC();
- richTextBox_OutputView.Clear();
- int total_npcs = NPCList.Count;
- richTextBox_OutputView.Text = total_npcs + " NPC's Found and listed on the left\n\nDouble Click an NPC's name to load its waypoints.";
- ListviewLoad();
- }
- }
- private void textBox_LogFile_DoubleClick(object sender, EventArgs e)
- {
- btn_Browse_Click(sender, e);
- }
- private void button_Update_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty || textBox_Speed.Text == String.Empty)
- {
- listView_Loaded_SelectedIndexChanged(sender, e);
- }
- else
- {
- DataStruct locData = dataLoc[rowNumber];
- locData.XLoc = float.Parse(textBox_XLOC.Text);
- locData.YLoc = float.Parse(textBox_YLOC.Text);
- locData.ZLoc = float.Parse(textBox_ZLOC.Text);
- locData.Speed = Convert.ToInt32(textBox_Speed.Text);
- locData.Delay = Convert.ToInt32(textBox_Delay.Text);
- locData.Function = textBox_Function.Text;
- dataLoc.Insert(rowNumber, locData);
- dataLoc.RemoveAt(rowNumber + 1);
- ResetTextBoxes();
- ResetListView(true);
- ListviewLoad();
- richTextBox_OutputView.Text = "Updated Entry";
- }
-
- }
- private void button_InsertAbove_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
- {
- MessageBox.Show("You must select something from the list first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty)
- {
- MessageBox.Show("You are missing either X, Y, or Z coordinates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (string.IsNullOrEmpty(textBox_Speed.Text))
- {
- textBox_Speed.Text = "2";
- }
- if (string.IsNullOrEmpty(textBox_Delay.Text))
- {
- textBox_Delay.Text = "0";
- }
- DataStruct locData = dataLoc[rowNumber];
- locData.XLoc = float.Parse(textBox_XLOC.Text);
- locData.YLoc = float.Parse(textBox_YLOC.Text);
- locData.ZLoc = float.Parse(textBox_ZLOC.Text);
- locData.Speed = Convert.ToInt32(textBox_Speed.Text);
- locData.Delay = Convert.ToInt32(textBox_Delay.Text);
- locData.Function = textBox_Function.Text;
- dataLoc.Insert(rowNumber, locData);
- ResetTextBoxes();
- ResetListView(true);
- ListviewLoad();
- richTextBox_OutputView.Text = "Inserted New Entry";
- }
- private void button_InsertBelow_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
- {
- MessageBox.Show("You must select something from the list first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty)
- {
- MessageBox.Show("You are missing either X, Y, or Z coordinates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (string.IsNullOrEmpty(textBox_Speed.Text))
- {
- textBox_Speed.Text = "2";
- }
- if (string.IsNullOrEmpty(textBox_Delay.Text))
- {
- textBox_Delay.Text = "0";
- }
- DataStruct locData = dataLoc[rowNumber];
- locData.XLoc = float.Parse(textBox_XLOC.Text);
- locData.YLoc = float.Parse(textBox_YLOC.Text);
- locData.ZLoc = float.Parse(textBox_ZLOC.Text);
- locData.Speed = Convert.ToInt32(textBox_Speed.Text);
- locData.Delay = Convert.ToInt32(textBox_Delay.Text);
- locData.Function = textBox_Function.Text;
- dataLoc.Insert(rowNumber + 1, locData);
- ResetTextBoxes();
- ResetListView(true);
- ListviewLoad();
- richTextBox_OutputView.Text = "Inserted New Entry";
- }
- private void button_Remove_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- DataStruct locData = dataLoc[rowNumber];
- dataLoc.RemoveAt(rowNumber);
- ResetTextBoxes();
- ResetListView(true);
- ListviewLoad();
- richTextBox_OutputView.Text = "Removed Selected Entry";
- }
- private void checkBox_ReversePath_CheckedChanged(object sender, EventArgs e)
- {
- // might be a reload so don't crash trying to pull beyond the array!
- if (dataLoc.Count() <= rowNumber)
- return;
- int rowCount = dataLoc.Count;
- // Throws an error here if the checkbox has been unchecked and checked a second time
- DataStruct locData = dataLoc[rowNumber];
- bool firstRun = true;
- // Reverse the path
- if (checkBox_ReversePath.Checked)
- {
- rowNumber = rowCount - 1;
- while (rowCount > 0)
- {
- if (firstRun == true)
- {
- rowCount = (rowCount - 2);
- firstRun = false;
- }
- else
- {
- rowCount--;
- }
- locData = dataLoc[rowCount];
- float tmpXLoc = locData.XLoc;
- float tmpYLoc = locData.YLoc;
- float tmpZLoc = locData.ZLoc;
- int tmpSpeed = locData.Speed;
- int tmpDelay = locData.Delay;
- string tmpFunction = locData.Function;
- locData.XLoc = tmpXLoc;
- locData.YLoc = tmpYLoc;
- locData.ZLoc = tmpZLoc;
- locData.Speed = tmpSpeed;
- locData.Delay = tmpDelay;
- locData.Function = tmpFunction;
- dataLoc.Add(locData);
- }
- ResetListView(true);
- ResetTextBoxes();
- richTextBox_OutputView.Clear();
- richTextBox_OutputView.Text = "The waypoints have been reverse, added to the current list of waypoints, and the spawn path will now loop";
- ListviewLoad();
- }
- else
- {
- // Revert Changes if checkbox is unchecked
- int revertrowcount = rowCount / 2;
- int count = 0;
- while (count < revertrowcount)
- {
- count++;
- dataLoc.RemoveAt(rowNumber);
- rowNumber--;
- }
- ResetListView(true);
- ResetTextBoxes();
- richTextBox_OutputView.Clear();
- ListviewLoad();
- }
- }
- private void button_Save_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- DateTime dateTime = DateTime.Now;
- List<string> checkfunctions = new List<string>();
- DataStruct locData = dataLoc[rowNumber];
- string spawnName = locData.Name + ".lua";
- StreamWriter streamWriter = new StreamWriter(spawnName);
- string script = "--[[\n\tScript Name\t\t:\t" + spawnName + "\n\tScript Purpose\t:\tWaypoint Path for " + spawnName + "\n\tScript Author\t:\t" +
- locData.Author + "\n\tScript Date\t\t:\t" + dateTime.ToString("MM/dd/yyyy hh:mm:ss tt") + "\n\tScript Notes\t:\tLocations collected from Live\n--]]\n\n" +
- "function spawn(NPC)\n\twaypoints(NPC)\nend\n\nfunction hailed(NPC, Spawn)\n\tFaceTarget(NPC, Spawn)\nend\n\nfunction respawn(NPC)\n\tspawn(NPC)\nend\n\n" +
- "function waypoints(NPC)";
- streamWriter.WriteLine(script);
- for (int i = 0; i < dataLoc.Count; i++)
- {
- //rowNumber = i;
- locData = dataLoc[i];
- if (!String.IsNullOrEmpty(locData.Function.ToString()))
- {
- string output = " MovementLoopAddLocation(NPC, " + locData.XLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.YLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.ZLoc.ToString(CultureInfo.InvariantCulture) + ", " +
- locData.Speed + ", " + locData.Delay + ", " +
- "\"" + locData.Function.ToString() + "\")";
- streamWriter.WriteLine(output);
- }
- else
- {
- string output = " MovementLoopAddLocation(NPC, " + locData.XLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.YLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.ZLoc.ToString(CultureInfo.InvariantCulture) + ", " +
- locData.Speed + ", " + locData.Delay + ")";
- streamWriter.WriteLine(output);
- }
-
-
- }
-
- streamWriter.WriteLine("end\n\n");
- for (int i = 0; i < dataLoc.Count; i++)
- {
-
- //need to check for duplicates of the movement function
- locData = dataLoc[i];
- if (!String.IsNullOrEmpty(locData.Function.ToString()))
- {
- string movementfunctions = "function " + locData.Function.ToString() + "(NPC)\n\t Say(NPC, " + "\"" + "This is the " + locData.Function.ToString() + " function\"" + ")\nend";
- streamWriter.WriteLine(movementfunctions + "\n\n");
- }
- }
- streamWriter.Close();
- richTextBox_OutputView.Text = "Saved to " + spawnName + "";
- }
- private void button_Reset_Click(object sender, EventArgs e)
- {
- richTextBox_OutputView.Clear();
- ResetTextBoxes();
- DataStruct locData = dataLoc[rowNumber];
- richTextBox_OutputView.Text = "Cleared Textboxes";
- }
- private void button_ParseDetalis_Click(object sender, EventArgs e)
- {
- ParseData();
- ListviewLoad();
- }
- /*********************************************************************************************************************************
- * MENU ITEMS
- *********************************************************************************************************************************/
- private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void collectWaypointsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Begin by using this line" + System.Environment.NewLine +
- System.Environment.NewLine +
- "/loc_start <name of spawn>" + System.Environment.NewLine +
- "Example: /loc_start a trained wolf" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Use /loc at each point the spawn stops/turns to log location" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Use /loc_speed to change the movement between waypoints" + System.Environment.NewLine +
- "Example: /loc_speed 4"+ System.Environment.NewLine +
- "to make spawn run from point to point" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Use /loc_delay to pause at a waypoint. /loc_delay 3" + System.Environment.NewLine +
- "Example /loc_delay 3" + System.Environment.NewLine +
- "to make spawn pause for 3 seconds" + System.Environment.NewLine +
- System.Environment.NewLine +
- "End the session by using this line" + System.Environment.NewLine +
- "/loc_stop", "Collecting location Waypoints", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void editinglogsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Choose a line of waypoints in the list to work on" + System.Environment.NewLine +
- "Edit the values in the boxes on the bottom" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Use the Update button to update the line" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Add a new waypoint to the list by using the Insert Above or Insert Below buttons" + System.Environment.NewLine +
- "Add a function here if the spawns does something at a stop/turn" + System.Environment.NewLine +
- "Otherwise leave blank"+ System.Environment.NewLine +
- "Note: If a function is added it auto creates a new function in the script" + System.Environment.NewLine +
- "Once script is saved you can edit the function in an editor" + System.Environment.NewLine +
- System.Environment.NewLine +
- "Once you are finished click on the Parse button to save or edit", "Editing Locations", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- private void loadingLogsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- MessageBox.Show("Use the browse button in the generator to locate your log." + System.Environment.NewLine +
- "these are located in your EverQuest II->logs folder inside the folder of your live client." + System.Environment.NewLine +
- System.Environment.NewLine +
- "Double click your spawn from the list on the left" + System.Environment.NewLine +
- "You can use the Parse button as well" + System.Environment.NewLine +
- "Example a trained wolf" + System.Environment.NewLine +
- "Note: Change the default author under file menu" + System.Environment.NewLine +
- "File->Settings->Author and edit in the textbox" + System.Environment.NewLine +
- "Hit enter to save.", "Loading Logs", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- // This loads the saved settings for Author into the toolStripTextBox
- private void authorToolStripMenuItem_MouseEnter(object sender, EventArgs e)
- {
- toolStripTextBox_Author.Text = Properties.Settings.Default.Author;
- }
- //Code for toolStripTextBoxAuthor Key Event set in the toolStripTextBoxAuthor Properties
- private void toolStripTextBoxAuthor_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
- {
- Properties.Settings.Default.Author = toolStripTextBox_Author.Text;
- Properties.Settings.Default.Save();
- userToolStripMenuItem.Text = Properties.Settings.Default.Author;
- e.Handled = true;
- e.SuppressKeyPress = true;
- fileToolStripMenuItem.HideDropDown(); // Hides the menu after enter key is pressed
- }
- }
- private void listBox_NPCs_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- if (checkBox_ReversePath.Checked == true)
- {
- checkBox_ReversePath.Checked = false;
- }
- ParseData();
- ListviewLoad();
- int total_wapoints = dataLoc.Count;
- richTextBox_OutputView.Text = richTextBox_OutputView.Text + "\n\n\n" + total_wapoints + " Waypoints were loaded\n\nClick a waypoint to edit it in the boxes below";
- }
- private bool OpenFile(out FileStream fileStream)
- {
- fileStream = null;
- try
- {
- fileStream = new FileStream(this.textBox_LogFile.Text, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite, 8, FileOptions.SequentialScan);
- return true;
- }
- catch (Exception ex)
- {
- LastErrMsg = ex.Message;
- LastExceptionMsg = ex;
- DisplayError();
- }
- return false;
- }
- public bool ReadLine(out String line)
- {
- bool val = false;
- line = "";
- FileStream fs = null;
- if (fileStream == null)
- {
- if (OpenFile(out fs))
- {
- String lineRead = "";
- val = ReadLineDown(-1, out lineRead);
- line = lineRead;
- CloseFile();
- }
- }
- else
- {
- String lineRead = "";
- val = ReadLineDown(-1, out lineRead);
- line = lineRead;
- CloseFile();
- }
- return val;
- }
- public bool OpenReadLine(out String line)
- {
- bool val = false;
- line = "";
- FileStream fs = null;
- if (fileStream == null)
- {
- if (OpenFile(out fs))
- {
- String lineRead = "";
- fileStream = fs;
- val = ReadLineDown(-1, out lineRead);
- line = lineRead;
- }
- }
- else
- {
- String lineRead = "";
- val = ReadLineDown(-1, out lineRead);
- line = lineRead;
- }
- return val;
- }
- private bool ReadLineDown(int locToStart, out String line)
- {
- line = "";
- try
- {
- byte[] dataToRead = new byte[256];
- bool firstRun = false;
- if (LastLengthLocation == -1)
- {
- firstRun = true;
- LastLengthLocation = 0;
- }
- if (fileStream.Position < LastLengthLocation)
- {
- fileStream.Position = LastLengthLocation;
- }
- else
- {
- fileStream.Position = LastLengthLocation;
- }
- String strToConstruct = "";
- while (true)
- {
- int dataRead = fileStream.Read(dataToRead, 0, dataToRead.Length);
- if (dataRead < 1)
- return false;
- String out_ = Encoding.UTF8.GetString(dataToRead, 0, dataRead);
- int firstIdx = out_.IndexOf(Environment.NewLine);
- if (firstIdx < 0)
- {
- strToConstruct += out_;
- LastLengthLocation += out_.Length;
- continue;
- }
- else
- {
- strToConstruct += out_.Substring(0, firstIdx);
- LastLengthLocation += (firstIdx + Environment.NewLine.Length);
- break;
- }
- }
- line = strToConstruct;
- return true;
- }
- catch (Exception ex)
- {
- LastErrMsg = ex.Message;
- LastExceptionMsg = ex;
- DisplayError();
- }
- return false;
- }
- public bool CloseFile()
- {
- try
- {
- if(fileStream != null)
- fileStream.Close();
- fileStream = null;
- return true;
- }
- catch (Exception ex)
- {
- LastErrMsg = ex.Message;
- LastExceptionMsg = ex;
- DisplayError();
- }
- return false;
- }
- public void DisplayError()
- {
- if (suppress)
- return;
- if (MessageBox.Show("Error Message: " + LastErrMsg + "\n\nWould you like to STOP being shown errors? Selecting YES means no errors will be shown until tool restart", "ERROR!", MessageBoxButtons.YesNo) ==
- DialogResult.Yes)
- suppress = true;
- }
- /*********************************************************************************************************************************
- * Notes
- *********************************************************************************************************************************/
- }
- }
|