--- /dev/null
+#include "appearance.h"
+#include "theme.h"
+
+using namespace std;
+using namespace Msp;
+
+Appearance::Appearance():
+ font_size(32),
+ sound_type(0),
+ sound_volume(100)
+{ }
+
+Appearance::Loader::Loader(Appearance &a, const Theme &t):
+ DataFile::ObjectLoader<Appearance>(a),
+ theme(t)
+{
+ add("alert_sound", &Appearance::sound_type, &Appearance::sound_volume);
+ add("background_color", &Loader::background_color);
+ add("background_color", &Loader::background_color_named);
+ add("border_color", &Loader::border_color);
+ add("border_color", &Loader::border_color_named);
+ add("font_size", &Loader::font_size);
+ add("text_color", &Loader::text_color);
+ add("text_color", &Loader::text_color_named);
+}
+
+void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b)
+{
+ obj.background_color = Color(r, g, b);
+}
+
+void Appearance::Loader::background_color_named(const string &name)
+{
+ obj.background_color = theme.get_color(name);
+}
+
+void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b)
+{
+ obj.border_color = Color(r, g, b);
+}
+
+void Appearance::Loader::border_color_named(const string &name)
+{
+ obj.border_color = theme.get_color(name);
+}
+
+void Appearance::Loader::font_size(float s)
+{
+ obj.font_size = theme.get_base_font_size()*s+0.5f;
+}
+
+void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b)
+{
+ obj.text_color = Color(r, g, b);
+}
+
+void Appearance::Loader::text_color_named(const string &name)
+{
+ obj.text_color = theme.get_color(name);
+}
--- /dev/null
+#ifndef APPEARANCE_H_
+#define APPEARANCE_H_
+
+#include <msp/datafile/objectloader.h>
+#include "color.h"
+
+class Theme;
+
+class Appearance
+{
+public:
+ class Loader: public Msp::DataFile::ObjectLoader<Appearance>
+ {
+ private:
+ const Theme &theme;
+
+ public:
+ Loader(Appearance &, const Theme &);
+
+ void background_color(unsigned, unsigned, unsigned);
+ void background_color_named(const std::string &);
+ void border_color(unsigned, unsigned, unsigned);
+ void border_color_named(const std::string &);
+ void font_size(float);
+ void text_color(unsigned, unsigned, unsigned);
+ void text_color_named(const std::string &);
+ };
+
+private:
+ unsigned font_size;
+ Color border_color;
+ Color background_color;
+ Color text_color;
+ unsigned sound_type;
+ unsigned sound_volume;
+
+public:
+ Appearance();
+
+ unsigned get_font_size() const { return font_size; }
+ const Color &get_border_color() const { return border_color; }
+ const Color &get_background_color() const { return background_color; }
+ const Color &get_text_color() const { return text_color; }
+ unsigned get_sound_type() const { return sound_type; }
+ unsigned get_sound_volume() const { return sound_volume; }
+};
+
+#endif
#include "category.h"
#include "choicecondition.h"
#include "filter.h"
+#include "poefilter.h"
#include "rangecondition.h"
#include "theme.h"
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;
}
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);
add_range<QualityCondition>("quality");
add_range<RarityCondition>("rarity");
add_range<WidthCondition>("width");
+
+ add_auxiliary_loader(app_loader);
}
template<typename T>
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)
{
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());
}
#include <list>
#include <string>
#include <msp/datafile/objectloader.h>
+#include "appearance.h"
#include "condition.h"
#include "rarity.h"
class FilterStatement;
+class PoeFilter;
class Theme;
class Category
class Loader: public Msp::DataFile::ObjectLoader<Category>
{
private:
+ const PoeFilter &poe;
CompoundCondition *compound;
+ Appearance::Loader app_loader;
public:
- Loader(Category &, CompoundCondition * = 0);
+ Loader(Category &, const PoeFilter &, CompoundCondition * = 0);
protected:
template<typename T>
private:
void and_();
+ void appearance(const std::string &);
template<typename T>
void condition(typename T::Type);
private:
Condition *condition;
- float font_size;
- std::string border_color;
unsigned order;
- unsigned sound_type;
- unsigned sound_volume;
+ Appearance appearance;
public:
Category();
~Category();
unsigned get_order() const { return order; }
- void create_statements(std::list<FilterStatement> &, const Theme &) const;
+ void create_statements(std::list<FilterStatement> &) const;
};
#endif
--- /dev/null
+#include "color.h"
+
+Color::Color():
+ defined(false),
+ r(0),
+ g(0),
+ b(0)
+{ }
+
+Color::Color(unsigned r_, unsigned g_, unsigned b_):
+ defined(true),
+ r(r_),
+ g(g_),
+ b(b_)
+{ }
--- /dev/null
+#ifndef COLOR_H_
+#define COLOR_H_
+
+struct Color
+{
+ bool defined;
+ unsigned r;
+ unsigned g;
+ unsigned b;
+
+ Color();
+ Color(unsigned, unsigned, unsigned);
+};
+
+#endif
abstract(false)
{ }
-void Filter::write(IO::Base &out, const Theme &theme) const
+void Filter::write(IO::Base &out) const
{
for(list<const Category *>::const_iterator i=categories.begin(); i!=categories.end(); ++i)
{
list<FilterStatement> st;
//IO::print(out, "# %s\n", i->first);
- (*i)->create_statements(st, theme);
+ (*i)->create_statements(st);
for(list<FilterStatement>::const_iterator j=st.begin(); j!=st.end(); ++j)
j->write(out);
}
Filter();
bool is_abstract() const { return abstract; }
- void write(Msp::IO::Base &, const Theme &) const;
+ void write(Msp::IO::Base &) const;
};
#endif
if(!i->second.is_abstract())
{
IO::BufferedFile out(i->first+".filter", IO::M_WRITE);
- i->second.write(out, theme);
+ i->second.write(out);
}
return 0;
void PoeFilter::Loader::category(const string &name)
{
Category cat;
- load_sub(cat);
+ load_sub(cat, obj);
obj.categories[name] = cat;
}
virtual int main();
+ const Theme &get_theme() const { return theme; }
const Category &get_category(const std::string &) const;
void find_categories(const Msp::Regex &, std::list<const Category *> &) const;
const Filter &get_filter(const std::string &) const;
using namespace std;
using namespace Msp;
-Color::Color():
- r(200),
- g(200),
- b(200)
-{ }
-
-Color::Color(unsigned r_, unsigned g_, unsigned b_):
- r(r_),
- g(g_),
- b(b_)
-{ }
-
-
Theme::Theme():
base_font_size(32)
{ }
base_font_size = size;
}
+void Theme::set_appearance(const string &name, const Appearance &app)
+{
+ appearances[name] = app;
+}
+
+const Appearance &Theme::get_appearance(const string &name) const
+{
+ return get_item(appearances, name);
+}
+
Theme::Loader::Loader(Theme &t):
DataFile::ObjectLoader<Theme>(t)
{
+ add("appearance", &Loader::appearance);
add("base_font_size", &Theme::base_font_size);
add("color", &Loader::color);
}
+void Theme::Loader::appearance(const string &name)
+{
+ Appearance app;
+ load_sub(app, obj);
+ obj.set_appearance(name, app);
+}
+
void Theme::Loader::color(const string &name, unsigned r, unsigned g, unsigned b)
{
obj.set_color(name, Color(r, g, b));
#include <map>
#include <string>
#include <msp/datafile/objectloader.h>
-
-struct Color
-{
- unsigned r;
- unsigned g;
- unsigned b;
-
- Color();
- Color(unsigned, unsigned, unsigned);
-};
-
+#include "appearance.h"
+#include "color.h"
class Theme
{
Loader(Theme &);
private:
+ void appearance(const std::string &);
void color(const std::string &, unsigned, unsigned, unsigned);
};
private:
typedef std::map<std::string, Color> ColorMap;
+ typedef std::map<std::string, Appearance> AppearanceMap;
ColorMap colors;
unsigned base_font_size;
+ AppearanceMap appearances;
public:
Theme();
void set_base_font_size(unsigned);
unsigned get_base_font_size() const { return base_font_size; }
+
+ void set_appearance(const std::string &, const Appearance &);
+ const Appearance &get_appearance(const std::string &) const;
};
#endif