Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-11-08 13:20:45 +0000
committerStijn Buys <ingar@osirion.org>2013-11-08 13:20:45 +0000
commitbeefcbd30e5cb1b700c977090021cd4784989c1e (patch)
tree354086869e69b72b5603a9a58485d1e09c373bd8 /src/client/reputationwindow.cc
parent3aa51da4ec976665a7e74bb659868d474400a101 (diff)
Added player reputation window,
minor cosmetic user interface changes.
Diffstat (limited to 'src/client/reputationwindow.cc')
-rw-r--r--src/client/reputationwindow.cc232
1 files changed, 232 insertions, 0 deletions
diff --git a/src/client/reputationwindow.cc b/src/client/reputationwindow.cc
new file mode 100644
index 0000000..6e5a535
--- /dev/null
+++ b/src/client/reputationwindow.cc
@@ -0,0 +1,232 @@
+/*
+ client/reputationwindow.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include <iomanip>
+
+#include "ui/ui.h"
+#include "client/client.h"
+#include "client/reputationwindow.h"
+#include "core/reputation.h"
+
+namespace client {
+
+ReputationWindow::ReputationWindow(ui::Widget *parent) : ui::Window(parent)
+{
+ // window title
+ reputationwindow_titlelabel = new ui::Label(this);
+ reputationwindow_titlelabel->set_label("title");
+ reputationwindow_titlelabel->set_background(false);
+ reputationwindow_titlelabel->set_border(false);
+ reputationwindow_titlelabel->set_font(ui::root()->font_large());
+ reputationwindow_titlelabel->set_alignment(ui::AlignCenter);
+ reputationwindow_titlelabel->set_text("REPUTATION");
+
+ // close button
+ reputationwindow_closebutton = new ui::IconButton(reputationwindow_titlelabel, "bitmaps/icons/window_close");
+
+ // reputation listview
+ reputationwindow_listview = new ui::ListView(this);
+ reputationwindow_listview->set_label("listview");
+
+ // target label
+ reputationwindow_targetlabel = new ui::Label(this);
+ reputationwindow_targetlabel->set_label("info");
+ reputationwindow_targetlabel->set_background(false);
+ reputationwindow_targetlabel->set_border(false);
+ reputationwindow_targetlabel->set_alignment(ui::AlignCenter);
+
+ // player statistics / faction description
+ reputationwindow_scrollpane = new ui::ScrollPane(this, reputationwindow_infotext);
+ reputationwindow_scrollpane->set_background(false);
+ reputationwindow_scrollpane->set_border(false);
+ reputationwindow_scrollpane->set_alignment(ui::AlignTop);
+
+ hide();
+}
+
+ReputationWindow::~ReputationWindow()
+{
+
+}
+
+void ReputationWindow::show()
+{
+ if (hidden()) {
+ refresh();
+ }
+
+ ui::Window::show();
+}
+
+void ReputationWindow::refresh()
+{
+ reputationwindow_listview->clear();
+
+ 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());
+ listitem->set_font(ui::root()->font_tiny());
+ listitem->set_height(listitem->font()->height() * 3.0f);
+ 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());
+ }
+ }
+
+ reputationwindow_listview->sort();
+
+ set_info();
+}
+
+void ReputationWindow::set_info(const core::Info *info)
+{
+ reputationwindow_infotext.clear();
+ reputationwindow_targetlabel->clear();
+
+ if (!info) {
+ // player name
+ reputationwindow_targetlabel->set_text(core::localplayer()->name());
+
+ std::ostringstream strinfotext;
+
+ // player level
+ strinfotext.str("");
+ strinfotext.clear();
+ strinfotext << "^NLevel: ";
+ strinfotext << core::localplayer()->level();
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ // player credits
+ strinfotext.str("");
+ strinfotext.clear();
+ strinfotext << "^NCredits: ";
+ strinfotext << core::localplayer()->credits();
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ // ------------------
+ strinfotext.str("");
+ strinfotext.clear();
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ // player NPC kills
+ strinfotext.str("");
+ strinfotext.clear();
+ strinfotext << "^NNPC kills: ";
+ strinfotext << core::localplayer()->npckills();
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ // player PVP kills
+ strinfotext.str("");
+ strinfotext.clear();
+ strinfotext << "^NPVP kills: ";
+ strinfotext << core::localplayer()->pvpkills();
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ // player time wasted
+ strinfotext.str("");
+ strinfotext.clear();
+ strinfotext << "^NTime wasted: ";
+ long time_wasted = (core::localplayer()->time_wasted() + core::game()->timestamp() - core::localplayer()->time_joined()) / 1000;
+ const long time_wasted_seconds = time_wasted % 60;
+
+ time_wasted = (time_wasted - time_wasted_seconds) / 60;
+ const long time_wasted_minutes = time_wasted % 60;
+
+ time_wasted = (time_wasted - time_wasted_minutes) / 60;
+ const long time_wasted_hours = time_wasted % 24;
+
+ const long time_wasted_days = (time_wasted - time_wasted_hours) / 24;
+
+ if (time_wasted_days > 0) {
+ strinfotext << time_wasted_days << aux::plural("day", time_wasted_days) << " ";
+ }
+ strinfotext << std::setfill('0') << std::setw(2) << time_wasted_hours << ":" ;
+ strinfotext << std::setfill('0') << std::setw(2) << time_wasted_minutes << ":";
+ strinfotext << std::setfill('0') << std::setw(2) << time_wasted_seconds;
+ reputationwindow_infotext.push_back(strinfotext.str());
+
+ } else {
+ core::game()->request_info(info->id());
+
+ reputationwindow_targetlabel->set_text(info->name());
+
+ for (core::Info::Text::const_iterator it = info->text().begin(); it != info->text().end(); it++) {
+ reputationwindow_infotext.push_back((*it));
+ }
+ }
+}
+
+void ReputationWindow::resize()
+{
+ const float padding = ui::root()->font_large()->height();
+ //const float icon_size = 24.0f; // small icons
+
+ // resize label
+ reputationwindow_titlelabel->set_size(width() - padding * 2.0f, reputationwindow_titlelabel->font()->height());
+ reputationwindow_titlelabel->set_location(padding, padding);
+
+ // resize close button
+ reputationwindow_closebutton->set_size(reputationwindow_titlelabel->font()->height(), reputationwindow_titlelabel->font()->height());
+ reputationwindow_closebutton->set_location(reputationwindow_titlelabel->width() - reputationwindow_closebutton->width(), 0);
+
+ // resize reputation listview
+ reputationwindow_listview->set_size(ui::UI::elementsize.width(), height() - reputationwindow_titlelabel->bottom() - padding * 2.0f);
+ reputationwindow_listview->set_location(reputationwindow_titlelabel->left(), reputationwindow_titlelabel->bottom() + padding);
+
+ // resize reputation info label
+ reputationwindow_targetlabel->set_size(width() - reputationwindow_listview->right() - padding * 2.0f, reputationwindow_targetlabel->font()->height());
+ reputationwindow_targetlabel->set_location(reputationwindow_listview->right() + padding,reputationwindow_titlelabel->bottom() + padding);
+
+ // resize infotext scrollpane
+ reputationwindow_scrollpane->set_size(width() - reputationwindow_listview->right() - padding * 2.0f, height() - reputationwindow_targetlabel->bottom() - padding * 2.0f);
+ reputationwindow_scrollpane->set_location(reputationwindow_listview->right() + padding, reputationwindow_targetlabel->bottom() + padding);
+}
+
+bool ReputationWindow::on_emit(ui::Widget *sender, const Event event, void *data)
+{
+ if (event == ui::Widget::EventButtonClicked) {
+
+ if (sender == reputationwindow_closebutton) {
+ hide();
+ }
+ return true;
+
+
+ } else if (event == ui::Widget::EventListViewChanged) {
+
+ if (sender == reputationwindow_listview) {
+ set_info( reputationwindow_listview->selected() ? reputationwindow_listview->selected()->info() : 0);
+ }
+
+ return true;
+ }
+
+ return Window::on_emit(sender, event, data);
+}
+
+bool ReputationWindow::on_keypress(const int key, const unsigned int modifier)
+{
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ this->hide();
+ return true;
+ break;
+
+ default:
+ break;
+ }
+
+ return Window::on_keypress(key, modifier);
+}
+
+
+} //namespace client