string_list_type additions and leveleditor improvements.
authorTobias Gläßer <tobi.web@gmx.de>
Fri, 5 Mar 2004 14:22:27 +0000 (14:22 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Fri, 5 Mar 2004 14:22:27 +0000 (14:22 +0000)
SVN-Revision: 171

src/leveleditor.c
src/type.c
src/type.h

index dacafa1..d21d876 100644 (file)
@@ -1,4 +1,3 @@
-
 /***************************************************************************
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -449,6 +448,7 @@ int le_init()
 void update_level_settings_menu()
 {
   char str[80];
+  int i;
 
   menu_item_change_input(&level_settings_menu.item[2], le_current_level->name);
   sprintf(str,"%d",le_current_level->width);
@@ -456,7 +456,13 @@ void update_level_settings_menu()
   string_list_copy(level_settings_menu.item[3].list, dsubdirs("images/themes", "solid0.png"));
   string_list_copy(level_settings_menu.item[4].list, dfiles("music/", NULL));
   string_list_copy(level_settings_menu.item[5].list, dfiles("images/background", NULL));
-  
+  if((i = string_list_find(level_settings_menu.item[3].list,le_current_level->theme)) != -1)
+    level_settings_menu.item[3].list->active_item = i;
+  if((i = string_list_find(level_settings_menu.item[4].list,le_current_level->song_title)) != -1)
+    level_settings_menu.item[4].list->active_item = i;
+  if((i = string_list_find(level_settings_menu.item[5].list,le_current_level->bkgd_image)) != -1)
+    level_settings_menu.item[5].list->active_item = i;
+
   menu_item_change_input(&level_settings_menu.item[6], str);
   sprintf(str,"%d",le_current_level->time_left);
   menu_item_change_input(&level_settings_menu.item[7], str);
@@ -473,19 +479,30 @@ void update_level_settings_menu()
 void apply_level_settings_menu()
 {
   int i,y,j;
+  i = NO;
+
   strcpy(le_current_level->name,level_settings_menu.item[2].input);
-  
-  strcpy(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list));
-  
+
+  if(strcmp(le_current_level->theme,string_list_active(level_settings_menu.item[5].list)) != 0)
+    {
+      strcpy(le_current_level->bkgd_image,string_list_active(level_settings_menu.item[5].list));
+      i = YES;
+    }
+
   if(strcmp(le_current_level->theme,string_list_active(level_settings_menu.item[3].list)) != 0)
-  {
-  strcpy(le_current_level->theme,string_list_active(level_settings_menu.item[3].list));
-  level_free_gfx();
-  level_load_gfx(le_current_level);
-  }
-  
+    {
+      strcpy(le_current_level->theme,string_list_active(level_settings_menu.item[3].list));
+      i = YES;
+    }
+
+  if(i == YES)
+    {
+      level_free_gfx();
+      level_load_gfx(le_current_level);
+    }
+
   strcpy(le_current_level->song_title,string_list_active(level_settings_menu.item[4].list));
-  
+
   i = le_current_level->width;
   le_current_level->width = atoi(level_settings_menu.item[6].input);
   if(le_current_level->width < i)
index ee23c27..2a77ee9 100644 (file)
 
 void string_list_init(string_list_type* pstring_list)
 {
-pstring_list->num_items = 0;
-pstring_list->active_item = -1;
-pstring_list->item = NULL;
+  pstring_list->num_items = 0;
+  pstring_list->active_item = -1;
+  pstring_list->item = NULL;
 }
 
 char* string_list_active(string_list_type* pstring_list)
 {
-if(pstring_list == NULL)
-return "";
+  if(pstring_list == NULL)
+    return "";
 
-if(pstring_list->active_item != -1)
-return pstring_list->item[pstring_list->active_item];
-else
-return "";
+  if(pstring_list->active_item != -1)
+    return pstring_list->item[pstring_list->active_item];
+  else
+    return "";
 }
 
 void string_list_add_item(string_list_type* pstring_list, char* str)
 {
-char *pnew_string;
-pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1));
-strcpy(pnew_string,str);
-++pstring_list->num_items;
-pstring_list->item = (char**) realloc(pstring_list->item,sizeof(char**)*pstring_list->num_items);
-pstring_list->item[pstring_list->num_items-1] = pnew_string;
-if(pstring_list->active_item == -1)
-pstring_list->active_item = 0;
+  char *pnew_string;
+  pnew_string = (char*) malloc(sizeof(char)*(strlen(str)+1));
+  strcpy(pnew_string,str);
+  ++pstring_list->num_items;
+  pstring_list->item = (char**) realloc(pstring_list->item,sizeof(char**)*pstring_list->num_items);
+  pstring_list->item[pstring_list->num_items-1] = pnew_string;
+  if(pstring_list->active_item == -1)
+    pstring_list->active_item = 0;
 }
 
 void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig)
 {
-int i;
-string_list_free(pstring_list);
-for(i = 0; i < pstring_list_orig.num_items; ++i)
-string_list_add_item(pstring_list,pstring_list_orig.item[i]);
+  int i;
+  string_list_free(pstring_list);
+  for(i = 0; i < pstring_list_orig.num_items; ++i)
+    string_list_add_item(pstring_list,pstring_list_orig.item[i]);
 }
 
-void string_list_free(string_list_type* pstring_list)
-{
-if(pstring_list != NULL)
+int string_list_find(string_list_type* pstring_list, char* str)
 {
   int i;
-  for(i=0; i < pstring_list->num_items; ++i)
-    free(pstring_list->item[i]);
-free(pstring_list->item);
-pstring_list->item = NULL;
-pstring_list->num_items = 0;
-pstring_list->active_item = -1;
+  for(i = 0; i < pstring_list->num_items; ++i)
+    {
+      if(strcmp(pstring_list->item[i],str) == 0)
+        {
+          return i;
+        }
+    }
+  return -1;
 }
+
+void string_list_free(string_list_type* pstring_list)
+{
+  if(pstring_list != NULL)
+    {
+      int i;
+      for(i=0; i < pstring_list->num_items; ++i)
+        free(pstring_list->item[i]);
+      free(pstring_list->item);
+      pstring_list->item = NULL;
+      pstring_list->num_items = 0;
+      pstring_list->active_item = -1;
+    }
 }
index b02a350..c039486 100644 (file)
@@ -41,6 +41,7 @@ string_list_type;
 void string_list_init(string_list_type* pstring_list);
 char* string_list_active(string_list_type* pstring_list);
 void string_list_copy(string_list_type* pstring_list, string_list_type pstring_list_orig);
+int string_list_find(string_list_type* pstring_list, char* str);
 void string_list_add_item(string_list_type* pstring_list, char* str);
 void string_list_free(string_list_type* pstring_list);