예제 #1
0
        public static void RunOld(string[] args)
        {
            var intrinsicfile = args.FirstOrDefault() ?? Calibration.KinectDefaultFileName;
            var camIntrinsic = Utils.DeSerializeObject<CalibrationResult>(intrinsicfile);
            var projFile = args.Skip(1).FirstOrDefault() ?? Calibration.ProjectorDefaultFileName;
            var projIntrinsic = Utils.DeSerializeObject<CalibrationResult>(projFile);
            KinectSensor sensor = KinectSensor.KinectSensors.First();
            Camera cam = new Camera(sensor, ColorImageFormat.RgbResolution1280x960Fps12);
            Projector proj = new Projector();
            var keyl = new KeyboardListener(proj.window.Keyboard);
            double offsetx = 0, offsety = 0, scale = 0.5;
            bool proceed = false, quit = false;
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Up, OpenTK.Input.Key.Down, new OpenTK.Input.Key[0], (f) => offsety += f);
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Left, OpenTK.Input.Key.Right, new OpenTK.Input.Key[0], (f) => offsetx -= f);
            keyl.AddBinaryAction(0.02, -0.02, OpenTK.Input.Key.Up, OpenTK.Input.Key.Down, new OpenTK.Input.Key[] { Key.ShiftLeft }, (f) => scale += f);
            keyl.AddAction(() => proceed = true, Key.Space);
            keyl.AddAction(() => quit = proceed = true, Key.Q);
            PointF[] corners;
            proj.DrawBackground(Color.Black);
            while (true)
            {
                Console.WriteLine("Make sure the kinect can see the board");
                Console.ReadLine();
                corners = StereoCalibration.GetCameraCorners(cam.TakePicture(3), new Size(7, 4), false);
                if (corners.All(c => c != null))
                {
                    break;
                }
                else
                    Console.WriteLine("Could not find corners");
            }
            PointF[] projCorners;
            var projectedCorners = proj.DrawCheckerboard(new Size(8, 5), 0, 0, 0, scale, offsetx, offsety);
            while (true)
            {
                Console.WriteLine("Make sure the kinect can see the projection");
                while (!proceed)
                {
                    projectedCorners = proj.DrawCheckerboard(new Size(8, 5), 0, 0, 0, scale, offsetx, offsety);
                    proj.window.ProcessEvents();
                }
                projCorners = StereoCalibration.GetCameraCorners(cam.TakePicture(3), new Size(7, 4), false);
                if (corners.All(c => c != null))
                {
                    break;
                }
                else
                    Console.WriteLine("Could not find any corners, make sure the checkerboard is visible to all Kinects.");
            }

            var camResult = StereoCalibration.CalibrateCamera(corners, new Size(7, 4), 0.05f, camIntrinsic);
            var transform = StereoCalibration.FindHomography(projCorners, projectedCorners);
            var projResult = StereoCalibration.CalibrateCamera(transform(corners), new Size(7, 4), 0.05f, projIntrinsic);
            Utils.SerializeObject(camResult, intrinsicfile);
            Utils.SerializeObject(projResult, projFile);
            proj.Close();
        }
예제 #2
0
 public EscapeHandler(KeyboardListener listener)
 {
     listener.KeyPressed += this.Listener_KeyPressed;
 }
예제 #3
0
 protected void PushKeyboardListener(KeyboardListener element)
 {
     keyboardListeners.Push(element);
 }
예제 #4
0
 public void Stop()
 {
     KeyboardListener.KeyboardListenerEvent -= OnKeyPressed;
     KeyboardListener.Stop();
 }
예제 #5
0
 public GameKeyboardHandler(IConsoleInteraction console)
 {
     Console          = console;
     KeyboardListener = new KeyboardListener(Console);
 }
