pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2515 - in trunk: data/data data/images/core/menu src


From: jave27
Subject: [Pingus-CVS] r2515 - in trunk: data/data data/images/core/menu src
Date: Thu, 1 Dec 2005 15:46:56 +0100

Author: jave27
Date: 2005-12-01 15:46:11 +0100 (Thu, 01 Dec 2005)
New Revision: 2515

Added:
   trunk/data/images/core/menu/default_level.jpg
   trunk/data/images/core/menu/down_arrow.png
   trunk/data/images/core/menu/filedialog.png
   trunk/data/images/core/menu/folder.png
   trunk/data/images/core/menu/up_arrow.png
   trunk/src/file_dialog.cxx
   trunk/src/file_dialog.hxx
   trunk/src/file_dialog_item.cxx
   trunk/src/file_dialog_item.hxx
Modified:
   trunk/data/data/core.xml
   trunk/src/Makefile.am
   trunk/src/pingus_menu.cxx
   trunk/src/pingus_menu.hxx
   trunk/src/pingus_menu_manager.cxx
   trunk/src/pingus_menu_manager.hxx
Log:
Added a new File Dialog for selecting levels and folders.  Needs to be expanded 
to handle Worldmaps, and a few more features are needed.  But, it works for now.

Modified: trunk/data/data/core.xml
===================================================================
--- trunk/data/data/core.xml    2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/data/data/core.xml    2005-12-01 14:46:11 UTC (rev 2515)
@@ -1,4 +1,4 @@
-<resources>
+<resources>
   <section name="core">
     <section name="cursors">
       <sprite name="editor">
@@ -129,6 +129,21 @@
       </sprite>
     </section>
     <section name="menu">
+                 <sprite name="filedialog">
+                         <image file="../images/core/menu/filedialog.png" />
+                 </sprite>
+      <sprite name="folder">
+        <image file="../images/core/menu/folder.png" />
+      </sprite>
+      <sprite name="default_level">
+        <image file="../images/core/menu/default_level.jpg" />
+      </sprite>
+      <sprite name="up_arrow">
+        <image file="../images/core/menu/up_arrow.png" />
+      </sprite>
+      <sprite name="down_arrow">
+        <image file="../images/core/menu/down_arrow.png" />
+      </sprite>
       <sprite name="startscreenbg">
         <translation origin="center"/>
         <image file="../images/core/menu/startscreenbg.jpg"/>

Added: trunk/data/images/core/menu/default_level.jpg
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/core/menu/default_level.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/core/menu/down_arrow.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/core/menu/down_arrow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/core/menu/filedialog.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/core/menu/filedialog.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/core/menu/folder.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/core/menu/folder.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/data/images/core/menu/up_arrow.png
===================================================================
(Binary files differ)


Property changes on: trunk/data/images/core/menu/up_arrow.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am       2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/Makefile.am       2005-12-01 14:46:11 UTC (rev 2515)
@@ -126,6 +126,10 @@
 direction.hxx \
 exit_menu.cxx \
 exit_menu.hxx \
+file_dialog.cxx \
+file_dialog.hxx \
+file_dialog_item.cxx \
+file_dialog_item.hxx \
 file_reader_impl.hxx \
 file_reader.hxx \
 file_reader.cxx \

