Skip to content

Commit

Permalink
Update other keybinding views when keybinding is set somewhere else
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Feb 16, 2016
1 parent 471ee1a commit a25add4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/cgame/rocket/rocketKeyBinder.h
Expand Up @@ -42,6 +42,10 @@ Maryland 20850 USA.


#define DEFAULT_BINDING 0 #define DEFAULT_BINDING 0


static const Rocket::Core::String KEY_SET_EVENT = "key_set_event";
static const Rocket::Core::String KEY_TEAM = "team";
static const Rocket::Core::String KEY_KEY = "key";

class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::EventListener class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::EventListener
{ {
public: public:
Expand Down Expand Up @@ -73,6 +77,7 @@ class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::Event
context = GetContext(); context = GetContext();
context->AddEventListener( "mousemove", this ); context->AddEventListener( "mousemove", this );
context->AddEventListener( "keydown", this ); context->AddEventListener( "keydown", this );
context->AddEventListener( KEY_SET_EVENT, this );
} }
} }


Expand All @@ -83,6 +88,7 @@ class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::Event
{ {
context->RemoveEventListener( "mousemove", this ); context->RemoveEventListener( "mousemove", this );
context->RemoveEventListener( "keydown", this ); context->RemoveEventListener( "keydown", this );
context->RemoveEventListener( KEY_SET_EVENT, this );
context = nullptr; context = nullptr;
} }
} }
Expand All @@ -99,7 +105,11 @@ class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::Event
void ProcessEvent( Rocket::Core::Event &event ) void ProcessEvent( Rocket::Core::Event &event )
{ {
Element::ProcessEvent( event ); Element::ProcessEvent( event );
if ( !waitingForKeypress && event == "mousedown" && event.GetTargetElement() == this ) if ( event == KEY_SET_EVENT )
{
dirty_key = true;
}
else if ( !waitingForKeypress && event == "mousedown" && event.GetTargetElement() == this )
{ {
waitingForKeypress = true; waitingForKeypress = true;
SetInnerRML( "Enter desired key..." ); SetInnerRML( "Enter desired key..." );
Expand Down Expand Up @@ -166,6 +176,10 @@ class RocketKeyBinder : public Rocket::Core::Element, public Rocket::Core::Event
key = newKey; key = newKey;
dirty_key = true; dirty_key = true;
waitingForKeypress = false; waitingForKeypress = false;
Rocket::Core::Dictionary dict;
dict.Set( KEY_TEAM, team );
dict.Set( KEY_KEY, key );
DispatchEvent( KEY_SET_EVENT, dict );
} }


int GetTeam( Rocket::Core::String team ) int GetTeam( Rocket::Core::String team )
Expand Down

0 comments on commit a25add4

Please sign in to comment.