diff --git a/Common/Cpp/Options/BatchOption.cpp b/Common/Cpp/Options/BatchOption.cpp index 4f90be20fa..a1514daae7 100644 --- a/Common/Cpp/Options/BatchOption.cpp +++ b/Common/Cpp/Options/BatchOption.cpp @@ -29,7 +29,7 @@ struct BatchOption::Data{ BatchOption::~BatchOption() = default; BatchOption::BatchOption(LockMode lock_while_program_is_running, bool horizontal) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, horizontal) {} void BatchOption::add_option(ConfigOption& option, std::string serialization_string){ diff --git a/Common/Cpp/Options/BatchOption.h b/Common/Cpp/Options/BatchOption.h index 40ea5d447f..3895876e1a 100644 --- a/Common/Cpp/Options/BatchOption.h +++ b/Common/Cpp/Options/BatchOption.h @@ -14,7 +14,7 @@ namespace PokemonAutomation{ // A ConfigOption that groups one or more options. -class BatchOption : public ConfigOption{ +class BatchOption : public ConfigOptionImpl{ public: ~BatchOption(); BatchOption(LockMode lock_while_program_is_running, bool horizontal = false); @@ -38,8 +38,6 @@ class BatchOption : public ConfigOption{ virtual void report_program_state(bool program_is_running) override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - bool horizontal() const; FixedLimitVector options() const; diff --git a/Common/Cpp/Options/BooleanCheckBoxOption.cpp b/Common/Cpp/Options/BooleanCheckBoxOption.cpp index 02d780ff22..8d54d44d08 100644 --- a/Common/Cpp/Options/BooleanCheckBoxOption.cpp +++ b/Common/Cpp/Options/BooleanCheckBoxOption.cpp @@ -16,6 +16,8 @@ namespace PokemonAutomation{ + + struct BooleanCheckBoxCell::Data{ const bool m_default; std::atomic m_current; @@ -28,21 +30,21 @@ struct BooleanCheckBoxCell::Data{ BooleanCheckBoxCell::~BooleanCheckBoxCell() = default; BooleanCheckBoxCell::BooleanCheckBoxCell(const BooleanCheckBoxCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_data(CONSTRUCT_TOKEN, x.default_value(), x.current_value()) {} BooleanCheckBoxCell::BooleanCheckBoxCell( LockMode lock_while_running, bool default_value, bool current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, default_value, current_value) {} BooleanCheckBoxCell::BooleanCheckBoxCell( LockMode lock_while_running, bool default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, default_value, default_value) {} @@ -81,7 +83,7 @@ BooleanCheckBoxOption::BooleanCheckBoxOption( LockMode lock_while_running, bool default_value ) - : BooleanCheckBoxCell(lock_while_running, default_value) + : ConfigOptionImpl(lock_while_running, default_value) , m_label(std::move(label)) {} BooleanCheckBoxOption::BooleanCheckBoxOption( @@ -89,7 +91,7 @@ BooleanCheckBoxOption::BooleanCheckBoxOption( LockMode lock_while_running, bool default_value, bool value ) - : BooleanCheckBoxCell(lock_while_running, default_value, value) + : ConfigOptionImpl(lock_while_running, default_value, value) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/BooleanCheckBoxOption.h b/Common/Cpp/Options/BooleanCheckBoxOption.h index 8039c523d0..f9a0b26301 100644 --- a/Common/Cpp/Options/BooleanCheckBoxOption.h +++ b/Common/Cpp/Options/BooleanCheckBoxOption.h @@ -14,7 +14,7 @@ namespace PokemonAutomation{ -class BooleanCheckBoxCell : public ConfigOption{ +class BooleanCheckBoxCell : public ConfigOptionImpl{ public: ~BooleanCheckBoxCell(); BooleanCheckBoxCell(const BooleanCheckBoxCell& x); @@ -23,6 +23,7 @@ class BooleanCheckBoxCell : public ConfigOption{ bool default_value, bool current_value ); + public: BooleanCheckBoxCell( LockMode lock_while_running, @@ -40,7 +41,6 @@ class BooleanCheckBoxCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: struct Data; @@ -50,7 +50,7 @@ class BooleanCheckBoxCell : public ConfigOption{ -class BooleanCheckBoxOption : public BooleanCheckBoxCell{ +class BooleanCheckBoxOption : public ConfigOptionImpl{ public: BooleanCheckBoxOption(const BooleanCheckBoxOption& x) = delete; BooleanCheckBoxOption( @@ -67,7 +67,6 @@ class BooleanCheckBoxOption : public BooleanCheckBoxCell{ const std::string& label() const{ return m_label; } using BooleanCheckBoxCell::operator=; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/BoxFloatOption.cpp b/Common/Cpp/Options/BoxFloatOption.cpp index c7bfe0e782..513a07bed2 100644 --- a/Common/Cpp/Options/BoxFloatOption.cpp +++ b/Common/Cpp/Options/BoxFloatOption.cpp @@ -39,7 +39,7 @@ BoxFloatOption::BoxFloatOption( double default_width, double default_height ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN) { Data& self = *m_data; diff --git a/Common/Cpp/Options/BoxFloatOption.h b/Common/Cpp/Options/BoxFloatOption.h index 25554d04c5..da4c18cb15 100644 --- a/Common/Cpp/Options/BoxFloatOption.h +++ b/Common/Cpp/Options/BoxFloatOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class BoxFloatOption : public ConfigOption{ +class BoxFloatOption : public ConfigOptionImpl{ public: ~BoxFloatOption(); BoxFloatOption( @@ -43,8 +43,6 @@ class BoxFloatOption : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: struct Data; diff --git a/Common/Cpp/Options/ButtonOption.cpp b/Common/Cpp/Options/ButtonOption.cpp index 0fa0749f8e..665b91e9e1 100644 --- a/Common/Cpp/Options/ButtonOption.cpp +++ b/Common/Cpp/Options/ButtonOption.cpp @@ -47,7 +47,7 @@ struct ButtonCell::Data{ ButtonCell::~ButtonCell() = default; ButtonCell::ButtonCell(const ButtonCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_data( CONSTRUCT_TOKEN, x.m_data->m_state, @@ -61,7 +61,7 @@ ButtonCell::ButtonCell( int button_height, int text_size ) - : ConfigOption(LockMode::UNLOCK_WHILE_RUNNING) + : ConfigOptionImpl(LockMode::UNLOCK_WHILE_RUNNING) , m_data(CONSTRUCT_TOKEN, ButtonCell::ENABLED, std::move(text), button_height, text_size) {} ButtonCell::ButtonCell( @@ -70,7 +70,7 @@ ButtonCell::ButtonCell( int button_height, int text_size ) - : ConfigOption(LockMode::UNLOCK_WHILE_RUNNING) + : ConfigOptionImpl(LockMode::UNLOCK_WHILE_RUNNING) , m_data(CONSTRUCT_TOKEN, state, std::move(text), button_height, text_size) {} @@ -145,7 +145,7 @@ ButtonOption::ButtonOption( int button_height, int text_size ) - : ButtonCell(std::move(text), button_height, text_size) + : ConfigOptionImpl(std::move(text), button_height, text_size) , m_data(CONSTRUCT_TOKEN, std::move(label)) {} ButtonOption::ButtonOption( @@ -155,7 +155,7 @@ ButtonOption::ButtonOption( int button_height, int text_size ) - : ButtonCell(state, std::move(text), button_height, text_size) + : ConfigOptionImpl(state, std::move(text), button_height, text_size) , m_data(CONSTRUCT_TOKEN, std::move(label)) {} diff --git a/Common/Cpp/Options/ButtonOption.h b/Common/Cpp/Options/ButtonOption.h index 104eeb6b3d..d4e967ab75 100644 --- a/Common/Cpp/Options/ButtonOption.h +++ b/Common/Cpp/Options/ButtonOption.h @@ -18,13 +18,14 @@ struct ButtonListener{ }; -class ButtonCell : public ConfigOption{ +class ButtonCell : public ConfigOptionImpl{ public: enum Enabled : bool{ DISABLED, ENABLED, }; + public: virtual ~ButtonCell(); ButtonCell(const ButtonCell& x); @@ -45,6 +46,7 @@ class ButtonCell : public ConfigOption{ void add_listener(ButtonListener& listener); void remove_listener(ButtonListener& listener); + public: bool is_enabled() const; void set_enabled(bool enabled); @@ -62,8 +64,6 @@ class ButtonCell : public ConfigOption{ // virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - protected: @@ -73,7 +73,7 @@ class ButtonCell : public ConfigOption{ -class ButtonOption : public ButtonCell{ +class ButtonOption : public ConfigOptionImpl{ public: virtual ~ButtonOption(); ButtonOption(const ButtonOption& x) = delete; @@ -94,8 +94,6 @@ class ButtonOption : public ButtonCell{ std::string label() const; void set_label(std::string label); - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: struct Data; diff --git a/Common/Cpp/Options/CheckboxDropdownOption.cpp b/Common/Cpp/Options/CheckboxDropdownOption.cpp new file mode 100644 index 0000000000..d69473e646 --- /dev/null +++ b/Common/Cpp/Options/CheckboxDropdownOption.cpp @@ -0,0 +1,12 @@ +/* Checkbox Dropdown Option + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CheckboxDropdownOption.h" + +namespace PokemonAutomation{ + + +} diff --git a/Common/Cpp/Options/CheckboxDropdownOption.h b/Common/Cpp/Options/CheckboxDropdownOption.h index e8dcd85cee..7eff36eff3 100644 --- a/Common/Cpp/Options/CheckboxDropdownOption.h +++ b/Common/Cpp/Options/CheckboxDropdownOption.h @@ -19,7 +19,7 @@ template class CheckboxDropdownDatabase; -class CheckboxDropdownBase : public ConfigOption{ +class CheckboxDropdownBase : public ConfigOptionImpl{ public: CheckboxDropdownBase(std::string label) : m_label(std::move(label)) @@ -34,7 +34,6 @@ class CheckboxDropdownBase : public ConfigOption{ virtual void clear_index(size_t index) = 0; virtual void toggle_index(size_t index) = 0; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: std::string m_label; diff --git a/Common/Cpp/Options/ColorOption.cpp b/Common/Cpp/Options/ColorOption.cpp index 8d6a61dce9..fa82944005 100644 --- a/Common/Cpp/Options/ColorOption.cpp +++ b/Common/Cpp/Options/ColorOption.cpp @@ -11,7 +11,7 @@ namespace PokemonAutomation{ ColorCell::ColorCell(const ColorCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_default_value(x.m_default_value) , m_current_value(x) {} @@ -20,7 +20,7 @@ ColorCell::ColorCell( bool has_alpha, uint32_t default_value, uint32_t current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_has_alpha(has_alpha) , m_default_value(default_value) , m_current_value(current_value) diff --git a/Common/Cpp/Options/ColorOption.h b/Common/Cpp/Options/ColorOption.h index 905063cd33..f53ecee0e4 100644 --- a/Common/Cpp/Options/ColorOption.h +++ b/Common/Cpp/Options/ColorOption.h @@ -14,7 +14,7 @@ namespace PokemonAutomation{ -class ColorCell : public ConfigOption{ +class ColorCell : public ConfigOptionImpl{ public: ColorCell(const ColorCell& x); ColorCell( @@ -35,8 +35,6 @@ class ColorCell : public ConfigOption{ virtual JsonValue to_json() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: bool m_has_alpha; diff --git a/Common/Cpp/Options/ConfigOption.cpp b/Common/Cpp/Options/ConfigOption.cpp index 4771c45df6..5fedbd18b0 100644 --- a/Common/Cpp/Options/ConfigOption.cpp +++ b/Common/Cpp/Options/ConfigOption.cpp @@ -132,4 +132,5 @@ void ConfigOption::report_value_changed(void* object){ + } diff --git a/Common/Cpp/Options/ConfigOption.h b/Common/Cpp/Options/ConfigOption.h index c4dcfbff3f..c9ee779967 100644 --- a/Common/Cpp/Options/ConfigOption.h +++ b/Common/Cpp/Options/ConfigOption.h @@ -11,6 +11,7 @@ #include "Common/Compiler.h" #include "Common/Cpp/LifetimeSanitizer.h" #include "Common/Cpp/Containers/Pimpl.h" +#include "Common/Cpp/UiWrapper.h" class QWidget; @@ -137,7 +138,8 @@ class ConfigOption{ public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) = 0; + virtual UiWrapper make_UiComponent(void* params) = 0; + ConfigWidget* make_QtWidget(QWidget& parent); private: struct Data; @@ -149,5 +151,36 @@ class ConfigOption{ + +// +// Helpers for implementations. +// + +template +using ConfigUiFactory = UiWrapper (*)(OptionType& option, void* params); + + +template +class ConfigOptionImpl : public ParentType{ +public: + using ParentType::ParentType; + + virtual UiWrapper make_UiComponent(void* params) override{ + if (m_ui_factory){ + return m_ui_factory(static_cast(*this), params); + } + return UiWrapper(); + } + + static ConfigUiFactory m_ui_factory; +}; + +template +ConfigUiFactory ConfigOptionImpl::m_ui_factory; + + + + + } #endif diff --git a/Common/Cpp/Options/DateOption.cpp b/Common/Cpp/Options/DateOption.cpp index 5a893a3a0c..381836d447 100644 --- a/Common/Cpp/Options/DateOption.cpp +++ b/Common/Cpp/Options/DateOption.cpp @@ -15,7 +15,6 @@ namespace PokemonAutomation{ - bool DateTimeCell::is_valid(const DateTime& date) const{ if (date.year < 0){ return false; @@ -55,7 +54,7 @@ DateTimeCell::DateTimeCell( const DateTime& min_value, const DateTime& max_value, const DateTime& default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_level(level) , m_min_value(min_value) , m_max_value(max_value) @@ -168,7 +167,13 @@ DateTimeOption::DateTimeOption( const DateTime& min_value, const DateTime& max_value, const DateTime& default_value ) - : DateTimeCell(lock_while_running, level, min_value, max_value, default_value) + : ConfigOptionImpl( + lock_while_running, + level, + min_value, + max_value, + default_value + ) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/DateOption.h b/Common/Cpp/Options/DateOption.h index ee44aeecf1..0e79379279 100644 --- a/Common/Cpp/Options/DateOption.h +++ b/Common/Cpp/Options/DateOption.h @@ -15,7 +15,7 @@ namespace PokemonAutomation{ -class DateTimeCell : public ConfigOption{ +class DateTimeCell : public ConfigOptionImpl{ public: enum Level{ DATE, @@ -44,6 +44,7 @@ class DateTimeCell : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; + public: static DateTime from_json(const JsonValue& json); static JsonValue to_json(const DateTime& date); @@ -51,11 +52,11 @@ class DateTimeCell : public ConfigOption{ virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: bool is_valid(const DateTime& date) const; + private: const Level m_level; const DateTime m_min_value; @@ -67,7 +68,7 @@ class DateTimeCell : public ConfigOption{ }; -class DateTimeOption : public DateTimeCell{ +class DateTimeOption : public ConfigOptionImpl{ public: DateTimeOption( std::string label, @@ -79,7 +80,6 @@ class DateTimeOption : public DateTimeCell{ const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/EditableTableOption.cpp b/Common/Cpp/Options/EditableTableOption.cpp index c386225bb6..492712816e 100644 --- a/Common/Cpp/Options/EditableTableOption.cpp +++ b/Common/Cpp/Options/EditableTableOption.cpp @@ -17,6 +17,7 @@ namespace PokemonAutomation{ + //EditableTableRow::EditableTableRow(void*) // : m_parent(nullptr) // , m_index((size_t)0 - 1) @@ -84,7 +85,7 @@ EditableTableOption::EditableTableOption( LockMode lock_while_running, std::vector> default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_label(std::move(label)) , m_enable_saveload(true) , m_default(std::move(default_value)) @@ -97,7 +98,7 @@ EditableTableOption::EditableTableOption( bool enable_saveload, std::vector> default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_label(std::move(label)) , m_enable_saveload(enable_saveload) , m_default(std::move(default_value)) diff --git a/Common/Cpp/Options/EditableTableOption.h b/Common/Cpp/Options/EditableTableOption.h index fb54076970..816460e20e 100644 --- a/Common/Cpp/Options/EditableTableOption.h +++ b/Common/Cpp/Options/EditableTableOption.h @@ -70,7 +70,7 @@ class EditableTableRow{ // This is the table itself. -class EditableTableOption : public ConfigOption{ +class EditableTableOption : public ConfigOptionImpl{ public: EditableTableOption( std::string label, @@ -85,6 +85,7 @@ class EditableTableOption : public ConfigOption{ ); void set_default(std::vector> default_value); + public: const std::string& label() const{ return m_label; } const std::vector>& defaults() const{ @@ -157,6 +158,7 @@ class EditableTableOption : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override final; + public: bool saveload_enabled() const{ return m_enable_saveload; } virtual std::vector make_header() const = 0; @@ -168,8 +170,6 @@ class EditableTableOption : public ConfigOption{ void clone_row(const EditableTableRow& row); void remove_row(EditableTableRow& row); -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/EnumDropdownOption.cpp b/Common/Cpp/Options/EnumDropdownOption.cpp index 570e24bb72..739f35b5c0 100644 --- a/Common/Cpp/Options/EnumDropdownOption.cpp +++ b/Common/Cpp/Options/EnumDropdownOption.cpp @@ -16,6 +16,8 @@ namespace PokemonAutomation{ + + struct IntegerEnumDropdownCell::Data{ const IntegerEnumDropdownDatabase& m_database; const size_t m_default; @@ -33,7 +35,7 @@ struct IntegerEnumDropdownCell::Data{ IntegerEnumDropdownCell::~IntegerEnumDropdownCell() = default; IntegerEnumDropdownCell::IntegerEnumDropdownCell(const IntegerEnumDropdownCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_data(CONSTRUCT_TOKEN, x.database(), x.default_value(), x.current_value()) {} IntegerEnumDropdownCell::IntegerEnumDropdownCell( @@ -41,7 +43,7 @@ IntegerEnumDropdownCell::IntegerEnumDropdownCell( LockMode lock_while_running, size_t default_value, size_t current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, database, default_value, current_value) { if (database.find(default_value) == nullptr){ @@ -56,7 +58,7 @@ IntegerEnumDropdownCell::IntegerEnumDropdownCell( LockMode lock_while_running, size_t default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, database, default_value, default_value) { if (database.find(default_value) == nullptr){ diff --git a/Common/Cpp/Options/EnumDropdownOption.h b/Common/Cpp/Options/EnumDropdownOption.h index eed0a8078b..d029412ddc 100644 --- a/Common/Cpp/Options/EnumDropdownOption.h +++ b/Common/Cpp/Options/EnumDropdownOption.h @@ -20,11 +20,12 @@ namespace PokemonAutomation{ // This is the typeless class that uses an integer for the enum value. -class IntegerEnumDropdownCell : public ConfigOption{ +class IntegerEnumDropdownCell : public ConfigOptionImpl{ public: ~IntegerEnumDropdownCell(); IntegerEnumDropdownCell(const IntegerEnumDropdownCell& x); + public: IntegerEnumDropdownCell( const IntegerEnumDropdownDatabase& database, @@ -59,7 +60,6 @@ class IntegerEnumDropdownCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; @@ -106,7 +106,7 @@ class EnumDropdownCell : public IntegerEnumDropdownCell{ -class IntegerEnumDropdownOption : private IntegerEnumDropdownDatabase, public IntegerEnumDropdownCell{ +class IntegerEnumDropdownOption : private IntegerEnumDropdownDatabase, public ConfigOptionImpl{ public: IntegerEnumDropdownOption(const IntegerEnumDropdownOption& x) = delete; IntegerEnumDropdownOption( @@ -116,7 +116,7 @@ class IntegerEnumDropdownOption : private IntegerEnumDropdownDatabase, public In size_t default_value ) : IntegerEnumDropdownDatabase(nullptr) - , IntegerEnumDropdownCell(database, lock_while_running, default_value) + , ConfigOptionImpl(database, lock_while_running, default_value) , m_label(std::move(label)) {} // you can construct IntegerEnumDropdownDatabase using initializer list: @@ -132,12 +132,12 @@ class IntegerEnumDropdownOption : private IntegerEnumDropdownDatabase, public In size_t default_value ) : IntegerEnumDropdownDatabase(std::move(database)) - , IntegerEnumDropdownCell(*this, lock_while_running, default_value) + , ConfigOptionImpl(*this, lock_while_running, default_value) , m_label(std::move(label)) {} const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; + private: const std::string m_label; diff --git a/Common/Cpp/Options/FixedCodeOption.cpp b/Common/Cpp/Options/FixedCodeOption.cpp index 3072b38be4..398a886505 100644 --- a/Common/Cpp/Options/FixedCodeOption.cpp +++ b/Common/Cpp/Options/FixedCodeOption.cpp @@ -17,6 +17,8 @@ namespace PokemonAutomation{ + + struct FixedCodeOption::Data{ std::string m_label; const size_t m_digits; diff --git a/Common/Cpp/Options/FixedCodeOption.h b/Common/Cpp/Options/FixedCodeOption.h index 32614712a6..8302f9d99e 100644 --- a/Common/Cpp/Options/FixedCodeOption.h +++ b/Common/Cpp/Options/FixedCodeOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class FixedCodeOption : public ConfigOption{ +class FixedCodeOption : public ConfigOptionImpl{ public: ~FixedCodeOption(); FixedCodeOption( @@ -38,7 +38,6 @@ class FixedCodeOption : public ConfigOption{ virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; diff --git a/Common/Cpp/Options/FloatingPointOption.cpp b/Common/Cpp/Options/FloatingPointOption.cpp index d1e3801fd7..1c15820694 100644 --- a/Common/Cpp/Options/FloatingPointOption.cpp +++ b/Common/Cpp/Options/FloatingPointOption.cpp @@ -19,6 +19,8 @@ namespace PokemonAutomation{ + + struct FloatingPointCell::Data{ const double m_min_value; const double m_max_value; @@ -40,7 +42,7 @@ struct FloatingPointCell::Data{ FloatingPointCell::~FloatingPointCell() = default; FloatingPointCell::FloatingPointCell(const FloatingPointCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_data(CONSTRUCT_TOKEN, x.min_value(), x.max_value(), x.default_value(), x) {} FloatingPointCell::FloatingPointCell( @@ -48,7 +50,7 @@ FloatingPointCell::FloatingPointCell( double min_value, double max_value, double default_value, double current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, min_value, max_value, default_value, current_value) {} @@ -59,7 +61,7 @@ FloatingPointCell::FloatingPointCell( double min_value, double max_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, min_value, max_value, default_value, default_value) {} @@ -151,7 +153,12 @@ FloatingPointOption::FloatingPointOption( double min_value, double max_value ) - : FloatingPointCell(lock_while_running, default_value, min_value, max_value) + : ConfigOptionImpl( + lock_while_running, + default_value, + min_value, + max_value + ) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/FloatingPointOption.h b/Common/Cpp/Options/FloatingPointOption.h index ae5fdd6139..5938e2f971 100644 --- a/Common/Cpp/Options/FloatingPointOption.h +++ b/Common/Cpp/Options/FloatingPointOption.h @@ -14,7 +14,7 @@ namespace PokemonAutomation{ -class FloatingPointCell : public ConfigOption{ +class FloatingPointCell : public ConfigOptionImpl{ public: ~FloatingPointCell(); FloatingPointCell(const FloatingPointCell& x); @@ -47,7 +47,6 @@ class FloatingPointCell : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; @@ -55,7 +54,7 @@ class FloatingPointCell : public ConfigOption{ }; -class FloatingPointOption : public FloatingPointCell{ +class FloatingPointOption : public ConfigOptionImpl{ public: FloatingPointOption(const FloatingPointOption& x) = delete; @@ -69,7 +68,6 @@ class FloatingPointOption : public FloatingPointCell{ const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/GroupOption.cpp b/Common/Cpp/Options/GroupOption.cpp index 9d62ff3e34..96ae0f7714 100644 --- a/Common/Cpp/Options/GroupOption.cpp +++ b/Common/Cpp/Options/GroupOption.cpp @@ -5,7 +5,6 @@ */ #include -#include "Common/Compiler.h" #include "Common/Cpp/Containers/Pimpl.tpp" #include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/Json/JsonObject.h" @@ -18,6 +17,7 @@ namespace PokemonAutomation{ + struct GroupOption::Data{ const std::string m_label; const EnableMode m_enable_mode; @@ -45,7 +45,7 @@ GroupOption::GroupOption( EnableMode enable_mode, bool show_restore_defaults_button ) - : BatchOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, std::move(label), enable_mode, show_restore_defaults_button) {} diff --git a/Common/Cpp/Options/GroupOption.h b/Common/Cpp/Options/GroupOption.h index 5cbc177ea7..dab5fc95f9 100644 --- a/Common/Cpp/Options/GroupOption.h +++ b/Common/Cpp/Options/GroupOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class GroupOption : public BatchOption{ +class GroupOption : public ConfigOptionImpl{ public: enum class EnableMode{ ALWAYS_ENABLED, @@ -42,12 +42,12 @@ class GroupOption : public BatchOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; public: // Callbacks virtual void on_set_enabled(bool enabled); + private: struct Data; Pimpl m_data; diff --git a/Common/Cpp/Options/IntegerRangeOption.cpp b/Common/Cpp/Options/IntegerRangeOption.cpp index 4789bf518e..ae547d9e30 100644 --- a/Common/Cpp/Options/IntegerRangeOption.cpp +++ b/Common/Cpp/Options/IntegerRangeOption.cpp @@ -15,8 +15,6 @@ #include "Common/Cpp/Concurrency/SpinLock.h" #include "IntegerRangeOption.h" -#include "Common/Qt/Options/IntegerRangeWidget.h" - //#include //using std::cout; //using std::endl; @@ -25,13 +23,6 @@ namespace PokemonAutomation{ -template -ConfigWidget* IntegerRangeCell::make_QtWidget(QWidget& parent){ - return new IntegerRangeCellWidget(parent, *this); -} - - - template struct IntegerRangeCell::Data{ const Type m_lo_min_value; @@ -85,7 +76,7 @@ template IntegerRangeCell::~IntegerRangeCell() = default; template IntegerRangeCell::IntegerRangeCell(const IntegerRangeCell& x) - : ConfigOption(x) + : ConfigOptionImpl>(x) , m_data( CONSTRUCT_TOKEN, x.lo_min_value(), x.lo_max_value(), x.lo_default_value(), x.lo_current_value(), @@ -98,7 +89,7 @@ IntegerRangeCell::IntegerRangeCell( Type lo_min_value, Type lo_max_value, Type lo_default_value, Type lo_current_value, Type hi_min_value, Type hi_max_value, Type hi_default_value, Type hi_current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data( CONSTRUCT_TOKEN, lo_min_value, lo_max_value, lo_default_value, lo_current_value, @@ -167,7 +158,7 @@ void IntegerRangeCell::set_lo(Type lo){ // need to check for lo. If this condition fails, we were already in a bad // state to begin with. if (current_lo != lo){ - report_value_changed(this); + this->report_value_changed(this); } } template @@ -190,7 +181,7 @@ void IntegerRangeCell::set_hi(Type hi){ // need to check for hi. If this condition fails, we were already in a bad // state to begin with. if (current_hi != hi){ - report_value_changed(this); + this->report_value_changed(this); } } template @@ -214,7 +205,7 @@ void IntegerRangeCell::set(Type lo, Type hi){ } } if (current_lo != lo || current_hi != hi){ - report_value_changed(this); + this->report_value_changed(this); } } diff --git a/Common/Cpp/Options/IntegerRangeOption.h b/Common/Cpp/Options/IntegerRangeOption.h index ce6653df0d..17fb34e23e 100644 --- a/Common/Cpp/Options/IntegerRangeOption.h +++ b/Common/Cpp/Options/IntegerRangeOption.h @@ -16,7 +16,7 @@ namespace PokemonAutomation{ template -class IntegerRangeCell : public ConfigOption{ +class IntegerRangeCell : public ConfigOptionImpl>{ public: ~IntegerRangeCell(); IntegerRangeCell(const IntegerRangeCell& x); @@ -50,8 +50,6 @@ class IntegerRangeCell : public ConfigOption{ // virtual std::string check_validity() const override; virtual void restore_defaults() override; -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: struct Data; @@ -60,6 +58,8 @@ class IntegerRangeCell : public ConfigOption{ + + } #endif diff --git a/Common/Cpp/Options/MacAddressOption.cpp b/Common/Cpp/Options/MacAddressOption.cpp index 8ecdb98868..a63b78d598 100644 --- a/Common/Cpp/Options/MacAddressOption.cpp +++ b/Common/Cpp/Options/MacAddressOption.cpp @@ -4,13 +4,12 @@ * */ +#include #include #include "Common/Cpp/Containers/Pimpl.tpp" #include "Common/Cpp/Json/JsonValue.h" #include "MacAddressOption.h" -#include "Common/Qt/Options/MacAddressWidget.h" - //#include //using std::cout; //using std::endl; @@ -19,11 +18,6 @@ namespace PokemonAutomation{ -ConfigWidget* MacAddressCell::make_QtWidget(QWidget& parent){ - return new MacAddressCellWidget(parent, *this); -} - - std::string write_MAC_address(size_t length, const uint8_t* address){ static const char HEX_DIGITS[] = "0123456789ABCDEF"; @@ -77,7 +71,7 @@ struct MacAddressCell::Data{ MacAddressCell::~MacAddressCell() = default; MacAddressCell::MacAddressCell(const MacAddressCell& x) - : ConfigOption(x) + : ConfigOptionImpl(x) , m_data(CONSTRUCT_TOKEN, x.m_data->m_current.size(), x.m_data->m_current.data()) {} void MacAddressCell::operator=(const MacAddressCell& x){ @@ -98,7 +92,7 @@ MacAddressCell::MacAddressCell( size_t bytes, uint8_t* current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, bytes, current_value) {} diff --git a/Common/Cpp/Options/MacAddressOption.h b/Common/Cpp/Options/MacAddressOption.h index f24e545a1e..ad3a90f7bd 100644 --- a/Common/Cpp/Options/MacAddressOption.h +++ b/Common/Cpp/Options/MacAddressOption.h @@ -19,7 +19,7 @@ std::string write_MAC_address(size_t length, const uint8_t* address); void parse_MAC_address(size_t length, uint8_t* address, const std::string& str); -class MacAddressCell : public ConfigOption{ +class MacAddressCell : public ConfigOptionImpl{ public: ~MacAddressCell(); MacAddressCell(const MacAddressCell& x); @@ -30,6 +30,7 @@ class MacAddressCell : public ConfigOption{ uint8_t* current_value ); + public: size_t bytes() const; std::string to_string() const; @@ -45,8 +46,6 @@ class MacAddressCell : public ConfigOption{ virtual void load_json(const JsonValue& json) override; virtual JsonValue to_json() const override; -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: struct Data; diff --git a/Common/Cpp/Options/PathOption.cpp b/Common/Cpp/Options/PathOption.cpp index 51854c3730..bd6fd2012e 100644 --- a/Common/Cpp/Options/PathOption.cpp +++ b/Common/Cpp/Options/PathOption.cpp @@ -12,6 +12,7 @@ namespace PokemonAutomation{ + struct PathCell::Data{ const std::string m_default; const std::string m_filter_string; @@ -42,7 +43,7 @@ PathCell::PathCell( std::string filter_string, std::string placeholder_text ) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, std::move(default_value), std::move(filter_string), std::move(placeholder_text)) {} @@ -110,7 +111,12 @@ PathOption::PathOption( std::string filter_string, std::string placeholder_text ) - : PathCell(lock_while_program_is_running, default_value, filter_string, placeholder_text) + : ConfigOptionImpl( + lock_while_program_is_running, + default_value, + filter_string, + placeholder_text + ) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/PathOption.h b/Common/Cpp/Options/PathOption.h index 1b352a207f..cff3e0e7af 100644 --- a/Common/Cpp/Options/PathOption.h +++ b/Common/Cpp/Options/PathOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class PathCell : public ConfigOption{ +class PathCell : public ConfigOptionImpl{ public: ~PathCell(); PathCell( @@ -39,18 +39,18 @@ class PathCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: virtual void sanitize(std::string& str){} + private: struct Data; Pimpl m_data; }; -class PathOption : public PathCell{ +class PathOption : public ConfigOptionImpl{ public: PathOption( std::string label, @@ -62,7 +62,6 @@ class PathOption : public PathCell{ const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/RandomCodeOption.cpp b/Common/Cpp/Options/RandomCodeOption.cpp index f2b65ec1d4..fe53fa718f 100644 --- a/Common/Cpp/Options/RandomCodeOption.cpp +++ b/Common/Cpp/Options/RandomCodeOption.cpp @@ -10,7 +10,6 @@ #include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/Json/JsonObject.h" #include "Common/Qt/CodeValidator.h" -#include "Common/Qt/Options/ConfigWidget.h" #include "RandomCodeOption.h" namespace PokemonAutomation{ diff --git a/Common/Cpp/Options/RandomCodeOption.h b/Common/Cpp/Options/RandomCodeOption.h index 65723f79a6..7243736c16 100644 --- a/Common/Cpp/Options/RandomCodeOption.h +++ b/Common/Cpp/Options/RandomCodeOption.h @@ -37,7 +37,7 @@ class RaidCodeOption{ -class RandomCodeOption : public ConfigOption{ +class RandomCodeOption : public ConfigOptionImpl{ public: ~RandomCodeOption(); RandomCodeOption(size_t total_digits); @@ -58,7 +58,6 @@ class RandomCodeOption : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; diff --git a/Common/Cpp/Options/SimpleIntegerOption.cpp b/Common/Cpp/Options/SimpleIntegerOption.cpp index d85cbf0e95..ef77943046 100644 --- a/Common/Cpp/Options/SimpleIntegerOption.cpp +++ b/Common/Cpp/Options/SimpleIntegerOption.cpp @@ -10,24 +10,9 @@ #include "Common/Cpp/Json/JsonValue.h" #include "SimpleIntegerOption.h" -#include "Common/Qt/Options/SimpleIntegerWidget.h" - namespace PokemonAutomation{ - - -template -ConfigWidget* SimpleIntegerCell::make_QtWidget(QWidget& parent){ - return new SimpleIntegerCellWidget(parent, *this); -} -template -ConfigWidget* SimpleIntegerOption::make_QtWidget(QWidget& parent){ - return new SimpleIntegerOptionWidget(parent, *this); -} - - - template struct SimpleIntegerCell::Data{ const Type m_min_value; @@ -50,7 +35,7 @@ template SimpleIntegerCell::~SimpleIntegerCell() = default; template SimpleIntegerCell::SimpleIntegerCell(const SimpleIntegerCell& x) - : ConfigOption(x) + : ConfigOptionImpl>(x) , m_data(CONSTRUCT_TOKEN, x.min_value(), x.max_value(), x.default_value(), x.current_value()) {} template @@ -59,7 +44,7 @@ SimpleIntegerCell::SimpleIntegerCell( Type min_value, Type max_value, Type default_value, Type current_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data(CONSTRUCT_TOKEN, min_value, max_value, default_value, current_value) {} @@ -68,7 +53,7 @@ SimpleIntegerCell::SimpleIntegerCell( LockMode lock_while_running, Type default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data(CONSTRUCT_TOKEN, std::numeric_limits::min(), std::numeric_limits::max(), default_value, default_value) {} template @@ -76,7 +61,7 @@ SimpleIntegerCell::SimpleIntegerCell( LockMode lock_while_running, Type default_value, Type min_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data(CONSTRUCT_TOKEN, min_value, std::numeric_limits::max(), default_value, default_value) {} template @@ -84,7 +69,7 @@ SimpleIntegerCell::SimpleIntegerCell( LockMode lock_while_running, Type default_value, Type min_value, Type max_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data(CONSTRUCT_TOKEN, min_value, max_value, default_value, default_value) {} @@ -118,7 +103,7 @@ std::string SimpleIntegerCell::set(Type x){ return std::string(); } if (x != m_data->m_current.exchange(x, std::memory_order_relaxed)){ - report_value_changed(this); + this->report_value_changed(this); } return std::string(); } @@ -164,7 +149,13 @@ SimpleIntegerOption::SimpleIntegerOption( Type min_value, Type max_value, Type default_value, Type current_value ) - : SimpleIntegerCell(lock_while_running, min_value, max_value, default_value, current_value) + : ConfigOptionImpl, SimpleIntegerCell>( + lock_while_running, + min_value, + max_value, + default_value, + current_value + ) , m_label(std::move(label)) {} template @@ -173,7 +164,10 @@ SimpleIntegerOption::SimpleIntegerOption( LockMode lock_while_running, Type default_value ) - : SimpleIntegerCell(lock_while_running, default_value) + : ConfigOptionImpl, SimpleIntegerCell>( + lock_while_running, + default_value + ) , m_label(std::move(label)) {} template @@ -182,7 +176,11 @@ SimpleIntegerOption::SimpleIntegerOption( LockMode lock_while_running, Type default_value, Type min_value ) - : SimpleIntegerCell(lock_while_running, default_value, min_value) + : ConfigOptionImpl, SimpleIntegerCell>( + lock_while_running, + default_value, + min_value + ) , m_label(std::move(label)) {} template @@ -191,7 +189,12 @@ SimpleIntegerOption::SimpleIntegerOption( LockMode lock_while_running, Type default_value, Type min_value, Type max_value ) - : SimpleIntegerCell(lock_while_running, default_value, min_value, max_value) + : ConfigOptionImpl, SimpleIntegerCell>( + lock_while_running, + default_value, + min_value, + max_value + ) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/SimpleIntegerOption.h b/Common/Cpp/Options/SimpleIntegerOption.h index 484e18cad1..b5b3ad9b33 100644 --- a/Common/Cpp/Options/SimpleIntegerOption.h +++ b/Common/Cpp/Options/SimpleIntegerOption.h @@ -17,7 +17,7 @@ namespace PokemonAutomation{ template -class SimpleIntegerCell : public ConfigOption{ +class SimpleIntegerCell : public ConfigOptionImpl>{ public: ~SimpleIntegerCell(); SimpleIntegerCell(const SimpleIntegerCell& x); @@ -27,6 +27,7 @@ class SimpleIntegerCell : public ConfigOption{ Type default_value, Type current_value ); + public: SimpleIntegerCell( LockMode lock_while_running, @@ -56,8 +57,6 @@ class SimpleIntegerCell : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: struct Data; @@ -67,9 +66,8 @@ class SimpleIntegerCell : public ConfigOption{ - template -class SimpleIntegerOption : public SimpleIntegerCell{ +class SimpleIntegerOption : public ConfigOptionImpl, SimpleIntegerCell>{ public: SimpleIntegerOption(const SimpleIntegerOption& x) = delete; SimpleIntegerOption( @@ -79,6 +77,7 @@ class SimpleIntegerOption : public SimpleIntegerCell{ Type default_value, Type current_value ); + public: SimpleIntegerOption( std::string label, @@ -98,8 +97,6 @@ class SimpleIntegerOption : public SimpleIntegerCell{ const std::string& label() const{ return m_label; } -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; @@ -108,6 +105,12 @@ class SimpleIntegerOption : public SimpleIntegerCell{ + + + + + + } #endif diff --git a/Common/Cpp/Options/StaticTableOption.cpp b/Common/Cpp/Options/StaticTableOption.cpp index 7bbf91e413..0f38d2e21b 100644 --- a/Common/Cpp/Options/StaticTableOption.cpp +++ b/Common/Cpp/Options/StaticTableOption.cpp @@ -19,6 +19,7 @@ namespace PokemonAutomation{ + StaticTableRow::StaticTableRow(std::string slug) : m_slug(std::move(slug)) {} @@ -217,7 +218,7 @@ StaticTableOption::StaticTableOption( LockMode lock_while_program_is_running, bool enable_saveload ) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, std::move(label), enable_saveload) {} void StaticTableOption::add_row(std::unique_ptr row){ diff --git a/Common/Cpp/Options/StaticTableOption.h b/Common/Cpp/Options/StaticTableOption.h index e97cbd7042..1101d8ff0e 100644 --- a/Common/Cpp/Options/StaticTableOption.h +++ b/Common/Cpp/Options/StaticTableOption.h @@ -57,7 +57,7 @@ class StaticTableRow{ // This is the table itself. -class StaticTableOption : public ConfigOption{ +class StaticTableOption : public ConfigOptionImpl{ public: ~StaticTableOption(); StaticTableOption( @@ -91,8 +91,6 @@ class StaticTableOption : public ConfigOption{ bool saveload_enabled() const; virtual std::vector make_header() const = 0; -public: - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; @@ -100,16 +98,6 @@ class StaticTableOption : public ConfigOption{ }; -#if 0 -// Convenience helper class that's type-aware. -template -class StaticTableOption_t : public StaticTableOption{ -public: - using StaticTableOption::StaticTableOption; - - -}; -#endif diff --git a/Common/Cpp/Options/StaticTextOption.cpp b/Common/Cpp/Options/StaticTextOption.cpp index b4a68ee963..c05e58bf31 100644 --- a/Common/Cpp/Options/StaticTextOption.cpp +++ b/Common/Cpp/Options/StaticTextOption.cpp @@ -27,7 +27,7 @@ struct StaticTextOption::Data{ StaticTextOption::~StaticTextOption() = default; StaticTextOption::StaticTextOption(std::string label, bool text_wrapping) - : ConfigOption(LockMode::UNLOCK_WHILE_RUNNING) + : ConfigOptionImpl(LockMode::UNLOCK_WHILE_RUNNING) , m_data(CONSTRUCT_TOKEN, std::move(label), text_wrapping) {} #if 0 diff --git a/Common/Cpp/Options/StaticTextOption.h b/Common/Cpp/Options/StaticTextOption.h index acece933d4..fd85f4357e 100644 --- a/Common/Cpp/Options/StaticTextOption.h +++ b/Common/Cpp/Options/StaticTextOption.h @@ -14,7 +14,7 @@ namespace PokemonAutomation{ -class StaticTextOption : public ConfigOption{ +class StaticTextOption : public ConfigOptionImpl{ public: ~StaticTextOption(); StaticTextOption(std::string label, bool text_wrapping = true); @@ -28,7 +28,6 @@ class StaticTextOption : public ConfigOption{ virtual void restore_defaults() override{} - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; @@ -37,7 +36,7 @@ class StaticTextOption : public ConfigOption{ -class SectionDividerOption : public ConfigOption{ +class SectionDividerOption : public ConfigOptionImpl{ public: ~SectionDividerOption(); SectionDividerOption(std::string label, bool text_wrapping = true); @@ -51,7 +50,6 @@ class SectionDividerOption : public ConfigOption{ virtual void restore_defaults() override{} - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; diff --git a/Common/Cpp/Options/StringOption.cpp b/Common/Cpp/Options/StringOption.cpp index 430d50abd7..58c7a4ee0f 100644 --- a/Common/Cpp/Options/StringOption.cpp +++ b/Common/Cpp/Options/StringOption.cpp @@ -12,6 +12,7 @@ namespace PokemonAutomation{ + struct StringCell::Data{ const bool m_is_password; const std::string m_default; @@ -46,7 +47,7 @@ StringCell::StringCell( std::string placeholder_text, bool signal_all_text_changes ) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, is_password, std::move(default_value), std::move(placeholder_text), signal_all_text_changes) {} @@ -118,7 +119,13 @@ StringOption::StringOption( std::string placeholder_text, bool signal_all_text_changes ) - : StringCell(is_password, lock_while_program_is_running, default_value, placeholder_text, signal_all_text_changes) + : ConfigOptionImpl( + is_password, + lock_while_program_is_running, + default_value, + placeholder_text, + signal_all_text_changes + ) , m_label(std::move(label)) {} diff --git a/Common/Cpp/Options/StringOption.h b/Common/Cpp/Options/StringOption.h index d86c161742..70273dffc5 100644 --- a/Common/Cpp/Options/StringOption.h +++ b/Common/Cpp/Options/StringOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class StringCell : public ConfigOption{ +class StringCell : public ConfigOptionImpl{ public: ~StringCell(); StringCell( @@ -40,18 +40,18 @@ class StringCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; protected: virtual void sanitize(std::string& str){} + private: struct Data; Pimpl m_data; }; -class StringOption : public StringCell{ +class StringOption : public ConfigOptionImpl{ public: StringOption( bool is_password, @@ -64,7 +64,6 @@ class StringOption : public StringCell{ const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; diff --git a/Common/Cpp/Options/TextEditOption.cpp b/Common/Cpp/Options/TextEditOption.cpp index 42682f966d..ba31da475e 100644 --- a/Common/Cpp/Options/TextEditOption.cpp +++ b/Common/Cpp/Options/TextEditOption.cpp @@ -13,6 +13,7 @@ namespace PokemonAutomation{ + struct TextEditOption::Data{ const std::string m_label; const std::string m_default; @@ -63,7 +64,7 @@ TextEditOption::TextEditOption( std::string placeholder_text, bool signal_all_text_changes ) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, std::move(label), std::move(default_value), std::move(placeholder_text), signal_all_text_changes) {} #if 0 diff --git a/Common/Cpp/Options/TextEditOption.h b/Common/Cpp/Options/TextEditOption.h index 246abaf37c..1a3ff09425 100644 --- a/Common/Cpp/Options/TextEditOption.h +++ b/Common/Cpp/Options/TextEditOption.h @@ -13,7 +13,7 @@ namespace PokemonAutomation{ -class TextEditOption : public ConfigOption{ +class TextEditOption : public ConfigOptionImpl{ public: // Listeners for when the user focuses on this box. struct FocusListener{ @@ -47,7 +47,6 @@ class TextEditOption : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; diff --git a/Common/Cpp/Options/TimeDurationOption.cpp b/Common/Cpp/Options/TimeDurationOption.cpp index dc585c00bc..9780d718b7 100644 --- a/Common/Cpp/Options/TimeDurationOption.cpp +++ b/Common/Cpp/Options/TimeDurationOption.cpp @@ -9,7 +9,6 @@ #include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/Containers/Pimpl.tpp" #include "Common/Cpp/Concurrency/SpinLock.h" -#include "Common/Qt/Options/TimeDurationWidget.h" #include "TimeDurationOption.h" //#include @@ -19,6 +18,7 @@ namespace PokemonAutomation{ + template struct TimeDurationCell::Data{ const std::string m_units; @@ -129,7 +129,7 @@ TimeDurationCell::TimeDurationCell( Type min_value, Type max_value, std::string default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data( CONSTRUCT_TOKEN, std::move(units), show_summary, @@ -144,7 +144,7 @@ TimeDurationCell::TimeDurationCell( LockMode lock_while_running, std::string default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data( CONSTRUCT_TOKEN, std::move(units), true, @@ -159,7 +159,7 @@ TimeDurationCell::TimeDurationCell( Type min_value, std::string default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data( CONSTRUCT_TOKEN, std::move(units), true, @@ -175,7 +175,7 @@ TimeDurationCell::TimeDurationCell( Type min_value, Type max_value, std::string default_value ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl>(lock_while_running) , m_data( CONSTRUCT_TOKEN, std::move(units), true, @@ -232,7 +232,7 @@ std::string TimeDurationCell::set(std::string text){ data.m_value = value; data.m_error.clear(); } - report_value_changed(this); + this->report_value_changed(this); return error; } @@ -275,7 +275,7 @@ void TimeDurationCell::load_json(const JsonValue& json){ data.m_current = *str; data.m_error = data.process(data.m_current, data.m_value); } - report_value_changed(this); + this->report_value_changed(this); } template JsonValue TimeDurationCell::to_json() const{ @@ -298,7 +298,7 @@ void TimeDurationCell::restore_defaults(){ data.m_current = data.m_default; data.m_error = data.process(data.m_current, data.m_value); } - report_value_changed(this); + this->report_value_changed(this); } @@ -307,22 +307,6 @@ void TimeDurationCell::restore_defaults(){ - - -template -ConfigWidget* TimeDurationCell::make_QtWidget(QWidget& parent){ - return new TimeDurationCellWidget(parent, *this); -} - -template -ConfigWidget* TimeDurationOption::make_QtWidget(QWidget& parent){ - return new TimeDurationOptionWidget(parent, *this); -} - - - - - template class TimeDurationCell; template class TimeDurationCell; template class TimeDurationOption; @@ -333,5 +317,4 @@ template class TimeDurationOption; - } diff --git a/Common/Cpp/Options/TimeDurationOption.h b/Common/Cpp/Options/TimeDurationOption.h index 0db97e386e..345073ee67 100644 --- a/Common/Cpp/Options/TimeDurationOption.h +++ b/Common/Cpp/Options/TimeDurationOption.h @@ -15,7 +15,7 @@ namespace PokemonAutomation{ template -class TimeDurationCell : public ConfigOption{ +class TimeDurationCell : public ConfigOptionImpl>{ public: ~TimeDurationCell(); TimeDurationCell(const TimeDurationCell& x) = delete; @@ -78,8 +78,6 @@ class TimeDurationCell : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - protected: struct Data; @@ -89,17 +87,18 @@ class TimeDurationCell : public ConfigOption{ template -class TimeDurationOption : public TimeDurationCell{ +class TimeDurationOption : public ConfigOptionImpl, TimeDurationCell>{ public: template TimeDurationOption(std::string label, Args&&... args) - : TimeDurationCell(std::forward(args)...) + : ConfigOptionImpl, TimeDurationCell>( + std::forward(args)... + ) , m_label(std::move(label)) {} const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: const std::string m_label; @@ -109,6 +108,10 @@ class TimeDurationOption : public TimeDurationCell{ + + + + class MillisecondsCell : public TimeDurationCell{ public: template @@ -144,6 +147,5 @@ class MicrosecondsOption : public TimeDurationOption{ - } #endif diff --git a/Common/Cpp/UiWrapper.h b/Common/Cpp/UiWrapper.h new file mode 100644 index 0000000000..a0201f8174 --- /dev/null +++ b/Common/Cpp/UiWrapper.h @@ -0,0 +1,99 @@ +/* UI Wrapper + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_UiWrapper_H +#define PokemonAutomation_UiWrapper_H + +namespace PokemonAutomation{ + + + +class UiComponent{ +public: + UiComponent(const UiComponent& x) = delete; + void operator=(const UiComponent& x) = delete; + + UiComponent() = default; + virtual ~UiComponent() = default; +}; + + + +// Lightweight smart pointer to avoid pulling in . +class UiWrapper{ +public: + UiWrapper() + : m_owns(false) + , m_component(nullptr) + {} + UiWrapper(bool take_ownership, UiComponent* component) + : m_owns(take_ownership) + , m_component(component) + {} + ~UiWrapper(){ + if (m_owns){ + delete m_component; + } + } + + UiWrapper(UiWrapper&& x) + : m_owns(x.m_owns) + , m_component(x.m_component) + { + x.m_component = nullptr; + } + void operator=(UiWrapper&& x){ + if (this == &x){ + return; + } + if (m_owns){ + delete m_component; + } + m_owns = x.m_owns; + m_component = x.m_component; + x.m_component = nullptr; + } + UiWrapper(const UiWrapper& x) = delete; + void operator=(const UiWrapper& x) = delete; + + +public: + operator bool() const{ + return m_component != nullptr; + } + + const UiComponent& operator*() const{ + return *m_component; + } + UiComponent& operator*(){ + return *m_component; + } + + const UiComponent* operator->() const{ + return m_component; + } + UiComponent* operator->(){ + return m_component; + } + + const UiComponent* get() const{ + return m_component; + } + UiComponent* get(){ + return m_component; + } + + +private: + bool m_owns; + UiComponent* m_component; +}; + + + + +} +#endif diff --git a/Common/Qt/Options/BatchWidget.cpp b/Common/Qt/Options/BatchWidget.cpp index 4bdc9a9e86..e97a48fc17 100644 --- a/Common/Qt/Options/BatchWidget.cpp +++ b/Common/Qt/Options/BatchWidget.cpp @@ -11,10 +11,9 @@ namespace PokemonAutomation{ +template class RegisterConfigWidget; + -ConfigWidget* BatchOption::make_QtWidget(QWidget& parent){ - return new BatchWidget(parent, *this); -} @@ -38,7 +37,7 @@ BatchWidget::BatchWidget(QWidget& parent, BatchOption& value) } for (auto& item : value.options()){ - m_options.emplace_back(item->make_QtWidget(parent)); + m_options.emplace_back(ConfigWidget::make_from_option(*item, &parent)); if (value.horizontal()){ m_options.back()->widget().setContentsMargins(3, 0, 3, 0); }else{ diff --git a/Common/Qt/Options/BooleanCheckBoxWidget.cpp b/Common/Qt/Options/BooleanCheckBoxWidget.cpp index 045ab359d9..06f58bd0b5 100644 --- a/Common/Qt/Options/BooleanCheckBoxWidget.cpp +++ b/Common/Qt/Options/BooleanCheckBoxWidget.cpp @@ -13,13 +13,9 @@ namespace PokemonAutomation{ +template class RegisterConfigWidget; +template class RegisterConfigWidget; -ConfigWidget* BooleanCheckBoxCell::make_QtWidget(QWidget& parent){ - return new BooleanCheckBoxCellWidget(parent, *this); -} -ConfigWidget* BooleanCheckBoxOption::make_QtWidget(QWidget& parent){ - return new BooleanCheckBoxOptionWidget(parent, *this); -} diff --git a/Common/Qt/Options/BoxFloatWidget.cpp b/Common/Qt/Options/BoxFloatWidget.cpp index 9db2f7ba40..e3d43da32c 100644 --- a/Common/Qt/Options/BoxFloatWidget.cpp +++ b/Common/Qt/Options/BoxFloatWidget.cpp @@ -17,10 +17,7 @@ namespace PokemonAutomation{ - -ConfigWidget* BoxFloatOption::make_QtWidget(QWidget& parent){ - return new BoxFloatWidget(parent, *this); -} +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/ButtonWidget.cpp b/Common/Qt/Options/ButtonWidget.cpp index 6fb0baee43..f289bdee87 100644 --- a/Common/Qt/Options/ButtonWidget.cpp +++ b/Common/Qt/Options/ButtonWidget.cpp @@ -16,12 +16,10 @@ using std::endl; namespace PokemonAutomation{ -ConfigWidget* ButtonCell::make_QtWidget(QWidget& parent){ - return new ButtonCellWidget(parent, *this); -} -ConfigWidget* ButtonOption::make_QtWidget(QWidget& parent){ - return new ButtonOptionWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; + + ButtonCellWidget::~ButtonCellWidget(){ diff --git a/Common/Qt/Options/CheckboxDropdownWidget.cpp b/Common/Qt/Options/CheckboxDropdownWidget.cpp index 9c4ee129ea..cdce05fdf1 100644 --- a/Common/Qt/Options/CheckboxDropdownWidget.cpp +++ b/Common/Qt/Options/CheckboxDropdownWidget.cpp @@ -9,9 +9,7 @@ namespace PokemonAutomation{ -ConfigWidget* CheckboxDropdownBase::make_QtWidget(QWidget& parent){ - return new CheckboxDropdownCellWidget(parent, *this); -} +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/ColorWidget.cpp b/Common/Qt/Options/ColorWidget.cpp index d86918c5de..6eb1ba5e59 100644 --- a/Common/Qt/Options/ColorWidget.cpp +++ b/Common/Qt/Options/ColorWidget.cpp @@ -12,9 +12,10 @@ namespace PokemonAutomation{ -ConfigWidget* ColorCell::make_QtWidget(QWidget& parent){ - return new ColorCellWidget(parent, *this); -} +template class RegisterConfigWidget; + + + ColorCellWidget::~ColorCellWidget(){ diff --git a/Common/Qt/Options/ConfigWidget.cpp b/Common/Qt/Options/ConfigWidget.cpp index 2ff8652d9c..3522653418 100644 --- a/Common/Qt/Options/ConfigWidget.cpp +++ b/Common/Qt/Options/ConfigWidget.cpp @@ -5,6 +5,7 @@ */ #include +#include "Common/Cpp/Exceptions.h" #include "ConfigWidget.h" //#include @@ -14,6 +15,39 @@ namespace PokemonAutomation{ + +ConfigWidget* ConfigWidget::make_from_option(ConfigOption& option, QWidget* parent){ + ConfigWidget* widget = nullptr; + + // This always returns a widget that is owned by a parent. + // So the pointer can be released here. + UiWrapper wrapper = option.make_UiComponent(parent); + if (wrapper){ + widget = dynamic_cast(wrapper.get()); + } + if (widget){ + return widget; + } + + if (widget == nullptr){ + throw InternalProgramError( + nullptr, + PA_CURRENT_FUNCTION, + std::string("UI component not registered for type: ") + typeid(option).name() + ); + } + + return widget; +} + + +ConfigWidget* ConfigOption::make_QtWidget(QWidget& parent){ + return ConfigWidget::make_from_option(*this, &parent); +} + + + + ConfigWidget::~ConfigWidget(){ m_value.remove_listener(*this); } diff --git a/Common/Qt/Options/ConfigWidget.h b/Common/Qt/Options/ConfigWidget.h index f6da2fa229..d631d9753e 100644 --- a/Common/Qt/Options/ConfigWidget.h +++ b/Common/Qt/Options/ConfigWidget.h @@ -23,7 +23,12 @@ namespace PokemonAutomation{ // ConfigWidget's derived classes need to inherit a QWidget or its derived class // and pass *this as the widget in ConfigWidget(m_valuie, widget) so a ConfigWidget // pointer can get the actual QWidget. -class ConfigWidget : protected ConfigOption::Listener{ +class ConfigWidget : public UiComponent, protected ConfigOption::Listener{ +public: + // Temporary for refactoring. + static ConfigWidget* make_from_option(ConfigOption& option, QWidget* parent); + + public: virtual ~ConfigWidget(); ConfigWidget(ConfigOption& m_value); @@ -45,6 +50,7 @@ class ConfigWidget : protected ConfigOption::Listener{ void update_visibility(bool program_is_running); void update_all(bool program_is_running); + protected: // Overwrite ConfigOption::Listener::on_config_visibility_changed(). // Called when the listened config option's visibility is changed. @@ -56,6 +62,7 @@ class ConfigWidget : protected ConfigOption::Listener{ virtual void on_config_visibility_changed() override; virtual void on_program_state_changed(bool program_is_running) override; + protected: ConfigOption& m_value; QWidget* m_widget = nullptr; @@ -64,5 +71,33 @@ class ConfigWidget : protected ConfigOption::Listener{ + + +// +// Helpers for implementations. +// + +template +class RegisterConfigWidget{ + using ConfigOptionType = typename ConfigWidgetType::ParentOption; + +public: + RegisterConfigWidget(){ + ConfigOptionType::m_ui_factory = [](ConfigOptionType& option, void* params){ + QWidget* parent = (QWidget*)params; + return UiWrapper(parent == nullptr, new ConfigWidgetType(*parent, option)); + }; + } + + static RegisterConfigWidget initializer; +}; + +template +RegisterConfigWidget RegisterConfigWidget::initializer; + + + + + } #endif diff --git a/Common/Qt/Options/DateWidget.cpp b/Common/Qt/Options/DateWidget.cpp index eeda42b60d..2efcb132d8 100644 --- a/Common/Qt/Options/DateWidget.cpp +++ b/Common/Qt/Options/DateWidget.cpp @@ -17,13 +17,8 @@ namespace PokemonAutomation{ - -ConfigWidget* DateTimeCell::make_QtWidget(QWidget& parent){ - return new DateTimeCellWidget(parent, *this); -} -ConfigWidget* DateTimeOption::make_QtWidget(QWidget& parent){ - return new DateTimeOptionWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/EditableTableWidget.cpp b/Common/Qt/Options/EditableTableWidget.cpp index faa7dba053..6580142ce5 100644 --- a/Common/Qt/Options/EditableTableWidget.cpp +++ b/Common/Qt/Options/EditableTableWidget.cpp @@ -22,9 +22,7 @@ namespace PokemonAutomation{ -ConfigWidget* EditableTableOption::make_QtWidget(QWidget& parent){ - return new EditableTableWidget(parent, *this); -} +template class RegisterConfigWidget; @@ -237,7 +235,7 @@ void EditableTableWidget::update_value(){ // QTableWidget for some reason forces the visibility of its // cells to visible. // cout << "make cell widget" << endl; - QWidget* widget = &cells[c]->make_QtWidget(*m_table)->widget(); + QWidget* widget = &ConfigWidget::make_from_option(*cells[c], m_table)->widget(); QWidget* cell_widget = new QWidget(this); QVBoxLayout* layout = new QVBoxLayout(cell_widget); layout->setContentsMargins(0, 0, 0, 0); diff --git a/Common/Qt/Options/EnumDropdownWidget.cpp b/Common/Qt/Options/EnumDropdownWidget.cpp index b2ea90406e..9e58113e50 100644 --- a/Common/Qt/Options/EnumDropdownWidget.cpp +++ b/Common/Qt/Options/EnumDropdownWidget.cpp @@ -13,12 +13,8 @@ namespace PokemonAutomation{ -ConfigWidget* IntegerEnumDropdownCell::make_QtWidget(QWidget& parent){ - return new EnumDropdownCellWidget(parent, *this); -} -ConfigWidget* IntegerEnumDropdownOption::make_QtWidget(QWidget& parent){ - return new EnumDropdownOptionWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/FixedCodeWidget.cpp b/Common/Qt/Options/FixedCodeWidget.cpp index c8bc03f424..6d0add80d7 100644 --- a/Common/Qt/Options/FixedCodeWidget.cpp +++ b/Common/Qt/Options/FixedCodeWidget.cpp @@ -14,9 +14,7 @@ namespace PokemonAutomation{ -ConfigWidget* FixedCodeOption::make_QtWidget(QWidget& parent){ - return new FixedCodeWidget(parent, *this); -} +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/FloatingPointWidget.cpp b/Common/Qt/Options/FloatingPointWidget.cpp index 4444b7bc80..9ffa190ff1 100644 --- a/Common/Qt/Options/FloatingPointWidget.cpp +++ b/Common/Qt/Options/FloatingPointWidget.cpp @@ -17,13 +17,8 @@ namespace PokemonAutomation{ - -ConfigWidget* FloatingPointCell::make_QtWidget(QWidget& parent){ - return new FloatingPointCellWidget(parent, *this, true); -} -ConfigWidget* FloatingPointOption::make_QtWidget(QWidget& parent){ - return new FloatingPointOptionWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/FloatingPointWidget.h b/Common/Qt/Options/FloatingPointWidget.h index 9f48da8eff..dc23b2bcc8 100644 --- a/Common/Qt/Options/FloatingPointWidget.h +++ b/Common/Qt/Options/FloatingPointWidget.h @@ -20,7 +20,7 @@ class FloatingPointCellWidget : public QLineEdit, public ConfigWidget{ public: ~FloatingPointCellWidget(); - FloatingPointCellWidget(QWidget& parent, FloatingPointCell& value, bool sanitize); + FloatingPointCellWidget(QWidget& parent, FloatingPointCell& value, bool sanitize = true); virtual void update_value() override; virtual void on_config_value_changed(void* object) override; diff --git a/Common/Qt/Options/GroupWidget.cpp b/Common/Qt/Options/GroupWidget.cpp index 1c5d8f6eba..bd202409c7 100644 --- a/Common/Qt/Options/GroupWidget.cpp +++ b/Common/Qt/Options/GroupWidget.cpp @@ -19,10 +19,10 @@ namespace PokemonAutomation{ +template class RegisterConfigWidget; + + -ConfigWidget* GroupOption::make_QtWidget(QWidget& parent){ - return new GroupWidget(parent, *this); -} GroupWidget::~GroupWidget(){ @@ -71,7 +71,7 @@ GroupWidget::GroupWidget(QWidget& parent, GroupOption& value) m_options_layout->setContentsMargins(0, 0, 0, 0); for (auto& item : value.options()){ - m_options.emplace_back(item->make_QtWidget(parent)); + m_options.emplace_back(ConfigWidget::make_from_option(*item, &parent)); m_options.back()->widget().setContentsMargins(5, 5, 5, 5); m_options_layout->addWidget(&m_options.back()->widget()); } diff --git a/Common/Qt/Options/IntegerRangeWidget.cpp b/Common/Qt/Options/IntegerRangeWidget.cpp index e9be85b9ac..6f3b1a580b 100644 --- a/Common/Qt/Options/IntegerRangeWidget.cpp +++ b/Common/Qt/Options/IntegerRangeWidget.cpp @@ -88,6 +88,8 @@ void IntegerRangeCellWidget::on_config_value_changed(void* object){ template class IntegerRangeCellWidget; +template class RegisterConfigWidget>; + diff --git a/Common/Qt/Options/MacAddressWidget.cpp b/Common/Qt/Options/MacAddressWidget.cpp index 1085de25e8..7240f7249c 100644 --- a/Common/Qt/Options/MacAddressWidget.cpp +++ b/Common/Qt/Options/MacAddressWidget.cpp @@ -15,6 +15,10 @@ namespace PokemonAutomation{ +template class RegisterConfigWidget; + + + MacAddressCellWidget::~MacAddressCellWidget(){ m_value.remove_listener(*this); } diff --git a/Common/Qt/Options/PathWidget.cpp b/Common/Qt/Options/PathWidget.cpp index 2e1c506a37..69356a74b8 100644 --- a/Common/Qt/Options/PathWidget.cpp +++ b/Common/Qt/Options/PathWidget.cpp @@ -14,13 +14,9 @@ namespace PokemonAutomation{ -ConfigWidget* PathCell::make_QtWidget(QWidget& parent){ - return new PathCellWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; -ConfigWidget* PathOption::make_QtWidget(QWidget& parent){ - return new PathOptionWidget(parent, *this); -} diff --git a/Common/Qt/Options/RandomCodeWidget.cpp b/Common/Qt/Options/RandomCodeWidget.cpp index 957f5f8f4f..e83717f3fd 100644 --- a/Common/Qt/Options/RandomCodeWidget.cpp +++ b/Common/Qt/Options/RandomCodeWidget.cpp @@ -15,10 +15,9 @@ namespace PokemonAutomation{ +template class RegisterConfigWidget; + -ConfigWidget* RandomCodeOption::make_QtWidget(QWidget& parent){ - return new RandomCodeWidget(parent, *this); -} RandomCodeWidget::~RandomCodeWidget(){ diff --git a/Common/Qt/Options/SimpleIntegerWidget.cpp b/Common/Qt/Options/SimpleIntegerWidget.cpp index 7d28b68169..5e2a2ec97f 100644 --- a/Common/Qt/Options/SimpleIntegerWidget.cpp +++ b/Common/Qt/Options/SimpleIntegerWidget.cpp @@ -135,6 +135,25 @@ template class SimpleIntegerOptionWidget; template class SimpleIntegerOptionWidget; template class SimpleIntegerOptionWidget; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; + +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; + + // This is stupid. #ifdef __APPLE__ diff --git a/Common/Qt/Options/StaticTableWidget.cpp b/Common/Qt/Options/StaticTableWidget.cpp index c10ffa6c72..1723524962 100644 --- a/Common/Qt/Options/StaticTableWidget.cpp +++ b/Common/Qt/Options/StaticTableWidget.cpp @@ -22,9 +22,8 @@ using std::endl; namespace PokemonAutomation{ -ConfigWidget* StaticTableOption::make_QtWidget(QWidget& parent){ - return new StaticTableWidget(parent, *this); -} +template class RegisterConfigWidget; + @@ -67,7 +66,10 @@ StaticTableWidget::StaticTableWidget(QWidget& parent, StaticTableOption& value) for (size_t r = 0; r < table.size(); r++){ std::vector cells = table[r]->make_cells(); for (size_t c = 0; c < cells.size(); c++){ - m_table->setCellWidget((int)r, (int)c, &cells[c]->make_QtWidget(*this)->widget()); + m_table->setCellWidget( + (int)r, (int)c, + &ConfigWidget::make_from_option(*cells[c], &parent)->widget() + ); } } diff --git a/Common/Qt/Options/StaticTextWidget.cpp b/Common/Qt/Options/StaticTextWidget.cpp index 79bd0c1471..75fb65c560 100644 --- a/Common/Qt/Options/StaticTextWidget.cpp +++ b/Common/Qt/Options/StaticTextWidget.cpp @@ -12,13 +12,8 @@ namespace PokemonAutomation{ - -ConfigWidget* StaticTextOption::make_QtWidget(QWidget& parent){ - return new StaticTextWidget(parent, *this); -} -ConfigWidget* SectionDividerOption::make_QtWidget(QWidget& parent){ - return new SectionDividerWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/StringWidget.cpp b/Common/Qt/Options/StringWidget.cpp index b22ef7ff38..b209bf4432 100644 --- a/Common/Qt/Options/StringWidget.cpp +++ b/Common/Qt/Options/StringWidget.cpp @@ -16,13 +16,9 @@ namespace PokemonAutomation{ -ConfigWidget* StringCell::make_QtWidget(QWidget& parent){ - return new StringCellWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; -ConfigWidget* StringOption::make_QtWidget(QWidget& parent){ - return new StringOptionWidget(parent, *this); -} diff --git a/Common/Qt/Options/TextEditWidget.cpp b/Common/Qt/Options/TextEditWidget.cpp index 22ed148253..bb17d58942 100644 --- a/Common/Qt/Options/TextEditWidget.cpp +++ b/Common/Qt/Options/TextEditWidget.cpp @@ -17,10 +17,7 @@ namespace PokemonAutomation{ - -ConfigWidget* TextEditOption::make_QtWidget(QWidget& parent){ - return new TextEditWidget(parent, *this); -} +template class RegisterConfigWidget; diff --git a/Common/Qt/Options/TimeDurationWidget.cpp b/Common/Qt/Options/TimeDurationWidget.cpp index f6333e090b..d6dcac4409 100644 --- a/Common/Qt/Options/TimeDurationWidget.cpp +++ b/Common/Qt/Options/TimeDurationWidget.cpp @@ -164,6 +164,11 @@ template class TimeDurationOptionWidget; template class TimeDurationOptionWidget; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; +template class RegisterConfigWidget>; + } diff --git a/SerialPrograms/Source/CommonFramework/Main.cpp b/SerialPrograms/Source/CommonFramework/Main.cpp index 91cd43fd8f..be1fb49e44 100644 --- a/SerialPrograms/Source/CommonFramework/Main.cpp +++ b/SerialPrograms/Source/CommonFramework/Main.cpp @@ -8,6 +8,7 @@ #include "Common/Cpp/Concurrency/FireForgetDispatcher.h" #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/ImageResolution.h" +#include "StaticRegistration.h" #include "CommonFramework/Tools/GlobalThreadPools.h" #include "VideoPipeline/Backends/MediaServicesQt6.h" #include "Globals.h" @@ -159,6 +160,8 @@ int main(int argc, char *argv[]){ set_program_path(argv[0]); #endif + PokemonAutomation::register_all_statics(); + setup_crash_handler(); int ret = run_program(argc, argv); diff --git a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.cpp b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.cpp index 2d4957bd5a..26ce9adea7 100644 --- a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.cpp @@ -9,54 +9,17 @@ #include "Common/Cpp/Options/BooleanCheckBoxOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" #include "Common/Cpp/Options/StringOption.h" -#include "CommonFramework/Logging/Logger.h" #include "CommonFramework/Options/LabelCellOption.h" #include "CommonFramework/Notifications/ProgramNotifications.h" #include "EventNotificationOption.h" -#include -#include -#include "Common/Qt/Options/ConfigWidget.h" - namespace PokemonAutomation{ -class TestButtonWidget : public ConfigWidget{ -public: - TestButtonWidget(QWidget& parent, TestMessageButton& value) - : ConfigWidget(value) - { - QPushButton* button = new QPushButton(&parent); - m_widget = button; - - QFont font; - font.setBold(true); - button->setFont(font); - button->setText("Send Test Message"); - - button->connect( - button, &QPushButton::clicked, - button, [&](bool){ - send_raw_program_notification( - global_logger_tagged(), value.option, - COLOR_GREEN, - ProgramInfo("Test Message"), - "Notification Test", - { - {"Event Type:", value.option.label()}, - } - ); - } - ); - } -}; TestMessageButton::TestMessageButton(EventNotificationOption& p_option) - : ConfigOption(LockMode::UNLOCK_WHILE_RUNNING) + : ConfigOptionImpl(LockMode::UNLOCK_WHILE_RUNNING) , option(p_option) {} -ConfigWidget* TestMessageButton::make_QtWidget(QWidget& parent){ - return new TestButtonWidget(parent, *this); -} diff --git a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.h b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.h index ca12d06baf..b2ad3b5cb7 100644 --- a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.h +++ b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationOption.h @@ -20,10 +20,9 @@ namespace PokemonAutomation{ class EventNotificationOption; -class TestMessageButton : public ConfigOption{ +class TestMessageButton : public ConfigOptionImpl{ public: TestMessageButton(EventNotificationOption& p_option); - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; EventNotificationOption& option; }; diff --git a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.cpp b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.cpp new file mode 100644 index 0000000000..fd3c0f6d8a --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.cpp @@ -0,0 +1,48 @@ +/* Event Notification Option + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Logging/Logger.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "EventNotificationWidget.h" + +namespace PokemonAutomation{ + + +template class RegisterConfigWidget; + + +TestButtonWidget::TestButtonWidget(QWidget& parent, TestMessageButton& value) + : ConfigWidget(value) +{ + QPushButton* button = new QPushButton(&parent); + m_widget = button; + + QFont font; + font.setBold(true); + button->setFont(font); + button->setText("Send Test Message"); + + button->connect( + button, &QPushButton::clicked, + button, [&](bool){ + send_raw_program_notification( + global_logger_tagged(), value.option, + COLOR_GREEN, + ProgramInfo("Test Message"), + "Notification Test", + { + {"Event Type:", value.option.label()}, + } + ); + } + ); +} + + + +} diff --git a/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.h b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.h new file mode 100644 index 0000000000..aff4f868a0 --- /dev/null +++ b/SerialPrograms/Source/CommonFramework/Notifications/EventNotificationWidget.h @@ -0,0 +1,27 @@ +/* Event Notification Option + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_EventNotificationWidget_H +#define PokemonAutomation_EventNotificationWidget_H + +#include "Common/Qt/Options/ConfigWidget.h" +#include "EventNotificationOption.h" + +namespace PokemonAutomation{ + + +class TestButtonWidget : public ConfigWidget{ +public: + using ParentOption = TestMessageButton; + +public: + TestButtonWidget(QWidget& parent, TestMessageButton& value); +}; + + + +} +#endif diff --git a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp index d998c6c78b..66e6eb7416 100644 --- a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.cpp @@ -5,9 +5,7 @@ */ #include "Common/Cpp/Containers/Pimpl.tpp" -#include "Common/Cpp/Concurrency/SpinLock.h" #include "Common/Cpp/Json/JsonValue.h" -#include "Common/Qt/Options/ConfigWidget.h" #include "LabelCellOption.h" //#include @@ -17,6 +15,7 @@ namespace PokemonAutomation{ + struct LabelCellOption::Data{ // mutable SpinLock m_lock; std::string m_text; @@ -60,21 +59,21 @@ LabelCellOption::LabelCellOption( LockMode lock_while_running, std::string text ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, std::move(text)) {} LabelCellOption::LabelCellOption( LockMode lock_while_running, std::string text, const ImageViewRGB32& icon ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, std::move(text), icon) {} LabelCellOption::LabelCellOption( LockMode lock_while_running, std::string text, const ImageViewRGB32& icon, size_t icon_size ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, std::move(text), icon, icon_size) {} //LabelCellOption::LabelCellOption(std::string text, ImageRGB32 icon) diff --git a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h index ca373bade3..f7afe0b27e 100644 --- a/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h +++ b/SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h @@ -17,7 +17,7 @@ namespace PokemonAutomation{ -class LabelCellOption : public ConfigOption{ +class LabelCellOption : public ConfigOptionImpl{ public: ~LabelCellOption(); @@ -50,7 +50,6 @@ class LabelCellOption : public ConfigOption{ virtual void restore_defaults() override{} - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: struct Data; diff --git a/SerialPrograms/Source/CommonFramework/Options/QtWidget/LabelCellWidget.cpp b/SerialPrograms/Source/CommonFramework/Options/QtWidget/LabelCellWidget.cpp index 4786d1dab9..4964284466 100644 --- a/SerialPrograms/Source/CommonFramework/Options/QtWidget/LabelCellWidget.cpp +++ b/SerialPrograms/Source/CommonFramework/Options/QtWidget/LabelCellWidget.cpp @@ -16,10 +16,7 @@ namespace PokemonAutomation{ - -ConfigWidget* LabelCellOption::make_QtWidget(QWidget& parent){ - return new LabelCellWidget(parent, *this); -} +template class RegisterConfigWidget; LabelCellWidget::~LabelCellWidget(){ diff --git a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp index fea4c71118..3fb35887a6 100644 --- a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp +++ b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.cpp @@ -24,7 +24,7 @@ LanguageOCRCell::LanguageOCRCell( LockMode lock_while_running, bool required ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_default(0) , m_current(0) { @@ -120,7 +120,11 @@ LanguageOCROption::LanguageOCROption( LockMode lock_while_running, bool required ) - : LanguageOCRCell(languages, lock_while_running, required) + : ConfigOptionImpl( + languages, + lock_while_running, + required + ) , m_label(std::move(label)) {} diff --git a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h index c63fabca98..c06f16ea3f 100644 --- a/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h +++ b/SerialPrograms/Source/CommonTools/Options/LanguageOCROption.h @@ -17,7 +17,7 @@ namespace PokemonAutomation{ namespace OCR{ -class LanguageOCRCell : public ConfigOption{ +class LanguageOCRCell : public ConfigOptionImpl{ public: LanguageOCRCell( const LanguageSet& languages, @@ -37,8 +37,6 @@ class LanguageOCRCell : public ConfigOption{ virtual std::string check_validity() const override; virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: friend class LanguageOCRCellWidget; @@ -52,7 +50,7 @@ class LanguageOCRCell : public ConfigOption{ -class LanguageOCROption : public LanguageOCRCell{ +class LanguageOCROption : public ConfigOptionImpl{ public: LanguageOCROption( std::string label, @@ -63,8 +61,6 @@ class LanguageOCROption : public LanguageOCRCell{ const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: friend class LanguageOCROptionWidget; diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.cpp b/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.cpp index c9df0bac7b..147d871ec5 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.cpp +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.cpp @@ -18,16 +18,11 @@ //using std::endl; namespace PokemonAutomation{ -namespace OCR{ - +template class RegisterConfigWidget; +template class RegisterConfigWidget; -ConfigWidget* LanguageOCRCell::make_QtWidget(QWidget& parent){ - return new LanguageOCRCellWidget(parent, *this); -} -ConfigWidget* LanguageOCROption::make_QtWidget(QWidget& parent){ - return new LanguageOCROptionWidget(parent, *this); -} +namespace OCR{ diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.h b/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.h index 28118eb0e6..e3e168c217 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.h +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/LanguageOCRWidget.h @@ -19,6 +19,9 @@ namespace OCR{ class LanguageOCRCellWidget : public QWidget, public ConfigWidget{ +public: + using ParentOption = LanguageOCRCell; + public: LanguageOCRCellWidget(QWidget& parent, LanguageOCRCell& value); @@ -36,6 +39,9 @@ class LanguageOCRCellWidget : public QWidget, public ConfigWidget{ class LanguageOCROptionWidget : public QWidget, public ConfigWidget{ +public: + using ParentOption = LanguageOCROption; + public: ~LanguageOCROptionWidget(); LanguageOCROptionWidget(QWidget& parent, LanguageOCROption& value); diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.cpp b/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.cpp index ac15410ce1..bf9761976d 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.cpp +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.cpp @@ -15,22 +15,18 @@ #include #include "ScreenWatchWidget.h" -#include -using std::cout; -using std::endl; +//#include +//using std::cout; +//using std::endl; namespace PokemonAutomation{ -ConfigWidget* ScreenWatchDisplay::make_QtWidget(QWidget& parent){ - return new ScreenWatchWidget(*this, parent); -} -ConfigWidget* ScreenWatchButtons::make_QtWidget(QWidget& parent){ - return new ScreenWatchButtonWidget(m_option, parent); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; -ScreenWatchDisplayWidget::ScreenWatchDisplayWidget(ScreenWatchOption& option, ScreenWatchWidget& parent) +ScreenWatchDisplayWidget::ScreenWatchDisplayWidget(ScreenWatchWidget& parent, ScreenWatchOption& option) : QWidget(&parent) , m_holder(parent) , m_option(option) @@ -81,11 +77,11 @@ void ScreenWatchDisplayWidget::thread_loop(){ } } -ScreenWatchWidget::ScreenWatchWidget(ScreenWatchDisplay& option, QWidget& parent) +ScreenWatchWidget::ScreenWatchWidget(QWidget& parent, ScreenWatchDisplay& option) : WidgetStackFixedAspectRatio(parent, ADJUST_HEIGHT_TO_WIDTH) , ConfigWidget(option, *this) { - m_widget = new ScreenWatchDisplayWidget(option.m_option, *this); + m_widget = new ScreenWatchDisplayWidget(*this, option.m_option); add_widget(*m_widget); m_overlay = new VideoOverlayWidget(*this, option.m_option.overlay()); add_widget(*m_overlay); @@ -175,7 +171,7 @@ class SelectorOverlay : public QDialog{ -ScreenWatchButtonWidget::ScreenWatchButtonWidget(ScreenWatchOption& option, QWidget& parent) +ScreenWatchButtonWidget::ScreenWatchButtonWidget(QWidget& parent, ScreenWatchButtons& option) : QWidget(&parent) , ConfigWidget(option, *this) { @@ -194,13 +190,13 @@ ScreenWatchButtonWidget::ScreenWatchButtonWidget(ScreenWatchOption& option, QWid connect( draw_box, &QPushButton::clicked, this, [&](bool){ - qsizetype index = (qsizetype)option.MONITOR_INDEX; + qsizetype index = (qsizetype)option.m_option.MONITOR_INDEX; auto screens = QGuiApplication::screens(); if (screens.size() <= index){ return; } - SelectorOverlay w(option, *this, *screens[index]); + SelectorOverlay w(option.m_option, *this, *screens[index]); w.exec(); ImageFloatBox box = w.get_box(); @@ -208,20 +204,20 @@ ScreenWatchButtonWidget::ScreenWatchButtonWidget(ScreenWatchOption& option, QWid return; } - option.X.set(box.x); - option.Y.set(box.y); - option.WIDTH.set(box.width); - option.HEIGHT.set(box.height); + option.m_option.X.set(box.x); + option.m_option.Y.set(box.y); + option.m_option.WIDTH.set(box.width); + option.m_option.HEIGHT.set(box.height); } ); connect( reset_button, &QPushButton::clicked, this, [&](bool){ - option.X.set(0.0); - option.Y.set(0.0); - option.WIDTH.set(1.0); - option.HEIGHT.set(1.0); + option.m_option.X.set(0.0); + option.m_option.Y.set(0.0); + option.m_option.WIDTH.set(1.0); + option.m_option.HEIGHT.set(1.0); } ); } diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.h b/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.h index e2b8a4139b..b0fed86c1a 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.h +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/ScreenWatchWidget.h @@ -24,7 +24,7 @@ class ScreenWatchWidget; class ScreenWatchDisplayWidget : public QWidget{ public: - ScreenWatchDisplayWidget(ScreenWatchOption& option, ScreenWatchWidget& parent); + ScreenWatchDisplayWidget(ScreenWatchWidget& parent, ScreenWatchOption& option); ~ScreenWatchDisplayWidget(); void paintEvent(QPaintEvent* event) override; @@ -43,7 +43,10 @@ class ScreenWatchDisplayWidget : public QWidget{ class ScreenWatchWidget : public WidgetStackFixedAspectRatio, public ConfigWidget{ public: - ScreenWatchWidget(ScreenWatchDisplay& option, QWidget& parent); + using ParentOption = ScreenWatchDisplay; + +public: + ScreenWatchWidget(QWidget& parent, ScreenWatchDisplay& option); private: QWidget* m_widget; @@ -52,7 +55,10 @@ class ScreenWatchWidget : public WidgetStackFixedAspectRatio, public ConfigWidge class ScreenWatchButtonWidget : public QWidget, public ConfigWidget{ public: - ScreenWatchButtonWidget(ScreenWatchOption& option, QWidget& parent); + using ParentOption = ScreenWatchButtons; + +public: + ScreenWatchButtonWidget(QWidget& parent, ScreenWatchButtons& option); }; diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.cpp b/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.cpp index 01a4385768..5b42a51e18 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.cpp +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.cpp @@ -13,20 +13,15 @@ #include "CommonFramework/Logging/Logger.h" #include "StringSelectWidget.h" -#include -using std::cout; -using std::endl; +//#include +//using std::cout; +//using std::endl; namespace PokemonAutomation{ - -ConfigWidget* StringSelectCell::make_QtWidget(QWidget& parent){ - return new StringSelectCellWidget(parent, *this); -} -ConfigWidget* StringSelectOption::make_QtWidget(QWidget& parent){ - return new StringSelectOptionWidget(parent, *this); -} +template class RegisterConfigWidget; +template class RegisterConfigWidget; diff --git a/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.h b/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.h index e97469dbe3..2d36f7a715 100644 --- a/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.h +++ b/SerialPrograms/Source/CommonTools/Options/QtWidgets/StringSelectWidget.h @@ -16,6 +16,9 @@ namespace PokemonAutomation{ class StringSelectCellWidget : public NoWheelComboBox, public ConfigWidget{ +public: + using ParentOption = StringSelectCell; + public: ~StringSelectCellWidget(); StringSelectCellWidget(QWidget& parent, StringSelectCell& value); @@ -38,6 +41,9 @@ class StringSelectCellWidget : public NoWheelComboBox, public ConfigWidget{ class StringSelectOptionWidget : public QWidget, public ConfigWidget{ +public: + using ParentOption = StringSelectOption; + public: StringSelectOptionWidget(QWidget& parent, StringSelectOption& value); diff --git a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.cpp b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.cpp index e2da3edf85..5dd325ec0a 100644 --- a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.cpp +++ b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.cpp @@ -29,7 +29,10 @@ ScreenWatchOption::ScreenWatchOption( double default_x, double default_y, double default_width, double default_height ) - : GroupOption(std::move(label), LockMode::UNLOCK_WHILE_RUNNING) + : GroupOption( + std::move(label), + LockMode::UNLOCK_WHILE_RUNNING + ) , MONITOR_INDEX( "Monitor Index: For multi-monitor setups, this lets you choose which monitor to watch.", LockMode::UNLOCK_WHILE_RUNNING, diff --git a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h index 9fcf0ab5de..90fc7eb420 100644 --- a/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h +++ b/SerialPrograms/Source/CommonTools/Options/ScreenWatchOption.h @@ -12,30 +12,30 @@ #include "Common/Cpp/Options/FloatingPointOption.h" #include "CommonFramework/VideoPipeline/VideoOverlaySession.h" +//#include +//using std::cout; +//using std::endl; + namespace PokemonAutomation{ struct VideoSnapshot; class ScreenWatchOption; -class ScreenWatchDisplay : public ConfigOption{ +class ScreenWatchDisplay : public ConfigOptionImpl{ public: ScreenWatchDisplay(ScreenWatchOption& option) : m_option(option) {} - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - ScreenWatchOption& m_option; }; -class ScreenWatchButtons : public ConfigOption{ +class ScreenWatchButtons : public ConfigOptionImpl{ public: ScreenWatchButtons(ScreenWatchOption& option) : m_option(option) {} - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - ScreenWatchOption& m_option; }; diff --git a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp index e657f84eaf..24af414bb1 100644 --- a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp +++ b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.cpp @@ -196,7 +196,7 @@ StringSelectCell::StringSelectCell( LockMode lock_while_running, size_t default_index ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, database, default_index) {} StringSelectCell::StringSelectCell( @@ -204,7 +204,7 @@ StringSelectCell::StringSelectCell( LockMode lock_while_running, const std::string& default_slug ) - : ConfigOption(lock_while_running) + : ConfigOptionImpl(lock_while_running) , m_data(CONSTRUCT_TOKEN, database, default_slug) {} diff --git a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h index 1d476751c1..849ea0fe24 100644 --- a/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h +++ b/SerialPrograms/Source/CommonTools/Options/StringSelectOption.h @@ -80,7 +80,7 @@ bool load_json_to_string_select_database(const JsonValue& json, StringSelectData // Config option that creates a cell where users can select a string from // its dropdown menu. It is best to put this cell in a table widget. -class StringSelectCell : public ConfigOption{ +class StringSelectCell : public ConfigOptionImpl{ public: ~StringSelectCell(); StringSelectCell(const StringSelectCell&) = delete; @@ -123,8 +123,6 @@ class StringSelectCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: struct Data; Pimpl m_data; @@ -135,7 +133,7 @@ class StringSelectCell : public ConfigOption{ // a sring. Different from StringSelectCell which is typically used // in a table, StringSelectOption is considered a standalone option // that comes with its own label. -class StringSelectOption : public StringSelectCell{ +class StringSelectOption : public ConfigOptionImpl{ public: StringSelectOption( std::string label, @@ -143,7 +141,11 @@ class StringSelectOption : public StringSelectCell{ LockMode lock_while_running, size_t default_index ) - : StringSelectCell(database, lock_while_running, default_index) + : ConfigOptionImpl( + database, + lock_while_running, + default_index + ) , m_label(std::move(label)) {} StringSelectOption( @@ -152,12 +154,15 @@ class StringSelectOption : public StringSelectCell{ LockMode lock_while_running, const std::string& default_slug ) - : StringSelectCell(database, lock_while_running, default_slug) + : ConfigOptionImpl( + database, + lock_while_running, + default_slug + ) , m_label(std::move(label)) {} const std::string& label() const{ return m_label; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; private: std::string m_label; diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp index 5479447b1b..291863ddbe 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.cpp @@ -32,7 +32,7 @@ KeyboardHidBindingCell::~KeyboardHidBindingCell(){ } KeyboardHidBindingCell::KeyboardHidBindingCell(LockMode lock_while_program_is_running) - : ConfigOption(lock_while_program_is_running) + : ConfigOptionImpl(lock_while_program_is_running) , m_data(CONSTRUCT_TOKEN, (KeyboardKey)0) {} diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h index 12228f135a..12f45041b8 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingOption.h @@ -16,7 +16,7 @@ namespace PokemonAutomation{ -class KeyboardHidBindingCell : public ConfigOption{ +class KeyboardHidBindingCell : public ConfigOptionImpl{ public: ~KeyboardHidBindingCell(); KeyboardHidBindingCell(LockMode lock_while_program_is_running); @@ -30,8 +30,6 @@ class KeyboardHidBindingCell : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - public: // UI Functions diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.cpp b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.cpp index 6b7111f2f9..0437a93a54 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.cpp +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.cpp @@ -17,10 +17,7 @@ namespace PokemonAutomation{ - -ConfigWidget* KeyboardHidBindingCell::make_QtWidget(QWidget& parent){ - return new KeyboardHidBindingCellWidget(parent, *this); -} +template class RegisterConfigWidget; diff --git a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.h b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.h index c5a4afa652..ba22e4cc58 100644 --- a/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.h +++ b/SerialPrograms/Source/ControllerInput/Keyboard/KeyBindingWidget.h @@ -16,6 +16,9 @@ namespace PokemonAutomation{ class KeyboardHidBindingCellWidget : public QLineEdit, public ConfigWidget{ +public: + using ParentOption = KeyboardHidBindingCell; + public: ~KeyboardHidBindingCellWidget(); KeyboardHidBindingCellWidget(QWidget& parent, KeyboardHidBindingCell& value); diff --git a/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.cpp b/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.cpp index a2465d37de..bf5f50dac3 100644 --- a/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.cpp +++ b/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.cpp @@ -4,9 +4,6 @@ * */ -#include -#include -#include #include "Common/Qt/StringToolsQt.h" //#include "CommonFramework/Globals.h" //#include "CommonFramework/GlobalSettingsPanel.h" @@ -25,7 +22,7 @@ DiscordIntegrationSettingsOption::~DiscordIntegrationSettingsOption(){ this->remove_listener(*this); } DiscordIntegrationSettingsOption::DiscordIntegrationSettingsOption() - : GroupOption( + : ConfigOptionImpl( "Discord Integration Settings", LockMode::LOCK_WHILE_RUNNING, GroupOption::EnableMode::DEFAULT_DISABLED @@ -106,58 +103,6 @@ void DiscordIntegrationSettingsOption::on_config_value_changed([[maybe_unused]] } -class DiscordIntegrationSettingsWidget : public GroupWidget{ -public: - DiscordIntegrationSettingsWidget(QWidget& parent, DiscordIntegrationSettingsOption& value); -}; -ConfigWidget* DiscordIntegrationSettingsOption::make_QtWidget(QWidget& parent){ - return new DiscordIntegrationSettingsWidget(parent, *this); -} - -DiscordIntegrationSettingsWidget::DiscordIntegrationSettingsWidget(QWidget& parent, DiscordIntegrationSettingsOption& value) - : GroupWidget(parent, value) -{ -#ifdef PA_DPP - - QWidget* control_buttons = new QWidget(this); - m_options_layout->insertWidget(0, control_buttons); - - QHBoxLayout* layout = new QHBoxLayout(control_buttons); - layout->setContentsMargins(5, 5, 5, 5); - - QLabel* text = new QLabel("Bot Control:", control_buttons); - layout->addWidget(text, 2); - text->setWordWrap(true); - - QPushButton* button_start = new QPushButton("Start Bot", this); - layout->addWidget(button_start, 1); - - QPushButton* button_stop = new QPushButton("Stop Bot", this); - layout->addWidget(button_stop, 1); - - QFont font = button_start->font(); - font.setBold(true); - button_start->setFont(font); - button_stop->setFont(font); - - connect( - button_start, &QPushButton::clicked, - this, [this, &value](bool){ - DppClient::Client::instance().connect(); - value.on_config_value_changed(this); - } - ); - connect( - button_stop, &QPushButton::clicked, - this, [this, &value](bool){ - DppClient::Client::instance().disconnect(); - value.on_config_value_changed(this); - } - ); - -#endif -} - diff --git a/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.h b/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.h index 4020189462..16b4467812 100644 --- a/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.h +++ b/SerialPrograms/Source/Integrations/DiscordIntegrationSettings.h @@ -19,12 +19,14 @@ namespace PokemonAutomation{ namespace Integration{ -class DiscordIntegrationSettingsOption : public GroupOption, private ConfigOption::Listener{ +class DiscordIntegrationSettingsOption + : public ConfigOptionImpl + , private ConfigOption::Listener +{ public: ~DiscordIntegrationSettingsOption(); DiscordIntegrationSettingsOption(); - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; virtual void on_config_value_changed(void* object) override; BooleanCheckBoxOption run_on_start; diff --git a/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.cpp b/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.cpp new file mode 100644 index 0000000000..cd5e0b0fff --- /dev/null +++ b/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.cpp @@ -0,0 +1,69 @@ +/* Discord Integration Settings + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Integrations/DppIntegration/DppClient.h" +#include "DiscordIntegrationSettingsWidget.h" + +namespace PokemonAutomation{ + +template class RegisterConfigWidget; + +namespace Integration{ + + + +DiscordIntegrationSettingsWidget::DiscordIntegrationSettingsWidget(QWidget& parent, DiscordIntegrationSettingsOption& value) + : GroupWidget(parent, value) +{ +#ifdef PA_DPP + + QWidget* control_buttons = new QWidget(this); + m_options_layout->insertWidget(0, control_buttons); + + QHBoxLayout* layout = new QHBoxLayout(control_buttons); + layout->setContentsMargins(5, 5, 5, 5); + + QLabel* text = new QLabel("Bot Control:", control_buttons); + layout->addWidget(text, 2); + text->setWordWrap(true); + + QPushButton* button_start = new QPushButton("Start Bot", this); + layout->addWidget(button_start, 1); + + QPushButton* button_stop = new QPushButton("Stop Bot", this); + layout->addWidget(button_stop, 1); + + QFont font = button_start->font(); + font.setBold(true); + button_start->setFont(font); + button_stop->setFont(font); + + connect( + button_start, &QPushButton::clicked, + this, [this, &value](bool){ + DppClient::Client::instance().connect(); + value.on_config_value_changed(this); + } + ); + connect( + button_stop, &QPushButton::clicked, + this, [this, &value](bool){ + DppClient::Client::instance().disconnect(); + value.on_config_value_changed(this); + } + ); + +#endif +} + + + + +} +} diff --git a/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.h b/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.h new file mode 100644 index 0000000000..e9b4b4d6f9 --- /dev/null +++ b/SerialPrograms/Source/Integrations/DiscordIntegrationSettingsWidget.h @@ -0,0 +1,31 @@ +/* Discord Integration Settings + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_DiscordIntegrationSettingsWidget_H +#define PokemonAutomation_DiscordIntegrationSettingsWidget_H + +#include "Common/Qt/Options/GroupWidget.h" +#include "DiscordIntegrationSettings.h" + +namespace PokemonAutomation{ +namespace Integration{ + + + +class DiscordIntegrationSettingsWidget : public GroupWidget{ +public: + using ParentOption = DiscordIntegrationSettingsOption; + +public: + DiscordIntegrationSettingsWidget(QWidget& parent, DiscordIntegrationSettingsOption& value); +}; + + + + +} +} +#endif diff --git a/SerialPrograms/Source/Integrations/DiscordSettingsOption.cpp b/SerialPrograms/Source/Integrations/DiscordSettingsOption.cpp index 2785a93fcd..18f01d16f9 100644 --- a/SerialPrograms/Source/Integrations/DiscordSettingsOption.cpp +++ b/SerialPrograms/Source/Integrations/DiscordSettingsOption.cpp @@ -18,7 +18,6 @@ namespace Integration{ - DiscordMessageSettingsOption::DiscordMessageSettingsOption() : BatchOption(LockMode::LOCK_WHILE_RUNNING) , instance_name( @@ -49,16 +48,8 @@ DiscordMessageSettingsOption::DiscordMessageSettingsOption() // PA_ADD_OPTION(message); // } } -class DiscordMessageSettingsOptionUI : public BatchWidget{ -public: - DiscordMessageSettingsOptionUI(QWidget& parent, DiscordMessageSettingsOption& value); -}; -DiscordMessageSettingsOptionUI::DiscordMessageSettingsOptionUI(QWidget& parent, DiscordMessageSettingsOption& value) - : BatchWidget(parent, value) -{} -ConfigWidget* DiscordMessageSettingsOption::make_QtWidget(QWidget& parent){ - return new DiscordMessageSettingsOptionUI(parent, *this); -} + + diff --git a/SerialPrograms/Source/Integrations/DiscordSettingsOption.h b/SerialPrograms/Source/Integrations/DiscordSettingsOption.h index 10f902e629..db96d92dc2 100644 --- a/SerialPrograms/Source/Integrations/DiscordSettingsOption.h +++ b/SerialPrograms/Source/Integrations/DiscordSettingsOption.h @@ -19,7 +19,6 @@ namespace Integration{ class DiscordMessageSettingsOption : public BatchOption{ public: DiscordMessageSettingsOption(); - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; StringOption instance_name; StringOption user_id; diff --git a/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp b/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp index 08e0edc824..25933964f7 100644 --- a/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp +++ b/SerialPrograms/Source/ML/Programs/ML_LabelImagesWidget.cpp @@ -128,23 +128,24 @@ LabelImages_Widget::LabelImages_Widget( // add GPU checkbox row QHBoxLayout* use_gpu_row = new QHBoxLayout(); scroll_layout->addLayout(use_gpu_row); - ConfigWidget* gpu_checkbox_widget = program.USE_GPU_FOR_EMBEDDER_SESSION.make_QtWidget(*scroll_inner); + + ConfigWidget* gpu_checkbox_widget = ConfigWidget::make_from_option(program.USE_GPU_FOR_EMBEDDER_SESSION, scroll_inner); use_gpu_row->addWidget(&gpu_checkbox_widget->widget(), 2); // add Color selection dropdown QHBoxLayout* selected_color_choice_row = new QHBoxLayout(); scroll_layout->addLayout(selected_color_choice_row); - ConfigWidget* selected_color_choice_widget = program.SELECTED_ANNO_COLOR.make_QtWidget(*scroll_inner); + ConfigWidget* selected_color_choice_widget = ConfigWidget::make_from_option(program.SELECTED_ANNO_COLOR, scroll_inner); selected_color_choice_row->addWidget(&selected_color_choice_widget->widget(), 2); QHBoxLayout* unselected_color_choice_row = new QHBoxLayout(); scroll_layout->addLayout(unselected_color_choice_row); - ConfigWidget* unselected_color_choice_widget = program.UNSELECTED_ANNO_COLOR.make_QtWidget(*scroll_inner); + ConfigWidget* unselected_color_choice_widget = ConfigWidget::make_from_option(program.UNSELECTED_ANNO_COLOR, scroll_inner); unselected_color_choice_row->addWidget(&unselected_color_choice_widget->widget(), 2); QHBoxLayout* current_drawn_box_row = new QHBoxLayout(); scroll_layout->addLayout(current_drawn_box_row); - ConfigWidget* current_drawn_box_widget = program.CURRENT_DRAWN_BOX.make_QtWidget(*scroll_inner); + ConfigWidget* current_drawn_box_widget = ConfigWidget::make_from_option(program.CURRENT_DRAWN_BOX, scroll_inner); current_drawn_box_row->addWidget(¤t_drawn_box_widget->widget(), 2); // add compute embedding button @@ -411,4 +412,4 @@ void LabelImages_Widget::on_mouse_move(double x, double y){ } -} \ No newline at end of file +} diff --git a/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.h b/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.h index e388cd40a9..2e96f0f34f 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.h +++ b/SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.h @@ -15,7 +15,7 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ -class FriendCodeListOption : public ConfigOption{ +class FriendCodeListOption : public ConfigOptionImpl{ public: FriendCodeListOption(std::string label, std::vector default_lines); @@ -30,8 +30,6 @@ class FriendCodeListOption : public ConfigOption{ virtual void restore_defaults() override; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - private: friend class FriendCodeListWidget; const std::string m_label; diff --git a/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp b/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp index 053f46523c..7a1bdda7db 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.cpp @@ -10,12 +10,10 @@ #include "NintendoSwitch_FriendCodeListWidget.h" namespace PokemonAutomation{ -namespace NintendoSwitch{ +template class RegisterConfigWidget; -ConfigWidget* FriendCodeListOption::make_QtWidget(QWidget& parent){ - return new FriendCodeListWidget(parent, *this); -} +namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h b/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h index c2d269e1ac..fb06285d1c 100644 --- a/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h +++ b/SerialPrograms/Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h @@ -17,6 +17,9 @@ namespace NintendoSwitch{ class FriendCodeListWidget : public QWidget, public ConfigWidget{ +public: + using ParentOption = FriendCodeListOption; + public: ~FriendCodeListWidget(); FriendCodeListWidget(QWidget& parent, FriendCodeListOption& value); diff --git a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp index e92f28fe60..4f2b2dc7ee 100644 --- a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp +++ b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.cpp @@ -350,11 +350,8 @@ std::vector> CustomPathTable::make_defaults(){ - - - CustomPathTableFromJubilife::CustomPathTableFromJubilife() - : BatchOption(LockMode::LOCK_WHILE_RUNNING) + : ConfigOptionImpl(LockMode::LOCK_WHILE_RUNNING) // : PATH( // "Custom Path Table:
" // "Set a sequence of actions to navigate the map. By default, the shiny detected behavior is \"Enroute Shiny Action\".
" @@ -367,77 +364,8 @@ CustomPathTableFromJubilife::CustomPathTableFromJubilife() } -class CustomPathTableWidget : public QWidget, public ConfigWidget{ -public: - CustomPathTableWidget(QWidget& parent, CustomPathTableFromJubilife& value) - : QWidget(&parent) - , ConfigWidget(value, *this) - { - // m_table_widget is class EditableTableWidget : public EditableTableBaseWidget, public ConfigWidget - // EditableTableBaseWidget inherits QWidget. - // Since it's a QWidget, we don't need to care about its memory ownership after its parent is set (as `this`). - - m_travel_location = value.TRAVEL_LOCATION.make_QtWidget(*this); - m_table_widget = value.PATH.make_QtWidget(*this); - - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(&m_travel_location->widget()); - layout->addWidget(&m_table_widget->widget()); - - QHBoxLayout* button_layout = new QHBoxLayout(); - button_layout->setContentsMargins(0, 0, 0, 0); - layout->addLayout(button_layout); - auto load_button = new QPushButton("Load Path", this); - button_layout->addWidget(load_button, 1); - auto save_button = new QPushButton("Save Path", this); - button_layout->addWidget(save_button, 1); - button_layout->addStretch(2); - - connect(load_button, &QPushButton::clicked, this, [&value, this](bool){ - std::string path = QFileDialog::getOpenFileName(this, tr("Open option file"), ".", "*.json").toStdString(); - std::cout << "Load CustomPathTableFromJubilife from " << path << std::endl; - if (path.empty()){ - return; - } - JsonValue json = load_json_file(path); - JsonObject& root = json.to_object_throw(path); - JsonValue& obj = root.get_value_throw("CUSTOM_PATH_TABLE", path); - value.load_json(obj); - if (m_table_widget == nullptr){ - QMessageBox box; - box.critical(nullptr, "Error", "Internal code error, cannot convert to EditableTableBaseWidget."); - return; - } -// m_travel_location->update(); -// m_table_widget->update(); - }); - - connect(save_button, &QPushButton::clicked, this, [&value, this](bool){ - std::string path = QFileDialog::getSaveFileName(this, tr("Open option file"), ".", "*.json").toStdString(); - std::cout << "Save CustomPathTableFromJubilife from " << path << std::endl; - if (path.size() > 0){ - try{ - JsonObject root; - root["CUSTOM_PATH_TABLE"] = value.to_json(); - root.dump(path); - }catch (FileException&){ - QMessageBox box; - box.critical(nullptr, "Error", QString::fromStdString("Failed to save to file: " + path)); - return; - } - } - }); - } -private: - ConfigWidget* m_travel_location = nullptr; - ConfigWidget* m_table_widget = nullptr; -}; -ConfigWidget* CustomPathTableFromJubilife::make_QtWidget(QWidget& parent){ - return new CustomPathTableWidget(parent, *this); -} } diff --git a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h index 8760a42dec..f44961313d 100644 --- a/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h +++ b/SerialPrograms/Source/PokemonLA/Options/PokemonLA_CustomPathTable.h @@ -108,14 +108,12 @@ class CustomPathTable : public EditableTableOption_t{ // A program option to build a custom path to navigate the map -class CustomPathTableFromJubilife : public BatchOption{ +class CustomPathTableFromJubilife : public ConfigOptionImpl{ public: CustomPathTableFromJubilife(); const WildTravelLocationOption& travel_location() const{ return TRAVEL_LOCATION; } - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - public: friend class CustomPathTableWidget; diff --git a/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.cpp b/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.cpp new file mode 100644 index 0000000000..bb364a7066 --- /dev/null +++ b/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.cpp @@ -0,0 +1,91 @@ +/* Custom Path Table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Json/JsonValue.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "PokemonLA_CustomPathTableWidget.h" + +namespace PokemonAutomation{ + +template class RegisterConfigWidget; + +namespace NintendoSwitch{ +namespace PokemonLA{ + + +CustomPathTableWidget::CustomPathTableWidget(QWidget& parent, CustomPathTableFromJubilife& value) + : QWidget(&parent) + , ConfigWidget(value, *this) +{ + // m_table_widget is class EditableTableWidget : public EditableTableBaseWidget, public ConfigWidget + // EditableTableBaseWidget inherits QWidget. + // Since it's a QWidget, we don't need to care about its memory ownership after its parent is set (as `this`). + + m_travel_location = value.TRAVEL_LOCATION.make_QtWidget(*this); + m_table_widget = value.PATH.make_QtWidget(*this); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(&m_travel_location->widget()); + layout->addWidget(&m_table_widget->widget()); + + QHBoxLayout* button_layout = new QHBoxLayout(); + button_layout->setContentsMargins(0, 0, 0, 0); + layout->addLayout(button_layout); + auto load_button = new QPushButton("Load Path", this); + button_layout->addWidget(load_button, 1); + auto save_button = new QPushButton("Save Path", this); + button_layout->addWidget(save_button, 1); + button_layout->addStretch(2); + + connect(load_button, &QPushButton::clicked, this, [&value, this](bool){ + std::string path = QFileDialog::getOpenFileName(this, tr("Open option file"), ".", "*.json").toStdString(); + std::cout << "Load CustomPathTableFromJubilife from " << path << std::endl; + if (path.empty()){ + return; + } + JsonValue json = load_json_file(path); + JsonObject& root = json.to_object_throw(path); + JsonValue& obj = root.get_value_throw("CUSTOM_PATH_TABLE", path); + value.load_json(obj); + if (m_table_widget == nullptr){ + QMessageBox box; + box.critical(nullptr, "Error", "Internal code error, cannot convert to EditableTableBaseWidget."); + return; + } +// m_travel_location->update(); +// m_table_widget->update(); + }); + + connect(save_button, &QPushButton::clicked, this, [&value, this](bool){ + std::string path = QFileDialog::getSaveFileName(this, tr("Open option file"), ".", "*.json").toStdString(); + std::cout << "Save CustomPathTableFromJubilife from " << path << std::endl; + if (path.size() > 0){ + try{ + JsonObject root; + root["CUSTOM_PATH_TABLE"] = value.to_json(); + root.dump(path); + }catch (FileException&){ + QMessageBox box; + box.critical(nullptr, "Error", QString::fromStdString("Failed to save to file: " + path)); + return; + } + } + }); +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h b/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h new file mode 100644 index 0000000000..6d318987ec --- /dev/null +++ b/SerialPrograms/Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h @@ -0,0 +1,37 @@ +/* Custom Path Table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLA_CustomPathTableTableWidget_H +#define PokemonAutomation_PokemonLA_CustomPathTableTableWidget_H + +#include +#include "Common/Qt/Options/ConfigWidget.h" +#include "PokemonLA/Options/PokemonLA_CustomPathTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLA{ + + + +class CustomPathTableWidget : public QWidget, public ConfigWidget{ +public: + using ParentOption = CustomPathTableFromJubilife; + +public: + CustomPathTableWidget(QWidget& parent, CustomPathTableFromJubilife& value); + +private: + ConfigWidget* m_travel_location = nullptr; + ConfigWidget* m_table_widget = nullptr; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.cpp b/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.cpp index e2552534c7..495a740199 100644 --- a/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.cpp +++ b/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.cpp @@ -4,7 +4,6 @@ * */ -#include "Common/Cpp/Json/JsonValue.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" #include "PokemonSwSh/Commands/PokemonSwSh_Commands_DateSpam.h" #include "PokemonSwSh_DateToucher.h" @@ -27,7 +26,7 @@ TimeRollbackHoursOption::TimeRollbackHoursOption() TouchDateIntervalOption::TouchDateIntervalOption() - : m_hours( + : SimpleIntegerOption( "Rollover Prevention:
Prevent a date-skip by touching the date every this many hours. If set to zero, this feature is disabled.", LockMode::LOCK_WHILE_RUNNING, 4, 0, 11 @@ -37,29 +36,14 @@ TouchDateIntervalOption::TouchDateIntervalOption() } -void TouchDateIntervalOption::load_json(const JsonValue& json){ - m_hours.load_json(json); -} -JsonValue TouchDateIntervalOption::to_json() const{ - return m_hours.to_json(); -} -std::string TouchDateIntervalOption::check_validity() const{ - return m_hours.check_validity(); -} -void TouchDateIntervalOption::restore_defaults(){ - m_hours.restore_defaults(); -} void TouchDateIntervalOption::reset_state(){ WriteSpinLock lg(m_lock); m_last_touch = WallClock::min(); } -ConfigWidget* TouchDateIntervalOption::make_QtWidget(QWidget& parent){ - return m_hours.make_QtWidget(parent); -} bool TouchDateIntervalOption::ok_to_touch_now(){ - uint8_t hours = m_hours; + uint8_t hours = *this; if (hours == 0){ return false; } diff --git a/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.h b/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.h index c03f77e946..fc8a707b50 100644 --- a/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.h +++ b/SerialPrograms/Source/PokemonSwSh/Options/PokemonSwSh_DateToucher.h @@ -22,27 +22,16 @@ class TimeRollbackHoursOption : public SimpleIntegerOption{ TimeRollbackHoursOption(); }; -class TouchDateIntervalOption : public ConfigOption{ +class TouchDateIntervalOption : public SimpleIntegerOption{ public: TouchDateIntervalOption(); - virtual void load_json(const JsonValue& json) override; - virtual JsonValue to_json() const override; - - // Returns error message if invalid. Otherwise returns empty string. - virtual std::string check_validity() const override; - - virtual void restore_defaults() override; virtual void reset_state() override final; - virtual ConfigWidget* make_QtWidget(QWidget& parent) override; - bool ok_to_touch_now(); void touch_now_from_home_if_needed(ConsoleHandle& console, ProControllerContext& context); private: - SimpleIntegerOption m_hours; - SpinLock m_lock; WallClock m_last_touch; }; diff --git a/SerialPrograms/Source/StaticRegistration.h b/SerialPrograms/Source/StaticRegistration.h new file mode 100644 index 0000000000..978c4cc7ed --- /dev/null +++ b/SerialPrograms/Source/StaticRegistration.h @@ -0,0 +1,19 @@ +/* Static Registration + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_StaticRegistration_H +#define PokemonAutomation_StaticRegistration_H + +namespace PokemonAutomation{ + + + +void register_all_statics(); + + + +} +#endif diff --git a/SerialPrograms/Source/StaticRegistrationQt.cpp b/SerialPrograms/Source/StaticRegistrationQt.cpp new file mode 100644 index 0000000000..0562a18777 --- /dev/null +++ b/SerialPrograms/Source/StaticRegistrationQt.cpp @@ -0,0 +1,139 @@ +/* Static Registration + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonTools/Options/QtWidgets/ScreenWatchWidget.h" +#include "StaticRegistration.h" + +// Basic Options +#include "Common/Qt/Options/BatchWidget.h" +#include "Common/Qt/Options/BooleanCheckBoxWidget.h" +#include "Common/Qt/Options/BoxFloatWidget.h" +#include "Common/Qt/Options/ButtonWidget.h" +#include "Common/Qt/Options/CheckboxDropdownWidget.h" +#include "Common/Qt/Options/ColorWidget.h" +//#include "Common/Qt/Options/ConfigWidget.h" +#include "Common/Qt/Options/DateWidget.h" +#include "Common/Qt/Options/EditableTableWidget.h" +#include "Common/Qt/Options/EnumDropdownWidget.h" +#include "Common/Qt/Options/FixedCodeWidget.h" +#include "Common/Qt/Options/FloatingPointWidget.h" +#include "Common/Qt/Options/GroupWidget.h" +#include "Common/Qt/Options/IntegerRangeWidget.h" +#include "Common/Qt/Options/MacAddressWidget.h" +#include "Common/Qt/Options/PathWidget.h" +#include "Common/Qt/Options/RandomCodeWidget.h" +#include "Common/Qt/Options/SimpleIntegerWidget.h" +#include "Common/Qt/Options/StaticTableWidget.h" +#include "Common/Qt/Options/StaticTextWidget.h" +#include "Common/Qt/Options/StringWidget.h" +#include "Common/Qt/Options/TextEditWidget.h" +#include "Common/Qt/Options/TimeDurationWidget.h" + +// Common Framework +#include "CommonFramework/Options/QtWidget/LabelCellWidget.h" +#include "CommonFramework/Notifications/EventNotificationWidget.h" + +// Integrations +#include "Integrations/DiscordIntegrationSettingsWidget.h" + +// Common Tools +#include "CommonTools/Options/QtWidgets/StringSelectWidget.h" +#include "CommonTools/Options/QtWidgets/ScreenWatchWidget.h" +#include "CommonTools/Options/QtWidgets/LanguageOCRWidget.h" + +// Controller Input +#include "ControllerInput/Keyboard/KeyBindingWidget.h" + +// Nintendo Switch +#include "NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h" + +// Pokemon LA +#include "PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h" + +namespace PokemonAutomation{ + + + +void register_all_statics(){ + // Basic Options + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget>(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + RegisterConfigWidget>(); + + // Common Framework + RegisterConfigWidget(); + RegisterConfigWidget(); + + // Integrations + RegisterConfigWidget(); + + // Common Tools + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + RegisterConfigWidget(); + + // Controller Input + RegisterConfigWidget(); + + // Nintendo Switch + RegisterConfigWidget(); + + // Pokemon LA + RegisterConfigWidget(); +} + + + + +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 92b1bf6e5d..9041e6bfdb 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -106,6 +106,7 @@ file(GLOB LIBRARY_SOURCES ../Common/Cpp/Options/ButtonOption.cpp ../Common/Cpp/Options/ButtonOption.h ../Common/Cpp/Options/CheckboxDropdownDatabase.h + ../Common/Cpp/Options/CheckboxDropdownOption.cpp ../Common/Cpp/Options/CheckboxDropdownOption.h ../Common/Cpp/Options/CheckboxDropdownOption.tpp ../Common/Cpp/Options/ColorOption.cpp @@ -178,6 +179,7 @@ file(GLOB LIBRARY_SOURCES ../Common/Cpp/StringTools.h ../Common/Cpp/Time.cpp ../Common/Cpp/Time.h + ../Common/Cpp/UiWrapper.h ../Common/Cpp/Unicode.cpp ../Common/Cpp/Unicode.h ../Common/Cpp/ValueDebouncer.h @@ -367,6 +369,8 @@ file(GLOB LIBRARY_SOURCES Source/CommonFramework/Notifications/EventNotificationOption.h Source/CommonFramework/Notifications/EventNotificationsTable.cpp Source/CommonFramework/Notifications/EventNotificationsTable.h + Source/CommonFramework/Notifications/EventNotificationWidget.cpp + Source/CommonFramework/Notifications/EventNotificationWidget.h Source/CommonFramework/Notifications/MessageAttachment.cpp Source/CommonFramework/Notifications/MessageAttachment.h Source/CommonFramework/Notifications/ProgramInfo.h @@ -715,6 +719,8 @@ file(GLOB LIBRARY_SOURCES Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.h Source/Integrations/DiscordIntegrationSettings.cpp Source/Integrations/DiscordIntegrationSettings.h + Source/Integrations/DiscordIntegrationSettingsWidget.cpp + Source/Integrations/DiscordIntegrationSettingsWidget.h Source/Integrations/DiscordIntegrationTable.cpp Source/Integrations/DiscordIntegrationTable.h Source/Integrations/DiscordSettingsOption.cpp @@ -1456,6 +1462,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonLA/Options/PokemonLA_TradeCountTable.h Source/PokemonLA/Options/PokemonLA_TravelLocation.cpp Source/PokemonLA/Options/PokemonLA_TravelLocation.h + Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.cpp + Source/PokemonLA/Options/QtWidgets/PokemonLA_CustomPathTableWidget.h Source/PokemonLA/Panels_PokemonLA.cpp Source/PokemonLA/Panels_PokemonLA.h Source/PokemonLA/PokemonLA_Locations.cpp @@ -2554,6 +2562,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonSwSh/Resources/PokemonSwSh_TypeSprites.h Source/PokemonSwSh/ShinyHuntTracker.cpp Source/PokemonSwSh/ShinyHuntTracker.h + Source/StaticRegistration.h + Source/StaticRegistrationQt.cpp Source/Tests/CommandLineTests.cpp Source/Tests/CommandLineTests.h Source/Tests/CommonFramework_Tests.cpp