]> git.tdb.fi Git - poefilter.git/blobdiff - source/category.cpp
Revamp appearance definitions
[poefilter.git] / source / category.cpp
index 2ea4818b9ae460871b520fc84504fcd4f450b8e4..8b0d442ea8d572c016fe4f01fb9c891109b23ffd 100644 (file)
@@ -1,6 +1,7 @@
 #include "category.h"
 #include "choicecondition.h"
 #include "filter.h"
+#include "poefilter.h"
 #include "rangecondition.h"
 #include "theme.h"
 
@@ -9,30 +10,21 @@ using namespace Msp;
 
 Category::Category():
        condition(0),
-       font_size(1.0f),
-       order(0),
-       sound_type(0),
-       sound_volume(100)
+       order(0)
 { }
 
 Category::Category(const Category &other):
        condition(other.condition ? other.condition->clone() : 0),
-       font_size(other.font_size),
-       border_color(other.border_color),
        order(other.order),
-       sound_type(other.sound_type),
-       sound_volume(other.sound_volume)
+       appearance(other.appearance)
 { }
 
 Category &Category::operator=(const Category &other)
 {
        delete condition;
        condition = (other.condition ? other.condition->clone() : 0);
-       font_size = other.font_size;
-       border_color = other.border_color;
        order = other.order;
-       sound_type = other.sound_type;
-       sound_volume = other.sound_volume;
+       appearance = other.appearance;
        return *this;
 }
 
@@ -41,34 +33,43 @@ Category::~Category()
        delete condition;
 }
 
-void Category::create_statements(list<FilterStatement> &st, const Theme &theme) const
+void Category::create_statements(list<FilterStatement> &st) const
 {
        st.clear();
        st.push_back(FilterStatement());
-       st.back().add_line(format("SetFontSize %d", static_cast<int>(font_size*theme.get_base_font_size()+0.5)));
-       if(!border_color.empty())
-       {
-               const Color &color = theme.get_color(border_color);
-               st.back().add_line(format("SetBorderColor %d %d %d", color.r, color.g, color.b));
-       }
-       if(sound_type)
-               st.back().add_line(format("PlayAlertSound %d %d", sound_type, sound_volume));
+       st.back().add_line(format("SetFontSize %d", appearance.get_font_size()));
+
+       const Color &bg_color = appearance.get_background_color();
+       if(bg_color.defined)
+               st.back().add_line(format("SetBackgroundColor %d %d %d", bg_color.r, bg_color.g, bg_color.b));
+
+       const Color &brd_color = appearance.get_border_color();
+       if(brd_color.defined)
+               st.back().add_line(format("SetBorderColor %d %d %d", brd_color.r, brd_color.g, brd_color.b));
+
+       const Color &txt_color = appearance.get_text_color();
+       if(txt_color.defined)
+               st.back().add_line(format("SetTextColor %d %d %d", txt_color.r, txt_color.g, txt_color.b));
+
+       if(appearance.get_sound_type())
+               st.back().add_line(format("PlayAlertSound %d %d", appearance.get_sound_type(), appearance.get_sound_volume()));
+
        if(condition)
                condition->add_lines(st);
 }
 
 
-Category::Loader::Loader(Category &c, CompoundCondition *n):
+Category::Loader::Loader(Category &c, const PoeFilter &p, CompoundCondition *n):
        DataFile::ObjectLoader<Category>(c),
-       compound(n)
+       poe(p),
+       compound(n),
+       app_loader(c.appearance, p.get_theme())
 {
-       add("alert_sound", &Category::sound_type, &Category::sound_volume);
        add("and", &Loader::and_);
+       add("appearance", &Loader::appearance);
        add("base_type", &Loader::condition<BaseTypeCondition>);
-       add("border_color", &Category::border_color);
        add("class", &Loader::condition<ClassCondition>);
        add_range<DropLevelCondition>("drop_level");
-       add("font_size", &Category::font_size);
        add_range<HeightCondition>("height");
        add_range<ItemLevelCondition>("item_level");
        add("linked_colors", &Loader::linked_colors);
@@ -79,6 +80,8 @@ Category::Loader::Loader(Category &c, CompoundCondition *n):
        add_range<QualityCondition>("quality");
        add_range<RarityCondition>("rarity");
        add_range<WidthCondition>("width");
+
+       add_auxiliary_loader(app_loader);
 }
 
 template<typename T>
@@ -108,11 +111,16 @@ void Category::Loader::add_condition(Condition *cond)
 void Category::Loader::and_()
 {
        RefPtr<AndCondition> cond = new AndCondition;
-       Loader sub_ldr(obj, cond.get());
+       Loader sub_ldr(obj, poe, cond.get());
        load_sub_with(sub_ldr);
        add_condition(cond.release());
 }
 
+void Category::Loader::appearance(const std::string &name)
+{
+       obj.appearance = poe.get_theme().get_appearance(name);
+}
+
 template<typename T>
 void Category::Loader::condition(typename T::Type value)
 {
@@ -145,7 +153,7 @@ void Category::Loader::linked_colors(const LinkedColorsCondition::Colors &colors
 void Category::Loader::or_()
 {
        RefPtr<OrCondition> cond = new OrCondition;
-       Loader sub_ldr(obj, cond.get());
+       Loader sub_ldr(obj, poe, cond.get());
        load_sub_with(sub_ldr);
        add_condition(cond.release());
 }