diff --git a/.github/reviewers.yml b/.github/reviewers.yml index 4cb54fa6bd4a4..4cc5438ab5b09 100644 --- a/.github/reviewers.yml +++ b/.github/reviewers.yml @@ -51,5 +51,5 @@ files: - dseguin 'src/ui_manager.*': - Qrox - 'data/raw/keybindings.json': + 'data/raw/keybindings{.json,/**}': - Qrox diff --git a/data/raw/keybindings/vehicle.json b/data/raw/keybindings/vehicle.json index d15e75e2c57c4..4550bfc1a961a 100644 --- a/data/raw/keybindings/vehicle.json +++ b/data/raw/keybindings/vehicle.json @@ -39,7 +39,7 @@ "type": "keybinding", "category": "VEHICLE", "name": "Pull handbrake", - "bindings": [ { "input_method": "keyboard_any", "key": "H" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "H" }, { "input_method": "keyboard_code", "key": "h", "mod": [ "shift" ] } ] }, { "id": "USE_WORKBENCH", @@ -88,21 +88,21 @@ "type": "keybinding", "category": "VEHICLE", "name": "Toggle autoclave", - "bindings": [ { "input_method": "keyboard_any", "key": "C" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "C" }, { "input_method": "keyboard_code", "key": "c", "mod": [ "shift" ] } ] }, { "id": "TOGGLE_WASHING_MACHINE", "type": "keybinding", "category": "VEHICLE", "name": "Toggle washing machine", - "bindings": [ { "input_method": "keyboard_any", "key": "W" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "W" }, { "input_method": "keyboard_code", "key": "w", "mod": [ "shift" ] } ] }, { "id": "TOGGLE_DISHWASHER", "type": "keybinding", "category": "VEHICLE", "name": "Toggle dishwasher", - "bindings": [ { "input_method": "keyboard_any", "key": "D" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "D" }, { "input_method": "keyboard_code", "key": "d", "mod": [ "shift" ] } ] }, { "id": "GET_ITEMS", @@ -151,21 +151,21 @@ "type": "keybinding", "category": "VEHICLE", "name": "Purify water in vehicle tank", - "bindings": [ { "input_method": "keyboard_any", "key": "P" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "P" }, { "input_method": "keyboard_code", "key": "p", "mod": [ "shift" ] } ] }, { "id": "USE_CAPTURE_MONSTER_VEH", "type": "keybinding", "category": "VEHICLE", "name": "Capture or release a creature", - "bindings": [ { "input_method": "keyboard_any", "key": "G" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "G" }, { "input_method": "keyboard_code", "key": "g", "mod": [ "shift" ] } ] }, { "id": "USE_ANIMAL_CTRL", "type": "keybinding", "category": "VEHICLE", "name": "Harness an animal", - "bindings": [ { "input_method": "keyboard_any", "key": "H" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "H" }, { "input_method": "keyboard_code", "key": "h", "mod": [ "shift" ] } ] }, { "id": "USE_PLANTER", @@ -256,7 +256,7 @@ "type": "keybinding", "category": "VEHICLE", "name": "Toggle space heater", - "bindings": [ { "input_method": "keyboard_any", "key": "J" } ] + "bindings": [ { "input_method": "keyboard_char", "key": "J" }, { "input_method": "keyboard_code", "key": "j", "mod": [ "shift" ] } ] }, { "id": "TOGGLE_HEATED_TANK", diff --git a/src/veh_utils.cpp b/src/veh_utils.cpp index 2090c369f5ac5..dba4b9e7d20f6 100644 --- a/src/veh_utils.cpp +++ b/src/veh_utils.cpp @@ -196,16 +196,10 @@ static std::optional veh_keybind( const std::optional return std::nullopt; } - const std::vector hk_keycode = input_context( "VEHICLE", keyboard_mode::keycode ) - .keys_bound_to( *hotkey, /* maximum_modifier_count = */ 1 ); - if( !hk_keycode.empty() ) { - return hk_keycode.front(); // try for keycode hotkey first - } - - const std::vector hk_keychar = input_context( "VEHICLE", keyboard_mode::keychar ) - .keys_bound_to( *hotkey ); - if( !hk_keychar.empty() ) { - return hk_keychar.front(); // fallback to keychar hotkey + const std::vector hk = input_context( "VEHICLE" ) + .keys_bound_to( *hotkey, /* maximum_modifier_count = */ 1 ); + if( !hk.empty() ) { + return hk.front(); } return input_event(); @@ -215,7 +209,6 @@ veh_menu_item &veh_menu_item::hotkey( const char hotkey_char ) { this->_hotkey_action = std::nullopt; this->_hotkey_char = hotkey_char; - this->_hotkey_event = std::nullopt; return *this; } @@ -223,15 +216,6 @@ veh_menu_item &veh_menu_item::hotkey( const std::string &action ) { this->_hotkey_action = action; this->_hotkey_char = std::nullopt; - this->_hotkey_event = std::nullopt; - return *this; -} - -veh_menu_item &veh_menu_item::hotkey( const input_event &ev ) -{ - this->_hotkey_action = std::nullopt; - this->_hotkey_char = std::nullopt; - this->_hotkey_event = ev; return *this; } @@ -239,7 +223,6 @@ veh_menu_item &veh_menu_item::hotkey_auto() { this->_hotkey_char = std::nullopt; this->_hotkey_action = std::nullopt; - this->_hotkey_event = std::nullopt; return *this; } @@ -314,15 +297,12 @@ std::vector veh_menu::get_uilist_entries() const for( size_t i = 0; i < items.size(); i++ ) { const veh_menu_item &it = items[i]; - std::optional hotkey_event = std::nullopt; - if( it._hotkey_event.has_value() ) { - hotkey_event = it._hotkey_event.value(); - } else if( it._hotkey_action.has_value() ) { - hotkey_event = veh_keybind( it._hotkey_action ); + uilist_entry entry( it._text, std::nullopt ); + if( it._hotkey_action.has_value() ) { + entry = uilist_entry( it._text, veh_keybind( it._hotkey_action ) ); } else if( it._hotkey_char.has_value() ) { - hotkey_event = input_event( it._hotkey_char.value(), input_event_t::keyboard_char ); + entry = uilist_entry( it._text, it._hotkey_char.value() ); } - uilist_entry entry = uilist_entry( it._text, hotkey_event ); entry.retval = static_cast( i ); entry.desc = it._desc; diff --git a/src/veh_utils.h b/src/veh_utils.h index cea2e355ea1c8..e68e7cf971f78 100644 --- a/src/veh_utils.h +++ b/src/veh_utils.h @@ -42,7 +42,6 @@ struct veh_menu_item { bool _keep_menu_open = false; std::optional _hotkey_char = std::nullopt; std::optional _hotkey_action = std::nullopt; - std::optional _hotkey_event = std::nullopt; std::function _on_submit; veh_menu_item &text( const std::string &text ); @@ -52,7 +51,6 @@ struct veh_menu_item { veh_menu_item &skip_locked_check( bool skip_locked_check = true ); veh_menu_item &hotkey( char hotkey_char ); veh_menu_item &hotkey( const std::string &action ); - veh_menu_item &hotkey( const input_event &ev ); veh_menu_item &hotkey_auto(); veh_menu_item &on_submit( const std::function &on_submit ); veh_menu_item &keep_menu_open( bool keep_menu_open = true ); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 8a53282f223e4..32e84452325fb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2434,9 +2434,9 @@ std::optional vpart_position::part_with_tool( const itype_id &t if( vp.part().is_broken() ) { continue; } - const std::map tools = vehicle().prepare_tools( vp.part() ); + const std::map tools = vehicle().prepare_tools( vp.part() ); if( std::find_if( tools.begin(), tools.end(), - [&tool_type]( const std::pair &pair ) { + [&tool_type]( const std::pair &pair ) { return pair.first.typeId() == tool_type; } ) != tools.end() ) { return vp; @@ -2445,16 +2445,16 @@ std::optional vpart_position::part_with_tool( const itype_id &t return std::optional(); } -std::map vpart_position::get_tools() const +std::map vpart_position::get_tools() const { - std::map res; + std::map res; for( const int part_idx : this->vehicle().parts_at_relative( this->mount(), false ) ) { const vehicle_part &vp = this->vehicle().part( part_idx ); if( vp.is_broken() ) { continue; } - for( const auto &[tool_item, ev] : this->vehicle().prepare_tools( vp ) ) { - res[tool_item] = ev; + for( const auto &[tool_item, hk] : this->vehicle().prepare_tools( vp ) ) { + res[tool_item] = hk; } } return res; @@ -5593,22 +5593,18 @@ const std::vector &vehicle::get_tools( const vehicle_part &vp ) const return vp.tools; } -std::map vehicle::prepare_tools( const vehicle_part &vp ) const +std::map vehicle::prepare_tools( const vehicle_part &vp ) const { - std::map res; + std::map res; for( const std::pair &pair : vp.info().get_pseudo_tools() ) { item it( pair.first, calendar::turn ); - const input_event ev( pair.second, input_event_t::keyboard_char ); prepare_tool( it ); - res.emplace( it, pair.second > 0 ? ev : input_event( -1, input_event_t::error ) ); + res.emplace( it, pair.second > 0 ? pair.second : -1 ); } for( const item &it_src : vp.tools ) { item it( it_src ); // make a copy - const input_event ev = it.invlet > 0 - ? input_event( it.invlet, input_event_t::keyboard_char ) - : input_event(); prepare_tool( it ); - res.emplace( it, ev ); + res.emplace( it, it.invlet > 0 ? it.invlet : 0 ); } return res; } diff --git a/src/vehicle.h b/src/vehicle.h index 330141e5a0348..8a4cbe132fdb4 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -1748,7 +1748,7 @@ class vehicle * marked with PSEUDO flags, pseudo_magazine_mod and pseudo_magazine attached, magazines filled * with the first ammo type required by the tool. pseudo tools are mapped to their hotkey if exists. */ - std::map prepare_tools( const vehicle_part &vp ) const; + std::map prepare_tools( const vehicle_part &vp ) const; /** * Update an item's active status, for example when adding diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index f2567195d9ec1..bdf59530ae075 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -2057,18 +2057,18 @@ void vehicle::build_interact_menu( veh_menu &menu, const tripoint &p, bool with_ } } - for( const auto&[tool_item, hotkey_event] : vp.get_tools() ) { + for( const auto&[tool_item, hk] : vp.get_tools() ) { const itype_id &tool_type = tool_item.typeId(); if( !tool_type->has_use() ) { continue; // passive tool } - if( !hotkey_event.sequence.empty() && hotkey_event.sequence.front() == -1 ) { + if( hk == -1 ) { continue; // skip old passive tools } const auto &[tool_ammo, ammo_amount] = tool_ammo_available( tool_type ); menu.add( string_format( _( "Use %s" ), tool_type->nname( 1 ) ) ) .enable( ammo_amount >= tool_item.typeId()->charges_to_use() ) - .hotkey( hotkey_event ) + .hotkey( hk ) .skip_locked_check( tool_ammo.is_null() || tool_ammo->ammo->type != ammo_battery ) .on_submit( [this, vppos, tool_type] { use_vehicle_tool( *this, vppos, tool_type ); } ); } @@ -2251,7 +2251,7 @@ void vehicle::build_interact_menu( veh_menu &menu, const tripoint &p, bool with_ Character &you = get_player_character(); vehicle_part &vp = part( vp_idx ); std::set allowed_types = vp.info().toolkit_info->allowed_types; - for( const std::pair &pair : prepare_tools( vp ) ) + for( const std::pair &pair : prepare_tools( vp ) ) { allowed_types.erase( pair.first.typeId() ); // one tool of each kind max } diff --git a/src/vpart_position.h b/src/vpart_position.h index 590641c158b8e..66dee4b16efba 100644 --- a/src/vpart_position.h +++ b/src/vpart_position.h @@ -91,7 +91,7 @@ class vpart_position // Finds vpart_reference to inner part with specified tool std::optional part_with_tool( const itype_id &tool_type ) const; // Returns a list of all tools provided by vehicle and their hotkey - std::map get_tools() const; + std::map get_tools() const; // Forms inventory for inventory::form_from_map void form_inventory( inventory &inv ) const;