Skip to content

Commit

Permalink
Client|Bindings: Checking for bindings regardless of context activation
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jun 21, 2013
1 parent 65c76be commit 3b6dc16
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion doomsday/client/include/ui/b_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ void B_EventBindingToString(const evbinding_t* eb, ddstring_t* str);
* @param eventClass The event has been bound in this binding class. If the
* bound state is associated with a higher-priority active
* class, the binding cannot be executed.
* @param respectHigherAssociatedContexts Bindings are shadowed by higher active contexts.
*
* @return Action to be triggered, or @c NULL. Caller gets ownership.
*/
de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event, struct bcontext_s *eventClass);
de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event,
struct bcontext_s *eventClass, bool respectHigherAssociatedContexts);

#endif // __DOOMSDAY_BIND_COMMAND_H__
3 changes: 2 additions & 1 deletion doomsday/client/include/ui/b_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ de::Action *B_ActionForEvent(ddevent_t const *event);
*
* @param bc Binding context to look in.
* @param event Event to match against.
* @param respectHigherAssociatedContexts Bindings shadowed by higher active contexts.
*
* @return Action instance (caller gets ownership), or @c NULL if not found.
*/
de::Action *BindContext_ActionForEvent(bcontext_t *bc, ddevent_t const *event);
de::Action *BindContext_ActionForEvent(bcontext_t *bc, ddevent_t const *event, bool respectHigherAssociatedContexts);

boolean B_FindMatchingBinding(bcontext_t* bc, evbinding_t* match1, dbinding_t* match2,
evbinding_t** evResult, dbinding_t** dResult);
Expand Down
13 changes: 10 additions & 3 deletions doomsday/client/src/ui/b_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ static void B_SubstituteInCommand(char const *command, ddevent_t const *event,
}
}

de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event, struct bcontext_s *eventClass)
de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event,
struct bcontext_s *eventClass,
bool respectHigherAssociatedContexts)
{
int i;
inputdev_t* dev = 0;
Expand All @@ -380,10 +382,15 @@ de::Action *EventBinding_ActionForEvent(evbinding_t *eb, ddevent_t const *event,
switch(event->type)
{
case E_TOGGLE:
qDebug() << "eb->id" << eb->id << "event.id" << event->toggle.id;
if(eb->id != event->toggle.id)
return 0;
if(eventClass && dev->keys[eb->id].assoc.bContext != eventClass)
return 0; // Shadowed by a more important active class.

if(respectHigherAssociatedContexts)
{
if(eventClass && dev->keys[eb->id].assoc.bContext != eventClass)
return 0; // Shadowed by a more important active class.
}

// We're checking it, so clear the triggered flag.
dev->keys[eb->id].assoc.flags &= ~IDAF_TRIGGERED;
Expand Down
10 changes: 4 additions & 6 deletions doomsday/client/src/ui/b_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,14 @@ boolean B_DeleteBinding(bcontext_t* bc, int bid)
return false;
}

de::Action *BindContext_ActionForEvent(bcontext_t *bc, ddevent_t const *event)
de::Action *BindContext_ActionForEvent(bcontext_t *bc, ddevent_t const *event,
bool respectHigherAssociatedContexts)
{
if(!(bc->flags & BCF_ACTIVE))
return 0;

// See if the command bindings will have it.
for(evbinding_t *eb = bc->commandBinds.next; eb != &bc->commandBinds; eb = eb->next)
{
de::Action *act = 0;
if((act = EventBinding_ActionForEvent(eb, event, bc)) != 0)
if((act = EventBinding_ActionForEvent(eb, event, bc, respectHigherAssociatedContexts)) != 0)
{
return act;
}
Expand All @@ -561,7 +559,7 @@ de::Action *B_ActionForEvent(ddevent_t const *event)
if(!(bc->flags & BCF_ACTIVE))
continue;

de::Action *act = BindContext_ActionForEvent(bc, event);
de::Action *act = BindContext_ActionForEvent(bc, event, true);
if(act)
{
return act;
Expand Down
5 changes: 3 additions & 2 deletions doomsday/client/src/ui/widgets/widgetactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ bool WidgetActions::tryEvent(Event const &event, String const &context)
return tryEvent(&ddev);
}

// Check a specific binding context for an action.
// Check a specific binding context for an action (regardless of its
// activation status).
bcontext_t *bc = B_ContextByName(context.toLatin1());
if(bc)
{
std::auto_ptr<Action> act(BindContext_ActionForEvent(bc, &ddev));
std::auto_ptr<Action> act(BindContext_ActionForEvent(bc, &ddev, false));
if(act.get())
{
act->trigger();
Expand Down

0 comments on commit 3b6dc16

Please sign in to comment.