From 559a6ce1d8a1847af45c4a95021d165fa4629802 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 9 Jan 2009 02:22:43 +0000 Subject: [PATCH] - fixed SELECT_FIRST behavior: 0 >= 0 - added DoGetBestSize to PackTotalsPanel, so the text always fits git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1313 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/pack.cpp | 7 ++++--- src/gui/set/random_pack_panel.cpp | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/data/pack.cpp b/src/data/pack.cpp index 5fc2ec77..6fa56e8e 100644 --- a/src/data/pack.cpp +++ b/src/data/pack.cpp @@ -300,11 +300,11 @@ void PackInstance::expect_copy(double copies) { } else if (pack_type.select == SELECT_PROPORTIONAL) { i.expect_copy(copies * item->amount * item->probability * i.count / total_probability); } else if (pack_type.select == SELECT_NONEMPTY) { - if (i.count >= 0) { + if (i.count > 0) { i.expect_copy(copies * item->amount * item->probability / total_probability); } } else if (pack_type.select == SELECT_FIRST) { - if (i.count >= 0 && cards.empty()) { + if (i.count > 0 && cards.empty()) { i.expect_copy(copies * item->amount); break; } @@ -328,6 +328,7 @@ struct RandomRange { void PackInstance::generate(vector* out) { card_copies = 0; + if (requested_copies == 0) return; if (pack_type.select == SELECT_ALL) { // add all cards card_copies += requested_copies * cards.size(); @@ -417,7 +418,7 @@ void PackInstance::generate(vector* out) { // pick first nonempty item FOR_EACH_CONST(item, pack_type.items) { PackInstance& i = parent.get(item->name); - if (i.count >= 0) { + if (i.count > 0) { i.request_copy(requested_copies * item->amount); break; } diff --git a/src/gui/set/random_pack_panel.cpp b/src/gui/set/random_pack_panel.cpp index 3a5158ed..2a7b19a2 100644 --- a/src/gui/set/random_pack_panel.cpp +++ b/src/gui/set/random_pack_panel.cpp @@ -99,6 +99,7 @@ class PackTotalsPanel : public wxPanel { void addPack(PackType& pack, int copies); void addItemRef(PackItemRef& item, int copies); #endif + virtual wxSize DoGetBestSize() const; private: DECLARE_EVENT_TABLE(); GameP game; @@ -149,7 +150,6 @@ void PackTotalsPanel::draw(DC& dc) { dc.DrawLine(0, y-2, size.x, y-2); y += 7; drawItem(dc, y, _LABEL_("total cards"), total); - } void PackTotalsPanel::drawItem(DC& dc, int& y, const String& name, double value) { wxSize size = dc.GetSize(); @@ -161,6 +161,27 @@ void PackTotalsPanel::drawItem(DC& dc, int& y, const String& name, double value y += h + 10; } +wxSize PackTotalsPanel::DoGetBestSize() const { + // count lines + int lines = 0; + #if USE_NEW_PACK_SYSTEM + if (game && generator.set) { + FOR_EACH(pack, game->pack_types) { + PackInstance& i = generator.get(pack); + if (pack->summary && i.has_cards()) lines++; + } + } + #else + lines = game ? (int)game->pack_items.size() : 0; + #endif + // don't forget the total + lines++; + // size + int height = lines * (GetCharHeight() + 10) + 7 - 10; + wxSize ws = GetSize(), cs = GetClientSize(); + return wxSize(0,height) + ws - cs; +} + void PackTotalsPanel::setGame(const GameP& game) { this->game = game; #if !USE_NEW_PACK_SYSTEM