public eAnim(string path, ResourceManager.LoadingType type)
        {
            frames = new List <eFrame>();
            var incidences = new List <Incidence>();

            Animation = Loader.LoadAnimation(path, Game.Instance.ResourceManager, incidences);

            foreach (var frame in Animation.getFrames())
            {
                var eframe = new eFrame();
                eframe.Image    = Game.Instance.ResourceManager.getImage(frame.getUri());
                eframe.Duration = (int)frame.getTime();
                frames.Add(eframe);
            }
        }
        public void Parse(string path_)
        {
            XmlDocument xmld = new XmlDocument();

            xmld.Load(path_);

            XmlElement element = xmld.DocumentElement;

            string tmpArgVal;

            XmlNode animationNode = element.SelectSingleNode("/animation");

            tmpArgVal = animationNode.Attributes["id"].Value;
            if (!string.IsNullOrEmpty(tmpArgVal))
            {
                animation = new Animation(tmpArgVal, factory);
                animation.getFrames().Clear();
                animation.getTransitions().Clear();
            }

            animation.setSlides("yes".Equals(animationNode.Attributes["slides"].Value));
            animation.setUseTransitions("yes".Equals(animationNode.Attributes["usetransitions"].Value));

            if (element.SelectSingleNode("documentation") != null)
            {
                animation.setDocumentation(element.SelectSingleNode("documentation").InnerText);
            }

            // FRAMES
            foreach (var frame in DOMParserUtility.DOMParse <Frame>(element.SelectNodes("/animation/frame"), animation.getImageLoaderFactory()))
            {
                animation.addFrame(frame);
            }

            // TRANSITIONS
            foreach (var transition in DOMParserUtility.DOMParse <Transition>(element.SelectNodes("/animation/transition")))
            {
                animation.getTransitions().Add(transition);
            }


            // RESOURCES
            foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("/animation/resources")))
            {
                animation.addResources(res);
            }
        }
Beispiel #3
0
        public void Init(DialogReceiverInterface e, string cutsceneFilePath)
        {
            cutscenePath = cutsceneFilePath;
            clearImg     = (Texture2D)Resources.Load("EAdventureData/img/icons/deleteContent", typeof(Texture2D));
            addTexture   = (Texture2D)Resources.Load("EAdventureData/img/icons/addNode", typeof(Texture2D));
            moveLeft     = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeLeft", typeof(Texture2D));
            moveRight    = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeRight", typeof(Texture2D));
            duplicateImg = (Texture2D)Resources.Load("EAdventureData/img/icons/duplicateNode", typeof(Texture2D));

            animInfoRect        = new Rect(0f, 0.05f * windowHeight, windowWidth, 0.15f * windowHeight);
            timelineRect        = new Rect(0f, 0.25f * windowHeight, windowWidth, 0.3f * windowHeight);
            timelineButtonsRect = new Rect(0f, 0.50f * windowHeight, windowWidth, 0.1f * windowHeight);
            frameInfoRect       = new Rect(0f, 0.65f * windowHeight, windowWidth, 0.25f * windowHeight);
            buttonRect          = new Rect(0f, 0.9f * windowHeight, windowWidth, 0.1f * windowHeight);

            noBackgroundSkin  = (GUISkin)Resources.Load("Editor/EditorNoBackgroundSkin", typeof(GUISkin));
            selectedFrameSkin = (GUISkin)Resources.Load("Editor/EditorLeftMenuItemSkinConcreteOptions", typeof(GUISkin));

            //transitionTypes = new string []{ "None" , "Fade in", "Horizontal", "Vertical"};
            Debug.Log(cutsceneFilePath);

            workingAnimation = Loader.loadAnimation(AssetsController.InputStreamCreatorEditor.getInputStreamCreator(),
                                                    cutsceneFilePath, new EditorImageLoader());

            Debug.Log(workingAnimation.getAboslutePath() + " " + workingAnimation.getFrames().Count + " " + workingAnimation.isSlides() + " " + workingAnimation.getId());
            if (workingAnimation == null)
            {
                workingAnimation = new Animation(cutsceneFilePath, 40, new EditorImageLoader());
            }

            // Initalize
            selectedFrame            = 0;
            documentationTextContent = workingAnimation.getFrames()[selectedFrame].getDocumentation();
            imagePath = workingAnimation.getFrames()[selectedFrame].getUri();
            soundPath = workingAnimation.getFrames()[selectedFrame].getSoundUri();
            animationDurationString          =
                animationDurationStringLast  = workingAnimation.getFrames()[selectedFrame].getTime().ToString();
            transitionDurationString         =
                transitionDurationStringLast = workingAnimation.getTransitions()[selectedFrame + 1].getTime().ToString();
            useTransitonFlag    = useTransitonFlagLast = workingAnimation.isUseTransitions();
            slidesAnimationFlag = slidesAnimationFlagLast = workingAnimation.isSlides();

            base.Init(e);
        }
        public static bool writeAnimation(string filename, Animation animation)
        {
            bool            dataSaved      = false;
            XmlDocument     doc            = doc = new XmlDocument();
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("animation", "SYSTEM", "animation.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);
            XmlElement mainNode = doc.CreateElement("animation");

            //mainNode.AppendChild(doc.createAttribute("id").setNodeValue(animation.getId()));
            mainNode.SetAttribute("id", animation.getId());
            mainNode.SetAttribute("usetransitions", animation.isUseTransitions() ? "yes" : "no");
            mainNode.SetAttribute("slides", animation.isSlides() ? "yes" : "no");
            XmlElement documentation = doc.CreateElement("documentation");

            if (animation.getDocumentation() != null && animation.getDocumentation().Length > 0)
            {
                documentation.InnerText = animation.getDocumentation();
            }
            mainNode.AppendChild(documentation);

            foreach (ResourcesUni resources in animation.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ANIMATION);
                doc.ImportNode(resourcesNode, true);
                mainNode.AppendChild(resourcesNode);
            }

            for (int i = 0; i < animation.getFrames().Count; i++)
            {
                mainNode.AppendChild(createTransitionElement(animation.getTransitions()[i], doc));
                mainNode.AppendChild(createFrameElement(animation.getFrames()[i], doc));
            }
            mainNode.AppendChild(createTransitionElement(animation.getEndTransition(), doc));

            doc.ImportNode(mainNode, true);
            doc.AppendChild(mainNode);
            string name = "Assets/Resources/CurrentGame/" + filename;

            if (!name.EndsWith(".eaa"))
            {
                name += ".eaa";
            }
            doc.Save(name);
            System.IO.File.Copy(name, name.Substring(0, name.LastIndexOf(".")) + ".xml", true);
            //TODO: implementation?
            //transformer = tf.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "animation.dtd");

            //try
            //{
            //    fout = new FileOutputStream(filename);
            //}
            //catch (FileNotFoundException e)
            //{
            //    fout = new FileOutputStream(Controller.getInstance().getProjectFolder() + "/" + filename);
            //}

            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();

            dataSaved = true;

            return(dataSaved);
        }
        public static bool WriteAnimation(string filename, Animation animation)
        {
            bool        dataSaved = false;
            XmlDocument doc       = new XmlDocument();

            // Declaration, encoding, version, etc
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");

            doc.AppendChild(declaration);

            // DTD
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("animation", "SYSTEM", "animation.dtd", null);

            doc.AppendChild(typeDescriptor);

            // Main animation node
            XmlElement mainNode = doc.CreateElement("animation");

            mainNode.SetAttribute("id", animation.getId());
            mainNode.SetAttribute("usetransitions", animation.isUseTransitions() ? "yes" : "no");
            mainNode.SetAttribute("slides", animation.isSlides() ? "yes" : "no");

            // Documentation node
            XmlElement documentation = doc.CreateElement("documentation");

            if (animation.getDocumentation() != null && animation.getDocumentation().Length > 0)
            {
                documentation.InnerText = animation.getDocumentation();
            }

            mainNode.AppendChild(documentation);

            // Resources in this animation
            foreach (ResourcesUni resources in animation.getResources())
            {
                // TODO update to domwriter resource
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ANIMATION);
                doc.ImportNode(resourcesNode, true);
                mainNode.AppendChild(resourcesNode);
            }

            // Frames and transitions
            // TODO update to DOMWriter
            for (int i = 0; i < animation.getFrames().Count; i++)
            {
                mainNode.AppendChild(createTransitionElement(animation.getTransitions()[i], doc));
                mainNode.AppendChild(createFrameElement(animation.getFrames()[i], doc));
            }
            mainNode.AppendChild(createTransitionElement(animation.getEndTransition(), doc));
            doc.ImportNode(mainNode, true);
            doc.AppendChild(mainNode);

            // File saving
            string name = "Assets/uAdventure/Resources/CurrentGame/" + filename;

            if (!name.EndsWith(".eaa.xml"))
            {
                name += ".eaa.xml";
            }

            try
            {
                // Save
                doc.Save(name);
                dataSaved = true;
            }
            catch (System.Exception ex)
            {
                Debug.Log("Couldn't save Animation file \"" + name + "\": " + ex.Message);
            }

            return(dataSaved);
        }
Beispiel #6
0
        protected void OnGUI()
        {
            if (workingAnimation == null)
            {
                this.Close();
                return;
            }

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    Debug.Log("Dragging (" + Event.current.type + "):" + System.String.Join("\n", DragAndDrop.paths));
                }
                break;

            case EventType.DragPerform:
                if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
                {
                    DragAndDrop.AcceptDrag();
                    foreach (var path in DragAndDrop.paths)
                    {
                        var uri   = AssetsController.AddSingleAsset(AssetsConstants.CATEGORY_ANIMATION_IMAGE, path);
                        var frame = workingAnimation.addFrame(selectedFrame, null);
                        frame.setUri(uri);
                    }
                }
                break;
            }

            EditorGUILayout.PrefixLabel(TC.get("Animation.GeneralInfo"), GUIStyle.none, titleStyle);
            EditorGUI.BeginChangeCheck();
            var documentationTextContent = EditorGUILayout.TextField(TC.get("Animation.Documentation"), workingAnimation.getDocumentation());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setDocumentation(documentationTextContent);
            }

            EditorGUI.BeginChangeCheck();
            var useTransitions = EditorGUILayout.Toggle(TC.get("Animation.UseTransitions"), workingAnimation.isUseTransitions());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setUseTransitions(useTransitions);
            }

            EditorGUI.BeginChangeCheck();
            var isSlides = EditorGUILayout.Toggle(TC.get("Animation.Slides"), workingAnimation.isSlides());

            if (EditorGUI.EndChangeCheck())
            {
                workingAnimation.setSlides(isSlides);
            }

            /*
             * Transition panel
             */
            EditorGUILayout.PrefixLabel(TC.get("Animation.Timeline"), GUIStyle.none, titleStyle);

            using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPosition, true, false, GUILayout.Height(125)))
                using (new EditorGUILayout.HorizontalScope())
                    using (new GUIUtil.SkinScope(noBackgroundSkin))
                    {
                        scrollPosition = scroll.scrollPosition;
                        for (int i = 0, frameCount = workingAnimation.getFrames().Count; i < frameCount; i++)
                        {
                            if (selectedFrame == i)
                            {
                                GUI.skin = selectedFrameSkin;
                            }

                            var frame        = workingAnimation.getFrame(i);
                            var image        = Controller.ResourceManager.getImage(frame.getUri());
                            var frameContent = new GUIContent(frame.getTime().ToString(), image);
                            if (GUILayout.Button(frameContent, GUILayout.Height(100), GUILayout.Width(80)))
                            {
                                selectedFrame = (i == selectedFrame) ? -1 : i;
                                GUI.FocusControl(null);
                            }
                            if (useTransitions && i != workingAnimation.getFrames().Count - 1)
                            {
                                var transition        = workingAnimation.getTranstionForFrame(i);
                                var transitionContent = new GUIContent(transition.getTime().ToString(), transitionTypeTexture[(int)transition.getType()]);
                                if (GUILayout.Button(transitionContent, GUILayout.Height(100), GUILayout.Width(80)))
                                {
                                    selectedFrame = (i == selectedFrame) ? -1 : i;
                                    GUI.FocusControl(null);
                                }
                            }
                            GUI.skin = noBackgroundSkin;
                        }
                    }

            /*
             * Transition button panel
             */
            using (new EditorGUILayout.HorizontalScope())
                using (new GUIUtil.SkinScope(noBackgroundSkin))
                {
                    GUILayout.FlexibleSpace();
                    using (new EditorGUI.DisabledScope(selectedFrame < 0))
                    {
                        if (GUILayout.Button(moveLeft))
                        {
                            workingAnimation.moveLeft(selectedFrame);
                            selectedFrame--;
                        }
                    }
                    using (new EditorGUI.DisabledScope(selectedFrame < 0 || workingAnimation.getFrames().Count < 2))
                    {
                        if (GUILayout.Button(clearImg))
                        {
                            workingAnimation.removeFrame(selectedFrame);
                            selectedFrame--;
                        }
                    }

                    if (GUILayout.Button(addTexture))
                    {
                        var frame = workingAnimation.addFrame(selectedFrame, null);
                        frame.setUri(SpecialAssetPaths.ASSET_EMPTY_ANIMATION + "_01.png");
                    }

                    using (new EditorGUI.DisabledScope(selectedFrame < 0))
                    {
                        if (GUILayout.Button(duplicateImg))
                        {
                            workingAnimation.addFrame(selectedFrame, workingAnimation.getFrame(selectedFrame));
                        }
                    }

                    using (new EditorGUI.DisabledScope(selectedFrame >= workingAnimation.getFrames().Count - 1))
                    {
                        if (GUILayout.Button(moveRight))
                        {
                            workingAnimation.moveRight(selectedFrame);
                            selectedFrame++;
                        }
                    }
                    GUILayout.FlexibleSpace();
                }


            using (new EditorGUI.DisabledScope(selectedFrame == -1))
            {/*
              * Frame info panel
              */
                var frame = selectedFrame >= 0 ? workingAnimation.getFrame(selectedFrame): emptyFrame;

                EditorGUILayout.PrefixLabel(TC.get("Animation.Details"), GUIStyle.none, titleStyle);

                EditorGUI.BeginChangeCheck();
                var frameDocumentation = EditorGUILayout.TextField(TC.get("Animation.Documentation"), frame.getDocumentation());
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setDocumentation(frameDocumentation);
                }

                EditorGUI.BeginChangeCheck();
                var frameDuration = System.Math.Max(0, EditorGUILayout.LongField(TC.get("Animation.Duration"), frame.getTime()));
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setTime(frameDuration);
                }

                EditorGUI.BeginChangeCheck();
                imageChooser.Path = frame.getUri();
                imageChooser.DoLayout();
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setUri(imageChooser.Path);
                }

                EditorGUI.BeginChangeCheck();
                soundChooser.Path = frame.getSoundUri();
                soundChooser.DoLayout();
                if (EditorGUI.EndChangeCheck())
                {
                    frame.setSoundUri(soundChooser.Path);
                }

                var editTransition = useTransitions && selectedFrame.InRange(-1, workingAnimation.getFrames().Count - 1);
                var transition     = editTransition ? workingAnimation.getTranstionForFrame(selectedFrame) : emptyTransition;

                using (new EditorGUI.DisabledScope(!editTransition))
                {
                    EditorGUILayout.PrefixLabel(TC.get("NextScene.Transition"), GUIStyle.none, titleStyle);
                    EditorGUI.BeginChangeCheck();
                    var transitionDuration = EditorGUILayout.LongField(TC.get("Animation.Duration"), transition.getTime());
                    if (EditorGUI.EndChangeCheck())
                    {
                        transition.setTime(transitionDuration);
                    }

                    EditorGUI.BeginChangeCheck();
                    var transitionType = EditorGUILayout.Popup(TC.get("Conditions.Type"), (int)transition.getType(), transitionTypeName);
                    if (EditorGUI.EndChangeCheck())
                    {
                        transition.setType((TransitionType)transitionType);
                    }
                }
            }

            var lastEditorRect = GUILayoutUtility.GetLastRect();


            // Ending buttons
            GUILayout.FlexibleSpace();
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("OK"))
                {
                    // If it doesnt have an extension its because its an old animation
                    if (!Path.HasExtension(cutscenePath))
                    {
                        cutscenePath = cutscenePath + ".eaa.xml";
                    }

                    AnimationWriter.WriteAnimation(cutscenePath, workingAnimation);
                    AssetDatabase.Refresh(ImportAssetOptions.Default);
                    if (reference != null)
                    {
                        reference.OnDialogOk(cutscenePath, this);
                    }
                    this.Close();
                }
                if (GUILayout.Button(TC.get("GeneralText.Cancel")))
                {
                    if (reference != null)
                    {
                        reference.OnDialogCanceled();
                    }
                    this.Close();
                }
            }

            if (Event.current.type == EventType.Repaint)
            {
                var lastButtonRect = GUILayoutUtility.GetLastRect();
                var minheight      = lastEditorRect.y + lastEditorRect.height + lastEditorRect.height + 10;
                minSize = new Vector2(400, minheight);
            }
        }