示例#1
0
        public override void Idle(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Idle(gameTime);

            if (Simulation == null)
            {
                MenuBar.GetItem("Edit").Enabled       = false;
                MenuBar.GetItem("Simulation").Enabled = false;
                MenuBar.GetItem("Entities").Enabled   = false;
                MenuBar.GetItem("World").Enabled      = false;
            }
            else
            {
                MenuBar.GetItem("Edit").Enabled       = true;
                MenuBar.GetItem("Simulation").Enabled = true;
                MenuBar.GetItem("Entities").Enabled   = true;
                MenuBar.GetItem("World").Enabled      = true;
            }

            if (Mode == Modes.AddEntity)
            {
                if (WorldBox.IsUnderMouse && MouseInput.IsClicked(TakaGUI.Services.MouseButtons.Left))
                {
                    var entity = GetEntityFunction();

                    var pos = new EntityPosition();
                    pos.X           = (MouseInput.X - WorldBox.RealX + WorldBox.ViewCamera.LookX) / WorldBox.ViewCamera.Zoom;
                    pos.Y           = (MouseInput.Y - WorldBox.RealY + WorldBox.ViewCamera.LookY) / WorldBox.ViewCamera.Zoom;
                    entity.Position = pos;

                    WorldBox.World.AddEntity(entity);
                }
                else if (WorldBox.IsUnderMouse && MouseInput.IsClicked(TakaGUI.Services.MouseButtons.Right))
                {
                    Mode = Modes.None;
                }
            }
            else if (Mode == Modes.SetPeremiter)
            {
                if (MouseInput.IsClicked(TakaGUI.Services.MouseButtons.Left))
                {
                    var c = p1;
                    p1 = p2;
                    p2 = c;
                }
                else if (MouseInput.IsClicked(TakaGUI.Services.MouseButtons.Right))
                {
                    Mode = Modes.None;
                    var peremiter = new Rectangle();
                    peremiter.X      = Math.Min(p1.X, p2.X);
                    peremiter.Y      = Math.Min(p1.Y, p2.Y);
                    peremiter.Width  = Math.Max(p1.X, p2.X) - peremiter.X;
                    peremiter.Height = Math.Max(p1.Y, p2.Y) - peremiter.Y;

                    SendPeremiterFunction(peremiter);
                }

                p1 = new Point(MouseInput.X, MouseInput.Y);
            }
        }