From b49e4da20b25e130cfdce4c861f0bec901f9c057 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Tue, 21 Oct 2008 18:40:46 +0000 Subject: fixed editor saving, open and append. note that you can only save maps to your user directory --- src/engine/e_engine.c | 21 +++++++++++++++------ src/engine/e_engine.h | 10 +++++++++- src/game/client/components/skins.cpp | 2 +- src/game/editor/ed_editor.cpp | 21 ++++++++++++--------- src/game/editor/ed_editor.hpp | 2 +- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/engine/e_engine.c b/src/engine/e_engine.c index d73082db..e3dd4df1 100644 --- a/src/engine/e_engine.c +++ b/src/engine/e_engine.c @@ -88,20 +88,29 @@ void engine_init(const char *appname) } -void engine_listdir(const char *path, FS_LISTDIR_CALLBACK cb, void *user) +void engine_listdir(int types, const char *path, FS_LISTDIR_CALLBACK cb, void *user) { char buffer[1024]; /* list current directory */ - fs_listdir(path, cb, user); + if(types&LISTDIRTYPE_CURRENT) + { + fs_listdir(path, cb, user); + } /* list users directory */ - engine_savepath(path, buffer, sizeof(buffer)); - fs_listdir(buffer, cb, user); + if(types&LISTDIRTYPE_SAVE) + { + engine_savepath(path, buffer, sizeof(buffer)); + fs_listdir(buffer, cb, user); + } /* list datadir directory */ - str_format(buffer, sizeof(buffer), "%s/%s", datadir, path); - fs_listdir(buffer, cb, user); + if(types&LISTDIRTYPE_DATA) + { + str_format(buffer, sizeof(buffer), "%s/%s", datadir, path); + fs_listdir(buffer, cb, user); + } } void engine_getpath(char *buffer, int buffer_size, const char *filename, int flags) diff --git a/src/engine/e_engine.h b/src/engine/e_engine.h index f11ba5c5..0a5385cc 100644 --- a/src/engine/e_engine.h +++ b/src/engine/e_engine.h @@ -11,7 +11,15 @@ void engine_config_write_line(const char *line); void engine_config_write_stop(); -void engine_listdir(const char *path, FS_LISTDIR_CALLBACK cb, void *user); +enum +{ + LISTDIRTYPE_SAVE=1, + LISTDIRTYPE_CURRENT=2, + LISTDIRTYPE_DATA=4, + LISTDIRTYPE_ALL = ~0 +}; + +void engine_listdir(int types, const char *path, FS_LISTDIR_CALLBACK cb, void *user); IOHANDLE engine_openfile(const char *filename, int flags); void engine_getpath(char *buffer, int buffer_size, const char *filename, int flags); diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 0ce3d952..451a77f3 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -125,7 +125,7 @@ void SKINS::init() { // load skins num_skins = 0; - engine_listdir("skins", skinscan, this); + engine_listdir(LISTDIRTYPE_ALL, "skins", skinscan, this); } int SKINS::num() diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index a7110a3b..11df0a59 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -10,6 +10,7 @@ extern "C" { #include #include #include + #include } #include @@ -541,11 +542,11 @@ static void do_toolbar(RECT toolbar) // ctrl+o to open if(inp_key_down('O') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL))) - editor.invoke_file_dialog("Open Map", "Open", "maps/", "", callback_open_map); + editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Open Map", "Open", "maps/", "", callback_open_map); // ctrl+s to save if(inp_key_down('S') && (inp_key_pressed(KEY_LCTRL) || inp_key_pressed(KEY_RCTRL))) - editor.invoke_file_dialog("Save Map", "Save", "maps/", "", callback_save_map); + editor.invoke_file_dialog(LISTDIRTYPE_SAVE, "Save Map", "Save", "maps/", "", callback_save_map); // animate button ui_vsplit_l(&toolbar, 30.0f, &button, &toolbar); @@ -1676,7 +1677,7 @@ static int popup_image(RECT view) ui_hsplit_t(&view, 12.0f, &slot, &view); if(do_editor_button(&replace_button, "Replace", 0, &slot, draw_editor_button_menuitem, 0, "Replaces the image with a new one")) { - editor.invoke_file_dialog("Replace Image", "Replace", "mapres/", "", replace_image); + editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Replace Image", "Replace", "mapres/", "", replace_image); return 1; } @@ -1757,10 +1758,11 @@ static void render_images(RECT toolbox, RECT toolbar, RECT view) ui_hsplit_t(&toolbox, 10.0f, &slot, &toolbox); ui_hsplit_t(&toolbox, 12.0f, &slot, &toolbox); if(do_editor_button(&new_image_button, "Add", 0, &slot, draw_editor_button, 0, "Load a new image to use in the map")) - editor.invoke_file_dialog("Add Image", "Add", "mapres/", "", add_image); + editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Add Image", "Add", "mapres/", "", add_image); } +static int file_dialog_dirtypes = 0; static const char *file_dialog_title = 0; static const char *file_dialog_button_text = 0; static void (*file_dialog_func)(const char *filename); @@ -1832,7 +1834,7 @@ static void render_file_dialog() strcat(file_dialog_complete_filename, file_dialog_filename); // the list - fs_listdir(file_dialog_path, editor_listdir_callback, &view); + engine_listdir(file_dialog_dirtypes, file_dialog_path, editor_listdir_callback, &view); // the buttons static int ok_button = 0; @@ -1853,10 +1855,11 @@ static void render_file_dialog() editor.dialog = DIALOG_NONE; } -void EDITOR::invoke_file_dialog(const char *title, const char *button_text, +void EDITOR::invoke_file_dialog(int listdirtypes, const char *title, const char *button_text, const char *basepath, const char *default_name, void (*func)(const char *filename)) { + file_dialog_dirtypes = listdirtypes; file_dialog_title = title; file_dialog_button_text = button_text; file_dialog_func = func; @@ -2294,7 +2297,7 @@ static int popup_menu_file(RECT view) ui_hsplit_t(&view, 12.0f, &slot, &view); if(do_editor_button(&open_button, "Open", 0, &slot, draw_editor_button_menuitem, 0, "Opens a map for editing")) { - editor.invoke_file_dialog("Open Map", "Open", "maps/", "", callback_open_map); + editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Open Map", "Open", "maps/", "", callback_open_map); return 1; } @@ -2302,7 +2305,7 @@ static int popup_menu_file(RECT view) ui_hsplit_t(&view, 12.0f, &slot, &view); if(do_editor_button(&append_button, "Append", 0, &slot, draw_editor_button_menuitem, 0, "Opens a map and adds everything from that map to the current one")) { - editor.invoke_file_dialog("Append Map", "Append", "maps/", "", callback_append_map); + editor.invoke_file_dialog(LISTDIRTYPE_ALL, "Append Map", "Append", "maps/", "", callback_append_map); return 1; } @@ -2317,7 +2320,7 @@ static int popup_menu_file(RECT view) ui_hsplit_t(&view, 12.0f, &slot, &view); if(do_editor_button(&save_as_button, "Save As", 0, &slot, draw_editor_button_menuitem, 0, "Saves the current map under a new name")) { - editor.invoke_file_dialog("Save Map", "Save", "maps/", "", callback_save_map); + editor.invoke_file_dialog(LISTDIRTYPE_SAVE, "Save Map", "Save", "maps/", "", callback_save_map); return 1; } diff --git a/src/game/editor/ed_editor.hpp b/src/game/editor/ed_editor.hpp index 44eb4664..4f48406e 100644 --- a/src/game/editor/ed_editor.hpp +++ b/src/game/editor/ed_editor.hpp @@ -367,7 +367,7 @@ public: show_envelope_editor = 0; } - void invoke_file_dialog(const char *title, const char *button_text, + void invoke_file_dialog(int listdir_type, const char *title, const char *button_text, const char *basepath, const char *default_name, void (*func)(const char *filename)); -- cgit 1.4.1