Added new sort options for special rarity

Added "sort script" field
BUG: Dependencies are not correctly updated for collection sorting, so card numbers don't update properly.


git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@546 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
coppro
2007-07-10 16:44:43 +00:00
parent fb428ee66e
commit fa21bee0b1
12 changed files with 92 additions and 50 deletions
+3 -1
View File
@@ -55,6 +55,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_visible);
REFLECT(card_list_allow);
REFLECT(card_list_name);
REFLECT(sort_script);
REFLECT_IF_READING if(card_list_name.empty()) card_list_name = name;
REFLECT_N("card_list_alignment", card_list_align);
REFLECT(tab_index);
@@ -215,7 +216,8 @@ bool Value::equals(const Value* that) {
}
void init_object(const FieldP& field, ValueP& value) {
if (!value) value = field->newValue(field);
if (!value)
value = field->newValue(field);
}
template <> ValueP read_new<Value>(Reader&) {
throw InternalError(_("IndexMap contains nullptr ValueP the application should have crashed already"));
+15 -2
View File
@@ -54,6 +54,7 @@ class Field : public IntrusivePtrVirtualBase {
bool card_list_allow; ///< Is this field allowed to appear in the card list?
String card_list_name; ///< Alternate name to use in card list.
Alignment card_list_align; ///< Alignment of the card list colummn.
OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
int tab_index; ///< Tab index in editor
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
@@ -67,7 +68,9 @@ class Field : public IntrusivePtrVirtualBase {
virtual String typeName() const = 0;
/// Add the given dependency to the dependet_scripts list for the variables this field depends on
virtual void initDependencies(Context&, const Dependency&) const {}
inline virtual void initDependencies(Context& ctx, const Dependency& dep) const {
sort_script.initDependencies(ctx, dep);
}
private:
DECLARE_REFLECTION_VIRTUAL();
@@ -183,6 +186,7 @@ class Value : public IntrusivePtrVirtualBase {
const FieldP fieldP; ///< Field this value is for, should have the right type!
Age last_script_update; ///< When where the scripts last updated? (by calling update)
ScriptValueP sortValue; ///< How this should be sorted.
/// Get a copy of this value
virtual ValueP clone() const = 0;
@@ -190,7 +194,11 @@ class Value : public IntrusivePtrVirtualBase {
/// Convert this value to a string for use in tables
virtual String toString() const = 0;
/// Apply scripts to this value, return true if the value has changed
virtual bool update(Context&) { last_script_update.update(); return false; }
inline virtual bool update(Context& ctx) {
sortValue = fieldP->sort_script.invoke(ctx);
last_script_update.update();
return false;
}
/// This value has been updated by an action
/** Does nothing for most Values, only FakeValues can update underlying data */
virtual void onAction(Action& a, bool undone) {}
@@ -199,6 +207,11 @@ class Value : public IntrusivePtrVirtualBase {
* In that case, afterwards this becomes equal to that if they use the same underlying object.
*/
virtual bool equals(const Value* that);
/// Get the sort key for this value.
inline String getSortKey () const {
return sortValue == script_nil ? *sortValue : toString();
}
private:
DECLARE_REFLECTION_VIRTUAL();
+2
View File
@@ -8,6 +8,8 @@
#include <data/field/choice.hpp>
#include <util/io/package.hpp>
#include <wx/spinctrl.h>
#include <wx/imaglist.h>
DECLARE_TYPEOF_COLLECTION(ChoiceField::ChoiceP);
DECLARE_TYPEOF(map<String COMMA ScriptableImage>);
+1
View File
@@ -65,6 +65,7 @@ class BlankImage : public GeneratedImage {
public:
virtual Image generate(const Options&) const;
virtual bool operator == (const GeneratedImage& that) const;
virtual bool threadSafe() const { return false; };
};
// ----------------------------------------------------------------------------- : LinearBlendImage
+1 -1
View File
@@ -176,7 +176,7 @@ bool CardListBase::compareItems(void* a, void* b) const {
ValueP va = reinterpret_cast<Card*>(a)->data[sort_field];
ValueP vb = reinterpret_cast<Card*>(b)->data[sort_field];
if (!va || !vb) return va < vb; // got to do something, compare pointers
return smart_less( va->toString() , vb->toString() );
return smart_less( va->getSortKey(), vb->getSortKey() );
}
void CardListBase::rebuild() {
+1
View File
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <data/symbol.hpp>
#include <wx/imaglist.h>
class SymbolPartsSelection;
+1
View File
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <gui/symbol/editor.hpp>
#include <wx/spinctrl.h>
class SymmetryMoveAction;
+5 -5
View File
@@ -50,7 +50,7 @@ typedef shared_ptr<wxMemoryDC> MemoryDCP;
// Return a temporary DC with the same size as the parameter
MemoryDCP getTempDC(DC& dc) {
wxSize s = dc.GetSize();
Bitmap buffer(s.GetWidth(), s.GetHeight(), 1);
Bitmap buffer(s.GetWidth(), s.GetHeight(), 24);
MemoryDCP newDC(new wxMemoryDC);
newDC->SelectObject(buffer);
clearDC(*newDC, *wxBLACK_BRUSH);
@@ -161,10 +161,10 @@ void SymbolViewer::combineSymbolPart(DC& dc, const SymbolPart& part, bool& paint
// Matrix2D rot(cos(a),-sin(a), sin(a),cos(a));
//
// ref * rot
// /cos b sin b\ /cos a -sin a\
// = \sin b -cos b/ \sin a cos a/
// = /cos(a+b) sin(a+b)\
// \sin(a+b) -cos(a+b)/
// /cos b sin b\ /cos a -sin a\;
// = \sin b -cos b/ \sin a cos a/;s
// = /cos(a+b) sin(a+b)\;
// \sin(a+b) -cos(a+b)/;
Matrix2D rot(cos(a+b),sin(a+b), sin(a+b),-cos(a+b));
multiply.mx = rot.mx * old_m;
multiply.my = rot.my * old_m;
+1 -1
View File
@@ -67,7 +67,7 @@ class SymbolViewer : public SymbolView {
int in_symmetry;
/// Combine a symbol part with the dc
void SymbolViewer::combineSymbolPart(DC& dc, const SymbolPart& part, bool& paintedSomething, bool& buffersFilled, bool allow_overlap, MemoryDCP& borderDC, MemoryDCP& interiorDC);
void combineSymbolPart(DC& dc, const SymbolPart& part, bool& paintedSomething, bool& buffersFilled, bool allow_overlap, MemoryDCP& borderDC, MemoryDCP& interiorDC);
/// Combines a symbol part with what is currently drawn, the border and interior are drawn separatly
/** directB/directI are true if the border/interior is the screen dc, false if it
+4 -4
View File
@@ -229,7 +229,7 @@ void SetScriptManager::updateStyles(Context& ctx, const IndexMap<FieldP,StyleP>&
s->tellListeners(only_content_dependent);
}
} catch (const ScriptError& e) {
throw ScriptError(e.what() + _("\n while updating styles for '") + s->fieldP->name + _("'"));
handle_error(ScriptError(e.what() + _("\n while updating styles for '") + s->fieldP->name + _("'")));
}
}
}
@@ -267,7 +267,7 @@ void SetScriptManager::updateAll() {
try {
v->update(ctx);
} catch (const ScriptError& e) {
throw ScriptError(e.what() + _("\n while updating set value '") + v->fieldP->name + _("'"));
handle_error(ScriptError(e.what() + _("\n while updating set value '") + v->fieldP->name + _("'")));
}
}
// update card data of all cards
@@ -277,7 +277,7 @@ void SetScriptManager::updateAll() {
try {
v->update(ctx);
} catch (const ScriptError& e) {
throw ScriptError(e.what() + _("\n while updating card value '") + v->fieldP->name + _("'"));
handle_error(ScriptError(e.what() + _("\n while updating card value '") + v->fieldP->name + _("'")));
}
}
}
@@ -311,7 +311,7 @@ void SetScriptManager::updateToUpdate(const ToUpdate& u, deque<ToUpdate>& to_upd
try {
changes = u.value->update(ctx);
} catch (const ScriptError& e) {
throw ScriptError(e.what() + _("\n while updating value '") + u.value->fieldP->name + _("'"));
handle_error(ScriptError(e.what() + _("\n while updating value '") + u.value->fieldP->name + _("'")));
}
if (changes) {
// changed, send event