Beispiel #1
0
    private void handleInput()
    {
        handleUIListeners();

        if (controllerState.Equals(ControllerState.Map))
        {
            handleMapInput();
        }
    }
Beispiel #2
0
        bool SearchDevices()
        {
            if (hidStream != null)
            {
                hidStream.Dispose();
                hidStream = null;
            }

            var list = DeviceList.Local;
            var dev  = list.GetHidDevices().FirstOrDefault(d => d.GetProductName().Contains("FrSky"));

            if (dev == null)
            {
                Console.WriteLine("No FrSky device found.");
                return(false);
            }
            if (dev.TryOpen(out hidStream))
            {
                hidStream.ReadTimeout = Timeout.Infinite;
                var inputReportBuffer   = new byte[dev.GetMaxInputReportLength()];
                var rawReportDescriptor = dev.GetRawReportDescriptor();
                var reportDescriptor    = dev.GetReportDescriptor();

                var inputReceiver = reportDescriptor.CreateHidDeviceInputReceiver();
                foreach (var deviceItem in reportDescriptor.DeviceItems)
                {
                    var inputParser = deviceItem.CreateDeviceItemInputParser();
                    inputReceiver.Received += (sender, e) =>
                    {
                        Report report;

                        while (inputReceiver.TryRead(inputReportBuffer, 0, out report))
                        {
                            if (inputParser.TryParseReport(inputReportBuffer, 0, report))
                            {
                                WriteDeviceItemInputParserResult(inputParser);
                            }
                        }
                        if (oldState == null || !controllerState.Equals(oldState))
                        {
                            Console.WriteLine(controllerState);
                            UpdateControlState();
                            oldState = controllerState.Clone();
                        }
                    };
                }
                inputReceiver.Start(hidStream);
                Console.WriteLine("FrSky device found and initialized.");
            }
            else
            {
                Console.WriteLine($"Can't open device {dev.GetFriendlyName()}. Check permissions for {dev.GetFileSystemName()}.");
                return(false);
            }
            return(true);
        }
Beispiel #3
0
    void Update()
    {
        if (controllerState.Equals(ControllerState.WorldCreation) && !worldBuilderMenu.creationInProgress)
        {
            worldData = worldBuilderMenu.extractWorldData();
            //infoLayer.updateWorldData(worldData);
            mapMenu.loadRegionHub(ref worldData);
            controllerState = ControllerState.Map;
        }
        else if (controllerState.Equals(ControllerState.Map))
        {
            mapMenu.manualUpdate(ref worldData);

            if (mapMenu.getMapState().Equals(MapMenuHandler.MapState.World))
            {
                constructAndSendJob(mapMenu.getCurrentTile());
            }
            else if (mapMenu.getMapState().Equals(MapMenuHandler.MapState.Region))
            {
                checkHoverTile(InfoLayerJob.InfoJob.TownPreview);
            }
        }
        else
        {
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            uIHandler.showUI(UIHandlerBehaviour.Type.Map);
            mapMenu.focusList();
            controllerState = ControllerState.Map;
        }

        if (Input.GetKeyDown(KeyCode.Y))
        {
            uIHandler.hideAllUI();
            controllerState = ControllerState.None;
        }
    }
        protected override void ProcessController()
        {
            ControllerState newState = new ControllerState();
            JoystickState joyState = new JoystickState();

            if (this.padsList == null || !this.padsList.Any())
            {
                this.padsList = this.GetGamePads();
                if (!this.padsList.Any()) return;
            }

            if (this.device == null)
            {
                this.device = this.padsList[0];
            }

            if (this.pad == null)
            {
                this.Acquire();
            }

            if (this.pad == null || this.pad.Poll().IsFailure || this.pad.GetCurrentState(ref joyState).IsFailure)
            {
                newState.Active = false;
            }
            else
            {
                //var objs = pad.GetObjects();
                newState.Active = true;
                newState.X = (joyState.X / 5000d);
                newState.Y = (joyState.Y / 5000d);
                newState.Buttons = joyState.GetButtons();
            }

            if (!newState.Equals(this.State))
            {

                this.State = newState;

                if (this.OnUpdate != null)
                {
                    this.OnUpdate.Invoke(this.State);
                }
            }
        }