Exemplo n.º 1
0
        public override void Update(GameTime gameTime)
        {
            //Debug.WriteLine($"Running Movement Update on {ActiveEntities.Count} active entities.");
            foreach (var entity in ActiveEntities)
            {
                Player       player       = _playerComponentMapper.Get(entity);
                Velocity     velocity     = _velocityComponentMapper.Get(entity);
                FreePosition freeposition = _freePositionComponentMapper.Get(entity);

                KeyboardState kstate = Keyboard.GetState();

                //Player Movement Logic
                if (kstate.IsKeyDown(_keybinds.PlayerMoveUp))
                {
                    freeposition.position.Y -= velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveDown))
                {
                    freeposition.position.Y += velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveLeft))
                {
                    freeposition.position.X -= velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }

                if (kstate.IsKeyDown(_keybinds.PlayerMoveRight))
                {
                    freeposition.position.X += velocity.speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }
Exemplo n.º 2
0
        /// <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
            BoxingViewportAdapter viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, windowWidth, windowHeight);

            camera = new OrthographicCamera(viewportAdapter);
            CameraManager.mainCamera = camera;
            //Debug.WriteLine(camera.GetType());
            //Debug.WriteLine("Camera: " + camera.ToString());

            world = new WorldBuilder()
                    .AddSystem(new DynamicRenderSystem(GraphicsDevice))
                    .AddSystem(new PlayerMovementSystem(keybinds))
                    .Build();

            //Initialise Player Entity
            player = world.CreateEntity();
            FreePosition playerposition = new FreePosition();
            Velocity     playerspeed    = new Velocity();

            playerposition.position = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
            playerspeed.speed       = 100f;
            player.Attach(playerposition);
            player.Attach(playerspeed);
            player.Attach(new Player());

            Content.RootDirectory = "Content";
            gui = new GuiManager(Content, graphics, GraphicsDevice);
            gui.activatePlayMenu();



            //this.IsMouseVisible = true;

            base.Initialize();
            initialisationComplete = true;
        }
Exemplo n.º 3
0
        protected virtual void SetupXtraChartAnnotation(TextAnnotation annotation)
        {
            AnchorDockPane = Pane ?? AnchorDockPane;

            //Need this to link annotation to series point in BoundDataChanged
            annotation.Tag = this;

            if (!string.IsNullOrWhiteSpace(Name))
            {
                annotation.Name = Name;
            }

            annotation.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;

            if (Angle.HasValue)
            {
                annotation.Angle = Angle.Value;
            }

            var backColor = Utils.ColorFromString(BackColor);

            if (backColor != Color.Empty)
            {
                annotation.BackColor = backColor;
            }

            var borderColor = Utils.ColorFromString(BorderColor);

            if (borderColor != Color.Empty)
            {
                annotation.Border.Color      = borderColor;
                annotation.Border.Visibility = DevExpress.Utils.DefaultBoolean.True;
            }
            if (BorderThickness.HasValue)
            {
                annotation.Border.Thickness  = BorderThickness.Value;
                annotation.Border.Visibility = DevExpress.Utils.DefaultBoolean.True;
            }
            if (BorderVisible.HasValue)
            {
                annotation.Border.Visibility = BorderVisible.Value ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.Default;
            }

            if (FillMode.HasValue)
            {
                annotation.FillStyle.FillMode = FillMode.Value;
                switch (FillMode.Value)
                {
                case DevExpress.XtraCharts.FillMode.Empty:
                    break;

                case DevExpress.XtraCharts.FillMode.Solid:
                    break;

                case DevExpress.XtraCharts.FillMode.Gradient:
                    if (annotation.FillStyle.Options is RectangleGradientFillOptions gradientOptions)
                    {
                        var backColor2 = Utils.ColorFromString(BackColor2);
                        if (backColor2 != System.Drawing.Color.Empty)
                        {
                            gradientOptions.Color2 = backColor2;
                        }
                        if (FillGradientMode.HasValue)
                        {
                            gradientOptions.GradientMode = FillGradientMode.Value;
                        }
                    }
                    break;

                case DevExpress.XtraCharts.FillMode.Hatch:
                    if (annotation.FillStyle.Options is HatchFillOptions hatchOptions)
                    {
                        var backColor2 = Utils.ColorFromString(BackColor2);
                        if (backColor2 != System.Drawing.Color.Empty)
                        {
                            hatchOptions.Color2 = backColor2;
                        }
                        if (FillHatchStyle.HasValue)
                        {
                            hatchOptions.HatchStyle = FillHatchStyle.Value;
                        }
                    }
                    break;
                }
            }

            var font = Utils.StringToFont(Font, out Color textColor);

            if (font != null)
            {
                annotation.Font = font;
            }
            if (textColor != Color.Empty)
            {
                annotation.TextColor = textColor;
            }

            if (ConnectorStyle.HasValue)
            {
                annotation.ConnectorStyle = ConnectorStyle.Value;
            }

            if (Width.HasValue)
            {
                annotation.Width    = Width.Value;
                annotation.AutoSize = false;
            }
            if (Height.HasValue)
            {
                annotation.Height   = Height.Value;
                annotation.AutoSize = false;
            }

            if (Padding != null && Padding.Length == 1)
            {
                annotation.Padding.All = Padding[0];
            }
            else if (Padding != null && Padding.Length == 4)
            {
                annotation.Padding.Left   = Padding[0];
                annotation.Padding.Top    = Padding[1];
                annotation.Padding.Right  = Padding[2];
                annotation.Padding.Bottom = Padding[3];
            }
            else if (Padding != null)
            {
                throw new Exception("Invalid padding. Padding shall be an array with 1 or 4 integer values.");
            }

            var shadowColor = Utils.ColorFromString(ShadowColor);

            if (shadowColor != Color.Empty)
            {
                annotation.Shadow.Color   = shadowColor;
                annotation.Shadow.Visible = true;
            }
            if (ShadowSize.HasValue)
            {
                annotation.Shadow.Size    = ShadowSize.Value;
                annotation.Shadow.Visible = true;
            }

            if (ShapeFillet.HasValue)
            {
                annotation.ShapeFillet = ShapeFillet.Value;
            }
            if (ShapeKind.HasValue)
            {
                annotation.ShapeKind = ShapeKind.Value;
            }

            annotation.LabelMode = LabelMode;

            if (AnchorAngle.HasValue || AnchorConnectorLength.HasValue)
            {
                annotation.ShapePosition = new RelativePosition(AnchorAngle ?? 0.0, AnchorConnectorLength ?? 0.0);
            }
            else if (AnchorDockCorner.HasValue)
            {
                XYDiagramPane pane = null;
                if (!string.IsNullOrWhiteSpace(AnchorDockPane))
                {
                    if (ChartContext.Chart.Diagram is not XYDiagram2D diagramXY)
                    {
                        throw new Exception("Panes are available only in 2D XY charts.");
                    }

                    pane = diagramXY.Panes[AnchorDockPane];
                    if (pane == null)
                    {
                        throw new Exception($"Cannot find pane '{AnchorDockPane}'.");
                    }
                }

                var freePosition = new FreePosition();
                if (pane != null)
                {
                    freePosition.DockTarget = pane;
                }
                freePosition.DockCorner = AnchorDockCorner.Value;

                if (DockInnerIndents != null && DockInnerIndents.Length == 1)
                {
                    freePosition.InnerIndents.All = DockInnerIndents[0];
                }
                else if (DockInnerIndents != null && DockInnerIndents.Length == 4)
                {
                    freePosition.InnerIndents.Left   = DockInnerIndents[0];
                    freePosition.InnerIndents.Top    = DockInnerIndents[1];
                    freePosition.InnerIndents.Right  = DockInnerIndents[2];
                    freePosition.InnerIndents.Bottom = DockInnerIndents[3];
                }

                if (DockOuterIndents != null && DockOuterIndents.Length == 1)
                {
                    freePosition.OuterIndents.All = DockOuterIndents[0];
                }
                else if (DockOuterIndents != null && DockOuterIndents.Length == 4)
                {
                    freePosition.OuterIndents.Left   = DockOuterIndents[0];
                    freePosition.OuterIndents.Top    = DockOuterIndents[1];
                    freePosition.OuterIndents.Right  = DockOuterIndents[2];
                    freePosition.OuterIndents.Bottom = DockOuterIndents[3];
                }

                annotation.ShapePosition = freePosition;
            }

            annotation.Text    = Text;
            annotation.Visible = true;
            if (TextAlignment.HasValue)
            {
                annotation.TextAlignment = TextAlignment.Value;
            }
            if (ZOrder.HasValue)
            {
                annotation.ZOrder = ZOrder.Value;
            }

            switch (ParameterSetName)
            {
            case "Chart":
                annotation.AnchorPoint = new ChartAnchorPoint(X, Y);
                break;

            case "Pane":
                if (ChartContext.Chart.Diagram is not XYDiagram diagramXY)
                {
                    throw new Exception("Panes are available only in 2D XY charts.");
                }

                var anchor = new PaneAnchorPoint();

                if (!string.IsNullOrWhiteSpace(AnchorDockPane))
                {
                    var pane = diagramXY.Panes[AnchorDockPane];
                    anchor.Pane = pane ?? throw new Exception($"Cannot find pane '{AnchorDockPane}'.");
                }

                var axisX = !string.IsNullOrWhiteSpace(AxisX) ? diagramXY.FindAxisXByName(AxisX) : diagramXY.AxisX;
                var axisY = !string.IsNullOrWhiteSpace(AxisY) ? diagramXY.FindAxisYByName(AxisY) : diagramXY.AxisY;

                anchor.AxisXCoordinate.Axis      = axisX;
                anchor.AxisXCoordinate.AxisValue = ValueX;

                anchor.AxisYCoordinate.Axis      = axisY;
                anchor.AxisYCoordinate.AxisValue = ValueY;
                break;
            }
        }