Added: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx   2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/file_dialog.cxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -0,0 +1,339 @@
+//  $Id: file_dialog.cxx,v 1.00 2005/11/18 00:30:04 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//
+//  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 distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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.
+
+#include <ClanLib/Display/display.h>
+#include <ClanLib/Core/IOData/directory_scanner.h>
+#include "gettext.h"
+#include "pingus_menu_manager.hxx"
+#include "resource.hxx"
+#include "gui/surface_button.hxx"
+#include "gui/gui_manager.hxx"
+#include "sound/sound.hxx"
+#include "file_dialog.hxx"
+#include "file_dialog_item.hxx"
+
+namespace Pingus {
+
+       const int DIR_UP = 0;
+       const int DIR_DOWN = 1;
+
+       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)
+                       : 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),
+                       label (l), 
+                       file_dialog(f),
+                       is_hidden(true)
+               {
+               }
+
+               void draw (DrawingContext& gc) {
+                       if (!is_hidden)
+                       {
+                               SurfaceButton::draw(gc);
+                               gc.print_right(Fonts::chalk_large, 
(float)CL_Display::get_width()/2 + 200,
+                                       (float)CL_Display::get_height()/2 + 
160, label);
+                       }
+               }
+
+               void on_click()
+               {
+                       if (!is_hidden)
+                       {
+                               Sound::PingusSound::play_sound ("yipee");
+                               file_dialog->ok_pressed();
+                       }
+               }
+
+               void on_pointer_enter()
+               {
+                       if (!is_hidden)
+                       {
+                               SurfaceButton::on_pointer_enter();
+                               Sound::PingusSound::play_sound ("tick");
+                       }
+               }
+
+               void hide() { is_hidden = true; }
+               void show() { is_hidden = false; }
+
+       };
+
+       class FileDialogCancelButton : public GUI::SurfaceButton
+       {
+       private:
+               PingusMenuManager* manager;
+
+       public:
+               FileDialogCancelButton (PingusMenuManager* m)
+                       : 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)
+               {
+               }
+
+               void draw (DrawingContext& gc) {
+                       SurfaceButton::draw(gc);
+                       gc.print_right(Fonts::chalk_large, 
(float)CL_Display::get_width()/2 - 200,
+                               (float)CL_Display::get_height()/2 + 160, 
_("Cancel"));
+               }
+
+               void on_click()
+               {
+                       Sound::PingusSound::play_sound ("yipee");
+                       manager->pop_menu();
+               }
+
+               void on_pointer_enter()
+               {
+                       SurfaceButton::on_pointer_enter();
+                       Sound::PingusSound::play_sound ("tick");
+               }
+       };
+
+       class FileDialogScrollButton : public GUI::Component
+       {
+       private:
+               /** FileDialog box to this which button is assigned */
+               FileDialog* file_dialog;
+
+               /** Where the image is located */
+               Vector pos;
+
+               /** Image used for the scroll button */
+               CL_Sprite sprite;
+
+               /** 0 for Up, 1 for Down */
+               int direction;
+
+       public:
+               FileDialogScrollButton (FileDialog* f, int d, int height_offset)
+                       : pos(Vector((float)CL_Display::get_width()/2 + 210,
+                       (float)CL_Display::get_height()/2 + height_offset)),
+                       file_dialog(f),
+                       direction(d)
+               {
+                       std::string str_direction = d==0 ? "up" : "down";
+                       sprite = Resource::load_sprite("core/menu/" + 
str_direction + "_arrow");
+               }
+
+               void draw (DrawingContext& gc) {
+                       //FIXME: Should also draw a hover box around it when 
the mouse is over it.
+                       gc.draw(sprite, pos);
+               }
+               
+               void on_primary_button_click(int x, int y)
+               {
+                       file_dialog->scroll(direction);
+               }
+
+               bool is_at(int x, int y)
+               {
+                       return (x > (int)pos.x && x < (int)pos.x + 
sprite.get_width()
+                               && y > (int)pos.y && y < (int)pos.y + 
sprite.get_height());
+               }
+       };
+
+       FileDialog::FileDialog (PingusMenuManager* manager_, const std::string 
filemask_, 
+               const std::string searchpath_, bool for_load)
+               : PingusSubMenu (manager_),
+               file_mask(filemask_),
+               current_path(searchpath_),
+               for_loading(for_load)
+       {
+               // Initialize the buttons
+               ok_button = new FileDialogOkButton(manager, this,
+                       for_loading ? _("Load") : _("Save"));
+
+               gui_manager->add(ok_button, true);
+               gui_manager->add(new FileDialogCancelButton(manager), true);
+               gui_manager->add(new FileDialogScrollButton(this, DIR_DOWN, 
100), true);
+               gui_manager->add(new FileDialogScrollButton(this, DIR_UP, 
-150), true);
+               
+               // FIXME: Add a button to go to the parent folder
+
+
+               // FIXME: Ugly - hardcoded values for items in file dialog.  
Should be dynamic.
+               // Create 8 FileDialogItems and add them to the gui_manager.
+               float center_x = (float)CL_Display::get_width()/2;
+               float center_y = (float)CL_Display::get_height()/2;
+
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 280, center_y - 140)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 280, center_y - 70)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 280, center_y + 10)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 280, center_y + 80)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 10, center_y - 140)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 10, center_y - 70)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 10, center_y + 10)));
+               file_dialog_items.push_back(new FileDialogItem(this, 
+                       Vector(center_x - 10, center_y + 80)));
+
+               for (std::vector<FileDialogItem*>::const_iterator i = 
file_dialog_items.begin();
+                       i != file_dialog_items.end(); i++)
+                       gui_manager->add((GUI::Component*)(*i));
+
+               refresh();
+       }
+
+       FileDialog::~FileDialog ()
+       {
+       }
+
+       bool
+               FileDialog::draw (DrawingContext& gc)
+       {
+               gc.draw(sprite, Vector(gc.get_width ()/2 - sprite.get_width 
()/2,
+                       gc.get_height ()/2 - sprite.get_height ()/2));
+               gc.draw_rect(gc.get_width() / 2 - 285, gc.get_height() / 2 - 
160,
+                       gc.get_width() / 2 + 285, gc.get_height() / 2 + 160, 
CL_Color::black);
+               gc.print_center(Fonts::chalk_large, gc.get_width()/2, 
gc.get_height()/2 - 220, 
+                       current_file);
+
+               PingusSubMenu::draw(gc);
+               return true;
+       }
+
+       void
+               FileDialog::preload ()
+       {
+               sprite = Resource::load_sprite("core/menu/filedialog");
+       }
+
+       void
+               FileDialog::refresh ()
+       {
+               // Clear the current list of files
+               file_list.clear();
+               current_offset=0;
+
+               // Get the list of files and folders in the current folder
+               CL_DirectoryScanner scanner;
+               scanner.scan(current_path, "*");
+               while (scanner.next())
+               {
+                       if (scanner.get_name() != "." && scanner.get_name() != 
".." 
+                               && scanner.get_name() != ".svn" && 
scanner.is_directory())
+                               file_list[scanner.get_name()] = true;
+               }
+
+               scanner.scan(current_path, "*" + file_mask);
+               while (scanner.next())
+                       file_list[scanner.get_name()] = false;
+
+               // FIXME: Should sort the file_list here
+
+               current_offset = 0;
+               offset_changed();
+       }
+
+       // Whenever the list of showing files has changed.
+       void
+       FileDialog::offset_changed()
+       {
+               std::map<std::string, bool>::const_iterator it = 
file_list.begin();
+               
+               //FIXME: Is there a better way to do this?  It just looks ugly.
+               for (unsigned j = 0; j < current_offset && it != 
file_list.end(); j++)
+                       it++;
+
+               for (std::vector<FileDialogItem*>::const_iterator i = 
file_dialog_items.begin();
+                       i != file_dialog_items.end(); i++)
+               {
+                        if (it != file_list.end())
+                        {
+                                (*i)->set_file(it->first, it->second);
+                                it++;
+                        }
+                        else
+                                (*i)->hide();
+               }
+       }
+
+       // Scroll the list up or down.
+       void
+       FileDialog::scroll(int direction)
+       {
+               if (direction == DIR_UP)
+               {
+                       if (current_offset != 0)
+                               current_offset -= 
(unsigned)file_dialog_items.size();
+               }
+               else
+               {
+                       if (current_offset + (unsigned)file_dialog_items.size() 
< (unsigned)file_list.size())
+                               current_offset += 
(unsigned)file_dialog_items.size();
+               }
+               offset_changed();
+       }
+
+       // Set the file and show or hide the OK button.
+       void
+       FileDialog::set_selected_file(std::string f)
+       { 
+        current_file = f; 
+        if (current_file != "")
+                ok_button->show();
+        else
+                ok_button->hide();
+       }
+
+       void
+       FileDialog::ok_pressed()
+       {
+               // If it's a directory, change to it.
+               if (file_list[current_file] == true)
+               {
+                       current_path += current_file + "/";
+                       refresh();
+                       ok_button->hide();
+               }
+               else
+               {
+                       // FIXME: Temporary since we only use this dialog on 
the main menu.
+                       if (for_loading)
+                               manager->mainmenu.do_contrib(current_path + 
current_file);
+                       manager->pop_menu();
+               }
+       }
+
+} // namespace Pingus
+
+/* EOF */

