Exemplo n.º 1
0
 public void OnEnable()
 {
     this.mouseHandler = new MouseInputManager();
     if (this.adapter == null)
     {
         if (< > f__am$cacheF == null)
         {
Exemplo n.º 2
0
    void Awake()
    {
        networkView = GetComponent <NetworkView>();
        cam         = GameObject.Find("Camera");
        mngr        = cam.GetComponent <MouseInputManager>();
        if (server)
        {
            LaunchServer();
            mngr.enabled = false;
            StartCoroutine(checkPlayers());
        }
        else
        {
            ConnectServer();
        }
        if (Application.loadedLevelName == "MainMenu" || Application.loadedLevelName == "Options" || Application.loadedLevelName == "PlanetSelector" || Application.loadedLevelName == "ProfileSelector")
        {
            isMenu = true;
        }
        entities     = new Dictionary <Vector3Int, GameEntity> (new Vector3EqualityComparer());
        sensorSpaces = new Dictionary <Vector3Int, List <BasicSensor> > (new Vector3EqualityComparer());
        images[0]    = Resources.Load("Art/Textures/GUI/button_exit") as Texture2D;
        images[1]    = Resources.Load("Art/Textures/GUI/button_hint") as Texture2D;
        images[2]    = Resources.Load("Art/Textures/GUI/button_restart") as Texture2D;
        skin         = Resources.Load("Art/Textures/GUI/ingame_skin") as GUISkin;
        foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
        {
            if (go.name == "Camera")
            {
                CameraDecubeLevel c = go.GetComponent <CameraDecubeLevel>();
                levelCamera = c;
                break;
            }
        }
        hints = new List <string>();
        path  = "Assets/Resources/Txt/hints.txt";
        try{
            tr = new StreamReader(path);
            string temp;
            while ((temp = tr.ReadLine()) != null)
            {
                if (hints.Count == 12)
                {
                    hints.Add(temp);
                }
                hints.Add(temp);
            }

            // Close the stream
            tr.Close();
        }
        catch (FileLoadException e) {
            Debug.LogException(e);
        }
    }
Exemplo n.º 3
0
        public override void Initialize(IGameEngine engine)
        {
            base.Initialize(engine);

            // Get mouse device.
            Device = Engine.Systems.First <IInputDeviceSystem>().First(d => d is IMouseDevice)
                     as IMouseDevice;

            // Initialize manager.
            manager = new MouseInputManager(Device);
        }
Exemplo n.º 4
0
 private void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         instance = this;
     }
 }
Exemplo n.º 5
0
        public void SingleDeviceSelection(int id)
        {
            var mouse = new MouseInputManager();

            Assert.Raises <DeviceListChangedEventArgs <Mouse> >(h => mouse.DeviceListChanged += h, h => mouse.DeviceListChanged -= h, () => { });
            mouse.SelectDevice(id);
            Assert.NotEmpty(mouse.RawDevices);
            Assert.NotEmpty(mouse.Devices);
            Assert.NotEmpty(mouse.DeviceNames);
            Assert.NotNull(mouse.DeviceNames[0]);
            Assert.NotEqual("Dummy", mouse.DeviceNames[0]);
            Assert.True(mouse.DeviceNames[0].Length > 0);
            Console.WriteLine(mouse.DeviceNames[0]);
        }
Exemplo n.º 6
0
        public TilesPanel(IContainer Parent) : base(Parent)
        {
            Label Header = new Label(this);

            Header.SetText("Tiles");
            Header.SetFont(Font.Get("Fonts/Ubuntu-B", 16));
            Header.SetPosition(5, 5);

            Sprites["sep"]   = new Sprite(this.Viewport, new SolidBitmap(288, 2, new Color(10, 23, 37)));
            Sprites["sep"].Y = 50;

            Sprites["slider"]   = new Sprite(this.Viewport, new SolidBitmap(10, Size.Height - 34, new Color(10, 23, 37)));
            Sprites["slider"].Y = 53;

            this.OnWidgetSelected += WidgetSelected;

            CursorIM = new MouseInputManager(this);

            MainContainer = new Container(this);
            MainContainer.SetPosition(0, 53);
            MainContainer.VAutoScroll = true;

            VScrollBar vs = new VScrollBar(this);

            MainContainer.SetVScrollBar(vs);

            Cursor = new CursorWidget(MainContainer);
            Cursor.SetPosition(3, 8);
            Cursor.SetZIndex(1);

            MainStackPanel = new VStackPanel(MainContainer);
            MainStackPanel.SetWidth(264);
            MainStackPanel.SetPosition(8, 3);

            DrawToolsContainer = new Container(this);
            DrawToolsContainer.SetPosition(46, 22);
            DrawToolsContainer.SetSize(186, 28);
            DrawToolsContainer.Sprites["line1"]   = new Sprite(DrawToolsContainer.Viewport, new SolidBitmap(1, 26, new Color(28, 50, 73)));
            DrawToolsContainer.Sprites["line1"].X = 144;
            DrawToolsContainer.Sprites["line2"]   = new Sprite(DrawToolsContainer.Viewport, new SolidBitmap(1, 26, new Color(28, 50, 73)));
            DrawToolsContainer.Sprites["line2"].X = 185;

            PencilButton = new IconButton(DrawToolsContainer);
            PencilButton.SetIcon(15, 0);
            PencilButton.SetSelected(true);

            FillButton = new IconButton(DrawToolsContainer);
            FillButton.SetIcon(16, 0);
            FillButton.SetPosition(32, 0);

            EllipseButton = new IconButton(DrawToolsContainer);
            EllipseButton.SetIcon(17, 0);
            EllipseButton.SetPosition(64, 0);

            RectButton = new IconButton(DrawToolsContainer);
            RectButton.SetIcon(18, 0);
            RectButton.SetPosition(96, 0);

            SelectButton = new IconButton(DrawToolsContainer);
            SelectButton.SetIcon(19, 0);
            SelectButton.SetPosition(128, 0);
            SelectButton.OnSelection += delegate(BaseEventArgs e)
            {
                MapViewer.Cursor.SetVisible(false);
                Cursor.SetPosition(0, 0);
                Cursor.SetVisible(false);
            };
            SelectButton.OnDeselection += delegate(BaseEventArgs e)
            {
                UpdateCursor();
            };

            EraserButton = new IconButton(DrawToolsContainer);
            EraserButton.SetIcon(20, 0);
            EraserButton.SetPosition(160, 0);
            EraserButton.Toggleable   = true;
            EraserButton.OnSelection += delegate(BaseEventArgs e)
            {
                if (AutotileIndex != -1 || TilesetIndex != -1 || TileStartX != -1 || TileEndX != -1 || TileStartY != -1 || TileEndY != -1)
                {
                    SelectTile(null);
                }
            };
            EraserButton.OnDeselection += delegate(BaseEventArgs e)
            {
                if (AutotileIndex == -1 && TilesetIndex == -1 && TileStartX == -1 && TileEndX == -1 && TileStartY == -1 && TileEndY == -1 &&
                    !MapViewer.SelectionOnMap)
                {
                    SelectTile(0, 0, 0);
                }
                else
                {
                    UpdateCursor();
                }
            };

            SetSize(288, 200); // Dummy size so the sprites can be drawn properly
        }
    public void OnEnable()
    {
        activeInstances.Add( this );

        // Mouse input will be handled by a MouseInputManager instance to
        // consolidate the complexity of mouse operations
        mouseHandler = new MouseInputManager();

        if( useTouch )
        {
            // Multi-touch input will be handled by a TouchInputHandler instance
            // to localize code complexity
            touchHandler = new TouchInputManager( this );
        }

        // If an input adapter has not already been assigned, look for
        // a replacement or assign the default
        if( this.adapter == null )
        {

            // Look for a replacement IInputAdapter component
            var inputAdapter =
                GetComponents( typeof( MonoBehaviour ) )
                .Where( c => c != null && c.GetType() != null && typeof( IInputAdapter ).IsAssignableFrom( c.GetType() ) )
                .FirstOrDefault();

            // Use the replacement if found, otherwise use the default adapter
            this.adapter = (IInputAdapter)inputAdapter ?? new DefaultInput();

        }

        Input.simulateMouseWithTouches = !this.useTouch;
    }
Exemplo n.º 8
0
        public override void Update(GameTime gameTime)
        {
            MouseInputManager.Begin();
            KeyboardInputManager.Begin();

            // Change Gravity
            if (KeyboardInputManager.IsKeyPressed(Keys.VolumeUp))
            {
                Gravity += new Vector2(0f, -5);
            }
            if (KeyboardInputManager.IsKeyPressed(Keys.VolumeDown))
            {
                Gravity -= new Vector2(0f, -5);
            }

            // Change Impulse
            if (KeyboardInputManager.IsKeyPressed(Keys.Up))
            {
                _impulse += 10f;
            }
            if (KeyboardInputManager.IsKeyPressed(Keys.Down))
            {
                _impulse -= 10f;
            }

            if (_impulse == 0f)
            {
                _impulse = _playerBodyComponent.Mass * 10 / DeltaTime;
            }

            #region Camera
            _cameraPosition.X = MouseInputManager.GetPosition().X;
            _cameraPosition.Y = InvertPositionY(MouseInputManager.GetPosition().Y);

            Camera2D.Position = _cameraPosition;

            if (KeyboardInputManager.IsKeyDown(Keys.OemPlus))
            {
                Camera2D.Zoom -= new Vector2(0.01f);
            }

            if (KeyboardInputManager.IsKeyDown(Keys.OemMinus))
            {
                Camera2D.Zoom += new Vector2(0.01f);
            }

            if (KeyboardInputManager.IsKeyPressed(Keys.R))
            {
                Camera2D.Reset();
            }
            #endregion

            #region Player
            if (KeyboardInputManager.IsKeyDown(Keys.Right))
            {
                _playerBodyComponent.SetLinearVelocityX(100f);
                _isMoving = true;
            }

            if (KeyboardInputManager.IsKeyDown(Keys.Left))
            {
                _playerBodyComponent.SetLinearVelocityX(-100f);
                _isMoving = true;
            }

            if (!_isMoving)
            {
                _playerBodyComponent.SetLinearVelocityX(0f);
                _impulse = _playerBodyComponent.Mass * 10 / DeltaTime;
            }

            if (KeyboardInputManager.IsKeyPressed(Keys.Space))
            {
                _playerBodyComponent.ApplyLinearImpulseY(_impulse);
            }
            #endregion

            KeyboardInputManager.End();
            MouseInputManager.End();

            _textComponent.Text = BuildDebugText();
            _isMoving           = false;

            base.Update(gameTime);
        }
Exemplo n.º 9
0
        private void OnInitialized(object sender, EventArgs e)
        {
            var mergedmouseman     = new MouseInputManager();
            var individualmouseman = new MouseInputManager();

            individualmouseman.SelectDevice(false, (info, i) => true);
            var mice       = mergedmouseman.WrappedDevices.Concat(individualmouseman.WrappedDevices).ToArray();
            var mousenames = mergedmouseman.DeviceNames.Concat(individualmouseman.DeviceNames).ToArray();
            var accmice    = mice.Select(currmnouse =>
            {
                var res = new AccumulatingMouseObserver();
                res.SubscribeTo(currmnouse.Device.MouseNotifications);
                return(res);
            }).ToArray();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                for (int i = 0; i < accmice.Length; i++)
                {
                    Mice.Items.Add(new MouseDevice(mice[i], accmice[i]));
                }
            }));

            var mergedkeyman = new KeyboardInputManager();

            mergedkeyman.SelectDevice(-1);
            var individualkeyman = new KeyboardInputManager();

            individualkeyman.SelectDevice(Enumerable.Range(0, mergedkeyman.RawDevices.Count).ToArray());
            var keyboards     = mergedkeyman.Devices.Concat(individualkeyman.Devices).ToArray();
            var keyboardnames = mergedkeyman.DeviceNames.Concat(individualkeyman.DeviceNames).ToArray();
            var acckeyboards  = keyboards.Select(currkb =>
            {
                var res = new AccumulatingKeyboardObserver();
                res.SubscribeTo(currkb.KeyNotifications);
                return(res);
            }).ToArray();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                AggregatedKeyboards = new ObservableCollection <string>(new string[acckeyboards.Length]);
                Keyboards.ItemsSource = AggregatedKeyboards;
                Observable.Interval(new TimeSpan(0, 0, 0, 0, 20)).Subscribe(t =>
                {
                    Dispatcher.BeginInvoke((Action)(() =>
                    {
                        for (int i = 0; i < AggregatedKeyboards.Count; i++)
                        {
                            AggregatedKeyboards[i] = acckeyboards[i].Keypresses
                                                     .Where(kvp => kvp.Value.Pressed)
                                                     .Aggregate(keyboardnames[i] + Environment.NewLine, (s, key) =>
                            {
                                return(s += (s == keyboardnames[i] + Environment.NewLine ? "" : ", ") +
                                            key.Key.ToString()
                                            //.Repeat(Math.Max(key.Value.Count, 1))
                                            .Aggregate("", (s1, c) => s1 + c));
                            });
                            acckeyboards[i].ResetAccumulation();
                        }
                    }));
                });
            }));
        }
