public void LoadFromData(string propertyName, IINode dataNode) { if (!Guid.TryParse(propertyName, out serializedId)) { throw new Exception("Invalid ID, can't deserialize."); } string propertiesString = string.Empty; if (!dataNode.GetUserPropString(propertyName, ref propertiesString)) { return; } string[] properties = propertiesString.Split(s_PropertySeparator); if (properties.Length < 4) { throw new Exception("Invalid number of properties, can't deserialize."); } // set dirty explicitly just before we start loading, set to false when loading is done // if any exception is thrown, it will have a correct value IsDirty = true; name = properties[0]; if (!int.TryParse(properties[1], out ticksStart)) { throw new Exception("Failed to parse FrameStart property."); } if (!int.TryParse(properties[2], out ticksEnd)) { throw new Exception("Failed to parse FrameEnd property."); } if (string.IsNullOrEmpty(properties[3])) { return; } int numNodeIDs = properties.Length - 3; if (nodeGuids.Capacity < numNodeIDs) { nodeGuids.Capacity = numNodeIDs; } int numFailed = 0; for (int i = 0; i < numNodeIDs; ++i) { Guid guid; if (!Guid.TryParse(properties[3 + i], out guid)) { uint id; if (!uint.TryParse(properties[3 + i], out id)) { ++numFailed; continue; } //node is serialized in the old way ,force the reassignation of a new Guid on IINode node = Loader.Core.GetINodeByHandle(id); if (node != null) { guid = node.GetGuid(); } } nodeGuids.Add(guid); } AnimationGroupNodes = new List <AnimationGroupNode>(); foreach (Guid nodeGuid in nodeGuids) { IINode node = Tools.GetINodeByGuid(nodeGuid); if (node != null) { string name = node.Name; string parentName = node.ParentNode.Name; AnimationGroupNode nodeData = new AnimationGroupNode(nodeGuid, name, parentName); AnimationGroupNodes.Add(nodeData); } } if (numFailed > 0) { throw new Exception(string.Format("Failed to parse {0} node ids.", numFailed)); } IsDirty = false; }
private void confirmButton_Click(object sender, EventArgs e) { if (currentInfo == null) { return; } AnimationGroup confirmedInfo = currentInfo; string newName = nameTextBox.Text; bool newKeepEmpty = keepStaticAnimBox.Checked; bool newKeepNonAnimated = keepNonAnimatedBox.Checked; int newFrameStart; if (!int.TryParse(startTextBox.Text, out newFrameStart)) { newFrameStart = confirmedInfo.FrameStart; } int newFrameEnd; if (!int.TryParse(endTextBox.Text, out newFrameEnd)) { newFrameEnd = confirmedInfo.FrameEnd; } List <uint> newHandles; bool nodesChanged = MaxNodeTree.ApplyQueuedChanges(out newHandles); IList <Guid> newMaterialGUIDs; bool materialsChanged = maxMaterialView.ApplyMaterialsChanges(out newMaterialGUIDs); bool changed = newKeepEmpty != confirmedInfo.KeepStaticAnimation || newName != confirmedInfo.Name || newFrameStart != confirmedInfo.FrameStart || newFrameEnd != confirmedInfo.FrameEnd || nodesChanged || materialsChanged || newKeepNonAnimated != confirmedInfo.KeepNonAnimated; if (!changed) { return; } confirmedInfo.Name = newName; confirmedInfo.FrameStart = newFrameStart; confirmedInfo.FrameEnd = newFrameEnd; confirmedInfo.KeepStaticAnimation = newKeepEmpty; confirmedInfo.KeepNonAnimated = newKeepNonAnimated; if (nodesChanged) { confirmedInfo.NodeGuids = newHandles.ToGuids(); if (confirmedInfo.AnimationGroupNodes == null) { confirmedInfo.AnimationGroupNodes = new List <AnimationGroupNode>(); } foreach (uint handle in newHandles) { IINode node = Loader.Core.GetINodeByHandle(handle); if (node != null) { string name = node.Name; string parentName = node.ParentNode.Name; AnimationGroupNode nodeData = new AnimationGroupNode(node.GetGuid(), name, parentName); confirmedInfo.AnimationGroupNodes.Add(nodeData); } } } if (materialsChanged) { confirmedInfo.MaterialGuids = newMaterialGUIDs; if (confirmedInfo.AnimationGroupMaterials == null) { confirmedInfo.AnimationGroupMaterials = new List <AnimationGroupMaterial>(); } foreach (Guid guid in newMaterialGUIDs) { IMtl mat = Tools.GetIMtlByGuid(guid); if (mat != null) { string name = mat.Name; AnimationGroupMaterial matData = new AnimationGroupMaterial(guid, name); confirmedInfo.AnimationGroupMaterials.Add(matData); } } } ResetChangedTextBoxColors(); MaxNodeTree.SelectedNode = null; InfoChanged?.Invoke(confirmedInfo); ConfirmPressed?.Invoke(confirmedInfo); }
private void confirmButton_Click(object sender, EventArgs e) { if (currentInfo == null) { return; } AnimationGroup confirmedInfo = currentInfo; string newName = nameTextBox.Text; int newFrameStart; if (!int.TryParse(startTextBox.Text, out newFrameStart)) { newFrameStart = confirmedInfo.FrameStart; } int newFrameEnd; if (!int.TryParse(endTextBox.Text, out newFrameEnd)) { newFrameEnd = confirmedInfo.FrameEnd; } List <uint> newHandles; bool nodesChanged = MaxNodeTree.ApplyQueuedChanges(out newHandles); bool changed = newName != confirmedInfo.Name || newFrameStart != confirmedInfo.FrameStart || newFrameEnd != confirmedInfo.FrameEnd || nodesChanged; if (!changed) { return; } confirmedInfo.Name = newName; confirmedInfo.FrameStart = newFrameStart; confirmedInfo.FrameEnd = newFrameEnd; if (nodesChanged) { confirmedInfo.NodeGuids = newHandles.ToGuids(); if (confirmedInfo.AnimationGroupNodes == null) { confirmedInfo.AnimationGroupNodes = new List <AnimationGroupNode>(); } foreach (uint handle in newHandles) { IINode node = Loader.Core.GetINodeByHandle(handle); if (node != null) { string name = node.Name; string parentName = node.ParentNode.Name; AnimationGroupNode nodeData = new AnimationGroupNode(node.GetGuid(), name, parentName); confirmedInfo.AnimationGroupNodes.Add(nodeData); } } } ResetChangedTextBoxColors(); MaxNodeTree.SelectedNode = null; InfoChanged?.Invoke(confirmedInfo); ConfirmPressed?.Invoke(confirmedInfo); }
public void LoadFromData(string propertyName, IINode dataNode, Dictionary <string, string> rootNodePropDictionary = null) { if (!Guid.TryParse(propertyName, out serializedId)) { throw new Exception("Invalid ID, can't deserialize."); } string propertiesString = string.Empty; if (rootNodePropDictionary == null) { if (!dataNode.GetUserPropString(propertyName, ref propertiesString)) { return; } } else { if (!rootNodePropDictionary.TryGetValue(propertyName, out propertiesString)) { return; } } int numFailed = 0; try // Try using the new way, if it's not working use the old way. { SerializableAnimationGroup serialAnimGroup = new SerializableAnimationGroup(propertiesString); serialAnimGroup.FillSerializedData(this); } catch { int indexOfguidPart = propertiesString .Select((c, i) => new { c, i }) .Where(x => x.c == s_PropertySeparator) .Skip(2) .FirstOrDefault().i; string[] baseProperties = propertiesString.Substring(0, indexOfguidPart)?.Split(s_PropertySeparator); string guidPart = propertiesString.Substring(indexOfguidPart + 1); if (baseProperties.Length != 3) { throw new Exception("Invalid number of properties, can't deserialize."); } // set dirty explicitly just before we start loading, set to false when loading is done // if any exception is thrown, it will have a correct value IsDirty = true; name = baseProperties[0]; if (!int.TryParse(baseProperties[1], out ticksStart)) { throw new Exception("Failed to parse FrameStart property."); } if (!int.TryParse(baseProperties[2], out ticksEnd)) { throw new Exception("Failed to parse FrameEnd property."); } if (string.IsNullOrEmpty(guidPart) || guidPart == s_GUIDTypeSeparator.ToString()) { return; } if (!guidPart.Contains(s_GUIDTypeSeparator)) { // to grant retro-compatiblity numFailed = ParseOldProperties(guidPart); } else { //new format with nodes and node materials guid numFailed = ParseNewProperties(guidPart); } } AnimationGroupNodes = new List <AnimationGroupNode>(); foreach (Guid nodeGuid in nodeGuids) { IINode node = Tools.GetINodeByGuid(nodeGuid); if (node != null) { string name = node.Name; string parentName = node.ParentNode.Name; AnimationGroupNode nodeData = new AnimationGroupNode(nodeGuid, name, parentName); AnimationGroupNodes.Add(nodeData); } } AnimationGroupMaterials = new List <AnimationGroupMaterial>(); foreach (Guid materialGUID in materialsGuids) { IMtl mat = Tools.GetIMtlByGuid(materialGUID); if (mat != null) { string name = mat.Name; AnimationGroupMaterial matData = new AnimationGroupMaterial(materialGUID, name); AnimationGroupMaterials.Add(matData); } } if (numFailed > 0) { throw new Exception(string.Format("Failed to parse {0} node ids.", numFailed)); } IsDirty = false; }