src/Graphics.cc
changeset 393 5dd4d782cf3a
parent 392 6c4dc68360eb
child 394 82def222fe7d
--- a/src/Graphics.cc	Tue Jan 13 21:36:43 2009 +0200
+++ b/src/Graphics.cc	Tue Jan 13 23:15:47 2009 +0200
@@ -4,6 +4,18 @@
 #include <cmath>
 #include <sstream>
 
+/*
+ * XXX: until we figure out a better way to layout stuff
+ */
+static PixelArea getMessageViewArea (PixelCoordinate resolution) {
+    return PixelArea(
+            400,
+            resolution.y - 100,
+            resolution.x,
+            resolution.y
+    );
+}
+
 Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) :
     CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen),
     engine(engine), 
@@ -11,7 +23,8 @@
     resolution(resolution),
     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
     input(get_ic()->get_keyboard()),
-    simple_font("Font2", engine.getResourceManager()) 
+    simple_font("Font2", engine.getResourceManager()),
+    message_view(getMessageViewArea(resolution))
 {
 
     // connect timer signal
@@ -19,6 +32,12 @@
 
     // enable
     update_timer.start();
+
+    // push something to message_view
+    message_view.add_message(CL_Color::white, "Hello World"); 
+
+    // GameState events....
+    state.setEventHandler(this);
 }
 
 const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) {
@@ -75,8 +94,11 @@
     }
 
     // dump player debug info on stderr
-    if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer())
+    if ((flags & GUI_INPUT_DEBUG_PLAYER) && state.getLocalPlayer()) {
         state.getLocalPlayer()->printDebugInfo();
+        
+        message_view.add_message(CL_Color::green, "...");
+    }
     
     // toggle fullscreen?
     if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) {
@@ -128,11 +150,14 @@
 
     // Draw the game
     state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON);
-
+    
+    // draw player info box
     if (player != NULL) {
-        // draw player info box
         draw_player_info(gc, player);
     }
+    
+    // draw messages
+    message_view.draw(this);
 
     // Flip window buffer, sync
     flip(1);
@@ -261,5 +286,14 @@
         p->getCurrentWeapon()->getName(),
         get_gc()
     );
+
 }
 
+    
+void Graphics::on_player_joined (Player *p) {
+    message_view.add_message(CL_Color::white, " *** Player joined");
+}
+    
+void Graphics::on_player_left (Player *p) {
+    message_view.add_message(CL_Color::white, " *** Player left");
+}