00001 #include "editor.h"
00002
00003
00004 void map_properties(void)
00005 {
00006 enter_properties_state();
00007 }
00008
00009
00010 void map_resize(void)
00011 {
00012 enter_resize_state();
00013 }
00014
00015
00016 void map_next(void)
00017 {
00018 if(current_map_num+1 < num_maps) {
00019 set_current_map(current_map_num+1);
00020 draw_current_map();
00021 }
00022 }
00023
00024
00025 void map_previous(void)
00026 {
00027 if(current_map_num > 0) {
00028 set_current_map(current_map_num-1);
00029 draw_current_map();
00030 }
00031 }
00032
00033
00034 void map_import_level(void)
00035 {
00036 char filename[64];
00037 FILE *fin;
00038 file_header header;
00039 int ii=current_map_num;
00040 int format;
00041 int offset;
00042 dialog_read_string("Import what file?", filename, 30, 25, 100, 40);
00043
00044 fin = fopen(filename, "rb");
00045 if(!fin) {
00046 draw_current_map();
00047 show_dialog("File not found.", 25, 25, 70, 30);
00048 return;
00049 }
00050
00051 if(fread(&header, sizeof(file_header), 1, fin) < 1) {
00052 fclose(fin);
00053 show_dialog("Corrupt file.", 25, 25, 70, 30);
00054 return;
00055 }
00056 if( strncmp(header.magic_bytes, "SKye", 4) ) {
00057 fseek(fin, 0, SEEK_SET);
00058 format = 0;
00059 } else {
00060 format = header.revision;
00061 }
00062
00063 if(format == 0)
00064 {
00065 do {
00066 map_insert();
00067 ii++;
00068 } while( load_dckye_level(fin, current_map_num));
00069 map_delete();
00070 set_current_map(ii-1);
00071 } else if(format == 1) {
00072 do {
00073 map_insert();
00074 ii++;
00075 } while( load_skye_level_r1(fin, current_map_num));
00076 map_delete();
00077 set_current_map(ii-1);
00078 } else if(format == 2) {
00079 for(ii=0; ii<header.num_levels; ii++) {
00080 fseek(fin, sizeof(header)+ii*sizeof(short), SEEK_SET);
00081 fread(&offset, sizeof(short), 1, fin);
00082 fseek(fin, offset, SEEK_SET);
00083 map_insert();
00084 load_skye_level_r2(fin, current_map_num);
00085 }
00086 }
00087
00088 fclose(fin);
00089 }
00090
00091
00092 void map_insert(void)
00093 {
00094 int ii;
00095 editor_map added_map;
00096 set_num_maps(num_maps+1);
00097 added_map = maps[num_maps-1];
00098 for(ii=num_maps-1; ii>current_map_num; ii--)
00099 maps[ii] = maps[ii-1];
00100 maps[current_map_num+1] = added_map;
00101 set_current_map(current_map_num+1);
00102 default_map();
00103 }
00104
00105
00106 void map_delete(void)
00107 {
00108 int ii;
00109 if(num_maps==1) {
00110 draw_current_map();
00111 show_dialog("You cannot delete the last map!", 25, 25, 75, 30);
00112 return;
00113 }
00114 cleanup_map(&maps[current_map_num]);
00115 for(ii=current_map_num; ii<num_maps-1; ii++)
00116 maps[ii] = maps[ii+1];
00117 maps[num_maps-1].t = NULL;
00118
00119 set_num_maps(num_maps-1);
00120 draw_current_map();
00121 }
00122
00123
00124 void map_move_up(void)
00125 {
00126 editor_map temp;
00127
00128 if(current_map_num == 0) return;
00129
00130 temp = maps[current_map_num];
00131 maps[current_map_num] = maps[current_map_num-1];
00132 maps[current_map_num-1] = temp;
00133 set_current_map(current_map_num-1);
00134 }
00135
00136
00137 void map_move_down(void)
00138 {
00139 editor_map temp;
00140
00141 if(current_map_num+1 >= num_maps) return;
00142
00143 temp = maps[current_map_num];
00144 maps[current_map_num] = maps[current_map_num+1];
00145 maps[current_map_num+1] = temp;
00146 set_current_map(current_map_num+1);
00147 }
00148
00149