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>2008-10-19 16:03:56 +0000
committerStijn Buys <ingar@osirion.org>2008-10-19 16:03:56 +0000
commit1d580ed36893b24b618ff1e6f9023e497c62498c (patch)
treeac942e5fd15811c6ea2fa449f88f5c4cc4187d30
parent56cdfd3822d2800abdd2f912ab7f76a5764793a7 (diff)
on-screen notifications
-rw-r--r--src/client/Makefile.am4
-rw-r--r--src/client/chat.cc2
-rw-r--r--src/client/client.cc25
-rw-r--r--src/client/client.h8
-rw-r--r--src/client/notifications.cc62
-rw-r--r--src/client/notifications.h40
-rw-r--r--src/client/view.cc16
-rw-r--r--src/client/view.h17
-rw-r--r--src/core/application.cc2
-rw-r--r--src/core/application.h2
-rw-r--r--src/render/camera.cc12
11 files changed, 167 insertions, 23 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 09046d9..9fa05e0 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,11 +8,11 @@ noinst_LTLIBRARIES = libclient.la
endif
libclient_la_SOURCES = action.cc chat.cc client.cc console.cc input.cc \
- joystick.cc key.cc keyboard.cc targets.cc video.cc view.cc
+ joystick.cc key.cc keyboard.cc notifications.cc targets.cc video.cc view.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_HEADERS = action.h chat.h client.h console.h input.h joystick.h key.h \
- keyboard.h targets.h video.h view.h
+ keyboard.h notifications.h targets.h video.h view.h
libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \
$(top_builddir)/src/render/librender.la $(top_builddir)/src/ui/libui.la
diff --git a/src/client/chat.cc b/src/client/chat.cc
index af50dff..a3c60c0 100644
--- a/src/client/chat.cc
+++ b/src/client/chat.cc
@@ -12,7 +12,7 @@
namespace client {
-const size_t DEFAULT_CHAT_LOG_SIZE = 256;
+const size_t DEFAULT_CHAT_LOG_SIZE = 2048;
const size_t DEFAULT_CHAT_HISTO_SIZE = 512;
Chat::Chat(ui::Widget *parent) : ui::Window(parent)
diff --git a/src/client/client.cc b/src/client/client.cc
index 45cc47a..c1fab8a 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -92,6 +92,9 @@ void Client::quit(int status)
void Client::init(int count, char **arguments)
{
con_print << "^BInitializing client..." << std::endl;
+
+ client_console = 0;
+ client_view = 0;
// initialize core
core::Cvar::sv_private = core::Cvar::set("sv_private", "0");
@@ -262,12 +265,23 @@ void Client::notify_zonechange()
render::unload();
}
-void Client::notify_sound(const char * name)
+void Client::notify_sound(const char *name)
{
audio::play(name);
}
-void Client::notify_message(core::Message::Channel const channel, std::string const message)
+void Client::notify_message(const char *message)
+{
+ std::string text(message);
+ notify_message(core::Message::Info, text);
+}
+
+void Client::notify_message(const std::string &message)
+{
+ notify_message(core::Message::Info, message);
+}
+
+void Client::notify_message(const core::Message::Channel channel, const std::string &message)
{
switch(channel) {
@@ -293,9 +307,12 @@ void Client::notify_message(core::Message::Channel const channel, std::string co
break;
}
+ if (view()) {
+ view()->chat()->event_text(message);
+ view()->notify()->event_text(message);
+ }
+
con_print << message << std::endl;
- view()->chat()->event_text(message);
- //console()->notify(message);
}
/* FIXME
diff --git a/src/client/client.h b/src/client/client.h
index 67fba13..d7e3cc0 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -34,7 +34,13 @@ public:
virtual void notify_sound(const char * name);
/// text notifications from the core
- virtual void notify_message(core::Message::Channel const channel, std::string const message);
+ virtual void notify_message(const core::Message::Channel channel, const std::string &message);
+
+ /// text notifications from the client
+ void notify_message(const std::string &message);
+
+ /// text notifications from the client
+ void notify_message(const char *message);
/// remove sound source notification
virtual void notify_remove_sound(size_t source);
diff --git a/src/client/notifications.cc b/src/client/notifications.cc
new file mode 100644
index 0000000..b7c11fd
--- /dev/null
+++ b/src/client/notifications.cc
@@ -0,0 +1,62 @@
+/*
+ client/notifications.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#include "client/notifications.h"
+#include "core/application.h"
+
+namespace client
+{
+
+const size_t NOTIFY_LOG_SIZE = 256;
+const unsigned long NOTIFY_TIMEOUT = 7000; //timeout in microseconds
+
+Notifications::Notifications(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("notifications");
+ set_border(false);
+
+ notify_scrollpane = new ui::ScrollPane(this, notify_log);
+ notify_scrollpane->set_border(false);
+}
+
+Notifications::~Notifications()
+{
+}
+
+void Notifications::event_text(const std::string & text)
+{
+ while (notify_log.size() >= NOTIFY_LOG_SIZE) {
+ notify_log.pop_front();
+ notify_timestamp.pop_front();
+ }
+
+ notify_log.push_back(text);
+ notify_timestamp.push_back(core::application()->timestamp());
+}
+
+void Notifications::draw()
+{
+ Timestamps::iterator t = notify_timestamp.begin();
+ while ( (t != notify_timestamp.end()) && ( core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT )) {
+
+ notify_log.pop_front();
+ notify_timestamp.pop_front();
+
+ t = notify_timestamp.begin();
+ }
+
+ const float margin = 8.0f;
+ math::Vector2f s(size());
+ s.x -= margin*2;
+ s.y -= margin*2;
+
+ notify_scrollpane->set_location(margin, margin);
+ notify_scrollpane->set_size(s.x, s.y );
+}
+
+
+}
+
diff --git a/src/client/notifications.h b/src/client/notifications.h
new file mode 100644
index 0000000..be168fb
--- /dev/null
+++ b/src/client/notifications.h
@@ -0,0 +1,40 @@
+/*
+ client/notifications.h
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CLIENT_NOTIFICATIONS_H__
+#define __INCLUDED_CLIENT_VIEW_H__
+
+#include "ui/widget.h"
+#include "ui/scrollpane.h"
+
+namespace client
+{
+
+/// a widget to draw engine notifications and messages
+class Notifications : public ui::Widget
+{
+public:
+ Notifications(ui::Widget *parent = 0);
+ ~Notifications();
+
+ void event_text(const std::string & text);
+
+protected:
+ /// draw notifications
+ void draw();
+
+private:
+ typedef std::deque<unsigned long> Timestamps;
+
+ Timestamps notify_timestamp;
+ ui::Text notify_log;
+
+ ui::ScrollPane *notify_scrollpane;
+};
+
+}
+
+#endif // __INCLUDED_CLIENT_NOTIFICATIONS_H__
diff --git a/src/client/view.cc b/src/client/view.cc
index a5da7d4..771f63a 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -197,7 +197,7 @@ View::View(ui::Widget *parent) : ui::Widget(parent)
view_devinfo = new DevInfo(this);
view_stats = new Stats(this);
view_keypress = new KeyPress(this);
-
+ view_notify = new Notifications(this);
view_chat = new Chat(this);
// make sure the view is at the bottom of the draw stack
@@ -216,6 +216,10 @@ void View::resize()
view_devinfo->set_size(font()->width()*32, font()->height()*5);
view_devinfo->set_location(font()->width() * 0.5f, font()->height() * 0.5f);
+ // reposition notifications widget
+ view_notify->set_location(font()->width(), view_devinfo->top() + view_devinfo->height() + font()->width());
+ view_notify->set_size(width() - font()->width() * 2, height() * 0.5f - view_notify->top());
+
// reposition stats widget
view_stats->set_size(font()->width()*12, font()->height()*5);
view_stats->set_location(width() - view_stats->width() - font()->width() * 0.5, font()->height() * 0.5f);
@@ -237,6 +241,16 @@ void View::draw()
view_stats->set_visible(draw_stats->value() ? true : false);
view_keypress->set_visible(draw_keypress->value() ? true : false);
+ if (core::application()->connected() && core::game()->interactive()) {
+ if (client()->console()->visible() || chat()->visible()) {
+ view_notify->set_visible(false);
+ } else {
+ view_notify->set_visible(true);
+ }
+ } else {
+ view_notify->set_visible(false);
+ }
+
if (core::localcontrol() && (input::mouse_control || input::joystick_control) &&
(render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
view_center->set_visible(true);
diff --git a/src/client/view.h b/src/client/view.h
index 960e633..c9c9156 100644
--- a/src/client/view.h
+++ b/src/client/view.h
@@ -1,4 +1,5 @@
-/* client/view.h
+/*
+ client/view.h
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
@@ -8,6 +9,7 @@
#include "core/zone.h"
#include "client/chat.h"
+#include "client/notifications.h"
#include "ui/widget.h"
#include "ui/bitmap.h"
@@ -21,23 +23,23 @@ const size_t net_counter_size = 128; // net is the average of 128 frames
class DevInfo : public ui::Widget
{
public:
- // default constructor
+ /// default constructor
DevInfo(ui::Widget *parent = 0);
protected:
- // draw developer info
+ /// draw developer info
void draw();
};
-// a widget that shows engine statistics
+/// a widget that shows engine statistics
class Stats : public ui::Widget
{
public:
- // default constructor
+ /// default constructor
Stats(ui::Widget *parent=0);
protected:
- // draw engine statistics
+ /// draw engine statistics
virtual void draw();
private:
@@ -72,6 +74,8 @@ public:
inline Chat *chat() { return view_chat; }
+ inline Notifications *notify() { return view_notify; }
+
protected:
virtual void draw();
@@ -82,6 +86,7 @@ private:
DevInfo *view_devinfo;
Stats *view_stats;
KeyPress *view_keypress;
+ Notifications *view_notify;
ui::Bitmap *view_center;
};
diff --git a/src/core/application.cc b/src/core/application.cc
index 71d739f..09e900d 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -518,7 +518,7 @@ void Application::load_commandline(int count, char **arguments)
cmd() << '\n';
}
-void Application::notify_message(Message::Channel const channel, std::string const message)
+void Application::notify_message(const core::Message::Channel channel, const std::string &message)
{
con_print << message << std::endl;
}
diff --git a/src/core/application.h b/src/core/application.h
index 229f318..f241aa3 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -70,7 +70,7 @@ public:
virtual void notify_sound(const char * name);
/// text notifications from the core to the application
- virtual void notify_message(Message::Channel const channel, std::string const message);
+ virtual void notify_message(const core::Message::Channel channel, const std::string &message);
/// connect notification
virtual void notify_connect();
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 108e4db..852e93f 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -145,21 +145,21 @@ void Camera::view_next()
case Free:
// switch camera to Track mode
set_mode(Track);
- con_print << "view: track" << std::endl;
+ //con_print << "view: track" << std::endl;
//core::application()->notify_message(core::Message::Info, std::string("view: track"));
break;
case Track:
// switch camera to Cockpit mode
set_mode(Cockpit);
- con_print << "view: cockpit" << std::endl;
+ //con_print << "view: cockpit" << std::endl;
//core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
break;
case Cockpit:
// switch camera to Free mode
set_mode(Free);
- con_print << "view: free" << std::endl;
+ //con_print << "view: free" << std::endl;
//core::application()->notify_message(core::Message::Info, std::string("view: free"));
break;
@@ -180,21 +180,21 @@ void Camera::view_previous()
case Cockpit:
// switch camera to Track mode
set_mode(Track);
- con_print << "view: track" << std::endl;
+ //con_print << "view: track" << std::endl;
//core::application()->notify_message(std::string("view: track"));
break;
case Free:
// switch camera to Cockpit mode
set_mode(Cockpit);
- con_print << "view: cockpit" << std::endl;
+ //con_print << "view: cockpit" << std::endl;
//core::application()->notify_message(std::string("view: cockpit"));
break;
case Track:
// switch camera to Free mode
set_mode(Free);
- con_print << "view: free" << std::endl;
+ //con_print << "view: free" << std::endl;
//core::application()->notify_message(std::string("view: free"));
break;