Commit ac81c734 authored by twanvl's avatar twanvl

adding & editing custom pack types now works.

parent 7cda5e66
......@@ -201,6 +201,8 @@ help:
random seed: Different packs will be generated each time.
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.
edit pack type: Double click to edit pack type
number of packs: The number of %ss to generate
# Preferences
app language:
......@@ -426,6 +428,7 @@ label:
# Random pack panel
pack selection: Pack selection
pack totals: Totals
pack name: Pack name
seed: Seed
total cards: Total
......@@ -552,6 +555,7 @@ button:
generate pack: &Generate Pack
random seed: &Random Seed
fixed seed: &Fixed Seed
add custom pack: Add &Custom Pack...
# Welcome
new set: New set
......@@ -641,6 +645,8 @@ title:
select cards export:Select Cards to Export
# slice
slice image: Slice Image
# pack
custom pack: Custom Pack Type
# print
print preview: Print Preview
# export
......@@ -824,6 +830,7 @@ type:
value: value
keyword: keyword
keywords: keywords
pack: pack type
# Symbol editor shapes
shape: shape
......
......@@ -10,11 +10,13 @@
#include <data/action/set.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/pack.hpp>
#include <data/stylesheet.hpp>
#include <util/error.hpp>
DECLARE_TYPEOF_COLLECTION(IndexMap<FieldP COMMA ValueP>);
DECLARE_TYPEOF_COLLECTION(CardP);
DECLARE_TYPEOF_COLLECTION(PackTypeP);
DECLARE_TYPEOF_COLLECTION(int);
// ----------------------------------------------------------------------------- : Add card
......@@ -135,3 +137,32 @@ void ChangeCardHasStylingAction::perform(bool to_undo) {
card->has_styling = !card->has_styling;
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);
DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(PackType);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<CardP>::Step);
DECLARE_TYPEOF_COLLECTION(GenericAddAction<PackTypeP>::Step);
// ----------------------------------------------------------------------------- : Add card
......@@ -119,5 +121,43 @@ class ChangeCardHasStylingAction : public DisplayChangeAction {
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
#endif
......@@ -55,7 +55,7 @@ IMPLEMENT_REFLECTION(Game) {
REFLECT_NO_SCRIPT(statistics_dimensions);
REFLECT_NO_SCRIPT(statistics_categories);
#if USE_NEW_PACK_SYSTEM
REFLECT_ALIAS(307, "pack item", "pack type");
REFLECT_ALIAS(308, "pack item", "pack type");
#else
REFLECT_NO_SCRIPT(pack_items);
#endif
......
......@@ -454,6 +454,13 @@ PackInstance& PackGenerator::get(const String& name) {
if (instance) {
return *instance;
} 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) {
if (type->name == name) {
instance = PackInstanceP(new PackInstance(*type,*this));
......@@ -481,6 +488,13 @@ void PackGenerator::generate(vector<CardP>& 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> {
DECLARE_REFLECTION();
};
inline String type_name(const PackType&) {
return _TYPE_("pack");
}
// ----------------------------------------------------------------------------- : Generating / counting
......
......@@ -181,6 +181,7 @@ IMPLEMENT_REFLECTION(Set) {
}
REFLECT(cards);
REFLECT(keywords);
REFLECT(pack_types);
}
reflect_set_info_get_member(tag,data);
REFLECT(apprentice_code);
......
......@@ -25,6 +25,7 @@ DECLARE_POINTER_TYPE(Styling);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(Keyword);
DECLARE_POINTER_TYPE(PackType);
DECLARE_POINTER_TYPE(ScriptValue);
class SetScriptManager;
class SetScriptContext;
......@@ -55,7 +56,9 @@ class Set : public Packaged {
DelayedIndexMaps<FieldP,ValueP> styling_data;
vector<CardP> cards; ///< The cards in the set
vector<KeywordP> keywords; ///< Additional keywords used in this set
vector<PackTypeP> pack_types; ///< Additional/replacement pack types
String apprentice_code; ///< Code to use for apprentice (Magic only)
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
......
......@@ -12,6 +12,7 @@
#include <gui/control/filtered_card_list.hpp>
#include <gui/util.hpp>
#include <gui/about_window.hpp> // HoverButtonBase
#include <data/action/set.hpp>
#include <data/game.hpp>
#include <data/pack.hpp>
#include <data/settings.hpp>
......@@ -279,9 +280,9 @@ PackAmountPicker::PackAmountPicker(wxWindow* parent, wxFlexGridSizer* sizer, con
sizer->Add(label, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
sizer->Add(value, 0, wxEXPAND | wxALIGN_CENTER);
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) {
......@@ -434,9 +435,9 @@ void RandomPackPanel::initControls() {
wxSizer* s4b = new wxBoxSizer(wxHORIZONTAL);
packsSizer = new wxFlexGridSizer(0, 2, 4, 4);
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(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);
wxSizer* s5 = new wxStaticBoxSizer(wxHORIZONTAL, this, _LABEL_("pack totals"));
s5->Add(totals, 1, wxEXPAND | wxALL, 4);
......@@ -480,15 +481,22 @@ void RandomPackPanel::onChangeSet() {
pickers.clear();
// add pack controls
FOR_EACH(pack, set->game->pack_types) {
#if USE_NEW_PACK_SYSTEM
FOR_EACH(pack, set->game->pack_types) {
if (pack->selectable) {
#endif
pickers.push_back(PackAmountPicker(this,packsSizer,pack));
#if USE_NEW_PACK_SYSTEM
pickers.push_back(PackAmountPicker(this,packsSizer,pack,false));
}
#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();
......@@ -508,6 +516,14 @@ void RandomPackPanel::onChangeSet() {
updateTotals();
}
void RandomPackPanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, PackTypesAction) {
// rebuild the list
storeSettings();
onChangeSet();
}
}
void RandomPackPanel::storeSettings() {
if (!isInitialized()) return;
GameSettings& gs = settings.gameSettingsFor(*set->game);
......@@ -555,19 +571,26 @@ void RandomPackPanel::onCommand(int id) {
case ID_CUSTOM_PACK: {
CustomPackDialog dlg(this, set, PackTypeP());
if (dlg.ShowModal() == wxID_OK) {
// TODO: add pack
set->actions.addAction( new AddPackAction(ADD,*set,dlg.get()) );
}
break;
}
}
}
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()) {
// edit this pack type
CustomPackDialog dlg(this, set, pick.pack);
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;
}
......
......@@ -30,7 +30,7 @@ struct PackAmountPicker {
wxSpinCtrl* value;
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);
};
......@@ -46,6 +46,7 @@ class RandomPackPanel : public SetWindowPanel {
virtual void onBeforeChangeSet();
virtual void onChangeSet();
virtual void onAction(const Action&, bool undone);
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
......
# This file contains the keys expected to be in MSE locales
# 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:
add control point: 0
......@@ -40,6 +40,7 @@ action:
typing: 0
ungroup parts: 0
button:
add custom pack: 0
add item: 0
always: 0
browse: 0
......@@ -179,6 +180,7 @@ help:
draw rectangle: 0
draw star: 0
duplicate: 0
edit pack type: 0
ellipse: 0
exit: 0
expand notes: 0
......@@ -208,6 +210,7 @@ help:
next card: 0
next keyword: 0
no spelling suggestions: 0
number of packs: 1
open set: 0
open symbol: 0
orientation: 0
......@@ -306,6 +309,7 @@ label:
no version: 0
original: 0
original size: 0
pack name: 0
pack selection: 0
pack totals: 0
package action: 0
......@@ -443,6 +447,7 @@ title:
about: 0
auto replaces: 0
cannot create file: 0
custom pack: 0
directories: 0
display: 0
export cancelled: 0
......@@ -589,6 +594,7 @@ type:
locale: optional, 0
nil: 0
object: 0
pack: 0
package: optional, 0
pentagon: 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