Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions recompinput/include/recompinput/profiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace recompinput {
const std::vector<int> get_indices_for_custom_profiles(InputDevice device);
void set_input_profile_for_player(int player_index, int profile_index, InputDevice device);
int get_input_profile_for_player(int player_index, InputDevice device);
void mask_currently_pressed_buttons_for_all_players();
int add_controller(ControllerGUID guid, int profile_index);
const ControllerGUID &get_controller_guid(int controller_index);
int get_controller_profile_index(int controller_index);
Expand Down
4 changes: 4 additions & 0 deletions recompinput/src/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ bool players::get_player_is_assigned(int player_index, bool temp_player) {
}

bool players::has_enough_players_assigned() {
if (players::is_single_player_mode()) {
return true;
}
return PlayerState.players.get_count() >= PlayerState.min_players;
}

Expand Down Expand Up @@ -150,6 +153,7 @@ void playerassignment::stop_and_close_modal() {
}

void playerassignment::commit_player_assignment() {
profiles::mask_currently_pressed_buttons_for_all_players();
stop_and_close_modal();

PlayerState.players = PlayerState.temp_players;
Expand Down
8 changes: 7 additions & 1 deletion recompinput/src/profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct InputProfile {

static std::vector<InputProfile> input_profiles{};
static std::array<std::pair<int, int>, recompinput::max_num_players_supported> players_input_profile_indices{};
static std::array<uint16_t, recompinput::max_num_players_supported> players_input_currently_pressed_buttons_mask{};
static std::unordered_map<std::string, int> input_profile_key_index_map{};
static std::vector<int> input_profile_custom_indices[static_cast<size_t>(recompinput::InputDevice::COUNT)]{};

Expand Down Expand Up @@ -224,6 +225,10 @@ namespace recompinput {
return -1;
}
}

void profiles::mask_currently_pressed_buttons_for_all_players() {
players_input_currently_pressed_buttons_mask.fill(0xFFFFU);
}

int profiles::add_controller(ControllerGUID guid, int profile_index) {
auto it = controller_hash_index_map.find(guid.hash);
Expand Down Expand Up @@ -407,7 +412,8 @@ namespace recompinput {
check_joystick(profile_index_kb);
}

*buttons_out = cur_buttons;
*buttons_out = cur_buttons & (~players_input_currently_pressed_buttons_mask[player_index]);
players_input_currently_pressed_buttons_mask[player_index] &= cur_buttons;
*x_out = std::clamp(cur_x, -1.0f, 1.0f);
*y_out = std::clamp(cur_y, -1.0f, 1.0f);

Expand Down
11 changes: 11 additions & 0 deletions recompui/src/base/ui_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ void draw_hook(plume::RenderCommandList* command_list, plume::RenderFramebuffer*
}
} // end dequeue event loop

// In game when the player count isn't sufficient, open the assign player process
if (
!recompui::is_context_shown(recompui::config::get_config_context_id()) &&
ultramodern::is_game_started() &&
!recompinput::players::has_enough_players_assigned() &&
!recompui::AssignPlayersModal::check_is_open()
) {
recompinput::playerassignment::start();
recompui::AssignPlayersModal::open();
}

// Handle controller key repeats.
if (latest_controller_key_pressed != SDLK_UNKNOWN) {
clock::time_point now = clock::now();
Expand Down
8 changes: 8 additions & 0 deletions recompui/src/composites/ui_assign_players_modal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,12 @@ void AssignPlayersModal::init() {
assign_players_modal_context.close();
}

bool AssignPlayersModal::check_is_open() {
if (assign_players_modal_instance == nullptr || !recompui::is_context_shown(assign_players_modal_context)) {
return false;
}

return assign_players_modal_instance->is_open;
}

} // namespace recompui
1 change: 1 addition & 0 deletions recompui/src/composites/ui_assign_players_modal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AssignPlayersModal : public Element {
// Pass false to force player assignment.
static void open();
static void close();
static bool check_is_open();
};

} // namespace recompui