record and replay tab/shift-tab in multi-field forms
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "tools/prefs.hpp"
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
#include "replay.hpp"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace ticpp;
|
||||
@@ -547,6 +548,9 @@ void cDialog::handle_events() {
|
||||
Element& next_action = pop_next_action();
|
||||
cKey key = key_from_action(next_action);
|
||||
dynamic_cast<cTextField&>(getControl(currentFocus)).handleInput(key);
|
||||
}else if(replaying && has_next_action() && next_action_type() == "handleTab"){
|
||||
Element& next_action = pop_next_action();
|
||||
handleTab(boost::lexical_cast<bool>(next_action.GetText()));
|
||||
}else{
|
||||
while(win.pollEvent(currentEvent)) handle_one_event(currentEvent, fps_limiter);
|
||||
}
|
||||
@@ -559,6 +563,17 @@ void cDialog::handle_events() {
|
||||
}
|
||||
}
|
||||
|
||||
void cDialog::handleTab(bool reverse) {
|
||||
if(recording){
|
||||
record_action("handleTab", boost::lexical_cast<std::string>(reverse));
|
||||
}
|
||||
if(reverse) {
|
||||
handleTabOrder(currentFocus, tabOrder.rbegin(), tabOrder.rend());
|
||||
} else {
|
||||
handleTabOrder(currentFocus, tabOrder.begin(), tabOrder.end());
|
||||
}
|
||||
}
|
||||
|
||||
// This method handles one event received by the dialog.
|
||||
void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter& fps_limiter) {
|
||||
using Key = sf::Keyboard::Key;
|
||||
@@ -650,11 +665,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
|
||||
// If it's a tab, handle tab order
|
||||
if(key.spec && key.k == key_tab) {
|
||||
// Could use key.mod, but this is slightly easier.
|
||||
if(currentEvent.key.shift) {
|
||||
handleTabOrder(currentFocus, tabOrder.rbegin(), tabOrder.rend());
|
||||
} else {
|
||||
handleTabOrder(currentFocus, tabOrder.begin(), tabOrder.end());
|
||||
}
|
||||
handleTab(currentEvent.key.shift);
|
||||
} else {
|
||||
// If it's a character key, and the system key (control/command) is not pressed,
|
||||
// we have an upcoming TextEntered event which contains more information.
|
||||
|
@@ -68,6 +68,7 @@ class cDialog {
|
||||
cDialog* parent;
|
||||
std::string generateRandomString();
|
||||
void loadFromFile(const DialogDefn& file);
|
||||
void handleTab(bool reverse);
|
||||
template<typename Iter> void handleTabOrder(std::string& itemHit, Iter begin, Iter end);
|
||||
std::vector<std::pair<std::string,cTextField*>> tabOrder;
|
||||
static cDialog* topWindow; // Tracks the frontmost dialog.
|
||||
|
Reference in New Issue
Block a user