private LevelTexAnim.Def OptimizeEntry(LevelTexAnim.Def animEntry)
 {
     animEntry.m_TranslationXValues = OptimizeValues(animEntry.m_TranslationXValues);
     animEntry.m_TranslationYValues = OptimizeValues(animEntry.m_TranslationYValues);
     animEntry.m_RotationValues     = OptimizeValues(animEntry.m_RotationValues);
     animEntry.m_ScaleValues        = OptimizeValues(animEntry.m_ScaleValues);
     return(animEntry);
 }
Example #2
0
        protected virtual LevelTexAnim.Def ReadTextureAnimation(XmlReader reader,
                                                                List <float> scales, List <float> rotations, List <float> translations)
        {
            LevelTexAnim.Def texAnim = new LevelTexAnim.Def();

            int scaleStart = 0, scaleLength = 0;
            int rotationStart = 0, rotationLength = 0;
            int translationStart = 0, translationLength = 0;

            while (reader.Read())
            {
                reader.MoveToContent();
                if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("MaterialName"))
                {
                    texAnim.m_MaterialName = reader.ReadElementContentAsString();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("DefaultScaleValue"))
                {
                    texAnim.m_DefaultScale = (uint)reader.ReadElementContentAsInt() / 4096f;
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("ScaleStartIndex"))
                {
                    scaleStart = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("ScaleLength"))
                {
                    scaleLength = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("RotationStartIndex"))
                {
                    rotationStart = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("RotationLength"))
                {
                    rotationLength = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("TranslationStartIndex"))
                {
                    translationStart = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.Element) && reader.LocalName.Equals("TranslationLength"))
                {
                    translationLength = reader.ReadElementContentAsInt();
                }
                else if (reader.NodeType.Equals(XmlNodeType.EndElement) && reader.LocalName.Equals("TextureAnimation"))
                {
                    texAnim.m_ScaleValues        = scales.GetRange(scaleStart, scaleLength);
                    texAnim.m_RotationValues     = rotations.GetRange(rotationStart, rotationLength);
                    texAnim.m_TranslationXValues = translations.GetRange(translationStart, translationLength);
                    return(texAnim);
                }
            }

            return(texAnim);
        }
        //reinitialize for selected material
        private void tvMaterials_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode selected = tvMaterials.SelectedNode;

            if (selected.Level == 1)
            {
                int chunkId = (int)selected.Parent.Tag;
                int matId   = (int)selected.Tag;
                m_previewTexture = m_BMD.m_ModelChunks[chunkId].m_MatGroups[matId].m_Texture.ToBitmap();
                BMD.MaterialGroup matGroup = m_BMD.m_ModelChunks[chunkId].m_MatGroups[matId];

                m_animEntry     = null;
                m_animId        = chunkId;
                m_timelineParts = (int)Math.Ceiling(m_animations[m_animId].m_NumFrames / 120f);
                m_timelinePart  = 0;
                m_timelineFrame = 0;
                if (m_entries.ContainsKey(matGroup.m_Name))
                {
                    m_animEntry = m_entries[matGroup.m_Name];
                    cbSelectProperty.SelectedIndex = 0;
                    InitializeTimeLine(AnimationProperty.TRANSLATION_X);
                    cbSelectProperty.Enabled = true;
                    if (m_animations[m_animId].m_NumFrames == 1)
                    {
                        StartAnimation();
                        btnPlay.Enabled = false;
                        btnStop.Enabled = false;
                    }
                    else
                    {
                        StopAnimation();
                        btnPlay.Enabled = true;
                        btnStop.Enabled = true;
                    }
                }
                else
                {
                    StopAnimation();
                    textureView.Refresh();
                    timelinePanel.Refresh();
                    cbSelectProperty.Enabled = false;
                }
                btnCreateAnimData.Enabled = false;
                btnDeleteAnimData.Enabled = false;
            }
            else if (selected.Level == 0)
            {
                btnCreateAnimData.Enabled = true;
                btnDeleteAnimData.Enabled = true;
            }
        }
        //Generating
        private void btnCreateNew_Click(object sender, EventArgs e)
        {
            LevelTexAnim.Def newEntry = new LevelTexAnim.Def()
            {
                m_DefaultScale       = 1,
                m_MaterialName       = tvMaterials.SelectedNode.Name,
                m_TranslationXValues = new List <float>(),
                m_TranslationYValues = new List <float>(),
                m_RotationValues     = new List <float>(),
                m_ScaleValues        = new List <float>()
            };
            newEntry.m_RotationValues.Add(0);
            newEntry.m_ScaleValues.Add(1);

            if (m_entries.ContainsKey(tvMaterials.SelectedNode.Name))
            {
                m_entries[tvMaterials.SelectedNode.Name] = newEntry;
            }
            else
            {
                m_entries.Add(tvMaterials.SelectedNode.Name, newEntry);
            }
            m_animEntry = newEntry;

            if (m_unsavedEntries[m_animId].ContainsKey(m_animEntry.m_MaterialName))
            {
                m_unsavedEntries[m_animId][m_animEntry.m_MaterialName] = m_animEntry;
            }
            else
            {
                m_unsavedEntries[m_animId].Add(m_animEntry.m_MaterialName, m_animEntry);
            }

            cbSelectProperty.Enabled       = true;
            cbSelectProperty.SelectedIndex = 0;
            InitializeTimeLine(AnimationProperty.TRANSLATION_X);

            TreeNode node = tvMaterials.SelectedNode;

            if (!node.Text.EndsWith("[ANIMATED]"))
            {
                node.Text = node.Text + "[ANIMATED]";
            }
            SetupGUIForPauseMode();
        }
        private void RefreshLbx()
        {
            if (lbxArea.SelectedIndex < 0)
            {
                return;
            }
            LevelTexAnim texAnim = m_Level.m_TexAnims[lbxArea.SelectedIndex];

            if (lbxTexAnim.SelectedIndex < 0)
            {
                ClearFormFields();
                return;
            }
            LevelTexAnim.Def texAnimDef = texAnim.m_Defs[lbxTexAnim.SelectedIndex];

            txtMaterialName.Text = texAnimDef.m_MaterialName;
            txtNumFrames.Text    = texAnim.m_NumFrames.ToString();
            lbxScaleValues.Items.Clear();
            for (int i = 0; i < texAnimDef.m_ScaleValues.Count; i++)
            {
                lbxScaleValues.Items.Add("Scale value " + i.ToString("D4"));
            }
            lbxRotationValues.Items.Clear();
            for (int i = 0; i < texAnimDef.m_RotationValues.Count; i++)
            {
                lbxRotationValues.Items.Add("Rotation value " + i.ToString("D4"));
            }
            lbxTranslationXValues.Items.Clear();
            for (int i = 0; i < texAnimDef.m_TranslationXValues.Count; i++)
            {
                lbxTranslationXValues.Items.Add("Translation X value " + i.ToString("D4"));
            }
            lbxTranslationYValues.Items.Clear();
            for (int i = 0; i < texAnimDef.m_TranslationYValues.Count; i++)
            {
                lbxTranslationYValues.Items.Add("Translation Y value " + i.ToString("D4"));
            }
            txtScaleLength.Text        = texAnimDef.m_NumScaleValues.ToString();
            txtRotationLength.Text     = texAnimDef.m_NumRotationValues.ToString();
            txtTranslationXLength.Text = texAnimDef.m_NumTranslationXValues.ToString();
            txtTranslationYLength.Text = texAnimDef.m_NumTranslationYValues.ToString();
        }
        private void btnDeleteAnim_Click(object sender, EventArgs e)
        {
            m_animEntry.m_RotationValues = new List <float>();

            if (m_unsavedEntries[m_animId].ContainsKey(m_animEntry.m_MaterialName))
            {
                m_unsavedEntries[m_animId][m_animEntry.m_MaterialName] = m_animEntry;
            }
            else
            {
                m_unsavedEntries[m_animId].Add(m_animEntry.m_MaterialName, m_animEntry);
            }

            SaveAnimation(m_animId, m_animEntry.m_MaterialName);

            m_entries.Remove(m_animEntry.m_MaterialName);
            m_animEntry = null;

            TreeNode node = tvMaterials.SelectedNode;

            node.Text = node.Text.Substring(0, node.Text.Length - 10);
            SetupGUIForPauseMode();
        }
        //---CONSTRUCTOR---
        public BetterTextureAnimationEditor(LevelEditorForm parent)
        {
            //setup GUI
            InitializeComponent();
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, textureView, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered",
                                       BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                       null, timelinePanel, new object[] { true });
            InitTimer();
            textureView.MouseWheel     += textureView_MouseWheel;
            numScaling.Tag              = 1;
            valueSettingPanel2.Location = valueSettingPanel1.Location;
            valueSettingPanel1.BringToFront();

            //set private values
            m_parent         = parent;
            m_BMD            = m_parent.m_LevelModel;
            m_previewTexture = new Bitmap(64, 64);

            m_animId     = 0;
            m_animations = new List <LevelTexAnim>();

            //load Animations
            m_unsavedEntries = new Dictionary <string, LevelTexAnim.Def> [m_BMD.m_ModelChunks.Length];
            m_entries        = new Dictionary <string, LevelTexAnim.Def>();
            int i = 0;

            foreach (BMD.ModelChunk chunk in m_BMD.m_ModelChunks)
            {
                LevelTexAnim animForArea = m_parent.m_Level.m_TexAnims[i];
                TreeNode     chunkNode   = tvMaterials.Nodes.Add(chunk.m_Name, "Area " + i + " (" + m_parent.m_Level.m_TexAnims[i].m_NumFrames + " frames)");
                chunkNode.Tag = i;

                m_unsavedEntries[i] = new Dictionary <string, LevelTexAnim.Def>();
                m_animations.Add(animForArea);
                List <LevelTexAnim.Def> newEntries = new List <LevelTexAnim.Def>();

                foreach (LevelTexAnim.Def entry in animForArea.m_Defs)
                {
                    LevelTexAnim.Def newEntry = new LevelTexAnim.Def()
                    {
                        m_DefaultScale       = entry.m_DefaultScale,
                        m_MaterialName       = entry.m_MaterialName,
                        m_TranslationXValues = new List <float>(entry.m_TranslationXValues),
                        m_TranslationYValues = new List <float>(entry.m_TranslationYValues),
                        m_RotationValues     = new List <float>(entry.m_RotationValues),
                        m_ScaleValues        = new List <float>(entry.m_ScaleValues),
                    };

                    m_entries.Add(entry.m_MaterialName, newEntry);
                }

                if (animForArea.m_NumFrames > 0)
                {
                    //populate AnimationNode
                    int i2 = 0;
                    foreach (BMD.MaterialGroup matGroup in chunk.m_MatGroups)
                    {
                        if (matGroup.m_Texture != null)
                        {
                            bool hasAnimation = false;
                            foreach (LevelTexAnim.Def entry in m_animations[i].m_Defs)
                            {
                                if (entry.m_MaterialName == matGroup.m_Name)
                                {
                                    hasAnimation = true;
                                }
                            }
                            TreeNode matGroupNode = chunkNode.Nodes.Add(matGroup.m_Name, matGroup.m_Name + (hasAnimation ? "[ANIMATED]" : ""));
                            matGroupNode.Tag = i2;
                        }
                        i2++;
                    }
                }
                i++;
            }
        }