示例#1
0
        private async void OnSaveClicked(object sender, RoutedEventArgs e)
        {
            IFileService fileService = Module.Services.Get <IFileService>();

            PoseFile file = new PoseFile();

            file.Read(this.ViewModel.Bones);

            await fileService.SaveAs(file);
        }
示例#2
0
        private async void OnSaveClicked(object sender, RoutedEventArgs e)
        {
            SkeletonViewModel vm = this.DataContext as SkeletonViewModel;

            IViewService viewService = Services.Get <IViewService>();

            PoseFile.Groups groups = await viewService.ShowDialog <BoneGroupsSelectorDialog, PoseFile.Groups>("Save Pose...");

            if (groups == PoseFile.Groups.None)
            {
                return;
            }

            IFileService fileService = Services.Get <IFileService>();
            PoseFile     file        = new PoseFile();

            file.Read(vm.Bones, groups);

            await fileService.SaveAs(file);
        }
示例#3
0
        public PoseFile Upgrade()
        {
            PoseFile file = new PoseFile();

            // This whole function just does this:
            // file.Root = StringToBone(this.Root, this.RootSize);
            // but for every bone in the file.
            Type legacyType = this.GetType();
            Type newType    = typeof(PoseFile);

            PropertyInfo[] props = file.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in props)
            {
                PropertyInfo rotProp   = legacyType.GetProperty(propertyInfo.Name);
                PropertyInfo scaleProp = legacyType.GetProperty(propertyInfo.Name + "Size");
                PropertyInfo transProp = newType.GetProperty(propertyInfo.Name);

                string rotString   = null;
                string scaleString = null;

                if (rotProp != null)
                {
                    rotString = (string)rotProp.GetValue(this);
                }

                if (scaleProp != null)
                {
                    scaleString = (string)scaleProp.GetValue(this);
                }

                Transform bone = StringToBone(rotString, scaleString);
                transProp.SetValue(file, bone);
            }

            return(file);
        }
示例#4
0
        public PoseFile Upgrade(Appearance.Races race)
        {
            PoseFile file = new PoseFile();

            file.IncludePositions = false;
            file.IncludeScale     = false;
            Type legacyType = this.GetType();

            Appearance.Races fileRace = (Appearance.Races) byte.Parse(this.Race);

            PropertyInfo[] props = this.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in props)
            {
                string boneName = propertyInfo.Name;

                if (boneName == "Race")
                {
                    continue;
                }

                if (boneName.EndsWith("Size"))
                {
                    continue;
                }

                PropertyInfo rotProp   = legacyType.GetProperty(boneName);
                PropertyInfo scaleProp = legacyType.GetProperty(boneName + "Size");

                if (boneName.StartsWith(@"Hroth"))
                {
                    if (fileRace == Appearance.Races.Hrothgar)
                    {
                        boneName = boneName.Replace(@"Hroth", string.Empty);
                    }
                    else
                    {
                        continue;
                    }
                }

                if (boneName.StartsWith("Viera"))
                {
                    if (fileRace == Appearance.Races.Viera)
                    {
                        boneName = boneName.Replace("Viera", string.Empty);
                    }
                    else
                    {
                        continue;
                    }
                }

                if (boneName.StartsWith("ExHair"))
                {
                    string letter = boneName.Replace("ExHair", string.Empty);
                    byte   index  = this.StringToByte(letter);
                    boneName = "ExHair" + index;
                }
                else if (boneName.StartsWith("ExMet"))
                {
                    string letter = boneName.Replace("ExMet", string.Empty);
                    byte   index  = this.StringToByte(letter);
                    boneName = "ExMet" + index;
                }
                else if (boneName.StartsWith("ExTop"))
                {
                    string letter = boneName.Replace("ExTop", string.Empty);
                    byte   index  = this.StringToByte(letter);
                    boneName = "ExTop" + index;
                }

                string rotString   = null;
                string scaleString = null;

                if (rotProp != null)
                {
                    rotString = (string)rotProp.GetValue(this);
                }

                if (scaleProp != null)
                {
                    scaleString = (string)scaleProp.GetValue(this);
                }

                if (rotString == null && scaleString == null)
                {
                    continue;
                }

                // Hroth and Viera bones should always be _after_ the base bones,
                // And we only reach this point if we want them, so always prefer newer bones.
                if (file.Bones.ContainsKey(boneName))
                {
                    file.Bones.Remove(boneName);
                }

                Transform bone = StringToBone(rotString, scaleString);
                file.Bones.Add(boneName, bone);
            }

            return(file);
        }