Exemplo n.º 10
0
 private void Awake()
 {
     Instance = this;
 }
Exemplo n.º 11
0
    void Awake()
    {
        networkView = GetComponent<NetworkView>();
        cam = GameObject.Find("Camera");
        mngr = cam.GetComponent<MouseInputManager>();
        if (server){
            LaunchServer();
            mngr.enabled = false;
            StartCoroutine(checkPlayers());
        }else{
            ConnectServer();
        }
        if (Application.loadedLevelName == "MainMenu" || Application.loadedLevelName == "Options" || Application.loadedLevelName == "PlanetSelector" || Application.loadedLevelName == "ProfileSelector")
        {
            isMenu = true;
        }
        entities = new Dictionary<Vector3Int, GameEntity> (new Vector3EqualityComparer ());
        sensorSpaces = new Dictionary<Vector3Int, List<BasicSensor>> (new Vector3EqualityComparer ());
        images[0] = Resources.Load("Art/Textures/GUI/button_exit") as Texture2D;
        images[1] = Resources.Load("Art/Textures/GUI/button_hint") as Texture2D;
        images[2] = Resources.Load("Art/Textures/GUI/button_restart") as Texture2D;
        skin = Resources.Load("Art/Textures/GUI/ingame_skin") as GUISkin;
        foreach (GameObject go in FindObjectsOfType(typeof(GameObject))){
            if (go.name == "Camera"){
                CameraDecubeLevel c = go.GetComponent<CameraDecubeLevel>();
                levelCamera = c;
                break;
            }
        }
        hints = new List<string>();
        path = "Assets/Resources/Txt/hints.txt";
        try{
            tr = new StreamReader(path);
            string temp;
            while((temp = tr.ReadLine()) != null)
            {
                if(hints.Count == 12){
                    hints.Add(temp);
                }
                hints.Add(temp);
            }

            // Close the stream
            tr.Close();
        }
        catch(FileLoadException e) {
            Debug.LogException(e);
        }
    }