void InputControlSystem::loadKeyBinders(TiXmlElement* xmlControlNode) { TiXmlElement* xmlKeyBinder = xmlControlNode->FirstChildElement("KeyBinder"); while(xmlKeyBinder) { Control::ControlChangingDirection dir = Control::STOP; if(std::string(xmlKeyBinder->Attribute("direction")) == "INCREASE") { dir = Control::INCREASE; } else if(std::string(xmlKeyBinder->Attribute("direction")) == "DECREASE") { dir = Control::DECREASE; } addKeyBinding(mControls.back(), SDL_Scancode(FromString<int>(xmlKeyBinder->Attribute("key"))), dir); xmlKeyBinder = xmlKeyBinder->NextSiblingElement("KeyBinder"); } }
variant playable_custom_object::get_player_value_by_slot(int slot) const { switch(slot) { case CUSTOM_OBJECT_PLAYER_DIFFICULTY: { if(preferences::force_difficulty() != INT_MIN) { return variant(preferences::force_difficulty()); } return variant(difficulty_); } case CUSTOM_OBJECT_PLAYER_CAN_INTERACT: { return variant(can_interact_); } case CUSTOM_OBJECT_PLAYER_UNDERWATER_CONTROLS: { return variant(underwater_controls_); } case CUSTOM_OBJECT_PLAYER_CTRL_MOD_KEY: { return variant(SDL_GetModState()); } case CUSTOM_OBJECT_PLAYER_CTRL_KEYS: { std::vector<variant> result; if(level_runner::get_current() && level_runner::get_current()->get_debug_console() && level_runner::get_current()->get_debug_console()->has_keyboard_focus()) { //the debug console is stealing all keystrokes. return variant(&result); } #if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR int ary_length; const Uint8* key_state = SDL_GetKeyboardState(&ary_length); #ifndef NO_EDITOR if(level_runner::get_current()) { const editor* e = level_runner::get_current()->get_editor(); if(e && e->has_keyboard_focus()) { //the editor has the focus, so we tell the game there //are no keys pressed. ary_length = 0; } } #endif for(int count = 0; count < ary_length; ++count) { if(key_state[count]) { //Returns only keys that are down so the list that ffl has to deal with is small. SDL_Keycode k = SDL_GetKeyFromScancode(SDL_Scancode(count)); if(k < 128 && util::c_isprint(k)) { std::string str(1,k); result.push_back(variant(str)); } else { result.push_back(variant(k)); } } } #endif return variant(&result); } case CUSTOM_OBJECT_PLAYER_CTRL_MICE: { std::vector<variant> result; #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR const int nmice = SDL_GetNumMice(); #else const int nmice = 1; #endif for(int n = 0; n != nmice; ++n) { #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR SDL_SelectMouse(n); #endif std::vector<variant> info; int x, y; Uint8 button_state = input::sdl_get_mouse_state(&x, &y); translate_mouse_coords(&x, &y); info.push_back(variant(x)); info.push_back(variant(y)); if(button_state & SDL_BUTTON(SDL_BUTTON_LEFT)) { info.push_back(variant("left")); } if(button_state & SDL_BUTTON(SDL_BUTTON_RIGHT)) { info.push_back(variant("right")); } if(button_state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) { info.push_back(variant("middle")); } if(button_state & SDL_BUTTON(SDL_BUTTON_X1)) { //these aren't tested info.push_back(variant("x1")); } if(button_state & SDL_BUTTON(SDL_BUTTON_X2)) { info.push_back(variant("x2")); } result.push_back(variant(&info)); } return variant(&result); } case CUSTOM_OBJECT_PLAYER_CTRL_TILT: { return variant(-joystick::iphone_tilt()); } case CUSTOM_OBJECT_PLAYER_CTRL_X: { return variant(underwater_ctrl_x_); } case CUSTOM_OBJECT_PLAYER_CTRL_Y: { return variant(underwater_ctrl_y_); } case CUSTOM_OBJECT_PLAYER_CTRL_REVERSE_AB: { return variant::from_bool(reverse_ab_); } case CUSTOM_OBJECT_PLAYER_CONTROL_SCHEME: { return variant(preferences::control_scheme()); } case CUSTOM_OBJECT_PLAYER_VERTICAL_LOOK: { return variant(vertical_look_); } case CUSTOM_OBJECT_PLAYER_CONTROL_LOCK: { std::vector<variant> result; const unsigned char* locked_control_frame = controls::get_local_control_lock(); if (locked_control_frame == nullptr) { return variant(); } for(int i = 0; i < 8; ++i){ if((*locked_control_frame & (0x01 << i)) ){ result.push_back( variant(ctrl[i]) ); } else { //this key isn't pressed } } return variant(&result); } } ASSERT_LOG(false, "unknown slot in get_player_value_by_slot: " << slot); }