pingus-devel
[Top][All Lists]
Advanced

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

Patch for pingus_menu - Contrib Levels file dialog


From: Jason Green
Subject: Patch for pingus_menu - Contrib Levels file dialog
Date: Wed, 05 Oct 2005 16:43:27 -0400
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

I'll leave this one up to your discretion if it should be applied or not... This patch adds a file dialog box when you click on "Contrib Levels" that let you load up any level you'd like off of the hard drive. However, I can't figure out why, but if you hit Cancel, the box doesn't always go away. You have to hit it a few times. Based on some minor debugging, it looks like setup_contrib_click() is getting called multiple times, but I haven't been able to get rid of it, and it doesn't seem to happen all of the time.

Regardless of the little bug, I still think it's a nice feature to have.
Index: pingus_menu.cxx
===================================================================
--- pingus_menu.cxx     (revision 2454)
+++ pingus_menu.cxx     (working copy)
@@ -18,19 +18,26 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <ClanLib/Display/display.h>
+#include <ClanLib/core.h>
+#include <ClanLib/gui.h>
+#include <ClanLib/guistylesilver.h>
 #include <config.h>
 #include "gettext.h"
 #include "menu_button.hxx"
 #include "resource.hxx"
 #include "debug.hxx"
+#include "globals.hxx"
 #include "sound/sound.hxx"
 #include "stat_manager.hxx"
+#include "start_screen.hxx"
 #include "story_screen.hxx"
 #include "story.hxx"
 #include "worldmap/manager.hxx"
 #include "gui/screen_manager.hxx"
 #include "pingus_menu_manager.hxx"
 #include "gui/gui_manager.hxx"
+#include "plf_res_mgr.hxx"
+#include "path_manager.hxx"
 
 namespace Pingus {
 
@@ -74,6 +81,8 @@
 
   slots.push_back(story_button->sig_click().connect(this, 
&PingusMenu::do_start));
   slots.push_back(multiplayer_button->sig_click().connect(this, 
&PingusMenu::setup_main_menu));
+  
+  slots.push_back(contrib_button->sig_click().connect(this, 
&PingusMenu::setup_contrib_menu));
 }
 
 void
@@ -99,6 +108,45 @@
 }
 
 void
+PingusMenu::setup_contrib_menu()
+{ // Remove buttons and select a level to play
+  gui_manager->remove(contrib_button);
+  gui_manager->remove(story_button);
+  gui_manager->remove(multiplayer_button);
+  
+       // Create a Clanlib GUIManager using the silver style
+  CL_ResourceManager *resources = new 
+      CL_ResourceManager(path_manager.complete("GUIStyleSilver/gui.xml"));
+       CL_StyleManager_Silver *style = new CL_StyleManager_Silver(resources);
+       CL_GUIManager *gui = new CL_GUIManager(style);
+       CL_FileDialog *filedialog = new CL_FileDialog("Levels", "", "*.pingus", 
gui, style);
+
+       // This next line is a workaround until ClanLib applies my patch to 
their SVN
+       // set_dir should do this automatically.
+  CL_Directory::change_to(path_manager.complete("levels"));
+
+       filedialog->set_dir(path_manager.complete("levels"));
+  filedialog->run();
+       const std::string filename = filedialog->get_file();
+  pout(PINGUS_DEBUG_LOADING) << "PingusMenu: Chose filename: " << filename << 
std::endl;
+    
+  // Clean up ClanLib stuff
+  delete filedialog;
+  delete gui;
+  delete style;
+  delete resources;
+  
+  // Launch level
+  if (filename != "")
+     do_contrib(filename);
+
+  // Reset menu
+  gui_manager->add(contrib_button);
+  gui_manager->add(story_button);
+  gui_manager->add(multiplayer_button);
+}
+
+void
 PingusMenu::preload ()
 {
   if (!is_init)
@@ -138,6 +186,14 @@
     }
 }
 
+void PingusMenu::do_contrib(const std::string &levelfile)
+{ // Launch the specified level - don't bother checking for it, it has to exist
+  Sound::PingusSound::play_sound ("letsgo");
+  ScreenManager::instance()->push_screen
+     (new StartScreen(PLFResMgr::load_plf_from_filename(levelfile)),
+      true);
+}
+
 void
 PingusMenu::on_resize(int w, int h)
 {
Index: pingus_menu.hxx
===================================================================
--- pingus_menu.hxx     (revision 2454)
+++ pingus_menu.hxx     (working copy)
@@ -58,11 +58,14 @@
   
   void on_resize (int w, int h);
 
+  // These functions setup the different menus
   void setup_main_menu();
   void setup_game_menu();
-
+  void setup_contrib_menu();
+  
   void do_quit();
   void do_start();
+  void do_contrib(const std::string&);
 
 public:
   PingusMenu (PingusMenuManager* m);

reply via email to

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