コード例 #1
0
ファイル: HtmlContent.cs プロジェクト: Emilgardis/falloutsnip
        public void UpdateRecord(BaseRecord record)
        {
            if (record == null)
            {
                this.UpdateText(string.Empty);
                return;
            }

            try
            {
                string html = FalloutSnip.UI.Rendering.HtmlRenderer.GetDescription(record);
                UpdateText(html);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Resources.WarningText);
            }
        }
コード例 #2
0
        public void UpdateRecord(BaseRecord sc)
        {
            if (sc == null)
            {
                this.UpdateText(string.Empty);
                return;
            }

            FontLangInfo defLang;
            if (!Encoding.TryGetFontInfo(Domain.Properties.Settings.Default.LocalizationName, out defLang))
            {
                defLang = new FontLangInfo(1252, 1033, 0);
            }

            var rb = new RTFBuilder(RTFFont.Arial, 16, defLang.lcid, defLang.charset);
            sc.GetFormattedHeader(rb);
            sc.GetFormattedData(rb);
            this.rtfInfo.Rtf = rb.ToString();
        }
コード例 #3
0
ファイル: Spells.cs プロジェクト: Emilgardis/falloutsnip
        /// <summary>
        ///  Copy Records to new plugin.  By default make as overrides
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="bOverride">Make record an override in the new location</param>
        /// <returns></returns>
        public static int CopyRecordsTo(BaseRecord[] src, IGroupRecord dst, bool bOverride = true)
        {
            int count = 0;
            if (src != null && dst != null)
            {
                if (dst is Plugin)
                {
                    var plugin = (Plugin)dst;
                    count = new CloneTool(plugin, bOverride).CopyRecordsTo(src);
                }
                else
                {
                    var dstRec = src.Select(x => x.Clone()).ToArray();
                    dst.AddRecords(dstRec);
                    count += dstRec.Count();
                }
            }

            return count;
        }
コード例 #4
0
ファイル: CloneTool.cs プロジェクト: Emilgardis/falloutsnip
        public static Plugin GetPluginFromNode(BaseRecord node)
        {
            BaseRecord tn = node;
            if (tn is Plugin)
            {
                return (Plugin)tn;
            }

            while (!(tn is Plugin) && tn != null)
            {
                tn = tn.Parent;
            }

            if (tn != null)
            {
                return tn as Plugin;
            }

            return null;
        }
コード例 #5
0
        private Plugin GetPluginFromNode(BaseRecord node)
        {
            var tn = node;
            if (tn is Plugin)
            {
                return (Plugin)tn;
            }

            while (!(tn is Plugin) && tn != null)
            {
                tn = tn.Parent;
            }

            if (tn != null)
            {
                return tn as Plugin;
            }

            return new Plugin();
        }
コード例 #6
0
 public static string GetDescription(BaseRecord rec)
 {
     if (rendererImpl == null)
     {
     return defaultRenderText;
     //                var sb = new StringBuilder();
     //                Extensions.StringRenderer.GetFormattedData(rec, sb);
     //                return sb.ToString();
     }
     try
     {
         var kwargs = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
         kwargs["title"] = "Record";
         kwargs["css"] = new string[] {Path.ChangeExtension(RendererPyPath, ".css")};
         return rendererImpl.Render(rec, kwargs);
     }
     catch (Exception ex)
     {
         return ex.ToString();
         //return Extensions.StringRenderer.GetDesc(rec);
     }
 }
コード例 #7
0
ファイル: PluginList.cs プロジェクト: Emilgardis/falloutsnip
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var r = br as Plugin;
            r.Parent = this;
            if (idx < 0 || idx > this.pluginList.Count)
            {
                idx = this.pluginList.Count;
            }

            this.pluginList.Insert(idx, r);
            FireRecordListUpdate(this, null);
        }
コード例 #8
0
ファイル: GroupRecord.cs プロジェクト: Emilgardis/falloutsnip
 public override int IndexOf(BaseRecord br)
 {
     return this.records.IndexOf(br as Rec);
 }
コード例 #9
0
ファイル: GroupRecord.cs プロジェクト: Emilgardis/falloutsnip
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var r = br as Rec;
            if (r == null)
            {
                throw new TESParserException("Record to add was not of the correct type." + Environment.NewLine + "Groups can only hold records or other groups.");
            }

            r.Parent = this;
            if (idx < 0 || idx > this.records.Count)
            {
                idx = this.records.Count;
            }

            this.records.Insert(idx, r);
            FireRecordListUpdate(this, this);
        }
コード例 #10
0
ファイル: PluginList.cs プロジェクト: Emilgardis/falloutsnip
        public override bool DeleteRecord(BaseRecord br)
        {
            var p = br as Plugin;
            if (p != null)
            {
                p.Parent = null;
                bool ok = this.pluginList.Remove(p);
                FireRecordListUpdate(this, this);
                return ok;
            }

            return false;
        }
