pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3344 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3344 - trunk/pingus/src
Date: Sat, 27 Oct 2007 13:51:35 +0200

Author: grumbel
Date: 2007-10-27 13:51:35 +0200 (Sat, 27 Oct 2007)
New Revision: 3344

Modified:
   trunk/pingus/src/level_menu.cpp
   trunk/pingus/src/levelset.cpp
   trunk/pingus/src/levelset.hpp
Log:
- added savegame stuff to levelset

Modified: trunk/pingus/src/level_menu.cpp
===================================================================
--- trunk/pingus/src/level_menu.cpp     2007-10-27 10:00:45 UTC (rev 3343)
+++ trunk/pingus/src/level_menu.cpp     2007-10-27 11:51:35 UTC (rev 3344)
@@ -149,23 +149,30 @@
 
     if (levelset)
       {
+        levelset->refresh(); // should be better placed in on_startup() or so
+        
         //gc.draw_fillrect(Rect(Vector2i(0,0), Size(rect.get_width(), 
rect.get_height())),
         //                 Color(255, 255, 0, 100));
 
         gc.print_left(Fonts::chalk_normal,  30, -32, "Levelname");
-        gc.print_right(Fonts::chalk_normal, rect.get_width() - 30, - 32, 
"Completed");
+        gc.print_right(Fonts::chalk_normal, rect.get_width() - 30, - 32, 
"Status");
 
         int y = 0;
         for(int i = 0; i < levelset->get_level_count(); ++i)
           {
-            if (i == current_level)
+            if (!levelset->get_level(i)->accessible)
+              gc.draw(marker_locked, 0, y);
+            else if (i == current_level)
               gc.draw(marker, 0, y);
-            else if (i > 3)
-              gc.draw(marker_locked, 0, y);
+                        
+            std::string level = levelset->get_level(i)->plf.get_levelname();
+            gc.print_left(Fonts::chalk_small, 30, y+4, level);
 
-            std::string level = levelset->get_level(i);          
-            gc.print_left(Fonts::chalk_small, 30, y+4, level);
-            gc.print_right(Fonts::chalk_small, rect.get_width() -30, y+4, 
"[x]");
+            if (levelset->get_level(i)->finished)
+              gc.print_right(Fonts::chalk_small, rect.get_width() -30, y+4, 
"solved");
+            else
+              gc.print_right(Fonts::chalk_small, rect.get_width() -30, y+4, 
"unsolved");
+
             y += 32;
           }
       }
@@ -193,9 +200,10 @@
   {
     if (current_level != -1)
       {
-        PingusLevel level(Pathname("levels/" + 
levelset->get_level(current_level), Pathname::DATA_PATH));
-        //ScreenManager::instance()->push_screen(new PingusGameSession(level, 
false), true);
-        ScreenManager::instance()->push_screen(new StartScreen(level), true);
+        if (levelset->get_level(current_level)->accessible);
+          {
+            ScreenManager::instance()->push_screen(new 
StartScreen(levelset->get_level(current_level)->plf), true);
+          }
       }
   }
 

Modified: trunk/pingus/src/levelset.cpp
===================================================================
--- trunk/pingus/src/levelset.cpp       2007-10-27 10:00:45 UTC (rev 3343)
+++ trunk/pingus/src/levelset.cpp       2007-10-27 11:51:35 UTC (rev 3344)
@@ -21,6 +21,8 @@
 #include "pingus_error.hpp"
 #include "file_reader.hpp"
 #include "levelset.hpp"
+#include "plf_res_mgr.hpp"
+#include "savegame_manager.hpp"
 
 Levelset::Levelset(const Pathname& pathname)
 {
@@ -39,12 +41,14 @@
         {
           if (i->get_name() == "level")
             {
-              Level level;
-              level.accessible = false;
-              level.finished   = false;
-
-              if (i->read_string("filename", level.filename))
+              Level* level = new Level();
+              if (i->read_string("filename", level->resname))
                 {
+                  level->plf        = PLFResMgr::load_plf(level->resname);
+                  
+                  level->accessible = false;
+                  level->finished   = false;
+                      
                   levels.push_back(level);
                 }
               else
@@ -55,12 +59,12 @@
         }
     }
 
-  if (!levels.empty())
-    levels.front().accessible = true;
+  refresh();
 }
 
 Levelset::~Levelset()
 {
+  
 }
 
 std::string
@@ -75,13 +79,13 @@
   return description;
 }
 
-std::string
+Levelset::Level*
 Levelset::get_level(int num) const
 {
   if (num >= 0 && num < int(levels.size()))
-    return levels[num].filename;
+    return levels[num];
   else
-    return "";
+    return 0;
 }
 
 int
@@ -97,4 +101,33 @@
   return 0;
 }
 
+void
+Levelset::refresh()
+{
+  for(std::vector<Level*>::iterator i = levels.begin(); i != levels.end(); ++i)
+    {
+      Savegame* savegame = SavegameManager::instance()->get((*i)->resname);
+
+      if (savegame)
+        {
+          (*i)->accessible = (savegame->get_status() != Savegame::NONE);
+          (*i)->finished   = (savegame->get_status() == Savegame::FINISHED);
+        }
+    }
+
+  if (!levels.empty())
+    {
+      if (levels.size() == 1)
+        {
+          levels[0]->accessible = true; 
+        }
+      else
+        {
+          for(std::vector<Level*>::size_type i = 0; i < levels.size()-1; ++i)
+            if (levels[i]->finished)
+              levels[i+1]->accessible = true;
+        }
+    }
+}
+
 /* EOF */

Modified: trunk/pingus/src/levelset.hpp
===================================================================
--- trunk/pingus/src/levelset.hpp       2007-10-27 10:00:45 UTC (rev 3343)
+++ trunk/pingus/src/levelset.hpp       2007-10-27 11:51:35 UTC (rev 3344)
@@ -22,21 +22,24 @@
 
 #include <string>
 #include <vector>
+#include "pingus_level.hpp"
 #include "pathname.hpp"
 
 /** */
 class Levelset
 {
-private:
+public:
   struct Level {
-    std::string filename;
+    std::string resname;
     bool accessible;
     bool finished;
+    PingusLevel plf;
   };
 
+private:
   std::string title;
   std::string description;
-  std::vector<Level> levels;
+  std::vector<Level*> levels;
 
 public:
   Levelset(const Pathname& pathname);
@@ -44,12 +47,13 @@
 
   std::string get_title() const;
   std::string get_description() const;
-  std::string get_level(int num) const;
+  Level* get_level(int num) const;
   int get_level_count() const;
 
   /** Return the number of completed levels */
   int get_completion()  const;
 
+  void refresh();
 private:
   Levelset (const Levelset&);
   Levelset& operator= (const Levelset&);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]