public Vehicle(Texture2D texture, V2DInstance instance) : base(texture, instance)
 {
     this.restitution    = .30f;
     this.friction       = 0f;
     this.angularDamping = 3;
     this.linearDamping  = .1f;
 }
Exemple #2
0
        private V2DInstance GetV2DInstance(Instance2D inst)
        {
            V2DInstance result = new V2DInstance();

            result.DefinitionName = inst.DefinitionName;
            result.Density        = inst.Density;
            result.Depth          = inst.Depth;
            result.Friction       = inst.Friction;
            result.InstanceName   = inst.InstanceName;
            //result.Joints = inst.Joints;
            DDW.Vex.Matrix m = inst.Matrix;
            //result.Matrix = new V2DMatrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, m.TranslateX, m.TranslateY);
            result.Restitution = inst.Restitution;
            result.StartFrame  = inst.StartFrame;
            result.EndFrame    = inst.TotalFrames + inst.StartFrame;
            result.Visible     = inst.Visible;

            result.Alpha      = inst.Alpha;
            result.X          = inst.X;
            result.Y          = inst.Y;
            result.Rotation   = inst.Rotation;
            result.ScaleX     = inst.ScaleX;
            result.ScaleY     = inst.ScaleY;
            result.Transforms = TransformsConversion(result, inst.Transforms);

            return(result);

            //Dictionary<string, string> dict = null;
            //if (v2d.codeData.ContainsKey(inst.InstanceName))
            //{
            //    dict = v2d.codeData[inst.InstanceName];
            //}
            //return inst.GetV2DInstance(dict);
        }
Exemple #3
0
        public DisplayObject(Texture2D texture, V2DInstance inst)
        {
            id = idCounter++;

            Texture            = texture;
            instanceDefinition = inst;

            this.X = (int)inst.X;
            this.Y = (int)inst.Y;

            ResetInstanceProperties();
        }
Exemple #4
0
 public TextBox(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
     if (inst.Definition is V2DText)
     {
         sb = new StringBuilder();
         V2DText t = (V2DText)inst.Definition;
         textAtoms = new List <TextAtom>();
         for (int i = 0; i < t.TextRuns.Count; i++)
         {
             TextAtom ta = new TextAtom(this.X, this.Y, t.TextRuns[i]);
             textAtoms.Add(ta);
             sb.Append(ta.Text);
         }
         RecreateTextRuns();
     }
 }
Exemple #5
0
        public V2DGenericTransform[] TransformsConversion(V2DInstance obj, List <Transform> trs)
        {
            V2DGenericTransform[] result = new V2DGenericTransform[trs.Count];
            if (trs.Count > 0)
            {
                MatrixComponents firstMc    = trs[0].Matrix.GetMatrixComponents();
                float            firstAlpha = trs[0].Alpha;
                obj.X        += firstMc.TranslateX;
                obj.Y        += firstMc.TranslateY;
                obj.Rotation += (float)(firstMc.Rotation * Math.PI / 180);
                obj.ScaleX   *= firstMc.ScaleX;
                obj.ScaleY   *= firstMc.ScaleY;
                obj.Alpha    *= firstAlpha;

                for (int i = 0; i < trs.Count; i++)
                {
                    Transform tin = trs[i];

                    uint                sf   = (uint)Math.Round(tin.StartTime / (1000d / v2dWorld.FrameRate));
                    uint                ef   = (uint)Math.Round(tin.EndTime / (1000d / v2dWorld.FrameRate)) - 1;
                    MatrixComponents    mc   = tin.Matrix.GetMatrixComponents();
                    V2DGenericTransform tout = new V2DGenericTransform(
                        sf,
                        ef,
                        mc.ScaleX / firstMc.ScaleX,
                        mc.ScaleY / firstMc.ScaleY,
                        (float)(mc.Rotation * Math.PI / 180) - (float)(firstMc.Rotation * Math.PI / 180),
                        mc.TranslateX - firstMc.TranslateX,
                        mc.TranslateY - firstMc.TranslateY,
                        tin.Alpha / firstAlpha);

                    //V2DTransform tout = new V2DTransform(
                    //    (uint)Math.Floor(tin.StartTime / (1000d / v2dWorld.FrameRate)),
                    //    (uint)Math.Floor(tin.EndTime / (1000d / v2dWorld.FrameRate)),
                    //    new V2DMatrix(  tin.Matrix.ScaleX, tin.Matrix.Rotate0, tin.Matrix.Rotate1, tin.Matrix.ScaleX,
                    //                    tin.Matrix.TranslateX, tin.Matrix.TranslateY),
                    //    tin.Alpha);

                    tout.IsTweening = tin.IsTweening;

                    result[i] = tout;
                }
            }
            return(result);
        }
