상속: MonoBehaviour
 void Awake()
 {
     Instance = this;
     clickStarted = new Dictionary<int, bool>();
     clickStartTime = new Dictionary<int, double>();
     actualMouseDirection = new Vector2(0,0);
     mousePosition = new Vector2(0,0);
     mouseStartPosition = new Vector2(0,0);
 }
예제 #2
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()
        {
            // TODO: Add your initialization logic here
            inputEvents = new InputEvents(Keyboard.GetState(), Mouse.GetState());
            inputEvents.RegisterForKeyUp(HandleKeyEscape, Keys.F1);

            this.IsMouseVisible = true;

            base.Initialize();
        }
예제 #3
0
    public Windowing( Game g )
    {
        game = g as SPW ;

        this.input = new InputEvents( game );
        game.Components.Add( this.input );

        this.gui = new GUIManager( game );
        game.Components.Add( this.gui );

        this.gui.Initialize();
    }
예제 #4
0
        public MotorkiGame()
        {
            game = this;
            random = new Random();

            ieGenerator = new InputEvents(this, 500, 50, 100, 50);
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            layerTargets = new RenderTarget2D[6];
            mCursor = new MouseCursor(this);
            loading_stage = -1;
            loading_stages = new List<GameLoadingStages>();
            connecting_stage = -1;
            gameSettings = new GameSettings();
            gameSettings.LoadFromFile("settings.xml");
        }