Added: trunk/src/file_dialog.hxx
===================================================================
--- trunk/src/file_dialog.hxx   2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/file_dialog.hxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -0,0 +1,104 @@
+//  $Id: file_dialog.hxx,v 1.0 2005/11/18 00:30:04 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//
+//  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 distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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.
+
+#ifndef HEADER_PINGUS_FILE_DIALOG_HXX
+#define HEADER_PINGUS_FILE_DIALOG_HXX
+
+#include <ClanLib/Display/sprite.h>
+#include <vector>
+#include <map>
+#include <string>
+#include "pingus_sub_menu.hxx"
+
+namespace Pingus {
+
+       class Vector;
+       class FileDialogItem;
+       class FileDialogOkButton;
+       class PingusMenuManager;
+
+class FileDialog : public PingusSubMenu
+{
+private:
+  CL_Sprite sprite;
+
+       /** The OK button - need to be able to hide and show it */
+       FileDialogOkButton* ok_button;
+
+       /** Should this dialog box be used for loading?  True for load, false 
for saving */
+       bool for_loading;
+
+       /** Mask for which files to display (*.pingus, *.xml, etc.) */
+       std::string file_mask;
+
+       /** Current path that is being displayed */
+       std::string current_path;
+
+       /** Current file that is selected */
+       std::string current_file;
+
+       /** Offset in the file_list that is the index of the first file/folder 
shown */
+       unsigned current_offset;
+
+       /** List of directories & files in the current folder */
+       std::map<std::string, bool> file_list;
+
+       /** List of files in the directory */
+       std::vector<FileDialogItem*> file_dialog_items;
+
+       /** Scroll the displayed file list */
+       void offset_changed();
+
+public:
+       FileDialog (PingusMenuManager* manager, const std::string filemask_, 
+               const std::string searchpath_, const bool for_load = true);
+  ~FileDialog ();
+
+  bool draw (DrawingContext& gc);
+
+       void preload();
+
+       /** Refresh the file list */
+       void refresh();
+
+       /** Return the current path in the dialog */
+       std::string get_path() const { return current_path; }
+
+       /** Return the file mask */
+       std::string get_file_mask() const { return file_mask; }
+
+       /** Sets the currently selected file name */
+       void set_selected_file(std::string f);
+
+       /** The Ok button has been pressed - either Save or Load this file */
+       void ok_pressed();
+
+       /** Need to scroll the list of files if possible */
+       void scroll(int direction);
+
+private:
+  FileDialog (const FileDialog&);
+  FileDialog& operator= (const FileDialog&);
+};
+
+} // namespace Pingus
+
+#endif
+
+/* EOF */

Added: trunk/src/file_dialog_item.cxx
===================================================================
--- trunk/src/file_dialog_item.cxx      2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/file_dialog_item.cxx      2005-12-01 14:46:11 UTC (rev 2515)
@@ -0,0 +1,106 @@
+//  $Id: file_dialog.hxx,v 1.0 2005/11/28 00:30:04 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//
+//  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 distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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.
+
+#include <Clanlib/Display/sprite.h>
+#include <ClanLib/Core/IOData/directory_scanner.h>
+#include "file_dialog_item.hxx"
+#include "file_dialog.hxx"
+#include "vector.hxx"
+#include "fonts.hxx"
+#include "resource.hxx"
+
+namespace Pingus {
+
+
+       // Only Constructor
+       FileDialogItem::FileDialogItem(FileDialog* f, Vector p) 
+               : file_dialog(f), mouse_over(false), is_hidden(true),
+                       pos(p), 
sprite(Resource::load_sprite("core/misc/404sprite"))
+       {
+       }
+
+       /** Set the current file assigned to this button */
+       void 
+       FileDialogItem::set_file(const std::string f, bool is_dir) 
+       { 
+               file_item = f;
+               is_directory = is_dir;
+               is_hidden = false;
+               // Load sprite based on file  (folder icon, level screenshot, 
or generic)
+               if (is_directory)
+                       sprite = Resource::load_sprite("core/menu/folder");
+               else
+                       sprite = 
Resource::load_sprite("core/menu/default_level");
+       }
+
+       bool 
+       FileDialogItem::is_at(int x, int y)
+       {
+               if (is_hidden)
+                       return false;
+               return (x > pos.x && x < pos.x + sprite.get_width()
+                       && y > pos.y && y < pos.y + sprite.get_height());
+       }
+
+       void 
+       FileDialogItem::draw (DrawingContext& gc)
+       {
+               if (!is_hidden)
+               {
+                       // Draw thumbnail
+                       gc.draw(sprite, pos);
+
+                       // Draw title
+                       gc.print_left(Fonts::pingus_small, pos.x + 
(float)sprite.get_width(), 
+                               pos.y, get_filename());
+
+                       // FIXME: If mouse over, draw a quick info box about 
the level
+                       if (mouse_over)
+                       {
+                       }
+               }
+       }
+
+       void
+       FileDialogItem::on_primary_button_click (int x, int y)
+       {
+               file_dialog->set_selected_file(file_item);
+               // Change immediately to the folder if clicked on one
+               if (is_directory)
+                       file_dialog->ok_pressed();
+       }
+
+       void
+       FileDialogItem::hide()
+       {
+               file_item = "";
+               is_hidden = true;
+       }
+
+       std::string 
+       FileDialogItem::get_filename() const 
+       {
+               if (is_directory)
+                       return file_item;
+               else
+                       return file_item.substr(0, file_item.size() - 
file_dialog->get_file_mask().size());
+       }
+}
+
+/* EOF */
\ No newline at end of file

Added: trunk/src/file_dialog_item.hxx
===================================================================
--- trunk/src/file_dialog_item.hxx      2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/file_dialog_item.hxx      2005-12-01 14:46:11 UTC (rev 2515)
@@ -0,0 +1,83 @@
+//  $Id: file_dialog.hxx,v 1.0 2005/11/28 00:30:04 Jave27 Exp $
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+//
+//  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 distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  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.
+
+#ifndef HEADER_PINGUS_FILE_DIALOG_ITEM_HXX
+#define HEADER_PINGUS_FILE_DIALOG_ITEM_HXX
+
+#include <Clanlib/Display/sprite.h>
+#include "gui/component.hxx"
+#include "vector.hxx"
+
+namespace Pingus {
+
+       class FileDialog;
+
+/** Class representing a clickable object in a File Dialog (a Directory, Level,
+       or Worldmap */
+class FileDialogItem : GUI::Component
+{
+private:
+       bool mouse_over;
+       bool is_directory;
+       bool is_hidden;
+
+       FileDialog* file_dialog;
+       Vector pos;
+
+       /** This file_item name will change based on the current file list */
+       std::string file_item;
+       
+       /** This sprite will change based on the currently displayed file */
+       CL_Sprite sprite;
+
+public:
+       // Only Constructor
+       FileDialogItem(FileDialog* f, Vector p) ;
+
+       /** Set the current file assigned to this button */
+       void set_file(const std::string f, bool is_dir);
+
+       /** Get the cleaned up file name (no extension) */
+       std::string get_filename() const;
+
+       bool is_at(int x, int y);
+
+       void draw (DrawingContext& gc);
+
+       void hide ();
+
+       void on_primary_button_click (int x, int y);
+
+       /** Emmitted when pointer enters the region of the component */
+       void on_pointer_enter () { mouse_over = true; }
+
+       /** Emmitted when pointer leaves the region of the component */
+       void on_pointer_leave () { mouse_over = false; }
+
+private:
+       FileDialogItem();
+  FileDialogItem (const FileDialogItem&);
+  FileDialogItem& operator= (const FileDialogItem&);
+};     // FileDialogItem class
+
+}              // Pingus namespace
+
+#endif
+
+/* EOF */
\ No newline at end of file

Modified: trunk/src/pingus_menu.cxx
===================================================================
--- trunk/src/pingus_menu.cxx   2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/pingus_menu.cxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -120,7 +120,11 @@
 
 void
 PingusMenu::setup_contrib_menu()
-{  
+{
+       get_manager ()->show_file_dialog (".pingus", 
+               path_manager.complete("levels/"), true);
+
+       /*
        // Create a Clanlib File Dialog using the silver style
   CL_ResourceManager *resources = new 
       CL_ResourceManager(path_manager.complete("GUIStyleSilver/gui.xml"));
@@ -142,6 +146,7 @@
   // Launch level
   if (filename != "")
      do_contrib(filename);
+ */
 }
 
 void

Modified: trunk/src/pingus_menu.hxx
===================================================================
--- trunk/src/pingus_menu.hxx   2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/pingus_menu.hxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -66,7 +66,6 @@
   
   void do_quit();
   void do_start();
-  void do_contrib(const std::string&);
        void do_edit();
 
 public:
@@ -75,6 +74,7 @@
 
   /// Load all images and other stuff for the menu
   void preload ();
+  void do_contrib(const std::string&);
 
   void on_escape_press ();
   void draw_foreground(DrawingContext& gc);

Modified: trunk/src/pingus_menu_manager.cxx
===================================================================
--- trunk/src/pingus_menu_manager.cxx   2005-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/pingus_menu_manager.cxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -29,13 +29,16 @@
 
 PingusMenuManager::PingusMenuManager ()
   : mainmenu (this),
-    exitmenu (this)
+    exitmenu (this),
+               filedialog (0)
 {
   push_menu (&mainmenu);
 }
 
 PingusMenuManager::~PingusMenuManager ()
 {
+       if (filedialog)
+               delete filedialog;
 }
 
 bool
@@ -106,6 +109,18 @@
 }
 
 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(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-11-21 19:53:35 UTC (rev 2514)
+++ trunk/src/pingus_menu_manager.hxx   2005-12-01 14:46:11 UTC (rev 2515)
@@ -23,6 +23,7 @@
 #include "menu_background.hxx"
 #include "exit_menu.hxx"
 #include "pingus_menu.hxx"
+#include "file_dialog.hxx"
 
 namespace Pingus {
 
@@ -48,6 +49,7 @@
   PingusMenu mainmenu;
   MenuBackground background;
   ExitMenu exitmenu;
+       FileDialog* filedialog;
 
   virtual ~PingusMenuManager();
 
@@ -56,6 +58,10 @@
 
   /// 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 ();
 





reply via email to

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