Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 26, 2013 6:34 am

All times are UTC




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Mar 09, 2010 7:09 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
I'm using this: http://wiki.l33tlabs.org/bin/view/TWL/U ... with+Slick

When I use mouse clicks or key presses, both Slick and TWL are getting the event. I'm calling the TWLInput update method in the Slick Render method.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2010 7:56 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Yeah,

I expected that :( I'm currently working on a solution.

As a work around you could handle all events in the TWL root pane instead of using a Slick input listener.

Ciao Matthias

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2010 10:29 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
Is there a way to detect/set focus on TWL windows?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2010 7:29 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
yes, but it would be better to ask a new question in a new topic - otherwise it will be hard for others to find it

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2010 1:59 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
I'm currently working on a solution.



Just curious how this is going?

Quote:
As a work around you could handle all events in the TWL root pane instead of using a Slick input listener.

Ciao Matthias


You mean handle everything in the TWLInputWrapper and then don't do anything with the Slick key capture methods? How do I tell if the input was meant for TWL or Slick?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2010 6:30 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
A solution (which I had not yet time to really test) is to call Slick's Input.consumeEvent() when any of the GUI.handle* method returned true.

The other option is to override handleEvent() in the root widget you pass to GUI. Try something like this:
Code:
protected boolean handleEvent(Event evt) {
    if(super.handleEvent(evt)) {
        return true;
    }
    if(mySlickGame.handleEvent(evt)) {
        return true;
    }
    return false;
}

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 4:58 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
A solution (which I had not yet time to really test) is to call Slick's Input.consumeEvent() when any of the GUI.handle* method returned true.


Doesn't the TWLInputWrapper already do that?

In TWLInputWrapper.java I have this:

Code:
   private void consume() {
      if (gui.getRootPane().hasOpenPopups()) {
         input.consumeEvent();
      }
   }


Quote:
The other option is to override handleEvent() in the root widget you pass to GUI. Try something like this:
Code:
protected boolean handleEvent(Event evt) {
    if(super.handleEvent(evt)) {
        return true;
    }
    if(mySlickGame.handleEvent(evt)) {
        return true;
    }
    return false;
}



I took this from the wiki/example:

Code:
try {
         lwjglRenderer = new LWJGLRenderer();
         gui = new GUI(root, lwjglRenderer);
         twlWrapper = new TWLInputWrapper(gui, gc.getInput());
         gc.getInput().addPrimaryListener(twlWrapper);
      } catch (Exception e) {
         Debug.exit(e);
      } finally {
         GL11.glPopAttrib();
      }


So override it in TWLInputWrapper?

Quote:
Code:
  if(mySlickGame.handleEvent(evt)) {



AppGameContainer doesn't have a handleEvent method.

http://slick.cokeandcode.com/javadoc/or ... ainer.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 6:47 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
No, the code on the wiki is wrong. Currently it consumes events when a popup is open - it should consume when GUI.handle* returns true:
Code:
@Override
   public void mouseReleased(int button, int x, int y){
      if(gui.handleMouse(x, y, button, false)) {
         input.consumeEvent();
      }
   }

But I did not have a Slick app around to play with such things. One major drawback with the above approach is that you must make sure that the TWLInputWrapper is always called first. For that you need to be careful in which order you add them to slick - esp once you start to remove things.

And the 2nd approach (which works always) is overriding the handleEvent method in the root widget. The root widget is the root parameter you pass to GUI:
Code:
Widget root = new Widget();
....
gui = new GUI(root, lwjglRenderer);

Just replace the "new Widget()" with your own class which overrides handleEvent.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 7:18 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
And the 2nd approach (which works always) is overriding the handleEvent method in the root widget. The root widget is the root parameter you pass to GUI:
Code:
Widget root = new Widget();
....
gui = new GUI(root, lwjglRenderer);

Just replace the "new Widget()" with your own class which overrides handleEvent.


ok, this is setup. The only part is this:

Code:
if(mySlickGame.handleEvent(evt)) {
        return true;
    }
    return false;


I can't find mySlickGame.handleEvent(evt) in the API (AppGameContrainer or GameContrainer). Do I have to create my own and do something with it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 5:15 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Of course, the intent behind the "mySlickGame" variable was to indicate that this calls your game logic.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 8:20 pm 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
So I have to put all my slick input handling in one method?
I'll look at it more tonight. If that is the case I'll have to try that first way again.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2010 9:49 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
No, you can of course dispatch to other methods. TWL uses an Event object and a single handleEvent() method but this does not mean that all code has to be in that method.

Btw - did you try the 1st approach (calling input.consumeEvent() when GUI.handle* returned true) ?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2010 1:39 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
MatthiasM wrote:
No, you can of course dispatch to other methods. TWL uses an Event object and a single handleEvent() method but this does not mean that all code has to be in that method.


ok. It'll take me a while to try this, as I have to rewrite a bunch of things. I handle everything in keyPressed or updates (in both States and in "Entities").

Quote:
Btw - did you try the 1st approach (calling input.consumeEvent() when GUI.handle* returned true) ?



Yes. I updated to latest build of TWL.jar from website. I update both MousePress and MouseRelease and re-arranged the code (so twl update would be called first). The behavior was almost the same expect some TWL windows won't get focus.

The problem with calling twl input wrapper's update first (in render per the example) is that everything gets drawn over it. It is ok to break this up into update and render right? I put everything in update (called from slicks update) and in Render it's just the draw (called from slicks render).

I'm still playing with it and going to try a few more things.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2010 4:02 am 
Offline
Game Developer
User avatar

Joined: Wed Feb 17, 2010 12:24 am
Posts: 594
ok, finally think I'm making some progress! thanks for your help.

I used your override method, but put in a pause/resume before/after the consumeEvent. That seems to be working:

Code:
   @Override
   public void mousePressed(int button, int x, int y) {
      if (gui.handleMouse(x, y, button, true)) {
         input.pause();
         input.consumeEvent();
         input.resume();
      }
   }


edit: Seems to only work for mouse though, still need to figure out the keyboard events now.

edit2:

A little bit closer. This works with keyboard *if* the slick calls is:

input.isKeyPressed

If I use:
input.isKeyDown

it doesn't consume the event (even if it's just a quick tap on the keyboard). I think I need to handleRepeatKeys or such?


Example (in Slick update()):

Code:
      if (input.isKeyDown(Input.KEY_A)) {
      owner.moveLeft(delta);
      }


doesn't work with the pause/consume/resume.

This *does* work though:

Code:
           if (input.isKeyPressed(Input.KEY_A)) {
      owner.moveLeft(delta);
     }


Unfortunately I don't see a KeyDown method that I can override:
http://slick.cokeandcode.com/javadoc/or ... apter.html

Any other way this could be dealt with?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2010 6:50 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
input.pause() / resume() can't be right - don't do that.
Did you add this code pattern to all methods in the TWLInputWrapper ? or only to mousePressed?

isKeyDown() etc won't work - as this does not use an event based system. You have to use keyboard events (keyPressed/keyReleased).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group