ULTIMA4: Turn off keybindings for controllers that don't need it
This commit is contained in:
parent
f2e8f22fc1
commit
d942d49a76
7 changed files with 47 additions and 7 deletions
|
@ -45,6 +45,11 @@ int Controller::getTimerInterval() {
|
|||
return _timerInterval;
|
||||
}
|
||||
|
||||
void Controller::setActive() {
|
||||
// Controllers by default won't use the keybindings
|
||||
MetaEngine::setKeybindingsActive(false);
|
||||
}
|
||||
|
||||
void Controller::timerFired() {
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,15 @@ public:
|
|||
static void timerCallback(void *data);
|
||||
|
||||
/** control methods subclasses may want to override */
|
||||
|
||||
/**
|
||||
* Called when a controller is made active
|
||||
*/
|
||||
virtual void setActive();
|
||||
|
||||
/**
|
||||
* Key was pressed
|
||||
*/
|
||||
virtual bool keyPressed(int key) = 0;
|
||||
|
||||
/**
|
||||
|
|
|
@ -330,6 +330,11 @@ void GameController::update(Location *location, MoveEvent &event) {
|
|||
}
|
||||
}
|
||||
|
||||
void GameController::setActive() {
|
||||
// The game controller has the keybindings enabled
|
||||
MetaEngine::setKeybindingsActive(true);
|
||||
}
|
||||
|
||||
void GameController::keybinder(KeybindingAction action) {
|
||||
MetaEngine::executeAction(action);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,11 @@ public:
|
|||
|
||||
/* controller functions */
|
||||
|
||||
/**
|
||||
* Called when a controller is made active
|
||||
*/
|
||||
void setActive() override;
|
||||
|
||||
/**
|
||||
* Keybinder actions
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "ultima/ultima4/controllers/read_dir_controller.h"
|
||||
#include "ultima/ultima4/map/direction.h"
|
||||
#include "ultima/ultima4/meta_engine.h"
|
||||
|
||||
namespace Ultima {
|
||||
namespace Ultima4 {
|
||||
|
@ -31,6 +32,11 @@ ReadDirController::ReadDirController() {
|
|||
_value = DIR_NONE;
|
||||
}
|
||||
|
||||
void ReadDirController::setActive() {
|
||||
// Have the keybinder active for the direction keys
|
||||
MetaEngine::setKeybindingsActive(true);
|
||||
}
|
||||
|
||||
void ReadDirController::keybinder(KeybindingAction action) {
|
||||
switch (action) {
|
||||
case KEYBIND_UP:
|
||||
|
|
|
@ -36,6 +36,11 @@ class ReadDirController : public WaitableController<Direction> {
|
|||
public:
|
||||
ReadDirController();
|
||||
|
||||
/**
|
||||
* Called when a controller is made active
|
||||
*/
|
||||
void setActive() override;
|
||||
|
||||
/**
|
||||
* Key was pressed
|
||||
*/
|
||||
|
|
|
@ -38,9 +38,9 @@ using namespace Std;
|
|||
bool EventHandler::_controllerDone = false;
|
||||
bool EventHandler::_ended = false;
|
||||
|
||||
EventHandler *EventHandler::_instance = NULL;
|
||||
EventHandler *EventHandler::_instance = nullptr;
|
||||
EventHandler *EventHandler::getInstance() {
|
||||
if (_instance == NULL)
|
||||
if (_instance == nullptr)
|
||||
_instance = new EventHandler();
|
||||
return _instance;
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ TimedEventMgr *EventHandler::getTimer() {
|
|||
}
|
||||
|
||||
Controller *EventHandler::pushController(Controller *c) {
|
||||
c->setActive();
|
||||
_controllers.push_back(c);
|
||||
getTimer()->add(&Controller::timerCallback, c->getTimerInterval(), c);
|
||||
return c;
|
||||
|
@ -92,24 +93,28 @@ Controller *EventHandler::pushController(Controller *c) {
|
|||
|
||||
Controller *EventHandler::popController() {
|
||||
if (_controllers.empty())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
Controller *controller = _controllers.back();
|
||||
getTimer()->remove(&Controller::timerCallback, controller);
|
||||
_controllers.pop_back();
|
||||
|
||||
return getController();
|
||||
controller = getController();
|
||||
if (controller)
|
||||
controller->setActive();
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
Controller *EventHandler::getController() const {
|
||||
if (_controllers.empty())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
return _controllers.back();
|
||||
}
|
||||
|
||||
void EventHandler::setController(Controller *c) {
|
||||
while (popController() != NULL) {}
|
||||
while (popController() != nullptr) {}
|
||||
pushController(c);
|
||||
}
|
||||
|
||||
|
@ -126,7 +131,7 @@ const MouseArea *EventHandler::getMouseAreaSet() const {
|
|||
if (_mouseAreaSets.size())
|
||||
return _mouseAreaSets.front();
|
||||
else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // End of namespace Ultima4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue