pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3176 - in trunk/pingus: . src/editor


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3176 - in trunk/pingus: . src/editor
Date: Tue, 18 Sep 2007 17:23:34 +0200

Author: grumbel
Date: 2007-09-18 17:23:33 +0200 (Tue, 18 Sep 2007)
New Revision: 3176

Modified:
   trunk/pingus/TODO
   trunk/pingus/src/editor/editor_level.cpp
   trunk/pingus/src/editor/editor_screen.cpp
   trunk/pingus/src/editor/editor_screen.hpp
   trunk/pingus/src/editor/editor_viewport.cpp
   trunk/pingus/src/editor/editor_viewport.hpp
   trunk/pingus/src/editor/file_dialog.cpp
   trunk/pingus/src/editor/file_dialog.hpp
Log:
- added save and save_as
- fixed level loading

Modified: trunk/pingus/TODO
===================================================================
--- trunk/pingus/TODO   2007-09-18 01:27:03 UTC (rev 3175)
+++ trunk/pingus/TODO   2007-09-18 15:23:33 UTC (rev 3176)
@@ -201,11 +201,13 @@
 
 - add options to show/hide hidden files and filter stuff
 
-- add new level and save level dialogs
+- add new level
 
 Less Important:
 ===============
 
+- added overwrite warning to file dialog
+
 - add pixel perfect object selection
 
 - implement a minimap (just rects when surfaces are to tricky)

Modified: trunk/pingus/src/editor/editor_level.cpp
===================================================================
--- trunk/pingus/src/editor/editor_level.cpp    2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/editor_level.cpp    2007-09-18 15:23:33 UTC (rev 
3176)
@@ -173,6 +173,8 @@
     delete impl;
   impl = new LevelImpl();
 
+  editor->get_viewport()->clear();
+
   // Load the level from the file - we don't care what it's res_name is.
   PingusLevel level(pathname);
        

Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp   2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/editor_screen.cpp   2007-09-18 15:23:33 UTC (rev 
3176)
@@ -74,13 +74,22 @@
   object_properties = new ObjectProperties(this, 
Rect(Vector2i(0,Display::get_height()-150), Size(200, 150)));
   gui_manager->add(object_properties, true);
 
-  file_dialog = new FileDialog(this, Rect(Vector2i(50, 50), 
+  file_load_dialog = new FileDialog(this, Rect(Vector2i(50, 50), 
                                           Size(Display::get_width() - 100, 
-                                               Display::get_height() - 100)));
-  file_dialog->set_directory(".");
-  file_dialog->hide();
-  gui_manager->add(file_dialog, true);
+                                               Display::get_height() - 100)), 
+                               FileDialog::LOAD);
+  file_load_dialog->set_directory(".");
+  file_load_dialog->hide();
+  gui_manager->add(file_load_dialog, true);
 
+  file_save_dialog = new FileDialog(this, Rect(Vector2i(50, 50), 
+                                          Size(Display::get_width() - 100, 
+                                               Display::get_height() - 100)), 
+                                    FileDialog::SAVE);
+  file_save_dialog->set_directory(".");
+  file_save_dialog->hide();
+  gui_manager->add(file_save_dialog, true);
+
   
viewport->selection_changed.connect(boost::bind(&ObjectProperties::set_objects, 
object_properties, _1));
 
   action_properties = new ActionProperties(this, Rect(Vector2i(0, 38), 
Size(150, 284)));
@@ -117,16 +126,19 @@
 
 // Save the current level
 void 
