Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Common/Cpp/Options/BatchOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BatchOption>(lock_while_program_is_running)
, m_data(CONSTRUCT_TOKEN, horizontal)
{}
void BatchOption::add_option(ConfigOption& option, std::string serialization_string){
Expand Down
4 changes: 1 addition & 3 deletions Common/Cpp/Options/BatchOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace PokemonAutomation{

// A ConfigOption that groups one or more options.
class BatchOption : public ConfigOption{
class BatchOption : public ConfigOptionImpl<BatchOption>{
public:
~BatchOption();
BatchOption(LockMode lock_while_program_is_running, bool horizontal = false);
Expand All @@ -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<ConfigOption*> options() const;

Expand Down
12 changes: 7 additions & 5 deletions Common/Cpp/Options/BooleanCheckBoxOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
namespace PokemonAutomation{




struct BooleanCheckBoxCell::Data{
const bool m_default;
std::atomic<bool> m_current;
Expand All @@ -28,21 +30,21 @@ struct BooleanCheckBoxCell::Data{

BooleanCheckBoxCell::~BooleanCheckBoxCell() = default;
BooleanCheckBoxCell::BooleanCheckBoxCell(const BooleanCheckBoxCell& x)
: ConfigOption(x)
: ConfigOptionImpl<BooleanCheckBoxCell>(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<BooleanCheckBoxCell>(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<BooleanCheckBoxCell>(lock_while_running)
, m_data(CONSTRUCT_TOKEN, default_value, default_value)
{}

Expand Down Expand Up @@ -81,15 +83,15 @@ BooleanCheckBoxOption::BooleanCheckBoxOption(
LockMode lock_while_running,
bool default_value
)
: BooleanCheckBoxCell(lock_while_running, default_value)
: ConfigOptionImpl<BooleanCheckBoxOption, BooleanCheckBoxCell>(lock_while_running, default_value)
, m_label(std::move(label))
{}
BooleanCheckBoxOption::BooleanCheckBoxOption(
std::string label,
LockMode lock_while_running,
bool default_value, bool value
)
: BooleanCheckBoxCell(lock_while_running, default_value, value)
: ConfigOptionImpl<BooleanCheckBoxOption, BooleanCheckBoxCell>(lock_while_running, default_value, value)
, m_label(std::move(label))
{}

Expand Down
7 changes: 3 additions & 4 deletions Common/Cpp/Options/BooleanCheckBoxOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace PokemonAutomation{



class BooleanCheckBoxCell : public ConfigOption{
class BooleanCheckBoxCell : public ConfigOptionImpl<BooleanCheckBoxCell>{
public:
~BooleanCheckBoxCell();
BooleanCheckBoxCell(const BooleanCheckBoxCell& x);
Expand All @@ -23,6 +23,7 @@ class BooleanCheckBoxCell : public ConfigOption{
bool default_value, bool current_value
);


public:
BooleanCheckBoxCell(
LockMode lock_while_running,
Expand All @@ -40,7 +41,6 @@ class BooleanCheckBoxCell : public ConfigOption{

virtual void restore_defaults() override;

virtual ConfigWidget* make_QtWidget(QWidget& parent) override;

protected:
struct Data;
Expand All @@ -50,7 +50,7 @@ class BooleanCheckBoxCell : public ConfigOption{



class BooleanCheckBoxOption : public BooleanCheckBoxCell{
class BooleanCheckBoxOption : public ConfigOptionImpl<BooleanCheckBoxOption, BooleanCheckBoxCell>{
public:
BooleanCheckBoxOption(const BooleanCheckBoxOption& x) = delete;
BooleanCheckBoxOption(
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Common/Cpp/Options/BoxFloatOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BoxFloatOption::BoxFloatOption(
double default_width,
double default_height
)
: ConfigOption(lock_while_running)
: ConfigOptionImpl<BoxFloatOption>(lock_while_running)
, m_data(CONSTRUCT_TOKEN)
{
Data& self = *m_data;
Expand Down
4 changes: 1 addition & 3 deletions Common/Cpp/Options/BoxFloatOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace PokemonAutomation{


class BoxFloatOption : public ConfigOption{
class BoxFloatOption : public ConfigOptionImpl<BoxFloatOption>{
public:
~BoxFloatOption();
BoxFloatOption(
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions Common/Cpp/Options/ButtonOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct ButtonCell::Data{

ButtonCell::~ButtonCell() = default;
ButtonCell::ButtonCell(const ButtonCell& x)
: ConfigOption(x)
: ConfigOptionImpl<ButtonCell>(x)
, m_data(
CONSTRUCT_TOKEN,
x.m_data->m_state,
Expand All @@ -61,7 +61,7 @@ ButtonCell::ButtonCell(
int button_height,
int text_size
)
: ConfigOption(LockMode::UNLOCK_WHILE_RUNNING)
: ConfigOptionImpl<ButtonCell>(LockMode::UNLOCK_WHILE_RUNNING)
, m_data(CONSTRUCT_TOKEN, ButtonCell::ENABLED, std::move(text), button_height, text_size)
{}
ButtonCell::ButtonCell(
Expand All @@ -70,7 +70,7 @@ ButtonCell::ButtonCell(
int button_height,
int text_size
)
: ConfigOption(LockMode::UNLOCK_WHILE_RUNNING)
: ConfigOptionImpl<ButtonCell>(LockMode::UNLOCK_WHILE_RUNNING)
, m_data(CONSTRUCT_TOKEN, state, std::move(text), button_height, text_size)
{}

Expand Down Expand Up @@ -145,7 +145,7 @@ ButtonOption::ButtonOption(
int button_height,
int text_size
)
: ButtonCell(std::move(text), button_height, text_size)
: ConfigOptionImpl<ButtonOption, ButtonCell>(std::move(text), button_height, text_size)
, m_data(CONSTRUCT_TOKEN, std::move(label))
{}
ButtonOption::ButtonOption(
Expand All @@ -155,7 +155,7 @@ ButtonOption::ButtonOption(
int button_height,
int text_size
)
: ButtonCell(state, std::move(text), button_height, text_size)
: ConfigOptionImpl<ButtonOption, ButtonCell>(state, std::move(text), button_height, text_size)
, m_data(CONSTRUCT_TOKEN, std::move(label))
{}

Expand Down
10 changes: 4 additions & 6 deletions Common/Cpp/Options/ButtonOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ struct ButtonListener{
};


class ButtonCell : public ConfigOption{
class ButtonCell : public ConfigOptionImpl<ButtonCell>{
public:
enum Enabled : bool{
DISABLED,
ENABLED,
};


public:
virtual ~ButtonCell();
ButtonCell(const ButtonCell& x);
Expand All @@ -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);
Expand All @@ -62,8 +64,6 @@ class ButtonCell : public ConfigOption{

// virtual void restore_defaults() override;

virtual ConfigWidget* make_QtWidget(QWidget& parent) override;



protected:
Expand All @@ -73,7 +73,7 @@ class ButtonCell : public ConfigOption{



class ButtonOption : public ButtonCell{
class ButtonOption : public ConfigOptionImpl<ButtonOption, ButtonCell>{
public:
virtual ~ButtonOption();
ButtonOption(const ButtonOption& x) = delete;
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions Common/Cpp/Options/CheckboxDropdownOption.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Checkbox Dropdown Option
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CheckboxDropdownOption.h"

namespace PokemonAutomation{


}
3 changes: 1 addition & 2 deletions Common/Cpp/Options/CheckboxDropdownOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ template <typename FlagEnum>
class CheckboxDropdownDatabase;


class CheckboxDropdownBase : public ConfigOption{
class CheckboxDropdownBase : public ConfigOptionImpl<CheckboxDropdownBase>{
public:
CheckboxDropdownBase(std::string label)
: m_label(std::move(label))
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Common/Cpp/Options/ColorOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace PokemonAutomation{


ColorCell::ColorCell(const ColorCell& x)
: ConfigOption(x)
: ConfigOptionImpl<ColorCell>(x)
, m_default_value(x.m_default_value)
, m_current_value(x)
{}
Expand All @@ -20,7 +20,7 @@ ColorCell::ColorCell(
bool has_alpha,
uint32_t default_value, uint32_t current_value
)
: ConfigOption(lock_while_running)
: ConfigOptionImpl<ColorCell>(lock_while_running)
, m_has_alpha(has_alpha)
, m_default_value(default_value)
, m_current_value(current_value)
Expand Down
4 changes: 1 addition & 3 deletions Common/Cpp/Options/ColorOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace PokemonAutomation{



class ColorCell : public ConfigOption{
class ColorCell : public ConfigOptionImpl<ColorCell>{
public:
ColorCell(const ColorCell& x);
ColorCell(
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions Common/Cpp/Options/ConfigOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ void ConfigOption::report_value_changed(void* object){




}
35 changes: 34 additions & 1 deletion Common/Cpp/Options/ConfigOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -149,5 +151,36 @@ class ConfigOption{




//
// Helpers for implementations.
//

template <typename OptionType>
using ConfigUiFactory = UiWrapper (*)(OptionType& option, void* params);


template <typename ConfigType, typename ParentType = ConfigOption>
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<ConfigType&>(*this), params);
}
return UiWrapper();
}

static ConfigUiFactory<ConfigType> m_ui_factory;
};

template <typename ConfigType, typename ParentType>
ConfigUiFactory<ConfigType> ConfigOptionImpl<ConfigType, ParentType>::m_ui_factory;





}
#endif
Loading