Example #1
0
        private void OnKeyboardDown(object sender, KeyboardEventArgs args)
        {
            if (args[KeyModifier.Control, Key.F5])
            {
                string filename = Common.CaptureFilename;
                using (GifFile file = new GifFile(Runtime.Bitmap))
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        byte[] output = file.GetBytes();
                        fs.Write(output, 0, output.Length);
                        Runtime.Log($"Screenshot saved: {filename}");
                    }
                return;
            }

            if (args[KeyModifier.Control, Key.F6] && Game.Started)
            {
                string filename = Common.CaptureFilename;
                using (IBitmap tilesPicture = Map.Instance[0, 0, Map.WIDTH, Map.HEIGHT].ToBitmap())
                    using (GifFile file = new GifFile(tilesPicture))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                return;
            }

            TopScreen?.KeyDown(args);
        }
Example #2
0
        private void OnKeyDown(object sender, TkKeyArgs args)
        {
            _keyModifier = KeyModifier.None;
            if (args.Control)
            {
                _keyModifier |= KeyModifier.Control;
            }
            if (args.Shift)
            {
                _keyModifier |= KeyModifier.Shift;
            }
            if (args.Alt)
            {
                _keyModifier |= KeyModifier.Alt;
            }

            if (_keyModifier == KeyModifier.Alt && args.Key == TkKey.Enter)
            {
                if (WindowState == TkWinState.Fullscreen)
                {
                    Console.WriteLine("Windowed mode");
                    WindowState = _previousState;
                    return;
                }
                Console.WriteLine("Fullscreen mode");
                _previousState = WindowState;
                WindowState    = TkWinState.Fullscreen;
                return;
            }

            if (_keyModifier == KeyModifier.Control && args.Key == TkKey.F5)
            {
                string filename = Common.CaptureFilename;
                using (CivOne.GFX.ImageFormats.GifFile file = new CivOne.GFX.ImageFormats.GifFile(_canvas))
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        byte[] output = file.GetBytes();
                        fs.Write(output, 0, output.Length);
                        Console.WriteLine($"Screenshot saved: {filename}");
                    }
                return;
            }

            if (TopScreen == null)
            {
                return;
            }
            KeyboardEventArgs KeyboardEventArgs = ConvertKeyboardEvents(args);

            if (KeyboardEventArgs == null)
            {
                return;
            }
            TopScreen.KeyDown(KeyboardEventArgs);
        }
Example #3
0
        private void OnKeyboardDown(object sender, KeyboardEventArgs args)
        {
            if (args[KeyModifier.Control, Key.F5])
            {
                string filename = Common.CaptureFilename;
                if (Runtime.Layers == null)
                {
                    return;
                }
                using (IBitmap bitmap = new Picture(CanvasWidth, CanvasHeight, Common.TopScreen.Palette.Copy()))
                {
                    bitmap.Palette[0] = Colour.Black;
                    if (Common.HasAttribute <Modal>(TopScreen))
                    {
                        bitmap.AddLayer(TopScreen);
                    }
                    else
                    {
                        Runtime.Layers.ToList().ForEach(x => bitmap.AddLayer(x));
                    }

                    using (GifFile file = new GifFile(bitmap))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                }
                return;
            }

            if (args[KeyModifier.Control, Key.F6] && Game.Started)
            {
                string filename = Common.CaptureFilename;
                using (IBitmap tilesPicture = Map.Instance[0, 0, Map.WIDTH, Map.HEIGHT].ToBitmap())
                    using (GifFile file = new GifFile(tilesPicture))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                return;
            }

            TopScreen?.KeyDown(args);
        }
Example #4
0
        protected override void OnKeyPress(TkKeyPressArgs args)
        {
            if (TopScreen == null)
            {
                return;
            }
            char keyChar = (char)args.KeyChar;

            if (keyChar == '.' || keyChar == ',')
            {
                TopScreen.KeyDown(new KeyboardEventArgs(keyChar));
            }
            if (char.IsLetter(keyChar))
            {
                TopScreen.KeyDown(new KeyboardEventArgs(char.ToUpper((char)args.KeyChar), _keyModifier));
            }
        }