mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
Added Statistics dimension/categories
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@84 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+73
-14
@@ -10,31 +10,72 @@
|
||||
#include <gui/control/graph.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gui/control/filtered_card_list.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/statistics.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <util/alignment.hpp>
|
||||
#include <gfx/gfx.hpp>
|
||||
#include <wx/splitter.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatFieldList
|
||||
DECLARE_TYPEOF_COLLECTION(StatsDimensionP);
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatCategoryList
|
||||
|
||||
/// A list of fields of which the statistics can be shown
|
||||
class StatFieldList : public GalleryList {
|
||||
class StatCategoryList : public GalleryList {
|
||||
public:
|
||||
StatFieldList(Window* parent, int id)
|
||||
StatCategoryList(Window* parent, int id)
|
||||
: GalleryList(parent, id, wxVERTICAL)
|
||||
{
|
||||
item_size = wxSize(100, 30);
|
||||
item_size = wxSize(140, 23);
|
||||
}
|
||||
|
||||
void show(const GameP&);
|
||||
|
||||
/// The selected category
|
||||
inline StatsCategory& getSelection() {
|
||||
return *game->statistics_categories.at(selection);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual size_t itemCount() const;
|
||||
virtual void drawItem(DC& dc, int x, int y, size_t item, bool selected);
|
||||
|
||||
private:
|
||||
GameP game;
|
||||
};
|
||||
|
||||
size_t StatFieldList::itemCount() const {
|
||||
return 0; // TODO
|
||||
void StatCategoryList::show(const GameP& game) {
|
||||
this->game = game;
|
||||
update();
|
||||
}
|
||||
|
||||
void StatFieldList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
|
||||
// TODO
|
||||
size_t StatCategoryList::itemCount() const {
|
||||
return game ? game->statistics_categories.size() : 0;
|
||||
}
|
||||
|
||||
void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
|
||||
StatsCategory& cat = *game->statistics_categories.at(item);
|
||||
// draw icon
|
||||
if (!cat.icon_filename.empty() && !cat.icon.Ok()) {
|
||||
InputStreamP file = game->openIn(cat.icon_filename);
|
||||
Image img(*file);
|
||||
Image resampled(21, 21);
|
||||
resample_preserve_aspect(img, resampled);
|
||||
if (img.Ok()) cat.icon = Bitmap(resampled);
|
||||
}
|
||||
if (cat.icon.Ok()) {
|
||||
dc.DrawBitmap(cat.icon, x+1, y+1);
|
||||
}
|
||||
// draw name
|
||||
RealRect rect(RealPoint(x + 23, y), RealSize(item_size.width - 30, item_size.height));
|
||||
String str = capitalize(cat.name);
|
||||
dc.SetFont(wxFont(10,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
|
||||
int w, h;
|
||||
dc.GetTextExtent(str, &w, &h);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(w,h), rect);
|
||||
dc.DrawText(str, pos.x, pos.y);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatsPanel
|
||||
@@ -44,30 +85,47 @@ StatsPanel::StatsPanel(Window* parent, int id)
|
||||
{
|
||||
// init controls
|
||||
wxSplitterWindow* splitter;
|
||||
fields = new StatFieldList (this, ID_FIELD_LIST);
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
|
||||
graph = new GraphControl (splitter, wxID_ANY);
|
||||
card_list = new FilteredCardList(splitter, wxID_ANY);
|
||||
categories = new StatCategoryList(this, ID_FIELD_LIST);
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
|
||||
graph = new GraphControl (splitter, wxID_ANY);
|
||||
card_list = new FilteredCardList(splitter, wxID_ANY);
|
||||
// init splitter
|
||||
splitter->SetMinimumPaneSize(100);
|
||||
splitter->SetSashGravity(1.0);
|
||||
splitter->SplitHorizontally(graph, card_list, -100);
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
|
||||
s->Add(fields, 0, wxEXPAND | wxRIGHT, 2);
|
||||
s->Add(splitter, 1, wxEXPAND);
|
||||
s->Add(categories, 0, wxEXPAND | wxRIGHT, 2);
|
||||
s->Add(splitter, 1, wxEXPAND);
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
void StatsPanel::onChangeSet() {
|
||||
card_list->setSet(set);
|
||||
categories->show(set->game);
|
||||
}
|
||||
|
||||
void StatsPanel::onCommand(int id) {
|
||||
switch (id) {
|
||||
case ID_FIELD_LIST: {
|
||||
// change graph data
|
||||
if (categories->hasSelection()) {
|
||||
StatsCategory& cat = categories->getSelection();
|
||||
GraphDataPre d;
|
||||
FOR_EACH(dim, cat.dimensions) {
|
||||
d.axes.push_back(new_shared1<GraphAxis>(dim->name));
|
||||
}
|
||||
FOR_EACH(card, set->cards) {
|
||||
Context& ctx = set->getContext(card);
|
||||
GraphElementP e(new GraphElement);
|
||||
FOR_EACH(dim, cat.dimensions) {
|
||||
e->values.push_back(*dim->script.invoke(ctx));
|
||||
}
|
||||
d.elements.push_back(e);
|
||||
}
|
||||
graph->setData(d);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -80,4 +138,5 @@ CardP StatsPanel::selectedCard() const {
|
||||
}
|
||||
void StatsPanel::selectCard(const CardP& card) {
|
||||
card_list->setCard(card);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user