Game Options configure keys

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

Doles
Just popping in
Just popping in
Posts: 2
Joined: Sun Nov 13, 2011 10:53

Game Options configure keys

Postby Doles » Sun Nov 20, 2011 19:51

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 ?

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Game Options configure keys

Postby Kulik » Sun Nov 20, 2011 20:04

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.

Doles
Just popping in
Just popping in
Posts: 2
Joined: Sun Nov 13, 2011 10:53

Re: Game Options configure keys

Postby Doles » Sun Nov 20, 2011 21:01

To be honest I didn't really catch it :) Could you post some pseudocode ? After serveral ours nothing is done 'easly' for me :)

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Game Options configure keys

Postby Kulik » Sun Nov 20, 2011 23:56

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;

skyforger
Just popping in
Just popping in
Posts: 12
Joined: Mon Jan 02, 2012 19:21

Re: Game Options configure keys

Postby skyforger » Sun Jan 08, 2012 01:20

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.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 5 guests