1
0
Fork 0
forked from suyu/suyu

applet: controller: Implement cancel button

This commit is contained in:
german77 2023-03-26 21:26:28 -06:00
parent 8bdc51b620
commit 11edba4974
9 changed files with 33 additions and 19 deletions

View file

@ -71,7 +71,7 @@ void DefaultControllerApplet::ReconfigureControllers(ReconfigureCallback callbac
} }
} }
callback(); callback(true);
} }
} // namespace Core::Frontend } // namespace Core::Frontend

View file

@ -37,7 +37,7 @@ struct ControllerParameters {
class ControllerApplet : public Applet { class ControllerApplet : public Applet {
public: public:
using ReconfigureCallback = std::function<void()>; using ReconfigureCallback = std::function<void(bool)>;
virtual ~ControllerApplet(); virtual ~ControllerApplet();

View file

@ -224,7 +224,8 @@ void Controller::Execute() {
parameters.allow_dual_joycons, parameters.allow_left_joycon, parameters.allow_dual_joycons, parameters.allow_left_joycon,
parameters.allow_right_joycon); parameters.allow_right_joycon);
frontend.ReconfigureControllers([this] { ConfigurationComplete(); }, parameters); frontend.ReconfigureControllers(
[this](bool is_success) { ConfigurationComplete(is_success); }, parameters);
break; break;
} }
case ControllerSupportMode::ShowControllerStrapGuide: case ControllerSupportMode::ShowControllerStrapGuide:
@ -232,16 +233,16 @@ void Controller::Execute() {
case ControllerSupportMode::ShowControllerKeyRemappingForSystem: case ControllerSupportMode::ShowControllerKeyRemappingForSystem:
UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented", UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented",
controller_private_arg.mode); controller_private_arg.mode);
ConfigurationComplete(); ConfigurationComplete(true);
break; break;
default: { default: {
ConfigurationComplete(); ConfigurationComplete(true);
break; break;
} }
} }
} }
void Controller::ConfigurationComplete() { void Controller::ConfigurationComplete(bool is_success) {
ControllerSupportResultInfo result_info{}; ControllerSupportResultInfo result_info{};
// If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
@ -250,7 +251,8 @@ void Controller::ConfigurationComplete() {
result_info.selected_id = static_cast<u32>(system.HIDCore().GetFirstNpadId()); result_info.selected_id = static_cast<u32>(system.HIDCore().GetFirstNpadId());
result_info.result = 0; result_info.result =
is_success ? ControllerSupportResult::Success : ControllerSupportResult::Cancel;
LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}", LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}",
result_info.player_count, result_info.selected_id, result_info.result); result_info.player_count, result_info.selected_id, result_info.result);

View file

@ -48,6 +48,11 @@ enum class ControllerSupportCaller : u8 {
MaxControllerSupportCaller, MaxControllerSupportCaller,
}; };
enum class ControllerSupportResult : u32 {
Success = 0,
Cancel = 2,
};
struct ControllerSupportArgPrivate { struct ControllerSupportArgPrivate {
u32 arg_private_size{}; u32 arg_private_size{};
u32 arg_size{}; u32 arg_size{};
@ -112,7 +117,7 @@ struct ControllerSupportResultInfo {
s8 player_count{}; s8 player_count{};
INSERT_PADDING_BYTES(3); INSERT_PADDING_BYTES(3);
u32 selected_id{}; u32 selected_id{};
u32 result{}; ControllerSupportResult result{};
}; };
static_assert(sizeof(ControllerSupportResultInfo) == 0xC, static_assert(sizeof(ControllerSupportResultInfo) == 0xC,
"ControllerSupportResultInfo has incorrect size."); "ControllerSupportResultInfo has incorrect size.");
@ -131,7 +136,7 @@ public:
void Execute() override; void Execute() override;
Result RequestExit() override; Result RequestExit() override;
void ConfigurationComplete(); void ConfigurationComplete(bool is_success);
private: private:
const Core::Frontend::ControllerApplet& frontend; const Core::Frontend::ControllerApplet& frontend;

View file

@ -300,7 +300,7 @@ bool QtControllerSelectorDialog::CheckIfParametersMet() {
if (num_connected_players < min_supported_players || if (num_connected_players < min_supported_players ||
num_connected_players > max_supported_players) { num_connected_players > max_supported_players) {
parameters_met = false; parameters_met = false;
ui->buttonBox->setEnabled(parameters_met); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(parameters_met);
return parameters_met; return parameters_met;
} }
@ -327,7 +327,7 @@ bool QtControllerSelectorDialog::CheckIfParametersMet() {
}(); }();
parameters_met = all_controllers_compatible; parameters_met = all_controllers_compatible;
ui->buttonBox->setEnabled(parameters_met); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(parameters_met);
return parameters_met; return parameters_met;
} }
@ -697,8 +697,8 @@ void QtControllerSelector::ReconfigureControllers(
emit MainWindowReconfigureControllers(parameters); emit MainWindowReconfigureControllers(parameters);
} }
void QtControllerSelector::MainWindowReconfigureFinished() { void QtControllerSelector::MainWindowReconfigureFinished(bool is_success) {
if (callback) { if (callback) {
callback(); callback(is_success);
} }
} }

View file

@ -167,7 +167,7 @@ signals:
void MainWindowRequestExit() const; void MainWindowRequestExit() const;
private: private:
void MainWindowReconfigureFinished(); void MainWindowReconfigureFinished(bool is_success);
mutable ReconfigureCallback callback; mutable ReconfigureCallback callback;
}; };

View file

@ -2629,7 +2629,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -2649,5 +2649,11 @@
<receiver>QtControllerSelectorDialog</receiver> <receiver>QtControllerSelectorDialog</receiver>
<slot>accept()</slot> <slot>accept()</slot>
</connection> </connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QtControllerSelectorDialog</receiver>
<slot>reject()</slot>
</connection>
</connections> </connections>
</ui> </ui>

View file

@ -634,15 +634,16 @@ void GMainWindow::ControllerSelectorReconfigureControllers(
Qt::WindowStaysOnTopHint | Qt::WindowTitleHint | Qt::WindowStaysOnTopHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint); Qt::WindowSystemMenuHint);
controller_applet->setWindowModality(Qt::WindowModal); controller_applet->setWindowModality(Qt::WindowModal);
controller_applet->exec(); bool is_success = controller_applet->exec() != QDialog::Rejected;
emit ControllerSelectorReconfigureFinished();
// Don't forget to apply settings. // Don't forget to apply settings.
system->HIDCore().DisableAllControllerConfiguration();
system->ApplySettings(); system->ApplySettings();
config->Save(); config->Save();
UpdateStatusButtons(); UpdateStatusButtons();
emit ControllerSelectorReconfigureFinished(is_success);
} }
void GMainWindow::ControllerSelectorRequestExit() { void GMainWindow::ControllerSelectorRequestExit() {

View file

@ -165,7 +165,7 @@ signals:
void AmiiboSettingsFinished(bool is_success, const std::string& name); void AmiiboSettingsFinished(bool is_success, const std::string& name);
void ControllerSelectorReconfigureFinished(); void ControllerSelectorReconfigureFinished(bool is_success);
void ErrorDisplayFinished(); void ErrorDisplayFinished();