示例#1
0
        public override bool ProcessMouse(SadConsole.Input.MouseInfo info)
        {
            base.ProcessMouse(info);

            if (_isMouseOver)
            {
                if (info.ScrollWheelValueChange != 0)
                {
                    if (EditorConsoleManager.ToolsPaneScroller.IsEnabled)
                        EditorConsoleManager.ToolsPaneScroller.Value += info.ScrollWheelValueChange / 20;
                    return true;
                }

                foreach (var item in _hotSpots)
                {
                    if (item.Item2 == info.ConsoleLocation.Y)
                    {
                        if (info.LeftClicked)
                        {
                            item.Item1.IsCollapsed = !item.Item1.IsCollapsed;
                            RedrawPanels();
                            return true;
                        }
                    }
                }
            }

            return false;
        }
示例#2
0
        public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
        {
            // Forward the keyboard data to the entity to handle the movement code.
            // We could detect if the users hit ESC and popup a menu or something.
            // By not setting the entity as the active object, twe let this
            // "game level" (the console we're hosting the entity on) determine if
            // the keyboard data should be sent to the entity.

            // Process logic for moving the entity.
            bool keyHit = false;

            if (info.IsKeyReleased(Keys.Up))
            {
                player.Position = new Point(player.Position.X, player.Position.Y - 1);
                keyHit = true;
            }
            else if (info.IsKeyReleased(Keys.Down))
            {
                player.Position = new Point(player.Position.X, player.Position.Y + 1);
                keyHit = true;
            }

            if (info.IsKeyReleased(Keys.Left))
            {
                player.Position = new Point(player.Position.X - 1, player.Position.Y);
                keyHit = true;
            }
            else if (info.IsKeyReleased(Keys.Right))
            {
                player.Position = new Point(player.Position.X + 1, player.Position.Y);
                keyHit = true;
            }

            if (keyHit)
            {
                // Entity moved. Let's draw a trail of where they moved from.

                // We are not detecting when the player tries to move off the console area.
                // We could detected that though and then move the player back to where they were.
                SetGlyph(playerPreviousPosition.X, playerPreviousPosition.Y, 250);
                playerPreviousPosition = player.Position;

                return true;
            }

            // You could have multiple entities in the game for example, and change
            // which entity gets keyboard commands.
            return false;
        }
示例#3
0
 public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
 {
     if(info.IsKeyReleased(Keys.P))
     {
         if (PlayGame != null)
         {
             PlayGame(this, new EventArgs());
         }
         return true;
     }
     if (info.IsKeyReleased(Keys.I))
     {
         PrintInstructions();
         return true;
     }
     return false;
 }
示例#4
0
        public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
        {
            // Process logic for moving the entity.
            bool keyHit = false;

            if (info.IsKeyDown(Keys.Up))
            {
                if (CurrentDirection != Direction.Down)
                {
                    this.CurrentDirection = Direction.Up;
                }
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Down))
            {
                if (CurrentDirection != Direction.Up)
                {
                    this.CurrentDirection = Direction.Down;
                }
                keyHit = true;
            }

            if (info.IsKeyDown(Keys.Left))
            {
                if (CurrentDirection != Direction.Right)
                {
                    this.CurrentDirection = Direction.Left;
                }
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Right))
            {
                if (CurrentDirection != Direction.Left)
                {
                    this.CurrentDirection = Direction.Right;
                }
                keyHit = true;
            }

            return keyHit;

        }
示例#5
0
        public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
        {
            // Forward the keyboard data to the entity to handle the movement code.
            // We could detect if the users hit ESC and popup a menu or something.
            // By not setting the entity as the active object, twe let this
            // "game level" (the console we're hosting the entity on) determine if
            // the keyboard data should be sent to the entity.
            if (_player.ProcessKeyboard(info))
            {
                // Entity moved. Let's draw a trail of where they moved from.

                // We are not detecting when the player tries to move off the console area.
                // We could detected that though and then move the player back to where they were.
                _cellData.SetCharacter(_playerPreviousPosition.X, _playerPreviousPosition.Y, 250);
                _playerPreviousPosition = _player.Position;

                return true;
            }

            // You could have multiple entities in the game for example, and change
            // which entity gets keyboard commands.
            return false;
        }
示例#6
0
 public override int Redraw(SadConsole.Controls.ControlBase control)
 {
     return control == layers || control == toggleHideShow ? 1 : 0;
 }
