2 #include "choicecondition.h"
4 #include "rangecondition.h"
18 Category::Category(const Category &other):
19 condition(other.condition ? other.condition->clone() : 0),
20 font_size(other.font_size),
21 border_color(other.border_color),
23 sound_type(other.sound_type),
24 sound_volume(other.sound_volume)
27 Category &Category::operator=(const Category &other)
30 condition = (other.condition ? other.condition->clone() : 0);
31 font_size = other.font_size;
32 border_color = other.border_color;
34 sound_type = other.sound_type;
35 sound_volume = other.sound_volume;
44 void Category::create_statements(list<FilterStatement> &st, const Theme &theme) const
47 st.push_back(FilterStatement());
48 st.back().add_line(format("SetFontSize %d", static_cast<int>(font_size*theme.get_base_font_size()+0.5)));
49 if(!border_color.empty())
51 const Color &color = theme.get_color(border_color);
52 st.back().add_line(format("SetBorderColor %d %d %d", color.r, color.g, color.b));
55 st.back().add_line(format("PlayAlertSound %d %d", sound_type, sound_volume));
57 condition->add_lines(st);
61 Category::Loader::Loader(Category &c, CompoundCondition *n):
62 DataFile::ObjectLoader<Category>(c),
65 add("alert_sound", &Category::sound_type, &Category::sound_volume);
66 add("and", &Loader::and_);
67 add("base_type", &Loader::condition<BaseTypeCondition>);
68 add("border_color", &Category::border_color);
69 add("class", &Loader::condition<ClassCondition>);
70 add_range<DropLevelCondition>("drop_level");
71 add("font_size", &Category::font_size);
72 add_range<HeightCondition>("height");
73 add_range<ItemLevelCondition>("item_level");
74 add("linked_colors", &Loader::linked_colors);
75 add_range<LinkedSocketsCondition>("linked_sockets");
76 add_range<SocketsCondition>("sockets");
77 add("or", &Loader::or_);
78 add("order", &Category::order);
79 add_range<QualityCondition>("quality");
80 add_range<RarityCondition>("rarity");
81 add_range<WidthCondition>("width");
85 void Category::Loader::add_range(const string &keyword)
87 add(keyword, &Loader::condition<T>);
88 add(keyword, &Loader::condition_range<T>);
89 add("min_"+keyword, &Loader::condition_min<T>);
90 add("max_"+keyword, &Loader::condition_max<T>);
93 void Category::Loader::add_condition(Condition *cond)
97 else if(!obj.condition)
101 compound = new AndCondition;
102 compound->add(obj.condition);
104 obj.condition = compound;
108 void Category::Loader::and_()
110 RefPtr<AndCondition> cond = new AndCondition;
111 Loader sub_ldr(obj, cond.get());
112 load_sub_with(sub_ldr);
113 add_condition(cond.release());
117 void Category::Loader::condition(typename T::Type value)
119 add_condition(new T(value));
123 void Category::Loader::condition_max(typename T::Type max)
125 add_condition(new T(T::Traits::get_min(), max));
129 void Category::Loader::condition_min(typename T::Type min)
131 add_condition(new T(min, T::Traits::get_max()));
135 void Category::Loader::condition_range(typename T::Type min, typename T::Type max)
137 add_condition(new T(min, max));
140 void Category::Loader::linked_colors(const LinkedColorsCondition::Colors &colors)
142 add_condition(new LinkedColorsCondition(colors));
145 void Category::Loader::or_()
147 RefPtr<OrCondition> cond = new OrCondition;
148 Loader sub_ldr(obj, cond.get());
149 load_sub_with(sub_ldr);
150 add_condition(cond.release());