Exemplo n.º 4
0
        private void chartMain_MouseUp(object sender, MouseEventArgs e)
        {
            if (chartMain.Series.Count <= 0)
            {
                return;
            }


            switch (CETCManagerApp.Instance.ToolByttonNowStatu)
            {
            case ToolButtonDrawType.None:
                break;

            case ToolButtonDrawType.LABEL:
                if (e.Button == MouseButtons.Left)
                {
                    TextAnnotation     annotation = new TextAnnotation("Annotation" + (++CETCManagerApp.Instance.LabelCount).ToString(), "標籤" + (++CETCManagerApp.Instance.LabelIndex).ToString());
                    DiagramCoordinates point      = MainDiagram.PointToDiagram(e.Location);
                    annotation.AnchorPoint = new PaneAnchorPoint();
                    ((PaneAnchorPoint)annotation.AnchorPoint).AxisXCoordinate.AxisValue = point.NumericalArgument;
                    ((PaneAnchorPoint)annotation.AnchorPoint).AxisYCoordinate.AxisValue = point.NumericalValue;
                    annotation.ShapePosition = new FreePosition();
                    FreePosition position = annotation.ShapePosition as FreePosition;
                    position.InnerIndents.Left = e.X + 5;
                    position.InnerIndents.Top  = e.Y - annotation.Height - 5;
                    chartMain.AnnotationRepository.Add((TextAnnotation)annotation.Clone());
                    Main_Form.Instance.SetToolButtonStatu(ToolButtonDrawType.None);
                    CETCManagerApp.Instance.m_pETETCStage.m_ETCNotes.Add(annotation);
                }
                else if (e.Button == MouseButtons.Right)
                {
                }
                break;

            case ToolButtonDrawType.SLOP:
                if (e.Button == MouseButtons.Left)
                {
                    if (NowSeries == null)
                    {
                        var slope = new Series("Slope" + (++CETCManagerApp.Instance.SlopesCount).ToString(), ViewType.Line);

                        //slope.View.Color = Color.Red;
                        ((LineSeriesView)slope.View).LineStyle.Thickness = 2;
                        //((LineSeriesView)slope.View).ColorEach = true;
                        ((LineSeriesView)slope.View).MarkerVisibility = DefaultBoolean.True;

                        DiagramCoordinates point = MainDiagram.PointToDiagram(e.Location);

                        slope.Points.Add(new SeriesPoint(point.NumericalArgument, point.NumericalValue));
                        slope.Points.Add(new SeriesPoint(point.NumericalArgument, point.NumericalValue));
                        //slope.LabelsVisibility = DefaultBoolean.True;
                        slope.Label.Border.Visibility = DefaultBoolean.True;
                        slope.CrosshairEnabled        = DefaultBoolean.False;
                        slope.Visible         = true;
                        slope.Label.TextColor = Color.Black;
                        slope.ShowInLegend    = false;
                        slope.Points[0].Color = slope.View.Color;
                        slope.Points[0].Annotations.AddTextAnnotation(slope.Name, "12345");
                        slope.Points[1].Color = slope.View.Color;
                        slope.Tag             = new SuperTag()
                        {
                            SeriesIsDrawDown = true
                        };
                        CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes.Add(slope);
                        NowSlopeIndex = CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes.Count - 1;
                        var cloneSlope = (Series)slope.Clone();
                        cloneSlope.Points[0].Annotations.AddTextAnnotation(slope.Name, "12345");
                        basePoint     = cloneSlope.Points[0];
                        selectedPoint = cloneSlope.Points[1];
                        chartMain.Series.Add(cloneSlope);
                        NowSeries = cloneSlope;
                        //chartMain.CustomDrawSeriesPoint += chartMain_CustomDrawSeriesPoint;
                    }
                    else
                    {
                        CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes[NowSlopeIndex].Points.RemoveAt(1);
                        CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes[NowSlopeIndex].Points.Add(new SeriesPoint(selectedPoint.NumericalArgument, selectedPoint.Values[0]));
                        ((TextAnnotation)CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes[NowSlopeIndex].Points[0].Annotations[0]).Text = ((TextAnnotation)basePoint.Annotations[0]).Text;
                        ((SuperTag)CETCManagerApp.Instance.m_pETETCStage.m_ETCSlopes[NowSlopeIndex].Tag).SeriesLabelString = ((TextAnnotation)basePoint.Annotations[0]).Text;
                        ((SuperTag)NowSeries.Tag).SeriesIsDrawDown = false;
                        NowSeries     = null;
                        selectedPoint = null;
                        Main_Form.Instance.SetToolButtonStatu(ToolButtonDrawType.None);
                        //chartMain.CustomDrawSeriesPoint -= chartMain_CustomDrawSeriesPoint;
                    }
                }
                break;

            default:
                break;
            }
        }