예제 #6
0
        public static void Run(string[] args)
        {
            var projfile = args.Skip(1).FirstOrDefault() ?? Calibration.ProjectorDefaultFileName;
            if (!File.Exists(projfile))
            {
                Console.WriteLine("Either calib file could not be found.");
                return;
            }

            var pc = Utils.DeSerializeObject<CalibrationResult>(projfile);

            var window = ProgramWindow.OpenOnSecondary();

            var program = new LightStudioProgram(0.08f);
            window.SetProgram(program);

            var overviewWindow = new ProgramWindow(750, 50, 1280, 960);
            overviewWindow.Load();
            overviewWindow.ResizeGraphics();
            OverviewProgram overview = new OverviewProgram(program);
            overviewWindow.SetProgram(overview);

            var format = DepthImageFormat.Resolution80x60Fps30;
            var inputs = KinectSensor.KinectSensors.Where(k => k.Status == KinectStatus.Connected).Select(k =>
            {
                k.Start();
                return new
                {
                    sensor = k,
                    depth = new DepthCamera(k, format),
                    skeleton = new SkeletonCamera(k),
                    calibrator = new KinectCalibrator(Utils.DeSerializeObject<CalibrationResult>(k.UniqueKinectId.Substring(k.UniqueKinectId.Length - 16) + ".xml"))
                };
            });
            float[] data = Utils.DeSerializeObject<float[]>(LightningFastApp.IR2RGBFILE) ?? MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.Identity(4).ToColumnWiseArray();
            MathNet.Numerics.LinearAlgebra.Generic.Matrix<float> D2C = MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4, data);

            var keyl = new KeyboardListener(window.Keyboard);
            SkeletonPoint[] skeletons = null;
            // Action H hide background:
            bool hideBackground = false;
            float zCutoff = 3.4f;
            float xadj = 0, yadj = 0.0f, zadj = 0;
            float incr = 0.01f;
            bool adjust = true;
            program.SetProjection(pc);
            Action<float> xfoo = (f) =>
            {
                if (!adjust)
                    return;
                xadj += f;
                program.SetProjection(pc);
            };
            Action<float> yfoo = (f) =>
            {
                if (!adjust)
                    return;
                yadj += f;
                program.SetProjection(pc);
            };
            Action<float> zfoo = (f) =>
            {
                if (!adjust)
                    return;
                zadj += f;
                program.SetProjection(pc);
            };
            keyl.AddAction(() => adjust = !adjust, Key.A);
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, null, (i) => yfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Left, Key.Right, null, (i) => xfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ShiftLeft }, (i) => zfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ControlLeft }, (i) => yfoo(i * incr * 3));
            keyl.AddBinaryAction(1, -1, Key.Left, Key.Right, new Key[] { Key.ControlLeft }, (i) => xfoo(i * incr * 3));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ShiftLeft, Key.ControlLeft }, (i) => zfoo(i * incr * 3));

            keyl.AddAction(() =>
            {
                hideBackground = !hideBackground;
                if (skeletons != null && skeletons.Length > 0)
                {
                    zCutoff = skeletons.Min(sp => sp.Z);
                }
                else
                    zCutoff = 0;
            }, OpenTK.Input.Key.H);

            program.SetProjection(pc, inputs.Select(i => i.calibrator).First().GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(xadj, yadj, zadj));

            while (true)
            {
                var points = inputs.Select(inp => new
                {
                    Calibrator = inp.calibrator,
                    Skeletons = inp.depth.Get(100).Where(p => p.HasValue && p.Value.Index > 0)
                        .Select(p => inp.sensor.CoordinateMapper.MapDepthPointToSkeletonPoint(format, p.Value.Point))
                        .ToArray()
                });

                program.SetPositions(points.Take(1).SelectMany(v => v.Skeletons.Select(sp => new Vector3(sp.X, sp.Y, sp.Z))));

                overview.SetPointCloud(0, points.SelectMany(p =>
                    {
                        return p.Skeletons.Select(sp =>
                        {
                            var gp = p.Calibrator.ToGlobal(sp);
                            return new DynamicVertex(new Vector3(gp[0], gp[1], gp[2]));
                        });
                    }).ToArray());

                window.RenderFrame();
                overviewWindow.RenderFrame();
                window.ProcessEvents();
                overviewWindow.ProcessEvents();
            }
        }
 public override void Ready()
 {
     KeyboardListener.KeyPressed += OnKeyPressed;
     KeyboardListener.Start();
 }
 /// <summary>
 /// Unregister listener.
 /// </summary>
 /// <param name="listener">The listener.</param>
 public void UnRegisterListener(KeyboardListener listener)
 {
     _listeners.Remove(listener);
 }
예제 #9
0
파일: App.xaml.cs 프로젝트: eze1981/igor
 public App()
 {
     _window           = new MainWindow();
     _keyboardListener = new KeyboardListener();
 }
