mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Implemented seed controls on random pack panel;
seed settings and pack amounts are stored in settings git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1044 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -76,6 +76,8 @@ GameSettings::GameSettings()
|
|||||||
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
|
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
|
||||||
, use_auto_replace(true)
|
, use_auto_replace(true)
|
||||||
, initialized(false)
|
, initialized(false)
|
||||||
|
, pack_seed_random(true)
|
||||||
|
, pack_seed(123456)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void GameSettings::initDefaults(const Game& game) {
|
void GameSettings::initDefaults(const Game& game) {
|
||||||
@@ -110,6 +112,9 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) {
|
|||||||
REFLECT(images_export_conflicts);
|
REFLECT(images_export_conflicts);
|
||||||
REFLECT(use_auto_replace);
|
REFLECT(use_auto_replace);
|
||||||
REFLECT(auto_replaces);
|
REFLECT(auto_replaces);
|
||||||
|
REFLECT(pack_amounts);
|
||||||
|
REFLECT(pack_seed_random);
|
||||||
|
REFLECT(pack_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ class GameSettings : public IntrusivePtrBase<GameSettings> {
|
|||||||
FilenameConflicts images_export_conflicts;
|
FilenameConflicts images_export_conflicts;
|
||||||
bool use_auto_replace;
|
bool use_auto_replace;
|
||||||
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
vector<AutoReplaceP> auto_replaces; ///< Things to autoreplace in textboxes
|
||||||
|
map<String, int> pack_amounts;
|
||||||
|
bool pack_seed_random;
|
||||||
|
int pack_seed;
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -13,7 +13,10 @@
|
|||||||
#include <gui/control/filtered_card_list.hpp>
|
#include <gui/control/filtered_card_list.hpp>
|
||||||
#include <data/game.hpp>
|
#include <data/game.hpp>
|
||||||
#include <data/pack.hpp>
|
#include <data/pack.hpp>
|
||||||
|
#include <data/settings.hpp>
|
||||||
|
#include <util/window_id.hpp>
|
||||||
#include <wx/spinctrl.h>
|
#include <wx/spinctrl.h>
|
||||||
|
#include <boost/random/mersenne_twister.hpp>
|
||||||
|
|
||||||
DECLARE_TYPEOF_COLLECTION(PackTypeP);
|
DECLARE_TYPEOF_COLLECTION(PackTypeP);
|
||||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||||
@@ -71,9 +74,9 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
|
|||||||
// init controls
|
// init controls
|
||||||
preview = new CardViewer(this, wxID_ANY);
|
preview = new CardViewer(this, wxID_ANY);
|
||||||
card_list = new FilteredCardList(this, wxID_ANY);
|
card_list = new FilteredCardList(this, wxID_ANY);
|
||||||
wxButton* generate = new wxButton(this, wxID_ANY, _BUTTON_("generate pack"));
|
generate_button = new wxButton(this, ID_GENERATE_PACK, _BUTTON_("generate pack"));
|
||||||
wxRadioButton* seed_random = new wxRadioButton(this, wxID_ANY, _BUTTON_("random seed"));
|
seed_random = new wxRadioButton(this, ID_SEED_RANDOM, _BUTTON_("random seed"));
|
||||||
wxRadioButton* seed_fixed = new wxRadioButton(this, wxID_ANY, _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);
|
||||||
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"));
|
||||||
@@ -100,8 +103,8 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
|
|||||||
s7->Add(s8, 0, wxALL & ~wxTOP, 4);
|
s7->Add(s8, 0, wxALL & ~wxTOP, 4);
|
||||||
s6->Add(s7, 0, 0, 8);
|
s6->Add(s7, 0, 0, 8);
|
||||||
//s6->AddStretchSpacer();
|
//s6->AddStretchSpacer();
|
||||||
//s6->Add(generate, 0, wxTOP | wxALIGN_RIGHT, 8);
|
//s6->Add(generate_button, 0, wxTOP | wxALIGN_RIGHT, 8);
|
||||||
s6->Add(generate, 1, wxTOP | wxEXPAND, 8);
|
s6->Add(generate_button, 1, wxTOP | wxEXPAND, 8);
|
||||||
s3->Add(s6, 0, wxEXPAND | wxLEFT, 8);
|
s3->Add(s6, 0, wxEXPAND | wxLEFT, 8);
|
||||||
s2->Add(s3, 0, wxEXPAND | wxALL & ~wxTOP, 4);
|
s2->Add(s3, 0, wxEXPAND | wxALL & ~wxTOP, 4);
|
||||||
s2->Add(card_list, 1, wxEXPAND);
|
s2->Add(card_list, 1, wxEXPAND);
|
||||||
@@ -110,7 +113,12 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
|
|||||||
SetSizer(s);
|
SetSizer(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RandomPackPanel::~RandomPackPanel() {
|
||||||
|
storeSettings();
|
||||||
|
}
|
||||||
|
|
||||||
void RandomPackPanel::onChangeSet() {
|
void RandomPackPanel::onChangeSet() {
|
||||||
|
storeSettings();
|
||||||
preview ->setSet(set);
|
preview ->setSet(set);
|
||||||
card_list->setSet(set);
|
card_list->setSet(set);
|
||||||
|
|
||||||
@@ -128,36 +136,98 @@ void RandomPackPanel::onChangeSet() {
|
|||||||
PackItem i;
|
PackItem i;
|
||||||
i.pack = pack;
|
i.pack = pack;
|
||||||
i.label = new wxStaticText(this, wxID_ANY, pack->name);
|
i.label = new wxStaticText(this, wxID_ANY, pack->name);
|
||||||
i.value = new wxSpinCtrl(this, wxID_ANY, _("0"), wxDefaultPosition, wxSize(50,-1));
|
i.value = new wxSpinCtrl(this, ID_PACK_AMOUNT, _("0"), wxDefaultPosition, wxSize(50,-1));
|
||||||
packsSizer->Add(i.label, 0, wxALIGN_CENTER_VERTICAL);
|
packsSizer->Add(i.label, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
packsSizer->Add(i.value, 0, wxEXPAND | wxALIGN_CENTER);
|
packsSizer->Add(i.value, 0, wxEXPAND | wxALIGN_CENTER);
|
||||||
packs.push_back(i);
|
packs.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout();
|
Layout();
|
||||||
|
|
||||||
|
// settings
|
||||||
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
|
seed_random->SetValue(gs.pack_seed_random);
|
||||||
|
seed_fixed ->SetValue(!gs.pack_seed_random);
|
||||||
|
seed->Enable(!gs.pack_seed_random);
|
||||||
|
setSeed(gs.pack_seed);
|
||||||
|
FOR_EACH(i, packs) {
|
||||||
|
i.value->SetValue(gs.pack_amounts[i.pack->name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTotals();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RandomPackPanel::storeSettings() {
|
||||||
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
|
gs.pack_seed_random = seed_random->GetValue();
|
||||||
|
FOR_EACH(i, packs) {
|
||||||
|
gs.pack_amounts[i.pack->name] = i.value->GetValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : UI
|
// ----------------------------------------------------------------------------- : UI
|
||||||
|
|
||||||
void RandomPackPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
|
void RandomPackPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {}
|
||||||
// ?
|
|
||||||
}
|
|
||||||
|
|
||||||
void RandomPackPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
void RandomPackPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {}
|
||||||
// ?
|
|
||||||
}
|
|
||||||
|
|
||||||
void RandomPackPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
void RandomPackPanel::onUpdateUI(wxUpdateUIEvent& ev) {}
|
||||||
// ?
|
|
||||||
}
|
|
||||||
|
|
||||||
void RandomPackPanel::onCommand(int id) {
|
void RandomPackPanel::onCommand(int id) {
|
||||||
// ?
|
switch (id) {
|
||||||
|
case ID_PACK_AMOUNT: {
|
||||||
|
updateTotals();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ID_GENERATE_PACK: {
|
||||||
|
generate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ID_SEED_RANDOM: case ID_SEED_FIXED: {
|
||||||
|
seed->Enable(seed_fixed->GetValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Generating
|
// ----------------------------------------------------------------------------- : Generating
|
||||||
|
|
||||||
|
void RandomPackPanel::updateTotals() {
|
||||||
|
total_packs = 0;
|
||||||
|
FOR_EACH(i,packs) {
|
||||||
|
total_packs += i.value->GetValue();
|
||||||
|
}
|
||||||
|
// update UI
|
||||||
|
generate_button->Enable(total_packs > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int RandomPackPanel::getSeed() {
|
||||||
|
// determine seed value
|
||||||
|
int seed = 0;
|
||||||
|
if (seed_random->GetValue()) {
|
||||||
|
// use the C rand() function to get a seed
|
||||||
|
seed = rand() % 1000 * 1000
|
||||||
|
+ clock() % 1000;
|
||||||
|
} else {
|
||||||
|
// convert *any* string to a number
|
||||||
|
String s = this->seed->GetValue();
|
||||||
|
FOR_EACH_CONST(c,s) {
|
||||||
|
seed *= 10;
|
||||||
|
seed += abs(c - '0') + 123456789*(abs(c - '0')/10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setSeed(seed);
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
void RandomPackPanel::setSeed(int seed) {
|
||||||
|
seed %= 1000000;
|
||||||
|
this->seed->SetValue(wxString::Format(_("%06d"),seed));
|
||||||
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
|
gs.pack_seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
void RandomPackPanel::generate() {
|
void RandomPackPanel::generate() {
|
||||||
|
boost::mt19937 random((unsigned)getSeed());
|
||||||
//set->game->pack_types[0].generate()
|
//set->game->pack_types[0].generate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ DECLARE_POINTER_TYPE(PackType);
|
|||||||
class RandomPackPanel : public SetWindowPanel {
|
class RandomPackPanel : public SetWindowPanel {
|
||||||
public:
|
public:
|
||||||
RandomPackPanel(Window* parent, int id);
|
RandomPackPanel(Window* parent, int id);
|
||||||
|
~RandomPackPanel();
|
||||||
|
|
||||||
// --------------------------------------------------- : UI
|
// --------------------------------------------------- : UI
|
||||||
|
|
||||||
@@ -44,6 +45,8 @@ class RandomPackPanel : public SetWindowPanel {
|
|||||||
wxTextCtrl* seed; ///< Seed value
|
wxTextCtrl* seed; ///< Seed value
|
||||||
wxFlexGridSizer* packsSizer;
|
wxFlexGridSizer* packsSizer;
|
||||||
wxFlexGridSizer* totalsSizer;
|
wxFlexGridSizer* totalsSizer;
|
||||||
|
wxButton* generate_button;
|
||||||
|
wxRadioButton* seed_random, *seed_fixed;
|
||||||
|
|
||||||
struct PackItem {
|
struct PackItem {
|
||||||
PackTypeP pack;
|
PackTypeP pack;
|
||||||
@@ -55,9 +58,17 @@ class RandomPackPanel : public SetWindowPanel {
|
|||||||
struct TotalItem {
|
struct TotalItem {
|
||||||
};
|
};
|
||||||
vector<TotalItem> totals;
|
vector<TotalItem> totals;
|
||||||
|
int total_packs;
|
||||||
|
|
||||||
|
/// Update the total count of each card type
|
||||||
|
void updateTotals();
|
||||||
|
/// Get a seed value
|
||||||
|
int getSeed();
|
||||||
|
void setSeed(int seed);
|
||||||
/// Generate the cards
|
/// Generate the cards
|
||||||
void generate();
|
void generate();
|
||||||
|
/// Store the settings
|
||||||
|
void storeSettings();
|
||||||
public:
|
public:
|
||||||
typedef PackItem PackItem_for_typeof;
|
typedef PackItem PackItem_for_typeof;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -771,6 +771,8 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
|
|||||||
EVT_MENU (ID_HELP_ABOUT, SetWindow::onHelpAbout)
|
EVT_MENU (ID_HELP_ABOUT, SetWindow::onHelpAbout)
|
||||||
EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SetWindow::onChildMenu)
|
EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SetWindow::onChildMenu)
|
||||||
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_BUTTON_CLICKED, SetWindow::onChildMenu)
|
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_BUTTON_CLICKED, SetWindow::onChildMenu)
|
||||||
|
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_SPINCTRL_UPDATED, SetWindow::onChildMenu)
|
||||||
|
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_RADIOBUTTON_SELECTED, SetWindow::onChildMenu)
|
||||||
EVT_GALLERY_SELECT (ID_FIELD_LIST, SetWindow::onChildMenu) // for StatsPanel, because it is not a EVT_TOOL
|
EVT_GALLERY_SELECT (ID_FIELD_LIST, SetWindow::onChildMenu) // for StatsPanel, because it is not a EVT_TOOL
|
||||||
|
|
||||||
EVT_UPDATE_UI (wxID_ANY, SetWindow::onUpdateUI)
|
EVT_UPDATE_UI (wxID_ANY, SetWindow::onUpdateUI)
|
||||||
|
|||||||
@@ -190,6 +190,12 @@ enum ChildMenuID {
|
|||||||
// Statistics panel
|
// Statistics panel
|
||||||
, ID_FIELD_LIST = 3031
|
, ID_FIELD_LIST = 3031
|
||||||
|
|
||||||
|
// Random pack panel
|
||||||
|
, ID_PACK_AMOUNT = 3041
|
||||||
|
, ID_SEED_RANDOM
|
||||||
|
, ID_SEED_FIXED
|
||||||
|
, ID_GENERATE_PACK
|
||||||
|
|
||||||
// SymbolFont (Format menu)
|
// SymbolFont (Format menu)
|
||||||
, ID_INSERT_SYMBOL_MENU_MIN = 3301
|
, ID_INSERT_SYMBOL_MENU_MIN = 3301
|
||||||
, ID_INSERT_SYMBOL_MENU_MAX = 3999
|
, ID_INSERT_SYMBOL_MENU_MAX = 3999
|
||||||
|
|||||||
Reference in New Issue
Block a user