Example #1
0
 public IsometricTest(LegatusGame game, int width, int depth, int height)
 {
     Game  = game;
     Input = new InputEventHandler();
     Input.KeyboardAction += OnKeyboardAction;
     Input.MouseDrag      += OnMouseDrag;
     Input.MouseScroll    += OnMouseScroll;
     RNG             = new Random();
     Block           = game.Content.Load <Texture2D>("Graphics/Isometric/IsometricBlock.png");
     BorderlessBlock = game.Content.Load <Texture2D>("Graphics/Isometric/IsometricBlockBorderless.png");
     Floor           = game.Content.Load <Texture2D>("Graphics/Isometric/IsometricFloor.png");
     BorderlessFloor = game.Content.Load <Texture2D>("Graphics/Isometric/IsometricFloorBorderless.png");
     Wall            = game.Content.Load <Texture2D>("Graphics/Isometric/IsometricWall.png");
     White           = game.Content.Load <Texture2D>("Graphics/WhiteTile.png");
     Font            = game.Content.Load <SpriteFont>("Graphics/DefaultFont12");
     TileGrid        = new Tile[width, depth, height];
     for (int z = 0; z < height; z++)
     {
         for (int y = 0; y < depth; y++)
         {
             for (int x = 0; x < width; x++)
             {
                 TileGrid[x, y, z] = new Tile(this, x, y, z);
             }
         }
     }
     GenerateMap();
 }
 public void SubscribeInputChanges(InputEventHandler e)
 {
     if (OnInputChanged == null)
         OnInputChanged = new InputEventHandler(e);
     else
         OnInputChanged += new InputEventHandler(e);
 }
Example #3
0
 public void InputHandler(InputEventHandler args)
 {
     if ((args.NewlyPressed & InputFlags.PlayerSpell1) != 0)
     {
         Cast(Player.instance);
     }
 }
Example #4
0
        public static void SafeSendEvent(InputEventHandler handler, object sender, InputEvent e)
        {
            var tmp = handler;

            if (tmp != null)
            {
                tmp(sender, e);
            }
        }
 // we only use one InputEventHandler function to publish/fire all of the different events
 void OnControllerInput(InputEventHandler handler, InputEventArgs e)
 {
     // check that the handler passed in is not null
     if (handler != null)
     {
         // call it
         handler(e);
     }
 }
 // Use this for initialization
 void Start()
 {
     playerCtl            = GetComponent <PlayerCtl>();
     characterStateActVer = new State(gameObject);
     Debug.Log(playerCtl.charcter_state[0]);
     foreach (State state in playerCtl.charcter_state)
     {
         InputTran += new InputEventHandler(state.handleInput);//向所有状态发送事件
     }
 }
Example #7
0
 public LanguageTest(LegatusGame game)
 {
     Input = new InputEventHandler();
     Input.KeyboardAction += OnKeyboardAction;
     //Input.KeyReleased += new KeyReleasedDelegate(OnKeyReleased);
     Font    = game.Content.Load <SpriteFont>("Graphics/DefaultFont12IPA");
     Factory = new ProceduralLanguageFactory(RNG);
     CreateLanguages();
     CreateWords();
     CreateLoanwords();
 }
    // this intermediate function is used to build the arguments for the event
    public void SendEvent(InputEventHandler handler, SteamVR_Controller.Device cont, float padX, float padY)
    {
        InputEventArgs args = new InputEventArgs();

        args.controller = cont;
        args.type       = GetControllerType(cont);
        args.padX       = padX;
        args.padY       = padY;

        OnControllerInput(handler, args);
    }
Example #9
0
 public StatusWindow(GUIIrcConnection baseCon)
     : base(baseCon)
 {
     InitializeComponent();
     AssociatedConnection.BaseConnection.PingReceived += new PingReceivedEventHandler(Client_OnPing);
     AssociatedConnection.BaseConnection.ModeReceived += new ModeReceivedEventHandler(Client_ModeReceived);
     MotdValue = new MotdListener(AssociatedConnection.BaseConnection);
     MotdValue.MotdEnd += new MotdEndEventHandler(MotdValue_MotdEnd);
     Input += new InputEventHandler(StatusWindow_Input);
     Disposed += new EventHandler(StatusWindow_Disposed);
 }
Example #10
0
 public GameUI(LegatusGame game, InputEventHandler input)
 {
     Game                   = game;
     Children               = new List <UIElement>();
     input.KeyboardAction  += OnKeyboardAction;
     input.MouseOver       += OnMouseOver;
     input.MouseAction     += OnMouseAction;
     input.MouseDrag       += OnMouseDrag;
     input.MouseScroll     += OnMouseScroll;
     game.Window.TextInput += OnTextInput;
 }
        /// <summary>
        /// Determines all the input events that have occured since the last frame and calls their
        /// respective handlers, while the gamestate may be changed in the callback functions, all
        /// events will be called for the gamestate we are in before UpdateHandler is called.
        /// </summary>
        /// <param name="time">Elapsed GameTime since the last update</param>
        public void UpdateHandler(GameTime time)
        {
            MouseState    mouse    = Mouse.GetState();
            KeyboardState keystate = Keyboard.GetState();
            List <int>    events   = new List <int>();

            int deltaX = lastMouseX - mouse.X;
            int deltaY = lastMouseY - mouse.Y;
            int deltaZ = lastScrollWheel - mouse.ScrollWheelValue;

            Vector3 mouseChange = new Vector3(deltaX, deltaY, deltaZ);

            if (deltaX != 0 || deltaY != 0)
            {
                events.Add((int)Events.MouseMove);
            }

            if (deltaZ != 0)
            {
                events.Add((int)Events.ScrollWheelMove);
            }

            if (leftMouseDown == true && mouse.LeftButton == ButtonState.Released)
            {
                events.Add((int)Events.LeftClick);
                leftMouseDown = false;
            }
            else if (mouse.LeftButton == ButtonState.Pressed)
            {
                leftMouseDown = true;
            }

            if (rightMouseDown == true && mouse.RightButton == ButtonState.Released)
            {
                events.Add((int)Events.RightClick);
                rightMouseDown = false;
            }
            else if (mouse.RightButton == ButtonState.Pressed)
            {
                rightMouseDown = true;
            }

            int state = (int)currentState;

            foreach (int eventFound in events)
            {
                InputEventHandler handler = (InputEventHandler)handlerMap[state][eventFound];
                if (handler != null)
                {
                    handler(mouse, keystate.GetPressedKeys(), mouseChange);
                }
            }
        }
Example #12
0
 /// <summary>
 /// Hooks or unhooks the event
 /// </summary>
 /// <param name="state">Game state</param>
 /// <param name="update">Update event</param>
 private void Set(IGameState state, InputEventHandler update)
 {
     if (null != State && null != Update)
     {
         State.Update -= Update;
     }
     _state = state;
     _update = update;
     if (null != State && null != Update)
     {
         State.Update += Update;
     }
 }
Example #13
0
 public MenuItem(string txt, Screen screenLink, LinkedEvent evLink)
 {
     enabled = true;
     text = txt;
     linksTo = screenLink;
     if (evLink != null)
     {
         eventLink = new InputEventHandler(evLink);
     }
     else
     {
         eventLink = null;
     }
 }
Example #14
0
 public MenuItem(string txt, Screen screenLink, LinkedEvent evLink)
 {
     enabled = true;
     text    = txt;
     linksTo = screenLink;
     if (evLink != null)
     {
         eventLink = new InputEventHandler(evLink);
     }
     else
     {
         eventLink = null;
     }
 }
Example #15
0
 public DialogItem(string txt, Dialog dialogLink, LinkedEvent evLink)
 {
     //enabled = true;
     text    = txt;
     linksTo = dialogLink;
     if (evLink != null)
     {
         eventLink = new InputEventHandler(evLink);
     }
     else
     {
         eventLink = null;
     }
 }
