示例#1
0
        public bool EditSettings(IUserSettings userSettings, IInputHandler inputHandler)
        {
            inputHandler.PauseOutput = true;
            SettingsEditorForm form = new SettingsEditorForm(userSettings, inputHandler);
            bool result             = form.ShowDialog() == DialogResult.OK;

            if (result)
            {
                userSettings.ShowHotkey      = form.ShowHotkey;
                userSettings.MoveLeftHotkey  = form.MoveLeftHotkey;
                userSettings.MoveRightHotkey = form.MoveRightHotkey;
                userSettings.Sensitivity     = form.Sensitivity;
                inputHandler.LoadHotkeys(userSettings);
            }
            inputHandler.PauseOutput = false;
            return(result);
        }
示例#2
0
        public MainWindow()
        {
            var model = new OverlayModel {
                ElementsPath = System.IO.Path.Combine(Program.programPath, "Elements.json")
            };

            IWheelElements elements = model.GetElements();

            elements        = elements ?? new WheelElements();
            elements.Editor = new ElementsEditor()
            {
                WheelEditor   = new WheelEditor <Wheel>(),
                ButtonEditor  = new ButtonEditor <WheelButton>(),
                ActionEditors = new List <IActionEditor>()
                {
                    new OpenProgramEditor(), new HotkeyActionEditor(), new OpenWebsiteActionEditor(), new OpenSteamAppActionEditor()
                },
            };

            var settings = UserSettings.Instance;

            settings.Editor = new SettingsEditor();
            controller      = new OverlayController(elements, settings)
            {
                Model = model,
            };
            InitializeComponent();
            view = new TcpOverlayView(controller, settings.Port);

            inputHandler = new InputHandler {
                View = view
            };
            inputHandler.LoadHotkeys(settings);

            Job     job     = new Job();
            Process process = new Process();

            process.StartInfo.FileName  = overlayPath;
            process.StartInfo.Arguments = $"--port {settings.Port} -single-instance -window-mode borderless -screen-fullscreen 0 -screen-height 500 -screen-width 500";
            process.Start();
            job.AddProcess(process.Handle);
            CancellationTokenSource tokenSource = new CancellationTokenSource();
            Task processTask = Task.Run(process.WaitForExit, tokenSource.Token);

            while (true)
            {
                try
                {
                    view.Connect();
                    break;
                }
                catch (System.Net.Sockets.SocketException)
                {
                    if (processTask.IsCompleted)
                    {
                        throw new ConnectionClosedException();
                    }
                    continue;
                }
            }
            tokenSource.Cancel();
            tokenSource.Dispose();

            controller.View         = view;
            controller.InputHandler = inputHandler;
            view.UpdateElements(new SimplifiedWheelElements(controller.Elements));
            view.SetSensitivity(settings.Sensitivity);
        }