//capture updates made to any item in the collections private void line_Updated(MapLine line) { m_Empty = false; Dirty = true; CheckBatch(line.Bounds.Left, line.Bounds.Top); CheckBatch(line.Bounds.Right, line.Bounds.Bottom); CheckBatchEnd(); }
/// <summary>Loads the map data from the given file. Do not specify a base path, but rather change the FilePath property as required.</summary> public void Load(string filename) { if (filename == "") return; m_FileName = filename; //set even if it doesnt exist, so that a (potential) future save can use it string fullfilepath = m_FilePath + filename; Debug.WriteLine("Load Map: " + fullfilepath); //Exit if the file does not exist if (!File.Exists(fullfilepath)) { Debug.WriteLine("FILE NOT FOUND: " + fullfilepath); return; } //LAYOUT //M RRGGBB,x,y,z,x,y,z (so on) 3D Map line. must have at least a pair of vectors. //P RRGGBB,x,y,z,text Label for on map display. //H pattern Regex pattern to match against spawn names. One pattern per line. try { m_suspendDirty = true; FileStream stream = File.OpenRead(fullfilepath); StreamReader reader = new StreamReader(stream); string line = ""; string lineData = ""; string[] parts; int linepos = 0; //for error tracking while ((line = reader.ReadLine()) != null) { lineData = line.Substring(2); switch (line[0]) { case 'M': //map line parts = lineData.Split(','); if (parts.Length == 0) //malformed entry if there are no delimiters continue; if (parts[0].Length != 6) //the first item is the line color continue; if ((parts.Length - 1) % 3 != 0) //the line should always have 3 coords per vector continue; try { //covert the RRGGBB line color to a Color object int red = System.Convert.ToByte(parts[0].Substring(0, 2), 16); int green = System.Convert.ToByte(parts[0].Substring(2, 2), 16); int blue = System.Convert.ToByte(parts[0].Substring(4, 2), 16); MapLine mapline = new MapLine(Color.FromArgb(red, green, blue)); int i = 1; while (i < parts.Length) { mapline.Add( float.Parse(parts[i], CultureInfo.InvariantCulture), float.Parse(parts[i + 1], CultureInfo.InvariantCulture), float.Parse(parts[i + 2], CultureInfo.InvariantCulture) ); i += 3; } mapline.Updated += new MapLineEvent(line_Updated); mapline.Update(); m_lines.Add(mapline); } catch (Exception ex) { //swallow any parsing errors here. this will effectivly reject the line in whole Debug.WriteLine("Error occurred parsing M type on line #" + linepos + ": " + ex.Message); } break; case 'P': //point of interest (map label) parts = lineData.Split(','); if (parts.Length != 5) //there are exactly 5 parts to each label. too bad if someone added a comma in the label text! continue; if (parts[0].Length != 6) //the first item is the line color continue; try { //covert the RRGGBB line color to a Color object int red = System.Convert.ToByte(parts[0].Substring(0, 2), 16); int green = System.Convert.ToByte(parts[0].Substring(2, 2), 16); int blue = System.Convert.ToByte(parts[0].Substring(4, 2), 16); //create the label object MapLabel label = new MapLabel( parts[4], new MapPoint( float.Parse(parts[1], CultureInfo.InvariantCulture), float.Parse(parts[2], CultureInfo.InvariantCulture), float.Parse(parts[3], CultureInfo.InvariantCulture) ), Color.FromArgb(red, green, blue) ); m_labels.Add(label); } catch (Exception ex) { //swallow any parsing errors here. this will effectivly reject the line in whole Debug.WriteLine("Error occurred parsing P type on line #" + linepos + ": " + ex.Message); } break; case 'H': //auto-hunt m_hunts.Add(lineData, true); break; case 'R': //auto-replacement parts = lineData.Split(','); m_replacements.Add(parts[0], parts[1], true); break; } linepos++; } //close the writer reader.Close(); m_Empty = false; //automatically snap the range into view (if enabled) if (m_engine.AutoRangeSnap) m_engine.SnapToRange(); } catch (Exception ex) { Debug.WriteLine("READ ERROR: " + ex.Message); } finally { m_suspendDirty = false; } }
/// <summary>Creates a new vector line with the specified color at the players current location and enables editting mode.</summary> public void EditStartLine(Color linecolor) { if (m_engine.Game.Player == null) return; m_editline = new MapLine(linecolor, m_engine.Game.Player.Location); m_lines.Add(m_editline); m_editline.Updated += new MapLineEvent(line_Updated); m_editline.Update(); m_editcolorlast = linecolor; }
/// <summary>The last vector line created in the current session is removed and edit mode disabled.</summary> public void EditCancelLine() { if (m_editline == null) return; m_editline.Updated -= new MapLineEvent(line_Updated); m_lines.Remove(m_editline); m_editline = null; if (DataChanged != null) DataChanged(); }
/// <summary>Adds a vector line to the current map.</summary> public void AddLine(MapLine line) { m_lines.Add(line); line.Updated += new MapLineEvent(line_Updated); line.Update(); }