Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 1:43 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Feb 03, 2012 9:32 pm 
Offline

Joined: Fri Feb 03, 2012 9:09 pm
Posts: 8
Hey,

I'm trying to get a title screen working that can be controlled with either the keyboard or mouse. So far I have buttons for "Start Game," "Settings," and "Exit" with rollovers and callbacks all working nicely. I'd like to be able to use the arrow keys to control the buttons as well, i.e., up/down selects the button and enter activates it. The best I can figure out is to capture arrow key movement and manually do rootPane.focusNextChild()/focusPreviousChild(). Then in the mouse hover for every button, shift keyboard focus to it. It seems like there should be a more elegant solution than that, but I can't figure anything better out. I'm also baffled by how I'm supposed to be using these input map/action map classes, too. I read through the tutorials and poked around in the demo, but still don't understand them. The answer to my question might lie simply in there somewhere, but any help on understanding this library is appreciated. From what I've seen so far it can do everything I need it to and more...just as soon as I figure out how. :]

Thanks,
Jarett


Top
 Profile  
 
PostPosted: Fri Feb 03, 2012 10:53 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
You can setup an inputMap for your title screen with up/down arrow as "next" / "prev" action. Then you can register actions for these:
Code:
addActionMapping("next", "focusNextChild");
addActionMapping("prev", "focusPrevChild");

And I would leave the hover and the focus separated from each other, but if you want to combine them you can use a ButtonModel callback to detect a hover change and transfer the focus when a button gains focus.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 12:19 am 
Offline

Joined: Fri Feb 03, 2012 9:09 pm
Posts: 8
Hey MatthiasM,

Thanks, that worked pretty well, except that focusNextChild and focusPrevChild don't seem to work like I expected. Next works perfectly, but when I hit up, it toggles between the item and the item above it. It almost seems like it wants to reorder the focus order, and "previous" becomes whichever one it focused last. Is there some way I can manually set the focus order, maybe?

Thanks,
Jarett


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 12:26 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
Are you using DesktopArea as parent? This widget reorders it's children based on keyboard focus (this is designed to be used with ResizableFrame as children).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 3:30 am 
Offline

Joined: Fri Feb 03, 2012 9:09 pm
Posts: 8
I'm using the TWLSlick package and adding them directly to the rootPane. I see that the RootPane class extends DesktopArea, so that must be the problem. Should I stick a ResizableFrame between the root pane and my buttons? I don't plan on using the functionality of ResizablePane, so would just a generic Widget object be a better choice?

Thanks for the help!
Jarett


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 5:38 am 
Offline

Joined: Fri Feb 03, 2012 9:09 pm
Posts: 8
Never mind, I think I got it: I used a BoxLayout, which actually simplified the rest of the code a little bit. Thanks for the help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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