Esempio n. 1
0
        public int Hovered(Game game)
        {
            int y = Rectangle.Value.Y + 15 + 12;

            for (int i = 0; i < Entries.Count; i++)
            {
                string s = Entries[i];

                if (s == SPACING)
                {
                    y += 8;
                }
                else
                {
                    Vector2   measure   = game.DefaultFonts.Bold.Measure(15, s);
                    Rectangle rectangle = new Rectangle(Rectangle.Value.X, y, Rectangle.Value.Width, (int)measure.Y);

                    if (rectangle.Contains(game.Input.MousePosition))
                    {
                        return(i);
                    }

                    y += 15 + 4;
                }
            }

            return(-1);
        }
Esempio n. 2
0
        public void Draw(Game game)
        {
            game.Batch.Scissor = Rectangle;

            game.Batch.Rectangle(Rectangle, Color.Black * 0.85f);

            Vector2 measure = game.DefaultFonts.Bold.Measure(15, Title);

            game.Batch.Text(SpriteBatch.FontStyle.Bold, 15, Title, new Vector2(Rectangle.Value.X + 8, Rectangle.Value.Y + 4),
                            Color.White * (Rectangle.Value.Contains(game.Input.MousePosition) ? 1.0f : 0.6f));

            int y = Rectangle.Value.Y + 15 + 12;

            foreach (string s in Entries)
            {
                if (s == SPACING)
                {
                    y += 8;
                }
                else
                {
                    measure = game.DefaultFonts.Bold.Measure(15, s);
                    Rectangle rectangle = new Rectangle(Rectangle.Value.X, y, Rectangle.Value.Width, (int)measure.Y);

                    bool hovered = rectangle.Contains(game.Input.MousePosition);

                    game.Batch.Text(SpriteBatch.FontStyle.Bold, 15, s, new Vector2(Rectangle.Value.X + 8, y),
                                    Color.White * (s == SelectedValue ? 0.8f : hovered ? 0.6f : 0.4f));
                    y += 15 + 4;
                }
            }

            game.Batch.Scissor = null;
        }
Esempio n. 3
0
        public void Update(Game game)
        {
            if (Game.Input.MousePressed(MouseButton.Left))
            {
                if (LeftButtonRectangle.Contains(Game.Input.MousePosition))
                {
                    Choice--;
                    if (Choice < (Choices == null ? MinValue : 0))
                    {
                        Choice = Choices == null ? MaxValue : Choices.Length - 1;
                    }

                    if (ChoiceChanged != null)
                    {
                        ChoiceChanged(this, Choice, Choices == null ? Choice.ToString() : Choices[Choice]);
                    }
                }

                if (RightButtonRectangle.Contains(Game.Input.MousePosition))
                {
                    Choice++;
                    if (Choice > (Choices == null ? MaxValue : Choices.Length - 1))
                    {
                        Choice = Choices == null ? MinValue : 0;
                    }

                    if (ChoiceChanged != null)
                    {
                        ChoiceChanged(this, Choice, Choices == null ? Choice.ToString() : Choices[Choice]);
                    }
                }
            }
        }
Esempio n. 4
0
        private static void Main()
        {
            // initalize input map before settings
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(InputMap).TypeHandle);
            Settings.Load();

            Game game = Game.Run(new PreloaderState(), "data", true);

            if (game.Fullscreen != Settings.Fullscreen)
            {
                game.Fullscreen = Settings.Fullscreen;
            }

            if (game.VSync != Settings.VSync)
            {
                game.VSync = Settings.VSync;
            }

            MediaPlayer.Volume = MathHelper.Clamp((float)(Settings.MasterVolume / 100f * Settings.MusicVolume / 100f), 0.0f, 1.0f);

            // makes sure all tiles and npcs are available at startup
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(DefaultTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(WaterTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(GroundTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(FoliageTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(ControlTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(InsideTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(CityTiles).TypeHandle);
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(NPCs).TypeHandle);

            game.OnUpdateAfterState += OnUpdate;

            if (System.Diagnostics.Debugger.IsAttached)
            {
                game.Run();
                game.OnUpdateAfterState -= OnUpdate;
                game.Dispose();
            }
            else
            {
                try
                {
                    game.Run();
                    game.OnUpdateAfterState -= OnUpdate;
                    game.Dispose();
                }
                catch (Exception e)
                {
                    game.OnUpdateAfterState -= OnUpdate;
                    game.Dispose();

                    Game recoveryGame = Game.Run(new CrashRecoveryState(game, e), "data", false);
                    recoveryGame.Run();
                    recoveryGame.Dispose();
                }
            }

            Settings.Save();
        }
Esempio n. 5
0
        public void Update(Game game)
        {
            bool hovered = (!Active || CanClickActive) && Rectangle.Contains(game.Input.MousePosition) && !Disabled;

            if (hovered && game.Input.MousePressed(MouseButton.Left) && Clicked != null)
            {
                Clicked(this);
            }
        }
Esempio n. 6
0
        public TileAtlas(Game game)
        {
            Game = game;
            Game.Assets.AssetChanged += OnAssetChanged;

            MissingRegion.Texture   = game.Assets.Get <Texture2D>("tiles/missing.png", true);
            MissingRegion.Rectangle = new Rectangle(0, 0, 16, 16);

            _atlases.Add(new Texture2D(game.GraphicsDevice, ATLAS_SIZE, ATLAS_SIZE));
        }
Esempio n. 7
0
        public void Update(Game game)
        {
            if (Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition))
            {
                int height = 15 + 12 + 4;
                foreach (string s in Entries)
                {
                    if (s == SPACING)
                    {
                        height += 8;
                    }
                    else
                    {
                        height += 15 + 4;
                    }
                }

                Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, Rectangle.TargetValue.Width, height), TweenEaseType.EaseOutQuad, 0.1f);
            }
            else if (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition))
            {
                Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, Rectangle.TargetValue.Width, 15 + 12), TweenEaseType.EaseOutQuad, 0.1f);
            }

            int y = Rectangle.Value.Y + 15 + 12;

            foreach (string s in Entries)
            {
                if (s == SPACING)
                {
                    y += 8;
                }
                else
                {
                    Vector2   measure   = game.DefaultFonts.Bold.Measure(15, s);
                    Rectangle rectangle = new Rectangle(Rectangle.Value.X, y, Rectangle.Value.Width, (int)measure.Y);

                    if (SelectedValue != s && Rectangle.Value.Contains(game.Input.MousePosition) && rectangle.Contains(game.Input.MousePosition) && game.Input.MousePressed(MouseButton.Left))
                    {
                        Selected = Entries.IndexOf(s);

                        if (SelectionChanged != null)
                        {
                            SelectionChanged(this, Selected);
                        }
                    }

                    y += 15 + 4;
                }
            }
        }
Esempio n. 8
0
        public void Draw(Game game)
        {
            bool        hovered = Rectangle.Contains(game.Input.MousePosition);
            SpriteBatch batch   = game.Batch;

            batch.Rectangle(Rectangle, Color.Black * 0.8f);

            if (Icon != null)
            {
                batch.Texture(new Vector2(Position.Value.X + 4, Position.Value.Y + 4), Icon, TextColor * (Focused ? 1.0f : hovered ? 0.8f : 0.6f));
            }

            batch.Text(Font, 15,
                       Label + Text + (Focused && (int)((game.Time * 4) % 2) == 0 ? "|" : ""),
                       new Vector2(Position.Value.X + (Icon != null ? Icon.Width + 8 : 8), Position.Value.Y + 6),
                       TextColor * (Focused ? 1.0f : hovered ? 0.8f : 0.6f));
        }
