pingus-cvs
[Top][All Lists]
Advanced

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

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


From: jave27
Subject: [Pingus-CVS] r2566 - in trunk/src: . editor
Date: Wed, 28 Dec 2005 18:54:02 +0100

Author: jave27
Date: 2005-12-28 18:53:40 +0100 (Wed, 28 Dec 2005)
New Revision: 2566

Modified:
   trunk/src/editor/editor_screen.cxx
   trunk/src/editor/editor_screen.hxx
   trunk/src/editor/panel_buttons.cxx
   trunk/src/file_dialog.cxx
   trunk/src/file_dialog.hxx
   trunk/src/file_dialog_listener.hxx
   trunk/src/pingus_menu.cxx
   trunk/src/pingus_menu.hxx
   trunk/src/pingus_menu_manager.cxx
   trunk/src/pingus_menu_manager.hxx
   trunk/src/pingus_sub_menu.hxx
Log:
Added file dialog to Editor (load only so far).

Modified: trunk/src/editor/editor_screen.cxx
===================================================================
--- trunk/src/editor/editor_screen.cxx  2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/editor/editor_screen.cxx  2005-12-28 17:53:40 UTC (rev 2566)
@@ -27,6 +27,8 @@
 #include "../res_descriptor.hxx"
 #include "../resource.hxx"
 #include "../fonts.hxx"
+#include "../file_dialog.hxx"
+#include "../path_manager.hxx"
 #include "editor_screen.hxx"
 #include "editor_panel.hxx"
 #include "editor_viewport.hxx"
@@ -39,7 +41,9 @@
 
 // Default constructor
 EditorScreen::EditorScreen(XMLLevel* level)
-: plf(level)
+: plf(level), 
+       close_dialog(false),
+       filedialog(0)
 {
        if (!plf) plf = new XMLLevel();
 }
@@ -48,6 +52,8 @@
 EditorScreen::~EditorScreen()
 {
        delete plf;
+       if (filedialog)
+               delete filedialog;
 }
 
 // Startup code
@@ -79,18 +85,39 @@
   close_screen();
 }
 
+// Show dialog box
+void
+EditorScreen::show_file_dialog(bool for_loading)
+{
+       if (filedialog)
+               delete filedialog;
+       close_dialog = false;
+       filedialog = new FileDialog(this, ".pingus", 
+               path_manager.complete("levels/"), for_loading);
+       filedialog->preload();  
+}
+
+// Close dialog box
+void
+EditorScreen::cancel()
+{
+       close_dialog = true;
+}
+
 // Save the current level
 void 
-EditorScreen::save_level(const std::string levelfile)
+EditorScreen::save(const std::string &file, const std::string &filemask)
 {
-       plf->save_level(levelfile);
+       close_dialog = true;
+       plf->save_level(file);
 }
 
 // Load a new level
 void 
-EditorScreen::load_level(const std::string levelfile)
+EditorScreen::load(const std::string &file, const std::string &filemask)
 {
-       plf->load_level(levelfile);
+       close_dialog = true;
+       plf->load_level(file);
 }
 
 // Play the current level (save to a temporary file 
@@ -115,10 +142,33 @@
                (float)CL_Display::get_height(), CL_Color::black, -10000);
        gui_manager->draw(gc);
 
+       // FIXME: Remove this warning
        gc.print_center(Fonts::pingus_large, (float)(CL_Display::get_width() / 
2), 
                (float)(CL_Display::get_height() / 2), "Not yet functional");
+               
+       if (filedialog)
+               filedialog->draw(gc);
+       
        return true;
 }
 
+void
+EditorScreen::update(const GameDelta &delta)
+{
+       if (filedialog)
+       {
+               if (close_dialog)
+               {
+                       delete filedialog;
+                       filedialog = 0;
+               }
+               else
+                       filedialog->update(delta);
+       }
+       else
+               GUIScreen::update(delta);
+
+}
+
 } // Editor namespace
 } // Pingus namespace

Modified: trunk/src/editor/editor_screen.hxx
===================================================================
--- trunk/src/editor/editor_screen.hxx  2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/editor/editor_screen.hxx  2005-12-28 17:53:40 UTC (rev 2566)
@@ -21,10 +21,12 @@
 #define HEADER_PINGUS_EDITOR_SCREEN_HXX
 
 #include "../gui/gui_screen.hxx"
