Moving doesnt work

Status
Niet open voor verdere reacties.

savant11

Gebruiker
Lid geworden
7 jan 2008
Berichten
153
Hoi allemaal,

ben bezig met een character editor. Maar ik kan de objecten die ik plaats in het main screen niet meer in het main screen verplaatsen.

Code:
//#define SCREENSHOTMODE

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using xCharEdit.Character;
using xCharEdit;
using System.IO;
using System.ComponentModel;
using System.Data;
//using System.Drawing;
//using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HelperClasses;

namespace CharacterEditor
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D arialText;
        //Text text;
        public CharDef charDef;

        List<Texture2D> headTex;
        List<Texture2D> torsoTex;
        List<Texture2D> legsTex;
        List<Texture2D> weaponTex;
        List<Texture2D> manTex;


        Texture2D nullTex;
        //Texture2D iconsTex;

        const int FACE_LEFT = 0;
        const int FACE_RIGHT = 1;

        public int selPart;
        public int selFrame = 0;
        public int selAnim = 0;
        int selKeyFrame;

        int frameScroll;
        int animScroll;
        int keyFrameScroll;

        bool mouseClick;

        MouseState mouseState;
        MouseState preState = Mouse.GetState();

        KeyboardState oldKeyState;
        private IntPtr Handle;

        bool playing;
        int curKey;
        float curFrame;

        #region Const
        const int AUX_SCRIPT = 0;
        const int AUX_TRIGS = 1;
        const int AUX_TEXTURES = 2;

        int auxMode = AUX_SCRIPT;
        int trigScroll = 0;

        const int EDITING_NONE = -1;
        const int EDITING_FRAME_NAME = 0;
        const int EDITING_PATH = 1;
        const int EDITING_ANIMATION_NAME = 2;
        const int EDITING_SCRIPT = 3;

        public const int TRIG_PISTOL_ACROSS = 0;
        public const int TRIG_PISTOL_UP = 1;
        public const int TRIG_PISTOL_DOWN = 2;
        public const int TRIG_WRENCH_UP = 3;
        public const int TRIG_WRENCH_DOWN = 4;
        public const int TRIG_WRENCH_DIAG_UP = 5;
        public const int TRIG_WRENCH_DIAG_DOWN = 6;
        public const int TRIG_WRENCH_UPPERCUT = 7;
        public const int TRIG_WRENCH_SMACKDOWN = 8;
        public const int TRIG_KICK = 9;
        public const int TRIG_ZOMBIE_HIT = 10;

        public const int TRIG_BLOOD_SQUIRT_UP = 11;
        public const int TRIG_BLOOD_SQUIRT_UP_FORWARD = 12;
        public const int TRIG_BLOOD_SQUIRT_FORWARD = 13;
        public const int TRIG_BLOOD_SQUIRT_DOWN_FORNWARD = 14;
        public const int TRIG_BLOOD_SQUIRT_DOWN = 15;
        public const int TRIG_BLOOD_SQUIRT_DOWN_BACK = 16;
        public const int TRIG_BLOOD_SQUIRT_BACK = 17;
        public const int TRIG_BLOOD_SQUIRT_UP_BACK = 18;

        public const int TRIG_BLOOD_CLOUD = 19;
        public const int TRIG_BLOOD_SPLAT = 20;

        public const int TRIG_CHAINSAW_DOWN = 21;
        public const int TRIG_CHAINSAW_UPPER = 22;
        public const int TRIG_ROCKET = 23;
        public const int TRIG_FIRE_DIE = 24;
        #endregion
        int selScriptLine = 0;

        //int editingText = EDITING_NONE;

        const bool screenShotMode = true;
        MainForm f;


        public Game1(IntPtr handle, MainForm form)
        {
            this.f = form;
            this.Handle = handle;
           // Mouse.WindowHandle = this.Handle;

            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
            System.Windows.Forms.Control.FromHandle((this.Window.Handle)).VisibleChanged += new EventHandler(Game1_VisibleChanged);
        }


        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            charDef = new CharDef();
            // Make mouse visible
            this.IsMouseVisible = false;


