Beispiel #1
0
        public void ChangeOutfit_Internal_KKABMX(KKABMXHelper helper)
        {
            List <BoneModifier> data = new List <BoneModifier>();

            foreach (KeyValuePair <string, Dictionary <string, Dictionary <string, BoneModifier> > > a in helper.KKABMX)
            {
                foreach (KeyValuePair <string, Dictionary <string, BoneModifier> > b in a.Value)
                {
                    foreach (KeyValuePair <string, BoneModifier> c in b.Value)
                    {
                        if (c.Value != null)
                        {
                            data.Add(c.Value);
                        }
                    }
                }
            }

            for (int i = 0; i < helper.KKABMXCoordinate.Length; i++)
            {
                foreach (KeyValuePair <string, Dictionary <string, Dictionary <string, BoneModifier> > > a in helper.KKABMXCoordinate[i])
                {
                    foreach (KeyValuePair <string, Dictionary <string, BoneModifier> > b in a.Value)
                    {
                        foreach (KeyValuePair <string, BoneModifier> c in b.Value)
                        {
                            if (c.Value != null)
                            {
                                BoneModifier bone = data.FirstOrDefault(v => v.BoneName == c.Key);

                                if (bone == null)
                                {
                                    data.Add(bone = new BoneModifier(c.Key));
                                }

                                if (!bone.IsCoordinateSpecific())
                                {
                                    bone.MakeCoordinateSpecific();
                                }

                                bone.CoordinateModifiers[i] = c.Value.CoordinateModifiers[i];
                            }
                        }
                    }
                }
            }

            kkabmx.SetExtendedData(data.KKABMXData());
        }
        private void DrawHeader()
        {
            GUILayout.BeginHorizontal(UnityEngine.GUI.skin.box);
            {
                GUILayout.Label("Add a new bone to the list. If valid, it will be saved to the card.");

                // todo Use _boneControllerMgr.GetAllPossibleBoneNames() for autocomplete/suggestions
                _boneAddFieldValue = GUILayout.TextField(_boneAddFieldValue, GUILayout.Width(90));

                if (GUILayout.Button("Add"))
                {
                    _addedBones.Add(_boneAddFieldValue);

                    var bc = _boneControllerMgr;

                    if (bc.GetModifier(_boneAddFieldValue) != null)
                    {
                        Logger.Log(LogLevel.Message, $"Bone {_boneAddFieldValue} is already added.");
                        _boneAddFieldValue = "";
                    }
                    else
                    {
                        var newMod = new BoneModifier(_boneAddFieldValue);
                        bc.AddModifier(newMod);
                        if (newMod.BoneTransform == null)
                        {
                            Logger.Log(LogLevel.Message, $"Failed to add bone {_boneAddFieldValue}, make sure the name is correct.");
                            bc.Modifiers.Remove(newMod);
                        }
                        else
                        {
                            Logger.Log(LogLevel.Message, $"Added bone {_boneAddFieldValue} successfully. Modify it to make it save.");
                            _boneAddFieldValue = "";
                        }
                    }
                }

                _onlyShowAdditional = GUILayout.Toggle(_onlyShowAdditional, "Only show added bones");
            }
            GUILayout.EndHorizontal();
        }
Beispiel #3
0
        /// <summary>
        /// Method to retrieve body bones from BoneModifier list.
        /// </summary>
        /// <param from>List of BoneModifiers to extract body bones from</param>
        protected static List <BoneModifier> GetBodyBones(List <BoneModifier> from)
        {
            List <BoneModifier> to = new List <BoneModifier>();

            foreach (BoneMeta boneMeta in InterfaceData.BoneControls.Where(x => makerBodyCategories.Contains(x.Category)))
            {
                BoneModifier addbone = from.Find(x => x.BoneName == boneMeta.BoneName);
                if (addbone != null)
                {
                    to.Add(addbone);
                }
                if (boneMeta.RightBoneName != "")
                {
                    addbone = from.Find(x => x.BoneName == boneMeta.RightBoneName);
                    if (addbone != null)
                    {
                        to.Add(addbone);
                    }
                }
            }
            return(to);
        }