-EditorScreen::save(const std::string &file)
+EditorScreen::save(const Pathname& file)
 {
-  plf->save_level(file);
+  level_pathname = file;
+  std::cout << "Save to: " << file.str() << std::endl;
+  plf->save_level(level_pathname.get_sys_path());
 }
 
 // Load a new level
 void 
 EditorScreen::load(const Pathname& file)
 {
-  plf->load_level(file);
+  level_pathname = file;
+  plf->load_level(level_pathname);
   level_properties->set_level(plf);
   action_properties->set_level(plf);
   viewport->refresh();
@@ -225,27 +237,34 @@
 void 
 EditorScreen::level_load()
 {
-  if (file_dialog->is_visible())
-    file_dialog->hide();
+  if (file_load_dialog->is_visible())
+    file_load_dialog->hide();
   else 
-    {
-      //file_dialog->set_rect(Rect(Vector2i(rand() % 200, rand() % 200),
-      //                                Size(rand()%600+200, rand()%600+300)));
-      file_dialog->show();
-    }
+    file_load_dialog->show();
 }
 
 void 
 EditorScreen::level_save()
 {
-  std::cout << "Function at '" << __FILE__ << ":" << __LINE__ << "' is 
unimplemented" << std::endl; 
+  if (level_pathname.empty())
+    {
+      level_save_as();
+    }
+  else
+    {
+      save(level_pathname); 
+    }
 }
 
 void 
 EditorScreen::level_save_as()
 {
-  std::cout << "Function at '" << __FILE__ << ":" << __LINE__ << "' is 
unimplemented" << std::endl; 
+  if (file_save_dialog->is_visible())
+    file_save_dialog->hide();
+  else 
+    file_save_dialog->show();
 }
+
 void
 EditorScreen::level_play()
 {

Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp   2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/editor_screen.hpp   2007-09-18 15:23:33 UTC (rev 
3176)
@@ -22,6 +22,7 @@
 #define HEADER_PINGUS_EDITOR_SCREEN_HXX
 
 #include "../gui/gui_screen.hpp"
+#include "pathname.hpp"
 #include "file_dialog.hpp"
 
 class DrawingContext;
@@ -46,14 +47,16 @@
 {
 private:
   EditorLevel* plf;
-
+  Pathname level_pathname;
+  
   Panel* panel;
   EditorViewport*   viewport;
   ObjectSelector*   object_selector;
   ObjectProperties* object_properties;
   ActionProperties* action_properties;
   LevelProperties*  level_properties;
-  FileDialog*   file_dialog;
+  FileDialog*       file_load_dialog;
+  FileDialog*       file_save_dialog;
   
   bool show_help;
 
@@ -96,7 +99,7 @@
   void cancel();
 
   /** Saves the currently loaded level */
-  void save(const std::string &file);
+  void save(const Pathname& file);
 
   /** Load a new level */
   void load(const Pathname& file);

Modified: trunk/pingus/src/editor/editor_viewport.cpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.cpp 2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/editor_viewport.cpp 2007-09-18 15:23:33 UTC (rev 
3176)
@@ -453,6 +453,15 @@
   state.set_size(rect.get_width(), rect.get_height());
   drawing_context->set_rect(rect);
 }
+
+void
+EditorViewport::clear()
+{
+  selected_objs.clear();
+  for(std::vector<LevelObj*>::iterator i = objs.begin(); i != objs.end(); ++i)
+    delete *i;
+  objs.clear();
+}
 
 } // namespace Editor
 

Modified: trunk/pingus/src/editor/editor_viewport.hpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.hpp 2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/editor_viewport.hpp 2007-09-18 15:23:33 UTC (rev 
3176)
@@ -150,6 +150,8 @@
 
   std::vector<LevelObj*>* get_objects() { return &objs; }
 
+  void clear();
+
   boost::signal<void (const std::vector<LevelObj*>&)> selection_changed;
 private:
   EditorViewport();

Modified: trunk/pingus/src/editor/file_dialog.cpp
===================================================================
--- trunk/pingus/src/editor/file_dialog.cpp     2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/file_dialog.cpp     2007-09-18 15:23:33 UTC (rev 
3176)
@@ -22,6 +22,7 @@
 #include "display/drawing_context.hpp"
 #include "gui/gui_manager.hpp"
 #include "editor_screen.hpp"
+#include "system.hpp"
 #include "gui_style.hpp"
 #include "fonts.hpp"
 #include "gettext.h"
@@ -33,9 +34,10 @@
 
 namespace Editor {
 
-FileDialog::FileDialog(EditorScreen* editor_, const Rect& rect)
+FileDialog::FileDialog(EditorScreen* editor_, const Rect& rect, Mode mode_)
   : GroupComponent(rect),
     editor(editor_),
+    mode(mode_),
     file_list(Rect(4, 30 + 30 + 30,
                    rect.get_width()-4 - 30, rect.get_height() - 4 - 35))
 {
@@ -44,26 +46,29 @@
 
   Rect file_rect = file_list.get_rect();
   up_button = new Button(Rect(file_rect.right + 2, file_rect.top,
-                                     rect.get_width()-4, file_rect.top + 
file_rect.get_height()/2 - 1),
-                                "/\\\n|");
+                              rect.get_width()-4, file_rect.top + 
file_rect.get_height()/2 - 1),
+                         "/\\\n|");
   down_button = new Button(Rect(file_rect.right + 2, file_rect.top + 
file_rect.get_height()/2 + 1,
                                 rect.get_width()-4, file_rect.bottom),
                            "|\n\\/");
 
-  // FIXME: This could be turned into system specific hotkeys (C:, D:,
-  // etc. on windows, Home, '/', Datadir on Linux)
-  home_button = new Button(Rect(Vector2i(4, rect.get_height() - 4 - 30),
-                                        Size(100, 30)), "Home");
+  datadir_button = new Button(Rect(Vector2i(4, rect.get_height() - 4 - 30),
+                                   Size(100, 30)), "Datadir");
+  userdir_button = new Button(Rect(Vector2i(4 + 110, rect.get_height() - 4 - 
30),
+                                   Size(100, 30)), "Userdir");
   
   open_button = new Button(Rect(Vector2i(rect.get_width() - 104, 
rect.get_height() - 4 - 30),
-                                        Size(100, 30)), "Open");
+                                Size(100, 30)), mode == LOAD ? "Open" : 
"Save");
   
   cancel_button = new Button(Rect(Vector2i(rect.get_width() - 104 - 104, 
rect.get_height() - 4 - 30),
                                   Size(100, 30)), "Cancel");
   
   up_button->on_click.connect(boost::bind(&FileDialog::on_up, this));
   down_button->on_click.connect(boost::bind(&FileDialog::on_down, this));
