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
5 changes: 3 additions & 2 deletions SerialPrograms/Source/CommonFramework/Panels/OptionsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ OptionsPanelDescriptor::OptionsPanelDescriptor(
std::move(category), std::move(display_name),
std::move(doc_link),
std::move(description),
deprecation
deprecation,
restore_defaults_button,
{}
)
, m_restore_defaults_button(restore_defaults_button)
{}
std::unique_ptr<PanelSession> OptionsPanelDescriptor::make_panel() const{
return std::make_unique<OptionsPanelSession>(*this);
Expand Down
6 changes: 0 additions & 6 deletions SerialPrograms/Source/CommonFramework/Panels/OptionsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ class OptionsPanelDescriptor : public PanelDescriptor{
bool restore_defaults_button = true
);

bool restore_defaults_button() const{ return m_restore_defaults_button; }

virtual std::unique_ptr<PanelSession> make_panel() const override;
virtual std::unique_ptr<OptionsPanelInstance> make_instance() const = 0;


private:
const bool m_restore_defaults_button;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OptionsPanelSession final : public UiState<OptionsPanelSession, PanelSessi


public:
void restore_defaults();
virtual void restore_defaults() override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PanelDescriptor::PanelDescriptor(
std::string doc_link,
std::string description,
PanelDeprecation deprecation,
bool restore_defaults_button,
std::vector<std::string> required_resources
)
: m_color(color)
Expand All @@ -26,6 +27,7 @@ PanelDescriptor::PanelDescriptor(
, m_doc_link(std::move(doc_link))
, m_description(std::move(description))
, m_deprecation(deprecation)
, m_restore_defaults_button(restore_defaults_button)
, m_required_resources(std::move(required_resources))
{}
std::unique_ptr<PanelSession> PanelDescriptor::make_panel() const{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class PanelDescriptor{
std::string category, std::string display_name,
std::string doc_link,
std::string description,
PanelDeprecation deprecation = PanelDeprecation::NOT_DEPRECATED,
std::vector<std::string> required_resources = {}
PanelDeprecation deprecation,
bool restore_defaults_button,
std::vector<std::string> required_resources
);
virtual ~PanelDescriptor() = default;

Expand All @@ -46,6 +47,7 @@ class PanelDescriptor{
const std::string& doc_link() const{ return m_doc_link; }
const std::string& description() const{ return m_description; }
PanelDeprecation deprecation() const{ return m_deprecation; }
bool restore_defaults_button() const{ return m_restore_defaults_button; }
const std::vector<std::string>& required_resources() const{ return m_required_resources; }

virtual std::unique_ptr<PanelSession> make_panel() const = 0;
Expand All @@ -58,6 +60,7 @@ class PanelDescriptor{
const std::string m_doc_link;
const std::string m_description;
const PanelDeprecation m_deprecation;
const bool m_restore_defaults_button;
const std::vector<std::string> m_required_resources;
};

Expand Down
3 changes: 2 additions & 1 deletion SerialPrograms/Source/CommonFramework/Panels/PanelSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class PanelSession : public UiState<PanelSession>{


public:
// Serialization
virtual void restore_defaults(){}

void load_json();
virtual JsonValue to_json() const;
virtual void load_json(const JsonValue& json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
*
*/

#include <QPushButton>
#include <QScrollArea>
#include <QMessageBox>
#include "Common/Qt/CollapsibleGroupBox.h"
#include "Common/Qt/Options/ConfigWidget.h"
#include "CommonFramework/Panels/UI/PanelElements.h"
#include "OptionsPanelWidget.h"

Expand All @@ -24,66 +19,14 @@ OptionsPanelWidget::OptionsPanelWidget(
OptionsPanelSession& session
)
: QWidget(&parent)
, m_session(session)
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);

const OptionsPanelDescriptor& descriptor = session.descriptor();

CollapsibleGroupBox* header = make_panel_header(
populate_panel_widget(
*this,
descriptor.display_name(),
descriptor.doc_link(),
descriptor.description()
session.descriptor(),
nullptr,
session.options(),
make_actions_bar(*this, session)
);
m_layout->addWidget(header);

{
QScrollArea* scroll_outer = new QScrollArea(this);
m_layout->addWidget(scroll_outer);
scroll_outer->setWidgetResizable(true);

QWidget* scroll_inner = new QWidget(scroll_outer);
scroll_outer->setWidget(scroll_inner);
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
scroll_layout->setAlignment(Qt::AlignTop);

m_options = ConfigWidget::make_from_option(session.options(), this);
scroll_layout->addWidget(&m_options->widget());

scroll_layout->addStretch(1);
}

if (session.descriptor().restore_defaults_button()){
QGroupBox* actions_widget = new QGroupBox("Actions", &parent);

QHBoxLayout* action_layout = new QHBoxLayout(actions_widget);
// action_layout->setContentsMargins(0, 0, 0, 0);
QPushButton* default_button = new QPushButton("Restore Defaults", actions_widget);
{
action_layout->addWidget(default_button, 1);
QFont font = default_button->font();
font.setPointSize(16);
default_button->setFont(font);
}

connect(
default_button, &QPushButton::clicked,
this, [this](bool){
QMessageBox::StandardButton button = QMessageBox::question(
nullptr,
"Restore Defaults",
"Are you sure you wish to restore settings back to defaults? This will wipe the current settings.",
QMessageBox::Ok | QMessageBox::Cancel
);
if (button == QMessageBox::Ok){
m_session.restore_defaults();
}
}
);
m_layout->addWidget(actions_widget);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class OptionsPanelWidget final : public QWidget, public UiComponentQtWidget{
virtual QWidget& widget() override{
return *this;
}

private:
OptionsPanelSession& m_session;
QVBoxLayout* m_layout;
ConfigWidget* m_options;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include <QMessageBox>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QLabel>
#include <QPushButton>
#include "CommonFramework/Globals.h"
#include "Common/Cpp/ColoredText.h"
#include "Common/Qt/Options/ConfigWidget.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/Panels/PanelSession.h"
#include "PanelElements.h"

namespace PokemonAutomation{
Expand Down Expand Up @@ -213,6 +216,89 @@ void RunnablePanelActionBar::set_state(ProgramState state){



QWidget* make_actions_bar(
QWidget& panel,
PanelSession& session
){
if (!session.descriptor().restore_defaults_button()){
return nullptr;
}

QWidget* actions_widget = new QGroupBox("Actions", &panel);

QHBoxLayout* action_layout = new QHBoxLayout(actions_widget);
// action_layout->setContentsMargins(0, 0, 0, 0);
QPushButton* default_button = new QPushButton("Restore Defaults", actions_widget);
{
action_layout->addWidget(default_button, 1);
QFont font = default_button->font();
font.setPointSize(16);
default_button->setFont(font);
}

panel.connect(
default_button, &QPushButton::clicked,
&panel, [&session](bool){
QMessageBox::StandardButton button = QMessageBox::question(
nullptr,
"Restore Defaults",
"Are you sure you wish to restore settings back to defaults? This will wipe the current settings.",
QMessageBox::Ok | QMessageBox::Cancel
);
if (button == QMessageBox::Ok){
session.restore_defaults();
}
}
);

return actions_widget;
}



void populate_panel_widget(
QWidget& panel,
const PanelDescriptor& descriptor,
QWidget* console_system,
ConfigOption& options,
QWidget* footer
){
QVBoxLayout* layout = new QVBoxLayout(&panel);
layout->setContentsMargins(0, 0, 0, 0);

CollapsibleGroupBox* header = make_panel_header(
panel,
descriptor.display_name(),
descriptor.doc_link(),
descriptor.description()
);
layout->addWidget(header);

QScrollArea* scroll_outer = new QScrollArea(&panel);
layout->addWidget(scroll_outer);
scroll_outer->setWidgetResizable(true);

QWidget* scroll_inner = new QWidget(scroll_outer);
scroll_outer->setWidget(scroll_inner);
QVBoxLayout* scroll_layout = new QVBoxLayout(scroll_inner);
scroll_layout->setAlignment(Qt::AlignTop);

if (console_system){
scroll_layout->addWidget(console_system);
}

ConfigWidget* options_widget = ConfigWidget::make_from_option(options, &panel);
scroll_layout->addWidget(&options_widget->widget());

scroll_layout->addStretch(1);

if (footer){
layout->addWidget(footer);
}
}






Expand Down
14 changes: 14 additions & 0 deletions SerialPrograms/Source/CommonFramework/Panels/UI/PanelElements.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class QPushButton;
namespace PokemonAutomation{


class ConfigOption;


CollapsibleGroupBox* make_panel_header(
Expand Down Expand Up @@ -69,6 +70,19 @@ public slots:



QWidget* make_actions_bar(
QWidget& panel,
PanelSession& session
);

void populate_panel_widget(
QWidget& panel,
const PanelDescriptor& descriptor,
QWidget* console_system,
ConfigOption& options,
QWidget* footer
);




Expand Down
4 changes: 3 additions & 1 deletion SerialPrograms/Source/ComputerPrograms/ComputerProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ ComputerProgramDescriptor::ComputerProgramDescriptor(
std::move(category), std::move(display_name),
std::move(doc_link),
std::move(description),
deprecation
deprecation,
true,
{}
)
{}
std::unique_ptr<PanelSession> ComputerProgramDescriptor::make_panel() const{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ComputerProgramSession final


public:
void restore_defaults();
virtual void restore_defaults() override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

Expand Down
5 changes: 3 additions & 2 deletions SerialPrograms/Source/GameConsole/ConsolePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ ConsolePanelDescriptor::ConsolePanelDescriptor(
std::move(category), std::move(display_name),
std::move(doc_link),
std::move(description),
deprecation
deprecation,
restore_defaults_button,
{}
)
, m_restore_defaults_button(restore_defaults_button)
, m_num_controllers(num_controllers)
{}
std::unique_ptr<PanelSession> ConsolePanelDescriptor::make_panel() const{
Expand Down
2 changes: 0 additions & 2 deletions SerialPrograms/Source/GameConsole/ConsolePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ class ConsolePanelDescriptor : public PanelDescriptor{
size_t num_controllers = 1
);

bool restore_defaults_button() const{ return m_restore_defaults_button; }
size_t num_controllers() const{ return m_num_controllers; }

virtual std::unique_ptr<PanelSession> make_panel() const override;
virtual std::unique_ptr<ConsolePanelInstance> make_instance(ConsoleSystemSession& system) const = 0;


private:
const bool m_restore_defaults_button;
const size_t m_num_controllers;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class ConsolePanelSession final : public UiState<ConsolePanelSession, PanelSessi


public:
// Serialization

void restore_defaults();
virtual void restore_defaults() override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MultiConsolePanelSession final : public UiState<MultiConsolePanelSession,
public:
// Serialization

void restore_defaults();
virtual void restore_defaults() override;
virtual JsonValue to_json() const override;
virtual void load_json(const JsonValue& json) override;

Expand Down
Loading
Loading