public static SpawnItem Load(XmlElement elem, ILog log) { string type = elem.Name; if (!Pack.SpawnItemConfig.Types.Keys.Contains(type)) { throw new CommonException("Unknown type: {0}", type); } var result = new SpawnItem(type, elem.GetFloatAttribute(DelayAttribName)); foreach (XmlElement attachElem in elem.GetChildElements()) { try { result.Attachments.Add(SpawnItemAttachment.Load(attachElem)); } catch (Exception ex) { log.Write("Error while loading attachment: {0}. Skipped.", ex.Message); } } return(result); }
private void gvItems_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) { if (!_attachTypeColMap.ContainsKey(e.Column)) return; string attachmentType = _attachTypeColMap[e.Column]; var item = (Item)e.Row; int index = int.Parse(e.Column.Name.Replace(PackForm.AttachmentColNamePrefix + attachmentType, String.Empty)); SpawnItemAttachment[] attachments = item.Attachments.Where(att => att.Type == attachmentType).ToArray(); SpawnItemAttachment attach = index < attachments.Length ? attachments[index] : null; if (e.IsGetData) { if (attach != null) e.Value = attachments[index].Name; else e.Value = null; } else if (e.IsSetData) { string attachmentName = (string)e.Value; if (attachmentName == null) { if (attach != null) item.Attachments.Remove(attach); } else { if (attach != null) { attach.Name = attachmentName; } else { attach = new SpawnItemAttachment(attachmentType, attachmentName); item.Attachments.Add(attach); } } } }