Commit ce99e785 authored by twanvl's avatar twanvl

pack totals on random pack panel

parent c9eecc04
...@@ -1844,6 +1844,9 @@ pack item: ...@@ -1844,6 +1844,9 @@ pack item:
pack item: pack item:
name: rare name: rare
filter: card.rarity == "rare" filter: card.rarity == "rare"
pack item:
name: special
filter: card.rarity == "special"
pack item: pack item:
name: basic land name: basic land
filter: card.type == "Plains" filter: card.type == "Plains"
......
...@@ -15,10 +15,13 @@ ...@@ -15,10 +15,13 @@
#include <data/pack.hpp> #include <data/pack.hpp>
#include <data/settings.hpp> #include <data/settings.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <wx/spinctrl.h>
#include <boost/random/mersenne_twister.hpp> #include <boost/random/mersenne_twister.hpp>
#include <wx/spinctrl.h>
#include <wx/dcbuffer.h>
DECLARE_TYPEOF_COLLECTION(PackTypeP); DECLARE_TYPEOF_COLLECTION(PackTypeP);
DECLARE_TYPEOF_COLLECTION(PackItemP);
DECLARE_TYPEOF_COLLECTION(PackItemRefP);
DECLARE_TYPEOF_COLLECTION(CardP); DECLARE_TYPEOF_COLLECTION(CardP);
DECLARE_TYPEOF_COLLECTION(RandomPackPanel::PackItem_for_typeof); DECLARE_TYPEOF_COLLECTION(RandomPackPanel::PackItem_for_typeof);
...@@ -68,6 +71,68 @@ void RandomCardList::getItems(vector<VoidP>& out) const { ...@@ -68,6 +71,68 @@ void RandomCardList::getItems(vector<VoidP>& out) const {
} }
// ----------------------------------------------------------------------------- : PackTotalsPanel
class PackTotalsPanel : public wxPanel {
public:
PackTotalsPanel(Window* parent, int id) : wxPanel(parent,id) {}
void setGame(const GameP& game);
void clear();
void addPack(PackType& pack, int copies);
void addItemRef(PackItemRef& item, int copies);
private:
DECLARE_EVENT_TABLE();
GameP game;
void onPaint(wxPaintEvent&);
void draw(DC& dc);
map<String,int> amounts;
};
void PackTotalsPanel::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this);
draw(dc);
}
void PackTotalsPanel::draw(DC& dc) {
// clear background
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
wxSize size = dc.GetSize();
dc.DrawRectangle(0,0,size.x,size.y);
// draw table
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
dc.SetFont(*wxNORMAL_FONT);
int y = 0;
FOR_EACH(item, game->pack_items) {
int w,h;
String name = capitalize(item->name);
String amount; amount << amounts[item->name];
dc.GetTextExtent(amount,&w,&h);
dc.DrawText(name, 0, y);
dc.DrawText(amount, size.x-w, y);//align right
y += h + 10;
}
}
void PackTotalsPanel::setGame(const GameP& game) {
this->game = game;
clear();
}
void PackTotalsPanel::clear() {
amounts.clear();
}
void PackTotalsPanel::addPack(PackType& pack, int copies) {
FOR_EACH(item,pack.items) {
addItemRef(*item, copies * item->amount);
}
}
void PackTotalsPanel::addItemRef(PackItemRef& item, int copies) {
amounts[item.name] += copies;
}
BEGIN_EVENT_TABLE(PackTotalsPanel, wxPanel)
EVT_PAINT(PackTotalsPanel::onPaint)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------- : RandomPackPanel // ----------------------------------------------------------------------------- : RandomPackPanel
RandomPackPanel::RandomPackPanel(Window* parent, int id) RandomPackPanel::RandomPackPanel(Window* parent, int id)
...@@ -80,6 +145,7 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id) ...@@ -80,6 +145,7 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
seed_random = new wxRadioButton(this, ID_SEED_RANDOM, _BUTTON_("random seed")); seed_random = new wxRadioButton(this, ID_SEED_RANDOM, _BUTTON_("random seed"));
seed_fixed = new wxRadioButton(this, ID_SEED_FIXED, _BUTTON_("fixed seed")); seed_fixed = new wxRadioButton(this, ID_SEED_FIXED, _BUTTON_("fixed seed"));
seed = new wxTextCtrl(this, wxID_ANY); seed = new wxTextCtrl(this, wxID_ANY);
totals = new PackTotalsPanel(this, wxID_ANY);
static_cast<SetWindow*>(parent)->setControlStatusText(seed_random, _HELP_("random seed")); static_cast<SetWindow*>(parent)->setControlStatusText(seed_random, _HELP_("random seed"));
static_cast<SetWindow*>(parent)->setControlStatusText(seed_fixed, _HELP_("fixed seed")); static_cast<SetWindow*>(parent)->setControlStatusText(seed_fixed, _HELP_("fixed seed"));
static_cast<SetWindow*>(parent)->setControlStatusText(seed, _HELP_("seed")); static_cast<SetWindow*>(parent)->setControlStatusText(seed, _HELP_("seed"));
...@@ -95,6 +161,7 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id) ...@@ -95,6 +161,7 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
s4->Add(packsSizer, 1, wxEXPAND | wxALL & ~wxTOP, 4); s4->Add(packsSizer, 1, wxEXPAND | wxALL & ~wxTOP, 4);
s3->Add(s4, 1, wxEXPAND, 8); s3->Add(s4, 1, wxEXPAND, 8);
wxSizer* s5 = new wxStaticBoxSizer(wxHORIZONTAL, this, _LABEL_("pack totals")); wxSizer* s5 = new wxStaticBoxSizer(wxHORIZONTAL, this, _LABEL_("pack totals"));
s5->Add(totals, 1, wxEXPAND | wxALL, 4);
s3->Add(s5, 1, wxEXPAND | wxLEFT, 8); s3->Add(s5, 1, wxEXPAND | wxLEFT, 8);
wxSizer* s6 = new wxBoxSizer(wxVERTICAL); wxSizer* s6 = new wxBoxSizer(wxVERTICAL);
wxSizer* s7 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("seed")); wxSizer* s7 = new wxStaticBoxSizer(wxVERTICAL, this, _LABEL_("seed"));
...@@ -123,6 +190,7 @@ void RandomPackPanel::onChangeSet() { ...@@ -123,6 +190,7 @@ void RandomPackPanel::onChangeSet() {
storeSettings(); storeSettings();
preview ->setSet(set); preview ->setSet(set);
card_list->setSet(set); card_list->setSet(set);
totals ->setGame(set->game);
// remove old pack controls // remove old pack controls
FOR_EACH(i, packs) { FOR_EACH(i, packs) {
...@@ -195,11 +263,15 @@ void RandomPackPanel::onCommand(int id) { ...@@ -195,11 +263,15 @@ void RandomPackPanel::onCommand(int id) {
// ----------------------------------------------------------------------------- : Generating // ----------------------------------------------------------------------------- : Generating
void RandomPackPanel::updateTotals() { void RandomPackPanel::updateTotals() {
totals->clear();
total_packs = 0; total_packs = 0;
FOR_EACH(i,packs) { FOR_EACH(i,packs) {
total_packs += i.value->GetValue(); int copies = i.value->GetValue();
total_packs += copies;
totals->addPack(*i.pack, copies);
} }
// update UI // update UI
totals->Refresh(false);
generate_button->Enable(total_packs > 0); generate_button->Enable(total_packs > 0);
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
class CardViewer; class CardViewer;
class RandomCardList; class RandomCardList;
class PackTotalsPanel;
DECLARE_POINTER_TYPE(PackType); DECLARE_POINTER_TYPE(PackType);
// ----------------------------------------------------------------------------- : RandomPackPanel // ----------------------------------------------------------------------------- : RandomPackPanel
...@@ -50,6 +51,7 @@ class RandomPackPanel : public SetWindowPanel { ...@@ -50,6 +51,7 @@ class RandomPackPanel : public SetWindowPanel {
wxFlexGridSizer* totalsSizer; wxFlexGridSizer* totalsSizer;
wxButton* generate_button; wxButton* generate_button;
wxRadioButton* seed_random, *seed_fixed; wxRadioButton* seed_random, *seed_fixed;
PackTotalsPanel* totals;
struct PackItem { struct PackItem {
PackTypeP pack; PackTypeP pack;
...@@ -58,9 +60,6 @@ class RandomPackPanel : public SetWindowPanel { ...@@ -58,9 +60,6 @@ class RandomPackPanel : public SetWindowPanel {
}; };
vector<PackItem> packs; vector<PackItem> packs;
struct TotalItem {
};
vector<TotalItem> totals;
int total_packs; int total_packs;
/// Update the total count of each card type /// Update the total count of each card type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment