//mxd internal virtual void SetViewSettings(ScriptDocumentSettings settings) { if (settings.TabType != tabtype) { throw new Exception("TabType mismatch!"); } // Text must be exactly the same long hash = MurmurHash2.Hash(Text); bool applyfolding = General.Settings.ScriptShowFolding && (editor.Scintilla.Lexer == Lexer.Cpp || (int)editor.Scintilla.Lexer == 35); // 35 - custom CPP case insensitive style lexer if (hash == settings.Hash) { // Restore fold levels if (applyfolding) { ApplyFolding(settings.FoldLevels ?? GetFoldLevels()); } // Restore scroll editor.Scintilla.FirstVisibleLine = settings.FirstVisibleLine; // Restore caret position editor.Scintilla.SetEmptySelection(settings.CaretPosition); } // Do what Visual Studio does: fold all #regions else if (applyfolding) { ApplyFolding(GetFoldLevels()); } }
//mxd internal void SetViewSettings(ScriptDocumentSettings settings) { // Text must be exactly the same long hash = MurmurHash2.Hash(Text); bool applyfolding = General.Settings.ScriptShowFolding && (Scintilla.Lexer == Lexer.Cpp || Scintilla.Lexer == Lexer.CppNoCase); if (hash == settings.Hash) { // Restore fold levels if (applyfolding) { ApplyFolding(settings.FoldLevels ?? GetFoldLevels()); } // Restore scroll Scintilla.FirstVisibleLine = settings.FirstVisibleLine; // Restore caret position Scintilla.SetEmptySelection(settings.CaretPosition); } // Do what Visual Studio does: fold all #regions else if (applyfolding) { ApplyFolding(GetFoldLevels()); } }
//mxd private static void WriteScriptDocumentSettings(Configuration mapconfig, string prefix, ScriptDocumentSettings settings) { // Store data ListDictionary data = new ListDictionary(); data.Add("filename", settings.Filename); data.Add("hash", settings.Hash); data.Add("resource", settings.ResourceLocation); data.Add("tabtype", (int)settings.TabType); data.Add("scripttype", (int)settings.ScriptType); if (settings.CaretPosition > 0) { data.Add("caretposition", settings.CaretPosition); } if (settings.FirstVisibleLine > 0) { data.Add("firstvisibleline", settings.FirstVisibleLine); } if (settings.IsActiveTab) { data.Add("activetab", true); } // Convert dictionary to string List <string> foldlevels = new List <string>(); foreach (KeyValuePair <int, HashSet <int> > group in settings.FoldLevels) { List <string> linenums = new List <string>(group.Value.Count); foreach (int i in group.Value) { linenums.Add(i.ToString()); } foldlevels.Add(group.Key + ":" + string.Join(",", linenums.ToArray())); } // Add to collection if (foldlevels.Count > 0) { data.Add("foldlevels", string.Join(";", foldlevels.ToArray())); } // Write to config mapconfig.WriteSetting(prefix, data); }
//mxd private static ScriptDocumentSettings ReadScriptDocumentSettings(IDictionary scfinfo) { ScriptDocumentSettings settings = new ScriptDocumentSettings { FoldLevels = new Dictionary <int, HashSet <int> >() }; // Copy information from Configuration to ScriptDocumentSaveSettings if (scfinfo.Contains("filename") && (scfinfo["filename"] is string)) { settings.Filename = (string)scfinfo["filename"]; } if (scfinfo.Contains("hash")) { // Configuration will parse the value as int if it's inside int type bounds. if (scfinfo["hash"] is int) { settings.Hash = (int)scfinfo["hash"]; } else if (scfinfo["hash"] is long) { settings.Hash = (long)scfinfo["hash"]; } } if (scfinfo.Contains("resource") && (scfinfo["resource"] is string)) { settings.ResourceLocation = (string)scfinfo["resource"]; } if (scfinfo.Contains("tabtype") && (scfinfo["tabtype"] is int)) { settings.TabType = (ScriptDocumentTabType)scfinfo["tabtype"]; } if (scfinfo.Contains("scripttype") && (scfinfo["scripttype"] is int)) { settings.ScriptType = (ScriptType)scfinfo["scripttype"]; } if (scfinfo.Contains("caretposition") && (scfinfo["caretposition"] is int)) { settings.CaretPosition = (int)scfinfo["caretposition"]; } if (scfinfo.Contains("firstvisibleline") && (scfinfo["firstvisibleline"] is int)) { settings.FirstVisibleLine = (int)scfinfo["firstvisibleline"]; } if (scfinfo.Contains("activetab") && (scfinfo["activetab"] is bool)) { settings.IsActiveTab = (bool)scfinfo["activetab"]; } if (scfinfo.Contains("foldlevels") && (scfinfo["foldlevels"] is string)) { // 1:12,13,14;2:21,43,36 string foldstr = (string)scfinfo["foldlevels"]; // Convert string to dictionary if (!string.IsNullOrEmpty(foldstr)) { //TODO: add all kinds of warnings? string[] foldlevels = foldstr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string foldlevel in foldlevels) { // 1:12,13,14 string[] parts = foldlevel.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) { continue; } int fold; if (!int.TryParse(parts[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out fold)) { continue; } if (settings.FoldLevels.ContainsKey(fold)) { continue; } string[] linenumbersstr = parts[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (linenumbersstr.Length == 0) { continue; } HashSet <int> linenumbers = new HashSet <int>(); foreach (string linenumber in linenumbersstr) { int linenum; if (int.TryParse(linenumber, NumberStyles.Integer, CultureInfo.InvariantCulture, out linenum)) { linenumbers.Add(linenum); } } if (linenumbers.Count != linenumbersstr.Length) { continue; } // Add to collection settings.FoldLevels.Add(fold, new HashSet <int>(linenumbers)); } } } return(settings); }
// Constructor to load from Doom Builder Map Settings Configuration internal MapOptions(Configuration cfg, string mapname, bool longtexturenamessupported) { // Initialize this.previousname = ""; this.currentname = mapname; this.strictpatches = General.Int2Bool(cfg.ReadSetting("strictpatches", 0)); this.configfile = cfg.ReadSetting("gameconfig", ""); this.resources = new DataLocationList(); this.mapconfig = new Configuration(true); this.scriptsettings = new Dictionary <string, ScriptDocumentSettings>(StringComparer.OrdinalIgnoreCase); //mxd // Read map configuration this.mapconfig.Root = cfg.ReadSetting("maps." + mapname, new Hashtable()); //mxd. Read Tag Labels this.tagLabels = new Dictionary <int, string>(); ListDictionary tagLabelsData = (ListDictionary)this.mapconfig.ReadSetting("taglabels", new ListDictionary()); foreach (DictionaryEntry tagLabelsEntry in tagLabelsData) { int tag = 0; string label = string.Empty; foreach (DictionaryEntry entry in (ListDictionary)tagLabelsEntry.Value) { switch ((string)entry.Key) { case "tag": tag = (int)entry.Value; break; case "label": label = (string)entry.Value; break; } } if (tag != 0 && !string.IsNullOrEmpty(label)) { tagLabels.Add(tag, label); } } //mxd. Script compiler scriptcompiler = this.mapconfig.ReadSetting("scriptcompiler", string.Empty); //mxd. Read Sector drawing options defaultfloortexture = this.mapconfig.ReadSetting("defaultfloortexture", string.Empty); defaultceiltexture = this.mapconfig.ReadSetting("defaultceiltexture", string.Empty); defaulttoptexture = this.mapconfig.ReadSetting("defaulttoptexture", string.Empty); defaultwalltexture = this.mapconfig.ReadSetting("defaultwalltexture", string.Empty); defaultbottomtexture = this.mapconfig.ReadSetting("defaultbottomtexture", string.Empty); custombrightness = General.Clamp(this.mapconfig.ReadSetting("custombrightness", 196), 0, 255); customfloorheight = this.mapconfig.ReadSetting("customfloorheight", 0); customceilheight = this.mapconfig.ReadSetting("customceilheight", 128); //mxd. Read Sector drawing overrides overridefloortexture = this.mapconfig.ReadSetting("overridefloortexture", false); overrideceiltexture = this.mapconfig.ReadSetting("overrideceiltexture", false); overridetoptexture = this.mapconfig.ReadSetting("overridetoptexture", false); overridemiddletexture = this.mapconfig.ReadSetting("overridemiddletexture", false); overridebottomtexture = this.mapconfig.ReadSetting("overridebottomtexture", false); overridefloorheight = this.mapconfig.ReadSetting("overridefloorheight", false); overrideceilheight = this.mapconfig.ReadSetting("overrideceilheight", false); overridebrightness = this.mapconfig.ReadSetting("overridebrightness", false); //mxd uselongtexturenames = longtexturenamessupported && this.mapconfig.ReadSetting("uselongtexturenames", false); useresourcesinreadonlymode = this.mapconfig.ReadSetting("useresourcesinreadonlymode", false); //mxd. Position and scale float vpx = this.mapconfig.ReadSetting("viewpositionx", float.NaN); float vpy = this.mapconfig.ReadSetting("viewpositiony", float.NaN); if (!float.IsNaN(vpx) && !float.IsNaN(vpy)) { viewposition = new Vector2D(vpx, vpy); } viewscale = this.mapconfig.ReadSetting("viewscale", float.NaN); // Resources IDictionary reslist = this.mapconfig.ReadSetting("resources", new Hashtable()); foreach (DictionaryEntry mp in reslist) { // Item is a structure? IDictionary resinfo = mp.Value as IDictionary; if (resinfo != null) { // Create resource DataLocation res = new DataLocation(); // Copy information from Configuration to ResourceLocation if (resinfo.Contains("type") && (resinfo["type"] is int)) { res.type = (int)resinfo["type"]; } if (resinfo.Contains("location") && (resinfo["location"] is string)) { res.location = (string)resinfo["location"]; } if (resinfo.Contains("textures") && (resinfo["textures"] is bool)) { res.option1 = (bool)resinfo["textures"]; } if (resinfo.Contains("flats") && (resinfo["flats"] is bool)) { res.option2 = (bool)resinfo["flats"]; } // Add resource AddResource(res); } } //mxd. Read script documents settings IDictionary sflist = this.mapconfig.ReadSetting("scriptdocuments", new Hashtable()); foreach (DictionaryEntry mp in sflist) { // Item is a structure? IDictionary scfinfo = mp.Value as IDictionary; if (scfinfo != null) { ScriptDocumentSettings settings = ReadScriptDocumentSettings(scfinfo); if (!string.IsNullOrEmpty(settings.Filename)) { scriptsettings[settings.Filename] = settings; } } } }
internal virtual void SetViewSettings(ScriptDocumentSettings settings) { }