fix focus bug, change battle events

master
Eduardo Bart 12 years ago
parent e0325c4c3b
commit 959d9a87b0

@ -23,6 +23,7 @@
#include "eventdispatcher.h" #include "eventdispatcher.h"
#include <framework/core/clock.h> #include <framework/core/clock.h>
#include "timer.h"
EventDispatcher g_eventDispatcher; EventDispatcher g_eventDispatcher;
@ -53,10 +54,10 @@ void EventDispatcher::poll()
int count = 0; int count = 0;
while(m_pollEventsSize > 0) { while(m_pollEventsSize > 0) {
if(count > 50) { if(count > 50) {
static bool reported = false; static Timer reportTimer;
if(!reported) { if(reportTimer.running() && reportTimer.ticksElapsed() > 250) {
logError("ATTENTION the event list is not getting empty, this could be caused by some bad code"); logError("ATTENTION the event list is not getting empty, this could be caused by some bad code");
reported = true; reportTimer.restart();
} }
break; break;
} }

@ -88,10 +88,7 @@ void UIManager::inputEvent(const InputEvent& event)
m_mouseReceiver->propagateOnMouseEvent(event.mousePos, widgetList); m_mouseReceiver->propagateOnMouseEvent(event.mousePos, widgetList);
for(const UIWidgetPtr& widget : widgetList) { for(const UIWidgetPtr& widget : widgetList) {
if(widget->isFocusable()) { widget->recursiveFocus(Fw::MouseFocusReason);
if(UIWidgetPtr parent = widget->getParent())
parent->focusChild(widget, Fw::MouseFocusReason);
}
if(widget->onMousePress(event.mousePos, event.mouseButton)) if(widget->onMousePress(event.mousePos, event.mouseButton))
break; break;
} }

@ -579,6 +579,18 @@ void UIWidget::focus()
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason); parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
} }
void UIWidget::recursiveFocus(Fw::FocusReason reason)
{
if(m_destroyed)
return;
if(UIWidgetPtr parent = getParent()) {
if(m_focusable)
parent->focusChild(asUIWidget(), reason);
parent->recursiveFocus(reason);
}
}
void UIWidget::lower() void UIWidget::lower()
{ {
if(m_destroyed) if(m_destroyed)

@ -100,6 +100,7 @@ public:
void lock(); void lock();
void unlock(); void unlock();
void focus(); void focus();
void recursiveFocus(Fw::FocusReason reason);
void lower(); void lower();
void raise(); void raise();
void grabMouse(); void grabMouse();

@ -753,7 +753,6 @@ void Game::setChaseMode(Otc::ChaseModes chaseMode)
{ {
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
m_chaseMode = chaseMode; m_chaseMode = chaseMode;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
} }
@ -762,7 +761,6 @@ void Game::setFightMode(Otc::FightModes fightMode)
{ {
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
m_fightMode = fightMode; m_fightMode = fightMode;
m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight);
} }
@ -886,30 +884,16 @@ bool Game::canPerformGameAction()
void Game::setAttackingCreature(const CreaturePtr& creature) void Game::setAttackingCreature(const CreaturePtr& creature)
{ {
if(m_attackingCreature) { CreaturePtr oldCreature = m_attackingCreature;
m_attackingCreature->hideStaticSquare(); m_attackingCreature = creature;
m_attackingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Color::red);
m_attackingCreature = creature;
}
g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature); g_lua.callGlobalField("g_game", "onAttackingCreatureChange", creature, oldCreature);
} }
void Game::setFollowingCreature(const CreaturePtr& creature) void Game::setFollowingCreature(const CreaturePtr& creature)
{ {
if(m_followingCreature) { CreaturePtr oldCreature = m_followingCreature;
m_followingCreature->hideStaticSquare(); m_followingCreature = creature;
m_followingCreature = nullptr;
}
if(creature) {
creature->showStaticSquare(Color::green);
m_followingCreature = creature;
}
g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature); g_lua.callGlobalField("g_game", "onFollowingCreatureChange", creature, oldCreature);
} }

Loading…
Cancel
Save