diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/chat.cc | 84 | ||||
-rw-r--r-- | src/client/chat.h | 12 | ||||
-rw-r--r-- | src/client/trademenu.cc | 15 | ||||
-rw-r--r-- | src/client/trademenu.h | 5 | ||||
-rw-r--r-- | src/core/gameconnection.cc | 1 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 6 | ||||
-rw-r--r-- | src/core/gameinterface.h | 10 | ||||
-rw-r--r-- | src/core/gameserver.cc | 2 | ||||
-rw-r--r-- | src/core/netconnection.cc | 2 |
9 files changed, 93 insertions, 44 deletions
diff --git a/src/client/chat.cc b/src/client/chat.cc index c1fc78f..8191e52 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -29,21 +29,19 @@ Chat::Chat(ui::Widget *parent) : ui::Window(parent) chat_scrollpane->set_border(false); chat_scrollpane->set_label("text"); - chat_playerpane = new ui::ScrollPane(this, chat_players); - chat_playerpane->set_border(false); - chat_playerpane->set_label("players"); - chat_playerpane->set_alignment(ui::AlignLeft | ui::AlignTop); + chat_playerlist = new ui::ListView(this); + chat_playerlist->set_label("playerlist"); chat_input = new ui::InputBox(this); chat_input->set_border(false); chat_input->set_prompt("^BSay^F:^B "); - chat_input->set_focus(); set_background(true); set_visible(false); chat_small = false; + chat_playerlist_timestamp = 0; } Chat::~Chat() @@ -53,15 +51,17 @@ Chat::~Chat() void Chat::clear() { - chat_players.clear(); chat_log.clear(); chat_input->clear(); + chat_playerlist->clear(); + chat_playerlist_timestamp = 0; } void Chat::set_small_view(bool small_chat_view) { chat_small = small_chat_view; + resize(); } void Chat::event_text(const std::string & text) @@ -164,8 +164,11 @@ bool Chat::on_keypress(const int key, const unsigned int modifier) return false; } -void Chat::event_draw() +void Chat::draw() { + /* + * this never worked before, event_draw is NOT virtual + if (ui::console()->visible()) return; @@ -178,48 +181,51 @@ void Chat::event_draw() hide(); return; } + */ + + if (!chat_small && (chat_playerlist_timestamp != core::game()->playerlist_timestamp())) { + update_player_list(); + } + + ui::Window::draw(); +} - if (chat_small) { - chat_playerpane->hide(); - chat_scrollpane->hide(); - } else { - chat_playerpane->show(); - chat_scrollpane->show(); - - chat_players.clear(); - std::ostringstream ostr; - - ostr << "^B" << core::game()->players().size() << " " << aux::plural("player", core::game()->players().size()); - chat_players.push_back(ostr.str()); - - for (core::GameInterface::Players::iterator it = core::game()->players().begin(); it != core::game()->players().end(); it++) { - core::Player *player = (*it); - chat_players.push_back(player->name() + "^N"); - } +void Chat::update_player_list() +{ + chat_playerlist->clear(); + + for (core::GameInterface::Players::const_iterator it = core::game()->players().begin(); it != core::game()->players().end(); it++) { + ui::ListItem *listitem = new ui::ListItem(chat_playerlist, (*it)->name().c_str()); + listitem->set_height(listitem->font()->height() * 1.5f); } - Widget::event_draw(); + chat_playerlist_timestamp = core::game()->playerlist_timestamp(); } void Chat::resize() { - const float margin = 8.0f; - math::Vector2f s(size()); - - s[0] -= margin * 2; - s[1] -= margin * 2; - - // player names - chat_playerpane->set_size(ui::UI::elementsize.width() , s.height() - font()->height() * 2.5f); - chat_playerpane->set_location(s.width() - chat_playerpane->width() + 2.0f * margin, margin + font()->height()); + const float fontmargin = ui::root()->font_large()->height(); + + if (chat_small) { + chat_playerlist->hide(); + chat_scrollpane->hide(); + + } else { + chat_playerlist->show(); + chat_scrollpane->show(); + + // player names + chat_playerlist->set_size(ui::UI::elementsize.width(), height() - fontmargin * 3.0f); + chat_playerlist->set_location(width() - ui::UI::elementsize.width() - fontmargin, fontmargin); - // chat text - chat_scrollpane->set_size(s.width() - chat_playerpane->width() - margin, s.height() - font()->height() * 1.5f); - chat_scrollpane->set_location(margin, margin); + // chat text + chat_scrollpane->set_size(width() - ui::UI::elementsize.width() - fontmargin * 3.0f, height() - fontmargin * 3.0f); + chat_scrollpane->set_location(fontmargin, fontmargin); + } // input bar - chat_input->set_location(margin, height() - font()->height() - margin); - chat_input->set_size(s.width(), font()->height()); + chat_input->set_location(fontmargin, height() - fontmargin); + chat_input->set_size(width() - 2.0f * fontmargin , fontmargin); } diff --git a/src/client/chat.h b/src/client/chat.h index 61f5bd1..0972400 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -13,6 +13,7 @@ #include "ui/inputbox.h" #include "ui/scrollpane.h" #include "ui/window.h" +#include "ui/listview.h" namespace client { @@ -37,22 +38,23 @@ public: void clear(); protected: - virtual void event_draw(); + virtual void draw(); + virtual void resize(); virtual bool on_keypress(const int key, const unsigned int modifier); private: + void update_player_list(); bool chat_small; ui::Text chat_log; ui::ScrollPane *chat_scrollpane; - - ui::Text chat_players; - ui::ScrollPane *chat_playerpane; - ui::InputBox *chat_input; + ui::ListView *chat_playerlist; + + unsigned long chat_playerlist_timestamp; typedef std::deque<std::string> History; diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 8aa9a52..c0d1f03 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -364,4 +364,19 @@ void TradeMenu::draw() Window::draw(); } +bool TradeMenu::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 diff --git a/src/client/trademenu.h b/src/client/trademenu.h index 5ea34aa..ecc41b9 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -36,11 +36,16 @@ protected: /// resize event handler virtual void resize(); + /// draw event handler virtual void draw(); /// emit event handler virtual bool on_emit(Widget *sender, const Event event, void *data); + /// keypress event handler + virtual bool on_keypress(const int key, const unsigned int modifier); + + private: void set_item(ui::ListItem *item); diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index f64c8fb..ba18bd5 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -61,6 +61,7 @@ GameConnection::GameConnection(std::string const &connectionstr) } game_players.push_back(localplayer()); + set_playerlist_timestamp(timestamp()); connection_running = true; } diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 5caa270..23018d3 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -122,6 +122,7 @@ void GameInterface::clear() } } game_players.clear(); + game_playerlist_timestamp = 0; // remove all game functions for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();) { @@ -193,4 +194,9 @@ void GameInterface::list_players() con_print << count << " connected " << aux::plural("player", count) << std::endl; } +void GameInterface::set_playerlist_timestamp(const unsigned long timestamp) +{ + game_playerlist_timestamp = ( timestamp > 0 ? timestamp : 1); +} + } diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h index bdce1d3..98894e7 100644 --- a/src/core/gameinterface.h +++ b/src/core/gameinterface.h @@ -38,6 +38,10 @@ public: inline Players & players() { return game_players; } + + inline const unsigned long playerlist_timestamp() const { + return game_playerlist_timestamp; + } inline model::VertexArray *vertexarray() { return game_vertexarray; @@ -68,6 +72,9 @@ public: /// request inventory for entity with id virtual Inventory *request_inventory(Entity *entity) = 0; + + void set_playerlist_timestamp(const unsigned long timestamp); + /*----- mutators ------------------------------------------------- */ @@ -89,6 +96,9 @@ protected: Players game_players; model::VertexArray *game_vertexarray; + + /// timestamp of the time the playerlist was last changed + unsigned long game_playerlist_timestamp; }; /// global local player instance diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 963db6d..31c6d42 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -441,6 +441,7 @@ void GameServer::player_connect(Player *player) // manage player list game_players.push_back(player); + set_playerlist_timestamp(timestamp()); } void GameServer::player_disconnect(Player *player) @@ -464,6 +465,7 @@ void GameServer::player_disconnect(Player *player) if (it != game_players.end()) { game_players.erase(it); } + set_playerlist_timestamp(timestamp()); } void GameServer::frame(unsigned long timestamp) diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 3318c1e..15e57e2 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -755,6 +755,7 @@ void NetConnection::parse_incoming_message(const std::string & message) if (!player) { player = new Player(); game()->players().push_back(player); + game()->set_playerlist_timestamp(game()->timestamp()); } player->receive_short_server_update(msgstream); @@ -781,6 +782,7 @@ void NetConnection::parse_incoming_message(const std::string & message) for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) { if ((*it)->id() == player_id) { game()->players().erase(it); + game()->set_playerlist_timestamp(game()->timestamp()); return; } } |