From 1b90f0666cbae4e52603ea5158ace19f35367d25 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 10 Jan 2009 01:47:50 +0000 Subject: [PATCH] fixed bug: empty OptionalScript were saved as empty string, causing parse error when reading. custom pack types can now be removed again. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1329 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/set/random_pack_panel.cpp | 25 +++++++++++++++++++------ src/script/scriptable.cpp | 4 +++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gui/set/random_pack_panel.cpp b/src/gui/set/random_pack_panel.cpp index 2b749ab8..9eb2fcf6 100644 --- a/src/gui/set/random_pack_panel.cpp +++ b/src/gui/set/random_pack_panel.cpp @@ -313,6 +313,7 @@ class CustomPackDialog : public wxDialog { void storePack(); void onAmountChange(wxSpinEvent&); void onOk(wxCommandEvent&); + void onRemove(wxCommandEvent&); }; CustomPackDialog::CustomPackDialog(Window* parent, const SetP& set, const PackTypeP& edited_pack) @@ -322,6 +323,7 @@ CustomPackDialog::CustomPackDialog(Window* parent, const SetP& set, const PackTy // init ui totals = new PackTotalsPanel(this, wxID_ANY, generator, true); name = new wxTextCtrl(this, wxID_ANY, edited_pack ? edited_pack->name : _("custom pack")); + wxButton* remove = new wxButton(this, ID_REMOVE_ITEM, _BUTTON_("remove item")); // init sizer wxSizer* s = new wxBoxSizer(wxVERTICAL); wxSizer* s2 = new wxStaticBoxSizer(wxHORIZONTAL, this, _LABEL_("pack name")); @@ -338,7 +340,10 @@ CustomPackDialog::CustomPackDialog(Window* parent, const SetP& set, const PackTy s5->Add(totals, 1, wxEXPAND | wxALL, 4); s3->Add(s5, 1, wxEXPAND | wxLEFT, 8); s->Add(s3, 0, wxEXPAND | wxALL & ~wxTOP, 8); - s->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxEXPAND | wxALL & ~wxTOP, 8); + wxSizer* s6 = new wxBoxSizer(wxHORIZONTAL); + s6->Add(remove, 0, wxALL & ~wxTOP & ~wxRIGHT, 8); + s6->Add(CreateButtonSizer(wxOK | wxCANCEL), 1, wxALL & ~wxTOP, 8); + s->Add(s6, 0, wxEXPAND); // add spin controls FOR_EACH(pack, set->game->pack_types) { if (pack->selectable) continue; // this pack is already selectable from the main UI @@ -392,12 +397,17 @@ void CustomPackDialog::onOk(wxCommandEvent&) { storePack(); EndModal(wxID_OK); } +void CustomPackDialog::onRemove(wxCommandEvent&) { + edited_pack = PackTypeP(); + EndModal(wxID_OK); +} void CustomPackDialog::onAmountChange(wxSpinEvent&) { updateTotals(); } BEGIN_EVENT_TABLE(CustomPackDialog, wxDialog) EVT_BUTTON (wxID_OK, CustomPackDialog::onOk) + EVT_BUTTON (ID_REMOVE_ITEM, CustomPackDialog::onRemove) EVT_SPINCTRL (ID_PACK_AMOUNT, CustomPackDialog::onAmountChange) END_EVENT_TABLE() @@ -578,18 +588,21 @@ void RandomPackPanel::onCommand(int id) { } } void RandomPackPanel::onPackTypeClick(wxCommandEvent& ev) { - for (size_t i = 0 ; i < pickers.size() ; ++i) { - const PackAmountPicker& pick = pickers[i]; + FOR_EACH(pick, pickers) { if (pick.label == ev.GetEventObject()) { // edit this pack type CustomPackDialog dlg(this, set, pick.pack); if (dlg.ShowModal() == wxID_OK) { if (dlg.get()) { + // update pack + for (size_t i = 0 ; i < set->pack_types.size() ; ++i) { + if (set->pack_types[i] == pick.pack) { + set->actions.addAction( new ChangePackAction(*set,i,dlg.get()) ); + } + } + } else { // delete pack set->actions.addAction( new AddPackAction(REMOVE,*set,pick.pack) ); - } else { - // update pack - set->actions.addAction( new ChangePackAction(*set,i,dlg.get()) ); } } break; diff --git a/src/script/scriptable.cpp b/src/script/scriptable.cpp index 64105fac..d6d7e853 100644 --- a/src/script/scriptable.cpp +++ b/src/script/scriptable.cpp @@ -90,7 +90,9 @@ template <> void Reader::handle(OptionalScript& os) { } template <> void Writer::handle(const OptionalScript& os) { - handle(os.unparsed); + if (os.script) { + handle(os.unparsed); + } } template <> void GetDefaultMember::handle(const OptionalScript& os) {