From ba36fa675f180929d0c5d189c9939a7f835b564d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 31 Oct 2009 17:33:04 +0000 Subject: [PATCH] =?UTF-8?q?-Moved=20test=20script=20to=20"scripts"=20direc?= =?UTF-8?q?tory=20-Allow=20to=20add=20other=20scripts=20to=20this=20dir=20?= =?UTF-8?q?and=20run=20them=20too.=20--Cette=20ligne,=20et=20les=20suivant?= =?UTF-8?q?es=20ci-dessous,=20seront=20ignor=C3=A9es--?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A trunk/scripts A + trunk/scripts/test.lua D trunk/test.lua M trunk/buttons.c M trunk/factory.c git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1125 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- buttons.c | 21 +++++++------ factory.c | 58 ++++++++++++++++++++++++++++++++++-- test.lua => scripts/test.lua | 0 3 files changed, 67 insertions(+), 12 deletions(-) rename test.lua => scripts/test.lua (100%) diff --git a/buttons.c b/buttons.c index b34e5049..75e0eba6 100644 --- a/buttons.c +++ b/buttons.c @@ -961,13 +961,13 @@ void Add_font_or_skin(const char *name) if (fname) fname++; else - fname=name; + fname = name; namelength = strlen(fname); if (namelength>=10 && fname[0]!='_' && !strncasecmp(fname, "skin_", 5) - && (!strcasecmp(fname+namelength-4,".png") - || !strcasecmp(fname+namelength-4,".gif"))) + && (!strcasecmp(fname + namelength - 4,".png") + || !strcasecmp(fname + namelength - 4,".gif"))) { - Add_element_to_list(&Skin_files_list, name, 0); + Add_element_to_list(&Skin_files_list, name, 0); if (fname[0]=='\0') return; @@ -979,9 +979,10 @@ void Add_font_or_skin(const char *name) Format_filename(Skin_files_list.First->Full_name, 0) ); } - else if (namelength>=10 && !strncasecmp(fname, "font_", 5) && (!strcasecmp(fname+namelength-4,".png"))) + else if (namelength>=10 && !strncasecmp(fname, "font_", 5) + && (!strcasecmp(fname + namelength - 4, ".png"))) { - Add_element_to_list(&Font_files_list, name, 0); + Add_element_to_list(&Font_files_list, name, 0); if (fname[0]=='\0') return; @@ -989,7 +990,8 @@ void Add_font_or_skin(const char *name) // Remove directory from full name strcpy(Font_files_list.First->Full_name, fname); // Reformat the short name differently - strcpy(Font_files_list.First->Short_name,Format_font_filename(Font_files_list.First->Full_name)); + strcpy(Font_files_list.First->Short_name, + Format_font_filename(Font_files_list.First->Full_name)); } } @@ -1002,7 +1004,8 @@ void Draw_one_skin_name(word x, word y, word index, byte highlighted) if (Skin_files_list.Nb_elements) { current_item = Get_item_by_index(&Skin_files_list, index); - Print_in_window(x,y,current_item->Short_name, MC_Black, (highlighted)?MC_Dark:MC_Light); + Print_in_window(x, y, current_item->Short_name, MC_Black, + (highlighted)?MC_Dark:MC_Light); } } @@ -1026,7 +1029,7 @@ void Button_Skins(void) byte separatecolors = Config.Separate_colors; byte showlimits = Config.Display_image_limits; - word x,y, x_pos, offs_y; + word x, y, x_pos, offs_y; char * cursors[] = { "Solid", "Transparent", "Thin" }; T_Gui_skin * gfx = NULL; diff --git a/factory.c b/factory.c index e781fce7..103cb65c 100644 --- a/factory.c +++ b/factory.c @@ -26,8 +26,10 @@ #include "buttons.h" #include "engine.h" #include "errors.h" +#include "filesel.h" // Get_item_by_index #include "global.h" #include "graph.h" +#include "io.h" // find_last_slash #include "misc.h" #include "readline.h" #include "sdlscreen.h" @@ -113,21 +115,68 @@ int L_GetColor(lua_State* L) return 3; } -int L_BrushEnable(lua_State* L) +int L_BrushEnable(__attribute__((unused)) lua_State* L) { Change_paintbrush_shape(PAINTBRUSH_SHAPE_COLOR_BRUSH); return 0; } +// Handlers for window internals +T_Fileselector Scripts_list; + +// Callback to display a skin name in the list +void Draw_script_name(word x, word y, word index, byte highlighted) +{ + T_Fileselector_item * current_item; + + DEBUG("draw",index); + if (Scripts_list.Nb_elements) + { + current_item = Get_item_by_index(&Scripts_list, index); + Print_in_window(x, y, current_item->Short_name, MC_Black, + (highlighted)?MC_Dark:MC_Light); + } +} + +// Add a skin to the list +void Add_script(const char *name) +{ + Add_element_to_list(&Scripts_list, Find_last_slash(name)+1, 0); +} + void Button_Brush_Factory(void) { short clicked_button; + T_List_button* scriptlist; + T_Scroller_button* scriptscroll; + char scriptdir[MAX_PATH_CHARACTERS]; - Open_window(154, 162, "Brush Factory"); + Open_window(175, 162, "Brush Factory"); + + // Here we use the same data container as the fileselectors. + // Reinitialize the list + Free_fileselector_list(&Scripts_list); + strcpy(scriptdir, Data_directory); + strcat(scriptdir, "scripts/"); + // Add each found file to the list + For_each_file(scriptdir, Add_script); + // Sort it + Sort_list_of_files(&Scripts_list); Window_set_normal_button(77, 141, 67, 14, "Cancel", 0, 1, KEY_ESC); // 1 Window_set_normal_button(10, 141, 67, 14, "Run", 0, 1, 0); // 2 + #define FILESEL_Y 18 + Window_display_frame_in(6, FILESEL_Y - 2, 148, 84); // File selector + scriptlist = Window_set_list_button( + // Fileselector + Window_set_special_button(8, FILESEL_Y + 1, 144, 80), // 3 + // Scroller for the fileselector + (scriptscroll = Window_set_scroller_button(154, FILESEL_Y - 1, 82, + Scripts_list.Nb_elements, 10, 0)), // 4 + Draw_script_name); // 5 + Window_redraw_list(scriptlist); + Update_window_area(0, 0, Window_width, Window_height); Display_cursor(); @@ -161,7 +210,10 @@ void Button_Brush_Factory(void) // For debug only // luaL_openlibs(L); - if (luaL_loadfile(L,"./test.lua") != 0) + strcat(scriptdir, Get_item_by_index(&Scripts_list, + scriptlist->List_start + scriptlist->Cursor_position) + -> Full_name); + if (luaL_loadfile(L,scriptdir) != 0) Verbose_error_message(lua_tostring(L, 1)); else if (lua_pcall(L, 0, 0, 0) != 0) Verbose_error_message(lua_tostring(L, 1)); diff --git a/test.lua b/scripts/test.lua similarity index 100% rename from test.lua rename to scripts/test.lua