Skip to content

Commit 74d1164

Browse files
committed
Add more video quality settings. Add restore defaults button to GroupOption. Refactor GroupOption configuration.
1 parent 8e87018 commit 74d1164

32 files changed

+283
-73
lines changed

Common/Cpp/Options/GroupOption.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ namespace PokemonAutomation{
2020

2121
struct GroupOption::Data{
2222
const std::string m_label;
23-
const bool m_toggleable;
24-
const bool m_default_enabled;
23+
const EnableMode m_enable_mode;
24+
const bool m_show_restore_defaults_button;
25+
2526
std::atomic<bool> m_enabled;
2627

2728
Data(
2829
std::string label,
29-
bool toggleable,
30-
bool enabled
30+
EnableMode enable_mode,
31+
bool show_restore_defaults_button
3132
)
3233
: m_label(std::move(label))
33-
, m_toggleable(toggleable)
34-
, m_default_enabled(enabled)
35-
, m_enabled(enabled)
34+
, m_enable_mode(enable_mode)
35+
, m_show_restore_defaults_button(show_restore_defaults_button)
3636
{}
3737
};
3838

@@ -41,18 +41,18 @@ GroupOption::~GroupOption() = default;
4141
GroupOption::GroupOption(
4242
std::string label,
4343
LockMode lock_while_program_is_running,
44-
bool toggleable,
45-
bool enabled
44+
EnableMode enable_mode,
45+
bool show_restore_defaults_button
4646
)
4747
: BatchOption(lock_while_program_is_running)
48-
, m_data(CONSTRUCT_TOKEN, std::move(label), toggleable, enabled)
48+
, m_data(CONSTRUCT_TOKEN, std::move(label), enable_mode, show_restore_defaults_button)
4949
{}
5050

5151
const std::string GroupOption::label() const{
5252
return m_data->m_label;
5353
}
5454
bool GroupOption::toggleable() const{
55-
return m_data->m_toggleable;
55+
return m_data->m_enable_mode != EnableMode::ALWAYS_ENABLED;
5656
}
5757
bool GroupOption::enabled() const{
5858
return m_data->m_enabled.load(std::memory_order_relaxed);
@@ -63,13 +63,17 @@ void GroupOption::set_enabled(bool enabled){
6363
on_set_enabled(enabled);
6464
}
6565
}
66+
bool GroupOption::restore_defaults_button_enabled() const{
67+
return m_data->m_show_restore_defaults_button;
68+
}
69+
6670
void GroupOption::load_json(const JsonValue& json){
6771
BatchOption::load_json(json);
6872
const JsonObject* obj = json.to_object();
6973
if (obj == nullptr){
7074
return;
7175
}
72-
if (m_data->m_toggleable){
76+
if (toggleable()){
7377
bool enabled;
7478
if (obj->read_boolean(enabled, "Enabled")){
7579
if (enabled != m_data->m_enabled.exchange(enabled, std::memory_order_relaxed)){
@@ -81,17 +85,19 @@ void GroupOption::load_json(const JsonValue& json){
8185
}
8286
JsonValue GroupOption::to_json() const{
8387
JsonObject obj = std::move(*BatchOption::to_json().to_object());
84-
if (m_data->m_toggleable){
88+
if (toggleable()){
8589
obj["Enabled"] = m_data->m_enabled.load(std::memory_order_relaxed);
8690
}
8791
return obj;
8892
}
8993
void GroupOption::restore_defaults(){
9094
BatchOption::restore_defaults();
91-
bool default_value = m_data->m_default_enabled;
92-
if (default_value != m_data->m_enabled.exchange(default_value, std::memory_order_relaxed)){
93-
report_value_changed(this);
94-
on_set_enabled(default_value);
95+
if (toggleable()){
96+
bool default_value = m_data->m_enable_mode == EnableMode::DEFAULT_ENABLED;
97+
if (default_value != m_data->m_enabled.exchange(default_value, std::memory_order_relaxed)){
98+
report_value_changed(this);
99+
on_set_enabled(default_value);
100+
}
95101
}
96102
}
97103
void GroupOption::on_set_enabled(bool enabled){}

Common/Cpp/Options/GroupOption.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@ namespace PokemonAutomation{
1515

1616
class GroupOption : public BatchOption{
1717
public:
18+
enum class EnableMode{
19+
ALWAYS_ENABLED,
20+
DEFAULT_DISABLED,
21+
DEFAULT_ENABLED,
22+
};
23+
1824
~GroupOption();
1925
GroupOption(
2026
std::string label,
2127
LockMode lock_while_program_is_running,
22-
bool toggleable = false,
23-
bool enabled = true
28+
EnableMode enable_mode = EnableMode::ALWAYS_ENABLED,
29+
bool show_restore_defaults_button = false
2430
);
2531

2632
const std::string label() const;
33+
2734
bool toggleable() const;
2835
bool enabled() const;
2936
void set_enabled(bool enabled);
3037

38+
bool restore_defaults_button_enabled() const;
39+
3140
virtual void load_json(const JsonValue& json) override;
3241
virtual JsonValue to_json() const override;
3342

Common/Qt/Options/GroupWidget.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#include <QVBoxLayout>
88
#include <QLabel>
9+
#include <QPushButton>
910
#include <QGroupBox>
11+
#include <QMessageBox>
1012
//#include "Common/Compiler.h"
1113
#include "GroupWidget.h"
1214

@@ -30,6 +32,7 @@ GroupWidget::GroupWidget(QWidget& parent, GroupOption& value)
3032
: QWidget(&parent)
3133
, ConfigWidget(value, *this)
3234
, m_value(value)
35+
, m_restore_defaults_button(nullptr)
3336
{
3437
QVBoxLayout* layout = new QVBoxLayout(this);
3538
// layout->setAlignment(Qt::AlignTop);
@@ -73,6 +76,26 @@ GroupWidget::GroupWidget(QWidget& parent, GroupOption& value)
7376
m_options_layout->addWidget(&m_options.back()->widget());
7477
}
7578

79+
if (value.restore_defaults_button_enabled()){
80+
m_options.back()->widget().setContentsMargins(5, 5, 5, 5);
81+
m_restore_defaults_button = new QPushButton("Restore Defaults", this);
82+
m_options_layout->addWidget(m_restore_defaults_button);
83+
connect(
84+
m_restore_defaults_button, &QPushButton::clicked,
85+
this, [this](bool on){
86+
QMessageBox::StandardButton button = QMessageBox::question(
87+
nullptr,
88+
"Restore Defaults",
89+
"Are you sure you wish to restore this section back to defaults?",
90+
QMessageBox::Ok | QMessageBox::Cancel
91+
);
92+
if (button == QMessageBox::Ok){
93+
m_value.restore_defaults();
94+
}
95+
}
96+
);
97+
}
98+
7699
connect(
77100
m_group_box, &QGroupBox::toggled,
78101
this, [this](bool on){

Common/Qt/Options/GroupWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class QVBoxLayout;
1515
class QGroupBox;
16+
class QPushButton;
1617

1718
namespace PokemonAutomation{
1819

@@ -37,6 +38,7 @@ class GroupWidget : public QWidget, public ConfigWidget{
3738
QWidget* m_expand_text;
3839
QWidget* m_options_holder;
3940
std::vector<ConfigWidget*> m_options;
41+
QPushButton* m_restore_defaults_button;
4042
bool m_expanded = true;
4143
QVBoxLayout* m_options_layout;
4244
};

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const std::string& ERROR_PATH_SENT = "ErrorReportsSent";
3535

3636

3737
ErrorReportOption::ErrorReportOption()
38-
: GroupOption("Error Reports", LockMode::UNLOCK_WHILE_RUNNING, false)
38+
: GroupOption(
39+
"Error Reports",
40+
LockMode::UNLOCK_WHILE_RUNNING,
41+
GroupOption::EnableMode::ALWAYS_ENABLED, true
42+
)
3943
, DESCRIPTION(
4044
"Send error reports to the " + PROGRAM_NAME + " server to help them resolve issues and improve the program."
4145
)

SerialPrograms/Source/CommonFramework/Notifications/EventNotificationsTable.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ std::vector<std::string> EventNotificationsTable::make_header() const{
4040

4141

4242
EventNotificationsOption::EventNotificationsOption(std::vector<EventNotificationOption*> options)
43-
: GroupOption("Discord Notifications", LockMode::UNLOCK_WHILE_RUNNING, true)
43+
: GroupOption(
44+
"Discord Notifications",
45+
LockMode::UNLOCK_WHILE_RUNNING,
46+
GroupOption::EnableMode::DEFAULT_ENABLED, false
47+
)
4448
, m_table(std::move(options))
4549
{
4650
PA_ADD_OPTION(m_table);

SerialPrograms/Source/CommonFramework/Options/Environment/SleepSuppressOption.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SleepSuppressOptions::SleepSuppressOptions()
3333
: GroupOption(
3434
"Suppress Screensaver/Sleep:",
3535
LockMode::UNLOCK_WHILE_RUNNING,
36-
false, true
36+
GroupOption::EnableMode::ALWAYS_ENABLED, true
3737
)
3838
, IDLE("No Program Running:", SleepSuppress::NONE)
3939
#ifdef PA_ENABLE_SLEEP_SUPPRESS_NO_SLEEP

SerialPrograms/Source/CommonFramework/Recording/StreamHistoryOption.cpp

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
namespace PokemonAutomation{
1111

12-
1312
StreamHistoryOption::StreamHistoryOption()
1413
: GroupOption(
1514
"Stream History",
1615
LockMode::LOCK_WHILE_RUNNING,
17-
true,
1816
IS_BETA_VERSION
17+
? GroupOption::EnableMode::DEFAULT_ENABLED
18+
: GroupOption::EnableMode::DEFAULT_DISABLED,
19+
true
1920
)
2021
, DESCRIPTION(
2122
"Keep a record of the recent video+audio streams. This will allow video capture "
@@ -35,10 +36,44 @@ StreamHistoryOption::StreamHistoryOption()
3536
LockMode::UNLOCK_WHILE_RUNNING,
3637
30
3738
)
39+
, RESOLUTION(
40+
"<b>Resolution:</b>",
41+
{
42+
{Resolution::MATCH_INPUT, "match", "Match Input Resolution"},
43+
{Resolution::FORCE_720p, "720p", "1280 x 720"},
44+
{Resolution::FORCE_1080p, "1080p", "1920 x 1080"},
45+
},
46+
LockMode::UNLOCK_WHILE_RUNNING,
47+
Resolution::MATCH_INPUT
48+
)
49+
, ENCODING_MODE(
50+
"<b>Encoding Mode:</b>",
51+
{
52+
{EncodingMode::FIXED_QUALITY, "fixed-quality", "Fixed Quality"},
53+
{EncodingMode::FIXED_BITRATE, "fixed-bitrate", "Fixed Bit Rate"},
54+
},
55+
LockMode::UNLOCK_WHILE_RUNNING,
56+
EncodingMode::FIXED_QUALITY
57+
)
58+
, VIDEO_QUALITY(
59+
"<b>Video Quality:</b><br>"
60+
"<font color=\"orange\">High quality videos will take more disk space "
61+
"and may exceed the attachment size limit for Discord notifications."
62+
"</font>",
63+
{
64+
{VideoQuality::VERY_LOW, "very-low", "Very Low"},
65+
{VideoQuality::LOW, "low", "Low"},
66+
{VideoQuality::NORMAL, "normal", "Normal"},
67+
{VideoQuality::HIGH, "high", "High"},
68+
{VideoQuality::VERY_HIGH, "very-high", "Very High"},
69+
},
70+
LockMode::UNLOCK_WHILE_RUNNING,
71+
VideoQuality::LOW
72+
)
3873
, VIDEO_BITRATE(
3974
"<b>Video Bit-Rate (kbps):</b><br>"
4075
"Lower = lower quality, smaller file size.<br>"
41-
"Higher = high quality, larger file size.<br><br>"
76+
"Higher = high quality, larger file size.<br>"
4277
"<font color=\"orange\">Large values can exceed the attachment size limit for Discord notifications."
4378
"</font>",
4479
LockMode::UNLOCK_WHILE_RUNNING,
@@ -47,9 +82,35 @@ StreamHistoryOption::StreamHistoryOption()
4782
{
4883
PA_ADD_STATIC(DESCRIPTION);
4984
PA_ADD_OPTION(HISTORY_SECONDS);
85+
PA_ADD_OPTION(RESOLUTION);
86+
PA_ADD_OPTION(ENCODING_MODE);
87+
PA_ADD_OPTION(VIDEO_QUALITY);
5088
PA_ADD_OPTION(VIDEO_BITRATE);
89+
90+
value_changed(this);
91+
92+
ENCODING_MODE.add_listener(*this);
93+
}
94+
StreamHistoryOption::~StreamHistoryOption(){
95+
ENCODING_MODE.remove_listener(*this);
96+
}
97+
98+
void StreamHistoryOption::value_changed(void* object){
99+
switch (ENCODING_MODE){
100+
case EncodingMode::FIXED_QUALITY:
101+
VIDEO_QUALITY.set_visibility(ConfigOptionState::ENABLED);
102+
VIDEO_BITRATE.set_visibility(ConfigOptionState::HIDDEN);
103+
break;
104+
case EncodingMode::FIXED_BITRATE:
105+
VIDEO_QUALITY.set_visibility(ConfigOptionState::HIDDEN);
106+
VIDEO_BITRATE.set_visibility(ConfigOptionState::ENABLED);
107+
break;
108+
}
51109
}
52110

53111

54112

113+
114+
115+
55116
}

SerialPrograms/Source/CommonFramework/Recording/StreamHistoryOption.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,45 @@
99

1010
#include "Common/Cpp/Options/StaticTextOption.h"
1111
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12+
#include "Common/Cpp/Options/EnumDropdownOption.h"
1213
#include "Common/Cpp/Options/GroupOption.h"
1314

1415
namespace PokemonAutomation{
1516

1617

1718

18-
class StreamHistoryOption : public GroupOption{
19+
class StreamHistoryOption : public GroupOption, public ConfigOption::Listener{
1920
public:
2021
StreamHistoryOption();
22+
~StreamHistoryOption();
23+
24+
virtual void value_changed(void* object) override;
2125

2226
StaticTextOption DESCRIPTION;
2327
SimpleIntegerOption<uint16_t> HISTORY_SECONDS;
28+
29+
enum class Resolution{
30+
MATCH_INPUT,
31+
FORCE_720p,
32+
FORCE_1080p,
33+
};
34+
EnumDropdownOption<Resolution> RESOLUTION;
35+
36+
enum class EncodingMode{
37+
FIXED_QUALITY,
38+
FIXED_BITRATE,
39+
};
40+
EnumDropdownOption<EncodingMode> ENCODING_MODE;
41+
42+
43+
enum class VideoQuality{
44+
VERY_LOW,
45+
LOW,
46+
NORMAL,
47+
HIGH,
48+
VERY_HIGH,
49+
};
50+
EnumDropdownOption<VideoQuality> VIDEO_QUALITY;
2451
SimpleIntegerOption<uint32_t> VIDEO_BITRATE;
2552
};
2653

0 commit comments

Comments
 (0)