| 678 | } |
| 679 | |
| 680 | void Pad::SetMacroButtonState(InputBindingKey& key, u32 pad, u32 index, bool state) |
| 681 | { |
| 682 | //0 appears for some reason and breaks mb.active_buttons.size() != binding_count |
| 683 | if (key.bits == 0) |
| 684 | return; |
| 685 | |
| 686 | if (pad >= Pad::NUM_CONTROLLER_PORTS || index >= NUM_MACRO_BUTTONS_PER_CONTROLLER) |
| 687 | return; |
| 688 | |
| 689 | MacroButton& mb = s_macro_buttons[pad][index]; |
| 690 | if (mb.buttons.empty()) |
| 691 | return; |
| 692 | |
| 693 | SettingsInterface& sif = *Host::GetSettingsInterface(); |
| 694 | std::vector<std::string> data = sif.GetStringList(fmt::format("Pad{}", pad+1).c_str(), fmt::format("Macro{}", index+1).c_str()); |
| 695 | size_t binding_count = 0; |
| 696 | //just in case there's more than one index |
| 697 | for (std::string bind : data) |
| 698 | { |
| 699 | binding_count += InputManager::SplitChord(bind).size(); |
| 700 | } |
| 701 | if (mb.active_buttons.find(key.bits) != mb.active_buttons.end()) |
| 702 | mb.active_buttons.erase(key.bits); |
| 703 | |
| 704 | mb.active_buttons.emplace(key.bits, state); |
| 705 | |
| 706 | if (mb.active_buttons.size() != binding_count) |
| 707 | return; |
| 708 | |
| 709 | if (mb.active_buttons.size() > 1 && state) |
| 710 | { |
| 711 | for (auto it = mb.active_buttons.begin(); it != mb.active_buttons.end(); ++it) |
| 712 | { |
| 713 | if (!it->second) |
| 714 | return; |
| 715 | } |
| 716 | } |
| 717 | const bool trigger_state = (mb.trigger_toggle ? (state ? !mb.trigger_state : mb.trigger_state) : state); |
| 718 | if (mb.trigger_state == trigger_state) |
| 719 | return; |
| 720 | |
| 721 | mb.toggle_counter = mb.toggle_frequency; |
| 722 | mb.trigger_state = trigger_state; |
| 723 | if (mb.toggle_state != trigger_state) |
| 724 | { |
| 725 | mb.toggle_state = trigger_state; |
| 726 | ApplyMacroButton(pad, mb); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | void Pad::ApplyMacroButton(u32 controller, const Pad::MacroButton& mb) |
| 731 | { |