mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2024-11-26 12:12:02 +00:00
Simplified LayeredErrorFrame by letting extended classes handle task events.
This commit is contained in:
parent
2ca9878c85
commit
1a2289c396
4 changed files with 93 additions and 85 deletions
|
@ -30,14 +30,13 @@
|
|||
|
||||
namespace nxdt::views
|
||||
{
|
||||
/* Instantiate the template for our class. */
|
||||
typedef LayeredErrorFrame<nxdt::tasks::GameCardTask, nxdt::tasks::GameCardStatusEvent> GameCardLayeredErrorFrame;
|
||||
|
||||
class GameCardTab: public GameCardLayeredErrorFrame
|
||||
class GameCardTab: public LayeredErrorFrame
|
||||
{
|
||||
typedef bool (*GameCardSizeFunc)(u64 *size);
|
||||
|
||||
private:
|
||||
nxdt::tasks::GameCardTask *gc_status_task = nullptr;
|
||||
nxdt::tasks::GameCardStatusEvent::Subscription gc_status_task_sub;
|
||||
GameCardStatus gc_status = GameCardStatus_NotInserted;
|
||||
|
||||
FocusableTable *properties_table = nullptr;
|
||||
|
@ -60,6 +59,7 @@ namespace nxdt::views
|
|||
|
||||
public:
|
||||
GameCardTab(nxdt::tasks::GameCardTask *gc_status_task);
|
||||
~GameCardTab(void);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,102 +28,26 @@
|
|||
|
||||
namespace nxdt::views
|
||||
{
|
||||
/* Extended class to switch between ErrorFrame and List views whenever an event is triggered. */
|
||||
template<typename TaskType, typename EventType>
|
||||
/* Extended class to switch between ErrorFrame and List views on demand. */
|
||||
class LayeredErrorFrame: public brls::LayerView
|
||||
{
|
||||
private:
|
||||
TaskType *task = nullptr;
|
||||
std::vector<typename EventType::Subscription> task_subs;
|
||||
int layer_view_index = 0;
|
||||
|
||||
ErrorFrame *error_frame = nullptr;
|
||||
|
||||
brls::List *list = nullptr;
|
||||
std::vector<brls::View*> list_views;
|
||||
|
||||
int layer_view_index = 0;
|
||||
|
||||
protected:
|
||||
void SwitchLayerView(bool use_error_frame);
|
||||
void SetErrorFrameMessage(std::string msg = "");
|
||||
void AddListView(brls::View* view);
|
||||
void RegisterListener(typename EventType::Callback cb);
|
||||
|
||||
public:
|
||||
LayeredErrorFrame(TaskType *task);
|
||||
LayeredErrorFrame(void);
|
||||
~LayeredErrorFrame(void);
|
||||
};
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
LayeredErrorFrame<TaskType, EventType>::LayeredErrorFrame(TaskType *task) : brls::LayerView(), task(task)
|
||||
{
|
||||
/* Error frame. */
|
||||
this->error_frame = new ErrorFrame();
|
||||
this->addLayer(this->error_frame);
|
||||
|
||||
/* List. */
|
||||
this->list = new brls::List();
|
||||
this->list->setSpacing(this->list->getSpacing() / 2);
|
||||
this->list->setMarginBottom(20);
|
||||
this->addLayer(this->list);
|
||||
}
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
LayeredErrorFrame<TaskType, EventType>::~LayeredErrorFrame(void)
|
||||
{
|
||||
/* Unregister task listeners. */
|
||||
for(typename EventType::Subscription task_sub : this->task_subs) this->task->UnregisterListener(task_sub);
|
||||
|
||||
/* Clear task subscriptions vector. */
|
||||
if (this->task_subs.size()) this->task_subs.clear();
|
||||
|
||||
/* Clear list views vector. */
|
||||
if (this->list_views.size()) this->list_views.clear();
|
||||
}
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
void LayeredErrorFrame<TaskType, EventType>::SwitchLayerView(bool use_error_frame)
|
||||
{
|
||||
if ((use_error_frame && this->layer_view_index == 0) || (!use_error_frame && this->layer_view_index == 1)) return;
|
||||
|
||||
int index = (this->layer_view_index ^ 1);
|
||||
brls::View *current_focus = brls::Application::getCurrentFocus();
|
||||
|
||||
/* Focus the sidebar if we're currently focusing an element from our List. */
|
||||
for(brls::View* list_view : this->list_views)
|
||||
{
|
||||
if (current_focus == list_view)
|
||||
{
|
||||
brls::Application::onGamepadButtonPressed(GLFW_GAMEPAD_BUTTON_DPAD_LEFT, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Change layer view. */
|
||||
this->changeLayer(index);
|
||||
this->invalidate(true);
|
||||
this->layer_view_index = index;
|
||||
}
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
void LayeredErrorFrame<TaskType, EventType>::SetErrorFrameMessage(std::string msg)
|
||||
{
|
||||
this->error_frame->SetMessage(msg);
|
||||
}
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
void LayeredErrorFrame<TaskType, EventType>::AddListView(brls::View* view)
|
||||
{
|
||||
this->list->addView(view);
|
||||
this->list_views.push_back(view);
|
||||
}
|
||||
|
||||
template<typename TaskType, typename EventType>
|
||||
void LayeredErrorFrame<TaskType, EventType>::RegisterListener(typename EventType::Callback cb)
|
||||
{
|
||||
typename EventType::Subscription task_sub = this->task->RegisterListener(cb);
|
||||
this->task_subs.push_back(task_sub);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __LAYERED_ERROR_FRAME_HPP__ */
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace nxdt::views
|
|||
[GameCardCompatibilityType_Terra] = "Terra"
|
||||
};
|
||||
|
||||
GameCardTab::GameCardTab(nxdt::tasks::GameCardTask *gc_status_task) : GameCardLayeredErrorFrame(gc_status_task)
|
||||
GameCardTab::GameCardTab(nxdt::tasks::GameCardTask *gc_status_task) : LayeredErrorFrame(), gc_status_task(gc_status_task)
|
||||
{
|
||||
/* Error frame. */
|
||||
this->SetErrorFrameMessage("gamecard_tab/error_frame/not_inserted"_i18n);
|
||||
|
@ -81,7 +81,7 @@ namespace nxdt::views
|
|||
this->AddListView(this->dump_hfs_partitions);
|
||||
|
||||
/* Subscribe to gamecard status event. */
|
||||
this->RegisterListener([this](GameCardStatus gc_status) {
|
||||
this->gc_status_task_sub = this->gc_status_task->RegisterListener([this](GameCardStatus gc_status) {
|
||||
if (gc_status < GameCardStatus_InsertedAndInfoLoaded) this->SwitchLayerView(true);
|
||||
|
||||
switch(gc_status)
|
||||
|
@ -137,6 +137,12 @@ namespace nxdt::views
|
|||
});
|
||||
}
|
||||
|
||||
GameCardTab::~GameCardTab(void)
|
||||
{
|
||||
/* Unregister task listener. */
|
||||
this->gc_status_task->UnregisterListener(this->gc_status_task_sub);
|
||||
}
|
||||
|
||||
std::string GameCardTab::GetFormattedSizeString(GameCardSizeFunc func)
|
||||
{
|
||||
u64 size = 0;
|
||||
|
|
78
source/layered_error_frame.cpp
Normal file
78
source/layered_error_frame.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* layered_error_frame.cpp
|
||||
*
|
||||
* Copyright (c) 2020-2021, DarkMatterCore <pabloacurielz@gmail.com>.
|
||||
*
|
||||
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
||||
*
|
||||
* nxdumptool is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* nxdumptool is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <layered_error_frame.hpp>
|
||||
|
||||
namespace nxdt::views
|
||||
{
|
||||
LayeredErrorFrame::LayeredErrorFrame(void) : brls::LayerView()
|
||||
{
|
||||
/* Error frame. */
|
||||
this->error_frame = new ErrorFrame();
|
||||
this->addLayer(this->error_frame);
|
||||
|
||||
/* List. */
|
||||
this->list = new brls::List();
|
||||
this->list->setSpacing(this->list->getSpacing() / 2);
|
||||
this->list->setMarginBottom(20);
|
||||
this->addLayer(this->list);
|
||||
}
|
||||
|
||||
LayeredErrorFrame::~LayeredErrorFrame(void)
|
||||
{
|
||||
/* Clear list views vector. */
|
||||
if (this->list_views.size()) this->list_views.clear();
|
||||
}
|
||||
|
||||
void LayeredErrorFrame::SwitchLayerView(bool use_error_frame)
|
||||
{
|
||||
if ((use_error_frame && this->layer_view_index == 0) || (!use_error_frame && this->layer_view_index == 1)) return;
|
||||
|
||||
int index = (this->layer_view_index ^ 1);
|
||||
brls::View *current_focus = brls::Application::getCurrentFocus();
|
||||
|
||||
/* Focus the sidebar if we're currently focusing an element from our List. */
|
||||
for(brls::View* list_view : this->list_views)
|
||||
{
|
||||
if (current_focus == list_view)
|
||||
{
|
||||
brls::Application::onGamepadButtonPressed(GLFW_GAMEPAD_BUTTON_DPAD_LEFT, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Change layer view. */
|
||||
this->changeLayer(index);
|
||||
this->invalidate(true);
|
||||
this->layer_view_index = index;
|
||||
}
|
||||
|
||||
void LayeredErrorFrame::SetErrorFrameMessage(std::string msg)
|
||||
{
|
||||
this->error_frame->SetMessage(msg);
|
||||
}
|
||||
|
||||
void LayeredErrorFrame::AddListView(brls::View* view)
|
||||
{
|
||||
this->list->addView(view);
|
||||
this->list_views.push_back(view);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue