Exemplo n.º 1
0
        public FpsCounterState(IHub services)
            : base(services)
        {
            _previousTimeStamp = DateTime.Now;

            _text = new Text2D
            {
                IsVisible = true,
                Text = "EMPTY",
                Color = Color.Blue,
                Position = new Vector2(50, 50)
            };
        }
Exemplo n.º 2
0
        private Text2D CreateTextDefinition(Text def)
        {
            Text2D result = new Text2D(def.TextRuns);

            result.Id = def.Id;
            result.DefinitionName = def.Name;
            result.LinkageName = def.Name;
            result.Bounds = def.StrokeBounds;
            AddFonts(def.TextRuns);
            return result;
        }
Exemplo n.º 3
0
        public HUD(ContentManager content)
        {
            SpriteFont   font  = LoadingUtils.load <SpriteFont>(content, "SpriteFont1");
            Text2DParams parms = new Text2DParams();

            parms.Font        = font;
            parms.LightColour = Color.Red;

            parms.Position    = new Vector2(Constants.RESOLUTION_X / 3, 450f);
            parms.WrittenText = TEXT_RESTART;
            this.statusText   = new Text2D(parms);

            ColourLerpEffectParams effectParms = new ColourLerpEffectParams {
                LerpBy     = 5f,
                LerpDownTo = Color.White,
                LerpUpTo   = Color.Red
            };

            int size = 1;

            if (StateManager.getInstance().GameMode == GameMode.TwoPlayer)
            {
                size = 2;
            }
            this.scoreTexts  = new Text2D[size];
            this.winnerTexts = new Text2D[size];

            parms.Position     = new Vector2(RIGHT_X, SCORES_Y);
            parms.WrittenText  = TEXT_SCORE + getScore(0);
            this.scoreTexts[0] = new Text2D(parms);
            this.scoreTexts[0].addEffect(new ColourLerpEffect(effectParms));

            parms.Position      = new Vector2(RIGHT_X + WINNER_X_PADDING, SCORES_Y + WINNER_Y_OFFSET);
            parms.WrittenText   = TEXT_WINNER;
            this.winnerTexts[0] = new Text2D(parms);
            this.winnerTexts[0].addEffect(new ColourLerpEffect(effectParms));

            if (StateManager.getInstance().GameMode == GameMode.TwoPlayer)
            {
                parms.Position     = new Vector2(LEFT_X, SCORES_Y);
                parms.WrittenText  = TEXT_SCORE + getScore(1);
                this.scoreTexts[1] = new Text2D(parms);
                this.scoreTexts[1].addEffect(new ColourLerpEffect(effectParms));

                parms.Position      = new Vector2(LEFT_X + WINNER_X_PADDING, SCORES_Y + WINNER_Y_OFFSET);
                parms.WrittenText   = TEXT_WINNER;
                this.winnerTexts[1] = new Text2D(parms);
                this.winnerTexts[1].addEffect(new ColourLerpEffect(effectParms));
            }

            this.countDownImages = new StaticDrawable2D[3];
            StaticDrawable2DParams countDownParms = new StaticDrawable2DParams {
                Position = new Vector2(Constants.RESOLUTION_X / 2, Constants.RESOLUTION_Y / 2),
                Origin   = new Vector2(256f),
            };

            for (int i = 0; i < this.countDownImages.Length; i++)
            {
                countDownParms.Texture  = LoadingUtils.load <Texture2D>(content, (i + 1).ToString());
                this.countDownImages[i] = new StaticDrawable2D(countDownParms);
            }

            StaticDrawable2DParams gameOverParms = new StaticDrawable2DParams {
                Position = new Vector2(Constants.RESOLUTION_X / 2, Constants.RESOLUTION_Y / 2),
                Origin   = new Vector2(512f),
                Texture  = LoadingUtils.load <Texture2D>(content, "GameOver")
            };

            this.gameOver = new StaticDrawable2D(gameOverParms);

            scaleOverTimeEffectParms = new ScaleOverTimeEffectParams {
                ScaleBy = new Vector2(-1f)
            };

            this.soundEffect = LoadingUtils.load <SoundEffect>(content, "ShortBeep");

            this.index = 2;
            this.activeCountdownItem = this.countDownImages[this.index];
            this.activeCountdownItem.addEffect(new ScaleOverTimeEffect(scaleOverTimeEffectParms));
            this.elapsedTime = 0f;
            SoundManager.getInstance().SFXEngine.playSoundEffect(this.soundEffect);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Renders the primities for the given scene.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="view"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="primitives"></param>
        private bool RenderPrimitives(Target2DWrapper <TTarget> target, View2D view, float zoomFactor,
                                      IEnumerable <Primitive2D> primitives)
        {
            try {
                // calculate current simplification epsilon.
                double epsilon = Scene2D.CalculateSimplificationEpsilon(new WebMercator(), zoomFactor);

                // loop over all primitives in the scene.
                int simplifiedLines = 0;
                int droppedLines    = 0;
                foreach (Primitive2D primitive in primitives)
                {     // the primitive is visible.
                    if (_cancelFlag)
                    {
                        return(false);                        // stop rendering on cancel and return false for an incomplete rendering.
                    }

                    if (primitive == null)
                    {
                        continue;
                    }
                    double[] x, y;
                    switch (primitive.Primitive2DType)
                    {
                    case Primitive2DType.Line2D:
                        Line2D line = (Line2D)primitive;

                        x = line.X;
                        y = line.Y;
                        if (x.Length > 4 && line.MaxZoom > zoomFactor * 2 && line.MaxZoom < 512)
                        {     // try and simplify.
                            double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                                                                                                    epsilon);
                            if (simplified[0].Length < line.X.Length)
                            {
                                simplifiedLines++;
                                x = simplified[0];
                                y = simplified[1];
                            }
                            double distance = epsilon * 2;
                            if (simplified[0].Length == 2)
                            {     // check if the simplified version is smaller than epsilon.
                                distance = System.Math.Sqrt(
                                    System.Math.Pow((simplified[0][0] - simplified[0][1]), 2) +
                                    System.Math.Pow((simplified[1][0] - simplified[1][1]), 2));
                            }
                            if (distance < epsilon)
                            {
                                droppedLines++;
                                continue;
                            }
                        }
                        this.DrawLine(target, x, y, line.Color,
                                      this.FromPixels(target, view, line.Width), line.LineJoin, line.Dashes);
                        break;

                    case Primitive2DType.Polygon2D:
                        Polygon2D polygon = (Polygon2D)primitive;

                        x = polygon.X;
                        y = polygon.Y;
                        //if (x.Length > 4 && polygon.MaxZoom > zoomFactor * 2 && polygon.MaxZoom < 512)
                        //{ // try and simplify.
                        //    double[][] simplified = OsmSharp.Math.Algorithms.SimplifyCurve.Simplify(new double[][] { x, y },
                        //        epsilon);
                        //    if (simplified[0].Length < polygon.X.Length)
                        //    {
                        //        simplifiedLines++;
                        //        x = simplified[0];
                        //        y = simplified[1];
                        //    }
                        //    double distance = epsilon * 2;
                        //    if (simplified[0].Length == 2)
                        //    { // check if the simplified version is smaller than epsilon.
                        //        distance = System.Math.Sqrt(
                        //            System.Math.Pow((simplified[0][0] - simplified[0][1]), 2) +
                        //            System.Math.Pow((simplified[1][0] - simplified[1][1]), 2));
                        //    }
                        //    //if (distance < epsilon)
                        //    //{
                        //    //    droppedLines++;
                        //    //    continue;
                        //    //}
                        //}
                        this.DrawPolygon(target, x, y, polygon.Color,
                                         this.FromPixels(target, view, polygon.Width), polygon.Fill);
                        break;

                    case Primitive2DType.LineText2D:
                        LineText2D lineText = (LineText2D)primitive;
                        this.DrawLineText(target, lineText.X, lineText.Y, lineText.Text, lineText.Color,
                                          this.FromPixels(target, view, lineText.Size), lineText.HaloColor, lineText.HaloRadius, lineText.Font);
                        break;

                    case Primitive2DType.Point2D:
                        Point2D point = (Point2D)primitive;
                        this.DrawPoint(target, point.X, point.Y, point.Color,
                                       this.FromPixels(target, view, point.Size));
                        break;

                    case Primitive2DType.Icon2D:
                        Icon2D icon = (Icon2D)primitive;
                        this.DrawIcon(target, icon.X, icon.Y, icon.Image);
                        break;

                    case Primitive2DType.ImageTilted2D:
                        ImageTilted2D imageTilted = (ImageTilted2D)primitive;
                        this.DrawImage(target, imageTilted.Bounds, imageTilted.NativeImage);
                        break;

                    case Primitive2DType.Image2D:
                        Image2D image = (Image2D)primitive;
                        this.DrawImage(target, image.Left, image.Top, image.Right, image.Bottom, image.NativeImage);
                        break;

                    case Primitive2DType.Text2D:
                        Text2D text = (Text2D)primitive;
                        this.DrawText(target, text.X, text.Y, text.Text, text.Color,
                                      this.FromPixels(target, view, text.Size), text.HaloColor, text.HaloRadius, text.Font);
                        break;
                    }
                }
                return(true);
            }
            catch (Exception ex) {
                OsmSharp.Logging.Log.TraceEvent("Renderer2D", OsmSharp.Logging.TraceEventType.Error,
                                                ex.Message);
                throw ex;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a Textbox based on the params object passed in
        /// </summary>
        /// <param name="parms">TextBoxParams object</param>
        public TextBox(TextBoxParams parms) : base(parms)
        {
            this.font = parms.Font;
            this.Text = parms.Text;
            this.SIZE_PER_CHARACTER = parms.SizePerCharacter;
            this.MAX_LENGTH         = parms.MaxLength;
            this.VALID_KEYS         = new List <Keys>();
            this.VALID_KEYS.AddRange(KeyLists.DIRECTIONAL_KEYS);
            this.VALID_KEYS.AddRange(KeyLists.LETTERS_KEYS);
            this.VALID_KEYS.AddRange(KeyLists.NUMBER_KEYS);
            this.VALID_KEYS.AddRange(KeyLists.NUMPAD_KEYS);

            Vector2 endsScale = new Vector2(1f, parms.Scale.Y);
            Vector2 midScale  = new Vector2(parms.Scale.X, 1f);

            this.imgs = new List <StaticDrawable2D>();
            // Starting edge
            StaticDrawable2DParams imgParms = new StaticDrawable2DParams {
                Position           = parms.Position,
                LightColour        = parms.LightColour,
                RenderingRectangle = Constants.TXT_BOX_END,
                Scale   = endsScale,
                Texture = LoadingUtils.load <Texture2D>(parms.Content, Constants.GUI_FILE_NAME)
            };

            this.imgs.Add(new StaticDrawable2D(imgParms));

            // Middle bars
            Vector2 start    = new Vector2(imgParms.Position.X - 30f, imgParms.Position.Y);
            Vector2 startBar = Vector2.Add(start, new Vector2(Constants.TXT_BOX_END.Width, 0f));

            START_BAR_X = startBar.X;
            float length = parms.MaxLength * parms.SizePerCharacter + parms.Scale.X;

            imgParms.Position           = startBar;
            imgParms.RenderingRectangle = Constants.TXT_BOX_MIDDLE;
            imgParms.Scale = new Vector2(length, parms.Scale.Y);
            this.imgs.Add(new StaticDrawable2D(imgParms));

            // Ending edge
            imgParms.Position           = Vector2.Add(start, new Vector2(Constants.TXT_BOX_END.Width + length, 0f));
            imgParms.RenderingRectangle = Constants.TXT_BOX_END;
            imgParms.Scale = endsScale;
            this.imgs.Add(new StaticDrawable2D(imgParms));

            this.bbox = new BoundingBox(new Vector3(start.X, start.Y, 0f), new Vector3(imgParms.Position.X + Constants.TXT_BOX_MIDDLE.Width,
                                                                                       imgParms.Position.Y + Constants.TXT_BOX_MIDDLE.Height, 0f));

            // Cursor indicator
            float x = START_BAR_X + text.Length * SIZE_PER_CHARACTER + 4f;

            imgParms.Position    = new Vector2(x, imgParms.Position.Y + 6f);
            imgParms.Scale       = new Vector2(1f, (parms.Scale.Y - .5f));
            imgParms.LightColour = parms.TextColour;
            this.cursorIndicator = new StaticDrawable2D(imgParms);
            updateIndicatorsPosition();

            Text2DParams txtParms = new Text2DParams {
                Position    = new Vector2(parms.Position.X + 2f, parms.Position.Y),
                Font        = parms.Font,
                Scale       = parms.TextScale,
                WrittenText = this.Text,
                LightColour = parms.TextColour
            };

            this.text2D = new Text2D(txtParms);
        }
Exemplo n.º 6
0
    bool ValidateText2D(Shape shape, MessageHandler handler)
    {
        bool          ok          = true;
        Text2D        text2D      = (Text2D)shape;
        Text2DHandler textHandler = handler as Text2DHandler;

        if (textHandler == null)
        {
            Debug.LogError(string.Format("Wrong handler for Text2D: {0}", textHandler.Name));
            ok = false;
            // Nothing more to test.
            return(false);
        }

        Text2DHandler.Text2DManager textManager = textHandler.PersistentText;
        Text2DHandler.TextEntry     textEntry   = null;
        foreach (var text in textManager.Entries)
        {
            if (text.ID == text2D.ID)
            {
                textEntry = text;
                break;
            }
        }

        if (textEntry == null)
        {
            Debug.LogError("Failed to find matching text entry.");
            ok = false;
            // Nothing more to test.
            return(false);
        }

        if (textEntry.Category != text2D.Category)
        {
            Debug.LogError("Category mismatch.");
            ok = false;
        }

        if (textEntry.ObjectFlags != text2D.Flags)
        {
            Debug.LogError("Flags mismatch.");
            ok = false;
        }

        if (textEntry.Position != Tes.Maths.Vector3Ext.ToUnity(shape.Position))
        {
            Debug.LogError(string.Format("Position mismatch: {0} != {1}",
                                         textEntry.Position, Tes.Maths.Vector3Ext.ToUnity(shape.Position)));
            ok = false;
        }

        Color32 c1 = textEntry.Colour;
        Color32 c2 = Tes.Handlers.ShapeComponent.ConvertColour(shape.Colour);

        if (c1.r != c2.r || c1.g != c2.g || c1.b != c2.b || c1.a != c2.a)
        {
            Debug.LogError("Colour mismatch.");
            ok = false;
        }

        if (string.Compare(textEntry.Text, text2D.Text) != 0)
        {
            Debug.LogError(string.Format("Text mismatch : {0} != {1}", textEntry.Text, text2D.Text));
            ok = false;
        }

        return(ok);
    }
Exemplo n.º 7
0
        /// <summary>
        /// Deserializes the given leaf.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override List <Primitive2D> DeSerialize(RuntimeTypeModel typeModel,
                                                          byte[] data, out List <BoxF2D> boxes)
        {
            if (_compressed)
            { // decompress if needed.
                data = GZipStream.UncompressBuffer(data);
            }

            List <Primitive2D> dataLists = new List <Primitive2D>();

            boxes = new List <BoxF2D>();

            int scaleFactor = _scaleFactor;

            // Assume the following stuff already exists in the current scene:
            // - ZoomRanges
            // - Styles

            // deserialize the leaf data.
            SceneObjectBlock leafData = typeModel.Deserialize(
                new MemoryStream(data), null, typeof(SceneObjectBlock)) as SceneObjectBlock;

            // decode
            for (int idx = 0; idx < leafData.PointsX.Count; idx++)
            {
                leafData.PointsX[idx] = leafData.PointsX[idx] + leafData.PointsXMin;
                leafData.PointsY[idx] = leafData.PointsY[idx] + leafData.PointsYMin;
            }

            // store the next points.
            bool[] pointsStarts = new bool[leafData.PointsX.Count];
            // loop over all points.
            for (int idx = 0; idx < leafData.PointPointId.Count; idx++)
            {
                pointsStarts[leafData.PointPointId[idx]] = true;
            }
            // loop over all text-points.
            for (int idx = 0; idx < leafData.TextPointPointId.Count; idx++)
            {
                pointsStarts[leafData.TextPointPointId[idx]] = true;
            }
            // loop over all icons.
            for (int idx = 0; idx < leafData.IconPointId.Count; idx++)
            {
                pointsStarts[leafData.IconPointId[idx]] = true;
            }
            // loop over all lines.
            for (int idx = 0; idx < leafData.LinePointsId.Count; idx++)
            {
                pointsStarts[leafData.LinePointsId[idx]] = true;
            }
            // loop over all polygons.
            for (int idx = 0; idx < leafData.PolygonPointsId.Count; idx++)
            {
                pointsStarts[leafData.PolygonPointsId[idx]] = true;
            }
            // loop over all line-texts.
            for (int idx = 0; idx < leafData.LineTextPointsId.Count; idx++)
            {
                pointsStarts[leafData.LineTextPointsId[idx]] = true;
            }
            Dictionary <int, int> pointsBoundaries = new Dictionary <int, int>();
            int previous = 0;

            for (int idx = 1; idx < pointsStarts.Length; idx++)
            {
                if (pointsStarts[idx])
                { // there is a start here.
                    pointsBoundaries[previous] = idx - previous;
                    previous = idx;
                }
            }
            pointsBoundaries[previous] = pointsStarts.Length - previous;

            // loop over all points.
            for (int idx = 0; idx < leafData.PointPointId.Count; idx++)
            {
                // get properties.
                int  pointId = leafData.PointPointId[idx];
                uint styleId = leafData.PointStyleId[idx];

                // get point/style/zoomrange.
                double     x     = (double)leafData.PointsX[pointId] / (double)scaleFactor;
                double     y     = (double)leafData.PointsY[pointId] / (double)scaleFactor;
                StylePoint style = _index.PointStyles[styleId];

                // build the primitive.
                Point2D point = new Point2D(x, y, style.Color, style.Size);
                point.Layer   = style.Layer;
                point.MinZoom = style.MinZoom;
                point.MaxZoom = style.MaxZoom;

                dataLists.Add(point);
                boxes.Add(new BoxF2D(new PointF2D(x, y)));
            }

            // loop over all text-points.
            for (int idx = 0; idx < leafData.TextPointPointId.Count; idx++)
            {
                // get properties.
                int    pointId = leafData.TextPointPointId[idx];
                uint   styleId = leafData.TextPointStyleId[idx];
                string text    = leafData.TextPointText[idx];

                // get point/style/zoomrange.
                float     x     = (float)leafData.PointsX[pointId] / (float)scaleFactor;
                float     y     = (float)leafData.PointsY[pointId] / (float)scaleFactor;
                StyleText style = _index.TextStyles[styleId];

                // build the primitive.
                Text2D text2D = new Text2D(x, y, text, style.Color, style.Size);
                text2D.Layer      = style.Layer;
                text2D.HaloColor  = style.HaloColor;
                text2D.HaloRadius = style.HaloRadius;
                text2D.MinZoom    = style.MinZoom;
                text2D.MaxZoom    = style.MaxZoom;

                dataLists.Add(text2D);
                boxes.Add(new BoxF2D(new PointF2D(x, y)));
            }

            // loop over all icons.
            for (int idx = 0; idx < leafData.IconPointId.Count; idx++)
            {
                // get properties.
                int  pointId = leafData.IconPointId[idx];
                uint imageId = leafData.IconImageId[idx];

                // get point/style/zoomrange.
                double x     = (double)leafData.PointsX[pointId] / (double)scaleFactor;
                double y     = (double)leafData.PointsY[pointId] / (double)scaleFactor;
                byte[] image = _index.IconImage[(int)imageId];

                // build the primitive.
                Icon2D icon = new Icon2D(x, y, image);
                icon.Layer = 0;
                // TODO: layer and zoom level. style.MinZoom, style.MaxZoom

                dataLists.Add(icon);
                boxes.Add(new BoxF2D(new PointF2D(x, y)));
            }

            // loop over all lines.
            for (int idx = 0; idx < leafData.LinePointsId.Count; idx++)
            {
                // get properties.
                int  pointsId = leafData.LinePointsId[idx];
                uint styleId  = leafData.LineStyleId[idx];

                // get points/style/zoomrange.
                int      pointsCount = pointsBoundaries[pointsId];
                double[] x           =
                    leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                double[] y =
                    leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                StyleLine style = _index.LineStyles[styleId];

                // build the primitive.
                Line2D line = new Line2D(x, y, style.Color, style.Width, style.LineJoin, style.Dashes);
                line.Layer   = style.Layer;
                line.MinZoom = style.MinZoom;
                line.MaxZoom = style.MaxZoom;

                dataLists.Add(line);
                boxes.Add(new BoxF2D(x, y));
            }

            // loop over all polygons.
            for (int idx = 0; idx < leafData.PolygonPointsId.Count; idx++)
            {
                // get properties.
                int  pointsId = leafData.PolygonPointsId[idx];
                uint styleId  = leafData.PolygonStyleId[idx];

                // get points/style/zoomrange.
                int      pointsCount = pointsBoundaries[pointsId];
                double[] x           =
                    leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                double[] y =
                    leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                StylePolygon style = _index.PolygonStyles[styleId];

                // build the primitive.
                Polygon2D polygon = new Polygon2D(x, y, style.Color, style.Width, style.Fill);
                polygon.Layer   = style.Layer;
                polygon.MaxZoom = style.MaxZoom;
                polygon.MinZoom = style.MinZoom;

                dataLists.Add(polygon);
                boxes.Add(new BoxF2D(x, y));
            }

            // loop over all line-texts.
            for (int idx = 0; idx < leafData.LineTextPointsId.Count; idx++)
            {
                // get properties.
                int    pointsId = leafData.LineTextPointsId[idx];
                uint   styleId  = leafData.LineTextStyleId[idx];
                string text     = leafData.LineTextText[idx];

                // get points/style/zoomrange.
                int      pointsCount = pointsBoundaries[pointsId];
                double[] x           =
                    leafData.PointsX.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                double[] y =
                    leafData.PointsY.GetRange(pointsId, pointsCount).ConvertFromLongArray(scaleFactor);
                StyleText style = _index.TextStyles[styleId];

                // build the primitive.
                LineText2D lineText = new LineText2D(x, y, style.Color, style.Size, text);
                lineText.Layer      = style.Layer;
                lineText.Font       = style.Font;
                lineText.HaloColor  = style.HaloColor;
                lineText.HaloRadius = style.HaloRadius;
                lineText.MinZoom    = style.MinZoom;
                lineText.MaxZoom    = style.MaxZoom;

                dataLists.Add(lineText);
                boxes.Add(new BoxF2D(x, y));
            }
            return(dataLists);
        }
Exemplo n.º 8
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "Unreal Science Scene files (*.usscene)|*.usscene";

            d.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();



            if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK && d.FileName.Length > 0)
            {
                if (System.Windows.MessageBox.Show("Do you want to save the scene?", "Save?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    SaveFileDialog save = new SaveFileDialog();

                    save.Filter = "Unreal Science Scene files (*.usscene)|*.usscene";

                    save.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();

                    if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK && save.FileName.Length > 0)
                    {
                        SaveSceneTo(save.FileName);
                    }
                }

                SavedFilename = d.FileName;

                UnrealScienceScripting.Cleanup();
                UnrealScienceScripting.CleanUI();

                UnrealScienceScripting.World.Entities.Clear();
                Hierarchy.Items.Clear();

                Read r = new Read();

                Scripting.isPlaying = false;

                r.Deserialize(d.FileName);

                #region entities
                foreach (SceneEntity s in r.Scene.Entities)
                {
                    Scripting.ScriptingManager.Parse(s.CreationCommand);

                    Scripting.ScriptingManager.Parse(String.Format("move {0} {1} {2}",
                                                                   s.Transform.Position.X,
                                                                   s.Transform.Position.Y,
                                                                   s.Transform.Position.Z));

                    Scripting.ScriptingManager.Parse(String.Format("rotate {0} {1} {2}",
                                                                   s.Transform.Rotation.X,
                                                                   s.Transform.Rotation.Y,
                                                                   s.Transform.Rotation.Z));

                    Scripting.ScriptingManager.Parse(String.Format("scale {0} {1} {2}",
                                                                   s.Transform.Scale.X,
                                                                   s.Transform.Scale.Y,
                                                                   s.Transform.Scale.Z));

                    Scripting.ScriptingManager.Parse("setTexture " + s.Texture);

                    Scripting.ScriptingManager.Parse(String.Format("setColor {0} {1} {2}", s.Color.X, s.Color.Y, s.Color.Z));

                    if (s.Animation.AnimationKeys.Count != 0)
                    {
                        foreach (AnimationKey key in s.Animation.AnimationKeys)
                        {
                            Vector3D v = new Vector3D();

                            if (key.KeyType == 1)
                            {
                                v = key.Destination.Position;
                            }
                            else if (key.KeyType == 2)
                            {
                                v = key.Destination.Rotation;
                            }
                            else if (key.KeyType == 3)
                            {
                                v = key.Destination.Scale;
                            }

                            string type = "";

                            if (key.KeyType == 1)
                            {
                                type = "position";
                            }
                            else if (key.KeyType == 2)
                            {
                                type = "rotation";
                            }
                            else if (key.KeyType == 3)
                            {
                                type = "scale";
                            }

                            Scripting.AnimationManager.Parse(String.Format("setKey {0} {1} {2} {3} {4} {5}",
                                                                           type, key.StartOrder, key.Duration, v.X, v.Y, v.Z));
                        }
                    }
                }
                #endregion

                #region create_UI

                foreach (UnrealScienceLibrary.UIElement element in r.Scene.Elements)
                {
                    if (element is Text2D)
                    {
                        //Scripting.ScriptingManager.Parse("addText {0} {1} {2} {3} {4} {5}",
                        //    (element as Text2D).Text, );

                        Text2D t = element as Text2D;

                        UnrealScienceScripting.AddText2D(t.Text, t.FontName, (int)t.Position.X, (int)t.Position.Y, (int)t.Scale.X, (int)t.Scale.Y, (int)t.FontSize);
                    }
                }

                #endregion
            }
        }