コード例 #11
0
ファイル: GroupRecord.cs プロジェクト: Emilgardis/falloutsnip
        public override bool DeleteRecord(BaseRecord br)
        {
            var r = br as Rec;
            if (r == null)
            {
                return false;
            }

            bool ok = this.records.Remove(r);
            if (ok)
            {
                r.Parent = null;
            }

            FireRecordListUpdate(this, this);
            FireRecordDeleted(this, r);
            return ok;
        }
コード例 #12
0
ファイル: Spells.cs プロジェクト: Emilgardis/falloutsnip
 public static void giveBaseRecordNewFormID(BaseRecord rec, bool updateReference, ref uint formCount,
                                            ref uint refCount)
 {
     if (rec is Record)
     {
         giveRecordNewFormID((Record)rec, updateReference, ref formCount, ref refCount);
     }
     else if (rec is GroupRecord)
     {
         foreach (BaseRecord rec2 in ((GroupRecord)rec).Records)
         {
             giveBaseRecordNewFormID(rec2, updateReference, ref formCount, ref refCount);
         }
     }
 }
コード例 #13
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 public abstract bool DeleteRecord(BaseRecord br);
コード例 #14
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 public abstract void AddRecord(BaseRecord br);
コード例 #15
0
ファイル: PluginList.cs プロジェクト: Emilgardis/falloutsnip
 public override int IndexOf(BaseRecord br)
 {
     return this.pluginList.IndexOf(br as Plugin);
 }
コード例 #16
0
ファイル: Record.cs プロジェクト: Emilgardis/falloutsnip
        public override bool DeleteRecord(BaseRecord br)
        {
            var sr = br as SubRecord;
            if (sr == null)
            {
                return false;
            }

            return this.SubRecords.Remove(sr);
        }
コード例 #17
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 protected static void FireRecordListUpdate(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && ChildListChanged != null)
     {
         ChildListChanged(sender, new RecordChangeEventArgs(rec));
     }
 }
コード例 #18
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 protected static void FireRecordDeleted(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && RecordDeleted != null)
     {
         RecordDeleted(sender, new RecordChangeEventArgs(rec));
     }
 }
コード例 #19
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 public virtual void InsertRecord(int index, BaseRecord br)
 {
     this.AddRecord(br);
 }
コード例 #20
0
ファイル: BaseRecord.cs プロジェクト: Emilgardis/falloutsnip
 public virtual int IndexOf(BaseRecord br)
 {
     return -1;
 }
コード例 #21
0
ファイル: Record.cs プロジェクト: Emilgardis/falloutsnip
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var sr = br as SubRecord;
            if (sr == null)
            {
                throw new TESParserException("Record to add was not of the correct type." + Environment.NewLine +
                                             "Records can only hold Subrecords.");
            }

            sr.Parent = this;
            this.SubRecords.Insert(idx, sr);
        }
コード例 #22
0
        private bool findDuplicateFormIDs(BaseRecord tn, Dictionary<uint, Record> ids)
        {
            if (tn is Record)
            {
                var r2 = (Record) tn;
                if (ids.ContainsKey(r2.FormID))
                {
                    this.PluginTree.SelectedRecord = tn;
                    MessageBox.Show("Record duplicates " + ids[r2.FormID].DescriptiveName);
                    ids.Clear();
                    return true;
                }
                else
                {
                    ids.Add(r2.FormID, r2);
                }
            }
            else
            {
                foreach (BaseRecord tn2 in tn.Records)
                {
                    this.findDuplicateFormIDs(tn2, ids);
                }
            }

            return false;
        }
コード例 #23
0
 public RecordChangeEventArgs(BaseRecord rec)
 {
     this.record = rec;
 }