#if SCREENSHOTMODE
                graphics.PreferredBackBufferWidth = 1280;
                graphics.PreferredBackBufferHeight = 720;
                graphics.ApplyChanges();
#endif

            base.Initialize();
        }

       /*private bool drawButton(int x, int y, int idx, bool mouseClick)
       {
            return drawButton(x, y, idx, mouseClick, 1.0f);
        }*/

        private void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = this.Handle; ;
        }

        /*private bool drawButton(int x, int y, int idx, bool mouseClick, float scale)
        {
            bool r = false;

            Microsoft.Xna.Framework.Rectangle sRect = new Microsoft.Xna.Framework.Rectangle(32 * (idx % 8),
                32 * (idx / 8), 32, 32);
            Microsoft.Xna.Framework.Rectangle dRect = new Microsoft.Xna.Framework.Rectangle(x, y,
                (int)(32f * scale),
                (int)(32f * scale));

            if (dRect.Contains(mouseState.X, mouseState.Y))
            {
                dRect.X -= 1;
                dRect.Y -= 1;
                dRect.Width += 2;
                dRect.Height += 2;
                if (mouseClick)
                    r = true;
            }
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            //spriteBatch.Draw(iconsTex, dRect, sRect, Microsoft.Xna.Framework.Graphics.Color.White);
            spriteBatch.End();

            return r;
        }*/

        private void Game1_VisibleChanged(object sender, EventArgs e)
        {
            if (System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible == true)
                System.Windows.Forms.Control.FromHandle((this.Window.Handle)).Visible = false;
        }

        /*private void DrawCursor()
        {
            Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle();
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            Color tColor = new Color();

            tColor = Color.White;
            //if (GetCanEdit()) tColor = Color.Yellow;

            rect.X = 0;
            rect.Y = 0;
            rect.Width = 32;
            rect.Height = 32;

            //spriteBatch.Draw(iconsTex, new Vector2((float)mouseState.X,
                //(float)mouseState.Y), rect,
               // tColor, 0.0f, new Vector2(0, 0), 1.0f, SpriteEffects.None, 0.0f);

            spriteBatch.End();
        }*/

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            arialText = Content.Load<Texture2D>(@"gfx/arial");
            //iconsTex = Content.Load<Texture2D>(@"gfx/icons");
            nullTex = Content.Load<Texture2D>(@"gfx/1x1");
            //text = new Text(arialText, spriteBatch);

            manTex = new List<Texture2D>();
            legsTex = new List<Texture2D>();
            torsoTex = new List<Texture2D>();
            headTex = new List<Texture2D>();
            weaponTex = new List<Texture2D>();

            // laden data



            for (int i = 0; i < (Directory.GetFiles(@"Content/gfx/", "legs*")).Length; i++)
                legsTex.Add(Content.Load<Texture2D>(@"gfx/legs" + (i + 1).ToString()));

            for (int i = 0; i < (Directory.GetFiles(@"Content/gfx/", "torso*")).Length; i++)
                torsoTex.Add(Content.Load<Texture2D>(@"gfx/torso" + (i + 1).ToString()));

            for (int i = 0; i < (Directory.GetFiles(@"Content/gfx/", "head*")).Length; i++)
                headTex.Add(Content.Load<Texture2D>(@"gfx/head" + (i + 1).ToString()));

            for (int i = 0; i < (Directory.GetFiles(@"Content/gfx/", "weapon*")).Length; i++)
                weaponTex.Add(Content.Load<Texture2D>(@"gfx/weapon" + (i + 1).ToString()));

            //Own content
            //for (int i = 0; i < manTex.Length; i++)
            // manTex[i] = Content.Load<Texture2D>(@"gfx/man" + (i + 1).ToString());

            //for (int i = 0; i < legsTex.Length; i++)
            // legsTex[i] = Content.Load<Texture2D>(@"gfx/objects" + (i + 1).ToString());


            //End content

            // TODO: use this.Content to load your game content here
            drawPallete();
            //DrawPartList();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
           // if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
               // this.Exit();
            //Zorgt voor actual annimating.
        // UpdateKeys();
            //KeyboardState keys = Keyboard.Equals();
            //if (Keys.Escape) Exit();

            Animation animation = charDef.GetAnimation(selAnim);
            KeyFrame keyframe = animation.GetKeyFrame(curKey);

            if (playing)
            {
                curFrame += (float)gameTime.ElapsedGameTime.TotalSeconds * 30.0f;

                if (curFrame > (float)keyframe.duration)
                {
                    curFrame -= (float)keyframe.duration;
                    curKey++;
                    keyframe = animation.GetKeyFrame(curKey);

                    if (curKey >=
                        animation.getKeyFrameArray().Count)
                        curKey = 0;
                }
            }
            else
                curKey = selKeyFrame;

            /*if (keyframe.frameRef < 0)
                curKey = 0;*/


            mouseState = Mouse.GetState();


            if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                if (preState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {

                }
                else
                {//Function for moving, scaling, rotating the objects.
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        if ((f.FrameList.SelectedIndex >= 0) && 
                            charDef.GetAnimation(f.AnimationBox.SelectedIndex).GetKeyFrame
                            (f.FrameList.SelectedIndex).frameRef.partList.Count > selPart)

                        if (charDef.GetAnimation
                            (f.AnimationBox.SelectedIndex).GetKeyFrame
                            (f.FrameList.SelectedIndex).frameRef.partList.Count > selPart)
                        {
                            try
                            {
                                CanEdit();

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "\n");
                            
                            }

                            //if (f == null)
                                //MessageBox.Show("Is null");
                            //new CharDef();
                            charDef.GetAnimation(f.AnimationBox.SelectedIndex).GetKeyFrame(f.FrameList.SelectedIndex).frameRef.partList[selPart].location +=
                                charDef.GetFrame(selFrame).GetPart(selPart).location +=
                                new Vector2((float)xM / 2.0f, (float)yM / 2.0f);//Speed where u can move the objects
                        }
                    }
                }
            }
            else
            {
                if (preState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    mouseClick = true;
                }
            }

            if (mouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                if (preState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int yM = mouseState.Y - preState.Y;
                        charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.GetPart(selPart).rotation +=
                        //charDef.GetFrame(selFrame).GetPart(selPart).rotation +=
                            (float)yM / 100.0f;
                    }
                }
            }

            if (mouseState.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                if (preState.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.GetPart(selPart).scaling +=
                            new Vector2((float)xM * 0.01f, (float)yM * 0.01f);
                    }
                }
            }//End funtion for moving the objects.

            preState = mouseState;

            base.Update(gameTime);
        }//End method