Esempio n. 9
0
        public void Draw(Game game)
        {
            SpriteBatch batch   = game.Batch;
            bool        hovered = (Active || Rectangle.Contains(game.Input.MousePosition)) && !Disabled;

            batch.Rectangle(Rectangle, Color.Black * 0.8f * Alpha);

            if (Icon != null)
            {
                batch.Texture(new Vector2(Position.Value.X + 4, Position.Value.Y + 4), Icon, Color.White * (hovered ? 1f : 0.6f) * Alpha * (Disabled ? 0.6f : 1.0f));
            }

            if (Text != "")
            {
                batch.Text(Font, 15, Text, new Vector2(Position.Value.X + (Icon != null ? Icon.Width + 8 : 8), Position.Value.Y + 6), Color.White * (hovered ? 1f : 0.6f) * Alpha * (Disabled ? 0.6f : 1.0f));
            }
        }
Esempio n. 10
0
        public void Update(Game game)
        {
            if (_first)
            {
                TextInputEXT.TextInput += OnTextInput;
                TextInputEXT.StartTextInput();
                game.OnStateChange += OnStateChange;
                _first              = false;
            }

            if (game.Input.MousePressed(MouseButton.Left))
            {
                bool oldFocused = Focused;
                Focused = Rectangle.Contains(game.Input.MousePosition);

                if (Focused != oldFocused && FocusChanged != null)
                {
                    FocusChanged(this, Focused);
                }
            }
        }
Esempio n. 11
0
        public CrashRecoveryState(Game game, Exception e)
        {
            RecoveryGame = game;
            Exception    = e;

            if (game.CurrentState != null && game.CurrentState.GetType() == typeof(MapEditorState))
            {
                _recoveryState = RecoveryState.Recovering;
                Task.Run(() =>
                {
                    try
                    {
                        _mapTempSaveName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).Replace("\\", "/") + "/" + new Random().Next() + ".json";
                        ((MapEditorState)game.CurrentState).Map.Save(File.OpenWrite(_mapTempSaveName));
                        _recoveryState = RecoveryState.RecoveredMapData;
                    }
                    catch
                    {
                        _recoveryState = RecoveryState.Nothing;
                    }
                });
            }
        }
Esempio n. 12
0
        public void Draw(Game game)
        {
            bool        hovered = Rectangle.Contains(game.Input.MousePosition);
            SpriteBatch batch   = game.Batch;

            batch.Rectangle(Rectangle, Color.Black * 0.8f);

            if (Icon != null)
            {
                batch.Texture(new Vector2(Position.Value.X + 4, Position.Value.Y + 4), Icon, TextColor * 0.6f);
            }

            batch.Text(Font, 15,
                       Label,
                       new Vector2(Position.Value.X + (Icon != null ? Icon.Width + 8 : 8), Position.Value.Y + 6),
                       TextColor * 0.6f);

            batch.Texture(new Rectangle(LeftButtonRectangle.X + 4, LeftButtonRectangle.Y + 4, 24, 24),
                          Game.Assets.Get <Texture2D>("editor/arrow.png"),
                          Color.White * (LeftButtonRectangle.Contains(Game.Input.MousePosition) ? Game.Input.Mouse(MouseButton.Left) ? 1.0f : 0.8f : 0.6f),
                          null, 0, null, SpriteEffects.FlipHorizontally);
            batch.Texture(new Rectangle(RightButtonRectangle.X + 4, RightButtonRectangle.Y + 4, 24, 24),
                          Game.Assets.Get <Texture2D>("editor/arrow.png"),
                          Color.White * (RightButtonRectangle.Contains(Game.Input.MousePosition) ? Game.Input.Mouse(MouseButton.Left) ? 1.0f : 0.8f : 0.6f));

            Vector2 measure = Font.Measure(13, Choices == null ? Choice.ToString() : Choices[Choice]);
            int     width   = RightButtonRectangle.X - (LeftButtonRectangle.X + LeftButtonRectangle.Width);

            width -= 8;
            Rectangle rect = new Rectangle(LeftButtonRectangle.X + LeftButtonRectangle.Width + 4, LeftButtonRectangle.Y, width, 32);

            batch.Text(Font, 13,
                       Choices == null ? Choice.ToString() : Choices[Choice],
                       new Vector2(rect.X + rect.Width / 2 - measure.X / 2, Position.Value.Y + 7),
                       TextColor * 0.6f);
        }