示例#7
0
        protected override void OnMouseIn(SadConsole.Input.MouseInfo data)
        {
            if (data.Cell != null && TrackedRegion.Contains(data.ConsoleLocation.X, data.ConsoleLocation.Y))
            {
                // Draw the character index and value in the status area
                string[] items = new string[] { "Index: ", data.Cell.GlyphIndex.ToString() + " ", ((char)data.Cell.GlyphIndex).ToString() };

                items[2] = items[2].PadRight(textSurface.Width - 2 - (items[0].Length + items[1].Length));

                var text = items[0].CreateColored(ColorHelper.LightBlue, Theme.BorderStyle.Background, null) +
                           items[1].CreateColored(ColorHelper.LightCoral, Color.Black, null) +
                           items[2].CreateColored(ColorHelper.LightCyan, Color.Black, null);

                text.IgnoreBackground = true;
                text.IgnoreEffect = true;

                Print(1, textSurface.Height - 2, text);

                // Set the special effect on the current known character and clear it on the last known
                if (_lastInfo == null)
                {
                }
                else if (_lastInfo.ConsoleLocation != data.ConsoleLocation)
                {
                    effects.SetEffect(_lastInfo.Cell,
                    new SadConsole.Effects.Fade()
                    {
                        FadeBackground = true,
                        FadeForeground = true,
                        DestinationForeground = new ColorGradient(_highlightedCellEffect.Foreground, _lastInfo.Cell.Foreground),
                        DestinationBackground = new ColorGradient(_highlightedCellEffect.Background, _lastInfo.Cell.Background),
                        FadeDuration = 0.3d,
                        RemoveOnFinished = true,
                        UseCellBackground = false,
                        UseCellForeground = false,
                        CloneOnApply = true
                    }
                    );
                }

                effects.SetEffect(data.Cell, _highlightedCellEffect);
                _lastInfo = data.Clone();
            }
            else
            {
                DrawSelectedItemString();

                // Clear the special effect on the last known character
                if (_lastInfo != null)
                {
                    effects.SetEffect(_lastInfo.Cell, null);
                    _lastInfo = null;
                }
            }

            base.OnMouseIn(data);
        }
 public override void ProcessMouse(SadConsole.Input.MouseInfo info)
 {
 }
示例#9
0
        private void ToolsListBox_SelectedItemChanged(object sender, SadConsole.Controls.ListBox<SadConsole.Controls.ListBoxItem>.SelectedItemEventArgs e)
        {
            Tools.ITool tool = e.Item as Tools.ITool;

            if (e.Item != null)
            {
                selectedTool = tool;

                List<CustomPanel> newPanels = new List<CustomPanel>() { layerManagementPanel, GameObjectPanel, ZonesPanel, HotspotPanel, toolsPanel };

                if (tool.ControlPanels != null && tool.ControlPanels.Length != 0)
                    newPanels.AddRange(tool.ControlPanels);

                panels = newPanels.ToArray();
                EditorConsoleManager.ToolsPane.RedrawPanels();
            }
        }
示例#10
0
        protected override void OnMouseIn(SadConsole.Input.MouseInfo info)
        {
            var mousePosition = TransformConsolePositionByControlPosition(info);

            if (new Rectangle(0, 0, 16, 16).Contains(mousePosition) && info.LeftButtonDown)
            {
                if (!UseFullClick)
                    SelectedCharacter = this[mousePosition.ToIndex(16)].GlyphIndex;
            }

            base.OnMouseIn(info);
        }
示例#11
0
        protected override void OnMouseIn(SadConsole.Input.MouseInfo info)
        {
            base.OnMouseIn(info);

            if (Parent.CapturedControl == null)
            {
                if (info.LeftButtonDown)
                {
                    var location = this.TransformConsolePositionByControlPosition(info);
                    _selectedPosition = location.X;
                    SelectedColorSafe = this[_selectedPosition, 0].Foreground;
                    IsDirty = true;

                    Parent.CaptureControl(this);
                }
            }
        }