예제 #5
0
    public override void DoFixedUpdate()
    {
        // Store initial AI
        if (initialAI == null && ai != null) initialAI = ai;

        if (this.inferenceEngine != null && UFE.config.aiOptions.engine == AIEngine.FuzzyAI){
            ControlsScript self = UFE.GetControlsScript(this.player);
            if (this.inputReferences != null && this.inputBuffer != null && self != null){
                ControlsScript opponent = self.opControlsScript;
                if (opponent != null){
                    //-------------------------------------------------------------------------------------------------
                    // Check the information stored in the input buffer...
                    //-------------------------------------------------------------------------------------------------
                    if (this.inputBuffer.Count == 0){
                        //---------------------------------------------------------------------------------------------
                        // If the we don't have the input of the previous frame, use the default input...
                        //---------------------------------------------------------------------------------------------
                        Dictionary<InputReferences, InputEvents> frame = new Dictionary<InputReferences, InputEvents>();
                        foreach (InputReferences input in this.inputReferences){
                            frame[input] = InputEvents.Default;
                        }
                        this.inputBuffer.Add(frame);
                    }else if (this.inputBuffer.Count >= 2){
                        this.inputBuffer.RemoveAt(0);
                    }

                    //-------------------------------------------------------------------------------------------------
                    // If we haven't decided the input for the current frame yet...
                    //-------------------------------------------------------------------------------------------------
                    if (this.inputBuffer.Count < 2){
                        //---------------------------------------------------------------------------------------------
                        // Ask the AI to choose the most appropriated movement...
                        //---------------------------------------------------------------------------------------------
                        MovementInfo chosenMovement = this.ChooseMovement(self, opponent, Time.fixedDeltaTime);

                        //---------------------------------------------------------------------------------------------
                        // And simulate the input required for executing the next movement
                        //---------------------------------------------------------------------------------------------
                        if (chosenMovement != null && chosenMovement.simulatedInput.Length > 0){
                            // HACK: added debug information, we should place this code in a more appropriated place
                            /*
                            RenderTexture renderTexture = new RenderTexture(300,40,24);
                            RenderTexture.active = renderTexture;

                            GameObject tempObject = new GameObject("Temporary");
                            tempObject.transform.position = new Vector3(-10000f, -10000f, -10000f);
                            tempObject.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);

                            Camera myCamera = tempObject.AddComponent<Camera>();
                            myCamera.orthographic = true;
                            myCamera.orthographicSize = 4;
                            myCamera.targetTexture = renderTexture;

                            GameObject childObject = new GameObject("TextMesh");
                            childObject.transform.parent = tempObject.transform;
                            childObject.transform.localPosition = new Vector3(0f, 0f, 1f);
                            childObject.transform.localScale = Vector3.one;
                            childObject.transform.localRotation = Quaternion.identity;

                            TextMesh tm = childObject.AddComponent<TextMesh>();
                            tm.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
                            tm.renderer.material = new Material(Shader.Find("GUI/Text Shader"));
                            tm.renderer.material.mainTexture = tm.font.material.mainTexture;
                            tm.renderer.material.color = Color.black;
                            tm.fontSize = 36;
                            tm.fontStyle = FontStyle.Bold;
                            tm.alignment = TextAlignment.Center;
                            tm.anchor = TextAnchor.MiddleCenter;
                            tm.text = (self.currentMove == null) + " -> " + chosenMovement.name;
                            myCamera.Render();

                            RenderTexture.active = null;
                            GameObject.Destroy(tempObject);
                             */

                            //UFE.CastInput(InputType.Button, 0f, renderTexture, this.player);
                            //---------------------------------------------------------------------------------//

                            float sign = Mathf.Sign(opponent.transform.position.x - self.transform.position.x);
                            foreach (ButtonPress[] buttonPresses in chosenMovement.simulatedInput){
                                Dictionary<InputReferences,InputEvents> frame = new Dictionary<InputReferences,InputEvents>();
                                foreach (InputReferences input in this.inputReferences){
                                    frame[input] = InputEvents.Default;
                                }

                                foreach (InputReferences input in this.inputReferences){
                                    if (input.inputType == InputType.HorizontalAxis){
                                        foreach (ButtonPress buttonPress in buttonPresses){
                                            if (buttonPress == ButtonPress.Back){
                                                frame[input] = new InputEvents(-1f * sign);
                                            }else if (buttonPress == ButtonPress.Foward){
                                                frame[input] = new InputEvents(1f * sign);
                                            }
                                        }
                                    }else if (input.inputType == InputType.VerticalAxis){
                                        foreach (ButtonPress buttonPress in buttonPresses){
                                            if (buttonPress == ButtonPress.Up){
                                                frame[input] = new InputEvents(1f);
                                            }else if (buttonPress == ButtonPress.Down){
                                                frame[input] = new InputEvents(-1f);
                                            }
                                        }
                                    }else{
                                        foreach (ButtonPress buttonPress in buttonPresses){
                                            if (input.engineRelatedButton == buttonPress){
                                                frame[input] = new InputEvents(true);
                                            }
                                        }
                                    }
                                }
                                this.inputBuffer.Add(frame);
                            }
                        }else{
                            Dictionary<InputReferences, InputEvents> frame = new Dictionary<InputReferences, InputEvents>();
                            foreach (InputReferences input in this.inputReferences){
                                frame[input] = InputEvents.Default;
                            }
                            this.inputBuffer.Add(frame);
                        }
                    }
                }
            }

            /*
            string debug = "Player " + this.player;
            foreach (InputReferences input in this.inputReferences){
                if (input.inputType == InputType.HorizontalAxis){
                    debug += "\nHorizontal: " + this.GetAxis(input);
                }else if (input.inputType == InputType.VerticalAxis){
                    debug += "\nVertical: " + this.GetAxis(input);
                }else{
                    debug += "\n" + input.engineRelatedButton + ": " + this.GetButton(input);
                }
            }
            Debug.Log(debug);
            */

        }else{
            base.DoFixedUpdate();
        }
    }
예제 #6
0
 public void OnEvent(InputEvents.InputEvent ev)
 {
     _events.Enqueue(ev);
 }
예제 #7
0
        protected void OnUpdate()
        {
            ActionsFired.Clear();
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            foreach (KeyValuePair <InputActions, InputState> action in Inputs.Info)
            {
                // Manage mouse events.
                if (!action.Value.IsKeyboard && action.Value.MouseKey != MouseKeys.None)
                {
                    if (CheckMouseState(keyboardState, mouseState, action.Value))
                    {
                        if (InputEvents.ContainsKey(action.Key))
                        {
                            InputEvents[action.Key](this, new InputEventArgs()
                            {
                                MousePosition = MousePosition
                            });
                        }
                        ActionsFired.Add(action.Key);
                    }
                }
                else if (action.Value.KeyboardKey != Keys.None)
                {
                    switch (action.Value.State)
                    {
                    // The type of key state.
                    case KeyState.Up:
                        // Makes sure it is in the good state.
                        if (keyboardState.IsKeyUp(action.Value.KeyboardKey) && (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            // Adds it to the list to be able to query all event fired in this frame.
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Down:
                        if (keyboardState.IsKeyDown(action.Value.KeyboardKey) && (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Pressed:
                        if (keyboardState.IsKeyDown(action.Value.KeyboardKey) && OldKeyboard.IsKeyUp(action.Value.KeyboardKey) &&
                            (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;

                    case KeyState.Released:
                        if (keyboardState.IsKeyUp(action.Value.KeyboardKey) && OldKeyboard.IsKeyDown(action.Value.KeyboardKey) &&
                            (!action.Value.Sensitive || CheckDeadKey(keyboardState, action.Value.DeadKey)))
                        {
                            if (InputEvents.ContainsKey(action.Key))
                            {
                                InputEvents[action.Key](this, new InputEventArgs());
                            }
                            ActionsFired.Add(action.Key);
                        }
                        break;
                    }
                }
            }
            OldKeyboard = keyboardState;
            OldMouse    = mouseState;

            if (IsWindowReady && IsActive)
            {
                Cursor.Position = MousePosition;
            }
        }
예제 #8
0
        /// <summary>
        /// Process mouse events.
        /// </summary>
        /// <param name="Event"></param>
        /// <param name="Args"></param>
        public void HandleInput(InputEvents Event, InputEventArgs Args)
        {
            switch (Event)
            {
            case InputEvents.MouseMove:
            {
                // Destroy tooltips when the mouse moves.
                MouseMotionTime = DateTime.Now;

                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs {
                    X = MousePosition.X, Y = MousePosition.Y
                };
                // Detect hover item and fire mouse enter/leave events as appropriate.
                var newHoverItem = RootItem.FindWidgetAt(MousePosition.X, MousePosition.Y);
                if (!Object.ReferenceEquals(newHoverItem, HoverItem))
                {
                    if (HoverItem != null)
                    {
                        SafeCall(HoverItem.OnMouseLeave, HoverItem, newArgs);
                    }
                    if (newHoverItem != null)
                    {
                        SafeCall(newHoverItem.OnMouseEnter, newHoverItem, newArgs);
                    }
                    if (TooltipItem != null)
                    {
                        DestroyWidget(TooltipItem);
                    }
                    HoverItem = newHoverItem;
                }

                if (MouseDownItem != null)
                {
                    SafeCall(MouseDownItem.OnMouseMove, MouseDownItem,
                             new InputEventArgs {
                            X = MousePosition.X, Y = MousePosition.Y
                        });
                }

                if (HoverItem != null && !Object.ReferenceEquals(HoverItem, MouseDownItem))
                {
                    SafeCall(HoverItem.OnMouseMove, HoverItem,
                             new InputEventArgs {
                            X = MousePosition.X, Y = MousePosition.Y
                        });
                }
            }
            break;

            case InputEvents.MouseDown:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                MouseDownItem = null;
                if (PopupStack.Count != 0)
                {
                    if (IsHoverPartOfPopup())
                    {
                        MouseDownItem = HoverItem;
                    }
                }
                else
                {
                    MouseDownItem = HoverItem;
                }

                if (MouseDownItem != null)
                {
                    CallOnMouseDown(MouseDownItem, newArgs);
                }
            }
            break;

            case InputEvents.MouseUp:
            {
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                if (MouseDownItem != null)
                {
                    CallOnMouseUp(MouseDownItem, newArgs);
                }
                //MouseDownItem = null;
            }
            break;

            case InputEvents.MouseClick:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));

                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                if (PopupStack.Count != 0)
                {
                    if (HoverItem == null || !IsHoverPartOfPopup())
                    {
                        if (PopupStack[PopupStack.Count - 1].PopupDestructionType == PopupDestructionType.DestroyOnOffClick)
                        {
                            DestroyWidget(PopupStack[PopupStack.Count - 1]);
                        }

                        MouseDownItem = null;
                        return;
                    }

                    if (IsHoverPartOfPopup())
                    {
                        Args.Handled = true;
                        if (Object.ReferenceEquals(HoverItem, MouseDownItem))
                        {
                            CallOnClick(HoverItem, newArgs);
                        }
                        MouseDownItem = null;
                        return;
                    }

                    MouseDownItem = null;
                    return;
                }

                if (HoverItem != null && Object.ReferenceEquals(HoverItem, MouseDownItem))
                {
                    Args.Handled = true;
                    CallOnClick(HoverItem, newArgs);
                }
                else
                {
                    SetFocus(null);
                }
                MouseDownItem = null;
            }
            break;

            case InputEvents.MouseWheel:
            {
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    ScrollValue = Args.ScrollValue
                };

                if (HoverItem != null)
                {
                    Args.Handled = true;
                    CallOnScroll(HoverItem, newArgs);
                }
            }
            break;

            case InputEvents.KeyPress:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyPress, FocusItem, Args);
                }
                break;

            case InputEvents.KeyDown:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyDown, FocusItem, Args);
                }
                break;

            case InputEvents.KeyUp:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyUp, FocusItem, Args);
                }
                break;
            }
        }