예제 #10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            this.DispatcherUnhandledException += (sender, args) => ReportException(sender, args.Exception);

            Settings.Load();
            DispatcherHelper.UIDispatcher = this.Dispatcher;
            ProductInfo = new ProductInfo();

            MainNotifier.Current.Initialize();
            GrandcypherClient.Current.Proxy.StartUp(Settings.Current.portNum);
            //GrandcypherClient.Current.WeaponHooker.MasterInfoListLoad();

            GrandcypherClient.Current.PortError += () =>
            {
                Settings.Current.portNum = Convert.ToInt32(AppSettings.Default.LocalProxyPort);
            };
            GrandcypherClient.Current.ResultHooker.EndBattle += () =>
            {
                MainNotifier.Current.Show("전투종료알림", "전투가 종료되었습니다", () => App.ViewModelRoot.Activate());
            };
            if (GrandcypherClient.Current.Updater.LoadVersion(AppSettings.Default.XMLUpdateUrl.AbsoluteUri))
            {
                if (GrandcypherClient.Current.Updater.IsOnlineVersionGreater(0, ProductInfo.Version.ToString()))
                {
                    Version temp = new Version(GrandcypherClient.Current.Updater.GetOnlineVersion(TranslationType.App));
                    MainNotifier.Current.Show("업데이트 알림", "상위버전의 어플리케이션이 존재합니다. \n" + temp.Major + "." + temp.Minor + "." + temp.Build + " Rev." + temp.Revision + " Ver", () => App.ViewModelRoot.Activate());
                }
            }

            if (GrandcypherClient.Current.Updater.UpdateTranslations(AppSettings.Default.XMLTransUrl.AbsoluteUri, GrandcypherClient.Current.Translations) > 0)
            {
                MainNotifier.Current.Show("업데이트 알림", "데이터를 성공적으로 업데이트하였습니다.", () => App.ViewModelRoot.Activate());
            }
            ViewModelRoot = new MainWindowViewModel();

            this.MainWindow = new MainWindow {
                DataContext = ViewModelRoot
            };

            WindowSizeSetter.Current.WindowSize = new WindowSize();

            this.MainWindow.Show();
            #region .Do(debug)
#if !DEBUG
            KListener = new KeyboardListener();

            KListener.KeyDown += new RawKeyEventHandler(KListener_KeyDown);
#endif
            #endregion
            using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                float dpiX = graphics.DpiX;
                float dpiY = graphics.DpiY;
                #region .Do(debug)
#if DEBUG
                Console.WriteLine(dpiX.ToString() + " " + dpiY.ToString());
#endif
                #endregion
                WindowSizeSetter.Current.dpiX = dpiX;
                WindowSizeSetter.Current.dpiY = dpiY;
            }
        }
예제 #11
0
        public static void Initialize()
        {
            keyboardListener = new KeyboardListener();

            escapeHandler = new EscapeHandler(keyboardListener);
        }
예제 #12
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Window.Title = "Tetris (MonoGame)";
            tetrisBoard  = new TetrisBoard();

            KeyboardListener keyboardListener = new KeyboardListener(new KeyboardListenerSettings());
            GamePadListener  gamePadListener  = new GamePadListener(new GamePadListenerSettings());

            Components.Add(new InputListenerComponent(this, keyboardListener, gamePadListener));

            keyboardListener.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Up && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Rotate();
                }
                else if (args.Key == Keys.Space && !tetrisBoard.IsOver)
                {
                    tetrisBoard.PlaceDown();
                }
                else if (args.Key == Keys.C && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Hold();
                }
                else if (args.Key == Keys.OemMinus)
                {
                    MediaPlayer.Volume -= 0.1f;
                }
                else if (args.Key == Keys.OemPlus)
                {
                    MediaPlayer.Volume += 0.1f;
                }
                else if (args.Key == Keys.M)
                {
                    MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
                }
                else if (args.Key == Keys.R && tetrisBoard.IsOver)
                {
                    tetrisBoard = new TetrisBoard();
                    inTimer     = 500;
                    presses     = 0;
                }
            };

            gamePadListener.ButtonDown += (sender, args) =>
            {
                if (!tetrisBoard.IsOver)
                {
                    if (args.Button == Buttons.DPadUp || args.Button == Buttons.Y)
                    {
                        tetrisBoard.Rotate();
                    }
                    if (args.Button == Buttons.B)
                    {
                        tetrisBoard.PlaceDown();
                    }
                    if (args.Button == Buttons.RightShoulder || args.Button == Buttons.LeftShoulder)
                    {
                        tetrisBoard.Hold();
                    }
                }
            };

            base.Initialize();
        }
예제 #13
0
 protected void PushKeyboardListener(KeyboardListener element)
 {
     keyboardListeners.Push(element);
 }
예제 #14
0
 public KeyboardInputProvider(KeyboardListener keyboardListener)
 {
     this.keyListener     = keyboardListener;
     keyListener.KeyDown += keyListener_KeyDown;
     keyListener.KeyUp   += keyListener_KeyUp;
 }
예제 #15
0
 public void AddKeyboardListener(KeyboardListener listener)
 {
     keyboardListeners.Add(listener);
 }
예제 #16
0
 public KeyboardInputProvider()
 {
     this.keyListener     = new KeyboardListener();
     keyListener.KeyDown += keyListener_KeyDown;
     keyListener.KeyUp   += keyListener_KeyUp;
 }
예제 #17
0
 public MainWindowViewModel()
 {
     LoadArchiveConfig();
     EventAggregatorHost.Aggregator.AddListener(this);
     keyListener = new KeyboardListener();
 }
예제 #18
0
 public TitleScreenGameController(TitleScreenScene scene)
 {
     this.scene                   = scene;
     keyboardListener             = new KeyboardListener();
     keyboardListener.KeyPressed += OnKeyPressed;
 }