/*        private void UpdateKeys()
        {
            KeyboardState keystate = new KeyboardState();

            keystate = Keyboard.GetState();

            Microsoft.Xna.Framework.Input.Keys[] currentkeys = keystate.GetPressedKeys();
            Microsoft.Xna.Framework.Input.Keys[] lastkeys = oldKeyState.GetPressedKeys();
            bool found = false;

            for (int i = 0; i < currentkeys.Length; i++)
            {
                found = false;

                for (int y = 0; y < lastkeys.Length; y++)
                {
                    if (currentkeys[i] == lastkeys[y]) found = true;
                }
                if (found == false)
                {
                    PressKey(currentkeys[i]);
                }
            }

            oldKeyState = keystate;
        }

        private void PressKey(Microsoft.Xna.Framework.Input.Keys key)
        {
#if SCREENSHOTMODE
            if (key == Keys.End)
                return;
#endif
            String t = "";
            switch (editingText)
            {
                case EDITING_FRAME_NAME:
                    t = charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.name;
                    break;
                case EDITING_ANIMATION_NAME:
                    t = charDef.GetAnimation(selAnim).name;
                    break;
                case EDITING_PATH:
                    t = charDef.path;
                    break;
                case EDITING_SCRIPT:
                    t = charDef.GetAnimation(selAnim).GetKeyFrame(selKeyFrame).GetScript(selScriptLine);
                    break;
                default:
                    return;
            }

            if (key == Microsoft.Xna.Framework.Input.Keys.Back)
            {
                if (t.Length > 0) t = t.Substring(0, t.Length - 1);
            }
            else if (key == Microsoft.Xna.Framework.Input.Keys.Enter)
            {
                editingText = EDITING_NONE;
            }
            else
            {
                t = (t + (char)key).ToLower();
            }

            switch (editingText)
            {
                case EDITING_FRAME_NAME:
                    charDef.GetFrame(selFrame).name = t;
                    break;
                case EDITING_ANIMATION_NAME:
                    charDef.GetAnimation(selAnim).name = t;
                    break;
                case EDITING_PATH:
                    charDef.path = t;
                    break;
                case EDITING_SCRIPT:
                    charDef.GetAnimation(selAnim).GetKeyFrame(selKeyFrame).SetScript(selScriptLine, t);
                    break;
            }
        }*/

        //Begin method DrawCharacter
        private void DrawCharacter(Vector2 loc, float scale, int face, Frame frame,
            bool preview, float alpha)
        {
            Rectangle sRect = new Rectangle();
            //Frame frame = charDef.GetFrame(frameIdx);

            if (frame != null)
            {


                for (int i = 0; i < frame.GetPartArray().Count; i++)
                {
                    Part part = frame.GetPart(i);
                    if (part.idx > -1)
                    {

                        sRect.X = ((part.idx % 64) % 5) * 64; //100;//64;//%5
                        sRect.Y = ((part.idx % 64) / 5) * 64;//100;//64;// /5                    
                        sRect.Width = 80; //80; //64; //Zorgt voor grote van object(X-as) die je kan selecteren!!
                        sRect.Height = 75;//75;//64; //Zorgt voor grote van object(Y-as) die je kan selecteren!!
                        if (part.idx >= 192)
                        {
                            sRect.X = ((part.idx % 64) % 4) * 100;//80;
                            sRect.Y = ((part.idx % 64) / 4) * 100;//64;
                            sRect.Width = 80;
                        }

                        float rotation = part.rotation;


                        Vector2 location = part.location * scale + loc;
                        Vector2 scaling = part.scaling * scale;
                        if (part.idx >= 128) scaling *= 1.35f;//1.35f;//128

                        if (face == FACE_LEFT)
                        {
                            rotation = -rotation;
                            location.X -= part.location.X * scale * 2.0f;
                        }

                        if (part.idx >= 1000 && alpha >= 1f)
                        {
                            //spriteBatch.End();

                            //text.Color = Color.Lime;
                            if (preview)
                            {
                                //text.Size = 0.45f;
                                //text.DrawText((int)location.X,
                                    //(int)location.Y,
                                   // "*");
                            }
                            else
                            {
                                //text.Size = 1f;
                                //text.DrawText((int)location.X,
                                    //(int)location.Y,
                                   // "*" + GetTrigName(part.idx - 1000));
                            }
                            spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
                        }
                        else
                        {
                            //Texture2D texture;//THis function is for the sprite maps, like: head1, head2..etc

                            Texture2D texture = null;


                            int t = part.idx / 128;
                            switch (t)
                            {
                                case 0:
                                    texture = headTex[charDef.headIdx];
                                    break;
                                case 1:
                                    texture = torsoTex[charDef.torsoIdx];
                                    break;
                                case 2:
                                    texture = legsTex[charDef.legsIdx];
                                    break;
                                case 3:
                                    texture = weaponTex[charDef.weaponIdx];
                                    break;
                                default:
                                    texture = null;
                                    break;
                            }//End function spriteMap!!
                            //If u clcik on the objet the color of the object will change
                            Color color = new Color(new
                                Vector4(1.0f, 1.0f, 1.0f, alpha));
                            if (!preview && selPart == i) color = new
                                Color(new Vector4(1.0f, 1.0f, 1.0f, alpha));

                            bool flip = false;

                            if ((face == FACE_RIGHT && part.flip == 0) ||
                                (face == FACE_LEFT && part.flip == 1)) flip = true;

                            if (texture != null)
                            {

                            }

                            spriteBatch.Begin();
                            spriteBatch.Draw(texture, location, sRect,
                                    color, rotation, new Vector2(
                                    (float)sRect.Width / 2f, 32.0f),
                                    scaling, (flip ?
                                    SpriteEffects.None : SpriteEffects.FlipHorizontally),
                                    1.0f);

                        }

                    }
                    spriteBatch.End();
                }//End fucntion

            }
        }
        



