Skip to content

Commit

Permalink
UI: Fix confirmation logic when changing drivers with a game loaded (#…
Browse files Browse the repository at this point in the history
…1428)

Addresses a minor issue with driver change confirmation logic and the
"Apply" button in the UI.

Previously, if the player changed the video, audio, or input driver with
a title loaded and clicked "No" at the confirmation dialog, the "Apply"
button would be disabled as if the player had changed the driver, when
they had not.

With this PR the "Apply" button state correctly reflects the driver
state and the result of the confirmation modal.

Co-authored-by: jcm <butt@butts.com>
  • Loading branch information
jcm93 and jcm committed Mar 27, 2024
1 parent d5d3d16 commit a29cd2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
30 changes: 18 additions & 12 deletions desktop-ui/settings/drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ auto DriverSettings::construct() -> void {
videoDriverLabel.setText("Driver:");
videoDriverAssign.setText("Apply").setEnabled(false).onActivate([&] {
settings.video.driver = videoDriverList.selected().text();
videoDriverUpdate();
videoDriverAssign.setEnabled(false);
if (videoDriverUpdate()) {
videoDriverAssign.setEnabled(false);
}
});
videoMonitorLabel.setText("Fullscreen monitor:");
videoMonitorList.onChange([&] {
Expand Down Expand Up @@ -48,8 +49,9 @@ auto DriverSettings::construct() -> void {
audioDriverLabel.setText("Driver:");
audioDriverAssign.setText("Apply").setEnabled(false).onActivate([&] {
settings.audio.driver = audioDriverList.selected().text();
audioDriverUpdate();
audioDriverAssign.setEnabled(false);
if (audioDriverUpdate()) {
audioDriverAssign.setEnabled(false);
}
});
audioDeviceLabel.setText("Output device:");
audioDeviceList.onChange([&] {
Expand Down Expand Up @@ -91,8 +93,9 @@ auto DriverSettings::construct() -> void {
inputDriverLabel.setText("Driver:");
inputDriverAssign.setText("Apply").setEnabled(false).onActivate([&] {
settings.input.driver = inputDriverList.selected().text();
inputDriverUpdate();
inputDriverAssign.setEnabled(false);
if (inputDriverUpdate()) {
inputDriverAssign.setEnabled(false);
}
});
inputDefocusLabel.setText("When focus is lost:");
inputDefocusPause.setText("Pause emulation").onActivate([&] {
Expand Down Expand Up @@ -148,13 +151,14 @@ auto DriverSettings::videoRefresh() -> void {
VerticalLayout::resize();
}

auto DriverSettings::videoDriverUpdate() -> void {
auto DriverSettings::videoDriverUpdate() -> bool {
if(emulator && settings.video.driver != "None" && MessageDialog(
"Warning: incompatible drivers may cause this software to crash.\n"
"Are you sure you want to change this driver while a game is loaded?"
).setAlignment(settingsWindow).question() != "Yes") return;
).setAlignment(settingsWindow).question() != "Yes") return false;
program.videoDriverUpdate();
videoRefresh();
return true;
}

auto DriverSettings::audioRefresh() -> void {
Expand Down Expand Up @@ -189,13 +193,14 @@ auto DriverSettings::audioRefresh() -> void {
VerticalLayout::resize();
}

auto DriverSettings::audioDriverUpdate() -> void {
auto DriverSettings::audioDriverUpdate() -> bool {
if(emulator && settings.audio.driver != "None" && MessageDialog(
"Warning: incompatible drivers may cause this software to crash.\n"
"Are you sure you want to change this driver while a game is loaded?"
).setAlignment(settingsWindow).question() != "Yes") return;
).setAlignment(settingsWindow).question() != "Yes") return false;
program.audioDriverUpdate();
audioRefresh();
return true;
}

auto DriverSettings::inputRefresh() -> void {
Expand All @@ -208,11 +213,12 @@ auto DriverSettings::inputRefresh() -> void {
VerticalLayout::resize();
}

auto DriverSettings::inputDriverUpdate() -> void {
auto DriverSettings::inputDriverUpdate() -> bool {
if(emulator && settings.input.driver != "None" && MessageDialog(
"Warning: incompatible drivers may cause this software to crash.\n"
"Are you sure you want to change this driver while a game is loaded?"
).setAlignment(settingsWindow).question() != "Yes") return;
).setAlignment(settingsWindow).question() != "Yes") return false;
program.inputDriverUpdate();
inputRefresh();
return true;
}
8 changes: 4 additions & 4 deletions desktop-ui/settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ struct PathSettings : VerticalLayout {
struct DriverSettings : VerticalLayout {
auto construct() -> void;
auto videoRefresh() -> void;
auto videoDriverUpdate() -> void;
auto videoDriverUpdate() -> bool;
auto audioRefresh() -> void;
auto audioDriverUpdate() -> void;
auto audioDriverUpdate() -> bool;
auto inputRefresh() -> void;
auto inputDriverUpdate() -> void;
auto inputDriverUpdate() -> bool;

Label videoLabel{this, Size{~0, 0}, 5};
HorizontalLayout videoDriverLayout{this, Size{~0, 0}};
Expand Down Expand Up @@ -432,4 +432,4 @@ extern OptionSettings& optionSettings;
extern FirmwareSettings& firmwareSettings;
extern PathSettings& pathSettings;
extern DriverSettings& driverSettings;
extern DebugSettings& debugSettings;
extern DebugSettings& debugSettings;

0 comments on commit a29cd2c

Please sign in to comment.