Esempio n. 13
0
 public TileTransitionCache(Game game)
 {
     Game = game;
     Game.Assets.AssetChanged += OnAssetChanged;
 }
Esempio n. 14
0
        private static void OnUpdate(object sender, Game.UpdateEventArgs e)
        {
            Game game = sender as Game;

            if (game.Window.Title != "Age of Darkness")
            {
                game.Window.Title = "Age of Darkness";
            }

            if (Settings.Fullscreen != game.Fullscreen)
            {
                Settings.Fullscreen = game.Fullscreen;
            }

            if (Settings.VSync != game.VSync)
            {
                Settings.VSync = game.VSync;
            }

            MediaPlayer.Volume = MathHelper.Clamp((float)(Settings.MasterVolume / 100f * Settings.MusicVolume / 100f), 0.0f, 1.0f);

            if (game.Input.Key(Keys.LeftShift) &&
                game.Input.KeyPressed(Keys.F8) &&
                game.CurrentState.GetType() != typeof(MapEditorState) &&
                game.CurrentState.GetType() != typeof(PreloaderState) &&
                game.CurrentState.GetType() != typeof(TeamStorLogoState))
            {
                game.CurrentState = new MapEditorState();
            }

            if (game.Input.Key(Keys.LeftShift) &&
                game.Input.KeyPressed(Keys.F9) &&
                game.CurrentState.GetType() != typeof(OpenMapState) &&
                game.CurrentState.GetType() != typeof(PreloaderState) &&
                game.CurrentState.GetType() != typeof(TeamStorLogoState))
            {
                OpenMapState state = new OpenMapState();
                state.Game = game;
                GameState prevState = game.CurrentState;

                // do it manually so we don't call OnLeave in the other state
                typeof(Game).GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(game, state);
                state.OnEnter(prevState);
            }

            if (game.Input.Key(Keys.LeftShift) &&
                game.Input.KeyPressed(Keys.F10) &&
                game.CurrentState.GetType() != typeof(PreloaderState) &&
                game.CurrentState.GetType() != typeof(TeamStorLogoState))
            {
                switch (SDL2.SDL.SDL_GetPlatform())
                {
                case "Windows":
                    Process.Start(Settings.SettingsDirectory);
                    break;

                case "Linux":
                    Process.Start("xdg-open", "\"" + Settings.SettingsDirectory.Replace("\"", "\\\"") + "\"");
                    break;
                }
            }
        }
