[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2624 - in trunk/src: . editor gui
From: |
jave27 |
Subject: |
[Pingus-CVS] r2624 - in trunk/src: . editor gui |
Date: |
Tue, 24 Jan 2006 02:45:08 +0100 |
Author: jave27
Date: 2006-01-24 02:44:58 +0100 (Tue, 24 Jan 2006)
New Revision: 2624
Modified:
trunk/src/editor/panel_buttons.cxx
trunk/src/file_dialog.cxx
trunk/src/file_dialog.hxx
trunk/src/gui/input_box.cxx
trunk/src/gui/input_box.hxx
Log:
Locked file dialog inputbox during loading to prevent users from
accessing unopened levels/worlds.
Enabled the file dialog box for the editor so you can pick the name of
the saved level.
Modified: trunk/src/editor/panel_buttons.cxx
===================================================================
--- trunk/src/editor/panel_buttons.cxx 2006-01-23 23:55:24 UTC (rev 2623)
+++ trunk/src/editor/panel_buttons.cxx 2006-01-24 01:44:58 UTC (rev 2624)
@@ -132,9 +132,8 @@
void
PanelButtonSave::on_primary_button_click(int x, int y)
{
- // TODO: Open a file dialog box to save the level.
PanelButton::on_primary_button_click(x, y);
- panel->get_screen()->save(path_manager.complete("levels/test.pingus"),
".pingus");
+ panel->get_screen()->show_file_dialog(false);
}
Modified: trunk/src/file_dialog.cxx
===================================================================
--- trunk/src/file_dialog.cxx 2006-01-23 23:55:24 UTC (rev 2623)
+++ trunk/src/file_dialog.cxx 2006-01-24 01:44:58 UTC (rev 2624)
@@ -20,6 +20,7 @@
#include <ClanLib/Display/display.h>
#include <ClanLib/Core/IOData/directory_scanner.h>
#include "gettext.h"
+#include "system.hxx"
#include "pingus_menu_manager.hxx"
#include "resource.hxx"
#include "gui/surface_button.hxx"
@@ -262,7 +263,8 @@
float center_x = (float)CL_Display::get_width()/2;
float center_y = (float)CL_Display::get_height()/2;
- inputbox = new GUI::InputBox(450, Vector(center_x - 225,
center_y - 170));
+ inputbox = new GUI::InputBox(450, Vector(center_x - 225,
+ center_y - 170), "", for_loading);
gui_manager->add((GUI::Component*)inputbox);
file_dialog_items.push_back(new FileDialogItem(this,
@@ -398,20 +400,17 @@
void
FileDialog::set_selected_file(FileItem f)
{
- current_file = f;
- if (current_file.name != "")
- {
+ current_file = f;
+ if (current_file.name != "")
ok_button->show();
- if (!current_file.is_directory)
- inputbox->set_string(current_file.name);
- else
- inputbox->set_string("");
- }
- else
- ok_button->hide();
-
- if (current_file.is_directory)
- ok_pressed();
+ else
+ ok_button->hide();
+
+ inputbox->set_string(current_file.name.substr(0,
+ current_file.name.length()-file_mask.length()));
+
+ if (current_file.is_directory)
+ ok_pressed();
}
void
@@ -426,7 +425,6 @@
}
else
{
- // Load or save the selected file
if (for_loading)
listener->load(current_path +
current_file.name, file_mask);
else
@@ -439,6 +437,23 @@
{
listener->cancel();
}
+
+ void
+ FileDialog::update(const GameDelta &delta)
+ {
+ PingusSubMenu::update(delta);
+
+ // FIXME: Ugly busy polling
+ if (!for_loading)
+ if (inputbox->get_string() != current_file.name)
+ {
+ FileItem f;
+ f.friendly_name = inputbox->get_string();
+ f.name = f.friendly_name + file_mask;
+ f.is_directory = false;
+ set_selected_file(f);
+ }
+ }
} // namespace Pingus
Modified: trunk/src/file_dialog.hxx
===================================================================
--- trunk/src/file_dialog.hxx 2006-01-23 23:55:24 UTC (rev 2623)
+++ trunk/src/file_dialog.hxx 2006-01-24 01:44:58 UTC (rev 2624)
@@ -96,7 +96,7 @@
/** Scroll the displayed file list */
void offset_changed();
-
+
public:
FileDialog (FileDialogListener* listener_,
const std::string filemask_,
@@ -106,6 +106,7 @@
~FileDialog ();
bool draw (DrawingContext& gc);
+ void update(const GameDelta &delta);
void preload();
Modified: trunk/src/gui/input_box.cxx
===================================================================
--- trunk/src/gui/input_box.cxx 2006-01-23 23:55:24 UTC (rev 2623)
+++ trunk/src/gui/input_box.cxx 2006-01-24 01:44:58 UTC (rev 2624)
@@ -26,11 +26,13 @@
namespace Pingus {
namespace GUI {
-InputBox::InputBox(float width_, Vector p, const std::string& default_value)
+InputBox::InputBox(float width_, Vector p, const std::string& default_value,
+ bool locked)
: str(default_value),
pos(p),
width(width_),
- height((float)Fonts::pingus_small.get_height())
+ height((float)Fonts::pingus_small.get_height()),
+ is_locked(locked)
{
}
@@ -66,7 +68,7 @@
std::string ret_string;
int w = (int)width / Fonts::pingus_small.get_width('W');
- if (s.length() > w - 1)
+ if ((int)s.length() > w - 1)
ret_string = s.substr(std::max(0, (int)s.length()-w), w - 1);
else
ret_string = s;
@@ -74,6 +76,21 @@
return ret_string;
}
+void
+InputBox::on_key_pressed(const char c)
+{
+ if (!is_locked)
+ {
+ // Verify input and escape out bad characters
+ if (c == 0x08) // backspace
+ str = str.substr(0, str.length()-1);
+ else if ((c > 0x2c && c < 0x3a) // - . / 0-9
+ || (c > 0x40 && c < 0x5b) // capital letters
+ || (c > 0x60 && c < 0x7b) // lowercase letters
+ || (c == 0x7e || c == 0x5f)) // ~ and _
+ str += c;
+ }
+}
} // GUI
} // Pingus
Modified: trunk/src/gui/input_box.hxx
===================================================================
--- trunk/src/gui/input_box.hxx 2006-01-23 23:55:24 UTC (rev 2623)
+++ trunk/src/gui/input_box.hxx 2006-01-24 01:44:58 UTC (rev 2624)
@@ -37,18 +37,19 @@
Vector pos;
float width;
float height;
+ bool is_locked;
/** Shrink the string to fit in the box */
std::string shrink_string(const std::string& s) const;
public:
InputBox(float width_, Vector p, const std::string&
- default_value = std::string());
+ default_value = std::string(), bool locked = false);
void set_string(const std::string& s) { str = s; }
std::string get_string() { return str; }
- void on_key_pressed(const char c) { str += c; }
+ void on_key_pressed(const char c);
/// GUI Component functions:
///
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2624 - in trunk/src: . editor gui,
jave27 <=