Game Development Community

Analog Input in GUI

by Henry Shilling · in Torque X 2D · 08/27/2009 (7:57 am) · 8 replies

Anyone know how to do this? All I want to do is get a number from the stick as it's moved while in the GUI. I can map buttons, stick left right etc, but how about analog?




#1
08/27/2009 (8:38 pm)
Henry, wouldn't you still be able to do this in the ProcessTick of the class that you are loading your GUI in? I haven't tried but I can only imagine that it would be the same as in a MovementComponent.
#2
08/28/2009 (7:36 am)
That's pretty much all he has to do. Inherit ITickObject and make sure to register it with the ProcessList at construction.
#3
08/30/2009 (7:40 am)
How do I register it with the process list?

ProcessList.Instance.AddTickCallback(???)

what is the owning object? I have tried this.parent, sadly that's a null, even though this is a popup dialog created inside another GUI screen.

It's all pretty confusing.

I have also tried to read the loop by using:

public override void OnRender(Vector2 offset, RectangleF updateRect)

just like I do in my main scene, however it never gets hit either.
#4
08/30/2009 (2:49 pm)
ProcessList.Instance.AddTickCallback(this);
#5
08/30/2009 (4:24 pm)
o O

That does nothing, it's the first thing I tried. I have also tried using the GUIControl directly.

private void _createDialog()
        {

            GUIStyle baseStyle = new GUIStyle();
            baseStyle.Focusable = true;
            GUIBitmapStyle bitmapStyle = new GUIBitmapStyle();
            bitmapStyle.SizeToBitmap = false;

            _menu = new GUIControl();
            _menu.Style = baseStyle;
            _menu.Layer = 0;
            _menu.FocusOnWake = true;
            _menu.Visible = true;

            int _wsize = Game.Instance.Window.ClientBounds.Width;

            GUIBitmap baseFrame = new GUIBitmap();
            baseFrame.Style = bitmapStyle;
            baseFrame.Position = Vector2.Zero;
            baseFrame.Size = new Vector2(1280, 720);

            baseFrame.Bitmap = @"dataimagesGUIDemoMenu";

            if (_wsize == 640)
            {
                baseFrame.Bitmap = @"dataimagesGUIDemoMenu";
                baseFrame.Position = new Vector2(0, 60);
                baseFrame.Size = new Vector2(640, 360);
            }
            if (_wsize == 1920)
            {
                baseFrame.Bitmap = @"dataimagesGUIDemoMenu";
                baseFrame.Size = new Vector2(1920, 1080);
            }

            baseFrame.Visible = true;
            baseFrame.Folder = _menu;


            InputMap input = new InputMap();
            int gamepadId = (int)Game.Instance.CurrentPlayer;
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.A, ToggleMenu, null);
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.B, _totallyQuit, null);
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.X, _buyThis, null);
            input.BindCommand(gamepadId, 
            this.InputMap = input;

            //this causes an error
            ProcessList.Instance.AddTickCallback(_menu);
        }

This is similar to wanting to read the analog stick. here I just want to check the loop and if they purchase, the Guide.IsTrialMode will flip to true, and this will go away.

public void ProcessTick(Move move, float elapsed)
        {
            if(!Guide.IsTrialMode)
                ToggleMenu();
        }

However it doesn't happen, I place a break in the Process tick and it never happens.

weird.




#6
08/30/2009 (10:49 pm)
Heya I think your looking for this? This is from my main menu code.
public override bool OnInputEvent(ref TorqueInputDevice.InputEventData data)
        {
            if (data.DeviceTypeId == TorqueInputDevice.GamePadId)
            {
                if (data.ObjectId == (int)XGamePadDevice.GamePadObjects.LeftThumbY)
                {
                    stickY = data.Value;
                    if (stickY > .35)
                    {
                        _currentMove = LastMove.up;
                        MoveUp();
                        return true;
                    }
                    else if (stickY < -.35)
                    {
                        _currentMove = LastMove.down;
                        MoveDown();
                        return true;
                    }
                    _currentMove = LastMove.clear;
                    return true;
                }
#7
08/31/2009 (4:39 pm)
Well, Ive had no problem with registering it that way, would it be possible to post the whole class?

Anywho, Matthews solution should work to.
#8
08/31/2009 (5:58 pm)
I seriously have two issues. : ) (not according to my wife.. she'd up that number)

OK the stick is one thing, I should have probably added a new thread for the second. That is I'd also like to know if something has happened while a screen is up. Precisely I'd like to know if they had registered and paid for my game.

Matthew's stick thing is for the volume adjust dialog. That will work great!

public class GUIDemo : GUIControl, IGUIScreen, ITickObject
    {
        public GUIDemo()
        {
            _createDialog();
        }

        public void ToggleMenu()
        {
            if (_menu == null)
                return;

            if (_menu.Folder == GUICanvas.Instance)
            {
                // hide pop-up
                Game.Instance.InitGame();
                InputManager.Instance.PopInputMap(this.InputMap);
                GUICanvas.Instance.PopDialogControl(_menu);
            }
            else
            {
                // show pop-up
                InputManager.Instance.PushInputMap(this.InputMap);
                GUICanvas.Instance.PushDialogControl(_menu, 0);
            }
        }

        private void _createDialog()
        {

            GUIStyle baseStyle = new GUIStyle();
            baseStyle.Focusable = true;
            GUIBitmapStyle bitmapStyle = new GUIBitmapStyle();
            bitmapStyle.SizeToBitmap = false;

            _menu = new GUIControl();
            _menu.Style = baseStyle;
            _menu.Layer = 0;
            _menu.FocusOnWake = true;
            _menu.Visible = true;

            int _wsize = Game.Instance.Window.ClientBounds.Width;

            GUIBitmap baseFrame = new GUIBitmap();
            baseFrame.Style = bitmapStyle;
            baseFrame.Position = Vector2.Zero;
            baseFrame.Size = new Vector2(1280, 720);

            baseFrame.Bitmap = @"dataimagesGUIDemoMenu";

            if (_wsize == 640)
            {
                baseFrame.Bitmap = @"dataimagesGUIDemoMenu";
                baseFrame.Position = new Vector2(0, 60);
                baseFrame.Size = new Vector2(640, 360);
            }
            if (_wsize == 1920)
            {
                baseFrame.Bitmap = @"dataimagesGUIDemoMenu";
                baseFrame.Size = new Vector2(1920, 1080);
            }

            baseFrame.Visible = true;
            baseFrame.Folder = _menu;


            InputMap input = new InputMap();
            int gamepadId = (int)Game.Instance.CurrentPlayer;
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.A, ToggleMenu, null);
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.B, _totallyQuit, null);
            input.BindCommand(gamepadId, (int)XGamePadDevice.GamePadObjects.X, _buyThis, null);
            input.BindCommand(gamepadId, 
            this.InputMap = input;

            
            //ProcessList.Instance.AddTickCallback(_menu);

            ToggleMenu();
        }

        public void InterpolateTick(float k)
        {
        }

        public void ProcessTick(Move move, float elapsed)
        {
            if(!Guide.IsTrialMode)
                ToggleMenu();
         // this turns false when the game is purchased
        }
       
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {

            base.OnRender(offset, updateRect);
        }

        void _menuOff(float val)
        {
            if (val > 0.0f)
                ToggleMenu();
        }

        void _buyThis()
        {
            //Microsoft.Xna.Framework.GamerServices.Gamer gamer = Microsoft.Xna.Framework.GamerServices.Gamer.SignedInGamers[Game.Instance.CurrentPlayer];


            if (Microsoft.Xna.Framework.GamerServices.Gamer.SignedInGamers[Game.Instance.CurrentPlayer] != null && Microsoft.Xna.Framework.GamerServices.Gamer.SignedInGamers[Game.Instance.CurrentPlayer].IsSignedInToLive)
            {
                Guide.ShowMarketplace(Game.Instance.CurrentPlayer);
            }
            else
            {
                Guide.ShowSignIn(1, true);
                
            }
            // the ShowSign in is asynchronous so I cannot wait for 
            // some return Toggle menu will just drop out and if they
            // if they have paid the game will recognize it. If they
            // didn't pay they will be sent back here. 
            //ToggleMenu();
        }

        void _totallyQuit()
        {
            Game.Instance.Exit();
        }


        GUIControl _menu;
        public bool isOn;
    }

I believe I got this basic class from the FPS demo... not certain where. But it works pretty flawlessly.