/*        private void SwapParts(int idx1, int idx2)
        {
            if (idx1 < 0 || idx2 < 0 ||
                idx1 >= charDef.GetFrame(selFrame).GetPartArray().Count ||
                idx2 >= charDef.GetFrame(selFrame).GetPartArray().Count)
                return;

            Part t = new Part();
            Part i = charDef.GetFrame(selFrame).GetPart(idx1);
            Part j = charDef.GetFrame(selFrame).GetPart(idx2);

            t.idx = i.idx;
            t.location = i.location;
            t.rotation = i.rotation;
            t.scaling = i.scaling;
            t.flip = i.flip;

            i.idx = j.idx;
            i.location = j.location;
            i.rotation = j.rotation;
            i.scaling = j.scaling;
            i.flip = j.flip;

            j.idx = t.idx;
            j.location = t.location;
            j.rotation = t.rotation;
            j.scaling = t.scaling;
            j.flip = t.flip;
        }*/

        /*private void CopyFrame(int src, int dest)
        {

            Frame keySrc = charDef.GetFrame(src);
            Frame keyDest = charDef.GetFrame(dest);

            keyDest.name = keySrc.name;
            for (int i = 0; i < keyDest.GetPartArray().Count; i++)
            {
                Part srcPart = keySrc.GetPart(i);
                Part destPart = keyDest.GetPart(i);

                destPart.idx = srcPart.idx;
                destPart.location = new Vector2(srcPart.location.X,
                    srcPart.location.Y);
                destPart.rotation = srcPart.rotation;
                destPart.scaling = new Vector2(srcPart.scaling.X,
                    srcPart.scaling.Y);
                destPart.flip = srcPart.flip;

            }
        }*/

        private bool CanEdit()
        {
            if (mouseState.X > 0 && mouseState.Y > 0 && mouseState.X <
                f.panel1.Height && mouseState.Y < f.panel1.Width)
                return true;
            else
                return false;
        }
        //Ouput Text messages 
        private string GetTrigName(int idx)
        {
            switch (idx)
            {

                case TRIG_WRENCH_UP:
                    return "wrench up";
                case TRIG_WRENCH_UPPERCUT:
                    return "wrench uppercut";
                case TRIG_KICK:
                    return "kick";
                case TRIG_ZOMBIE_HIT:
                    return "zombie hit";

                case TRIG_BLOOD_SQUIRT_UP:
                    return "squirt up";
                case TRIG_BLOOD_SQUIRT_UP_FORWARD:
                    return "squirt upforward";
                case TRIG_BLOOD_SQUIRT_FORWARD:
                    return "squirt forward";
                case TRIG_BLOOD_SQUIRT_DOWN_FORNWARD:
                    return "squirt downforward";
                case TRIG_BLOOD_SQUIRT_DOWN:
                    return "squirt down";
                case TRIG_BLOOD_SQUIRT_DOWN_BACK:
                    return "squirt downback";
                case TRIG_BLOOD_SQUIRT_BACK:
                    return "squirt back";
                case TRIG_BLOOD_SQUIRT_UP_BACK:
                    return "squirt upback";

                case TRIG_BLOOD_CLOUD:
                    return "blood cloud";
                case TRIG_BLOOD_SPLAT:
                    return "blood splat";

                case TRIG_CHAINSAW_DOWN:
                    return "chain down";
                case TRIG_CHAINSAW_UPPER:
                    return "chain up";
                case TRIG_ROCKET:
                    return "rocket";
                case TRIG_FIRE_DIE:
                    return "firedie";
            }
            return "";
        }//End method

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            //GraphicsDevice.Clear(Color.CornflowerBlue);//This colors the background Blue!!

           // spriteBatch.Begin();

            //spriteBatch.End();

            //base.Draw(gameTime);

            //if (mouseClick)
              //  editingText = EDITING_NONE;

           
            Frame currentFrame = charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef;
            if (selFrame > 0)
                DrawCharacter(new Vector2(400f, 450f), 2f, FACE_RIGHT,
                   currentFrame, false, 0.2f);

            if (selFrame < charDef.GetAnimation(selAnim).KeyFrame.Count)
                DrawCharacter(new Vector2(400f, 450f), 2f, FACE_RIGHT,
                    currentFrame, false, 0.2f);

            DrawCharacter(new Vector2(400f, 450f), 2f, FACE_RIGHT, currentFrame,
                false, 1.0f);

                
            
            mouseClick = false;
            base.Draw(gameTime);
        }//End method

        //This is to draw the objects in the pallete
        #region Draw item pallete to screen

        public void drawPallete(/*String[] names*/)
        {
            for (int j = 0; j < 4; j++)
            {
                //int i = 0;
                ImageList im = new ImageList();
                List<Texture2D> currentList = null;

                switch (j)
                {
                    case 0:
                        currentList = headTex;
                        f.ItemTabControl.TabPages.Add("Heads");
                        break;
                    case 1:
                        currentList = torsoTex;
                        f.ItemTabControl.TabPages.Add("Torso");
                        break;
                    case 2:
                        currentList = legsTex;
                        f.ItemTabControl.TabPages.Add("Legs");
                        break;
                    default:
                        currentList = weaponTex;
                        f.ItemTabControl.TabPages.Add("Weapons");
                        break;
                }

                FlowLayoutPanel l = new FlowLayoutPanel();
                l.AutoScroll = true;//Here u can scroll

                //paletteView.Add(l);
                //f.ItemTabControl.TabPages


                f.ItemTabControl.TabPages[j].Controls.Add(l);
                l.Dock = DockStyle.Fill;

                foreach (Texture2D sd in currentList)
                {

                    if (sd == null)
                        continue;

                    for (int i = 0; i < 25; i++)
                    {
                        Rectangle sRect = new Rectangle((i % 5) * 64,
                            (i / 5) * 64, 64, 64);
                        Button b = new Button();
                        System.Drawing.Bitmap bmp = GetButtonImage(sRect, sd);
                        b.Image = resizeImage(bmp, new System.Drawing.Size(64, 64));

                        b.Padding = new Padding(0);

                        b.Size = new System.Drawing.Size(64, 64);
                        b.Tag = i;
                        // click event
                        b.Click += new EventHandler(AddCharSegment);
                        //
                        l.Controls.Add(b);
                        //i++;
                    }
                }
            }
        }

        private System.Drawing.Bitmap GetButtonImage(Microsoft.Xna.Framework.Rectangle tile, Microsoft.Xna.Framework.Graphics.Texture2D tileTex)
        {
            int[] data = new int[tile.Width * tile.Height];
            tileTex.GetData<int>(0, tile, data, 0, tile.Width * tile.Height);
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(tile.Width, tile.Height);
            for (int x = 0; x < tile.Width; x++)
            {
                for (int y = 0; y < tile.Height; y++)
                {
                    System.Drawing.Color bitmapColor = System.Drawing.Color.FromArgb(data[y * tile.Width + x]);
                    bitmap.SetPixel(x, y, bitmapColor);
                }
            }
            return bitmap;
        }

        private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, System.Drawing.Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            System.Drawing.Bitmap b = new System.Drawing.Bitmap(destWidth, destHeight);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage((System.Drawing.Image)b);

            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (System.Drawing.Image)b;
        }

        private void AddCharSegment(object sender, EventArgs e)
        {
            int index = (int)((Button)sender).Tag;
            int selFrame = 0;
            charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.partList.Add(new Part(index + 64 * 1));
            //charDef.frame[selFrame].partList.Add(new Part(index + 64 * 1));
            //charDef.frame[selFrame].partList[selPart].idx = 
            //DrawPartList();
            //charDef.SetFrame(index
        }
        #endregion

        
        
        public void DrawPartList()
        {
            
            f.FrameList.Items.Clear();
            for (int i = 0; i < charDef.GetFrame(selFrame).GetPartArray().Count; i++)
            {

                String line = "-";
                int idx = charDef.GetFrame(selFrame).GetPart(i).idx;
                if (idx < 0)
                    line = "-";
                else if (idx < 64)
                    line = "head" + idx.ToString();
                else if (idx < 74)
                    line = "torso" + idx.ToString();
                else if (idx < 128)
                    line = "arms" + idx.ToString();
                else if (idx < 192)
                    line = "legs" + idx.ToString();
                else if (idx < 1000)
                    line = "weapon" + idx.ToString();
                else
                    line = GetTrigName(idx - 1000);
                f.FrameList.Items.Add(line);
            }
              
        }//End method
          
    }
}