Exemplo n.º 9
0
        public OptionsMenu(ContentManager content) : base(content, "OptionsMenu", new Vector2(Constants.RESOLUTION_X / 2, 100f))
        {
            this.effectParms = new PulseEffectParams {
                ScaleBy     = 1f,
                ScaleDownTo = .9f,
                ScaleUpTo   = 1.1f
            };

            float x                     = Constants.RESOLUTION_X / 10;
            float leftSideX             = Constants.RESOLUTION_X / 2 - 25f;
            float rightSideX            = leftSideX + 250f;
            float bindingsStartPaddingX = 125f;

            this.playerOneSection = new OptionsSection(content, new Vector2(x, 325f), x + bindingsStartPaddingX, "One", ConfigurationManager.getInstance().PlayerOnesControls);
            this.playerTwoSection = new OptionsSection(content, new Vector2(x * 6, 325f), x * 6 + bindingsStartPaddingX, "Two", ConfigurationManager.getInstance().PlayerTwosControls);

            SpriteFont font = LoadingUtils.load <SpriteFont>(content, "SpriteFont1");

            Vector2 position = new Vector2(leftSideX, 200f);
            SoundEngineSliderParams soundEngineParams = new SoundEngineSliderParams {
                Position         = position,
                BallColour       = Constants.TEXT_COLOUR,
                BarColour        = Constants.TEXT_COLOUR,
                Content          = content,
                CurrentValue     = SoundManager.getInstance().MusicEngine.Volume,
                Font             = font,
                LightColour      = Constants.TEXT_COLOUR,
                SoundEngine      = SoundManager.getInstance().MusicEngine,
                CheckBoxPosition = new Vector2(position.X + 250f, position.Y),
                Checked          = SoundManager.getInstance().MusicEngine.Muted,
                CheckBoxText     = "Muted",
            };

            this.musicSlider = new SoundEngineSlider(soundEngineParams);


            Text2DParams textParms = new Text2DParams {
                Font        = font,
                LightColour = Constants.TEXT_COLOUR,
                Position    = new Vector2(position.X - 300f, position.Y),
                WrittenText = "Music",
                Origin      = new Vector2(16f)
            };

            this.musicSliderText = new Text2D(textParms);


            soundEngineParams.Position         = new Vector2(position.X, position.Y + SPACE);
            soundEngineParams.CheckBoxPosition = new Vector2(soundEngineParams.CheckBoxPosition.X, position.Y + SPACE);
            soundEngineParams.SoundEngine      = SoundManager.getInstance().SFXEngine;
            soundEngineParams.CurrentValue     = SoundManager.getInstance().SFXEngine.Volume;
            soundEngineParams.Checked          = SoundManager.getInstance().SFXEngine.Muted;
            this.sfxSlider = new SoundEngineSlider(soundEngineParams);

            textParms.Position    = new Vector2(position.X - 300f, position.Y + SPACE);
            textParms.WrittenText = "SFX";
            this.sfxSliderText    = new Text2D(textParms);
            this.buttons          = new List <TexturedEffectButton>();
            Vector2 origin = new Vector2(90f, 64f);

            position = new Vector2(position.X, position.Y + 275f);
            TexturedEffectButtonParams buttonParms = new TexturedEffectButtonParams {
                Position = position,
                Origin   = origin,
                Scale    = new Vector2(1f),
                Effects  = new List <BaseEffect> {
                    new PulseEffect(this.effectParms)
                },
                PickableArea  = getRect(origin, position),
                ResetDelegate = delegate(StaticDrawable2D button) {
                    button.Scale = new Vector2(1f);
                }
            };

            for (int i = 0; i < this.BUTTON_NAMES.Length; i++)
            {
                buttonParms.Texture      = LoadingUtils.load <Texture2D>(content, BUTTON_NAMES[i]);
                buttonParms.Position     = new Vector2(buttonParms.Position.X, buttonParms.Position.Y + SPACE * 1.3f);
                buttonParms.PickableArea = getRect(origin, buttonParms.Position);
                this.buttons.Add(new TexturedEffectButton(buttonParms));
            }

#if DEBUG
            this.debugTexture = LoadingUtils.load <Texture2D>(content, "Chip");
            StaticDrawable2DParams centerParms = new StaticDrawable2DParams {
                Position    = new Vector2(Constants.RESOLUTION_X / 2, 0),
                Scale       = new Vector2(1f, Constants.RESOLUTION_Y),
                Texture     = this.debugTexture,
                LightColour = Color.Green
            };
            this.center = new StaticDrawable2D(centerParms);
#endif
        }
