mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
feat: new set stylesheet filtering
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user