Esempio n. 15
0
        public void Update(Game game)
        {
            if (_first)
            {
                TextInputEXT.TextInput += OnTextInput;
                TextInputEXT.StartTextInput();
                game.OnStateChange += OnStateChange;
                _first              = false;

                RecalculateTotalArea();
            }

            if (game.Input.MousePressed(MouseButton.Left) || _defocusQueued)
            {
                if (_isScrollingX || _isScrollingY)
                {
                    if (!_defocusQueued)
                    {
                        _defocusQueued = true;
                    }
                }
                else
                {
                    _defocusQueued = false;
                    bool oldFocused = Focused;
                    Focused = Area.Value.Contains(game.Input.MousePosition);

                    if (Focused != oldFocused && FocusChanged != null)
                    {
                        FocusChanged(this, Focused);
                    }
                }
            }

            if (Area.Value.Contains(game.Input.MousePosition))
            {
                if ((game.Input.MouseScroll < 0 && Scroll.Y < ScrollableAmount.Y) ||
                    (game.Input.MouseScroll > 0 && Scroll.Y > 0))
                {
                    Scroll.Y -= game.Input.MouseScroll / 4f;
                }

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

            if (_isScrollingX)
            {
                float at         = game.Input.MousePosition.X - (Area.Value.Left + 8);
                float percentage = at / (Area.Value.Width - 16);
                Scroll.X = percentage * ScrollableAmount.X;

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


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

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

            Scroll = Vector2.Clamp(Scroll, Vector2.Zero, ScrollableAmount);
        }
Esempio n. 16
0
        public void Draw(Game game)
        {
            bool        hovered = Area.Value.Contains(game.Input.MousePosition);
            SpriteBatch batch   = game.Batch;

            batch.Scissor = Area.Value;

            batch.Rectangle(Area, Color.Black * 0.8f);

            Matrix oldTransform = game.Batch.Transform;

            game.Batch.Transform = Matrix.CreateTranslation(
                (int)-Scroll.X,
                (int)-Scroll.Y,
                0);

            if (Icon != null)
            {
                batch.Texture(new Vector2(Area.Value.X + 4, Area.Value.Y + 4), Icon, TextColor * (Focused ? 1.0f : hovered ? 0.8f : 0.6f));
            }

            batch.Text(Font, 15,
                       Label + Text + (Focused && (int)((game.Time * 4) % 2) == 0 ? "|" : ""),
                       new Vector2(Area.Value.X + (Icon != null ? Icon.Width + 8 : 8), Area.Value.Y + 6),
                       TextColor * (Focused ? 1.0f : hovered ? 0.8f : 0.6f));

            batch.Transform = oldTransform;

            if (ScrollableAmount.X > 0)
            {
                float scrollBarWidth = 1000 / ScrollableAmount.X;
                if (scrollBarWidth > Area.Value.Width - 16)
                {
                    scrollBarWidth = Area.Value.Width - 16;
                }
                if (scrollBarWidth < 20)
                {
                    scrollBarWidth = 20;
                }

                Rectangle fullScrollRectangle = new Rectangle(Area.TargetValue.X + 8, Area.TargetValue.Bottom - 18, Area.TargetValue.Width - 16, 20);

                if (fullScrollRectangle.Contains(game.Input.MousePosition) || _isScrollingX)
                {
                    fullScrollRectangle.Y      = Area.TargetValue.Bottom - 10;
                    fullScrollRectangle.Height = 2;

                    game.Batch.Rectangle(fullScrollRectangle, Color.White * 0.4f);

                    if (game.Input.MousePressed(Engine.MouseButton.Left) && !_isScrollingX)
                    {
                        _isScrollingX = true;
                    }

                    game.Batch.Rectangle(new Rectangle(
                                             (int)(MathHelper.Lerp(Area.TargetValue.X + 8, Area.TargetValue.Right - 8 - scrollBarWidth, Scroll.X / ScrollableAmount.X)),
                                             Area.TargetValue.Bottom - 10,
                                             (int)scrollBarWidth,
                                             2),
                                         Color.White * 0.5f);
                }
            }

            if (ScrollableAmount.Y > 0)
            {
                float scrollBarHeight = 1000 / ScrollableAmount.Y;
                if (scrollBarHeight > Area.Value.Height - 16)
                {
                    scrollBarHeight = Area.Value.Height - 16;
                }
                if (scrollBarHeight < 20)
                {
                    scrollBarHeight = 20;
                }

                Rectangle fullScrollRectangle = new Rectangle(Area.TargetValue.Right - 18, Area.TargetValue.Y + 8, 20, Area.TargetValue.Height - 16);

                if (fullScrollRectangle.Contains(game.Input.MousePosition) || _isScrollingY)
                {
                    fullScrollRectangle.X     = Area.TargetValue.Right - 10;
                    fullScrollRectangle.Width = 2;

                    game.Batch.Rectangle(fullScrollRectangle, Color.White * 0.4f);

                    if (game.Input.MousePressed(Engine.MouseButton.Left) && !_isScrollingY)
                    {
                        _isScrollingY = true;
                    }
                }

                game.Batch.Rectangle(new Rectangle(
                                         Area.TargetValue.Right - 10,
                                         (int)(MathHelper.Lerp(Area.TargetValue.Y + 8, Area.TargetValue.Bottom - 8 - scrollBarHeight, Scroll.Y / ScrollableAmount.Y)),
                                         2,
                                         (int)scrollBarHeight),
                                     Color.White * 0.5f);
            }

            batch.Scissor = null;
        }