/// <summary> /// Loads character state from a stream /// </summary> /// <param name="s"></param> public void LoadCharacterFromStream(Stream s, Boolean autoLoadResources = false) { try { // Load XMLDocument XmlDocument doc = new XmlDocument(); s.Position = 0; doc.Load(s); // Get Character Name and Verify it String name = doc.SelectSingleNode("MoltenMercuryState").Attributes["name"].InnerText; if (name != resourceManager.Name) { if (autoLoadResources && characters.ContainsKey(name)) { LoadCharacterResourcesGeneric(characters[name]); } else { MessageBox.Show(String.Format(Localization.LocalizationDictionary.Instance["ERR_701"], name)); return; } } // Clear current selection and layer adjustment data resourceManager.ClearSelection(); ClearLayerAdjustments(); // Load Selection foreach (XmlNode selNode in doc.SelectNodes("MoltenMercuryState/Selection")) { String groupName = selNode.Attributes["group"].InnerText; String setName = selNode.Attributes["set"].InnerText; CharaSetGroup cgroup = resourceManager.GetGroupByName(groupName); if (cgroup == null) throw new Exception(String.Format("CharaSetGroup {0} Not Found!", groupName)); CharaSet cset = cgroup.GetSetByName(setName); if (cset == null) throw new Exception(String.Format("CharaSet {0} Not Found!", setName)); if (cgroup.Multiselect) { Int32 ladj = Int32.Parse(selNode.Attributes["adjustment"].InnerText); cset.LayerAdjustment = ladj; } cset.Selected = true; } // Regenerate layer adjustment values foreach (CharaSetGroup csg in resourceManager) { if (csg.Multiselect) GenerateLayerAdjustments(csg); } resourceManager.Processors.Clear(); UpdateColorProcessorList(); // Load Color Presets foreach (XmlNode colNode in doc.SelectNodes("MoltenMercuryState/ImageProcessor")) { String group = colNode.Attributes["colorgroup"].InnerText; String preset = colNode.InnerText; if (resourceManager.Processors.ContainsKey(group)) resourceManager.Processors[group].DecodeSettings(preset); } tmpProcessor = (ImageProcessor)resourceManager.Processors[cmbColorProcessors.Text].Clone(); SyncTmpToUI(); // Reflect changes on UI using (CharaBlocker cb = new CharaBlocker(this)) { ReloadPropertyListView((CharaSetGroup)cmbCharaProp.SelectedItem); cb.DummyMethod(); } } catch { // Done, Delete all cached data and Update Stuff UpdateCharacterPreviewAsync(); } }
private double GetRelation(ImageProcessor.AdjustmentMode mode, double original, double newval) { switch (mode) { case ImageProcessor.AdjustmentMode.None: return 0; case ImageProcessor.AdjustmentMode.Multiplication: return newval / original; case ImageProcessor.AdjustmentMode.Addition: return newval - original; case ImageProcessor.AdjustmentMode.Absolute: return newval; } throw new Exception(); }