-
Notifications
You must be signed in to change notification settings - Fork 113
Resource Download - Settings #1305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
20f6ae6
Resource Download - Settings
jw098 6f07e19
clean up class members and headers
jw098 be2fe4c
refactor listeners for Download Row options
jw098 8bc3762
refactor listeners for download widget
jw098 f8acb71
create SettingsDownloadPopup to listen for Row::on_metadata_fetch_fin…
jw098 f0de820
fix build
jw098 538712c
fix update_visibility() so that it hides the ProgressBar
jw098 0661989
use ScopeExit to always update action state.
jw098 faa005b
gate resource downloading behind dev mode
jw098 3830d54
update URL
jw098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadOptions.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* Resource Download Options | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include "SettingsResourceDownloadRow.h" | ||
| #include "SettingsResourceDownloadOptions.h" | ||
|
|
||
|
|
||
| // #include <iostream> | ||
| // using std::cout; | ||
| // using std::endl; | ||
|
|
||
| namespace PokemonAutomation{ | ||
|
|
||
|
|
||
|
|
||
| void SettingsResourceButton::add_button_listener(Listener& listener){ | ||
| m_listeners.add(listener); | ||
| } | ||
| void SettingsResourceButton::remove_button_listener(Listener& listener){ | ||
| m_listeners.remove(listener); | ||
| } | ||
|
|
||
| void SettingsResourceButton::change_text(const std::string& text){ | ||
| m_listeners.run_method(&Listener::on_change_text, text); | ||
| } | ||
|
|
||
|
|
||
| ////////////////////////////////////// | ||
| // SettingsResourceDownloadButton | ||
| ////////////////////////////////////// | ||
| // SettingsResourceDownloadButton::~SettingsResourceDownloadButton(){} | ||
| SettingsResourceDownloadButton::SettingsResourceDownloadButton(SettingsResourceDownloadRow& p_row) | ||
| : ConfigOptionImpl<SettingsResourceDownloadButton>(LockMode::UNLOCK_WHILE_RUNNING) | ||
| , row(p_row) | ||
| , m_enabled(true) | ||
| {} | ||
|
|
||
| void SettingsResourceDownloadButton::set_enabled(bool enabled){ | ||
| m_enabled = enabled; | ||
| change_text(enabled ? "Download" : "Downloading..."); | ||
| set_visibility(enabled ? ConfigOptionState::ENABLED : ConfigOptionState::DISABLED); | ||
| } | ||
|
|
||
|
|
||
| ////////////////////////////////////// | ||
| // SettingsResourceDeleteButton | ||
| ////////////////////////////////////// | ||
| SettingsResourceDeleteButton::SettingsResourceDeleteButton(SettingsResourceDownloadRow& p_row) | ||
| : ConfigOptionImpl<SettingsResourceDeleteButton>(LockMode::UNLOCK_WHILE_RUNNING) | ||
| , row(p_row) | ||
| , m_enabled(true) | ||
| {} | ||
|
|
||
| void SettingsResourceDeleteButton::set_enabled(bool enabled){ | ||
| m_enabled = enabled; | ||
| change_text(enabled ? "Delete" : "Deleting..."); | ||
| set_visibility(enabled ? ConfigOptionState::ENABLED : ConfigOptionState::DISABLED); | ||
| } | ||
|
|
||
| ////////////////////////////////////// | ||
| // SettingsResourceCancelButton | ||
| ////////////////////////////////////// | ||
| SettingsResourceCancelButton::SettingsResourceCancelButton(SettingsResourceDownloadRow& p_row) | ||
| : ConfigOptionImpl<SettingsResourceCancelButton>(LockMode::UNLOCK_WHILE_RUNNING) | ||
| , row(p_row) | ||
| , m_enabled(true) | ||
| {} | ||
|
|
||
| void SettingsResourceCancelButton::set_enabled(bool enabled){ | ||
| m_enabled = enabled; | ||
| change_text(enabled ? "Cancel" : "Cancelling..."); | ||
| set_visibility(enabled ? ConfigOptionState::ENABLED : ConfigOptionState::DISABLED); | ||
| } | ||
| ////////////////////////////////////// | ||
| // SettingsResourceProgressBar | ||
| ////////////////////////////////////// | ||
| SettingsResourceProgressBar::SettingsResourceProgressBar(SettingsResourceDownloadRow& p_row) | ||
| : ConfigOptionImpl<SettingsResourceProgressBar>(LockMode::UNLOCK_WHILE_RUNNING) | ||
| , row(p_row) | ||
| {} | ||
|
|
||
| void SettingsResourceProgressBar::add_progress_listener(Listener& listener){ | ||
| m_listeners.add(listener); | ||
| } | ||
| void SettingsResourceProgressBar::remove_progress_listener(Listener& listener){ | ||
| m_listeners.remove(listener); | ||
| } | ||
|
|
||
| void SettingsResourceProgressBar::change_text(const std::string& text){ | ||
| m_listeners.run_method(&Listener::on_change_text, text); | ||
| } | ||
|
|
||
| void SettingsResourceProgressBar::update_progress(uint64_t bytes_done, uint64_t total_bytes){ | ||
| m_listeners.run_method(&Listener::on_update_progress, bytes_done, total_bytes); | ||
| } | ||
|
|
||
| void SettingsResourceProgressBar::reset_progress(){ | ||
| m_listeners.run_method(&Listener::on_reset_progress); | ||
| } | ||
|
|
||
| //////////////////////////////// | ||
| // ResourceDownload::Listener | ||
| //////////////////////////////// | ||
| void SettingsResourceProgressBar::on_download_progress(uint64_t bytes_done, uint64_t total_bytes){ | ||
| change_text("Downloading"); | ||
| set_visibility(ConfigOptionState::ENABLED); | ||
| update_progress(bytes_done, total_bytes); | ||
| } | ||
| void SettingsResourceProgressBar::on_unzip_progress(uint64_t bytes_done, uint64_t total_bytes){ | ||
| change_text("Unzipping"); | ||
| set_visibility(ConfigOptionState::ENABLED); | ||
| update_progress(bytes_done, total_bytes); | ||
| } | ||
| void SettingsResourceProgressBar::on_hash_progress(uint64_t bytes_done, uint64_t total_bytes){ | ||
| change_text("Verifying"); | ||
| set_visibility(ConfigOptionState::ENABLED); | ||
| update_progress(bytes_done, total_bytes); | ||
| } | ||
|
|
||
| ////////////////////////////////////// | ||
| // SettingsDownloadPopup | ||
| ////////////////////////////////////// | ||
| SettingsDownloadPopup::SettingsDownloadPopup(SettingsResourceDownloadRow& p_row) | ||
| : ConfigOptionImpl<SettingsDownloadPopup>(LockMode::LOCK_WHILE_RUNNING) | ||
| , row(p_row) | ||
| {} | ||
|
|
||
| ////////////////////////////////////// | ||
| // SettingsDownloadError | ||
| ////////////////////////////////////// | ||
| SettingsDownloadError::SettingsDownloadError() | ||
| : ConfigOptionImpl<SettingsDownloadError>(LockMode::LOCK_WHILE_RUNNING) | ||
| {} | ||
|
|
||
| } |
131 changes: 131 additions & 0 deletions
131
SerialPrograms/Source/CommonFramework/ResourceDownload/SettingsResourceDownloadOptions.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* Resource Download Options | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_ResourceDownloadOptions_H | ||
| #define PokemonAutomation_ResourceDownloadOptions_H | ||
|
|
||
| #include "Common/Cpp/ListenerSet.h" | ||
| #include "ResourceDownload.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
|
|
||
| class SettingsResourceDownloadRow; | ||
|
|
||
|
|
||
| class SettingsResourceButton { | ||
| public: | ||
| struct Listener{ | ||
| virtual void on_change_text(const std::string& text){} | ||
| }; | ||
|
|
||
| void add_button_listener(Listener& listener); | ||
| void remove_button_listener(Listener& listener); | ||
|
|
||
| void change_text(const std::string& text); | ||
|
|
||
| private: | ||
| ListenerSet<Listener> m_listeners; | ||
|
|
||
| }; | ||
|
|
||
| class SettingsResourceDownloadButton : public ConfigOptionImpl<SettingsResourceDownloadButton>, public SettingsResourceButton{ | ||
| public: | ||
| // ~SettingsResourceDownloadButton(); | ||
| SettingsResourceDownloadButton(SettingsResourceDownloadRow& p_row); | ||
|
|
||
| public: | ||
| inline bool get_enabled(){ return m_enabled; } | ||
| void set_enabled(bool enabled); | ||
|
|
||
| public: | ||
| SettingsResourceDownloadRow& row; | ||
|
|
||
| private: | ||
| bool m_enabled; // button should be blocked during an active task. m_enabled is false when blocked | ||
|
|
||
|
|
||
|
|
||
| }; | ||
|
|
||
| class SettingsResourceDeleteButton : public ConfigOptionImpl<SettingsResourceDeleteButton>, public SettingsResourceButton{ | ||
| public: | ||
| SettingsResourceDeleteButton(SettingsResourceDownloadRow& p_row); | ||
|
|
||
| public: | ||
| inline bool get_enabled(){ return m_enabled; } | ||
| void set_enabled(bool enabled); | ||
|
|
||
| public: | ||
| SettingsResourceDownloadRow& row; | ||
|
|
||
| private: | ||
| bool m_enabled; | ||
| }; | ||
|
|
||
| class SettingsResourceCancelButton : public ConfigOptionImpl<SettingsResourceCancelButton>, public SettingsResourceButton{ | ||
| public: | ||
| SettingsResourceCancelButton(SettingsResourceDownloadRow& p_row); | ||
|
|
||
| public: | ||
| inline bool get_enabled(){ return m_enabled; } | ||
| void set_enabled(bool enabled); | ||
|
|
||
| public: | ||
| SettingsResourceDownloadRow& row; | ||
|
|
||
| private: | ||
| bool m_enabled; | ||
| }; | ||
|
|
||
| class SettingsResourceProgressBar : public ConfigOptionImpl<SettingsResourceProgressBar>, public ResourceDownload::Listener{ | ||
| public: | ||
| SettingsResourceProgressBar(SettingsResourceDownloadRow& p_row); | ||
|
|
||
| public: | ||
| struct Listener{ | ||
| virtual void on_change_text(const std::string& text){} | ||
| virtual void on_update_progress(uint64_t bytes_done, uint64_t total_bytes){} | ||
| virtual void on_reset_progress(){} | ||
| }; | ||
|
|
||
| void add_progress_listener(Listener& listener); | ||
| void remove_progress_listener(Listener& listener); | ||
|
|
||
| void change_text(const std::string& text); | ||
| void update_progress(uint64_t bytes_done, uint64_t total_bytes); | ||
| void reset_progress(); | ||
|
|
||
| public: // ResourceDownload::Listener | ||
| virtual void on_download_progress(uint64_t bytes_done, uint64_t total_bytes) override; | ||
| virtual void on_unzip_progress(uint64_t bytes_done, uint64_t total_bytes) override; | ||
| virtual void on_hash_progress(uint64_t bytes_done, uint64_t total_bytes) override; | ||
|
|
||
| public: | ||
| SettingsResourceDownloadRow& row; | ||
|
|
||
| private: | ||
| ListenerSet<Listener> m_listeners; | ||
|
|
||
| }; | ||
|
|
||
| class SettingsDownloadPopup : public ConfigOptionImpl<SettingsDownloadPopup>, public ResourceDownload::Listener{ | ||
| public: | ||
| SettingsDownloadPopup(SettingsResourceDownloadRow& p_row); | ||
| public: | ||
| SettingsResourceDownloadRow& row; | ||
|
|
||
| }; | ||
|
|
||
| class SettingsDownloadError : public ConfigOptionImpl<SettingsDownloadError>{ | ||
| public: | ||
| SettingsDownloadError(); | ||
|
|
||
|
|
||
| }; | ||
|
|
||
|
|
||
| } | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should gate this table behind dev mode for now.