-  home_button->on_click.connect(boost::bind(&FileDialog::on_home, this));
+
+  datadir_button->on_click.connect(boost::bind(&FileDialog::on_datadir, this));
+  userdir_button->on_click.connect(boost::bind(&FileDialog::on_userdir, this));
+
   open_button->on_click.connect(boost::bind(&FileDialog::on_open, this));
   cancel_button->on_click.connect(boost::bind(&FileDialog::on_cancel, this));
 
@@ -76,7 +81,8 @@
   add(up_button, true);
   add(down_button, true);
 
-  add(home_button, true);
+  add(datadir_button, true);
+  add(userdir_button, true);
 
   add(open_button, true);
   add(cancel_button, true);
@@ -92,7 +98,8 @@
   // Window border and title 
   GUIStyle::draw_raised_box(gc, Rect(0,0,rect.get_width(), rect.get_height()));
   gc.draw_fillrect(4,4,rect.get_width()-4, 30, Color(77,130,180));
-  gc.print_center(Fonts::pingus_small, rect.get_width()/2, 2, _("Open a 
level"));
+  gc.print_center(Fonts::pingus_small, rect.get_width()/2, 2, 
+                  mode == LOAD ? _("Open a level") : _("Save your level"));
 }
   
 void
@@ -133,10 +140,20 @@
 {
   if (!filename_inputbox->get_text().empty())
     {
-      Pathname file(pathname_inputbox->get_text() + "/" + 
filename_inputbox->get_text(), Pathname::SYSTEM_PATH);
-      std::cout << "Open: " << file << std::endl;
-      editor->load(file);
-      hide();
+      if (mode == LOAD)
+        {
+          Pathname file(pathname_inputbox->get_text() + "/" + 
filename_inputbox->get_text(), Pathname::SYSTEM_PATH);
+          std::cout << "Open: " << file << std::endl;
+          editor->load(file);
+          hide();
+        }
+      else if (mode == SAVE) 
+        {
+          Pathname file(pathname_inputbox->get_text() + "/" + 
filename_inputbox->get_text(), Pathname::SYSTEM_PATH);
+          std::cout << "Save: " << file << std::endl;
+          editor->save(file);
+          hide();
+        }
     }
 }
 
@@ -165,7 +182,7 @@
   Rect file_rect = file_list.get_rect();
 
   up_button->set_rect(Rect(file_rect.right + 2, file_rect.top,
-                          rect.get_width()-4, file_rect.top + 
file_rect.get_height()/2 - 1));
+                           rect.get_width()-4, file_rect.top + 
file_rect.get_height()/2 - 1));
                      
   down_button->set_rect(Rect(file_rect.right + 2, file_rect.top + 
file_rect.get_height()/2 + 1,
                              rect.get_width()-4, file_rect.bottom));
@@ -178,12 +195,18 @@
 }
 
 void
-FileDialog::on_home()
-{
-  
+FileDialog::on_userdir()
+{ 
+  set_directory(System::get_statdir() + "levels/");
 }
 
 void
+FileDialog::on_datadir()
+{ 
+  set_directory(Pathname("levels/", Pathname::DATA_PATH).get_sys_path());
+}
+
+void
 FileDialog::update_button_state()
 {
   if (file_list.has_more_prev_pages())

Modified: trunk/pingus/src/editor/file_dialog.hpp
===================================================================
--- trunk/pingus/src/editor/file_dialog.hpp     2007-09-18 01:27:03 UTC (rev 
3175)
+++ trunk/pingus/src/editor/file_dialog.hpp     2007-09-18 15:23:33 UTC (rev 
3176)
@@ -33,15 +33,21 @@
 /** */
 class FileDialog : public GUI::GroupComponent
 {
+public: 
+  enum Mode { LOAD, SAVE };
 private:
   EditorScreen* editor;
+  Mode mode;
+
   FileList file_list;
   Button* up_button;
   Button* down_button;
   Button* open_button;
   Button* cancel_button;
-  Button* home_button;
 
+  Button* datadir_button;
+  Button* userdir_button;
+
   Label* pathname_label;
   Label* filename_label;
 
@@ -49,7 +55,7 @@
   Inputbox* filename_inputbox;
 
 public:
-  FileDialog(EditorScreen* editor, const Rect& rect);
+  FileDialog(EditorScreen* editor, const Rect& rect, Mode mode);
   ~FileDialog();
   
   void draw_background(DrawingContext& gc);
@@ -64,7 +70,8 @@
   void on_up();
   void on_down();
   
-  void on_home();
+  void on_datadir();
+  void on_userdir();
 
 private:
   void update_button_state();





reply via email to

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