random pack generation works

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1045 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-04 01:38:46 +00:00
parent 0cb872a0d3
commit 04a040dc29
8 changed files with 189 additions and 47 deletions
+24 -7
View File
@@ -32,7 +32,9 @@ class RandomCardList : public CardListBase {
/// Reset the list
void reset();
/// Add a pack of cards
void add(PackType& pack);
void add(PackItemCache& packs, boost::mt19937& gen, const PackType& pack);
using CardListBase::rebuild;
protected:
virtual void getItems(vector<VoidP>& out) const;
@@ -49,8 +51,8 @@ RandomCardList::RandomCardList(Window* parent, int id, long style)
void RandomCardList::reset() {
cards.clear();
}
void RandomCardList::add(PackType& pack) {
pack.generate(*set,cards);
void RandomCardList::add(PackItemCache& packs, boost::mt19937& gen, const PackType& pack) {
pack.generate(packs,gen,cards);
}
void RandomCardList::onChangeSet() {
@@ -73,7 +75,7 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
{
// init controls
preview = new CardViewer(this, wxID_ANY);
card_list = new FilteredCardList(this, wxID_ANY);
card_list = new RandomCardList(this, wxID_ANY);
generate_button = new wxButton(this, ID_GENERATE_PACK, _BUTTON_("generate pack"));
seed_random = new wxRadioButton(this, ID_SEED_RANDOM, _BUTTON_("random seed"));
seed_fixed = new wxRadioButton(this, ID_SEED_FIXED, _BUTTON_("fixed seed"));
@@ -135,7 +137,7 @@ void RandomPackPanel::onChangeSet() {
FOR_EACH(pack, set->game->pack_types) {
PackItem i;
i.pack = pack;
i.label = new wxStaticText(this, wxID_ANY, pack->name);
i.label = new wxStaticText(this, wxID_ANY, capitalize_sentence(pack->name));
i.value = new wxSpinCtrl(this, ID_PACK_AMOUNT, _("0"), wxDefaultPosition, wxSize(50,-1));
packsSizer->Add(i.label, 0, wxALIGN_CENTER_VERTICAL);
packsSizer->Add(i.value, 0, wxEXPAND | wxALIGN_CENTER);
@@ -227,8 +229,23 @@ void RandomPackPanel::setSeed(int seed) {
}
void RandomPackPanel::generate() {
boost::mt19937 random((unsigned)getSeed());
//set->game->pack_types[0].generate()
boost::mt19937 gen((unsigned)getSeed());
PackItemCache pack_cache(*set);
// add packs to card list
card_list->reset();
FOR_EACH(item,packs) {
int copies = item.value->GetValue();
for (int i = 0 ; i < copies ; ++i) {
card_list->add(pack_cache, gen, *item.pack);
}
}
card_list->rebuild();
}
// ----------------------------------------------------------------------------- : Selection
void RandomPackPanel::selectCard(const CardP& card) {
preview->setCard(card);
}
// ----------------------------------------------------------------------------- : Clipboard
+5 -2
View File
@@ -14,7 +14,7 @@
#include <wx/spinctrl.h>
class CardViewer;
class FilteredCardList;
class RandomCardList;
DECLARE_POINTER_TYPE(PackType);
// ----------------------------------------------------------------------------- : RandomPackPanel
@@ -34,6 +34,9 @@ class RandomPackPanel : public SetWindowPanel {
virtual void onUpdateUI(wxUpdateUIEvent&);
virtual void onCommand(int id);
// --------------------------------------------------- : Selection
virtual void selectCard(const CardP& card);
// --------------------------------------------------- : Clipboard
virtual bool canCopy() const;
@@ -41,7 +44,7 @@ class RandomPackPanel : public SetWindowPanel {
private:
CardViewer* preview; ///< Card preview
FilteredCardList* card_list; ///< The list of cards
RandomCardList* card_list; ///< The list of cards
wxTextCtrl* seed; ///< Seed value
wxFlexGridSizer* packsSizer;
wxFlexGridSizer* totalsSizer;