示例#1
0
文件: TileMenu.cs 项目: teamstor/aod
        public TileMenu(Map.Environment environment, Engine.Game game)
        {
            _environment = environment;
            Game         = game;

            Rectangle   = new TweenedRectangle(game, new Rectangle(0, 0, (int)TotalArea.X, 28));
            _screenFade = new TweenedDouble(game, 0);

            Recreate();
        }
示例#2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Game teamStorGame = new Game(new PlayingState(new NukeField(9, 9, 10)));

            SetContentView((View)teamStorGame.Services.GetService(typeof(View)));

            SystemUiFlags uiOptions = SystemUiFlags.HideNavigation |
                                      SystemUiFlags.LayoutHideNavigation |
                                      SystemUiFlags.Fullscreen |
                                      SystemUiFlags.LayoutStable |
                                      SystemUiFlags.LowProfile |
                                      SystemUiFlags.Immersive |
                                      SystemUiFlags.ImmersiveSticky;

            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;

            teamStorGame.Stats |= Game.DebugStats.FPS;
            //teamStorGame.Stats |= Game.DebugStats.General;
            teamStorGame.Run();
        }
示例#3
0
文件: TileMenu.cs 项目: teamstor/aod
        public void Update(Game game)
        {
            if (!Disabled && ((Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition)) || (Game.Input.KeyPressed(Keys.S) && !_isSearching)))
            {
                Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, Math.Min((int)TotalArea.Y, MaxHeight)), TweenEaseType.EaseOutQuad, 0.1f);
                _screenFade.TweenTo(1, TweenEaseType.EaseOutQuad, 0.1f);

                if (Game.Input.KeyPressed(Keys.S))
                {
                    _isSearching = true;
                    _quitQueued  = true;

                    TextInputEXT.TextInput += OnSearchInput;
                    TextInputEXT.StartTextInput();
                    game.OnStateChange += RemoveSearchInput;
                }
            }
            else if (_quitQueued || (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition)))
            {
                if (_isScrolling || _isSearching)
                {
                    _quitQueued = true;
                }
                else
                {
                    if (!Rectangle.Value.Contains(game.Input.MousePosition))
                    {
                        Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, 28), TweenEaseType.EaseOutQuad, 0.1f);
                        _screenFade.TweenTo(0, TweenEaseType.EaseOutQuad, 0.1f);
                    }

                    _quitQueued = false;
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Tab))
            {
                string s = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(s, category);

                    if (searched != null)
                    {
                        _searchTerm = searched.Name(null, _environment);
                        break;
                    }
                }
            }

            if (_isSearching && game.Input.KeyPressed(Keys.Enter))
            {
                _searchTerm = _searchTerm.ToLowerInvariant().Trim().Replace(" ", "");

                foreach (Category category in Categories)
                {
                    Tile searched = Search(_searchTerm, category);
                    if (searched != null)
                    {
                        SelectedTile = searched;
                        if (SelectionChanged != null)
                        {
                            SelectionChanged(this, SelectedTile);
                        }
                    }
                }

                _isSearching = false;
                _searchTerm  = "";

                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }
            else if (_isSearching && game.Input.KeyPressed(Keys.Escape))
            {
                _isSearching            = false;
                _searchTerm             = "";
                TextInputEXT.TextInput -= OnSearchInput;
                TextInputEXT.StopTextInput();
                game.OnStateChange -= RemoveSearchInput;
            }

            if (IsHovered && CanInteractWith)
            {
                float changed = _scrollTarget;

                if (game.Input.KeyPressed(Keys.Home))
                {
                    _scrollTarget = 0;
                }

                if (game.Input.KeyPressed(Keys.PageUp))
                {
                    _scrollTarget = Scroll - 180;
                }
                if (game.Input.KeyPressed(Keys.PageDown))
                {
                    _scrollTarget = Scroll + 180;
                }

                if (game.Input.KeyPressed(Keys.End))
                {
                    _scrollTarget = ScrollableAmount;
                }

                if (changed != _scrollTarget)
                {
                    if (_scrollTarget < 0)
                    {
                        _scrollTarget = 0;
                    }
                    if (_scrollTarget > ScrollableAmount)
                    {
                        _scrollTarget = ScrollableAmount;
                    }
                }
            }

            if (CanInteractWith)
            {
                if (_scrollTarget != -1)
                {
                    Scroll = MathHelper.Lerp(Scroll, _scrollTarget, (float)Game.DeltaTime * 14f);
                    if (Math.Abs(Scroll - _scrollTarget) <= 0.75f)
                    {
                        _scrollTarget = -1;
                    }
                }
                else if (Rectangle.Value.Contains(game.Input.MousePosition))
                {
                    if ((game.Input.MouseScroll < 0 && Scroll < ScrollableAmount) ||
                        (game.Input.MouseScroll > 0 && Scroll > 0))
                    {
                        Scroll -= game.Input.MouseScroll / 4f;
                    }

                    if (game.Input.Key(Keys.Up) && Scroll > 0)
                    {
                        Scroll = Math.Max(0, Scroll - ((float)game.DeltaTime * 140f));
                    }
                    if (game.Input.Key(Keys.Down) && Scroll < ScrollableAmount)
                    {
                        Scroll = Math.Min(ScrollableAmount, Scroll + ((float)game.DeltaTime * 140f));
                    }
                }

                if (_isScrolling)
                {
                    float at         = game.Input.MousePosition.Y - (Rectangle.Value.Top + 8);
                    float percentage = at / (Rectangle.Value.Height - 16);
                    Scroll = percentage * ScrollableAmount;

                    if (game.Input.MouseReleased(Engine.MouseButton.Left))
                    {
                        _isScrolling = false;
                    }
                }

                Scroll = MathHelper.Clamp(Scroll, 0, ScrollableAmount);
            }
        }
示例#4
0
        /// <summary>
        /// Draws this map.
        /// </summary>
        /// <param name="layer">Layer to draw.</param>
        /// <param name="game">Game class.</param>
        /// <param name="rectangle">The cropped part of the map to draw. null - draw whole map</param>
        public void Draw(Tile.MapLayer layer, Game game, Rectangle?rectangle = null)
        {
            if (Atlas != null && Atlas.Game != game)
            {
                Atlas.Dispose();
                Atlas = null;
            }

            if (Atlas == null)
            {
                Atlas = new TileAtlas(game);
            }

            if (TransitionCache != null && TransitionCache.Game != game)
            {
                TransitionCache.Dispose();
                TransitionCache = null;
            }

            if (TransitionCache == null)
            {
                TransitionCache = new TileTransitionCache(game);
            }

            int xMin = 0;
            int yMin = 0;
            int xMax = Width - 1;
            int yMax = Height - 1;

            if (rectangle.HasValue)
            {
                xMin = Math.Max(0, (int)Math.Floor(rectangle.Value.X / 16.0));
                yMin = Math.Max(0, (int)Math.Floor(rectangle.Value.Y / 16.0));
                xMax = Math.Min(Width - 1, (int)Math.Ceiling((rectangle.Value.X + rectangle.Value.Width - 1) / 16.0));
                yMax = Math.Min(Height - 1, (int)Math.Ceiling((rectangle.Value.Y + rectangle.Value.Height - 1) / 16.0));
            }

            // Add one more to allow for transitions outside the rectangle.
            if (xMin > 0)
            {
                xMin--;
            }
            if (yMin > 0)
            {
                yMin--;
            }

            if (xMax < Width - 1)
            {
                xMax++;
            }
            if (yMax < Height - 1)
            {
                yMax++;
            }

            Rectangle drawRectangle = new Rectangle(xMin, yMin, xMax - xMin, yMax - yMin);

            drawRectangle.X      *= 16;
            drawRectangle.Y      *= 16;
            drawRectangle.Width  *= 16;
            drawRectangle.Height *= 16;
            drawRectangle.Width  += 16;
            drawRectangle.Height += 16;

            if (layer == Tile.MapLayer.Terrain)
            {
                (WaterTiles.DeepWaterOrVoid as AnimatedTile).UpdateCurrentFrameWithGame(game, new Point(0, 0));

                if (Info.Environment == Environment.Inside)
                {
                    game.Batch.Rectangle(drawRectangle, Color.Black);
                }
                else
                {
                    game.Batch.Texture(drawRectangle, game.Assets.Get <Texture2D>(WaterTiles.DeepWaterOrVoid.TextureName()), Color.White, drawRectangle);
                }
            }

            int x, y;

            for (x = xMin; x <= xMax; x++)
            {
                for (y = yMin; y <= yMax; y++)
                {
                    Tile tile = this[layer, x, y];
                    if (tile.ID != "") // water will be drawn by the map manually here
                    {
                        tile.Draw(game, new Point(x, y), this, GetMetadata(layer, x, y), Info.Environment);
                    }
                }
            }

            for (x = xMin; x <= xMax; x++)
            {
                for (y = yMin; y <= yMax; y++)
                {
                    Tile tile = this[layer, x, y];
                    if (layer == Tile.MapLayer.Terrain || tile.ID != "")
                    {
                        Point p1 = new Point(x - 1, y);
                        Point p2 = new Point(x + 1, y);
                        Point p3 = new Point(x, y - 1);
                        Point p4 = new Point(x, y + 1);

                        for (int i = 0; i < 4; i++)
                        {
                            Point point = i == 0 ? p1 :
                                          i == 1 ? p2 :
                                          i == 2 ? p3 :
                                          p4;

                            if (point.X >= 0 && point.Y >= 0 && point.X < Width && point.Y < Height &&
                                tile.UseTransition(
                                    new Point(x, y),
                                    point,
                                    this,
                                    this[layer, point.X, point.Y],
                                    GetMetadata(layer, x, y),
                                    GetMetadata(layer, point.X, point.Y)))
                            {
                                Point     transitionPoint;
                                Texture2D transitionTexture = TransitionCache.TextureForTile(
                                    tile,
                                    GetMetadata(layer, x, y),
                                    Info.Environment,
                                    out transitionPoint);

                                float         rotation = 0;
                                SpriteEffects effects  = SpriteEffects.None;

                                if (point == new Point(x + 1, y))
                                {
                                    effects = SpriteEffects.FlipHorizontally;
                                }
                                if (point == new Point(x, y - 1))
                                {
                                    rotation = MathHelper.PiOver2;
                                }
                                if (point == new Point(x, y + 1))
                                {
                                    rotation = MathHelper.Pi + MathHelper.PiOver2;
                                }

                                Rectangle textureRectangle = new Rectangle(
                                    transitionPoint.X * 16,
                                    transitionPoint.Y * 16,
                                    16,
                                    16);

                                game.Batch.Texture(
                                    new Vector2(
                                        point.X * 16 + (rotation == MathHelper.PiOver2 ? 16 : 0),
                                        point.Y * 16 + (rotation == MathHelper.Pi + MathHelper.PiOver2 ? 16 : 0)),
                                    transitionTexture,
                                    Color.White,
                                    Vector2.One,
                                    textureRectangle,
                                    rotation,
                                    null,
                                    effects);
                            }
                        }
                    }
                }
            }

            for (x = xMin; x <= xMax; x++)
            {
                for (y = yMin; y <= yMax; y++)
                {
                    Tile tile = this[layer, x, y];
                    if (layer == Tile.MapLayer.Terrain || tile.ID != "")
                    {
                        tile.DrawAfterTransition(game, new Point(x, y), this, GetMetadata(layer, x, y), Info.Environment);
                    }
                }
            }
        }