Commit ac81c734 authored by twanvl's avatar twanvl

adding & editing custom pack types now works.

parent 7cda5e66
...@@ -201,6 +201,8 @@ help: ...@@ -201,6 +201,8 @@ help:
random seed: Different packs will be generated each time. random seed: Different packs will be generated each time.
fixed seed: Using the same seed number gives the same 'random' packs. fixed seed: Using the same seed number gives the same 'random' packs.
seed: Seed number for the random generator. Using the same seed number gives the same 'random' packs. seed: Seed number for the random generator. Using the same seed number gives the same 'random' packs.
edit pack type: Double click to edit pack type
number of packs: The number of %ss to generate
# Preferences # Preferences
app language: app language:
...@@ -426,6 +428,7 @@ label: ...@@ -426,6 +428,7 @@ label:
# Random pack panel # Random pack panel
pack selection: Pack selection pack selection: Pack selection
pack totals: Totals pack totals: Totals
pack name: Pack name
seed: Seed seed: Seed
total cards: Total total cards: Total
...@@ -552,6 +555,7 @@ button: ...@@ -552,6 +555,7 @@ button:
generate pack: &Generate Pack generate pack: &Generate Pack
random seed: &Random Seed random seed: &Random Seed
fixed seed: &Fixed Seed fixed seed: &Fixed Seed
add custom pack: Add &Custom Pack...
# Welcome # Welcome
new set: New set new set: New set
...@@ -641,6 +645,8 @@ title: ...@@ -641,6 +645,8 @@ title:
select cards export:Select Cards to Export select cards export:Select Cards to Export
# slice # slice
slice image: Slice Image slice image: Slice Image
# pack
custom pack: Custom Pack Type
# print # print
print preview: Print Preview print preview: Print Preview
# export # export
...@@ -824,6 +830,7 @@ type: ...@@ -824,6 +830,7 @@ type:
value: value value: value
keyword: keyword keyword: keyword
keywords: keywords keywords: keywords
pack: pack type
# Symbol editor shapes # Symbol editor shapes
shape: shape shape: shape
......
...@@ -10,11 +10,13 @@ ...@@ -10,11 +10,13 @@
#include <data/action/set.hpp> #include <data/action/set.hpp>
#include <data/set.hpp> #include <data/set.hpp>
#include <data/card.hpp> #include <data/card.hpp>
#include <data/pack.hpp>
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <util/error.hpp> #include <util/error.hpp>
DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>); DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>);
DECLARE_TYPEOF_COLLECTION(CardP); DECLARE_TYPEOF_COLLECTION(CardP);
DECLARE_TYPEOF_COLLECTION(PackTypeP);
DECLARE_TYPEOF_COLLECTION(int); DECLARE_TYPEOF_COLLECTION(int);
// ----------------------------------------------------------------------------- : Add card // ----------------------------------------------------------------------------- : Add card
...@@ -135,3 +137,32 @@ void ChangeCardHasStylingAction::perform(bool to_undo) { ...@@ -135,3 +137,32 @@ void ChangeCardHasStylingAction::perform(bool to_undo) {
card->has_styling = !card->has_styling; card->has_styling = !card->has_styling;
swap(card->styling_data, styling_data); swap(card->styling_data, styling_data);
} }
// ----------------------------------------------------------------------------- : Pack types
AddPackAction::AddPackAction(AddingOrRemoving ar, Set& set, const PackTypeP& pack)
: PackTypesAction(set)
, action(ar, pack, set.pack_types)
{}
String AddPackAction::getName(bool to_undo) const {
return action.getName();
}
void AddPackAction::perform(bool to_undo) {
action.perform(set.pack_types, to_undo);
}
ChangePackAction::ChangePackAction(Set& set, size_t pos, const PackTypeP& pack)
: PackTypesAction(set)
, pos(pos), pack(pack)
{}
String ChangePackAction::getName(bool to_undo) const {
return _ACTION_1_("change",type_name(pack));
}
void ChangePackAction::perform(bool to_undo) {
swap(set.pack_types.at(pos), pack);
}
...@@ -23,7 +23,9 @@ DECLARE_POINTER_TYPE(Card); ...@@ -23,7 +23,9 @@ DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(StyleSheet); DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(PackType);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<CardP>::Step); DECLARE_TYPEOF_COLLECTION(GenericAddAction<CardP>::Step);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<PackTypeP>::Step);
// ----------------------------------------------------------------------------- : Add card // ----------------------------------------------------------------------------- : Add card
...@@ -119,5 +121,43 @@ class ChangeCardHasStylingAction : public DisplayChangeAction { ...@@ -119,5 +121,43 @@ class ChangeCardHasStylingAction : public DisplayChangeAction {
IndexMap<FieldP,ValueP> styling_data; ///< The old styling of the card IndexMap<FieldP,ValueP> styling_data; ///< The old styling of the card
}; };
// ----------------------------------------------------------------------------- : Pack types
/// An Action the changes the pack types of a set
class PackTypesAction : public Action {
public:
inline PackTypesAction(Set& set) : set(set) {}
protected:
Set& set; // the set owns this action, so the set will not be destroyed before this
// therefore we don't need a smart pointer
};
/// Adding/removing a pack from a Set
class AddPackAction : public PackTypesAction {
public:
/// Add a newly allocated card
AddPackAction(AddingOrRemoving, Set& set, const PackTypeP& pack);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
const GenericAddAction<PackTypeP> action;
};
/// Updating a pack in a Set
class ChangePackAction : public PackTypesAction {
public:
/// Add a newly allocated card
ChangePackAction(Set& set, size_t pos, const PackTypeP& new_pack);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
private:
PackTypeP pack;
size_t pos;
};
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
...@@ -55,7 +55,7 @@ IMPLEMENT_REFLECTION(Game) { ...@@ -55,7 +55,7 @@ IMPLEMENT_REFLECTION(Game) {
REFLECT_NO_SCRIPT(statistics_dimensions); REFLECT_NO_SCRIPT(statistics_dimensions);
REFLECT_NO_SCRIPT(statistics_categories); REFLECT_NO_SCRIPT(statistics_categories);
#if USE_NEW_PACK_SYSTEM #if USE_NEW_PACK_SYSTEM
REFLECT_ALIAS(307, "pack item", "pack type"); REFLECT_ALIAS(308, "pack item", "pack type");
#else #else
REFLECT_NO_SCRIPT(pack_items); REFLECT_NO_SCRIPT(pack_items);
#endif #endif
......
...@@ -454,6 +454,13 @@ PackInstance& PackGenerator::get(const String& name) { ...@@ -454,6 +454,13 @@ PackInstance& PackGenerator::get(const String& name) {
if (instance) { if (instance) {
return *instance; return *instance;
} else { } else {
FOR_EACH_CONST(type, set->pack_types) {
if (type->name == name) {
instance = PackInstanceP(new PackInstance(*type,*this));
max_depth = max(max_depth, instance->get_depth());
return *instance;
}
}
FOR_EACH_CONST(type, set->game->pack_types) { FOR_EACH_CONST(type, set->game->pack_types) {
if (type->name == name) { if (type->name == name) {
instance = PackInstanceP(new PackInstance(*type,*this)); instance = PackInstanceP(new PackInstance(*type,*this));
...@@ -481,6 +488,13 @@ void PackGenerator::generate(vector<CardP>& out) { ...@@ -481,6 +488,13 @@ void PackGenerator::generate(vector<CardP>& out) {
i.generate(&out); i.generate(&out);
} }
} }
// ...and then set file order
FOR_EACH_CONST(type, set->pack_types) {
PackInstance& i = get(type);
if (i.get_depth() == depth) {
i.generate(&out);
}
}
} }
} }
......
...@@ -166,6 +166,9 @@ class PackItem : public IntrusivePtrBase<PackItem> { ...@@ -166,6 +166,9 @@ class PackItem : public IntrusivePtrBase<PackItem> {
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
inline String type_name(const PackType&) {
return _TYPE_("pack");
}
// ----------------------------------------------------------------------------- : Generating / counting // ----------------------------------------------------------------------------- : Generating / counting
......
...@@ -181,6 +181,7 @@ IMPLEMENT_REFLECTION(Set) { ...@@ -181,6 +181,7 @@ IMPLEMENT_REFLECTION(Set) {
} }
REFLECT(cards); REFLECT(cards);
REFLECT(keywords); REFLECT(keywords);
REFLECT(pack_types);
} }
reflect_set_info_get_member(tag,data); reflect_set_info_get_member(tag,data);
REFLECT(apprentice_code); REFLECT(apprentice_code);
......
...@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Styling); ...@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Styling);
DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value); DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(Keyword); DECLARE_POINTER_TYPE(Keyword);
DECLARE_POINTER_TYPE(PackType);
DECLARE_POINTER_TYPE(ScriptValue); DECLARE_POINTER_TYPE(ScriptValue);
class SetScriptManager; class SetScriptManager;
class SetScriptContext; class SetScriptContext;
...@@ -45,19 +46,21 @@ class Set : public Packaged { ...@@ -45,19 +46,21 @@ class Set : public Packaged {
/// Create a set using the given stylesheet, and its game /// Create a set using the given stylesheet, and its game
Set(const StyleSheetP& stylesheet); Set(const StyleSheetP& stylesheet);
~Set(); ~Set();
GameP game; ///< The game this set uses GameP game; ///< The game this set uses
StyleSheetP stylesheet; ///< The default stylesheet StyleSheetP stylesheet; ///< The default stylesheet
/// The values on the fields of the set /// The values on the fields of the set
/** The indices should correspond to the set_fields in the Game */ /** The indices should correspond to the set_fields in the Game */
IndexMap<FieldP, ValueP> data; IndexMap<FieldP, ValueP> data;
/// Extra values for specitic stylesheets, indexed by stylesheet name /// Extra values for specitic stylesheets, indexed by stylesheet name
DelayedIndexMaps<FieldP,ValueP> styling_data; DelayedIndexMaps<FieldP,ValueP> styling_data;
vector<CardP> cards; ///< The cards in the set vector<CardP> cards; ///< The cards in the set
vector<KeywordP> keywords; ///< Additional keywords used in this set vector<KeywordP> keywords; ///< Additional keywords used in this set
String apprentice_code; ///< Code to use for apprentice (Magic only) vector<PackTypeP> pack_types; ///< Additional/replacement pack types
ActionStack actions; ///< Actions performed on this set and the cards in it String apprentice_code; ///< Code to use for apprentice (Magic only)
KeywordDatabase keyword_db; ///< Database for matching keywords, must be cleared when keywords change
ActionStack actions; ///< Actions performed on this set and the cards in it
KeywordDatabase keyword_db; ///< Database for matching keywords, must be cleared when keywords change
/// A context for performing scripts /// A context for performing scripts
/** Should only be used from the main thread! */ /** Should only be used from the main thread! */
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <gui/control/filtered_card_list.hpp> #include <gui/control/filtered_card_list.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <gui/about_window.hpp> // HoverButtonBase #include <gui/about_window.hpp> // HoverButtonBase
#include <data/action/set.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/pack.hpp> #include <data/pack.hpp>
#include <data/settings.hpp> #include <data/settings.hpp>
...@@ -279,9 +280,9 @@ PackAmountPicker::PackAmountPicker(wxWindow* parent, wxFlexGridSizer* sizer, con ...@@ -279,9 +280,9 @@ PackAmountPicker::PackAmountPicker(wxWindow* parent, wxFlexGridSizer* sizer, con
sizer->Add(label, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); sizer->Add(label, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
sizer->Add(value, 0, wxEXPAND | wxALIGN_CENTER); sizer->Add(value, 0, wxEXPAND | wxALIGN_CENTER);
if (active) { if (active) {
label->SetHelpText(_("Double click to edit.")); label->SetHelpText(_HELP_("edit pack type"));
} }
set_help_text(value, _("The number of ") + pack->name + _("s to use.")); set_help_text(value, _HELP_1_("number of packs", pack->name));
} }
void PackAmountPicker::destroy(wxFlexGridSizer* sizer) { void PackAmountPicker::destroy(wxFlexGridSizer* sizer) {
...@@ -434,9 +435,9 @@ void RandomPackPanel::initControls() { ...@@ -434,9 +435,9 @@ void RandomPackPanel::initControls() {
wxSizer* s4b = new wxBoxSizer(wxHORIZONTAL); wxSizer* s4b = new wxBoxSizer(wxHORIZONTAL);
packsSizer = new wxFlexGridSizer(0, 2, 4, 4); packsSizer = new wxFlexGridSizer(0, 2, 4, 4);
packsSizer->AddGrowableCol(0); packsSizer->AddGrowableCol(0);
s4b->Add(packsSizer, 1, wxEXPAND | wxALL & ~wxTOP & ~wxBOTTOM & ~wxLEFT, 4); s4b->Add(packsSizer, 1, wxEXPAND | wxALL & ~wxTOP & ~wxLEFT, 4);
s4->Add(s4b, 1, wxEXPAND | wxLEFT, 2); s4->Add(s4b, 1, wxEXPAND | wxLEFT, 2);
s4->Add(new wxButton(this, ID_CUSTOM_PACK, _BUTTON_("custom pack")), 0, wxEXPAND | wxALL & ~wxTOP, 4); s4->Add(new wxButton(this, ID_CUSTOM_PACK, _BUTTON_("add custom pack")), 0, wxEXPAND | wxALIGN_TOP | 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); s5->Add(totals, 1, wxEXPAND | wxALL, 4);
...@@ -480,15 +481,22 @@ void RandomPackPanel::onChangeSet() { ...@@ -480,15 +481,22 @@ void RandomPackPanel::onChangeSet() {
pickers.clear(); pickers.clear();
// add pack controls // add pack controls
#if USE_NEW_PACK_SYSTEM
FOR_EACH(pack, set->game->pack_types) { FOR_EACH(pack, set->game->pack_types) {
#if USE_NEW_PACK_SYSTEM
if (pack->selectable) { if (pack->selectable) {
#endif pickers.push_back(PackAmountPicker(this,packsSizer,pack,false));
pickers.push_back(PackAmountPicker(this,packsSizer,pack));
#if USE_NEW_PACK_SYSTEM
} }
#endif
} }
FOR_EACH(pack, set->pack_types) {
if (pack->selectable) {
pickers.push_back(PackAmountPicker(this,packsSizer,pack,true));
}
}
#else
FOR_EACH(pack, set->game->pack_types) {
pickers.push_back(PackAmountPicker(this,packsSizer,pack,false));
}
#endif
Layout(); Layout();
...@@ -508,6 +516,14 @@ void RandomPackPanel::onChangeSet() { ...@@ -508,6 +516,14 @@ void RandomPackPanel::onChangeSet() {
updateTotals(); updateTotals();
} }
void RandomPackPanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, PackTypesAction) {
// rebuild the list
storeSettings();
onChangeSet();
}
}
void RandomPackPanel::storeSettings() { void RandomPackPanel::storeSettings() {
if (!isInitialized()) return; if (!isInitialized()) return;
GameSettings& gs = settings.gameSettingsFor(*set->game); GameSettings& gs = settings.gameSettingsFor(*set->game);
...@@ -555,19 +571,26 @@ void RandomPackPanel::onCommand(int id) { ...@@ -555,19 +571,26 @@ void RandomPackPanel::onCommand(int id) {
case ID_CUSTOM_PACK: { case ID_CUSTOM_PACK: {
CustomPackDialog dlg(this, set, PackTypeP()); CustomPackDialog dlg(this, set, PackTypeP());
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
// TODO: add pack set->actions.addAction( new AddPackAction(ADD,*set,dlg.get()) );
} }
break; break;
} }
} }
} }
void RandomPackPanel::onPackTypeClick(wxCommandEvent& ev) { void RandomPackPanel::onPackTypeClick(wxCommandEvent& ev) {
FOR_EACH(pick,pickers) { for (size_t i = 0 ; i < pickers.size() ; ++i) {
const PackAmountPicker& pick = pickers[i];
if (pick.label == ev.GetEventObject()) { if (pick.label == ev.GetEventObject()) {
// edit this pack type // edit this pack type
CustomPackDialog dlg(this, set, pick.pack); CustomPackDialog dlg(this, set, pick.pack);
if (dlg.ShowModal() == wxID_OK) { if (dlg.ShowModal() == wxID_OK) {
// TODO: update pack if (dlg.get()) {
// delete pack
set->actions.addAction( new AddPackAction(REMOVE,*set,pick.pack) );
} else {
// update pack
set->actions.addAction( new ChangePackAction(*set,i,dlg.get()) );
}
} }
break; break;
} }
......
...@@ -30,7 +30,7 @@ struct PackAmountPicker { ...@@ -30,7 +30,7 @@ struct PackAmountPicker {
wxSpinCtrl* value; wxSpinCtrl* value;
PackAmountPicker() {} PackAmountPicker() {}
PackAmountPicker(wxWindow* parent, wxFlexGridSizer* sizer, const PackTypeP& pack, bool active = true); PackAmountPicker(wxWindow* parent, wxFlexGridSizer* sizer, const PackTypeP& pack, bool interactive);
void destroy(wxFlexGridSizer* sizer); void destroy(wxFlexGridSizer* sizer);
}; };
...@@ -46,6 +46,7 @@ class RandomPackPanel : public SetWindowPanel { ...@@ -46,6 +46,7 @@ class RandomPackPanel : public SetWindowPanel {
virtual void onBeforeChangeSet(); virtual void onBeforeChangeSet();
virtual void onChangeSet(); virtual void onChangeSet();
virtual void onAction(const Action&, bool undone);
virtual void initUI (wxToolBar* tb, wxMenuBar* mb); virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb); virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
......
# This file contains the keys expected to be in MSE locales # This file contains the keys expected to be in MSE locales
# It was automatically generated by tools/locale/locale.pl # It was automatically generated by tools/locale/locale.pl
# Generated on Tue Dec 30 20:45:27 2008 # Generated on Sat Jan 10 02:30:34 2009
action: action:
add control point: 0 add control point: 0
...@@ -40,6 +40,7 @@ action: ...@@ -40,6 +40,7 @@ action:
typing: 0 typing: 0
ungroup parts: 0 ungroup parts: 0
button: button:
add custom pack: 0
add item: 0 add item: 0
always: 0 always: 0
browse: 0 browse: 0
...@@ -179,6 +180,7 @@ help: ...@@ -179,6 +180,7 @@ help:
draw rectangle: 0 draw rectangle: 0
draw star: 0 draw star: 0
duplicate: 0 duplicate: 0
edit pack type: 0
ellipse: 0 ellipse: 0
exit: 0 exit: 0
expand notes: 0 expand notes: 0
...@@ -208,6 +210,7 @@ help: ...@@ -208,6 +210,7 @@ help:
next card: 0 next card: 0
next keyword: 0 next keyword: 0
no spelling suggestions: 0 no spelling suggestions: 0
number of packs: 1
open set: 0 open set: 0
open symbol: 0 open symbol: 0
orientation: 0 orientation: 0
...@@ -306,6 +309,7 @@ label: ...@@ -306,6 +309,7 @@ label:
no version: 0 no version: 0
original: 0 original: 0
original size: 0 original size: 0
pack name: 0
pack selection: 0 pack selection: 0
pack totals: 0 pack totals: 0
package action: 0 package action: 0
...@@ -443,6 +447,7 @@ title: ...@@ -443,6 +447,7 @@ title:
about: 0 about: 0
auto replaces: 0 auto replaces: 0
cannot create file: 0 cannot create file: 0
custom pack: 0
directories: 0 directories: 0
display: 0 display: 0
export cancelled: 0 export cancelled: 0
...@@ -589,6 +594,7 @@ type: ...@@ -589,6 +594,7 @@ type:
locale: optional, 0 locale: optional, 0
nil: 0 nil: 0
object: 0 object: 0
pack: 0
package: optional, 0 package: optional, 0
pentagon: 0 pentagon: 0
point: 0 point: 0
......
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