diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/reputationwindow.cc | 94 |
1 files changed, 90 insertions, 4 deletions
diff --git a/src/client/reputationwindow.cc b/src/client/reputationwindow.cc index f110971..bc1217c 100644 --- a/src/client/reputationwindow.cc +++ b/src/client/reputationwindow.cc @@ -6,12 +6,82 @@ #include <iomanip> +#include "ui/paint.h" #include "ui/ui.h" #include "client/client.h" #include "client/reputationwindow.h" #include "core/reputation.h" namespace client { + +class ReputationBar : public ui::Widget { +public: + ReputationBar(ui::Widget *parent = 0) : ui::Widget(parent) + { + bar_reputation = 0; + set_border(false); + } + + ~ReputationBar() + { + } + + inline const float reputation() const + { + + return bar_reputation; + } + + void set_reputation(const float reputation) + { + bar_reputation = reputation; + } + +protected: + virtual void draw() + { + const float box_padding = 4.0f; + float box_width = floorf((width() - 19.0f * box_padding) / 20.0f); + if (box_width < 1.0f) { + box_width = floorf(width() / 20.0f); + } + + math::Vector2f s(box_width, height()); + const math::Vector2f g (global_location()); + math::Vector2f pos (g); + + // draw squares + math::Color c1; + math::Color c2; + + for (int i = 0; i < 20; i++) { + pos[0] = g[0] + floorf (width() / 20.0f * (float) i); + if (i < 10) { + if (bar_reputation <= (i - 10) * 10.0f ) { + c1.assign(1.0f, 0.1f * (float) ( i), 0.1f * (float) ( i) ); + c2.assign(1.0f, 0.1f * (float) (i +1), 0.1f * (float) (i + 1)); + ui::Paint::draw_rectangle_gradient(pos, s, c1, c2); + } + + } else { + if (bar_reputation > (i - 10) * 10.0f) { + c1.assign(0.1f * (float) (20 - i), 1.0f, 0.1f * (float) (20 - i)); + c2.assign(0.1f * (float) (20 - i + 1), 1.0f, 0.1f * (float) (20 - i + 1)); + ui::Paint::draw_rectangle_gradient(pos, s, c1, c2); + } + } + } + + ui::Paint::set_color(palette()->border()); + for (int i = 0; i < 20; i++) { + pos[0] = g[0] + floorf (width() / 20.0f * (float) i); + ui::Paint::draw_border(pos, s); + } + } + +private: + float bar_reputation; +}; ReputationWindow::ReputationWindow(ui::Widget *parent) : ui::Window(parent) { @@ -70,19 +140,35 @@ void ReputationWindow::refresh() { reputationwindow_listview->clear(); + const float padding = ui::root()->font_large()->height(); + for (core::Reputation::FactionReps::const_iterator it = core::localplayer()->reputation().factionreps().begin(); it != core::localplayer()->reputation().factionreps().end(); ++it) { if ((*it)->faction()) { - std::ostringstream strdescription; - strdescription << (*it)->faction()->name() << '\n' << roundf((*it)->reputation()); - ui::ListItem *listitem = new ui::ListItem(reputationwindow_listview, strdescription.str().c_str()); + std::string strdescription; + if (roundf((*it)->reputation()) < -50.0f) { + strdescription.append("^1"); + } else if (roundf((*it)->reputation()) > 50.0f) { + strdescription.append("^2"); + } else { + strdescription.append("^B"); + } + strdescription.append((*it)->faction()->name()); + + ui::ListItem *listitem = new ui::ListItem(reputationwindow_listview, strdescription.c_str()); + listitem->set_alignment(ui::AlignTop | ui::AlignHCenter); listitem->set_font(ui::root()->font_tiny()); - listitem->set_height(listitem->font()->height() * 3.0f); + listitem->set_height(listitem->font()->height() * 3.5f); listitem->set_info((*it)->faction()); std::ostringstream strsortkey; strsortkey << std::setfill('0') << std::setw(2) << (*it)->reputation() + 100; listitem->set_sortkey(strsortkey.str().c_str()); + + ReputationBar *bar = new ReputationBar(listitem); + bar->set_reputation((*it)->reputation()); + bar->set_size(reputationwindow_listview->width() - padding, bar->font()->height()); + bar->set_location( padding * 0.5f, listitem->height() - bar->height() - padding * 0.5f); } } |