+#include "../file_dialog_listener.hxx"
 
 namespace Pingus {
 
 class DrawingContext;
+class FileDialog;
 class GUI::GUIManager;
 
 namespace Editor {
@@ -35,18 +37,23 @@
 
 /** This class is the screen that contains all of the
        editor objects */
-class EditorScreen : public GUIScreen
+class EditorScreen : public GUIScreen, public FileDialogListener
 {
 private:
-       /* The level currently being edited */
+       /** The level currently being edited */
        XMLLevel* plf;
 
-       /* Panel which contains all of the buttons for each action */
+       /** Panel which contains all of the buttons for each action */
        EditorPanel* panel;
 
-       /* Viewport which holds all of the level images and data */
+       /** Viewport which holds all of the level images and data */
        EditorViewport* viewport;
 
+       /** File Dialog box */
+       FileDialog* filedialog;
+
+       bool close_dialog;
+
 public:
        /** Default constructor */
   EditorScreen(XMLLevel* level = 0);
@@ -66,17 +73,26 @@
        /** Draw the items in the screen */
        bool draw (DrawingContext& gc);
 
+       /** Update the GUI objects */
+       void update (const GameDelta& delta);
+
        /** Return the gui_manager */
        GUI::GUIManager* get_gui_manager() const { return gui_manager; }
 
        /** Return a pointer to the current level */
        XMLLevel* get_level() const { return plf; }
 
+       /** Show a file dialog box */
+       void show_file_dialog(bool for_loading);
+
+       /** Closes the file dialog box */
+       void cancel();
+
        /** Saves the currently loaded level */
-       void save_level(const std::string levelfile);
+       void save(const std::string &file, const std::string &filemask);
 
        /** Load a new level */
-       void load_level(const std::string levelfile);
+       void load(const std::string &file, const std::string &filemask);
 
        /** Plays the currently loaded level */
        void play_level();

Modified: trunk/src/editor/panel_buttons.cxx
===================================================================
--- trunk/src/editor/panel_buttons.cxx  2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/editor/panel_buttons.cxx  2005-12-28 17:53:40 UTC (rev 2566)
@@ -104,7 +104,7 @@
 PanelButtonLoad::on_primary_button_click(int x, int y)
 {
        // TODO: Open a file dialog box to load a level.
-       
panel->get_screen()->load_level(path_manager.complete("levels/tutorial/miner-tutorial2-grumbel.pingus"));
+       panel->get_screen()->show_file_dialog(true);
 }
 
 // Standard save button
@@ -120,7 +120,7 @@
 PanelButtonSave::on_primary_button_click(int x, int y)
 {
        // TODO: Open a file dialog box to save the level.
-       
panel->get_screen()->save_level(path_manager.complete("levels/test.pingus"));
+       panel->get_screen()->save(path_manager.complete("levels/test.pingus"), 
".pingus");
 }
 
 } // Editor namespace

Modified: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/file_dialog.cxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -37,19 +37,17 @@
        class FileDialogOkButton : public GUI::SurfaceButton
        {
        private:
-               PingusMenuManager* manager;
                FileDialog* file_dialog;
                std::string label;
                bool is_hidden;
 
        public:
-               FileDialogOkButton (PingusMenuManager* m, FileDialog *f, 
std::string l)
+               FileDialogOkButton (FileDialog *f, std::string l)
                        : GUI::SurfaceButton(CL_Display::get_width()/2 + 170,
                        CL_Display::get_height()/2 + 160,
                        ResDescriptor("core/menu/exit_button_normal"),
                        ResDescriptor("core/menu/exit_button_pressed"),
                        ResDescriptor("core/menu/exit_button_hover")),
-                       manager (m),
                        file_dialog(f),
                        label (l), 
                        is_hidden(true)
@@ -91,16 +89,16 @@
        class FileDialogCancelButton : public GUI::SurfaceButton
        {
        private:
-               PingusMenuManager* manager;
+               FileDialog* file_dialog;
 
        public:
-               FileDialogCancelButton (PingusMenuManager* m)
+               FileDialogCancelButton (FileDialog* f)
                        : GUI::SurfaceButton(CL_Display::get_width()/2 - 250,
                        CL_Display::get_height()/2 + 160,
                        ResDescriptor("core/menu/exit_button_normal"),
                        ResDescriptor("core/menu/exit_button_pressed"),
                        ResDescriptor("core/menu/exit_button_hover")),
-                       manager (m)
+                       file_dialog (f)
                {
                }
 
@@ -113,7 +111,7 @@
                void on_click()
                {
                        Sound::PingusSound::play_sound ("yipee");
-                       manager->pop_menu();
+                       file_dialog->cancel_pressed();
                }
 
                void on_pointer_enter()
@@ -218,18 +216,17 @@
        };
 
        FileDialog::FileDialog (FileDialogListener* listener_, 
-               PingusMenuManager* manager_, 
                const std::string filemask_, 
                const std::string searchpath_, 
                bool for_load)
-               : PingusSubMenu (manager_),
+               : PingusSubMenu (PingusMenuManager::instance()),
                                                                        
listener(listener_),
                   for_loading(for_load),
                   file_mask(filemask_),
                   current_path(searchpath_)
        {
                // Initialize the buttons
-               ok_button = new FileDialogOkButton(manager, this,
+               ok_button = new FileDialogOkButton(this,
                        for_loading ? _("Load") : _("Save"));
 
                up_button = new FileDialogScrollButton(this, DIR_UP, -150);
@@ -238,7 +235,7 @@
                gui_manager->add(ok_button, true);
                gui_manager->add(up_button, true);
                gui_manager->add(down_button, true);
-               gui_manager->add(new FileDialogCancelButton(manager), true);
+               gui_manager->add(new FileDialogCancelButton(this), true);
                gui_manager->add(new FileDialogParentFolderButton(this));       
        
 
                // FIXME: Ugly - hardcoded values for items in file dialog.  
Should be dynamic.
@@ -410,6 +407,12 @@
                }
        }
 
+       void
+       FileDialog::cancel_pressed()
+       {
+               listener->cancel();
+       }
+
 } // namespace Pingus
 
 /* EOF */

Modified: trunk/src/file_dialog.hxx
===================================================================
--- trunk/src/file_dialog.hxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/file_dialog.hxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -89,7 +89,6 @@
 
 public:
        FileDialog (FileDialogListener* listener_, 
-               PingusMenuManager *manager_,
                const std::string filemask_, 
                const std::string searchpath_,
                const bool for_load = true);
@@ -115,6 +114,9 @@
        /** The Ok button has been pressed - either Save or Load this file */
        void ok_pressed();
 
+       /** The Cancel button has been pressed - close the box */
+       void cancel_pressed();
+
        /** Need to scroll the list of files if possible */
        void scroll(int direction);
 

Modified: trunk/src/file_dialog_listener.hxx
===================================================================
--- trunk/src/file_dialog_listener.hxx  2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/file_dialog_listener.hxx  2005-12-28 17:53:40 UTC (rev 2566)
@@ -30,6 +30,7 @@
                virtual ~FileDialogListener() {}
                virtual void save(const std::string &file, const std::string 
&filemask) { }
                virtual void load(const std::string &file, const std::string 
&filemask) { }
+               virtual void cancel() { }
        };      // class FileDialogListener
 
 }      // namespace Pingus

