summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/libman.cpp52
-rwxr-xr-xcommon/library.cpp34
-rwxr-xr-xcommon/library.h1
-rw-r--r--common/project.cpp6
-rw-r--r--common/typedefs.h23
5 files changed, 76 insertions, 40 deletions
diff --git a/common/libman.cpp b/common/libman.cpp
index 82d2fd3..fddf8e0 100644
--- a/common/libman.cpp
+++ b/common/libman.cpp
@@ -87,47 +87,37 @@ void LibraryManager::HandleCommand (int id, int param)
case LC_LIBDLG_FILE_MERGEUPDATE:
{
- char filename[LC_MAXPATH];
+// char filename[LC_MAXPATH];
// FIXME: file extension
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
- return;
+// if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
+// return;
- project->GetPiecesLibrary ()->LoadUpdate (filename);
+// project->GetPiecesLibrary ()->LoadUpdate (filename);
// FIXME: update m_pPieces
} break;
case LC_LIBDLG_FILE_IMPORTPIECE:
{
-/*
- char filename[LC_MAXPATH];
- LC_LDRAW_PIECE piece;
-
- // CFileDialog dlg(TRUE, ".dat\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- // "LDraw Files (*.dat)|*.dat|All Files (*.*)|*.*||",this);
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, filename))
- return;
-
- BeginWait ();
-
- if (ReadLDrawPiece(filename, &piece))
- {
- if (project->GetPiecesLibrary ()->FindPieceInfo(piece.name) != NULL)
- Sys_MessageBox ("Piece already exists in the library !");
-
- if (SaveLDrawPiece(&piece))
- Sys_MessageBox ("Piece successfully imported.");
- else
- Sys_MessageBox ("Error saving library.");
- }
- else
- Sys_MessageBox ("Error reading file.");
-
- EndWait ();
- FreeLDrawPiece(&piece);
+ LC_FILEOPENDLG_OPTS opts;
+
+ strcpy(opts.path, Sys_ProfileLoadString ("Default", "LDraw Pieces Path", ""));
+ opts.type = LC_FILEOPENDLG_DAT;
+
+ if (!SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
+ return;
+
+ for (int i = 0; i < opts.numfiles; i++)
+ {
+ project->GetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
+ free (opts.filenames[i]);
+ }
+
+ free (opts.filenames);
+ Sys_ProfileSaveString ("Default", "LDraw Pieces Path", opts.path);
+
// FIXME: update m_pPieces
-*/
} break;
case LC_LIBDLG_FILE_RETURN:
diff --git a/common/library.cpp b/common/library.cpp
index 6f9db2c..6fd8181 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -45,10 +45,13 @@ void PiecesLibrary::CheckReload ()
strcpy (LibraryPath, m_LibraryPath);
- // FIXME: project will crash if we don't update the pieceinfos
+ if (m_bNeedsReload)
+ {
+ // FIXME: project will crash if we don't update the pieceinfos
- Unload ();
- Load (LibraryPath);
+ Unload ();
+ Load (LibraryPath);
+ }
}
void PiecesLibrary::Unload ()
@@ -1103,8 +1106,33 @@ bool PiecesLibrary::ImportTexture (const char* Name)
}
// =============================================================================
+// LDraw support
+
+bool PiecesLibrary::ImportLDrawPiece (const char* Filename)
+{
+ LC_LDRAW_PIECE piece;
+
+ SystemDoWaitCursor(1);
+
+ if (ReadLDrawPiece (Filename, &piece))
+ {
+// if (FindPieceInfo (piece.name) != NULL)
+// Sys_MessageBox ("Piece already exists in the library !");
+ if (SaveLDrawPiece (&piece))
+ Sys_MessageBox ("Piece successfully imported.");
+ else
+ Sys_MessageBox ("Error saving library.");
+ }
+ else
+ Sys_MessageBox ("Error reading file.");
+
+ FreeLDrawPiece(&piece);
+ SystemDoWaitCursor(-1);
+
+ return true;
+}
diff --git a/common/library.h b/common/library.h
index c9b60c6..d24c029 100755
--- a/common/library.h
+++ b/common/library.h
@@ -46,6 +46,7 @@ public:
bool LoadUpdate (const char* update);
bool DeleteTextures (char** Names, int NumTextures);
bool ImportTexture (const char* Name);
+ bool ImportLDrawPiece (const char* Filename);
static unsigned long GetDefaultPieceGroup (const char* name);
diff --git a/common/project.cpp b/common/project.cpp
index 46ece2f..ec1f35b 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -1331,7 +1331,7 @@ bool Project::DoSave(char* lpszPathName, bool bReplace)
strcat(newName, ".lcd");
}
- if (!SystemDoDialog(LC_DLG_FILE_SAVE, &newName))
+ if (!SystemDoDialog(LC_DLG_FILE_SAVE_PROJECT, &newName))
return false; // don't even attempt to save
}
@@ -3051,7 +3051,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
char filename[LC_MAXPATH];
strcpy(filename, m_strModelsPath);
- if (SystemDoDialog(LC_DLG_FILE_OPEN, filename))
+ if (SystemDoDialog(LC_DLG_FILE_OPEN_PROJECT, filename))
{
if (!SaveModified())
return; // leave the original one
@@ -3079,7 +3079,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
char filename[LC_MAXPATH];
strcpy(filename, m_strModelsPath);
- if (SystemDoDialog(LC_DLG_FILE_MERGE, filename))
+ if (SystemDoDialog(LC_DLG_FILE_MERGE_PROJECT, filename))
{
FileDisk file;
if (file.Open(filename, "rb"))
diff --git a/common/typedefs.h b/common/typedefs.h
index 4465812..45d800b 100644
--- a/common/typedefs.h
+++ b/common/typedefs.h
@@ -173,7 +173,8 @@ typedef struct
// Image
-typedef enum {
+typedef enum
+{
LC_IMAGE_BMP,
LC_IMAGE_GIF,
LC_IMAGE_JPG,
@@ -204,9 +205,10 @@ typedef struct
} LC_IMAGEDLG_OPTS;
typedef enum {
+ LC_DLG_FILE_OPEN_PROJECT,
+ LC_DLG_FILE_SAVE_PROJECT,
+ LC_DLG_FILE_MERGE_PROJECT,
LC_DLG_FILE_OPEN,
- LC_DLG_FILE_SAVE,
- LC_DLG_FILE_MERGE,
LC_DLG_PICTURE_SAVE,
LC_DLG_HTML,
LC_DLG_POVRAY,
@@ -224,6 +226,21 @@ typedef enum {
LC_DLG_ABOUT
} LC_DIALOGS;
+typedef enum
+{
+ LC_FILEOPENDLG_DAT,
+ LC_FILEOPENDLG_LGF,
+ LC_FILEOPENDLG_LUP
+} LC_FILEOPENDLG_TYPES;
+
+typedef struct
+{
+ int type;
+ char path[LC_MAXPATH];
+ int numfiles;
+ char** filenames;
+} LC_FILEOPENDLG_OPTS;
+
typedef struct
{
bool render;