En dit is de methode voor moving:


Code:
{//Function for moving, scaling, rotating the objects.
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        if ((f.FrameList.SelectedIndex >= 0) && 
                            charDef.GetAnimation(f.AnimationBox.SelectedIndex).GetKeyFrame
                            (f.FrameList.SelectedIndex).frameRef.partList.Count > selPart)

                        if (charDef.GetAnimation
                            (f.AnimationBox.SelectedIndex).GetKeyFrame
                            (f.FrameList.SelectedIndex).frameRef.partList.Count > selPart)
                        {
                            try
                            {
                                CanEdit();

                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "\n");
                            
                            }

                            //if (f == null)
                                //MessageBox.Show("Is null");
                            //new CharDef();
                            charDef.GetAnimation(f.AnimationBox.SelectedIndex).GetKeyFrame(f.FrameList.SelectedIndex).frameRef.partList[selPart].location +=
                                charDef.GetFrame(selFrame).GetPart(selPart).location +=
                                new Vector2((float)xM / 2.0f, (float)yM / 2.0f);//Speed where u can move the objects
                        }
                    }
                }
            }
            else
            {
                if (preState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    mouseClick = true;
                }
            }

            if (mouseState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                if (preState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int yM = mouseState.Y - preState.Y;
                        charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.GetPart(selPart).rotation +=
                        //charDef.GetFrame(selFrame).GetPart(selPart).rotation +=
                            (float)yM / 100.0f;
                    }
                }
            }

            if (mouseState.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                if (preState.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if (CanEdit())
                    {
                        int xM = mouseState.X - preState.X;
                        int yM = mouseState.Y - preState.Y;

                        charDef.GetAnimation(selAnim).KeyFrame[selFrame].frameRef.GetPart(selPart).scaling +=
                            new Vector2((float)xM * 0.01f, (float)yM * 0.01f);
                    }
                }
            }//End funtion for moving the objects.

Alsvast enorm bedankt.
 
Wat ik vaak doe al dit mis gaat, of bijna altijd. Is de contole en de knoppen er bij plakken, die copieer ik gewoon uit die SDK. Voor DX gebruik ik al die SDK controles in die DX viewer, daar test ik ook de caracter animation van die rig model van mijn caracter mee, is die conversie vanuit Maya wel goed gegaan enzo.

Als de caracter dus goed werkt, texture, animation shaders etc, converteer ik ze pas naar een game engine, of waar ik die DX caracters maar voor nodig heb.
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan