Page 1 of 1

Game Options configure keys

Posted: Sun Nov 20, 2011 19:51
by Doles
Hi,
i'm working on key configuration for my game. I would like to do something like this scenario: Player goes into Options, then goes into Input, then (like in real games) he clicks on button (or something like that) and then he press key and done. I have been trying to do that for several hours and nothing :/ There is no such method to block and get any key. I was trying to do some boolean flags and stuff but i doesn't work at all. Here is a bit of my code:

Code: Select all

CEGUI::PushButton* RightSetup = static_cast<CEGUI::PushButton*>(opwmgr.createWindow("TaharezLook/Button", "RightSetup"));
   OptionInput->addChildWindow(RightSetup);
   RightSetup->setPosition(CEGUI::UVector2( CEGUI::UDim( 0.55f, 0.0f ), CEGUI::UDim( 0.5f, 0.0f) ));
   RightSetup->setSize(CEGUI::UVector2( CEGUI::UDim( 0.4f, 0.0f ), CEGUI::UDim( 0.1f, 0.0f ) ));
   RightSetup->setText("D");
   RightSetup->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&GUI::configKey, this));


and configKey() :

Code: Select all

bool GUI::configKey(const CEGUI::EventArgs &e)
{
   CEGUI::WindowManager &gowmgr = CEGUI::WindowManager::getSingleton();
   CEGUI::PushButton* button = static_cast<CEGUI::PushButton*>(gowmgr.getWindow("RightSetup"));
   button->setText("Press Key");
   
   mSetKey = false;
   while(!mSetKey) {}; // <- so stupid, so ugly
   button->setText(mKeyText);
   return true;
}


and then i have function passingKey() go ten input from my main class which has OIS::KeyListener(), so:

Code: Select all

bool GUI::passingKey(const OIS::KeyEvent &e)
{
   if(!mSetKey)
   {
      mKeyText = e.text;
      mSetKey = true;
   }
   return true;
}


And it of course stop completelly my game and it can't recieve any inputs. Is there any nice way to implement key configuration into game using CEGUI ? How do i do something like block-and-wait for input ?

Re: Game Options configure keys

Posted: Sun Nov 20, 2011 20:04
by Kulik
You can do it the way you are doing it because you simply block the main thread, the callback isn't ever called.

I wouldn't even think about multithreading regarding this, you can easily do this by flipping some switch and checking for it, if it's in this special "listening" state you just change currently edited binding.

Re: Game Options configure keys

Posted: Sun Nov 20, 2011 21:01
by Doles
To be honest I didn't really catch it :) Could you post some pseudocode ? After serveral ours nothing is done 'easly' for me :)

Re: Game Options configure keys

Posted: Sun Nov 20, 2011 23:56
by Kulik

Code: Select all

keyPressCallback(keyEvent)
{
   if (mKeyBindListening)
   {
      mCurrentBindAction->setKey(keyEvent.key);
      mKeyBindListening = false;
      ...set text to the editbox etc...
   }
}

blah blah blah
... user wants to rebind something
mCurrentBindAction = the action user wants to bind
mKeyBindListening = true;

Re: Game Options configure keys

Posted: Sun Jan 08, 2012 01:20
by skyforger
I thought about adding some explanations..

Code: Select all

while(!mSetKey) {}; // <- so stupid, so ugly

Don't use that. It's stupid. Because your program ( main thread ) is stuck in this loop, it never gets to the GUI::passingKey method. It never gets anywhere actually. It stops your game.