Exemple #6
0
        public void Init()
        {
            V2DDefinition ground = new V2DDefinition();

            ground.Name       = V2D.ROOT_NAME;
            ground.FrameCount = 1;

            V2DInstance inst = new V2DInstance();

            inst.DefinitionName = ground.Name;
            inst.InstanceName   = V2D.ROOT_NAME;
            inst.Definition     = ground;
            inst.Transform      = Matrix.Identitiy.GetDrawing2DMatrix().Elements;
            inst.TotalFrames    = (int)curVo.GetFrameFromMilliseconds(curVo.Root.Duration);

            parentStack.Push(inst);
            root = inst;
        }
Exemple #7
0
        private V2DInstance CreateInstance(Instance inst, V2DDefinition def)
        {
            V2DInstance result = new V2DInstance();

            result.InstanceName   = inst.Name;
            result.Definition     = def;
            result.DefinitionName = def.Name;
            result.Depth          = (int)inst.Depth;
            result.StartFrame     = curVo.GetFrameFromMillisecondsGetFrame(inst.StartTime);
            result.TotalFrames    = curVo.GetFrameFromMillisecondsGetFrame(inst.EndTime - inst.StartTime);
            Matrix m = inst.Transformations[0].Matrix;

            result.UserData = m;
            AddSymbolImage(inst, def);

            curDef.Instances.Add(result);
            return(result);
        }
        public V2DInstance CreateInstanceDefinition(string definitionName, string instName)
        {
            V2DInstance result = null;

            V2DDefinition def = screen.v2dWorld.GetDefinitionByName(definitionName);

            if (def != null)
            {
                result                = new V2DInstance();
                result.Definition     = def;
                result.DefinitionName = def.Name;
                result.InstanceName   = instName;
                result.Transforms     = new V2DGenericTransform[1];
                result.Transforms[0]  = new V2DGenericTransform(0, 0, 1, 1, 0, 0, 0, 1);
                result.Visible        = true;
            }

            return(result);
        }