Modified: trunk/src/pingus_menu.cxx
===================================================================
--- trunk/src/pingus_menu.cxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/pingus_menu.cxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -36,12 +36,14 @@
 #include "gui/gui_manager.hxx"
 #include "plf_res_mgr.hxx"
 #include "path_manager.hxx"
+#include "file_dialog.hxx"
 #include "editor/editor_screen.hxx"
 
 namespace Pingus {
 
 PingusMenu::PingusMenu (PingusMenuManager* m)
-  : PingusSubMenu (m)
+  : PingusSubMenu (m),
+         filedialog(0)
 {
   is_init = false;
     
@@ -119,15 +121,21 @@
 void
 PingusMenu::setup_contrib_menu()
 {
-       get_manager ()->show_file_dialog (".pingus", 
+       if (filedialog)
+               delete filedialog;
+       filedialog = new FileDialog(this, ".pingus", 
                path_manager.complete("levels/"), true);
+  manager->push_menu (filedialog);
 }
 
 void
 PingusMenu::setup_worldmap_menu()
 {
-       get_manager ()->show_file_dialog (".xml",
+       if (filedialog)
+               delete filedialog;
+       filedialog = new FileDialog(this, ".xml", 
                path_manager.complete("worldmaps/"), true);
+  manager->push_menu (filedialog);
 }
 
 void
@@ -150,6 +158,8 @@
        delete story_button;
        delete multiplayer_button;
        delete editor_button;
+       if (filedialog)
+               delete filedialog;
 }
 
 void
@@ -243,6 +253,11 @@
                do_start(file);
 }
                
+void
+PingusMenu::cancel()
+{
+       manager->pop_menu();
+}
 
 } // namespace Pingus
 

Modified: trunk/src/pingus_menu.hxx
===================================================================
--- trunk/src/pingus_menu.hxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/pingus_menu.hxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -22,6 +22,7 @@
 
 #include "fonts.hxx"
 #include "pingus_sub_menu.hxx"
+#include "file_dialog_listener.hxx"
 #include "layer_manager.hxx"
 
 class CL_Key;
@@ -31,6 +32,7 @@
 
 class SurfaceButton;
 class GameDelta;
+class FileDialog;
 
 namespace GUI {
 class GUIManager;
@@ -38,7 +40,7 @@
 
 class MenuButton;
 
-class PingusMenu : public PingusSubMenu
+class PingusMenu : public PingusSubMenu, public FileDialogListener
 {
 public:
   bool is_init;
@@ -56,6 +58,7 @@
   MenuButton* story_button;
   MenuButton* multiplayer_button;
        MenuButton* editor_button;
+       FileDialog* filedialog;
   
   void on_resize (int w, int h);
 
@@ -77,6 +80,9 @@
        /** Use this to load the level or worldmap */
        virtual void load(const std::string &file, const std::string &filemask);
 
+       /** Cancels the file dialog box */
+       virtual void cancel();
+
 public:
   PingusMenu (PingusMenuManager* m);
   ~PingusMenu();

Modified: trunk/src/pingus_menu_manager.cxx
===================================================================
--- trunk/src/pingus_menu_manager.cxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/pingus_menu_manager.cxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -30,8 +30,7 @@
 
 PingusMenuManager::PingusMenuManager ()
   : mainmenu (this),
-    exitmenu (this),
-               filedialog (0)
+    exitmenu (this)
 {
   background.add_layer (Resource::load_sprite("core/menu/layer1"),  0, 0, 12, 
0);
   background.add_layer (Resource::load_sprite("core/menu/layer2"),  0, 150, 
25, 0);
@@ -44,8 +43,6 @@
 
 PingusMenuManager::~PingusMenuManager ()
 {
-       if (filedialog)
-               delete filedialog;
 }
 
 bool
@@ -116,18 +113,6 @@
 }
 
 void
-PingusMenuManager::show_file_dialog (const std::string filemask, 
-                                                                               
                                                                 const 
std::string searchpath, bool for_load)
-{
-       // Initialize the dialog box either for loading or saving.
-       if (filedialog)
-               delete filedialog;
-       filedialog = new FileDialog(current_menu(), this, filemask, searchpath, 
for_load);
-       filedialog->preload();
-  push_menu (filedialog);
-}
-
-void
 PingusMenuManager::exit ()
 {
   //std::cout << "poping PingusMenuManager" << std::endl;

Modified: trunk/src/pingus_menu_manager.hxx
===================================================================
--- trunk/src/pingus_menu_manager.hxx   2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/pingus_menu_manager.hxx   2005-12-28 17:53:40 UTC (rev 2566)
@@ -49,7 +49,6 @@
   PingusMenu     mainmenu;
   LayerManager background;
   ExitMenu       exitmenu;
-       FileDialog* filedialog;
 
   virtual ~PingusMenuManager();
 
@@ -59,10 +58,6 @@
   /// Exit the menu manager (which means to exit the while() loop in display 
())
   void show_exit_menu ();
        
-       /** Show the file dialog menu.  True to load, false to save */
-       void show_file_dialog(const std::string filemask, 
-               const std::string searchpath, bool for_load = true);
-
   void exit ();
 
   PingusSubMenu * current_menu();

Modified: trunk/src/pingus_sub_menu.hxx
===================================================================
--- trunk/src/pingus_sub_menu.hxx       2005-12-27 21:58:03 UTC (rev 2565)
+++ trunk/src/pingus_sub_menu.hxx       2005-12-28 17:53:40 UTC (rev 2566)
@@ -21,7 +21,6 @@
 #define HEADER_PINGUS_PINGUS_SUB_MENU_HXX
 
 #include "gui/gui_screen.hxx"
-#include "file_dialog_listener.hxx"
 
 class CL_Key;
 class CL_InputDevice;
@@ -30,7 +29,7 @@
 
 class PingusMenuManager;
 
-class PingusSubMenu : public GUIScreen, public FileDialogListener
+class PingusSubMenu : public GUIScreen
 {
 protected:
   PingusMenuManager* manager;





reply via email to

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