示例#12
0
        public static unsafe TextSurface ToSurface(this Texture2D image, SadConsole.Font font, bool blockMode = false)
        {
            int imageWidth = image.Width;
            int imageHeight = image.Height;
            Color[] pixels = new Color[imageWidth * imageHeight];
            image.GetData<Color>(pixels);

            TextSurface surface = new TextSurface(imageWidth / font.Size.X, imageHeight / font.Size.Y, font);
            SurfaceEditor editor = new SurfaceEditor(surface);

            global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) =>
            //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++)
            {
                int startY = (h * surface.Font.Size.Y);
                //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) =>
                for (int w = 0; w < imageWidth / surface.Font.Size.X; w++)
                {
                    int startX = (w * surface.Font.Size.X);

                    float allR = 0;
                    float allG = 0;
                    float allB = 0;

                    for (int y = 0; y < surface.Font.Size.Y; y++)
                    {
                        for (int x = 0; x < surface.Font.Size.X; x++)
                        {
                            int cY = y + startY;
                            int cX = x + startX;

                            Color color = pixels[cY * imageWidth + cX];

                            allR += color.R;
                            allG += color.G;
                            allB += color.B;
                        }
                    }

                    byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y));
                    byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y));

                    var newColor = new Color(sr, sg, sb);

                    float sbri = newColor.GetBrightness() * 255;

                    if (blockMode)
                    {
                        if (sbri > 204)
                            editor.SetGlyph(w, h, 219, newColor); //█
                        else if (sbri > 152)
                            editor.SetGlyph(w, h, 178, newColor); //▓
                        else if (sbri > 100)
                            editor.SetGlyph(w, h, 177, newColor); //▒
                        else if (sbri > 48)
                            editor.SetGlyph(w, h, 176, newColor); //░
                    }
                    else
                    {
                        if (sbri > 230)
                            editor.SetGlyph(w, h, (int)'#', newColor);
                        else if (sbri > 207)
                            editor.SetGlyph(w, h, (int)'&', newColor);
                        else if (sbri > 184)
                            editor.SetGlyph(w, h, (int)'$', newColor);
                        else if (sbri > 161)
                            editor.SetGlyph(w, h, (int)'X', newColor);
                        else if (sbri > 138)
                            editor.SetGlyph(w, h, (int)'x', newColor);
                        else if (sbri > 115)
                            editor.SetGlyph(w, h, (int)'=', newColor);
                        else if (sbri > 92)
                            editor.SetGlyph(w, h, (int)'+', newColor);
                        else if (sbri > 69)
                            editor.SetGlyph(w, h, (int)';', newColor);
                        else if (sbri > 46)
                            editor.SetGlyph(w, h, (int)':', newColor);
                        else if (sbri > 23)
                            editor.SetGlyph(w, h, (int)'.', newColor);
                    }
                }
            }
            );

            return surface;
        }
示例#13
0
文件: Font.cs 项目: Thraka/SadConsole
 public static Font FromFramework(SadConsole.Font font)
 {
     return new Font() { Name = font.Name, Size = font.SizeMultiple };
 }
示例#14
0
        public override int Redraw(SadConsole.Controls.ControlBase control)
        {
            if (control == characterPicker)
                characterPicker.Position = new Point(characterPicker.Position.X + 1, characterPicker.Position.Y);

            if (control == useCharBorder)
                return 1;

            if (control != fillColor)
                return 0;
            else
                return 1;
        }
示例#15
0
            public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
            {
                // Process logic for moving the entity.
                bool keyHit = false;

                if (info.IsKeyReleased(Keys.Up))
                {
                    _position.Y -= 1;
                    keyHit = true;
                }
                else if (info.IsKeyReleased(Keys.Down))
                {
                    _position.Y += 1;
                    keyHit = true;
                }

                if (info.IsKeyReleased(Keys.Left))
                {
                    _position.X -= 1;
                    keyHit = true;
                }
                else if (info.IsKeyReleased(Keys.Right))
                {
                    _position.X += 1;
                    keyHit = true;
                }

                return keyHit;

            }
示例#16
0
        protected override void OnMouseLeftClicked(SadConsole.Input.MouseInfo data)
        {
            if (data.Cell != null && TrackedRegion.Contains(data.ConsoleLocation.X, data.ConsoleLocation.Y))
            {
                SelectedCharacterIndex = data.Cell.GlyphIndex;
            }
            else if (data.ConsoleLocation.X == textSurface.Width - 1 && data.ConsoleLocation.Y == 0)
                Hide();

            base.OnMouseLeftClicked(data);
        }