Exemplo n.º 10
0
 /** 計算。フォントサイズ。
  */
 public int CalcFontSize(Text2D a_text)
 {
     return((int)(a_text.GetFontSize() * this.calc_ui_scale));
 }
Exemplo n.º 11
0
        /** 計算。テキスト。
         */
        public void CalcTextRect(Text2D a_text)
        {
            //サイズ計算。
            if (a_text.Raw_IsCalcSize() == true)
            {
                a_text.Raw_SetCalcSizeFlag(false);

                int t_w = a_text.GetW();
                int t_h = a_text.GetH();

                UnityEngine.Vector2 t_sizedelta;

                if (t_w > 0)
                {
                    t_sizedelta.x = t_w * this.calc_ui_scale;
                }
                else
                {
                    t_sizedelta.x = Screen.GetScreenWidth();
                }

                if (t_h > 0)
                {
                    t_sizedelta.y = t_h * this.calc_ui_scale;
                }
                else
                {
                    t_sizedelta.y = Screen.GetScreenHeight();
                }

                //自動部分を最大設定。
                a_text.Raw_SetRectTransformSizeDelta(in t_sizedelta);

                if ((t_w <= 0) || (t_h <= 0))
                {
                    if (t_w <= 0)
                    {
                        t_sizedelta.x = a_text.Raw_GetPreferredWidth();
                    }

                    if (t_h <= 0)
                    {
                        t_sizedelta.y = a_text.Raw_GetPreferredHeight();
                    }

                    //自動部分再設定。
                    a_text.Raw_SetRectTransformSizeDelta(in t_sizedelta);
                }
            }

            //位置計算。
            UnityEngine.Vector3 t_localposition = new UnityEngine.Vector3(this.calc_ui_x + a_text.GetX() * this.calc_ui_scale, this.calc_ui_y - a_text.GetY() * this.calc_ui_scale, 0.0f);
            if ((a_text.GetAlignmentTypeX() != Text2D_HorizontalAlignmentType.Center) || (a_text.GetAlignmentTypeY() != Text2D_VerticalAlignmentType.Middle))
            {
                //計算済みサイズ取得。
                UnityEngine.Vector2 t_sizedelta;
                a_text.Raw_GetRectTransformSizeDelta(out t_sizedelta);

                switch (a_text.GetAlignmentTypeX())
                {
                case Text2D_HorizontalAlignmentType.Right:
                {
                    t_localposition.x -= t_sizedelta.x / 2;
                } break;

                case Text2D_HorizontalAlignmentType.Left:
                {
                    t_localposition.x += t_sizedelta.x / 2;
                } break;
                }

                switch (a_text.GetAlignmentTypeY())
                {
                case Text2D_VerticalAlignmentType.Bottom:
                {
                    t_localposition.y += t_sizedelta.y / 2;
                } break;

                case Text2D_VerticalAlignmentType.Top:
                {
                    t_localposition.y -= t_sizedelta.y / 2;
                } break;
                }
            }
            a_text.Raw_SetRectTransformLocalPosition(in t_localposition);
        }
Exemplo n.º 12
0
 protected override void Start(SystemRegistry registry)
 {
     _text = GameObject.GetComponent <Text2D>();
 }
Exemplo n.º 13
0
        public void CreateScene(Scene World)
        {
            #region generate_world
            foreach (SceneEntity s in World.Entities)
            {
                Scripting.ScriptingManager.Parse(s.CreationCommand);

                Scripting.ScriptingManager.Parse(String.Format("move {0} {1} {2}",
                                                               s.Transform.Position.X,
                                                               s.Transform.Position.Y,
                                                               s.Transform.Position.Z));

                Scripting.ScriptingManager.Parse(String.Format("rotate {0} {1} {2}",
                                                               s.Transform.Rotation.X,
                                                               s.Transform.Rotation.Y,
                                                               s.Transform.Rotation.Z));

                Scripting.ScriptingManager.Parse(String.Format("scale {0} {1} {2}",
                                                               s.Transform.Scale.X,
                                                               s.Transform.Scale.Y,
                                                               s.Transform.Scale.Z));

                Scripting.ScriptingManager.Parse("setTexture " + s.Texture);

                Scripting.ScriptingManager.Parse(String.Format("setColor {0} {1} {2}", s.Color.X, s.Color.Y, s.Color.Z));

                if (s.Animation.AnimationKeys.Count != 0)
                {
                    foreach (AnimationKey key in s.Animation.AnimationKeys)
                    {
                        Vector3D v = new Vector3D();

                        if (key.KeyType == 1)
                        {
                            v = key.Destination.Position;
                        }
                        else if (key.KeyType == 2)
                        {
                            v = key.Destination.Rotation;
                        }
                        else if (key.KeyType == 3)
                        {
                            v = key.Destination.Scale;
                        }

                        string type = "";

                        if (key.KeyType == 1)
                        {
                            type = "position";
                        }
                        else if (key.KeyType == 2)
                        {
                            type = "rotation";
                        }
                        else if (key.KeyType == 3)
                        {
                            type = "scale";
                        }

                        Scripting.AnimationManager.Parse(String.Format("setKey {0} {1} {2} {3} {4} {5}",
                                                                       type, key.StartOrder, key.Duration, v.X, v.Y, v.Z));
                    }
                }



                if (s.Animation.AnimationKeys.Count != 0)
                {
                    Scripting.ScriptingManager.Parse("startAnimation");
                }
            }
            //Scripting.ScriptingManager.Parse("select 1");
            #endregion

            #region create_UI

            foreach (UnrealScienceLibrary.UIElement element in World.Elements)
            {
                if (element is Text2D)
                {
                    //Scripting.ScriptingManager.Parse("addText {0} {1} {2} {3} {4} {5}",
                    //    (element as Text2D).Text, );

                    Text2D t = element as Text2D;

                    //UnrealScienceScripting.AddSprite2D("back.jpg", (int)t.Position.X, (int)t.Position.Y, 1000, 500);

                    UnrealScienceScripting.AddText2D(t.Text, t.FontName, (int)t.Position.X, (int)t.Position.Y, (int)t.Scale.X, (int)t.Scale.Y, (int)t.FontSize);
                }
            }

            UnrealScienceScripting.InitializeUI();



            #endregion
        }