예제 #19
0
        public void Initialize()
        {
            //watch Ctrl down to switch click-through
#if !DEBUG
            keyboardListener          = new KeyboardListener();
            keyboardListener.KeyDown += keyboardListener_KeyDown;
            keyboardListener.KeyUp   += keyboardListener_KeyUp;
#endif
            if (AppConfig.IsReplyBoxPersistent)
            {
                IsOverlayVisible = true;
                SendTextEditMode = true;
            }


            AppConfig.PropertyChanged += AppConfig_PropertyChanged;

            Win.ShowStatus();

            EnableMouseTransparency = AppConfig.MouseTransparency && Keyboard.Modifiers != ModifierKeys.Control;

            _generalDataService.Start();

            ChannelList         = _dataService.ChatChannels;
            SelectedChatChannel = ChannelList[0];


            MessengerInstance.Register <bool>(this, "ReopenMainWindow", (message) => {
                if (message)
                {
                    IsWindowReopen = true;
                }
            });

            MessengerInstance.Register <ChatMessage>(this, "SetChannel", (message) =>
            {
                SelectedChatChannel = ChannelList.FirstOrDefault(channel =>
                                                                 channel.ChatName == message.ChatName &&
                                                                 channel.ChannelName == message.Channel) ?? ChannelList[0];
            });

            MessengerInstance.Register <ChatMessage>(this, "SetReplyTo", (message) =>
            {
                SelectedChatChannel = ChannelList.FirstOrDefault(channel =>
                                                                 channel.ChatName == message.ChatName &&
                                                                 channel.ChannelName == message.Channel) ?? ChannelList[0];
                ReplyCarretPos = 0;
                SendText       = message.FromUserName + ", ";
                ReplyCarretPos = Int32.MaxValue;
            });

            var steamChat = _dataService.GetChat(SettingsRegistry.ChatTitleSteam);
            if (steamChat != null)
            {
                steamChat.RequestData = (what) => {
                    if (what.Equals("SteamGuardCode", StringComparison.InvariantCultureIgnoreCase))
                    {
                        UI.Dispatch(() =>
                        {
                            steamGuardWindow.Show();
                        });
                    }
                    return(null);
                };
            }
        }