示例#17
0
        public bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
        {
            // Process logic for moving the entity.
            bool keyHit = false;

            if (info.IsKeyDown(Keys.Up))
            {
                this.CurrentDirection = Direction.Up;
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Down))
            {
                this.CurrentDirection = Direction.Down;
                keyHit = true;
            }

            if (info.IsKeyDown(Keys.Left))
            {
                this.CurrentDirection = Direction.Left;
                keyHit = true;
            }
            else if (info.IsKeyDown(Keys.Right))
            {
                this.CurrentDirection = Direction.Right;
                keyHit = true;
            }

            switch(CurrentDirection)
            {
                case Direction.Up:
                    if(info.IsKeyReleased(Keys.Up))
                    {
                        this.CurrentDirection = Direction.None;
                        keyHit = true;
                    }
                    break;
                case Direction.Down:
                    if (info.IsKeyReleased(Keys.Down))
                    {
                        this.CurrentDirection = Direction.None;
                        keyHit = true;
                    }
                    break;
                case Direction.Left:
                    if (info.IsKeyReleased(Keys.Left))
                    {
                        this.CurrentDirection = Direction.None;
                        keyHit = true;
                    }
                    break;
                case Direction.Right:
                    if (info.IsKeyReleased(Keys.Right))
                    {
                        this.CurrentDirection = Direction.None;
                        keyHit = true;
                    }
                    break;
            }

            return keyHit;
        }
 public override int Redraw(SadConsole.Controls.ControlBase control)
 {
     return control == GameObjectList ? 1 : 0;
 }
示例#19
0
        public override bool ProcessMouse(SadConsole.Input.MouseInfo info)
        {
            if (Parent.CapturedControl == this)
            {
                if (info.LeftButtonDown == false)
                    Parent.ReleaseControl();
                else
                {
                    var location = this.TransformConsolePositionByControlPosition(info);

                    //if (info.ConsoleLocation.X >= Position.X && info.ConsoleLocation.X < Position.X + Width)
                    if (location.X >= 0 && location.X <= Width - 1 && location.Y > -4 && location.Y < Height + 3 )
                    {
                        _selectedPosition = location.X;
                        SelectedColorSafe = this[_selectedPosition, 0].Foreground;
                    }

                    IsDirty = true;
                }
            }

            return base.ProcessMouse(info);
        }
示例#20
0
 public override int Redraw(SadConsole.Controls.ControlBase control)
 {
     return 0;
 }
示例#21
0
        public override bool ProcessMouse(SadConsole.Input.MouseInfo info)
        {
            if (Parent.CapturedControl == this)
            {
                if (info.LeftButtonDown == false)
                    Parent.ReleaseControl();
                else
                {
                    var location = this.TransformConsolePositionByControlPosition(info);

                    //if (info.ConsoleLocation.X >= Position.X && info.ConsoleLocation.X < Position.X + Width)
                    if (location.X >= -6 && location.X <= Width + 5 && location.Y > -4 && location.Y < Height + 3)
                    {
                        this[_selectedColorPosition.X, _selectedColorPosition.Y].GlyphIndex = 0;
                        _selectedColorPosition = new Point(Microsoft.Xna.Framework.MathHelper.Clamp(location.X, 0, Width - 1), Microsoft.Xna.Framework.MathHelper.Clamp(location.Y, 0, Height - 1));
                        SelectedColorSafe = this[_selectedColorPosition.X, _selectedColorPosition.Y].Background;
                        this[_selectedColorPosition.X, _selectedColorPosition.Y].GlyphIndex = 4;
                    }

                    IsDirty = true;
                }
            }

            return base.ProcessMouse(info);
        }
示例#22
0
        protected override void OnLeftMouseClicked(SadConsole.Input.MouseInfo info)
        {
            var mousePosition = TransformConsolePositionByControlPosition(info);

            if (new Rectangle(0, 0, 16, 16).Contains(mousePosition))
            {
                SelectedCharacter = this[mousePosition.ToIndex(16)].GlyphIndex;
            }

            base.OnLeftMouseClicked(info);
        }
示例#23
0
        public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
        {
            if (gameOver == false)
            {
                if (player.ProcessKeyboard(info))
                {

                    return true;
                }
                else
                {
                    base.ProcessKeyboard(info);
                }
                return false;
            }
            else
            {
                if (info.KeysReleased.Count > 0)
                {
                    if (firstRelease)
                    {
                        firstRelease = false;
                        return true;
                    }
                    else
                    {
                        if (StopGamePlay != null)
                        {
                            StopGamePlay(this, new EventArgs());
                        }
                        return true;
                    }
                }
                else
                {
                    return false;
                }
                
            }
            
        }
