mirror of
https://github.com/sebastiandine/Card-Collection-Manager-3.git
synced 2026-08-29 17:28:48 +00:00
start of set completion tracking
This commit is contained in:
@@ -1,31 +1,45 @@
|
||||
#include "ccm/ui/DigiBattle99GameView.hpp"
|
||||
|
||||
#include "ccm/games/digibattle99/DigiBattle99SetSource.hpp"
|
||||
#include "ccm/ui/CardEditModalGuard.hpp"
|
||||
#include "ccm/ui/DigiBattle99CardEditDialog.hpp"
|
||||
#include "ccm/ui/DigiBattle99CardListPanel.hpp"
|
||||
#include "ccm/ui/DigiBattle99SelectedCardPanel.hpp"
|
||||
#include "ccm/ui/DigiBattle99SetCompletionPanel.hpp"
|
||||
#include "ccm/ui/SvgIcons.hpp"
|
||||
#include "ccm/ui/Theme.hpp"
|
||||
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/bmpbuttn.h>
|
||||
#include <wx/notebook.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/splitter.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace ccm::ui {
|
||||
|
||||
namespace {
|
||||
constexpr int kDigiToolbarIconPx = 18;
|
||||
constexpr const char kDigiFilterHint[] = "Filter";
|
||||
} // namespace
|
||||
|
||||
DigiBattle99GameView::DigiBattle99GameView(ConfigService& config,
|
||||
CollectionService<DigiBattle99Card>& collection,
|
||||
SetService& sets,
|
||||
ImageService& images,
|
||||
CardPreviewService& cardPreview,
|
||||
IGameModule& module)
|
||||
IGameModule& module,
|
||||
DigiBattle99SetCatalogService& catalogStore)
|
||||
: config_(config),
|
||||
collection_(collection),
|
||||
sets_(sets),
|
||||
images_(images),
|
||||
cardPreview_(cardPreview),
|
||||
module_(module) {}
|
||||
module_(module),
|
||||
catalogStore_(catalogStore) {}
|
||||
|
||||
void DigiBattle99GameView::ensureSetsLoaded() {
|
||||
if (attemptedInitialSetLoad_) return;
|
||||
@@ -45,6 +59,101 @@ void DigiBattle99GameView::ensureSetsLoaded() {
|
||||
}
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::ensureSingleCardsMounted(wxWindow* splitterParent) {
|
||||
if (singleSplitter_ == nullptr) {
|
||||
singleSplitter_ = new wxSplitterWindow(splitterParent, wxID_ANY, wxDefaultPosition,
|
||||
wxDefaultSize, wxSP_LIVE_UPDATE);
|
||||
singleSplitter_->SetMinimumPaneSize(280);
|
||||
}
|
||||
auto* list = listPanel(singleSplitter_);
|
||||
auto* selected = selectedPanel(singleSplitter_);
|
||||
if (!singleSplitter_->IsSplit()) {
|
||||
singleSplitter_->SplitVertically(selected, list, 360);
|
||||
}
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::buildSingleCardsToolbar(wxWindow* parent, wxBoxSizer* pageSizer) {
|
||||
auto* toolbar = new wxBoxSizer(wxHORIZONTAL);
|
||||
auto makeToolBtn = [&](const char* svg, const wxString& tip) {
|
||||
wxBitmap bmp = svgIconBitmap(svg, kDigiToolbarIconPx, "#000000");
|
||||
auto* b = new wxBitmapButton(parent, wxID_ANY, bmp, wxDefaultPosition, wxDefaultSize,
|
||||
wxBU_EXACTFIT);
|
||||
b->SetToolTip(tip);
|
||||
return b;
|
||||
};
|
||||
toolbarButtons_[0] = makeToolBtn(kSvgToolbarAdd, "Add Card");
|
||||
toolbarButtons_[1] = makeToolBtn(kSvgToolbarEdit, "Edit");
|
||||
toolbarButtons_[2] = makeToolBtn(kSvgToolbarDelete, "Delete");
|
||||
toolbar->AddSpacer(4);
|
||||
toolbar->Add(toolbarButtons_[0], 0, wxALIGN_CENTER_VERTICAL | wxALL, 4);
|
||||
toolbar->Add(toolbarButtons_[1], 0, wxALIGN_CENTER_VERTICAL | wxALL, 4);
|
||||
toolbar->Add(toolbarButtons_[2], 0, wxALIGN_CENTER_VERTICAL | wxALL, 4);
|
||||
toolbar->AddStretchSpacer(1);
|
||||
filterInput_ = new wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, wxSize(260, -1));
|
||||
filterInput_->SetHint(kDigiFilterHint);
|
||||
toolbar->Add(filterInput_, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxTOP | wxBOTTOM, 4);
|
||||
pageSizer->Add(toolbar, 0, wxEXPAND);
|
||||
|
||||
toolbarButtons_[0]->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
wxWindow* owner = wxGetTopLevelParent(contentPanel_);
|
||||
onAddCard(owner != nullptr ? owner : contentPanel_);
|
||||
});
|
||||
toolbarButtons_[1]->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
wxWindow* owner = wxGetTopLevelParent(contentPanel_);
|
||||
onEditCard(owner != nullptr ? owner : contentPanel_);
|
||||
});
|
||||
toolbarButtons_[2]->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
wxWindow* owner = wxGetTopLevelParent(contentPanel_);
|
||||
onDeleteCard(owner != nullptr ? owner : contentPanel_);
|
||||
});
|
||||
filterInput_->Bind(wxEVT_TEXT, [this](wxCommandEvent&) {
|
||||
if (filterInput_ == nullptr) return;
|
||||
setFilter(filterInput_->GetValue().ToStdString(wxConvUTF8));
|
||||
});
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::refreshToolbarIcons(const ThemePalette& palette) {
|
||||
const std::string tbHex = palette.buttonText.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
|
||||
if (toolbarButtons_[0]) {
|
||||
toolbarButtons_[0]->SetBitmap(
|
||||
svgIconBitmap(kSvgToolbarAdd, kDigiToolbarIconPx, tbHex.c_str()));
|
||||
}
|
||||
if (toolbarButtons_[1]) {
|
||||
toolbarButtons_[1]->SetBitmap(
|
||||
svgIconBitmap(kSvgToolbarEdit, kDigiToolbarIconPx, tbHex.c_str()));
|
||||
}
|
||||
if (toolbarButtons_[2]) {
|
||||
toolbarButtons_[2]->SetBitmap(
|
||||
svgIconBitmap(kSvgToolbarDelete, kDigiToolbarIconPx, tbHex.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
wxPanel* DigiBattle99GameView::contentPanel(wxWindow* parent) {
|
||||
if (contentPanel_ == nullptr) {
|
||||
contentPanel_ = new wxPanel(parent);
|
||||
auto* root = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
notebook_ = new wxNotebook(contentPanel_, wxID_ANY);
|
||||
auto* singlePage = new wxPanel(notebook_);
|
||||
auto* singleSizer = new wxBoxSizer(wxVERTICAL);
|
||||
buildSingleCardsToolbar(singlePage, singleSizer);
|
||||
ensureSingleCardsMounted(singlePage);
|
||||
singleSizer->Add(singleSplitter_, 1, wxEXPAND);
|
||||
singlePage->SetSizer(singleSizer);
|
||||
notebook_->AddPage(singlePage, "Single Cards");
|
||||
|
||||
setCompletionPanel_ = new DigiBattle99SetCompletionPanel(notebook_, catalogStore_);
|
||||
setCompletionPanel_->reloadFromStore();
|
||||
notebook_->AddPage(setCompletionPanel_, "Set Completion");
|
||||
|
||||
root->Add(notebook_, 1, wxEXPAND);
|
||||
contentPanel_->SetSizer(root);
|
||||
|
||||
refreshToolbarIcons(paletteForTheme(config_.current().theme));
|
||||
}
|
||||
return contentPanel_;
|
||||
}
|
||||
|
||||
wxPanel* DigiBattle99GameView::listPanel(wxWindow* parent) {
|
||||
if (listPanel_ == nullptr) {
|
||||
listPanel_ = new DigiBattle99CardListPanel(parent);
|
||||
@@ -69,7 +178,10 @@ wxPanel* DigiBattle99GameView::selectedPanel(wxWindow* parent) {
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::refreshCollection() {
|
||||
if (listPanel_ == nullptr) return;
|
||||
// Ensure the Digimon host (and list panel) exist even when MainFrame mounts
|
||||
// via contentPanel before an explicit listPanel call.
|
||||
if (contentPanel_ == nullptr && listPanel_ == nullptr) return;
|
||||
|
||||
auto loaded = collection_.list(Game::DigiBattle99);
|
||||
if (!loaded) {
|
||||
showThemedMessageDialog(
|
||||
@@ -78,9 +190,15 @@ void DigiBattle99GameView::refreshCollection() {
|
||||
"Error", wxOK | wxICON_ERROR);
|
||||
return;
|
||||
}
|
||||
listPanel_->setCards(std::move(loaded).value());
|
||||
listPanel_->activateSelection();
|
||||
if (selectedPanel_) selectedPanel_->setCard(listPanel_->selected());
|
||||
auto cards = std::move(loaded).value();
|
||||
if (listPanel_ != nullptr) {
|
||||
listPanel_->setCards(cards);
|
||||
listPanel_->activateSelection();
|
||||
if (selectedPanel_) selectedPanel_->setCard(listPanel_->selected());
|
||||
}
|
||||
if (setCompletionPanel_ != nullptr) {
|
||||
setCompletionPanel_->setCollection(std::move(cards));
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Set>& DigiBattle99GameView::setsForDialog() {
|
||||
@@ -190,27 +308,79 @@ void DigiBattle99GameView::onDeleteCard(wxWindow* parentWindow) {
|
||||
}
|
||||
|
||||
std::string DigiBattle99GameView::onUpdateSets(wxWindow* parentWindow) {
|
||||
auto out = sets_.updateSets(Game::DigiBattle99);
|
||||
if (!out) {
|
||||
showThemedMessageDialog(parentWindow, "Failed to update sets: " + out.error(),
|
||||
auto* digiSrc = dynamic_cast<DigiBattle99SetSource*>(&module_.setSource());
|
||||
if (digiSrc == nullptr) {
|
||||
showThemedMessageDialog(parentWindow, "Digimon Digi-Battle set source unavailable.",
|
||||
"Error", wxOK | wxICON_ERROR);
|
||||
return "Update failed";
|
||||
}
|
||||
setsCache_ = out.value();
|
||||
|
||||
auto both = digiSrc->fetchAllWithCatalog();
|
||||
if (!both) {
|
||||
showThemedMessageDialog(parentWindow, "Failed to update sets: " + both.error(),
|
||||
"Error", wxOK | wxICON_ERROR);
|
||||
return "Update failed";
|
||||
}
|
||||
|
||||
auto savedSets = sets_.saveSets(Game::DigiBattle99, both.value().sets);
|
||||
if (!savedSets) {
|
||||
showThemedMessageDialog(parentWindow, "Failed to save sets: " + savedSets.error(),
|
||||
"Error", wxOK | wxICON_ERROR);
|
||||
return "Update failed";
|
||||
}
|
||||
|
||||
auto savedCatalog = catalogStore_.save(both.value().catalog);
|
||||
if (!savedCatalog) {
|
||||
showThemedMessageDialog(parentWindow,
|
||||
"Sets saved, but set catalog failed: " + savedCatalog.error(),
|
||||
"Warning", wxOK | wxICON_WARNING);
|
||||
}
|
||||
|
||||
setsCache_ = both.value().sets;
|
||||
if (setCompletionPanel_ != nullptr) {
|
||||
setCompletionPanel_->reloadFromStore();
|
||||
if (auto loaded = collection_.list(Game::DigiBattle99)) {
|
||||
setCompletionPanel_->setCollection(std::move(loaded).value());
|
||||
}
|
||||
}
|
||||
|
||||
const std::size_t setCount = both.value().sets.size();
|
||||
const std::size_t packCount = both.value().catalog.packs.size();
|
||||
showThemedMessageDialog(
|
||||
parentWindow,
|
||||
"Updated " + std::to_string(out.value().size()) + " Digimon (Digi-Battle) sets.",
|
||||
"Updated " + std::to_string(setCount) + " Digimon (Digi-Battle) sets and " +
|
||||
std::to_string(packCount) + " set checklists.",
|
||||
"Sets updated", wxOK | wxICON_INFORMATION);
|
||||
return "Digimon (Digi-Battle) sets updated.";
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::setFilter(std::string_view filter) {
|
||||
if (filterInput_ != nullptr) {
|
||||
const wxString wanted = wxString::FromUTF8(std::string(filter).c_str());
|
||||
if (filterInput_->GetValue() != wanted) {
|
||||
filterInput_->ChangeValue(wanted);
|
||||
if (filter.empty()) {
|
||||
filterInput_->SetHint(kDigiFilterHint);
|
||||
filterInput_->Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (listPanel_) listPanel_->setFilter(filter);
|
||||
}
|
||||
|
||||
void DigiBattle99GameView::applyTheme(const ThemePalette& palette) {
|
||||
if (contentPanel_) applyThemeToWindowTree(contentPanel_, palette, config_.current().theme);
|
||||
if (listPanel_) listPanel_->applyTheme(palette);
|
||||
if (selectedPanel_) selectedPanel_->applyTheme(palette);
|
||||
if (setCompletionPanel_) setCompletionPanel_->applyTheme(palette);
|
||||
refreshToolbarIcons(palette);
|
||||
if (filterInput_ != nullptr) {
|
||||
filterInput_->SetBackgroundColour(palette.inputBg);
|
||||
filterInput_->SetForegroundColour(palette.inputText);
|
||||
filterInput_->SetOwnBackgroundColour(palette.inputBg);
|
||||
filterInput_->SetOwnForegroundColour(palette.inputText);
|
||||
filterInput_->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ccm::ui
|
||||
|
||||
Reference in New Issue
Block a user