コード例 #1
0
        public void DuplicateSelectedMotion()
        {
            if (!IsSelectedItemCopyable)
            {
                return;
            }

            MotionItemBase   latestNewItem = null;
            MotionFolderItem parentFolder  = SelectedItemParent;

            foreach (MotionItemBaseView refItem in MotionTreeView.SelectedItemSet)
            {
                if (refItem.Type == MotionItemType.Motion)
                {
                    MotionItem refMotionItem = (MotionItem)refItem.Data;
                    //Create motion
                    MotionItem newItem = EditingFile.CreateMotionEmpty(parentFolder);
                    latestNewItem = newItem;

                    //Copy points
                    foreach (MotionPoint refPoint in refMotionItem.pointList)
                    {
                        MotionPoint point = new MotionPoint();
                        newItem.AddPoint(point);

                        point.SetMainPoint(refPoint.MainPoint);
                        for (int i = 0; i < refPoint.SubPoints.Length; ++i)
                        {
                            point.SetSubPoint(i, refPoint.SubPoints[i]);
                        }
                    }

                    ((MotionItemView)DataToViewDict[newItem]).UpdatePreviewGraph();

                    //Set name
                    const string CopyPostfix = "_Copy";
                    string       name        = refItem.Data.Name;
                    for (; ;)
                    {
                        if (EditingFile.itemDict.ContainsKey(name))
                        {
                            name += CopyPostfix;
                        }
                        else
                        {
                            break;
                        }
                    }
                    newItem.SetName(name);
                }
            }
            if (latestNewItem != null)
            {
                MotionTreeView.SelectedItemSet.SetSelectedItem(DataToViewDict[latestNewItem]);
            }
        }
コード例 #2
0
ファイル: MotionFile.cs プロジェクト: Bgoon/PenMotion
        public void LoadFromJson(JObject jRoot)
        {
            //MotionTree
            JObject jRootFolder = jRoot[RootFolderName] as JObject;

            LoadItemRecursive(jRootFolder, null);


            void LoadItemRecursive(JToken jItem, MotionFolderItem parent)
            {
                JToken jType    = jItem["Type"];
                string typeText = jType != null?jType.ToString() : null;

                string name = (jItem.Parent as JProperty).Name;

                if (typeText == "Motion")
                {
                    LoadMotion(parent, jItem, name);
                }
                else
                {
                    LoadFolder(parent, jItem, name);
                }
            }

            void LoadMotion(MotionFolderItem parent, JToken jItem, string name)
            {
                JObject jData   = jItem["Data"] as JObject;
                JArray  jPoints = jData["Point"] as JArray;

                MotionItem motion = CreateMotionEmpty(parent);

                motion.SetName(name);

                foreach (JToken jPointToken in jPoints)
                {
                    JArray jPoint = jPointToken as JArray;

                    MotionPoint point = new MotionPoint(
                        PVector2.Parse(jPoint[0].ToObject <string>()),
                        PVector2.Parse(jPoint[1].ToObject <string>()),
                        PVector2.Parse(jPoint[2].ToObject <string>()));
                    motion.AddPoint(point);
                }
            }

            void LoadFolder(MotionFolderItem parent, JToken jItem, string name)
            {
                MotionFolderItem folder = CreateFolder(parent);

                if (parent == null)
                {
                    rootFolder = folder;
                }
                else
                {
                    folder.SetName(name);
                }

                JObject jItems = jItem["Items"] as JObject;

                foreach (JToken jChild in jItems.Children())
                {
                    JProperty jChildProp = jChild as JProperty;
                    LoadItemRecursive(jChildProp.Value, folder);
                }
            }
        }