예제 #20
0
        public static void RunOld(string[] args)
        {
            var camfile = args.FirstOrDefault() ?? Calibration.KinectDefaultFileName;
            var projfile = args.Skip(1).FirstOrDefault() ?? Calibration.ProjectorDefaultFileName;
            if (!File.Exists(camfile) || !File.Exists(projfile))
            {
                Console.WriteLine("Either calib file could not be found.");
                return;
            }
            var cc = Utils.DeSerializeObject<CalibrationResult>(camfile);
            var pc = Utils.DeSerializeObject<CalibrationResult>(projfile);

            var window = ProgramWindow.OpenOnSecondary();

            var program = new LightStudioProgram(0.08f);
            window.SetProgram(program);

            var overviewWindow = new ProgramWindow(750, 50, 1280, 960);
            overviewWindow.Load();
            overviewWindow.ResizeGraphics();
            OverviewProgram overview = new OverviewProgram(program);
            overviewWindow.SetProgram(overview);

            KinectSensor sensor = KinectSensor.KinectSensors.First();
            var format = DepthImageFormat.Resolution80x60Fps30;
            DepthCamera depthCam = new DepthCamera(sensor, format);
            KinectCalibrator kc = new KinectCalibrator(cc);
            SkeletonCamera scam = new SkeletonCamera(sensor);
            sensor.Start();
            float[] data = Utils.DeSerializeObject<float[]>(LightningFastApp.IR2RGBFILE) ?? MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.Identity(4).ToColumnWiseArray();
            MathNet.Numerics.LinearAlgebra.Generic.Matrix<float> D2C = MathNet.Numerics.LinearAlgebra.Single.DenseMatrix.OfColumnMajor(4, 4, data);
            //var adjustment = OpenTK.Matrix4.CreateTranslation(0f, 0.14f, 0.00f);
            //program.SetProjection(pc, kc.GetModelView(D2C), adjustment);

            //program.SetProjection(pc); //, kc.GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(0f, 0.14f, 0.06f));
            //var rs = Range.OfDoubles(0.5, -0.5, 0.04);
            //program.SetPositions(rs.SelectMany(x => rs.Select(y => new Vector3((float)x, (float)y, 1.7f))).ToArray());
            //while (true)
            //{
            //    window.RenderFrame();
            //    window.ProcessEvents();
            //}
            var keyl = new KeyboardListener(window.Keyboard);
            SkeletonPoint[] skeletons = null;
            // Action H hide background:
            bool hideBackground = false;
            float zCutoff = 3.4f;
            float xadj = 0, yadj = 0.0f, zadj = 0;
            float incr = 0.01f;
            bool adjust = true;
            program.SetProjection(pc, kc.GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(xadj, yadj, zadj));
            Action<float> xfoo = (f) =>
            {
                if (!adjust)
                    return;
                xadj += f;
                program.SetProjection(pc, kc.GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(xadj, yadj, zadj));
            };
            Action<float> yfoo = (f) =>
            {
                if (!adjust)
                    return;
                yadj += f;
                program.SetProjection(pc, kc.GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(xadj, yadj, zadj));
            };
            Action<float> zfoo = (f) =>
            {
                if (!adjust)
                    return;
                zadj += f;
                program.SetProjection(pc, kc.GetModelView(D2C), OpenTK.Matrix4.CreateTranslation(xadj, yadj, zadj));
            };
            keyl.AddAction(() => adjust = !adjust, Key.A);
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, null, (i) => yfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Left, Key.Right, null, (i) => xfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ShiftLeft }, (i) => zfoo(i * incr));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ControlLeft }, (i) => yfoo(i * incr * 3));
            keyl.AddBinaryAction(1, -1, Key.Left, Key.Right, new Key[] { Key.ControlLeft }, (i) => xfoo(i * incr * 3));
            keyl.AddBinaryAction(1, -1, Key.Up, Key.Down, new Key[] { Key.ShiftLeft, Key.ControlLeft }, (i) => zfoo(i * incr * 3));

            keyl.AddAction(() =>
            {
                hideBackground = !hideBackground;
                if (skeletons != null && skeletons.Length > 0)
                {
                    zCutoff = skeletons.Min(sp => sp.Z);
                }
                else
                    zCutoff = 0;
            }, OpenTK.Input.Key.H);
            while (true)
            {
                var points = depthCam.Get(1000).Where(p => p.HasValue && p.Value.Index > 0).Select(p => p.Value);
                skeletons = points.Select(p => sensor.CoordinateMapper.MapDepthPointToSkeletonPoint(format, p.Point)).ToArray();
                program.SetPositions(skeletons.Where(sp => !hideBackground || sp.Z < zCutoff).Select(sp => new Vector3(sp.X, sp.Y, sp.Z)).ToArray());
                overview.SetPointCloud(0, skeletons.Select(sp =>
                {
                    var gp = kc.ToGlobal(sp);
                    return new DynamicVertex(new Vector3(gp[0], gp[1], gp[2]));
                }).ToArray());
                window.RenderFrame();
                overviewWindow.RenderFrame();
                window.ProcessEvents();
                overviewWindow.ProcessEvents();
            }
        }
예제 #21
0
파일: Game.cs 프로젝트: Abishai2007/actools
        public static async Task <Result> StartAsync(IAcsStarter starter, StartProperties properties, IProgress <ProgressState> progress = null,
                                                     CancellationToken cancellation = default(CancellationToken))
        {
            if (_busy)
            {
                return(null);
            }
            _busy = true;

            if (OptionDebugMode)
            {
                progress?.Report(ProgressState.Waiting);
                await Task.Delay(500, cancellation);

                _busy = false;
                return(GetResult());
            }

            RemoveResultJson();
            KeyboardListener listener = null;

            if (properties.SetKeyboardListener)
            {
                try {
                    listener = new KeyboardListener();
                    listener.Subscribe();
                } catch (Exception e) {
                    AcToolsLogging.Write("Can’t set listener: " + e);
                }
            }

            try {
                progress?.Report(ProgressState.Preparing);
                await Task.Run(() => properties.Set(), cancellation);

                if (cancellation.IsCancellationRequested || OptionRaceIniTestMode)
                {
                    return(null);
                }

                progress?.Report(ProgressState.Launching);
                await starter.RunAsync(cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }

                var process = await starter.WaitUntilGameAsync(cancellation);

                await Task.Run(() => properties.SetGame(process), cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }

                progress?.Report(ProgressState.Waiting);
                await starter.WaitGameAsync(cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }
            } finally {
                _busy = false;

                if (cancellation.IsCancellationRequested)
                {
                    starter.CleanUp();
                }
                else
                {
                    progress?.Report(ProgressState.Finishing);
                    await starter.CleanUpAsync(cancellation);
                }

                properties.RevertChanges();
                listener?.Dispose();
            }

            return(GetResult());
        }
예제 #22
0
 public BattleScreen(Game game, GuiSystem guiSystem, Variables variables, MessageHub messageHub, SharedContext sharedContext, KeyboardListener keyboardListener) : base(game)
 {
     this.guiSystem               = guiSystem;
     this.variables               = variables;
     this.messageHub              = messageHub;
     this.sharedContext           = sharedContext;
     keyboardListener.KeyPressed += KeyboardListenerOnKeyPressed;
 }
