本文整理汇总了C++中input_manager::get_input_for_action方法的典型用法代码示例。如果您正苦于以下问题:C++ input_manager::get_input_for_action方法的具体用法?C++ input_manager::get_input_for_action怎么用?C++ input_manager::get_input_for_action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类input_manager
的用法示例。
在下文中一共展示了input_manager::get_input_for_action方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: press_x
// TODO: merge this with input_context::get_desc
std::string input_context::press_x(const std::string &action_id, const std::string &key_bound_pre,
const std::string &key_bound_suf, const std::string &key_unbound) const
{
if (action_id == "ANY_INPUT") {
return _("any key");
}
if (action_id == "COORDINATE") {
return _("mouse movement");
}
const input_manager::t_input_event_list &events = inp_mngr.get_input_for_action(action_id,
category);
if (events.empty()) {
return key_unbound;
}
std::ostringstream keyed;
keyed << key_bound_pre;
for (size_t j = 0; j < events.size(); j++) {
for (size_t k = 0; k < events[j].sequence.size(); ++k) {
keyed << inp_mngr.get_keyname(events[j].sequence[k], events[j].type);
}
if (j + 1 < events.size()) {
keyed << _(" or ");
}
}
keyed << key_bound_suf;
return keyed.str();
}
示例2: display_help
void input_context::display_help()
{
// Shamelessly stolen from help.cpp
WINDOW *w_help = newwin(FULL_SCREEN_HEIGHT - 2, FULL_SCREEN_WIDTH - 2,
1 + (int)((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0),
1 + (int)((TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0));
werase(w_help);
// Draw win header and borders
draw_border(w_help, c_white);
mvwprintz(w_help, 0, (FULL_SCREEN_WIDTH - utf8_width(_("Keybindings"))) / 2 - 1,
c_ltred, " %s ", _("Keybindings"));
mvwprintz(w_help, 1, 51, c_ltred, _("Unbound keys"));
mvwprintz(w_help, 2, 51, c_ltgreen, _("Keybinding active only"));
mvwprintz(w_help, 3, 51, c_ltgreen, _("on this screen"));
mvwprintz(w_help, 4, 51, c_ltgray, _("Keybinding active globally"));
// Clear the lines. Don't touch borders
for (int i = 1; i < FULL_SCREEN_HEIGHT - 3; i++) {
mvwprintz(w_help, i, 1, c_black, " ");
}
for (int i = 0; i < registered_actions.size(); i++) {
const std::string &action_id = registered_actions[i];
if(action_id == "ANY_INPUT") {
continue;
}
bool overwrite_default;
const std::vector<input_event> &input_events = inp_mngr.get_input_for_action(action_id, category,
&overwrite_default);
nc_color col = input_events.size() ? c_white : c_ltred;
mvwprintz(w_help, i, 3, col, "%s: ", inp_mngr.get_action_name(action_id).c_str());
if (!input_events.size()) {
mvwprintz(w_help, i, 30, c_ltred, _("Unbound!"));
} else {
// The color depends on whether this input draws from context-local or from
// default settings. Default will be ltgray, overwrite will be ltgreen.
col = overwrite_default ? c_ltgreen : c_ltgray;
mvwprintz(w_help, i, 30, col, "%s", get_desc(action_id).c_str());
}
}
wrefresh(w_help);
refresh();
long ch = getch();
while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE) {
ch = getch();
};
werase(w_help);
wrefresh(w_help);
delwin(w_help);
}
示例3:
std::vector<char> input_context::keys_bound_to(const std::string &action_descriptor) const
{
std::vector<char> result;
const std::vector<input_event> &events = inp_mngr.get_input_for_action(action_descriptor, category);
for( const auto &events_event : events ) {
// Ignore multi-key input and non-keyboard input
if( events_event.type == CATA_INPUT_KEYBOARD && events_event.sequence.size() == 1 ) {
result.push_back( (char)events_event.sequence[0] );
}
}
return result;
}
示例4:
const std::string& input_context::input_to_action(input_event& inp) {
for(int i=0; i<registered_actions.size(); i++) {
const std::string& action = registered_actions[i];
const std::vector<input_event>& check_inp = inp_mngr.get_input_for_action(action, category);
// Does this action have our queried input event in its keybindings?
for(int i=0; i<check_inp.size(); i++) {
if(check_inp[i] == inp) {
return action;
}
}
}
return CATA_ERROR;
}
示例5:
std::vector<char> input_context::keys_bound_to(const std::string &action_descriptor) const
{
std::vector<char> result;
const std::vector<input_event> &events = inp_mngr.get_input_for_action(action_descriptor, category);
for (std::vector<input_event>::const_iterator event = events.begin();
event != events.end();
++event) {
// Ignore multi-key input and non-keyboard input
if (event->type == CATA_INPUT_KEYBOARD && event->sequence.size() == 1) {
result.push_back((char) event->sequence[0]);
}
}
return result;
}
示例6:
const std::string &input_context::input_to_action(input_event &inp)
{
for( auto &elem : registered_actions ) {
const std::string &action = elem;
const std::vector<input_event> &check_inp = inp_mngr.get_input_for_action(action, category);
// Does this action have our queried input event in its keybindings?
for( auto &check_inp_i : check_inp ) {
if( check_inp_i == inp ) {
return action;
}
}
}
return CATA_ERROR;
}
示例7: _
const std::string input_context::get_desc( const std::string &action_descriptor,
const unsigned int max_limit ) const
{
if( action_descriptor == "ANY_INPUT" ) {
return "(*)"; // * for wildcard
}
const std::vector<input_event> &events = inp_mngr.get_input_for_action( action_descriptor,
category );
if( events.empty() ) {
return _( "Unbound!" );
}
std::vector<input_event> inputs_to_show;
for( auto &events_i : events ) {
const input_event &event = events_i;
// Only display gamepad buttons if a gamepad is available.
if( gamepad_available() || event.type != CATA_INPUT_GAMEPAD ) {
inputs_to_show.push_back( event );
}
if( max_limit > 0 && inputs_to_show.size() == max_limit ) {
break;
}
}
std::stringstream rval;
for( size_t i = 0; i < inputs_to_show.size(); ++i ) {
for( size_t j = 0; j < inputs_to_show[i].sequence.size(); ++j ) {
rval << inp_mngr.get_keyname( inputs_to_show[i].sequence[j], inputs_to_show[i].type );
}
// We're generating a list separated by "," and "or"
if( i + 2 == inputs_to_show.size() ) {
rval << _( " or " );
} else if( i + 1 < inputs_to_show.size() ) {
rval << ", ";
}
}
return rval.str();
}
示例8: get_available_single_char_hotkeys
std::string input_context::get_available_single_char_hotkeys(std::string requested_keys)
{
for (std::vector<std::string>::const_iterator registered_action = registered_actions.begin();
registered_action != registered_actions.end();
++registered_action) {
const std::vector<input_event> &events = inp_mngr.get_input_for_action(*registered_action,
category);
for( const auto &events_event : events ) {
// Only consider keyboard events without modifiers
if( events_event.type == CATA_INPUT_KEYBOARD && 0 == events_event.modifiers.size() ) {
requested_keys.erase( std::remove_if( requested_keys.begin(), requested_keys.end(),
ContainsPredicate<std::vector<long>, char>(
events_event.sequence ) ),
requested_keys.end() );
}
}
}
return requested_keys;
}
示例9: if
const std::string input_context::get_desc(const std::string &action_descriptor)
{
if(action_descriptor == "ANY_INPUT") {
return "(*)"; // * for wildcard
}
const std::vector<input_event> &events = inp_mngr.get_input_for_action(action_descriptor, category);
if(events.size() == 0) {
return UNDEFINED;
}
std::vector<input_event> inputs_to_show;
for( size_t i = 0; i < events.size(); ++i ) {
const input_event &event = events[i];
// Only display gamepad buttons if a gamepad is available.
if(gamepad_available() || event.type != CATA_INPUT_GAMEPAD) {
inputs_to_show.push_back(event);
}
}
std::stringstream rval;
for( size_t i = 0; i < inputs_to_show.size(); ++i ) {
for( size_t j = 0; j < inputs_to_show[i].sequence.size(); ++j ) {
rval << inp_mngr.get_keyname(inputs_to_show[i].sequence[j], inputs_to_show[i].type);
}
// We're generating a list separated by "," and "or"
if(i + 2 == inputs_to_show.size()) {
rval << " or ";
} else if(i + 1 < inputs_to_show.size()) {
rval << ", ";
}
}
return rval.str();
}