Beispiel #4
0
        public static void KKABMXCoordToChara(ChaFileCoordinate coord, ChaFileControl chara)
        {
            Dictionary <string, BoneModifierData> coordData = coord.KKABMXData().BoneModifierData();
            List <BoneModifier> charaData = chara.KKABMXData().BoneModifiers();

            foreach (KeyValuePair <string, BoneModifierData> pair in coordData)
            {
                BoneModifier modifier = charaData.FirstOrDefault(v => v.BoneName == pair.Key);

                if (modifier == null)
                {
                    charaData.Add(modifier = new BoneModifier(pair.Key));
                }

                modifier.MakeCoordinateSpecific();

                for (int i = 0; i < modifier.CoordinateModifiers.Length; i++)
                {
                    modifier.CoordinateModifiers[i] = pair.Value;
                }
            }

            ExtendedSave.SetExtendedDataById(chara, KKABMX_Core.ExtDataGUID, charaData.KKABMXData());
        }
Beispiel #5
0
        private void RegisterFingerControl(MakerCategory category, RegisterCustomControlsEvent callback)
        {
            var rbSide = callback.AddControl(new MakerRadioButtons(category, this, "Hand to edit", "Both", "Left", "Right")
            {
                TextColor = _settingColor
            });
            var rbFing = callback.AddControl(new MakerRadioButtons(category, this, "Finger to edit", "All", "1", "2", "3", "4", "5")
            {
                TextColor = _settingColor
            });
            var rbSegm = callback.AddControl(new MakerRadioButtons(category, this, "Segment to edit", "Base", "Center", "Tip")
            {
                TextColor = _settingColor
            });

            IEnumerable <string> GetFingerBoneNames()
            {
                var fingers   = rbFing.Value == 0 ? InterfaceData.FingerNamePrefixes : new[] { InterfaceData.FingerNamePrefixes[rbFing.Value - 1] };
                var segmented = fingers.Select(fName => $"{fName}0{rbSegm.Value + 1}").ToList();
                var sided     = Enumerable.Empty <string>();

                if (rbSide.Value <= 1)
                {
                    sided = segmented.Select(s => s + "_L");
                }
                if (rbSide.Value == 0 || rbSide.Value == 2)
                {
                    sided = sided.Concat(segmented.Select(s => s + "_R"));
                }
                return(sided);
            }

            var maxFingerValue = RaiseLimits.Value ? 3 * LimitRaiseAmount : 3;
            var x = callback.AddControl(new MakerSlider(category, "Scale X", 0, maxFingerValue, 1, this)
            {
                TextColor = _settingColor
            });
            var y = callback.AddControl(new MakerSlider(category, "Scale Y", 0, maxFingerValue, 1, this)
            {
                TextColor = _settingColor
            });
            var z = callback.AddControl(new MakerSlider(category, "Scale Z", 0, maxFingerValue, 1, this)
            {
                TextColor = _settingColor
            });

            void UpdateDisplay(int _)
            {
                var boneMod = _boneController.GetModifier(GetFingerBoneNames().First());
                var mod     = boneMod?.GetModifier(_boneController.CurrentCoordinate.Value);

                SetSliders(mod?.ScaleModifier ?? Vector3.one);
            }

            var isUpdatingValue = false;

            void SetSliders(Vector3 mod)
            {
                isUpdatingValue = true;
                if (x != null)
                {
                    x.Value = mod.x;
                }
                if (y != null)
                {
                    y.Value = mod.y;
                }
                if (z != null)
                {
                    z.Value = mod.z;
                }
                isUpdatingValue = false;
            }

            void PushValueToControls()
            {
                UpdateDisplay(0);
            }

            _updateActionList.Add(PushValueToControls);
            PushValueToControls();

            rbSide.ValueChanged.Subscribe(UpdateDisplay);
            rbFing.ValueChanged.Subscribe(UpdateDisplay);
            rbSegm.ValueChanged.Subscribe(UpdateDisplay);

            void PullValuesToBone(float _)
            {
                if (isUpdatingValue)
                {
                    return;
                }

                foreach (var boneName in GetFingerBoneNames())
                {
                    var bone     = _boneController.GetModifier(boneName);
                    var newValue = new Vector3(x.Value, y.Value, z.Value);
                    if (bone == null)
                    {
                        if (newValue == Vector3.one)
                        {
                            return;
                        }

                        bone = new BoneModifier(boneName);
                        _boneController.AddModifier(bone);
                    }

                    var mod = bone.GetModifier(_boneController.CurrentCoordinate.Value);
                    mod.ScaleModifier = newValue;
                }
            }

            var obs = Observer.Create <float>(PullValuesToBone);

            x?.ValueChanged.Subscribe(obs);
            y?.ValueChanged.Subscribe(obs);
            z?.ValueChanged.Subscribe(obs);
        }