From 6304a3afdcf747468dc125991b3313887c2af941 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 2 Jun 2011 00:22:05 +0200 Subject: Added a new transparent scheme based on Vanilla and a simple chat window, which displays text strings received from the server. --- GUI/Transparent.imageset | 21 ++ GUI/Transparent.looknfeel | 643 +++++++++++++++++++++++++++++++++++++++++++++ GUI/Transparent.png | Bin 0 -> 4692 bytes GUI/Transparent.scheme | 15 ++ GUI/layouts/chat.layout | 13 + GUI/layouts/console.layout | 2 + common | 2 +- game.cpp | 19 +- game.h | 3 +- gui.cpp | 28 ++ gui.h | 14 + scene.cpp | 17 +- scene.h | 1 + 13 files changed, 767 insertions(+), 11 deletions(-) create mode 100644 GUI/Transparent.imageset create mode 100644 GUI/Transparent.looknfeel create mode 100644 GUI/Transparent.png create mode 100644 GUI/Transparent.scheme create mode 100644 GUI/layouts/chat.layout diff --git a/GUI/Transparent.imageset b/GUI/Transparent.imageset new file mode 100644 index 0000000..8d317dd --- /dev/null +++ b/GUI/Transparent.imageset @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/GUI/Transparent.looknfeel b/GUI/Transparent.looknfeel new file mode 100644 index 0000000..877733b --- /dev/null +++ b/GUI/Transparent.looknfeel @@ -0,0 +1,643 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ +
+ + + + +
+ +
+
+
+ +
+ + + + +
+ +
+
+
+ +
+ + + + +
+ +
+
+ +
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + +
+ +
+
+
+
+ + diff --git a/GUI/Transparent.png b/GUI/Transparent.png new file mode 100644 index 0000000..3da2c88 Binary files /dev/null and b/GUI/Transparent.png differ diff --git a/GUI/Transparent.scheme b/GUI/Transparent.scheme new file mode 100644 index 0000000..4678748 --- /dev/null +++ b/GUI/Transparent.scheme @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/GUI/layouts/chat.layout b/GUI/layouts/chat.layout new file mode 100644 index 0000000..d37d03c --- /dev/null +++ b/GUI/layouts/chat.layout @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/GUI/layouts/console.layout b/GUI/layouts/console.layout index e6ef61b..879af94 100644 --- a/GUI/layouts/console.layout +++ b/GUI/layouts/console.layout @@ -3,6 +3,8 @@ + + diff --git a/common b/common index 1211f63..555f65a 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 1211f632092db824fb2c880063599f7642c34f30 +Subproject commit 555f65ad7171511d74513b7055552a941a6fe0f2 diff --git a/game.cpp b/game.cpp index 5bc1a8d..0ebefed 100644 --- a/game.cpp +++ b/game.cpp @@ -56,10 +56,10 @@ void Game::async_read() { uint8_t *t = new uint8_t; boost::asio::async_read(socket, boost::asio::buffer(t, sizeof(uint8_t)), boost::asio::transfer_all(), - boost::bind(&Game::handle_message, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, t)); + boost::bind(&Game::handle_type, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, t)); } -void Game::handle_message(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type) { +void Game::handle_type(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type) { if(error) { std::cerr << error << std::endl; delete type; @@ -71,6 +71,9 @@ void Game::handle_message(const boost::system::error_code& error, std::size_t by case message::MSG_TYPE_CHUNK: handle_chunk(); break; + case message::MSG_TYPE_MSG: + handle_message(); + break; default: std::cout << "unknown type: " << (int)*type << std::endl; } @@ -101,6 +104,18 @@ void Game::handle_chunk() { scene->terrain->chunks.push_back(chunk); } +void Game::handle_message() { + message::Message m; + + m.read(socket); + m.get_len(); + + m.read(socket); + std::string s = m.get_str(); + + scene->chat->add_line(s); +} + Game& Game::get_instance() { if(!game) game = new Game(); diff --git a/game.h b/game.h index f950b64..cad032e 100644 --- a/game.h +++ b/game.h @@ -23,8 +23,9 @@ class Game { void run(std::string host, std::string port); void async_read(); - void handle_message(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type); + void handle_type(const boost::system::error_code& error, std::size_t bytes_transferred, uint8_t *type); void handle_chunk(); + void handle_message(); static Game& get_instance(); }; diff --git a/gui.cpp b/gui.cpp index ed53cb4..4d4a723 100644 --- a/gui.cpp +++ b/gui.cpp @@ -29,6 +29,7 @@ void GUI::init() { WindowManager::setDefaultResourceGroup("layouts"); SchemeManager::getSingleton().create( "VanillaSkin.scheme" ); + SchemeManager::getSingleton().create( "Transparent.scheme" ); FontManager::getSingleton().create("VeraMono.font"); @@ -154,6 +155,33 @@ void ConsoleWindow::update() { WindowManager::getSingleton().getWindow("console_editbox")->activate(); } +/* ChatWindow */ + +ChatWindow::ChatWindow() { + WindowManager& wmgr(WindowManager::getSingleton()); + + wnd = wmgr.loadWindowLayout("chat.layout"); + root->addChildWindow(wnd); + + listbox = static_cast(wmgr.getWindow("chat_listbox")); +} + +ChatWindow::~ChatWindow() { + WindowManager& wmgr(WindowManager::getSingleton()); + wmgr.destroyWindow(wnd); + wmgr.cleanDeadPool(); +} + +void ChatWindow::add_line(const std::string& line) { + add_line(line.c_str()); +} + +void ChatWindow::add_line(const char *line) { + FormattedListboxTextItem *item = new FormattedListboxTextItem(String((utf8*)line), HTF_WORDWRAP_LEFT_ALIGNED); + listbox->addItem(item); + listbox->ensureItemIsVisible(item); +} + /* RaiseWindow */ /* default values */ diff --git a/gui.h b/gui.h index b770ed0..5ea5063 100644 --- a/gui.h +++ b/gui.h @@ -49,6 +49,20 @@ class ConsoleWindow : public GUI { void add_line(const char *line); }; +class ChatWindow : public GUI { + private: + CEGUI::Listbox *listbox; + + public: + ChatWindow(); + virtual ~ChatWindow(); + + virtual void update() {}; + + void add_line(const std::string& line); + void add_line(const char *line); +}; + class RaiseWindow : public GUI { private: CEGUI::PushButton *btn; diff --git a/scene.cpp b/scene.cpp index 20692d8..fa012a3 100644 --- a/scene.cpp +++ b/scene.cpp @@ -67,6 +67,8 @@ Scene::Scene() { console = new ConsoleWindow(lua); console->hide(); + chat = new ChatWindow(); + void (ConsoleWindow::*add_line)(const char*) = &ConsoleWindow::add_line; lua->set_log_func(boost::bind(add_line, console, _1)); } @@ -79,6 +81,7 @@ Scene::~Scene() { delete terrain; delete font; delete console; + delete chat; } void Scene::lookat() { @@ -223,11 +226,11 @@ void Scene::events() { case SDL_MOUSEBUTTONDOWN: switch(event.button.button) { case SDL_BUTTON_LEFT: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton); break; case SDL_BUTTON_RIGHT: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton); break; } @@ -235,7 +238,7 @@ void Scene::events() { case SDL_MOUSEBUTTONUP: switch(event.button.button) { case SDL_BUTTON_LEFT: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton); else { sx = event.button.x; @@ -244,23 +247,23 @@ void Scene::events() { } break; case SDL_BUTTON_RIGHT: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton); else show_selection = false; break; case SDL_BUTTON_WHEELUP: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseWheelChange(1); break; case SDL_BUTTON_WHEELDOWN: - if(dialog) + if(dialog || console->showing()) CEGUI::System::getSingleton().injectMouseWheelChange(-1); break; } break; case SDL_MOUSEMOTION: - if(dialog) { + if(dialog || console->showing()) { CEGUI::System::getSingleton().injectMousePosition(event.motion.x, event.motion.y); break; } diff --git a/scene.h b/scene.h index a3e2ee3..f244ab1 100644 --- a/scene.h +++ b/scene.h @@ -21,6 +21,7 @@ class Scene { GUI *gui; Tool *tool; ConsoleWindow *console; + ChatWindow *chat; Lua *lua; bool running; -- cgit v1.2.3