Support for extra card fields in stylesheets;

Fixed some bugs:
 - Missing choice images can crash mse.
 - The wrong style is used for making preview choice images on style panel.
FOR_EACH(x, *y.z) should now work without parentheses on linux as well.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@389 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-05-18 21:26:21 +00:00
parent 1c687fdc96
commit 4a6e10ad93
19 changed files with 136 additions and 42 deletions
+31 -12
View File
@@ -41,10 +41,14 @@ void DataViewer::draw(RotatedDC& dc, const Color& background) {
clearDC(dc.getDC(), background);
// update style scripts
try {
Context& ctx = getContext();
FOR_EACH(v, viewers) {
if (v->getStyle()->update(ctx)) {
v->getStyle()->tellListeners();
if (card) {
set->updateStyles(card);
} else {
Context& ctx = getContext();
FOR_EACH(v, viewers) {
if (v->getStyle()->update(ctx)) {
v->getStyle()->tellListeners();
}
}
}
} catch (const Error& e) {
@@ -91,8 +95,9 @@ void DataViewer::setCard(const CardP& card, bool refresh) {
assert(set);
this->card = card;
stylesheet = new_stylesheet;
setStyles(stylesheet, stylesheet->card_style);
setData(card->data);
setStyles(stylesheet, stylesheet->card_style, &stylesheet->extra_card_style);
card->extra_data.init(stylesheet->extra_card_fields); // make sure extra_data is initialized
setData(card->data, &card->extra_data);
onChangeSize();
}
@@ -111,7 +116,7 @@ struct CompareViewer {
}
};
void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles) {
void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles, IndexMap<FieldP,StyleP>* extra_styles) {
if (!viewers.empty() && styles.contains(viewers.front()->getStyle())) {
// already using these styles
return;
@@ -119,6 +124,13 @@ void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP
this->stylesheet = stylesheet;
// create viewers
viewers.clear();
addStyles(styles);
if (extra_styles) addStyles(*extra_styles);
// sort viewers by z-index of style
stable_sort(viewers.begin(), viewers.end(), CompareViewer());
onInit();
}
void DataViewer::addStyles(IndexMap<FieldP,StyleP>& styles) {
FOR_EACH(s, styles) {
if ((s->visible || s->visible.isScripted()) &&
nativeLook() || (
@@ -129,14 +141,21 @@ void DataViewer::setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP
if (viewer) viewers.push_back(viewer);
}
}
// sort viewers by z-index of style
stable_sort(viewers.begin(), viewers.end(), CompareViewer());
onInit();
}
void DataViewer::setData(IndexMap<FieldP,ValueP>& values) {
void DataViewer::setData(IndexMap<FieldP,ValueP>& values, IndexMap<FieldP,ValueP>* extra_values) {
FOR_EACH(v, viewers) {
v->setValue(values[v->getField()]);
// is this field contained in values?
ValueP val = values.tryGet(v->getField());
if (val) {
v->setValue(val);
} else {
// if it is not in values it should be in extra values
assert(extra_values);
val = extra_values->tryGet(v->getField());
assert(val);
v->setValue(val);
}
}
onChange();
}
+5 -2
View File
@@ -72,11 +72,14 @@ class DataViewer : public SetView {
virtual void onChangeSet();
// --------------------------------------------------- : The viewers
private:
/// Create some viewers for the given styles
void addStyles(IndexMap<FieldP,StyleP>& styles);
protected:
/// Set the styles for the data to be shown, recreating the viewers
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles);
void setStyles(const StyleSheetP& stylesheet, IndexMap<FieldP,StyleP>& styles, IndexMap<FieldP,StyleP>* extra_styles = nullptr);
/// Set the data to be shown in the viewers, refresh them
void setData(IndexMap<FieldP,ValueP>& values);
void setData(IndexMap<FieldP,ValueP>& values, IndexMap<FieldP,ValueP>* extra_values = nullptr);
/// Create a viewer for the given style.
/** Can be overloaded to create a ValueEditor instead */