* introduced a new config variable to be able to load maps directly from the enginePath/basePath/maps directory

git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@286 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
mattn 2008-06-26 18:50:18 +00:00
parent 3138825cde
commit 88d21daa67
5 changed files with 71 additions and 36 deletions

View file

@ -1197,7 +1197,10 @@ private:
};
const char* file_dialog (void *parent, gboolean open, const char* title, const char* path, const char* pattern)
/**
* @param[in] baseSubDir should have a trailing slash if not @c NULL
*/
const char* file_dialog (void *parent, gboolean open, const char* title, const char* path, const char* pattern, const char *baseSubDir)
{
// Gtk dialog
GtkWidget* file_sel;
@ -1290,6 +1293,7 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
else
{
#endif
char buf[PATH_MAX];
// do that the Gtk way
if (title == NULL)
title = open ? _("Open File") : _("Save File");
@ -1300,14 +1304,13 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
// we expect an actual path below, if the path is NULL we might crash
if (!path || path[0] == '\0')
{
#ifdef _WIN32
path = "C:\\";
#elif defined (__linux__) || defined (__APPLE__)
path = "/";
#else
path = "/";
#endif
}
strcpy(buf, g_pGameDescription->mEnginePath.GetBuffer());
strcat(buf, g_pGameDescription->mBaseGame.GetBuffer());
strcat(buf, "/");
if (baseSubDir)
strcat(buf, baseSubDir);
path = buf;
}
// alloc new path with extra char for dir separator
new_path = new char[strlen(path)+1+1];
@ -1320,16 +1323,13 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
*w = '\0';
#ifdef FILEDLG_DBG
Sys_Printf("Done.\n");
Sys_Printf("Calling gtk_file_selection_new with title: %s...", title);
Sys_Printf("Done.\n");
Sys_Printf("Calling gtk_file_selection_new with title: %s...", title);
#endif
file_sel = gtk_file_selection_new (title);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_sel), "/home/mattn/dev/ufoai/trunk/base/maps/");
#ifdef FILEDLG_DBG
Sys_Printf("Done.\n");
Sys_Printf("Set the masks...");
Sys_Printf("Done.\n");
Sys_Printf("Set the masks...");
#endif
#if 0 //!\todo Add masks to GtkFileSelection in gtk-2.0
@ -1380,7 +1380,7 @@ const char* file_dialog (void *parent, gboolean open, const char* title, const c
if (new_path != NULL)
{
#ifdef FILEDLG_DBG
Sys_Printf("gtk_file_selection_set_filename... %p", file_sel);
Sys_Printf("gtk_file_selection_set_filename... %p (%s)", file_sel, new_path);
#endif
gtk_file_selection_set_filename (GTK_FILE_SELECTION (file_sel), new_path);
delete[] new_path;

View file

@ -81,7 +81,7 @@ URL adds an optional 'go to URL' button
int WINAPI gtk_MessageBox (void *parent, const char* lpText, const char* lpCaption = "Radiant", guint32 uType = MB_OK, const char* URL = NULL);
// NOTE: the returned filename is allocated with g_malloc and MUST be freed with g_free (both for win32 and Gtk dialogs)
// GtkWidget *parent
const char* file_dialog (void *parent, gboolean open, const char* title, const char* path = (char*)NULL, const char* pattern = NULL);
const char* file_dialog (void *parent, gboolean open, const char* title, const char* path = (char*)NULL, const char* pattern = NULL, const char *baseSubDir = NULL);
/*!
\fn dir_dialog, prompts for a directory

View file

@ -1425,7 +1425,7 @@ void MainFrame::create_main_menu (GtkWidget *window, GtkWidget *vbox)
item = create_menu_item_with_mnemonic (menu, _("Previous leak spot"),
GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_PREVIOUSLEAKSPOT);
// http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=394
// create_menu_item_with_mnemonic (menu, "_Print XY View", GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_PRINTXY);
// create_menu_item_with_mnemonic (menu, _("_Print XY View"), GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_PRINTXY);
item = create_menu_item_with_mnemonic (menu, _("_Select Entity Color..."),
GTK_SIGNAL_FUNC (HandleCommand), ID_MISC_SELECTENTITYCOLOR);
g_object_set_data (G_OBJECT (window), "menu_misc_selectentitycolor", item);
@ -4264,10 +4264,14 @@ void MainFrame::OnFileOpen()
const char *str;
char buf[NAME_MAX];
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
if (!g_pGameDescription->noMapsInHome) {
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
} else {
buf[0] = '\0';
}
str = file_dialog (m_pWidget, TRUE, _("Open Map"), buf, MAP_MAJOR);
str = file_dialog (m_pWidget, TRUE, _("Open Map"), buf, MAP_MAJOR, "maps/");
if (str != NULL)
{
@ -4282,10 +4286,14 @@ void MainFrame::OnFileImportmap()
const char *str;
char buf[NAME_MAX];
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
if (!g_pGameDescription->noMapsInHome) {
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
} else {
buf[0] = '\0';
}
str = file_dialog (m_pWidget, TRUE, _("Import Map"), buf, MAP_MAJOR);
str = file_dialog (m_pWidget, TRUE, _("Import Map"), buf, MAP_MAJOR, "maps/");
if (str != NULL)
{
@ -4306,10 +4314,14 @@ void MainFrame::OnFileSaveas()
const char* str;
char buf[NAME_MAX];
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
if (!g_pGameDescription->noMapsInHome) {
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
} else {
buf[0] = '\0';
}
str = file_dialog (g_pParentWnd->m_pWidget, FALSE, _("Save Map"), buf, MAP_MAJOR);
str = file_dialog (g_pParentWnd->m_pWidget, FALSE, _("Save Map"), buf, MAP_MAJOR, "maps/");
if (str != NULL)
{
@ -4324,10 +4336,14 @@ void MainFrame::OnFileExportmap()
const char* str;
char buf[NAME_MAX];
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
if (!g_pGameDescription->noMapsInHome) {
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
} else {
buf[0] = '\0';
}
str = file_dialog (m_pWidget, FALSE, _("Export Selection"), buf, MAP_MAJOR);
str = file_dialog (m_pWidget, FALSE, _("Export Selection"), buf, MAP_MAJOR, "maps/");
if (str != NULL)
{
@ -4340,10 +4356,14 @@ void MainFrame::OnFileSaveregion()
const char* str;
char buf[NAME_MAX];
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
if (!g_pGameDescription->noMapsInHome) {
strcpy(buf, g_qeglobals.m_strHomeMaps.GetBuffer());
strcat(buf, "maps/");
} else {
buf[0] = '\0';
}
str = file_dialog (g_pParentWnd->m_pWidget, FALSE, _("Export Region"), buf, MAP_MAJOR);
str = file_dialog (g_pParentWnd->m_pWidget, FALSE, _("Export Region"), buf, MAP_MAJOR, "maps/");
if (str != NULL)
{
@ -4576,7 +4596,7 @@ void MainFrame::OnEditLoadprefab()
AddSlash (CurPath);
}
filename = file_dialog (m_pWidget, TRUE, _("Import Prefab"), CurPath.GetBuffer(), MAP_MAJOR);
filename = file_dialog (m_pWidget, TRUE, _("Import Prefab"), CurPath.GetBuffer(), MAP_MAJOR, "prefabs/");
if (filename != NULL)
{
@ -4600,7 +4620,7 @@ void MainFrame::OnEditSaveprefab()
}
AddSlash (CurPath);
filename = file_dialog (m_pWidget, FALSE, _("Export Prefab"), CurPath.GetBuffer(), MAP_MAJOR);
filename = file_dialog (m_pWidget, FALSE, _("Export Prefab"), CurPath.GetBuffer(), MAP_MAJOR, "prefabs/");
if (filename != NULL)
{
Map_SaveSelected(filename);

View file

@ -759,6 +759,20 @@ CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
xmlFree(prop);
}
// if this is set, the open maps dialoge will open the engine path not the
// home dir for map loading and saving
prop = (char*)xmlGetProp(pNode, (xmlChar*)"no_maps_in_home");
if (prop == NULL)
{
// default
noMapsInHome = false;
}
else
{
noMapsInHome = true;
xmlFree(prop);
}
prop = (char*)xmlGetProp(pNode, (xmlChar*)"basegame");
if (prop == NULL)
{

View file

@ -181,6 +181,7 @@ public:
bool mNoPatch; ///< this game doesn't support patch technology
Str mCaulkShader; ///< the shader to use for caulking
bool quake2; ///< set this to true to get quake2
bool noMapsInHome; ///< set this if you want to open the engine path/base dir/maps dir for map open/save dialoges */
CGameDescription() { mpDoc = NULL; }
/*!