Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 2:07 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Wed Jun 27, 2012 2:35 am 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
Hello,

I am working on an Options window where I can change the screen resolution during run time.

I have a combobox that displays all valid resolutions and when you select one, the game will automatically update the current state in the addCallback method. I have managed to successfully change the resolution (was having issues until I found syncViewportSize on the forums). I use setDisplayMode(....); And then call syncViewportSize on the renderer.

But the issue is that the Combobox will not "close" it's list pane after the display gets updated. So the screen resizes itself, then the sync is called, and afterwards, the Combobox is open still like nothing was clicked.

I'm not sure if this is a bug and/or if there is a way where I can manually tell the Combobox to close it's list. I see a method, "hasOpenPopups", but this seems to be for something else.

Hopefully this makes some sense. If you want to see some code or a better explanation let me know.

Thanks!


Top
 Profile  
 
PostPosted: Wed Jun 27, 2012 5:10 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Hmm strange - maybe you need to call GUI.clearKeyboardState() and clearMouseState() ?
Can you post the code (hopefully in a way that I can run it) ?

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Wed Jun 27, 2012 11:26 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
MatthiasM wrote:
Hmm strange - maybe you need to call GUI.clearKeyboardState() and clearMouseState() ?


I tried this but the panel still stays open.

MatthiasM wrote:
Can you post the code (hopefully in a way that I can run it) ?


I will have to write up a self contained program for you...I am running in Slick right now and need to extract the code.

But in the mean time, this is the method I have that actually changes the resolution and syncs the view port:
tswGame is a TWLStateBasedGame.

Code:
   public static void changeResolution ()
   {
      try
      {
         AppGameContainer app = (AppGameContainer)tswGame.getContainer();
         
         app.setDisplayMode(resolution.getDimension().getX(), resolution.getDimension().getY(), VideoSettings.isFullScreen());
         
         //Update the renderer to sync with the new display.
         tswGame.getRenderer().syncViewportSize();
         
      }
      catch (SlickException e)
      {
         e.printStackTrace();
      }
      catch(Exception ex)
      {
         ex.printStackTrace();
      }
   }


And the Combobox code...
Code:
      
      resolutionComboBox.addCallback(new Runnable(){

         @Override
         public void run ()
         {
            int index = resolutionComboBox.getSelected();
            ResolutionEntry newResolution = resolutionComboBox.getModel().getEntry(index);
            VideoSettings.setResolution(newResolution);
            VideoSettings.changeResolution();
            VideoSettings.saveSettings();
            
            //After this the popup is still there...
         }
         
      });



I will put something together and reply to this thread today or tomorrow.

Thanks!


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 3:20 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
Ok, I managed to create a very small example of this using the Slick/TWL StateBasedGame example. I added a few extra small things, but it is very simple.

I rar'ed up the entire Project in the workspace (this includes the libraries I am using), so it should be fairly easy to put into Eclipse (I'm taking a guess you are using this :) ) and execute.

If you want - I can also build an executable jar file for you - let me know.

Here is the download link(from my personal site):
http://www.tempestseason.com/combo_issu ... _issue.rar


Just so you know: when the program first loads and you click on the Open button, it usually hangs for a few seconds because the Display.getAvailableDisplayModes takes awhile for me to process, but maybe this isn't an issue with you.

Anyways, after the dialog opens, you can open the combo box and see all of your resolutions and start changing them. You should be able to see the list pane staying up.

The location of code for the Combobox is in the OptionDialog.java file around line 80. TestTWLUI.java contains the main method and the initial app setup.

Thanks and let me know if you need me to do anything else :)


Top
 Profile  
 
PostPosted: Thu Jun 28, 2012 7:56 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
The issue is that a combo box doesn't close the popup on a single click - you can verify that in the other TWL examples.

The best way to solve this would be to do it like nearly all other games - only change resolution after clicking an apply button.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Jul 05, 2012 11:25 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
Thanks for the reply.


Top
 Profile  
 
PostPosted: Wed Mar 06, 2013 3:03 am 
Offline

Joined: Sun Jul 18, 2010 2:10 pm
Posts: 30
I've faced the same issue. instead of adding callback to ComboBox, I've extended ComboBox as below:

Code:
      ComboBox<String> combo = new ComboBox<String>(selectionModel) {
         @Override
         protected void listBoxSelectionChanged(boolean close) {
            super.listBoxSelectionChanged(close);
            
            // changing video mode results in GUI recreated and combo.popup remain open in that case
            // we need to be sure callback is always called if popup is closed
            if (!popup.isOpen() && (callback != null))
               callback.run();
         }
      };


Top
 Profile  
 
PostPosted: Thu Mar 07, 2013 2:13 am 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
Thanks, I'll give this a try.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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