Example #16
0
 public DialogItem(string txt, Dialog dialogLink, LinkedEvent evLink)
 {
     //enabled = true;
     text = txt;
     linksTo = dialogLink;
     if (evLink != null)
     {
         eventLink = new InputEventHandler(evLink);
     }
     else
     {
         eventLink = null;
     }
 }
    void Start()
    {
        personCtrl        = this.GetComponent <HeroCtrl>();
        heroStateActVer   = new IdleStateActVer(this.gameObject);
        heroStateMoveVer  = new IdleStateMoveVer(this.gameObject);
        inputArgs         = new InputEventArgs("", "", "");
        hero_act_state[0] = new IdleStateActVer(this.gameObject);
        hero_act_state[1] = new ActState(this.gameObject);
        hero_act_state[2] = new DefenseState(this.gameObject);

        hero_move_state[0] = new IdleStateMoveVer(this.gameObject);
        hero_move_state[1] = new MoveState(this.gameObject);
        hero_move_state[2] = new JumpState(this.gameObject);

        InputTran += new InputEventHandler(heroStateActVer.handleInput);
        InputTran += new InputEventHandler(heroStateMoveVer.handleInput);
    }
        //Default constructor, requires an XML file that enumrates the available actions to take
        //on various GameState / Event conditions.
        public InputHandler(string inputEventsFile, object callBackHandler)
        {
            //fill out the handler map and populate the actions as null for now.
            handlerMap = new List <List <InputEventHandler> >(Enum.GetValues(typeof(GameState)).Length);
            for (int i = 0; i < Enum.GetValues(typeof(GameState)).Length; i++)
            {
                handlerMap.Add(new List <InputEventHandler>(Enum.GetValues(typeof(Events)).Length));
                for (int j = 0; j < Enum.GetValues(typeof(Events)).Length; j++)
                {
                    handlerMap[i].Add(null);
                }
            }

            //Get the available options for game state and events as strings so we can compare
            //them to what is specified in XML.
            string[]      eventNames     = Enum.GetNames(typeof(Events));
            string[]      gamestateNames = Enum.GetNames(typeof(GameState));
            List <string> eventList      = new List <string>(eventNames);
            List <string> gameStateList  = new List <string>(gamestateNames);

            //Load the XML handler informaiton and load each action.
            XmlDocument doc = new XmlDocument();

            doc.Load(inputEventsFile);
            XmlNodeList handlers = doc.GetElementsByTagName("InputEventHandler");

            foreach (XmlNode n in handlers)
            {
                //An action has three components, what game state it is attached to,
                //what input event should trigger it
                //and the name of the function in the callBackHandler that needs to be invoked.
                string gameState = n.Attributes["GameState"].Value;
                string eventType = n.Attributes["Event"].Value;
                string callback = n.Attributes["Action"].Value;
                int    gameStateIndex = 0, eventIndex = 0;
                gameStateIndex = gameStateList.IndexOf(gameState);
                eventIndex     = eventList.IndexOf(eventType);

                //Create the new delegate and assign it to the appropriate handlerMap index.
                InputEventHandler action = (InputEventHandler)Delegate.CreateDelegate(typeof(InputEventHandler), callBackHandler,
                                                                                      callback, true);

                handlerMap[gameStateIndex][eventIndex] = action;
            }
        }
Example #19
0
 /// <summary>
 /// Disposes the controller
 /// </summary>
 protected override void DisposeInternal()
 {
     Update = null;
     State = null;
 }
Example #20
0
 /// <summary>
 /// New Controller
 /// </summary>
 /// <param name="action">Update action</param>
 /// <param name="gameState">Game state this controller is on</param>
 public ControllerBase(InputEventHandler action, IGameState gameState)
 {
     Update = action;
     State = gameState;
 }
Example #21
0
 /// <summary>
 /// New controller. Uses the default keyboard
 /// </summary>
 /// <param name="action">Update action</param>
 /// <param name="gameState">Game state this controller is on</param>
 public ControllerBase(InputEventHandler action)
     : this(action, Module.Get<IGameStateManager>().CurrentState)
 {
 }
Example #22
0
    //---------------------------------------------------------------------------//

    public virtual void InitializeWordTyping()
    {
        InputEventHandler.RegisterToKeyboardCharPressed(CheckKeyboardInput);
        transform.GetChild(currentChar).GetComponent <Renderer>().material = StaticData.WordData.CurrentLetterMat;
    }
Example #23
0
 public virtual void DeInitializeWordTyping()
 {
     InputEventHandler.UnRegisterToKeyboardCharPressed(CheckKeyboardInput);
 }
Example #24
0
    void Start()
    {
        personCtrl = this.GetComponent<HeroCtrl>();
        heroStateActVer = new IdleStateActVer(this.gameObject);
        heroStateMoveVer = new IdleStateMoveVer(this.gameObject);
        inputArgs = new InputEventArgs("", "", "");
        hero_act_state[0] = new IdleStateActVer(this.gameObject);
        hero_act_state[1] = new ActState(this.gameObject);
        hero_act_state[2] = new DefenseState(this.gameObject);

        hero_move_state[0] = new IdleStateMoveVer(this.gameObject);
        hero_move_state[1] = new MoveState(this.gameObject);
        hero_move_state[2] = new JumpState(this.gameObject);

        InputTran += new InputEventHandler(heroStateActVer.handleInput);
        InputTran += new InputEventHandler(heroStateMoveVer.handleInput);
    }
Example #25
0
 public GameState(LegatusGame game)
 {
     Input = new InputEventHandler();
     UI    = new GameUI(game, Input);
 }
Example #26
0
 static Input()
 {
     OnInputStateChanged(inputEventHandler = InputEventHandler);
 }
Example #27
0
 private static extern void OnInputStateChanged(InputEventHandler handler);
Example #28
0
 // Start is called before the first frame update
 void Start()
 {
     eventHandler = new InputEventHandler();
 }
 /// <summary>
 /// If an action needs to be changed after initial loading, this function can be used
 /// to register a new action with an event / gamestate combination.
 /// </summary>
 /// <param name="inputEvent">The event the action is tied to</param>
 /// <param name="state">The GameState that must be active for the action to take place</param>
 /// <param name="handler">The InputEventHandler function to call.</param>
 public void RegisterHandler(Events inputEvent, GameState state, InputEventHandler handler)
 {
     handlerMap[(int)state][(int)inputEvent] = handler;
 }
Example #30
0
 public void SuscribeToInput(InputEventHandler inputhandler)
 {
     InputEvent += inputhandler;
 }
Example #31
0
 public void UnRegisterToIncomingEvents()
 {
     KeysEventHandler.UnRegisterToKeywordTyped(RegisterToWordTyped);
     InputEventHandler.UnRegisterToMovementKeyPressed(RegisterToMovementApplied);
 }
Example #32
0
        /// <summary>
        ///     The mechanism used to call the type-specific handler on the
        ///     target.
        /// </summary>
        /// <param name="genericHandler">
        ///     The generic handler to call in a type-specific way.
        /// </param>
        /// <param name="genericTarget">
        ///     The target to call the handler on.
        /// </param>
        protected override void InvokeEventHandler(Delegate genericHandler, object genericTarget)
        {
            InputEventHandler handler = (InputEventHandler)genericHandler;

            handler(genericTarget, this);
        }
Example #33
0
 protected virtual void OnDisable()
 {
     InputEventHandler.UnRegisterToKeyboardCharPressed(CheckKeyboardInput);
 }
Example #34
0
 public void Subscribe(InputEventHandler<MouseButtons, MouseState> handler)
 {
     MouseDevice mouse = Engine.Services.GetService<MouseDevice>();
     mouse.ButtonReleased += handler;
 }
Example #35
0
 private void OnDisable()
 {
     InputEventHandler.UnRegisterToKeyboardCharPressed(CheckKeyboardInput);
 }