Console logging is now identical in all builds; warning and error show the console...
[supertux.git] / src / supertux / console.cpp
index 860869b..883ec09 100644 (file)
@@ -51,7 +51,7 @@ Console::Console() :
 Console::~Console()
 {
   if(vm != NULL) {
-    sq_release(Scripting::global_vm, &vm_object);
+    sq_release(scripting::global_vm, &vm_object);
   }
 }
 
@@ -60,8 +60,8 @@ Console::init_graphics()
 {
   font.reset(new Font(Font::FIXED,"fonts/andale12.stf",1));
   fontheight = font->get_height();
-  background.reset(new Surface("images/engine/console.png"));
-  background2.reset(new Surface("images/engine/console2.png"));
+  background = Surface::create("images/engine/console.png");
+  background2 = Surface::create("images/engine/console2.png");
 }
 
 void
@@ -81,15 +81,15 @@ void
 Console::ready_vm()
 {
   if(vm == NULL) {
-    vm = Scripting::global_vm;
+    vm = scripting::global_vm;
     HSQUIRRELVM new_vm = sq_newthread(vm, 16);
     if(new_vm == NULL)
-      throw Scripting::SquirrelError(vm, "Couldn't create new VM thread for console");
+      throw scripting::SquirrelError(vm, "Couldn't create new VM thread for console");
 
     // store reference to thread
     sq_resetobject(&vm_object);
     if(SQ_FAILED(sq_getstackobj(vm, -1, &vm_object)))
-      throw Scripting::SquirrelError(vm, "Couldn't get vm object for console");
+      throw scripting::SquirrelError(vm, "Couldn't get vm object for console");
     sq_addref(vm, &vm_object);
     sq_pop(vm, 1);
 
@@ -97,7 +97,7 @@ Console::ready_vm()
     sq_newtable(new_vm);
     sq_pushroottable(new_vm);
     if(SQ_FAILED(sq_setdelegate(new_vm, -2)))
-      throw Scripting::SquirrelError(new_vm, "Couldn't set console_table delegate");
+      throw scripting::SquirrelError(new_vm, "Couldn't set console_table delegate");
 
     sq_setroottable(new_vm);
 
@@ -106,7 +106,7 @@ Console::ready_vm()
     try {
       std::string filename = "scripts/console.nut";
       IFileStream stream(filename);
-      Scripting::compile_and_run(vm, stream, filename);
+      scripting::compile_and_run(vm, stream, filename);
     } catch(std::exception& e) {
       log_warning << "Couldn't load console.nut: " << e.what() << std::endl;
     }
@@ -116,7 +116,7 @@ Console::ready_vm()
 void
 Console::execute_script(const std::string& command)
 {
-  using namespace Scripting;
+  using namespace scripting;
 
   ready_vm();
 
@@ -363,7 +363,7 @@ Console::addLine(std::string s)
     lines.pop_back();
 
   // increase console height if necessary
-  if (height < 64) {
+  if ((stayOpen > 0) && (height < 64)) {
     if(height < 4)
       height = 4;
     height += fontheight * line_count;
@@ -371,10 +371,6 @@ Console::addLine(std::string s)
 
   // reset console to full opacity
   alpha = 1.0;
-
-  // increase time that console stays open
-  if(stayOpen < 6)
-    stayOpen += 1.5;
 }
 
 void
@@ -439,6 +435,13 @@ Console::show()
 }
 
 void
+Console::open()
+{
+  if(stayOpen < 2)
+    stayOpen += 1.5;
+}
+
+void
 Console::hide()
 {
   focused = false;
@@ -488,10 +491,10 @@ Console::draw(DrawingContext& context)
 
   context.push_transform();
   context.set_alpha(alpha);
-  context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
-  context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
+  context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), layer);
+  context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), layer);
   for (int x = (SCREEN_WIDTH/2 - background->get_width()/2 - (static_cast<int>(ceilf((float)SCREEN_WIDTH / (float)background->get_width()) - 1) * background->get_width())); x < SCREEN_WIDTH; x+=background->get_width()) {
-    context.draw_surface(background.get(), Vector(x, height - background->get_height()), layer);
+    context.draw_surface(background, Vector(x, height - background->get_height()), layer);
   }
   backgroundOffset+=10;
   if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width();
@@ -501,10 +504,10 @@ Console::draw(DrawingContext& context)
   if (focused) {
     lineNo++;
     float py = height-4-1 * font->get_height();
-    context.draw_text(font.get(), "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer);
+    context.draw_text(font, "> "+inputBuffer, Vector(4, py), ALIGN_LEFT, layer);
     if (SDL_GetTicks() % 1000 < 750) {
       int cursor_px = 2 + inputBufferPosition;
-      context.draw_text(font.get(), "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer);
+      context.draw_text(font, "_", Vector(4 + (cursor_px * font->get_text_width("X")), py), ALIGN_LEFT, layer);
     }
   }
 
@@ -514,7 +517,7 @@ Console::draw(DrawingContext& context)
     lineNo++;
     float py = height - 4 - lineNo*font->get_height();
     if (py < -font->get_height()) break;
-    context.draw_text(font.get(), *i, Vector(4, py), ALIGN_LEFT, layer);
+    context.draw_text(font, *i, Vector(4, py), ALIGN_LEFT, layer);
   }
   context.pop_transform();
 }