Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/reputationwindow.cc94
-rw-r--r--src/ui/paint.cc14
-rw-r--r--src/ui/paint.h45
3 files changed, 139 insertions, 14 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);
}
}
diff --git a/src/ui/paint.cc b/src/ui/paint.cc
index 7b8e43f..6dd85b8 100644
--- a/src/ui/paint.cc
+++ b/src/ui/paint.cc
@@ -58,6 +58,20 @@ void Paint::draw_rectangle(const math::Vector2f &global_location, const math::Ve
end();
}
+void Paint::draw_rectangle_gradient(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color_left, const math::Color & color_right)
+{
+ gl::begin(gl::Quads);
+ gl::color(color_left);
+ gl::vertex(global_location.x(), global_location.y());
+ gl::color(color_right);
+ gl::vertex(global_location.x() + size.width(), global_location.y());
+ gl::color(color_right);
+ gl::vertex(global_location.x() + size.width(), global_location.y() + size.height());
+ gl::color(color_left);
+ gl::vertex(global_location.x(), global_location.y() + size.height());
+ gl::end();
+}
+
// draw a bitmap
void Paint::draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture)
{
diff --git a/src/ui/paint.h b/src/ui/paint.h
index d21aaa0..b2829ea 100644
--- a/src/ui/paint.h
+++ b/src/ui/paint.h
@@ -19,23 +19,40 @@ namespace ui {
class Paint
{
public:
- /// set paint color to RGB value
+ /**
+ * @brief set paint color to RGB value
+ * */
static void set_color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f);
- /// set paint color to RGB value
+ /**
+ * @brief set paint color to RGB value
+ * */
static void set_color(math::Color const & color);
- /// set paint color to system color code
+ /**
+ * @brief set paint color to system color code
+ * */
static void set_system_color(const char c);
- /// assign system color code
+ /**
+ * @brief assign system color code
+ * */
static void assign_system_color(const char c, const math::Color &color);
- /// draw a border
+ /**
+ * @brief draw a border
+ * */
static void draw_border(const math::Vector2f &global_location, const math::Vector2f &size);
- /// draw a rectangle
+ /**
+ * @brief draw a rectangle
+ * */
static void draw_rectangle(const math::Vector2f &global_location, const math::Vector2f &size);
+
+ /**
+ * @brief draw a color gradient rectangle
+ * */
+ static void draw_rectangle_gradient(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color_left, const math::Color & color_right);
/**
* @brief draw a rectangular bitmap
@@ -43,16 +60,24 @@ public:
**/
static void draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture);
- /// draw a rectangular bitmap and overrride material color
+ /**
+ * @brief draw a rectangular bitmap and overrride material color
+ * */
static void draw_bitmap(const math::Vector2f &global_location, const math::Vector2f &size, const math::Color & color, const std::string &texture);
- /// draw a tiled bitmap
+ /**
+ * @brief draw a tiled bitmap
+ * */
static void draw_material(const math::Vector2f &global_location, const math::Vector2f &size, const std::string &texture);
- /// draw unaligned text
+ /**
+ * @brief draw unaligned text
+ * */
static void draw_text(const math::Vector2f &global_location, const Font *font, const std::string &text);
- /// draw aligned text
+ /**
+ * @brief draw aligned text
+ * */
static void draw_label(const math::Vector2f &global_location, const math::Vector2f &size, const Font *font, const std::string &text, const unsigned int alignment = AlignCenter);
};