mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
feat: new set stylesheet filtering
This commit is contained in:
@@ -461,6 +461,8 @@ label:
|
||||
# New set window
|
||||
game type: &Game type:
|
||||
style type: &Card style:
|
||||
search stylesheet list: Filter Stylesheets
|
||||
search stylesheet list control: Filter the card list. Use - to exclude cards. Use field: to search in a specific field. Use quotes for literal search. Separate multiple queries with a space.
|
||||
|
||||
stylesheet not found :
|
||||
The set you are trying to open uses the stylesheet "%s".
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
#include <script/profiler.hpp>
|
||||
#include <gui/util.hpp>
|
||||
|
||||
bool PackageData::contains(QuickFilterPart const& query) const {
|
||||
if (query.match(_("full_name"), package->full_name)) return true;
|
||||
if (query.match(_("short_name"), package->short_name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackageList
|
||||
|
||||
PackageList::PackageList(Window* parent, int id, int direction, bool always_focused)
|
||||
@@ -23,29 +29,29 @@ PackageList::PackageList(Window* parent, int id, int direction, bool always_focu
|
||||
}
|
||||
|
||||
size_t PackageList::itemCount() const {
|
||||
return packages.size();
|
||||
return filtered_packages.size();
|
||||
}
|
||||
|
||||
void PackageList::drawItem(DC& dc, int x, int y, size_t item) {
|
||||
dc.SetClippingRegion(x+1, y+2, item_size.x-2, item_size.y-2);
|
||||
PackageData& d = packages.at(item);
|
||||
PackageDataP& d = filtered_packages.at(item);
|
||||
RealRect rect(RealPoint(x,y),item_size);
|
||||
RealPoint pos;
|
||||
int w, h;
|
||||
// draw image
|
||||
if (d.image.Ok()) {
|
||||
dc.DrawBitmap(d.image, x + int(align_delta_x(ALIGN_CENTER, item_size.x, d.image.GetWidth())), y + 3, true);
|
||||
if (d->image.Ok()) {
|
||||
dc.DrawBitmap(d->image, x + int(align_delta_x(ALIGN_CENTER, item_size.x, d->image.GetWidth())), y + 3, true);
|
||||
}
|
||||
// draw short name
|
||||
dc.SetFont(wxFont(12,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_("Arial")));
|
||||
dc.GetTextExtent(capitalize(d.package->short_name), &w, &h);
|
||||
dc.GetTextExtent(capitalize(d->package->short_name), &w, &h);
|
||||
pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
|
||||
dc.DrawText(capitalize(d.package->short_name), max(x+1,(int)pos.x), (int)pos.y + 110);
|
||||
dc.DrawText(capitalize(d->package->short_name), max(x+1,(int)pos.x), (int)pos.y + 110);
|
||||
// draw name
|
||||
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
|
||||
dc.GetTextExtent(d.package->full_name, &w, &h);
|
||||
dc.GetTextExtent(d->package->full_name, &w, &h);
|
||||
RealPoint text_pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
|
||||
dc.DrawText(d.package->full_name, max(x+1,(int)text_pos.x), (int)text_pos.y + 130);
|
||||
dc.DrawText(d->package->full_name, max(x+1,(int)text_pos.x), (int)text_pos.y + 130);
|
||||
dc.DestroyClippingRegion();
|
||||
}
|
||||
|
||||
@@ -62,6 +68,7 @@ struct PackageList::ComparePackagePosHint {
|
||||
void PackageList::showData(const String& pattern) {
|
||||
// clear
|
||||
packages.clear();
|
||||
|
||||
// find matching packages
|
||||
vector<PackagedP> matching;
|
||||
{
|
||||
@@ -82,19 +89,23 @@ void PackageList::showData(const String& pattern) {
|
||||
}
|
||||
// sort list
|
||||
sort(packages.begin(), packages.end(), ComparePackagePosHint());
|
||||
|
||||
// update list
|
||||
applyFilter();
|
||||
update();
|
||||
}
|
||||
|
||||
void PackageList::clear() {
|
||||
packages.clear();
|
||||
filtered_packages.clear();
|
||||
filter.reset();
|
||||
update();
|
||||
}
|
||||
|
||||
void PackageList::select(const String& name, bool send_event) {
|
||||
for (vector<PackageData>::const_iterator it = packages.begin() ; it != packages.end() ; ++it) {
|
||||
if (it->package->name() == name) {
|
||||
subcolumns[0].selection = it - packages.begin();
|
||||
for (vector<PackageDataP>::const_iterator it = filtered_packages.begin() ; it != filtered_packages.end() ; ++it) {
|
||||
if (it->get()->package->name() == name) {
|
||||
subcolumns[0].selection = it - filtered_packages.begin();
|
||||
update();
|
||||
if (send_event) {
|
||||
sendEvent(EVENT_GALLERY_SELECT);
|
||||
@@ -110,3 +121,19 @@ void PackageList::select(const String& name, bool send_event) {
|
||||
int PackageList::requiredWidth() const {
|
||||
return (item_size.x + SPACING) * (int)itemCount();
|
||||
}
|
||||
|
||||
void PackageList::setFilter(const PackageDataFilterP& filter) {
|
||||
this->filter = filter;
|
||||
applyFilter();
|
||||
update();
|
||||
}
|
||||
|
||||
void PackageList::applyFilter() {
|
||||
this->filtered_packages.clear();
|
||||
|
||||
FOR_EACH(p, packages) {
|
||||
if (!filter || filter->keep(p)) {
|
||||
filtered_packages.push_back(make_intrusive<PackageData>(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,25 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <data/filter.hpp>
|
||||
|
||||
DECLARE_POINTER_TYPE(Packaged);
|
||||
DECLARE_POINTER_TYPE(PackageData);
|
||||
|
||||
// Information about a package
|
||||
class PackageData : public IntrusivePtrVirtualBase, public IntrusiveFromThis<PackageData> {
|
||||
public:
|
||||
PackageData() {};
|
||||
PackageData(const PackagedP& package, const Bitmap& image) : package(package), image(image) {};
|
||||
PackagedP package;
|
||||
Bitmap image;
|
||||
|
||||
bool contains(QuickFilterPart const& query) const;
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
typedef intrusive_ptr<Filter<PackageData>> PackageDataFilterP;
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackageList
|
||||
|
||||
@@ -38,7 +55,7 @@ public:
|
||||
* Throws if the selection is not of type T */
|
||||
template <typename T>
|
||||
intrusive_ptr<T> getSelection(bool load_fully = true) const {
|
||||
intrusive_ptr<T> ret = dynamic_pointer_cast<T>(packages.at(getSelectionId()).package);
|
||||
intrusive_ptr<T> ret = dynamic_pointer_cast<T>(filtered_packages.at(getSelectionId())->package);
|
||||
if (!ret) throw InternalError(_("PackageList: Selected package has the wrong type"));
|
||||
if (load_fully) ret->loadFully();
|
||||
return ret;
|
||||
@@ -50,6 +67,8 @@ public:
|
||||
/// Required width to show all items
|
||||
int requiredWidth() const;
|
||||
using GalleryList::column_count;
|
||||
|
||||
void setFilter(const PackageDataFilterP& filter);
|
||||
|
||||
protected:
|
||||
/// Draw an item
|
||||
@@ -58,18 +77,11 @@ protected:
|
||||
size_t itemCount() const override;
|
||||
|
||||
private:
|
||||
// The default icon to use
|
||||
// wxIcon default_icon;
|
||||
|
||||
// Information about a package
|
||||
struct PackageData {
|
||||
PackageData() {}
|
||||
PackageData(const PackagedP& package, const Bitmap& image) : package(package), image(image) {}
|
||||
PackagedP package;
|
||||
Bitmap image;
|
||||
};
|
||||
void applyFilter();
|
||||
|
||||
struct ComparePackagePosHint;
|
||||
/// The displayed packages
|
||||
vector<PackageData> packages;
|
||||
vector<PackageDataP> filtered_packages;
|
||||
PackageDataFilterP filter;
|
||||
};
|
||||
|
||||
|
||||
+17
-5
@@ -26,7 +26,7 @@ SetP new_set_window(Window* parent) {
|
||||
}
|
||||
|
||||
NewSetWindow::NewSetWindow(Window* parent)
|
||||
: wxDialog(parent, wxID_ANY, _TITLE_("new set"), wxDefaultPosition, wxSize(530,320), wxDEFAULT_DIALOG_STYLE)
|
||||
: wxDialog(parent, wxID_ANY, _TITLE_("new set"), wxDefaultPosition, wxSize(840,360), wxDEFAULT_DIALOG_STYLE)
|
||||
{
|
||||
wxBusyCursor wait;
|
||||
// init controls
|
||||
@@ -34,11 +34,18 @@ NewSetWindow::NewSetWindow(Window* parent)
|
||||
stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST, wxHORIZONTAL, false);
|
||||
wxStaticText* game_text = new wxStaticText(this, ID_GAME_LIST, _LABEL_("game type"));
|
||||
wxStaticText* stylesheet_text = new wxStaticText(this, ID_STYLESHEET_LIST, _LABEL_("style type"));
|
||||
filter = new FilterCtrl(this, ID_STYLESHEET_FILTER, _LABEL_("search stylesheet list"), _HELP_("search stylesheet list control"));
|
||||
filter->setFilter(filter_value);
|
||||
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxVERTICAL);
|
||||
s->Add(game_text, 0, wxALL, 4);
|
||||
s->Add(game_list, 0, wxEXPAND | (wxALL & ~wxTOP), 4);
|
||||
s->Add(stylesheet_text, 0, wxALL, 4);
|
||||
wxSizer* s2 = new wxBoxSizer(wxHORIZONTAL);
|
||||
s2->Add(stylesheet_text, 0, wxALL & ~wxLEFT, 4);
|
||||
s2->AddSpacer(2);
|
||||
s2->Add(filter, 0, wxALL & ~wxRIGHT, 4);
|
||||
s->Add(s2);
|
||||
s->Add(stylesheet_list, 0, wxEXPAND | (wxALL & ~wxTOP), 4);
|
||||
s->Add(CreateButtonSizer(wxOK | wxCANCEL) , 0, wxEXPAND | wxALL, 8);
|
||||
s->SetSizeHints(this);
|
||||
@@ -84,6 +91,10 @@ void NewSetWindow::onStyleSheetActivate(wxCommandEvent&) {
|
||||
done();
|
||||
}
|
||||
|
||||
void NewSetWindow::onFilterUpdate(wxCommandEvent&) {
|
||||
stylesheet_list->setFilter(filter->getFilter<PackageData>());
|
||||
}
|
||||
|
||||
void NewSetWindow::OnOK(wxCommandEvent&) {
|
||||
done();
|
||||
}
|
||||
@@ -117,9 +128,10 @@ void NewSetWindow::onIdle(wxIdleEvent& ev) {
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(NewSetWindow, wxDialog)
|
||||
EVT_GALLERY_SELECT (ID_GAME_LIST, NewSetWindow::onGameSelect)
|
||||
EVT_GALLERY_SELECT (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
|
||||
EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
|
||||
EVT_GALLERY_SELECT(ID_GAME_LIST, NewSetWindow::onGameSelect)
|
||||
EVT_GALLERY_SELECT(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
|
||||
EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
|
||||
EVT_COMMAND_RANGE(ID_STYLESHEET_FILTER, ID_STYLESHEET_FILTER, wxEVT_COMMAND_TEXT_UPDATED, NewSetWindow::onFilterUpdate)
|
||||
EVT_BUTTON (wxID_OK, NewSetWindow::OnOK)
|
||||
EVT_UPDATE_UI (wxID_ANY, NewSetWindow::onUpdateUI)
|
||||
EVT_IDLE ( NewSetWindow::onIdle)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <gui/control/filter_ctrl.hpp>
|
||||
|
||||
class PackageList;
|
||||
class Game;
|
||||
@@ -34,6 +35,8 @@ private:
|
||||
|
||||
// gui items
|
||||
PackageList* game_list, *stylesheet_list;
|
||||
FilterCtrl* filter;
|
||||
String filter_value;
|
||||
|
||||
// --------------------------------------------------- : events
|
||||
|
||||
@@ -41,6 +44,7 @@ private:
|
||||
|
||||
void onStyleSheetSelect (wxCommandEvent&);
|
||||
void onStyleSheetActivate(wxCommandEvent&);
|
||||
void onFilterUpdate(wxCommandEvent&);
|
||||
|
||||
virtual void OnOK(wxCommandEvent&);
|
||||
|
||||
|
||||
@@ -227,6 +227,9 @@ enum ControlID {
|
||||
ID_CONTROL_MIN = 1000,
|
||||
ID_CONTROL_MAX = 1999,
|
||||
|
||||
// New Set Window
|
||||
ID_STYLESHEET_FILTER,
|
||||
|
||||
// Controls
|
||||
ID_VIEWER = 1001,
|
||||
ID_EDITOR,
|
||||
|
||||
Reference in New Issue
Block a user