[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2531 - trunk/src
From: |
jave27 |
Subject: |
[Pingus-CVS] r2531 - trunk/src |
Date: |
Fri, 2 Dec 2005 15:35:50 +0100 |
Author: jave27
Date: 2005-12-02 15:35:35 +0100 (Fri, 02 Dec 2005)
New Revision: 2531
Modified:
trunk/src/file_dialog.cxx
trunk/src/file_dialog.hxx
trunk/src/file_dialog_item.cxx
trunk/src/file_dialog_item.hxx
Log:
Sorted the file dialog box correctly.
Modified: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx 2005-12-02 03:24:09 UTC (rev 2530)
+++ trunk/src/file_dialog.cxx 2005-12-02 14:35:35 UTC (rev 2531)
@@ -193,8 +193,10 @@
void on_primary_button_click(int x, int y)
{
- file_dialog->set_selected_file("..");
- file_dialog->ok_pressed();
+ FileItem f;
+ f.name = "..";
+ f.is_directory = true;
+ file_dialog->set_selected_file(f);
}
bool is_at(int x, int y)
@@ -209,8 +211,7 @@
: PingusSubMenu (manager_),
for_loading(for_load),
file_mask(filemask_),
- current_path(searchpath_),
-
current_file("Pingus")
+ current_path(searchpath_)
{
// Initialize the buttons
ok_button = new FileDialogOkButton(manager, this,
@@ -263,7 +264,7 @@
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);
+ current_file.name);
PingusSubMenu::draw(gc);
return true;
@@ -282,6 +283,8 @@
file_list.clear();
current_offset=0;
+ FileItem f;
+
// Get the list of files and folders in the current folder
CL_DirectoryScanner scanner;
scanner.scan(current_path, "*");
@@ -289,14 +292,23 @@
{
if (scanner.get_name() != "." && scanner.get_name() !=
".."
&& scanner.get_name() != ".svn" &&
scanner.is_directory())
- file_list[scanner.get_name()] = true;
+ {
+ f.name = scanner.get_name();
+ f.is_directory = true;
+ file_list.push_back(f);
+ }
}
scanner.scan(current_path, "*" + file_mask);
while (scanner.next())
- file_list[scanner.get_name()] = false;
+ {
+ f.name = scanner.get_name();
+ f.is_directory = false;
+ file_list.push_back(f);
+ }
// FIXME: Should sort the file_list here
+ std::sort(file_list.begin(), file_list.end(), &FileItemCompare);
current_offset = 0;
offset_changed();
@@ -306,20 +318,13 @@
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++;
+ unsigned j = current_offset;
for (std::vector<FileDialogItem*>::const_iterator i =
file_dialog_items.begin();
- i != file_dialog_items.end(); i++)
+ i != file_dialog_items.end(); i++, j++)
{
- if (it != file_list.end())
- {
- (*i)->set_file(it->first, it->second);
- it++;
- }
+ if (j < (unsigned)file_list.size())
+ (*i)->set_file(file_list[j]);
else
(*i)->hide();
}
@@ -344,22 +349,25 @@
// Set the file and show or hide the OK button.
void
- FileDialog::set_selected_file(std::string f)
+ FileDialog::set_selected_file(FileItem f)
{
- current_file = f;
- if (current_file != "")
+ current_file = f;
+ if (current_file.name != "")
ok_button->show();
else
ok_button->hide();
+
+ if (current_file.is_directory)
+ ok_pressed();
}
void
FileDialog::ok_pressed()
{
// If it's a directory, change to it.
- if (current_file == ".." || file_list[current_file] == true)
+ if (current_file.is_directory)
{
- current_path += current_file + "/";
+ current_path += current_file.name + "/";
refresh();
ok_button->hide();
}
@@ -367,7 +375,7 @@
{
// FIXME: Temporary since we only use this dialog on
the main menu.
if (for_loading)
- manager->mainmenu.do_contrib(current_path +
current_file);
+ manager->mainmenu.do_contrib(current_path +
current_file.name);
manager->pop_menu();
}
}
Modified: trunk/src/file_dialog.hxx
===================================================================
--- trunk/src/file_dialog.hxx 2005-12-02 03:24:09 UTC (rev 2530)
+++ trunk/src/file_dialog.hxx 2005-12-02 14:35:35 UTC (rev 2531)
@@ -22,7 +22,6 @@
#include <ClanLib/Display/sprite.h>
#include <vector>
-#include <map>
#include <string>
#include "pingus_sub_menu.hxx"
@@ -33,6 +32,20 @@
class FileDialogOkButton;
class PingusMenuManager;
+ struct FileItem {
+ std::string name;
+ bool is_directory;
+ };
+
+ /** Sorting function for FileItem's */
+ inline bool FileItemCompare (const FileItem& a, const FileItem& b)
+ {
+ if (a.is_directory == b.is_directory)
+ return (a.name < b.name);
+ else
+ return (a.is_directory);
+ }
+
class FileDialog : public PingusSubMenu
{
private:
@@ -50,14 +63,14 @@
/** 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;
+ /** Current file that is selected */
+ FileItem current_file;
+
/** List of directories & files in the current folder */
- std::map<std::string, bool> file_list;
+ std::vector<FileItem> file_list;
/** List of files in the directory */
std::vector<FileDialogItem*> file_dialog_items;
@@ -84,7 +97,7 @@
std::string get_file_mask() const { return file_mask; }
/** Sets the currently selected file name */
- void set_selected_file(std::string f);
+ void set_selected_file(FileItem f);
/** The Ok button has been pressed - either Save or Load this file */
void ok_pressed();
Modified: trunk/src/file_dialog_item.cxx
===================================================================
--- trunk/src/file_dialog_item.cxx 2005-12-02 03:24:09 UTC (rev 2530)
+++ trunk/src/file_dialog_item.cxx 2005-12-02 14:35:35 UTC (rev 2531)
@@ -37,13 +37,12 @@
/** Set the current file assigned to this button */
void
- FileDialogItem::set_file(const std::string f, bool is_dir)
+ FileDialogItem::set_file(FileItem f)
{
file_item = f;
- is_directory = is_dir;
is_hidden = false;
// Load sprite based on file (folder icon, level screenshot,
or generic)
- if (is_directory)
+ if (file_item.is_directory)
sprite = Resource::load_sprite("core/menu/folder");
else
sprite =
Resource::load_sprite("core/menu/default_level");
@@ -81,25 +80,22 @@
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 = "";
+ file_item.name = "";
is_hidden = true;
}
std::string
FileDialogItem::get_filename() const
{
- if (is_directory)
- return file_item;
+ if (file_item.is_directory)
+ return file_item.name;
else
- return file_item.substr(0, file_item.size() -
file_dialog->get_file_mask().size());
+ return file_item.name.substr(0, file_item.name.size() -
file_dialog->get_file_mask().size());
}
}
Modified: trunk/src/file_dialog_item.hxx
===================================================================
--- trunk/src/file_dialog_item.hxx 2005-12-02 03:24:09 UTC (rev 2530)
+++ trunk/src/file_dialog_item.hxx 2005-12-02 14:35:35 UTC (rev 2531)
@@ -23,25 +23,23 @@
#include <ClanLib/Display/sprite.h>
#include "gui/component.hxx"
#include "vector.hxx"
+#include "file_dialog.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;
+ FileItem file_item;
/** This sprite will change based on the currently displayed file */
CL_Sprite sprite;
@@ -51,7 +49,7 @@
FileDialogItem(FileDialog* f, Vector p) ;
/** Set the current file assigned to this button */
- void set_file(const std::string f, bool is_dir);
+ void set_file(FileItem f);
/** Get the cleaned up file name (no extension) */
std::string get_filename() const;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2531 - trunk/src,
jave27 <=