Announcement

Collapse
No announcement yet.

OnMouseEnter behavior buttons

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • OnMouseEnter behavior buttons

    Is it true there is no behavior available out of the box for buttons that works with an OnMouseEnter or equivalent?
    I'm looking for such functionality, do i need to write my own logic for this?

    Thanks

  • #2
    Noone?????????

    Comment


    • #3
      well i also didn't find anything (i actually didn't look too much into the api), and judging by this piece of code from the examples repo:
      https://github.com/WaveEngine/Sample...ingBehavior.cs

      it is outdated but suggests that there isn't a default implementation for what you want, but this code kinda does what you want, not so very organized but there is the functionality demonstrated...

      Comment


      • #4
        Hi, there is not a built-in behavior for 3D entities, but you can use the piece of code provided by bio3c.

        Just attached a sample that could help you too (bases on the same code).

        Regards.
        Attached Files

        Comment


        • #5
          Thanks for the comments. i'll take a look and see what i can use..

          Thanks

          Is the attachment a project for Windows? I can't open it on Linux in editor and cant build it in MonoDevelop
          Last edited by Maxdg; 04-19-2017, 02:44 PM.

          Comment


          • #6
            Originally posted by sescalada View Post
            Hi, there is not a built-in behavior for 3D entities, but you can use the piece of code provided by bio3c.

            Just attached a sample that could help you too (bases on the same code).

            Regards.
            Curious, Is there a build in behavior for 2D entities then?
            also read edit op previous comment.

            Comment


            • #7
              Hi again Maxdg,

              there isn't except for 2d UI elements.

              Comment


              • #8
                Jacano could you explain the one for 2D UI Elements? My buttons are slightly altered but they still derive from the mainbutton class which is UI.

                Code:
                public class ToggleButton : Button

                Comment


                • #9
                  Hi Maxdg,

                  For 2D elements you have a button element that has a Click event. Can see an example in this link.
                  Always can create your own buttons as is done in this Quickstarter. Look at the ButtonComponent component.
                  You can apply different states based on events pressed, released, etc. It makes use of TouchGestures where you have the event TouchMoved. Using this event with GestureSample and the position you can manage the equivalent of MouseEnter or MouseExit.

                  I hope it helps!

                  Regards.

                  Comment


                  • #10
                    Thanks for the reply suarez, i'll look into that as soon as i got a bug resolved in my game.

                    Comment


                    • #11
                      hey Suarez,

                      Could you provide any help? I've attached the TouchGestures to the buttons, and looking on how i could implement the Position of the touch, however all the Position things return 0(X,Y, LocalX,LocalY and ScreenPosition). Am i missing something here?
                      Case:

                      I have multiple "Toggle"Buttons on screen, which change graphic one you click them. All these buttons have a TouchGestures component on them, if i start dragging from 1 button(with TouchMoved) i see that the touch is being dragged, however the position on the drag is not changing.


                      EDIT:

                      I've disabled Supported for a reason, i dont want my buttons to move. However this disables the change in position. I need to tackle it so that my buttons don't move around on but that the touch keeps transforming..

                      EDIT2:

                      You can disable the SupportedGestures:

                      Code:
                      touch.EnabledGestures = SupportedGesture.None
                      and then u read the gesture

                      Code:
                      touch.ReadGesture().Position
                      That value does actually change even though SupportedGesture is not supporting Translation anymore.
                      Last edited by Maxdg; 04-26-2017, 09:21 AM.

                      Comment


                      • #12
                        I'm reaching a new bottleneck, i'm reading out every buttons Transform and Position. The buttons have 0,0 position on World and Local Transforms, am i missing something?
                        Every button is in the same Grid

                        Some code to explain how i build the button grid:
                        Code:
                        public class Table : Grid
                                {
                                    public Table()
                                        : base()
                                    {
                                        this.SetTopGrid();
                                        this.CreateButtons();
                        
                                        this.IsVisible = true;
                                    }
                        
                                    private void SetTopGrid()
                                    {                
                                        this.Margin = new Thickness(75, 100, 500, 0);
                                        this.Width = 50;
                                        this.Height = 450;
                                        this.IsBorder = false;
                                        //Sets all RowDefenitions
                                        for (int i = 0; i <= 4; i++)
                                        {
                                            this.RowDefinitions.Add(new RowDefinition { Height = new GridLength(i, GridUnitType.Auto) });
                                        }
                                        for (int i = 0; i <= 10; i++)
                                        {
                                            this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(i, GridUnitType.Auto) });
                                        }
                                        Debug.WriteLine(RowDefinitions.Count);
                                        Debug.WriteLine(ColumnDefinitions.Count);
                                    }
                        
                                    private void CreateButtons()
                                    {
                        
                                        for (int i = 0; i < 40; i++)
                                        {
                                            int d = i + 1;
                                            ToggleButton cancelButton = new ToggleButton()
                                            {
                                                FontPath = WaveContent.Art.Font.Eurostile_24_ttf,
                                                Margin = new Thickness(2f),
                                                IsBorder = false,
                                                BackgroundImage = WaveContent.Art.Buttons.game_button_normal_png,
                                                ID = d,
                                                Foreground = WaveEngine.Common.Graphics.Color.Red,
                                                Text = d.ToString(),
                                                HorizontalAlignment = HorizontalAlignment.Center,
                                                VerticalAlignment = VerticalAlignment.Center,
                                                Width = 82,
                                                Height = 67,
                                            };
                        
                                            TouchGestures touch = cancelButton.Entity.FindComponent<TouchGestures>(false);
                                            touch.EnabledGestures = SupportedGesture.None;
                                            touch.TouchMoved += (sender, EventArgs) =>
                                            {
                                                Keno_Linux.Debugger.WriteLine("Detected Touch Move: " + cancelButton.ID);
                                                Keno_Linux.Debugger.WriteLine("Current ReadGesture Position: "+ touch.ReadGesture().Position);
                                                Keno_Linux.Debugger.WriteLine("Button Position: " + cancelButton.Entity.FindComponent<Transform2D>().Position);
                                                //This one reports the 0,0 while i'm assured its the button itself
                                            };
                        
                                            touch.TouchTap += (sender, args) =>
                                            {                            
                        
                                                if (cancelButton.state == ToggleButton.ToggleState.uncheck)
                                                {
                                                    if (DataHandler.selected <= maxvalue)
                                                    {
                                                        cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_selected_png;
                                                        cancelButton.state = ToggleButton.ToggleState.check;
                                                        cancelButton.previousState = cancelButton.state;
                                                        cancelButton.selected = true;
                                                        DataHandler.selected++;
                                                    }                                      
                                                }
                                                else if(cancelButton.state == ToggleButton.ToggleState.check)
                                                {
                                                    cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_normal_png;
                                                    cancelButton.state = ToggleButton.ToggleState.uncheck;
                                                    cancelButton.previousState = cancelButton.state;
                                                    cancelButton.selected = false;
                                                    DataHandler.selected--;
                                                }
                        
                                                DataHandler.CheckStates();
                        
                                            };
                                            cancelButton.Hit += (sender, EventArgs) =>
                                            {
                        
                                                cancelButton.BackgroundImage = WaveContent.Art.Buttons.game_button_selectedhit_png;
                                                cancelButton.state = ToggleButton.ToggleState.selecthit;
                        
                        
                                            };
                        
                                            if (i >= 10)
                                            {
                        
                                                int r;
                                                int c;
                                                r = i / 10;
                                                c = i % 10;                        
                                                if (c < 0)
                                                    c = 0;
                                                cancelButton.SetValue(GridControl.RowProperty, r);
                                                cancelButton.SetValue(GridControl.ColumnProperty, c);
                                                Debug.WriteLine((c - 1).ToString());
                                            }
                                            else
                                            {
                                                cancelButton.SetValue(GridControl.RowProperty, 0);
                                                cancelButton.SetValue(GridControl.ColumnProperty, i);
                                            }
                        
                        
                                            this.Add(cancelButton);
                                            DataHandler.toggles.Add(cancelButton);
                        
                                        }
                        
                                    }
                        
                                }
                        Sidenote: i've named them cancelbutton since i've started from there, the name doesn't matter anyway.
                        Last edited by Maxdg; 04-26-2017, 01:27 PM.

                        Comment


                        • #13
                          .*bumping*.

                          Comment


                          • #14
                            Maybe I can help you! If I understand correctly, you want to implement the behavior of OnMouseEnter

                            1. Create New Behavior:
                            Code:
                            [DataContract]
                                public class MouseEnterBehavior : Behavior
                                {
                                    [RequiredComponent]
                                    private Transform2D _transform2D;
                            
                                    protected override void Initialize()
                                    {
                                        _transform2D = Owner.FindComponent<Transform2D>();
                                    }
                            
                                    protected override void Update(TimeSpan gameTime)
                                    {
                                        var pos = WaveServices.Input.MouseState.Position;
                            
                                        // Mouse Over Button
                                        if (_transform2D.Rectangle.Contains(pos) && pos != Vector2.Zero)
                                        {
                                               // do something
                                        }
                                        else
                                        {
                            
                                        }
                                    }
                                }
                            2. Add behavior to button:
                            ... .AddComponent(new MouseEnterBehavior());

                            Comment


                            • #15
                              Thanks a lot yhplr! That was the way to go!

                              Comment

                              Working...
                              X