コード例 #24
0
ファイル: Plugin.cs プロジェクト: Hual/falloutsnip
        public override void AddRecord(BaseRecord br)
        {
            try
            {
                var r = br as Rec;
                if (r == null)
                {
                    throw new TESParserException("Record to add was not of the correct type." + Environment.NewLine + "PluginList can only hold Groups or Records.");
                }

                r.Parent = this;
                this.records.Add(r);
                this.InvalidateCache();
                FireRecordListUpdate(this, this);
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #25
0
ファイル: Spells.cs プロジェクト: Emilgardis/falloutsnip
 public static void giveBaseRecordNewFormID(BaseRecord rec, bool updateReference)
 {
     uint formCount = 0, refCount = 0;
     giveBaseRecordNewFormID(rec, updateReference, ref formCount, ref refCount);
 }
コード例 #26
0
ファイル: Plugin.cs プロジェクト: Hual/falloutsnip
        public override bool DeleteRecord(BaseRecord br)
        {
            var r = br as Rec;
            if (r == null)
            {
                return false;
            }

            bool result = this.records.Remove(r);
            if (result)
            {
                r.Parent = null;
            }

            this.InvalidateCache();
            FireRecordDeleted(this, r);
            FireRecordListUpdate(this, this);
            return result;
        }
コード例 #27
0
ファイル: CloneTool.cs プロジェクト: Emilgardis/falloutsnip
        BaseRecord Clone(BaseRecord record, bool bRecursive)
        {
            var p = GetPluginFromNode(record);
            PluginInfo info;
            if (!pluginMap.TryGetValue(p, out info))
                pluginMap.Add(p, info = new PluginInfo() { Masters = p.GetMasters() });

            var result = record.Clone(recursive: bRecursive);
            foreach (var rec in result.Enumerate().OfType<Record>())
            {
                uint newid;
                if (info.References.TryGetValue(rec.FormID, out newid) && rec.FormID != newid)
                    rec.FormID = newid;

                // now handle child references
                rec.MatchRecordStructureToRecord();
                foreach (var elem in rec.SubRecords
                    .SelectMany(sr => sr.EnumerateElements())
                    .Where(elem => elem.Structure != null && elem.Structure.type == ElementValueType.FormID)
                    )
                {
                    var value = elem.GetValue<uint>();
                    if (info.References.TryGetValue(value, out newid) && value != newid)
                        elem.AssignValue<uint>(newid);
                }
            }
            return result;
        }
コード例 #28
0
        private Plugin GetPluginFromNode(BaseRecord node)
        {
            BaseRecord tn = node;
            var pluginFromNode = tn as Plugin;
            if (pluginFromNode != null)
            {
                return pluginFromNode;
            }

            while (!(tn is Plugin) && tn != null)
            {
                tn = tn.Parent;
            }

            if (tn != null)
            {
                return tn as Plugin;
            }

            return null;
        }
コード例 #29
0
ファイル: CloneTool.cs プロジェクト: Emilgardis/falloutsnip
        /// <summary>
        /// Actually perform the copy
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public int CopyRecordsTo(BaseRecord[] src)
        {
            int count = 0;

            PrepMasters(src);

            var dstRec = this.Clone(src.Where(x => !LooseGroups.Contains(x.Name)), true).ToArray();
            if (dstRec.All(x => x is Record))
            {
                // put records into appropriate groups
                var groups = plugin.Records.OfType<GroupRecord>().ToList();
                var lookup = dstRec.GroupBy(r => r.Name)
                    .Select(g => new { key = g.Key, value = g.ToArray() })
                    .ToLookup(k => k.key, v => v.value);
                foreach (var kvp in lookup)
                {
                    if (LooseGroups.Contains(kvp.Key))
                    {
                        plugin.AddRecords(dstRec);
                    }
                    else
                    {
                        var gr = groups.FirstOrDefault(x => x.ContentsType == kvp.Key);
                        if (gr == null)
                        {
                            gr = new GroupRecord(kvp.Key);
                            plugin.AddRecord(gr);
                        }

                        foreach (var list in kvp)
                        {
                            gr.AddRecords(list);
                        }
                    }
                }
            }
            else
            {
                plugin.AddRecords(dstRec);
            }

            // handle loose groups by creating copy of parent groups
            foreach (var srcRec in src.Where(x => LooseGroups.Contains(x.Name)))
            {
                var dstnodes = new Stack<BaseRecord>();

                dstnodes.Push(this.Clone(srcRec, true));
                for (var n = srcRec.Parent; n is GroupRecord; n = n.Parent)
                {
                    dstnodes.Push(n.Clone(recursive: false));
                }

                var par = plugin as IGroupRecord;
                foreach (var baseRecord in dstnodes)
                {
                    if (par == null)
                    {
                        break;
                    }

                    if (baseRecord is GroupRecord)
                    {
                        var gr = baseRecord as GroupRecord;
                        var pargr = par.Records.OfType<GroupRecord>().FirstOrDefault(x => x.IsEquivalent(gr));
                        if (pargr != null)
                        {
                            par = pargr;
                            continue;
                        }
                    }

                    par.AddRecord(baseRecord);
                    par = baseRecord as IGroupRecord;
                }

                count += dstnodes.Count;
            }
            return count;
        }
コード例 #30
0
ファイル: GroupRecord.cs プロジェクト: Emilgardis/falloutsnip
        public override void AddRecord(BaseRecord br)
        {
            try
              {
            //var r = br as Rec;
            var r = br as Rec;
            if (r == null)
            {
              throw new TESParserException("Record to add was not of the correct type." + Environment.NewLine + "Groups can only hold records or other groups.");
            }

            r.Parent = this;
            this.records.Add(r);
            FireRecordListUpdate(this, this);
              }
              catch (Exception ex)
              {
              throw new TESParserException("GroupRecord.AddRecord: " + ex.Message);
              }
        }