예제 #23
0
 public void AddKeyboardListener(KeyboardListener listener)
 {
     keyboardListeners.Add(listener);
 }
예제 #24
0
 public void Start()
 {
     KeyboardListener.KeyboardListenerEvent += OnKeyPressed;
     KeyboardListener.Start();
 }
예제 #25
0
 public void RemoveKeyboardListener(KeyboardListener listener)
 {
     keyboardListeners.Remove(listener);
 }
예제 #26
0
 public RussianWindowsFix()
 {
     _keyboard = new KeyboardListener();
     _keyboard.PreviewKeyDown += OnPreviewKeyDown;
     _keyboard.PreviewKeyUp   += OnPreviewKeyUp;
 }
예제 #27
0
        public void Init(GraphicsDeviceManager GD, SpriteBatch SB, Game GameContext)
        {
            Context     = GameContext;
            SpriteBatch = SB;
            Graphics    = GD;
            KeySettings.RepeatDelayMilliseconds = 15;
            Context.IsMouseVisible = true;
            KeyListen   = new KeyboardListener(KeySettings);
            MouseListen = new MouseListener(MouseSettings);
            Context.Components.Add(new InputListenerComponent(Context, MouseListen, KeyListen));
            Font = Context.Content.Load <SpriteFont>("font2");
            Context.Window.AllowUserResizing = true;
            Strings.Add(ShellToUse.GetPrompt(this));
            caret    = Context.Content.Load <Texture2D>("findthepixel");
            caretPos = new Rectangle(0, 0, 8, 2);

            MouseListen.MouseDown += (sender, args) =>
            {
                if (args.Button == MouseButton.Right)
                {
                    Strings[Strings.Count - 1] += System.Windows.Forms.Clipboard.GetText();
                }
            };
            KeyListen.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Up)
                {
                    ShellToUse.Index          += 1;
                    Strings[Strings.Count - 1] = ShellToUse.GetFromIndex(this);
                }
                else if (args.Key == Keys.Down)
                {
                    ShellToUse.Index          -= 1;
                    Strings[Strings.Count - 1] = ShellToUse.GetFromIndex(this);
                }
                else if (args.Key == Keys.Left)
                {
                    CharScroll += 1;
                }
                else if (args.Key == Keys.Right)
                {
                    CharScroll -= 1;
                }
                else if (args.Key == Keys.Tab)
                {
                    string   ToSend       = Strings[Strings.Count - 1].Substring(ShellToUse.GetPrompt(this).Length, Strings[Strings.Count - 1].Length - ShellToUse.GetPrompt(this).Length);
                    string[] TabCompletes = ShellToUse.GetTabCompletes(ToSend);
                    if (TabCompletes.Length == 1)
                    {
                        Strings[Strings.Count - 1] = (ShellToUse.GetPrompt(this) + TabCompletes[0]);
                    }
                    else if (TabCompletes.Length > 0)
                    {
                        string ToOut = "";
                        foreach (string Complete in TabCompletes)
                        {
                            ToOut += Complete + " ";
                        }
                        SendOut(ToOut);
                        SendOut(ShellToUse.GetPrompt(this));
                    }
                }
            };
            KeyListen.KeyTyped += (sender, args) =>
            {
                if (args.Key == Keys.Back && CurrentIn.Length > 0)
                {
                    if (Strings[Strings.Count - 1].Substring(0, Strings[Strings.Count - 1].Length - CharScroll) != ShellToUse.GetPrompt(this))
                    {
                        Strings[Strings.Count - 1] = Strings[Strings.Count - 1].Remove(Strings[Strings.Count - 1].Length - CharScroll - 1, 1);
                    }
                }
                else if (args.Key == Keys.Enter)
                {
                    string ToSend = Strings[Strings.Count - 1].Substring(ShellToUse.GetPrompt(this).Length, Strings[Strings.Count - 1].Length - ShellToUse.GetPrompt(this).Length);
                    ShellToUse.ParseIn(ToSend, this);
                    SendOut(ShellToUse.GetPrompt(this));
                }
                else if (args.Key == Keys.Tab)
                {
                    //do nothing because this breaks everything lol
                }
                else
                {
                    Strings[Strings.Count - 1] = Strings[Strings.Count - 1].Insert(Strings[Strings.Count - 1].Length - CharScroll, args.Character?.ToString() ?? "");
                    ShellToUse.Index           = 0;
                    ScrollUp = 0;
                }
            };
            CurrYWorking = CurrentY + 10;
        }
예제 #28
0
 public void Init()
 {
     listener = new KeyboardListener();
 }