Exemple #9
0
        private bool IsPointInside(V2DInstance inst, Point p)
        {
            bool result = false;

            System.Drawing.Drawing2D.Matrix m = ((Matrix)inst.UserData).GetDrawing2DMatrix();
            m.Invert();
            System.Drawing.PointF[] p2 = new System.Drawing.PointF[] { new System.Drawing.PointF(p.X, p.Y) };
            m.TransformPoints(p2);
            Point tp = new Point(p2[0].X, p2[0].Y);

            for (int i = 0; i < inst.Definition.V2DShapes.Count; i++)
            {
                if (Shapes[i].IsPointInside(tp))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
        public virtual DisplayObject AddInstance(V2DInstance inst, DisplayObjectContainer parent)
        {
            DisplayObject result = null;

            if (inst != null)
            {
                V2DDefinition def = screen.v2dWorld.GetDefinitionByName(inst.DefinitionName);
                if (def != null)
                {
                    Texture2D namedTexture = screen.GetTexture(def.LinkageName);
                    inst.Definition = def;

                    if (inst.InstanceName == V2DGame.currentRootName)
                    {
                        result = this;
                    }
                    else
                    {
                        result = parent.SetFieldWithReflection(namedTexture, inst);

                        if (result == null)
                        {
                            result = screen.CreateDefaultObject(namedTexture, inst);
                        }
                        parent.AddChild(result);
                    }
                }
                else
                {
                    result = parent.SetFieldWithReflection(texture, inst);
                    if (result == null)
                    {
                        result = screen.CreateDefaultObject(texture, inst);
                    }
                    parent.AddChild(result);
                }
            }

            return(result);
        }
Exemple #11
0
        private V2DInstance FindRootInstance(V2DInstance inst, string rootName)
        {
            // look through higher level instances first
            V2DInstance result = null;

            if (inst.InstanceName == rootName)
            {
                result = inst;
            }
            else if (inst.Definition != null)
            {
                for (int i = 0; i < inst.Definition.Instances.Count; i++)
                {
                    if (inst.Definition.Instances[i].InstanceName == rootName)
                    {
                        result = inst.Definition.Instances[i];
                        break;
                    }
                }
            }

            if (result == null && inst.Definition != null)
            {
                for (int i = 0; i < inst.Definition.Instances.Count; i++)
                {
                    result = FindRootInstance(inst.Definition.Instances[i], rootName);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            if (result == null)
            {
                throw new Exception("Could not find root instance: " + rootName + " in " + inst.InstanceName + ".");
            }
            return(result);
        }
        public DisplayObject CreateInstanceAt(string definitionName, string instanceName, float x, float y, float rot, int depth)
        {
            DisplayObject result = null;

            if (definitionName == null || definitionName == "")
            {
                V2DInstance v2dInst = new V2DInstance();
                v2dInst.Depth         = depth;
                v2dInst.InstanceName  = instanceName;
                v2dInst.X             = x;
                v2dInst.Y             = y;
                v2dInst.Rotation      = rot;
                v2dInst.Transforms    = new V2DGenericTransform[1];
                v2dInst.Transforms[0] = new V2DGenericTransform(0, 0, 1, 1, 0, 0, 0, 1); // image
                v2dInst.Visible       = true;
                result = AddInstance(v2dInst, this);
            }
            else
            {
                V2DDefinition def = screen.v2dWorld.GetDefinitionByName(definitionName);
                if (def != null)
                {
                    V2DInstance v2dInst = new V2DInstance();
                    v2dInst.Depth          = depth;
                    v2dInst.Definition     = def;
                    v2dInst.DefinitionName = def.Name;
                    v2dInst.InstanceName   = instanceName;
                    v2dInst.X             = x;         // body
                    v2dInst.Y             = y;
                    v2dInst.Rotation      = rot;
                    v2dInst.Transforms    = new V2DGenericTransform[1];
                    v2dInst.Transforms[0] = new V2DGenericTransform(0, 0, 1, 1, 0, 0, 0, 1); // image
                    v2dInst.Visible       = true;

                    result = AddInstance(v2dInst, this);
                }
            }
            return(result);
        }
Exemple #13
0
 public ExitPanel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
 public SevenSegmentDisplay(Texture2D texture, V2DInstance instance) : base(texture, instance)
 {
 }
Exemple #15
0
 public InstructionsPanel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
 public LaserParticleEffect(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
Exemple #17
0
 public VideoPanel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
        public virtual DisplayObject SetFieldWithReflection(Texture2D texture, V2DInstance inst)
        {
            DisplayObject result = null;

            Type   t        = this.GetType();
            string instName = inst.InstanceName;
            int    index    = -1;

            Match m = lastDigits.Match(instName);

            if (m.Groups.Count > 2 && t.GetField(instName) == null)
            {
                instName = m.Groups[1].Value;
                index    = int.Parse(m.Groups[2].Value, System.Globalization.NumberStyles.None);
            }

            FieldInfo fi = t.GetField(instName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);

            if (fi != null)
            {
                Type ft = fi.FieldType;

                if (ft.BaseType.Name == typeof(V2DRuntime.Components.Group <>).Name &&                // IsSubclassOf etc doesn't work on generics?
                    ft.BaseType.Namespace == typeof(V2DRuntime.Components.Group <>).Namespace)
                {
                    // eg ButtonTabGroup
                    if (fi.GetValue(this) == null)
                    {
                        ConstructorInfo ci = ft.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) });
                        result = (DisplayObject)ci.Invoke(new object[] { texture, inst });
                        fi.SetValue(this, result);
                    }
                }
                else if (ft.IsArray)
                {
                    object array       = fi.GetValue(this);
                    Type   elementType = ft.GetElementType();
                    if (array == null)
                    {
                        int arrayLength = GetArrayLength(instName);
                        array = Array.CreateInstance(elementType, arrayLength);
                        fi.SetValue(this, array);
                    }
                    // add element
                    ConstructorInfo elementCtor = elementType.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) });
                    result = (DisplayObject)elementCtor.Invoke(new object[] { texture, inst });

                    MethodInfo mi = array.GetType().GetMethod("SetValue", new Type[] { elementType, index.GetType() });
                    mi.Invoke(array, new object[] { result, index });
                }
                else if (typeof(System.Collections.ICollection).IsAssignableFrom(ft))
                {
                    Type[] genTypes = ft.GetGenericArguments();
                    if (genTypes.Length == 1)                     // only support single type generics (eg List<>) for now
                    {
                        Type   gt         = genTypes[0];
                        object collection = fi.GetValue(this);
                        if (collection == null)                         // ensure list created
                        {
                            ConstructorInfo ci = ft.GetConstructor(new Type[] { });
                            collection = ci.Invoke(new object[] { });
                            fi.SetValue(this, collection);
                        }

                        // add element
                        ConstructorInfo elementCtor = gt.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) });
                        result = (DisplayObject)elementCtor.Invoke(new object[] { texture, inst });

                        PropertyInfo cm  = collection.GetType().GetProperty("Count");
                        int          cnt = (int)cm.GetValue(collection, new object[] { });

                        // pad with nulls if needs to skip indexes (order is based on flash depth, not index)
                        while (index > cnt)
                        {
                            MethodInfo mia = collection.GetType().GetMethod("Add");
                            mia.Invoke(collection, new object[] { null });
                            cnt = (int)cm.GetValue(collection, new object[] { });
                        }

                        if (index < cnt)
                        {
                            MethodInfo mia = collection.GetType().GetMethod("RemoveAt");
                            mia.Invoke(collection, new object[] { index });
                        }

                        MethodInfo mi = collection.GetType().GetMethod("Insert");
                        mi.Invoke(collection, new object[] { index, result });
                    }
                }
                //else if (ft.Equals(typeof(TextBox)) || ft.IsSubclassOf(typeof(TextBox)))
                //{
                //    ConstructorInfo ci = ft.GetConstructor(new Type[] { });
                //    result = (DisplayObject)ci.Invoke(new object[] { });
                //    fi.SetValue(this, result);
                //}
                else if (ft.Equals(typeof(DisplayObject)) || ft.IsSubclassOf(typeof(DisplayObject)))
                {
                    ConstructorInfo ci = ft.GetConstructor(new Type[] { typeof(Texture2D), typeof(V2DInstance) });
                    result = (DisplayObject)ci.Invoke(new object[] { texture, inst });
                    fi.SetValue(this, result);
                }
                else
                {
                    throw new ArgumentException("Not supported field type. " + ft.ToString() + " " + instName);
                }
            }

            if (result != null)
            {
                result.Index    = index; // set for all object, -1 if not in collection
                result.RootName = instName;

                // apply attributes
                System.Attribute[] attrs = System.Attribute.GetCustomAttributes(fi);                  // reflection

                foreach (System.Attribute attr in attrs)
                {
                    if (attr is SpriteAttribute)
                    {
                        SpriteAttribute a = (SpriteAttribute)attr;
                        result.DepthGroup = a.depthGroup;
                    }

                    if (attr is V2DSpriteAttribute)
                    {
                        if (result is V2DSprite)
                        {
                            V2DSpriteAttribute a  = (V2DSpriteAttribute)attr;
                            V2DSprite          sp = (V2DSprite)result;
                            sp.attributeProperties = a;
                            sp.SetGroupIndex(a.groupIndex);
                            sp.IsStatic = a.isStatic;
                        }
                    }
                }

                // need to do this separately to ensure the depth group is set in previous step
                if (this is Screen)
                {
                    Screen scr = (Screen)this;
                    // field attirbutes
                    foreach (System.Attribute attr in attrs)
                    {
                        if (attr is V2DShaderAttribute && !scr.shaderMap.ContainsKey(result.DepthGroup))
                        {
                            V2DShaderAttribute vsa        = (V2DShaderAttribute)attr;
                            float[]            parameters = new float[] { };
                            ConstructorInfo    ci         = vsa.shaderType.GetConstructor(new Type[] { parameters.GetType() });
                            scr.shaderMap.Add(
                                result.DepthGroup,
                                (V2DShader)ci.Invoke(new object[] { new float[] { vsa.param0, vsa.param1, vsa.param2, vsa.param3, vsa.param4 } })
                                );
                        }
                    }
                }
            }
            return(result);
        }
 public SteamParticleGroup(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
 public DisplayObjectContainer(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
     this.FrameCount = (inst.Definition == null) ? 1 : inst.Definition.FrameCount;
 }
Exemple #21
0
 public Panel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
     //isActive = false;
 }
 public LobbyPanel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
Exemple #23
0
 public SpaceVehicle(Texture2D texture, V2DInstance instance) : base(texture, instance)
 {
 }
 public Target(Texture2D texture, V2DInstance instance) : base(texture, instance)
 {
 }
Exemple #25
0
 public virtual Sprite CreateDefaultObject(Texture2D texture, V2DInstance inst)
 {
     return(new Sprite(texture, inst));
 }
Exemple #26
0
 public DirectionalParticle(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
 public HeadPlayer(Texture2D texture, V2DInstance instance) : base(texture, instance)
 {
 }
Exemple #28
0
 //public Button(Texture2D texture) : base(texture)
 //{
 //}
 public Button(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
 public TrafficSplashPanel(Texture2D texture, V2DInstance inst) : base(texture, inst)
 {
 }
Exemple #30
0
 public Group(Texture2D texture, V2DInstance inst)
     : base(texture, inst)
 {
 }