diff options
author | Stijn Buys <ingar@osirion.org> | 2013-11-10 17:13:41 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2013-11-10 17:13:41 +0000 |
commit | 5f0958c121a246d445507313984358ff8a6df3fa (patch) | |
tree | 34f0b53f0e7de9bee09ad8bcafa4228654365ae5 /src/client | |
parent | 82f0ac05f5da2d89c4a544ca22ff47e116e6dd97 (diff) |
Adjust reputation on NPC kills,
refresh reputation window if required.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/reputationwindow.cc | 47 | ||||
-rw-r--r-- | src/client/reputationwindow.h | 3 |
2 files changed, 37 insertions, 13 deletions
diff --git a/src/client/reputationwindow.cc b/src/client/reputationwindow.cc index 804ab50..3566458 100644 --- a/src/client/reputationwindow.cc +++ b/src/client/reputationwindow.cc @@ -11,6 +11,7 @@ #include "client/client.h" #include "client/reputationwindow.h" #include "core/reputation.h" +#include "core/range.h" namespace client { @@ -86,7 +87,8 @@ private: ReputationWindow::ReputationWindow(ui::Widget *parent) : ui::Window(parent) { reputationwindow_info = 0; - reputationwindow_timestamp = 0; + reputationwindow_info_timestamp = 0; + reputationwindow_reputation_timestamp = 0; // window title reputationwindow_titlelabel = new ui::Label(this); @@ -133,6 +135,7 @@ ReputationWindow::~ReputationWindow() void ReputationWindow::show() { if (hidden()) { + reputationwindow_info = 0; refresh(); } @@ -144,14 +147,15 @@ void ReputationWindow::refresh() reputationwindow_listview->clear(); const float padding = ui::root()->font_large()->height(); + ui::ListItem *selected_listitem = 0; for (core::Reputation::FactionReps::const_iterator it = core::localplayer()->reputation().factionreps().begin(); it != core::localplayer()->reputation().factionreps().end(); ++it) { if ((*it)->faction()) { std::string strdescription; - if (roundf((*it)->reputation()) < -50.0f) { + if (roundf((*it)->reputation()) <= core::range::reputation_hostile) { strdescription.append("^1"); - } else if (roundf((*it)->reputation()) > 50.0f) { + } else if (roundf((*it)->reputation()) >= core::range::reputation_friendly) { strdescription.append("^2"); } else { strdescription.append("^B"); @@ -172,12 +176,26 @@ void ReputationWindow::refresh() 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); + + if ((*it)->faction() == reputationwindow_info) { + selected_listitem = listitem; + } } } reputationwindow_listview->sort(); + reputationwindow_listview->event_resize(); + + reputationwindow_reputation_timestamp = core::localplayer()->reputation().timestamp(); + + if (selected_listitem) { + reputationwindow_listview->select(selected_listitem); + reputationwindow_info = selected_listitem->info(); + } else { + reputationwindow_info = 0; + } - set_info(); + set_info(reputationwindow_info); } void ReputationWindow::set_info(const core::Info *info) @@ -187,8 +205,6 @@ void ReputationWindow::set_info(const core::Info *info) reputationwindow_info = info; if (!info) { - reputationwindow_timestamp = 0; - // player name reputationwindow_targetlabel->set_text(core::localplayer()->name()); @@ -250,27 +266,34 @@ void ReputationWindow::set_info(const core::Info *info) strinfotext << std::setfill('0') << std::setw(2) << time_wasted_seconds; reputationwindow_infotext.push_back(strinfotext.str()); + reputationwindow_info_timestamp = 0; + } else { core::game()->request_info(info->id()); - reputationwindow_targetlabel->set_text(info->name()); - reputationwindow_timestamp = info->timestamp(); - + 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)); } + + reputationwindow_info_timestamp = info->timestamp(); } } void ReputationWindow::draw() { - if (!reputationwindow_info) { + if (reputationwindow_reputation_timestamp != core::localplayer()->reputation().timestamp()) { + con_debug << " ^2ReputationWindow::draw() forced refresh" << std::endl; + refresh(); + + } else if (!reputationwindow_info) { // update player info set_info(0); - - } else if (reputationwindow_timestamp != reputationwindow_info->timestamp()) { + + } else if (reputationwindow_info_timestamp != reputationwindow_info->timestamp()) { // update faction info if we received updates from the server set_info(reputationwindow_info); + } ui::Window::draw(); diff --git a/src/client/reputationwindow.h b/src/client/reputationwindow.h index b6c95c7..7b91cf3 100644 --- a/src/client/reputationwindow.h +++ b/src/client/reputationwindow.h @@ -80,7 +80,8 @@ private: const core::Info *reputationwindow_info; - unsigned long reputationwindow_timestamp; + unsigned long reputationwindow_info_timestamp; + unsigned long reputationwindow_reputation_timestamp; }; // class ReputationWindow |