예제 #29
0
        private void LoadGameAssets()
        {
            new GameStringsLoader(_localizedStringsRepository, _gameCulture);

            _assetsLoader = new AssetsLoader(
                Content,
                _textFileAssetsLoader);
            _mousePointer = _assetsLoader.Sprites["manina"];
            _soundManager = new SoundManager(_assetsLoader);

            var gameFactory = new Func <RellowGame>(
                () => new RellowGame(
                    _matrixScaleProvider,
                    _assetsLoader,
                    _orchestrator,
                    _soundManager,
                    _settingsRepository,
                    _localizedStringsRepository));

            var dialogDefinition = new Rectangle(
                100, 550, _matrixScaleProvider.VirtualWidth - 200, _matrixScaleProvider.VirtualHeight / 3);
            var rateMeDialog = new RateMeDialog(
                launchesUntilPrompt: 2,
                maxRateShowTimes: 2,
                rateAppUri: _rateMeUri,
                dialogDefinition: dialogDefinition,
                font: _assetsLoader.WritingFont,
                localizedStringsRepository: _localizedStringsRepository,
                rateMeDialogStrings: _gameCulture.TwoLetterISOLanguageName == "it" ? (RateMeDialogStrings) new DefaultItalianRateMeDialogStrings(_gameName) : (RateMeDialogStrings) new DefaultEnglishRateMeDialogStrings(_gameName),
                webPageOpener: _webPageOpener,
                settingsRepository: _settingsRepository,
                buttonADefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 350,
                    500, 100),
                buttonBDefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 500,
                    500, 100),
                backgroundColor: Color.DarkGray.WithAlpha(1f),
                buttonsBackgroundColor: Definitions.PrimaryBackgroundColor.WithAlpha(1f),
                buttonsShadowColor: Color.Black,
                backgroundShadowColor: Color.Black.WithAlpha(1f),
                titleColor: Color.Black,
                buttonsTextColor: Definitions.PrimaryForegroundColor,
                titlePositionOffset: new Vector2(dialogDefinition.Width / 2, 80f),
                buttonTextPadding: 60f,
                titlePadding: 90f);

            var mainMenuFactory = new Func <MainMenuPage>(
                () => new MainMenuPage(
                    _assetsLoader,
                    _orchestrator,
                    _matrixScaleProvider,
                    _localizedStringsRepository,
                    rateMeDialog,
                    _settingsRepository));

            _orchestrator = new GameOrchestrator(
                gameFactory,
                mainMenuFactory,
                GraphicsDevice,
                _matrixScaleProvider,
                _soundManager,
                _webPageOpener);

            _inputListeners = new List <IInputListener>();

            if (_isPc)
            {
                var mouseListener = new MouseListener(_matrixScaleProvider);
                mouseListener.MouseDown += MouseListener_MouseClicked;
                _inputListeners.Add(mouseListener);
            }
            else
            {
                var touchListener = new TouchListener(_matrixScaleProvider);
                touchListener.TouchStarted += TouchListener_TouchEnded;

                var gamepadListener = new GamePadListener();
                gamepadListener.ButtonDown += GamepadListener_ButtonDown;

                _inputListeners.Add(touchListener);
                _inputListeners.Add(gamepadListener);
            }

            // Perchè il back di Android lo prende la tastiera
            var keyboardListener = new KeyboardListener();

            keyboardListener.KeyPressed += KeyboardListener_KeyPressed;
            _inputListeners.Add(keyboardListener);
        }
예제 #30
0
 public void RemoveKeyboardListener(KeyboardListener listener)
 {
     keyboardListeners.Remove(listener);
 }
 /// <summary>
 /// Registers the listener.
 /// </summary>
 /// <param name="newListener">The new listener.</param>
 public void RegisterListener(KeyboardListener newListener)
 {
     _listeners.Add(newListener);
 }