Exemplo n.º 14
0
        /// <summary>
        /// Serializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override byte[] Serialize(RuntimeTypeModel typeModel, List <Scene2DEntry> data,
                                            List <BoxF2D> boxes)
        {
            var icons     = new List <Icon2DEntry>();
            var images    = new List <Image2DEntry>();
            var lines     = new List <Line2DEntry>();
            var points    = new List <Point2DEntry>();
            var polygons  = new List <Polygon2DEntry>();
            var texts     = new List <Text2DEntry>();
            var lineTexts = new List <LineText2DEntry>();

            // build the collection object.
            var collection = new PrimitivesCollection();

            for (int idx = 0; idx < data.Count; idx++)
            {
                IScene2DPrimitive primitive = data[idx].Scene2DPrimitive;
                if (primitive is Icon2D)
                {
                    Icon2D icon = primitive as Icon2D;
                    icons.Add(Icon2DEntry.From(data[idx].Id, icon, _styleIndex.AddStyle(icon, data[idx].Layer)));
                }
                else if (primitive is Image2D)
                {
                    Image2D image = primitive as Image2D;
                    images.Add(Image2DEntry.From(data[idx].Id, image, _styleIndex.AddStyle(image, data[idx].Layer)));
                }
                else if (primitive is Line2D)
                {
                    Line2D line = primitive as Line2D;
                    lines.Add(Line2DEntry.From(data[idx].Id, line, _styleIndex.AddStyle(line, data[idx].Layer)));
                }
                else if (primitive is Point2D)
                {
                    Point2D point = primitive as Point2D;
                    points.Add(Point2DEntry.From(data[idx].Id, point, _styleIndex.AddStyle(point, data[idx].Layer)));
                }
                else if (primitive is Polygon2D)
                {
                    Polygon2D polygon = primitive as Polygon2D;
                    polygons.Add(Polygon2DEntry.From(data[idx].Id, polygon, _styleIndex.AddStyle(polygon, data[idx].Layer)));
                }
                else if (primitive is Text2D)
                {
                    Text2D text = primitive as Text2D;
                    texts.Add(Text2DEntry.From(data[idx].Id, text, _styleIndex.AddStyle(text, data[idx].Layer)));
                }
                else if (primitive is LineText2D)
                {
                    LineText2D lineText = primitive as LineText2D;
                    lineTexts.Add(LineText2DEntry.From(data[idx].Id, lineText, _styleIndex.AddStyle(lineText, data[idx].Layer)));
                }
                else
                {
                    throw new Exception("Primitive type not supported by serializer.");
                }
            }

            collection.Icons     = icons.ToArray();
            collection.Images    = images.ToArray();
            collection.Lines     = lines.ToArray();
            collection.Points    = points.ToArray();
            collection.Polygons  = polygons.ToArray();
            collection.Texts     = texts.ToArray();
            collection.LineTexts = lineTexts.ToArray();

            // create the memory stream.
            var stream = new MemoryStream();

            typeModel.Serialize(stream, collection);
            if (!_compress)
            {
                return(stream.ToArray());
            }
            return(GZipStream.CompressBuffer(stream.ToArray()));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Deserializes the actual data.
        /// </summary>
        /// <param name="typeModel"></param>
        /// <param name="data"></param>
        /// <param name="boxes"></param>
        /// <returns></returns>
        protected override List <Scene2DEntry> DeSerialize(RuntimeTypeModel typeModel, byte[] data,
                                                           out List <BoxF2D> boxes)
        {
            // decompress if needed.
            Stream stream = null;

            if (_compress)
            {
                stream = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
            }
            else
            { // uncompressed stream.
                stream = new MemoryStream(data);
            }

            // create the memory stream.
            var collection = typeModel.Deserialize(stream, null,
                                                   typeof(PrimitivesCollection)) as PrimitivesCollection;

            if (collection == null)
            {
                throw new Exception("Could not deserialize primitives.");
            }

            // create the collection
            var primitives = new List <Scene2DEntry>();

            if (collection.Icons != null)
            {
                foreach (var primitive in collection.Icons)
                {
                    Icon2DStyle style = _styleIndex.IconStyles[primitive.StyleId];
                    Icon2D      icon  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = icon
                    });
                }
            }
            if (collection.Images != null)
            {
                foreach (var primitive in collection.Images)
                {
                    Image2DStyle style = _styleIndex.ImageStyles[primitive.StyleId];
                    Image2D      image = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = image
                    });
                }
            }
            if (collection.Lines != null)
            {
                foreach (var primitive in collection.Lines)
                {
                    Line2DStyle style = _styleIndex.LineStyles[primitive.StyleId];
                    Line2D      line  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = line
                    });
                }
            }
            if (collection.Points != null)
            {
                foreach (var primitive in collection.Points)
                {
                    Point2DStyle style = _styleIndex.PointStyles[primitive.StyleId];
                    Point2D      point = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = point
                    });
                }
            }
            if (collection.Polygons != null)
            {
                foreach (var primitive in collection.Polygons)
                {
                    Polygon2DStyle style   = _styleIndex.PolygonStyles[primitive.StyleId];
                    Polygon2D      polygon = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = polygon
                    });
                }
            }
            if (collection.Texts != null)
            {
                foreach (var primitive in collection.Texts)
                {
                    Text2DStyle style = _styleIndex.TextStyles[primitive.StyleId];
                    Text2D      text  = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = text
                    });
                }
            }
            if (collection.LineTexts != null)
            {
                foreach (var primitive in collection.LineTexts)
                {
                    LineText2DStyle style    = _styleIndex.LineTextStyles[primitive.StyleId];
                    LineText2D      lineText = primitive.To(style);
                    primitives.Add(new Scene2DEntry()
                    {
                        Id               = primitive.Id,
                        Layer            = style.Layer,
                        Scene2DPrimitive = lineText
                    });
                }
            }

            // build the boxes list.
            boxes = new List <BoxF2D>();
            for (int idx = 0; idx < primitives.Count; idx++)
            {
                boxes.Add(primitives[idx].Scene2DPrimitive.GetBox());
            }
            return(primitives);
        }
Exemplo n.º 16
0
 public void Render() => Text2D.render();