示例#24
0
 public override bool ProcessKeyboard(SadConsole.Input.KeyboardInfo info)
 {
     switch(gameState)
     {
         case GameState.MenuScreen:
             return ProcessKeyboardMenu(info);
         case GameState.Running:
             return ProcessKeyboardRunning(info);
         case GameState.GameOver:
             return ProcessKeyboardGameOver(info);
         default:
             return false;
     }
 }
示例#25
0
        public bool ProcessMouse(IConsole console, SadConsole.Input.MouseInfo info)
        {
            consoleWrapper.MouseHandler = null;
            consoleWrapper.CanUseMouse = true;
            consoleWrapper.ProcessMouse(info);
            consoleWrapper.MouseHandler = ProcessMouse;

            // Check if tool is our special tool...
            toolsPanel.SelectedTool?.ProcessMouse(info, textSurface);

            if (consoleWrapper.IsMouseOver)
            {
                EditorConsoleManager.SurfaceMouseLocation = info.ConsoleLocation;
                return true;
            }
            else
                EditorConsoleManager.SurfaceMouseLocation = Point.Zero;

            consoleWrapper.CanUseMouse = false;
            return false;
        }
示例#26
0
 private bool ProcessKeyboardMenu(SadConsole.Input.KeyboardInfo info)
 {
     bool processedKeyboard = false;
     if (info.IsKeyReleased(Keys.Multiply))
     {
         astrickKeyAnimation.Run();
         ResetGame();
         processedKeyboard = true;
     }
     return processedKeyboard;
 }
示例#27
0
        public override bool ProcessMouse(SadConsole.Input.MouseInfo info)
        {
            base.ProcessMouse(info);

            if (_isMouseOver)
            {
                if (info.ScrollWheelValueChange != 0)
                {
                    EditorConsoleManager.Instance.ScrollToolbox(info.ScrollWheelValueChange);
                    return true;
                }

                foreach (var item in _hotSpots)
                {
                    if (item.Item2 == info.ConsoleLocation.Y)
                    {
                        if (info.LeftClicked)
                        {
                            item.Item1.IsCollapsed = !item.Item1.IsCollapsed;
                            RefreshControls();
                            return true;
                        }
                    }
                }
            }

            return false;
        }
示例#28
0
        private bool ProcessKeyboardRunning(SadConsole.Input.KeyboardInfo info)
        {
            bool processedKeyboard = false;

            if (player.ProcessKeyboard(info))
            {
                processedKeyboard = true;
                if (info.IsKeyDown(Keys.Up))
                {
                    upKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Down))
                {
                    downKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Left))
                {
                    leftKeyAnimation.Run();
                }
                else if (info.IsKeyDown(Keys.Right))
                {
                    rightKeyAnimation.Run();
                }
            }

            return processedKeyboard;
        }
示例#29
0
        public override int Redraw(SadConsole.Controls.ControlBase control)
        {
            if (control == changeSpeedButton)
            {
                animationSpeedLabel.Fill(Settings.Green, Settings.Color_MenuBack, 0, null);
                animationSpeedLabel.Print(0, 0, new ColoredString("Speed: ", Settings.Green, Settings.Color_MenuBack) + new ColoredString(((AnimatedTextSurface)animations.SelectedItem).AnimationDuration.ToString(), Settings.Blue, Settings.Color_MenuBack));
                changeSpeedButton.Position = new Microsoft.Xna.Framework.Point(Consoles.ToolPane.PanelWidth - changeSpeedButton.Width - 1, animationSpeedLabel.Position.Y);
            }

            return 0;
        }
示例#30
0
        public override int Redraw(SadConsole.Controls.ControlBase control)
        {
            if (control == NewButton)
                NewButton.Position = new Point(1, NewButton.Position.Y);
            else if (control == LoadButton)
            {
                LoadButton.Position = new Point(NewButton.Bounds.Right + 2, NewButton.Position.Y);
            }
            else if (control == SaveButton)
                SaveButton.Position = new Point(1, SaveButton.Position.Y);
            else if (control == ResizeButton)
            {
                ResizeButton.Position = new Point(SaveButton.Bounds.Right + 2, SaveButton.Position.Y);
                return -1;
            }
            else if (control == CloseButton)
            {
                CloseButton.Position = new Point(ResizeButton.Bounds.Right + 2, SaveButton.Position.Y);
            }
            else if (control == documentsTitle)
                return 1;

            return 0;
        }