예제 #32
0
        public override void Load(ProgramWindow parent)
        {
            parent.MakeCurrent();
            base.Load(parent);
            GL.Disable(EnableCap.Dither);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.DstAlpha);
            GL.ClearColor(System.Drawing.Color.FromArgb(0,0,0,0));
            var vs = parent.CreateShader(ShaderType.VertexShader, VSLighting);
            var fs = parent.CreateShader(ShaderType.FragmentShader, FSLighting);
            program = parent.CreateProgram(vs, fs);
            GL.DeleteShader(vs);
            GL.DeleteShader(fs);
            dynamicProgram.Load();

            textures = new MultipleTextures(this);
            Bitmap white = new Bitmap(101, 101);
            QuickDraw.Start(white)
                .Fill(Color.White).Finish();
            Bitmap gridBot = new Bitmap(101, 101);
            QuickDraw.Start(gridBot)
                .All((x, y) =>
                {
                    var lpp = 10;
                    var xm = x % lpp;
                    var ym = y % lpp;
                    if (xm == 0 || ym == 0)
                        return Color.Gray;
                    return Color.FromArgb(150, 50, 50, 50);
                }, false).Finish();
            Bitmap[] maps = new Bitmap[] {
                white, gridBot
            };
            textures.Load(maps);

            if (lightStudio != null)
                lights = lightStudio.Lights;
            else
                lights = new MoveableLights(8);

            dynamicRenderer = new Renderer(dynamics = (Dynamight.ImageProcessing.CameraCalibration.Range.OfInts(6)).Select(_ => new DynamicRenderable()).ToArray());
            staticRenderer = new Renderer(null, (new Renderable[] {
                Grid = new Renderable() {
                    Visible = false,
                    Shape = new Quad(new Vector3(0,0,0), 10, new Vector3(1,0,0), new Vector3(0,0,1), (v) => textures.Transform(v, 1)),
                    Animatable = new Translator()
                },
            }).Concat(LightsObjects = lights.Select(l => new LightRenderable(l, (v) => textures.Transform(v, 0))).ToArray()).ToArray());
            windowSize = parent.Size;
            SetupCamera();

            staticRenderer.Load();
            dynamicRenderer.Load();
            staticRenderer.Start();
            dynamicRenderer.Start();

            keyl = new KeyboardListener(parent.Keyboard);

            keyl.AddAction(() => Selection = (Selection == null ? (int?)1 : null), Key.C);

            keyl.AddAction(() => Grid.Visible = !Grid.Visible, Key.G);

            keyl.AddBinaryAction(0.01f, -0.01f, Key.Right, Key.Left, null, (f) => MoveX(f));
            keyl.AddBinaryAction(0.01f, -0.01f, Key.Down, Key.Up, null, (f) => MoveY(f));
            keyl.AddBinaryAction(0.01f, -0.01f, Key.Down, Key.Up, new Key[] { Key.ShiftLeft }, (f) => MoveZ(f));

            keyl.AddBinaryAction(0.05f, -0.05f, Key.Right, Key.Left, new Key[] { Key.ControlLeft }, (f) => MoveX(f));
            keyl.AddBinaryAction(0.05f, -0.05f, Key.Down, Key.Up, new Key[] { Key.ControlLeft }, (f) => MoveY(f));
            keyl.AddBinaryAction(0.05f, -0.05f, Key.Down, Key.Up, new Key[] { Key.ShiftLeft, Key.ControlLeft }, (f) => MoveZ(f));

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);
            GL.Enable(EnableCap.Light1);
            GL.Enable(EnableCap.Light2);
            GL.Enable(EnableCap.Light3);
            GL.Enable(EnableCap.Light4);
            GL.Enable(EnableCap.Light5);
            GL.Enable(EnableCap.Light6);
            GL.Enable(EnableCap.Light7);
        }
예제 #33
0
        public StartupSystem(Game game, Screen hostScreen)
            : base(game, hostScreen)
        {
            var kbListener = new KeyboardListener(new KeyboardListenerSettings
            {
                InitialDelayMilliseconds = 500,
                RepeatDelayMilliseconds  = 50,
                RepeatPress = true
            });

            _inputListener = new InputListenerComponent(GameRoot, kbListener);
            _input         = new InputHandler(GameRoot);
            GameRoot.Components.Add(_inputListener);
            GameRoot.Components.Add(_input);
            kbListener.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Left)
                {
                    _cursorPosition--;
                }
                if (args.Key == Keys.Right)
                {
                    _cursorPosition++;
                }
                if (args.Key == Keys.Insert)
                {
                    _isInsert = !_isInsert;
                }

                if (args.Key == Keys.Delete && _inputText.Length > 0 && _cursorPosition < _inputText.Length)
                {
                    _inputText = _inputText.Remove(_cursorPosition, 1);
                }

                _cursorPosition = MathHelper.Clamp(_cursorPosition, 0, _inputText.Length);
            };
            kbListener.KeyTyped += (sender, args) =>
            {
                if (args.Character != null && args.Key != Keys.Back && args.Key != Keys.Tab)
                {
                    if (_isInsert && _cursorPosition < _inputText.Length)
                    {
                        _inputText = _inputText.Remove(_cursorPosition, 1);
                    }

                    if (_inputText.Length < 33)
                    {
                        _inputText = _inputText.Insert(_cursorPosition, args.Character.ToString());
                        _cursorPosition++;
                    }
                }

                if (args.Key == Keys.Back && _inputText.Length > 0)
                {
                    _inputText = _inputText.Remove(_inputText.Length - 1, 1);
                    _cursorPosition--;
                }

                if (args.Key == Keys.Enter)
                {
                    ProcessInputString();
                    _cursorPosition = 0;
                    _inputText      = "";
                }
            };

            _viewport = new BoxingViewportAdapter(GameRoot.Window, GameRoot.GraphicsDevice, 256, 256);
        }