Updated addon repository URL and improved debug output on download
[supertux.git] / src / trigger / secretarea_trigger.cpp
index abf342b..3242f45 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <config.h>
+#include "trigger/secretarea_trigger.hpp"
 
-#include "secretarea_trigger.hpp"
-#include "game_session.hpp"
-#include "lisp/lisp.hpp"
-#include "lisp/writer.hpp"
-#include "object_factory.hpp"
-#include "main.hpp"
-#include "sector.hpp"
-#include "level.hpp"
-#include "gettext.hpp"
 #include "object/tilemap.hpp"
+#include "supertux/level.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/resources.hpp"
+#include "supertux/sector.hpp"
+#include "util/gettext.hpp"
+#include "util/reader.hpp"
+#include "util/writer.hpp"
 
 static const float MESSAGE_TIME=3.5;
 
-SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader)
-        : fade_tilemap("")
+SecretAreaTrigger::SecretAreaTrigger(const Reader& reader) :
+  message_timer(),
+  message_displayed(),
+  message(),
+  fade_tilemap(),
+  script()
 {
   reader.get("x", bbox.p1.x);
   reader.get("y", bbox.p1.y);
@@ -42,12 +42,21 @@ SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader)
   reader.get("height", h);
   bbox.set_size(w, h);
   reader.get("fade-tilemap", fade_tilemap);
+  reader.get("message", message);
+  if(message == "") {
+    message = _("You found a secret area!");
+  }
+  reader.get("script", script);
 
   message_displayed = false;
 }
 
-SecretAreaTrigger::SecretAreaTrigger(const Rect& area, std::string fade_tilemap)
-        : fade_tilemap(fade_tilemap)
+SecretAreaTrigger::SecretAreaTrigger(const Rectf& area, std::string fade_tilemap_) :
+  message_timer(),
+  message_displayed(),
+  message(_("You found a secret area!")),
+  fade_tilemap(fade_tilemap_),
+  script()
 {
   bbox = area;
   message_displayed = false;
@@ -57,18 +66,10 @@ SecretAreaTrigger::~SecretAreaTrigger()
 {
 }
 
-void
-SecretAreaTrigger::write(lisp::Writer& writer)
+std::string
+SecretAreaTrigger::get_fade_tilemap_name()
 {
-  writer.start_list("secretarea");
-
-  writer.write("x", bbox.p1.x);
-  writer.write("y", bbox.p1.y);
-  writer.write("width", bbox.get_width());
-  writer.write("height", bbox.get_height());
-  writer.write("fade-tilemap", fade_tilemap);
-
-  writer.end_list("secretarea");
+  return fade_tilemap;
 }
 
 void
@@ -77,8 +78,8 @@ SecretAreaTrigger::draw(DrawingContext& context)
   if (message_timer.started()) {
     context.push_transform();
     context.set_translation(Vector(0, 0));
-    Vector pos = Vector(0, SCREEN_HEIGHT/2 - normal_font->get_height()/2);
-    context.draw_center_text(normal_font, _("You found a secret area!"), pos, LAYER_GUI, SecretAreaTrigger::text_color);
+    Vector pos = Vector(0, SCREEN_HEIGHT/2 - Resources::normal_font->get_height()/2);
+    context.draw_center_text(Resources::normal_font, message, pos, LAYER_HUD, SecretAreaTrigger::text_color);
     context.pop_transform();
   }
   if (message_timer.check()) {
@@ -99,15 +100,19 @@ SecretAreaTrigger::event(Player& , EventType type)
         // fade away tilemaps
         Sector& sector = *Sector::current();
         for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) {
-          TileMap* tm = dynamic_cast<TileMap*>(*i);
+          TileMap* tm = dynamic_cast<TileMap*>(i->get());
           if (!tm) continue;
           if (tm->get_name() != fade_tilemap) continue;
           tm->fade(0.0, 1.0);
         }
       }
 
+      if(script != "") {
+        std::istringstream stream(script);
+        Sector::current()->run_script(stream, "SecretAreaScript");
+      }
     }
   }
 }
 
-IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea");
+/* EOF */