예제 #9
0
    public override void DoFixedUpdate()
    {
        //this.ShowDebugInformation();


        ControlsScript self = UFE.GetControlsScript(this.player);

        if (this.inputReferences != null && this.inputBuffer != null && self != null)
        {
            ControlsScript opponent = self.opControlsScript;
            if (opponent != null)
            {
                //-------------------------------------------------------------------------------------------------
                // Check the information stored in the input buffer...
                //-------------------------------------------------------------------------------------------------
                if (this.inputBuffer.Count == 0)
                {
                    //---------------------------------------------------------------------------------------------
                    // If the we don't have the input of the previous frame, use the default input...
                    //---------------------------------------------------------------------------------------------
                    Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                    foreach (InputReferences input in this.inputReferences)
                    {
                        frame[input] = InputEvents.Default;
                    }
                    this.inputBuffer.Add(frame);
                }
                else if (this.inputBuffer.Count >= 2)
                {
                    this.inputBuffer.RemoveAt(0);
                }

                //-----------------------------------------------------------------------------------------------------
                // If we haven't decided the input for the current frame yet...
                //-----------------------------------------------------------------------------------------------------
                if (this.inputBuffer.Count < 2)
                {
                    //-------------------------------------------------------------------------------------------------
                    // And simulate the input required for executing the next movement
                    //-------------------------------------------------------------------------------------------------
                    if (
                        this.behaviour != null
                        &&
                        this.behaviour.steps.Length > 0
                        &&
                        self.currentMove == null
                        &&
                        (
                            self.currentBasicMove == BasicMoveReference.Idle ||
                            self.currentBasicMove == BasicMoveReference.Crouching
                        )
                        )
                    {
                        float sign = Mathf.Sign(opponent.transform.position.x - self.transform.position.x);

                        foreach (SimpleAIStep step in this.behaviour.steps)
                        {
                            Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                            foreach (InputReferences input in this.inputReferences)
                            {
                                frame[input] = InputEvents.Default;
                            }

                            foreach (InputReferences input in this.inputReferences)
                            {
                                if (input.inputType == InputType.HorizontalAxis)
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (buttonPress == ButtonPress.Back)
                                        {
                                            frame[input] = new InputEvents(-1f * sign);
                                        }
                                        else if (buttonPress == ButtonPress.Forward)
                                        {
                                            frame[input] = new InputEvents(1f * sign);
                                        }
                                    }
                                }
                                else if (input.inputType == InputType.VerticalAxis)
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (buttonPress == ButtonPress.Up)
                                        {
                                            frame[input] = new InputEvents(1f);
                                        }
                                        else if (buttonPress == ButtonPress.Down)
                                        {
                                            frame[input] = new InputEvents(-1f);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (input.engineRelatedButton == buttonPress)
                                        {
                                            frame[input] = new InputEvents(true);
                                        }
                                    }
                                }
                            }

                            for (int i = 0; i < step.frames; ++i)
                            {
                                this.inputBuffer.Add(frame);
                            }
                        }
                    }
                    else
                    {
                        Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                        foreach (InputReferences input in this.inputReferences)
                        {
                            frame[input] = InputEvents.Default;
                        }
                        this.inputBuffer.Add(frame);
                    }
                }
            }
        }
    }
예제 #10
0
        public DetailPage(int id)
        {
            InitializeComponent();

            WaitingView.Opacity = 1.0;

            Task.Run(async() =>
            {
                var client      = new TMDbClient(TMDbAPIKey.Key);
                var taskMovie   = client.GetMovieAsync(id);
                var taskSimilar = client.GetMovieSimilarAsync(id);
                var taskCredit  = client.GetMovieCreditsAsync(id);
                var taskVideo   = client.GetMovieVideosAsync(id);
                var movie       = await taskMovie;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    WaitingView.Opacity = 0.0;
                    _movie         = movie;
                    BindingContext = movie;

                    var credit = await taskCredit;
                    var cast   = new CastListModel
                    {
                        Items = credit.Cast
                    };
                    CastList.BindingContext = cast;

                    var similars = await taskSimilar;
                    _similars    = new MovieListModel
                    {
                        Title = "Similar Movies",
                        Items = similars.Results,
                    };
                    SimilarList.BindingContext = _similars;

                    var videos = await taskVideo;
                    int i      = 0;
                    foreach (var video in videos.Results)
                    {
                        if (video.Site == "YouTube")
                        {
                            i++;
                            var button = new Button
                            {
                                Text = $"Watch trailer #{i}",
                                HorizontalOptions = LayoutOptions.Center,
                                VerticalOptions   = LayoutOptions.CenterAndExpand
                            };
                            button.Clicked += (s, e) =>
                            {
#if USE_VIDEOPAGE
                                Navigation.PushAsync(new VideoPage(video.Key));
#else
                                AppControl appControl    = new AppControl();
                                appControl.ApplicationId = "com.samsung.tv.cobalt-yt";
                                appControl.Operation     = AppControlOperations.Default;
                                appControl.ExtraData.Add("PAYLOAD", $"#play?v={video.Key}");
                                AppControl.SendLaunchRequest(appControl);
#endif
                                Console.WriteLine($"ID : {video.Key}");
                            };
                            Console.WriteLine($"Video : {video.Key} {video.Name} {video.Site}");
                            ButtonArea.Children.Add(button);

                            InputEvents.GetEventHandlers(button).Add(
                                new RemoteKeyHandler((arg) => {
                                if (arg.KeyName == RemoteControlKeyNames.Up)
                                {
                                    ScrollView.ScrollToAsync(0, 0, true);
                                    arg.Handled = true;
                                }
                            }, RemoteControlKeyTypes.KeyDown
                                                     ));
                        }
                        if (i > 2)
                        {
                            break;
                        }
                    }
                });
            });
        }