Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make controller aiming analog #1818

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 5 additions & 4 deletions src/MenuActionBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ void MenuActionBar::checkAction(std::vector<ActionData> &action_queue) {
for (unsigned i = 0; i < slots_count; i++) {
ActionData action;
action.hotkey = i;
bool have_analog_aim = inpt->mode == InputState::MODE_JOYSTICK || inpt->usingMouse();
bool have_aim = false;
slot_activated[i] = false;

Expand Down Expand Up @@ -605,7 +606,7 @@ void MenuActionBar::checkAction(std::vector<ActionData> &action_queue) {
}

// joystick/keyboard action button
else if (!inpt->usingMouse() && slots[i]->checkClick() == WidgetSlot::ACTIVATE) {
else if (!have_analog_aim && slots[i]->checkClick() == WidgetSlot::ACTIVATE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, as it is handling the player clicking on an action bar slot as opposed to clicking on the play field.

have_aim = false;
slot_activated[i] = true;
action.power = hotkeys_mod[i];
Expand All @@ -614,17 +615,17 @@ void MenuActionBar::checkAction(std::vector<ActionData> &action_queue) {

// pressing hotkey
else if (i<10 && inpt->pressing[i + Input::BAR_1]) {
have_aim = inpt->usingMouse();
have_aim = have_analog_aim;
action.power = hotkeys_mod[i];
twostep_slot = -1;
}
else if (i==10 && inpt->pressing[Input::MAIN1] && !inpt->lock[Input::MAIN1] && !Utils::isWithinRect(window_area, inpt->mouse) && enable_main1) {
have_aim = inpt->usingMouse();
have_aim = have_analog_aim;
action.power = hotkeys_mod[10];
twostep_slot = -1;
}
else if (i==11 && inpt->pressing[Input::MAIN2] && !inpt->lock[Input::MAIN2] && !Utils::isWithinRect(window_area, inpt->mouse) && enable_main2) {
have_aim = inpt->usingMouse();
have_aim = have_analog_aim;
action.power = hotkeys_mod[11];
twostep_slot = -1;
}
Expand Down
8 changes: 3 additions & 5 deletions src/SDLInputState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,6 @@ void SDLInputState::initBindings() {

setBind(Input::PAUSE, InputBind::GAMEPAD, SDL_CONTROLLER_BUTTON_START, NULL);

setBind(Input::AIM_RIGHT, InputBind::GAMEPAD_AXIS, (SDL_CONTROLLER_AXIS_RIGHTX*2), NULL);
setBind(Input::AIM_DOWN, InputBind::GAMEPAD_AXIS, (SDL_CONTROLLER_AXIS_RIGHTY*2), NULL);
setBind(Input::AIM_LEFT, InputBind::GAMEPAD_AXIS, (SDL_CONTROLLER_AXIS_RIGHTX*2) + 1, NULL);
setBind(Input::AIM_UP, InputBind::GAMEPAD_AXIS, (SDL_CONTROLLER_AXIS_RIGHTY*2) + 1, NULL);

// Not user-modifiable
setBind(Input::CTRL, InputBind::KEY, SDL_SCANCODE_LCTRL, NULL);
setBind(Input::CTRL, InputBind::KEY, SDL_SCANCODE_RCTRL, NULL);
Expand Down Expand Up @@ -511,6 +506,9 @@ void SDLInputState::handle() {

SDL_JoystickID joy_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamepad));
if (joy_id == event.jbutton.which) {
mouse.x = SDL_GameControllerGetAxis(gamepad, SDL_CONTROLLER_AXIS_RIGHTX) + settings->view_w_half;
mouse.y = SDL_GameControllerGetAxis(gamepad, SDL_CONTROLLER_AXIS_RIGHTY) + settings->view_h_half;

for (int key=0; key<KEY_COUNT; key++) {
for (size_t i = 0; i < binding[key].size(); ++i) {
int bind_axis = binding[key][i].bind / 2;
Expand Down