int DoHelp() { int help_key = 2; int more_key = 2; while (help_key > 1) { help_key = ui_messagebox( -2, -2, 5, MainHelpText, "Ok", "Segment", "Keypad", "View", "More"); if (help_key == 2) ui_messagebox( -2, -2, 1, SegmentHelpText, "Ok" ); if (help_key == 3) ui_messagebox( -2, -2, 1, KeyPadHelpText, "Ok" ); if (help_key == 4) ui_messagebox( -2, -2, 1, ViewHelpText, "Ok" ); if (help_key == 5) { more_key = ui_messagebox( -2, -2, 4, MainHelpText, "Back", "Curve", "Macro", "Game"); if (more_key == 2) ui_messagebox( -2, -2, 1, CurveHelpText, "Ok" ); if (help_key == 3) ui_messagebox( -2, -2, 1, MacrosHelpText, "Ok" ); if (help_key == 4) ui_messagebox( -2, -2, 1, GameHelpText, "Ok" ); } } return 1; }
// ----------------------------------------------------------------------------- static int med_save_situation(char * filename) { auto SaveFile = PHYSFSX_openWriteBuffered(filename); if (!SaveFile) { char ErrorMessage[200]; snprintf(ErrorMessage, sizeof(ErrorMessage), "ERROR: Unable to open %s\n", filename); ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" ); return 1; } // Write mine name. struct splitpath_t path; d_splitpath(filename, &path); PHYSFSX_printf(SaveFile, "%.*s.min\n", DXX_ptrdiff_cast_int(path.base_end - path.base_start), path.base_start); // Write player position. PHYSFSX_printf(SaveFile, "%x %x %x\n",static_cast<unsigned>(ConsoleObject->pos.x),static_cast<unsigned>(ConsoleObject->pos.y),static_cast<unsigned>(ConsoleObject->pos.z)); // Write player orientation. PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.rvec.x),static_cast<unsigned>(ConsoleObject->orient.rvec.y),static_cast<unsigned>(ConsoleObject->orient.rvec.z)); PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.uvec.x),static_cast<unsigned>(ConsoleObject->orient.uvec.y),static_cast<unsigned>(ConsoleObject->orient.uvec.z)); PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",static_cast<unsigned>(ConsoleObject->orient.fvec.x),static_cast<unsigned>(ConsoleObject->orient.fvec.y),static_cast<unsigned>(ConsoleObject->orient.fvec.z)); PHYSFSX_printf(SaveFile, "%i\n", ConsoleObject->segnum); return 1; }
void gamestate_restore_check() { char Message[DIAGNOSTIC_MESSAGE_MAX]; obj_position Save_position; if (gamestate_not_restored) { sprintf( Message, "Do you wish to restore game state?\n"); if (ui_messagebox( -2, -2, 2, Message, "Yes", "No" )==1) { // Save current position Save_position.pos = ConsoleObject->pos; Save_position.orient = ConsoleObject->orient; Save_position.segnum = ConsoleObject->segnum; load_level("GAMESAVE.LVL"); // Restore current position if (Save_position.segnum <= Highest_segment_index) { ConsoleObject->pos = Save_position.pos; ConsoleObject->orient = Save_position.orient; obj_relink(ConsoleObject-Objects,Save_position.segnum); } gamestate_not_restored = 0; Update_flags |= UF_WORLD_CHANGED; } else gamestate_not_restored = 1; } }
int ShowAbout() { ui_messagebox( -2, -2, 1, "INFERNO Mine Editor\n\n" \ "Copyright (c) 1993 Parallax Software Corp.", "OK"); return 0; }
// ----------------------------------------------------------------------------- int med_save_situation(char * filename) { PHYSFS_file * SaveFile; char mine_name[MAX_NAME_LENGTH]; SaveFile = PHYSFSX_openWriteBuffered( filename ); if (!SaveFile) { char ErrorMessage[200]; sprintf( ErrorMessage, "ERROR: Unable to open %s\n", filename ); ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" ); return 1; } // Write mine name. // strcpy(mine_name, filename); d_splitpath(filename, NULL, NULL, mine_name, NULL); set_extension(mine_name, "min"); PHYSFSX_printf(SaveFile, "%s\n", mine_name); // Write player position. PHYSFSX_printf(SaveFile, "%x %x %x\n",(unsigned int) ConsoleObject->pos.x,(unsigned int) ConsoleObject->pos.y,(unsigned int) ConsoleObject->pos.z); // Write player orientation. PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.rvec.x,(unsigned int) ConsoleObject->orient.rvec.y,(unsigned int) ConsoleObject->orient.rvec.z); PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.uvec.x,(unsigned int) ConsoleObject->orient.uvec.y,(unsigned int) ConsoleObject->orient.uvec.z); PHYSFSX_printf(SaveFile, "%8x %8x %8x\n",(unsigned int) ConsoleObject->orient.fvec.x,(unsigned int) ConsoleObject->orient.fvec.y,(unsigned int) ConsoleObject->orient.fvec.z); PHYSFSX_printf(SaveFile, "%i\n", ConsoleObject->segnum); PHYSFS_close( SaveFile); return 1; }
int SaveMine() { char ErrorMessage[200]; sprintf( ErrorMessage, "Save Mine not available in demo version.\n"); ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" ); return 1; }
void med_show_warning(char *s) { grs_canvas *save_canv=grd_curcanv; //gr_pal_fade_in(grd_curscreen->pal); //in case palette is blacked ui_messagebox(-2,-2,1,s,"OK"); gr_set_current_canvas(save_canv); }
int med_save_mine(const char * filename) { char ErrorMessage[256]; auto SaveFile = PHYSFSX_openWriteBuffered(filename); if (!SaveFile) { snprintf(ErrorMessage, sizeof(ErrorMessage), "ERROR: Unable to open %s\n", filename); ui_messagebox( -2, -2, 1, ErrorMessage, "Ok" ); return 1; } save_mine_data(SaveFile); //==================== CLOSE THE FILE ============================= return 0; }
int delete_all_triggers() { char Message[DIAGNOSTIC_MESSAGE_MAX]; int w; sprintf( Message, "Are you sure that triggers are hosed so\n badly that you want them ALL GONE!?\n"); if (ui_messagebox( -2, -2, 2, Message, "YES!", "No" )==1) { for (w=0; w<Num_walls; w++) Walls[w].trigger=-1; Num_triggers=0; return 1; } return 0; }
int delete_all_walls() { char Message[DIAGNOSTIC_MESSAGE_MAX]; int seg, side; sprintf( Message, "Are you sure that walls are hosed so\n badly that you want them ALL GONE!?\n"); if (ui_messagebox( -2, -2, 2, Message, "YES!", "No" )==1) { for (seg=0;seg<=Highest_segment_index;seg++) for (side=0;side<MAX_SIDES_PER_SEGMENT;side++) Segments[seg].sides[side].wall_num = -1; Num_walls=0; Num_triggers=0; return 1; } return 0; }
static int browser_handler(UI_DIALOG *dlg, d_event *event, file_browser *b) { int rval = 0; if (event->type == EVENT_UI_DIALOG_DRAW) { ui_dprintf_at( dlg, 10, 5, "%s", b->message ); ui_dprintf_at( dlg, 20, 32,"N&ame" ); ui_dprintf_at( dlg, 20, 86,"&Files" ); ui_dprintf_at( dlg, 210, 86,"&Dirs" ); ui_dprintf_at( dlg, 20, 60, "%s", b->spaces ); ui_dprintf_at( dlg, 20, 60, "%s", b->view_dir ); return 1; } if (GADGET_PRESSED(b->button2)) { PHYSFS_freeList(b->filename_list); b->filename_list = NULL; PHYSFS_freeList(b->directory_list); b->directory_list = NULL; ui_close_dialog(dlg); return 1; } if (GADGET_PRESSED(b->help_button)) { ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" ); rval = 1; } if (event->type == EVENT_UI_LISTBOX_MOVED) { if ((ui_event_get_gadget(event) == (UI_GADGET *)b->listbox1) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item]) ui_inputbox_set_text(b->user_file, b->filename_list[b->listbox1->current_item]); if ((ui_event_get_gadget(event) == (UI_GADGET *)b->listbox2) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item]) ui_inputbox_set_text(b->user_file, b->directory_list[b->listbox2->current_item]); rval = 1; } if (GADGET_PRESSED(b->button1) || GADGET_PRESSED(b->user_file) || (event->type == EVENT_UI_LISTBOX_SELECTED)) { char *p; if (ui_event_get_gadget(event) == (UI_GADGET *)b->listbox2) strcpy(b->user_file->text, b->directory_list[b->listbox2->current_item]); strncpy(b->filename, b->view_dir, PATH_MAX); p = b->user_file->text; while (!strncmp(p, "..", 2)) // shorten the path manually { char *sep = strrchr(b->filename, '/'); if (sep) *sep = 0; else *b->filename = 0; // look directly in search paths p += 2; if (*p == '/') p++; } if (*b->filename && *p) strncat(b->filename, "/", PATH_MAX - strlen(b->filename)); strncat(b->filename, p, PATH_MAX - strlen(b->filename)); if (!PHYSFS_isDirectory(b->filename)) { PHYSFS_file *TempFile; TempFile = PHYSFS_openRead(b->filename); if (TempFile) { // Looks like a valid filename that already exists! PHYSFS_close(TempFile); ui_close_dialog(dlg); return 1; } // File doesn't exist, but can we create it? TempFile = PHYSFS_openWrite(b->filename); if (TempFile) { // Looks like a valid filename! PHYSFS_close(TempFile); PHYSFS_delete(b->filename); ui_close_dialog(dlg); return 1; } } else { if (b->filename[strlen(b->filename) - 1] == '/') // user typed a separator on the end b->filename[strlen(b->filename) - 1] = 0; strcpy(b->view_dir, b->filename); PHYSFS_freeList(b->filename_list); b->filename_list = file_getfilelist(&b->num_files, b->filespec, b->view_dir); if (!b->filename_list) { PHYSFS_freeList(b->directory_list); b->directory_list = NULL; ui_close_dialog(dlg); return 1; } ui_inputbox_set_text(b->user_file, b->filespec); PHYSFS_freeList(b->directory_list); b->directory_list = file_getdirlist(&b->num_dirs, b->view_dir); if (!b->directory_list) { PHYSFS_freeList(b->filename_list); b->filename_list = NULL; ui_close_dialog(dlg); return 1; } ui_listbox_change(dlg, b->listbox1, b->num_files, b->filename_list); ui_listbox_change(dlg, b->listbox2, b->num_dirs, b->directory_list); //i = TICKER; //while ( TICKER < i+2 ); } rval = 1; } return rval; }
int check_walls() { int w, seg, side, wall_count, trigger_count; int w1; count_wall CountedWalls[MAX_WALLS]; char Message[DIAGNOSTIC_MESSAGE_MAX]; int matcen_num; wall_count = 0; for (seg=0;seg<=Highest_segment_index;seg++) if (Segments[seg].segnum != -1) { // Check fuelcenters matcen_num = Segments[seg].matcen_num; if (matcen_num == 0) if (RobotCenters[0].segnum != seg) { Segments[seg].matcen_num = -1; } if (matcen_num > -1) if (RobotCenters[matcen_num].segnum != seg) { RobotCenters[matcen_num].segnum = seg; } for (side=0;side<MAX_SIDES_PER_SEGMENT;side++) if (Segments[seg].sides[side].wall_num != -1) { CountedWalls[wall_count].wallnum = Segments[seg].sides[side].wall_num; CountedWalls[wall_count].segnum = seg; CountedWalls[wall_count].sidenum = side; wall_count++; } } if (wall_count != Num_walls) { sprintf( Message, "Num_walls is bogus\nDo you wish to correct it?\n"); if (ui_messagebox( -2, -2, 2, Message, "Yes", "No" )==1) { Num_walls = wall_count; editor_status_fmt("Num_walls set to %d\n", Num_walls); } } // Check validity of Walls array. for (w=0; w<Num_walls; w++) { if ((Walls[CountedWalls[w].wallnum].segnum != CountedWalls[w].segnum) || (Walls[CountedWalls[w].wallnum].sidenum != CountedWalls[w].sidenum)) { sprintf( Message, "Unmatched wall detected\nDo you wish to correct it?\n"); if (ui_messagebox( -2, -2, 2, Message, "Yes", "No" )==1) { Walls[CountedWalls[w].wallnum].segnum = CountedWalls[w].segnum; Walls[CountedWalls[w].wallnum].sidenum = CountedWalls[w].sidenum; } } } trigger_count = 0; for (w1=0; w1<wall_count; w1++) { if (Walls[w1].trigger != -1) trigger_count++; } if (trigger_count != Num_triggers) { sprintf( Message, "Num_triggers is bogus\nDo you wish to correct it?\n"); if (ui_messagebox( -2, -2, 2, Message, "Yes", "No" )==1) { Num_triggers = trigger_count; editor_status_fmt("Num_triggers set to %d\n", Num_triggers); } } return 1; }
int ui_get_filename( char * filename, char * Filespec, char * message ) { char ViewDir[PATH_MAX]; char InputText[PATH_MAX]; char *p; PHYSFS_file *TempFile; int NumFiles, NumDirs,i; char **filename_list; char **directory_list; char Spaces[35]; UI_WINDOW *wnd; UI_GADGET_BUTTON *Button1, *Button2, *HelpButton; UI_GADGET_LISTBOX *ListBox1; UI_GADGET_LISTBOX *ListBox2; UI_GADGET_INPUTBOX *UserFile; int new_listboxes; if ((p = strrchr(filename, '/'))) { *p++ = 0; strcpy(ViewDir, filename); strcpy(InputText, p); } else { strcpy(ViewDir, ""); strcpy(InputText, filename); } filename_list = file_getfilelist(&NumFiles, Filespec, ViewDir); directory_list = file_getdirlist(&NumDirs, ViewDir); // Running out of memory may become likely in the future if (!filename_list && !directory_list) return 0; if (!filename_list) { PHYSFS_freeList(directory_list); return 0; } if (!directory_list) { PHYSFS_freeList(filename_list); return 0; } //ui_messagebox( -2,-2, 1,"DEBUG:0", "Ok" ); for (i=0; i<35; i++) Spaces[i] = ' '; Spaces[34] = 0; wnd = ui_open_window( 200, 100, 400, 370, WIN_DIALOG ); ui_wprintf_at( wnd, 10, 5, message ); ui_wprintf_at( wnd, 20, 32,"N&ame" ); UserFile = ui_add_gadget_inputbox( wnd, 60, 30, PATH_MAX, 40, InputText ); ui_wprintf_at( wnd, 20, 86,"&Files" ); ui_wprintf_at( wnd, 210, 86,"&Dirs" ); ListBox1 = ui_add_gadget_listbox(wnd, 20, 110, 125, 200, NumFiles, filename_list); ListBox2 = ui_add_gadget_listbox(wnd, 210, 110, 100, 200, NumDirs, directory_list); Button1 = ui_add_gadget_button( wnd, 20, 330, 60, 25, "Ok", NULL ); Button2 = ui_add_gadget_button( wnd, 100, 330, 60, 25, "Cancel", NULL ); HelpButton = ui_add_gadget_button( wnd, 180, 330, 60, 25, "Help", NULL ); wnd->keyboard_focus_gadget = (UI_GADGET *)UserFile; Button1->hotkey = KEY_CTRLED + KEY_ENTER; Button2->hotkey = KEY_ESC; HelpButton->hotkey = KEY_F1; ListBox1->hotkey = KEY_ALTED + KEY_F; ListBox2->hotkey = KEY_ALTED + KEY_D; UserFile->hotkey = KEY_ALTED + KEY_A; ui_gadget_calc_keys(wnd); ui_wprintf_at( wnd, 20, 60, "%s", Spaces ); ui_wprintf_at( wnd, 20, 60, "%s", ViewDir ); new_listboxes = 0; while( 1 ) { ui_mega_process(); ui_window_do_gadgets(wnd); if ( Button2->pressed ) { PHYSFS_freeList(filename_list); PHYSFS_freeList(directory_list); ui_close_window(wnd); return 0; } if ( HelpButton->pressed ) ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" ); if (ListBox1->moved || new_listboxes) { if (ListBox1->current_item >= 0 ) ui_inputbox_set_text(UserFile, filename_list[ListBox1->current_item]); } if (ListBox2->moved || new_listboxes) { if (ListBox2->current_item >= 0 ) ui_inputbox_set_text(UserFile, directory_list[ListBox2->current_item]); } new_listboxes = 0; if (Button1->pressed || UserFile->pressed || (ListBox1->selected_item > -1 ) || (ListBox2->selected_item > -1 )) { ui_mouse_hide(); if (ListBox2->selected_item > -1 ) strcpy(UserFile->text, directory_list[ListBox2->selected_item]); strncpy(filename, ViewDir, PATH_MAX); p = UserFile->text; while (!strncmp(p, "..", 2)) // shorten the path manually { char *sep = strrchr(filename, '/'); if (sep) *sep = 0; else *filename = 0; // look directly in search paths p += 2; if (*p == '/') p++; } if (*filename && *p) strncat(filename, "/", PATH_MAX - strlen(filename)); strncat(filename, p, PATH_MAX - strlen(filename)); if (!PHYSFS_isDirectory(filename)) { TempFile = PHYSFS_openRead(filename); if (TempFile) { // Looks like a valid filename that already exists! PHYSFS_close(TempFile); break; } // File doesn't exist, but can we create it? TempFile = PHYSFS_openWrite(filename); if (TempFile) { // Looks like a valid filename! PHYSFS_close(TempFile); PHYSFS_delete(filename); break; } } else { if (filename[strlen(filename) - 1] == '/') // user typed a separator on the end filename[strlen(filename) - 1] = 0; strcpy(ViewDir, filename); //mprintf( 0, "----------------------------\n" ); //mprintf( 0, "Full dir: '%s'\n", ViewDir ); PHYSFS_freeList(filename_list); filename_list = file_getfilelist(&NumFiles, Filespec, ViewDir); if (!filename_list) { PHYSFS_freeList(directory_list); return 0; } ui_inputbox_set_text(UserFile, Filespec); PHYSFS_freeList(directory_list); directory_list = file_getdirlist(&NumDirs, ViewDir); if (!directory_list) { PHYSFS_freeList(filename_list); return 0; } ui_listbox_change(wnd, ListBox1, NumFiles, filename_list); ui_listbox_change(wnd, ListBox2, NumDirs, directory_list); new_listboxes = 0; ui_wprintf_at( wnd, 20, 60, "%s", Spaces ); ui_wprintf_at( wnd, 20, 60, "%s", ViewDir ); //i = TICKER; //while ( TICKER < i+2 ); } ui_mouse_show(); } vid_update(); } //key_flush(); ui_close_window(wnd); if (filename_list) PHYSFS_freeList(filename_list); if (directory_list) PHYSFS_freeList(directory_list); return 1; }
void map_save(MAP *map, const char *filename) { int i, j; LDI_MAIN m; LDI_ENTRY *entry; DARNIT_FILE *f; struct LDMZ ldmz; MAP_PROPERTY *stringtable, **st_add, **st_temp; char *stringtable_data, *p; int32_t *ref_data; unsigned long zsize; uint32_t (*layer_header)[8]; uint32_t header[12]; unsigned int stringtable_layerref; header[0]=ldmz.header.magic=LDMZ_MAGIC; header[1]=ldmz.header.version=LDMZ_VERSION; header[6]=ldmz.header.layers=map->map->layers; ldmz.layer=malloc(ldmz.header.layers*sizeof(struct LDMZ_LAYER)); header[8]=ldmz.header.objects=0; /*map->map->objects; nope.jpg*/ header[9]=ldmz.header.objects_zsize=0; ldmz.object=NULL; ldmz.objectz=NULL; ldmz.header.stringtable_size=0; for(st_add=&(map->stringtable), i=0; *st_add; st_add=&((*st_add)->next), i++) ldmz.header.stringtable_size+=strlen((*st_add)->key)+strlen((*st_add)->value)+2; /*So we can later clean out the added elements*/ st_temp=st_add; *st_add=malloc(sizeof(MAP_PROPERTY)); (*st_add)->key=(*st_add)->value=(void *) ((*st_add)->next=NULL); for(st_add=&((*st_add)->next), j=0; j<ldmz.header.layers*2; st_add=&((*st_add)->next), j++ ) { *st_add=malloc(sizeof(MAP_PROPERTY)); (*st_add)->next=NULL; if(j&1) { (*st_add)->key=(*st_add)->value=NULL; } else { (*st_add)->key="NAME"; (*st_add)->value="layer"; ldmz.header.stringtable_size+=strlen((*st_add)->key)+strlen((*st_add)->value)+2; } } stringtable_data=malloc(header[2]=ldmz.header.stringtable_size); stringtable_layerref=i+1; header[10]=ldmz.header.refs=i+1+ldmz.header.layers*2; header[4]=ldmz.header.refs_size=sizeof(int32_t)*ldmz.header.refs*2; header[11]=ldmz.header.main_ref_index=0; ref_data=malloc(ldmz.header.refs_size); for(stringtable=map->stringtable, i=0, p=stringtable_data; stringtable; stringtable=stringtable->next) { unsigned int size; if(!stringtable->key) { ref_data[i++]=-1; ref_data[i++]=-1; continue; } strcpy(p, stringtable->key); size=strlen(stringtable->key)+1; ref_data[i++]=d_util_htonl(p-stringtable_data); p+=size; strcpy(p, stringtable->value); size=strlen(stringtable->value)+1; ref_data[i++]=d_util_htonl(p-stringtable_data); p+=size; } ldmz.stringtablez=malloc(zsize=compressBound(ldmz.header.stringtable_size)); compress(ldmz.stringtablez, &zsize, (void *) stringtable_data, ldmz.header.stringtable_size); header[3]=ldmz.header.stringtable_zsize=zsize; free(stringtable_data); ldmz.refsz=malloc(zsize=compressBound(ldmz.header.refs_size)); compress(ldmz.refsz, &zsize, (void *) ref_data, ldmz.header.refs_size); header[5]=ldmz.header.refs_zsize=zsize; free(ref_data); layer_header=malloc(sizeof(uint32_t)*8*ldmz.header.layers); for(i=0; i<map->map->layers; i++) { unsigned int size; unsigned int *data; layer_header[i][0]=d_util_htonl(ldmz.layer[i].width=map->map->layer[i].tilemap->w); layer_header[i][1]=d_util_htonl(ldmz.layer[i].height=map->map->layer[i].tilemap->h); layer_header[i][2]=d_util_htonl(ldmz.layer[i].offset_x=map->map->layer[i].offset_x); layer_header[i][3]=d_util_htonl(ldmz.layer[i].offset_y=map->map->layer[i].offset_y); layer_header[i][5]=d_util_htonl(ldmz.layer[i].ref_index=stringtable_layerref+i*2); layer_header[i][6]=d_util_htonl(ldmz.layer[i].tile_w=map->map->layer[i].tile_w); layer_header[i][7]=d_util_htonl(ldmz.layer[i].tile_h=map->map->layer[i].tile_h); size=sizeof(uint32_t)*map->map->layer[i].tilemap->w*map->map->layer[i].tilemap->h; ldmz.layer[i].dataz=malloc(zsize=compressBound(size)); data=malloc(size); memcpy(data, map->map->layer[i].tilemap->data, size); d_util_endian_convert(data, size/sizeof(uint32_t)); compress((void *) ldmz.layer[i].dataz, &zsize, (void *) data, size); free(data); layer_header[i][4]=d_util_htonl(ldmz.layer[i].zsize=((unsigned int) zsize)); } ldmz.layer_headerz=malloc(zsize=compressBound(sizeof(uint32_t)*8*ldmz.header.layers)); compress((void *) ldmz.layer_headerz, &zsize, (void *) layer_header, sizeof(uint32_t)*8*ldmz.header.layers); header[7]=ldmz.header.layer_headers_zsize=zsize; free(layer_header); if(!(f=d_file_open(filename, "wb"))) { ui_messagebox(font_std, "Unable to save map"); goto map_save_error; } m.magic=d_util_htonl(LDI_MAGIC); m.version=d_util_htonl(LDI_VERSION); m.files=d_util_htonl(2); d_file_write(&m.magic, sizeof(uint32_t), f); d_file_write(&m.version, sizeof(uint32_t), f); d_file_write(&m.files, sizeof(uint32_t), f); m.files=d_util_ntohl(m.files); entry=calloc(sizeof(LDI_ENTRY), m.files); strcpy(entry[0].name, "mapdata/map.ldmz"); entry[0].len=sizeof(uint32_t)*12+ldmz.header.stringtable_zsize+ldmz.header.refs_zsize+ldmz.header.layer_headers_zsize; for(i=0; i<ldmz.header.layers; i++) entry[0].len+=ldmz.layer[i].zsize; entry[0].len=d_util_htonl(entry[0].len); strcpy(entry[1].name, "mapdata/default.png"); entry[1].pos=entry[0].len; entry[1].len=d_util_htonl(map->tilesheet_size); for(i=0; i<m.files; i++) { d_file_write(entry[i].name, LDI_FILENAME_LEN, f); d_file_write(&entry[i].pos, sizeof(uint32_t), f); d_file_write(&entry[i].len, sizeof(uint32_t), f); d_file_write(&entry[i].pad, sizeof(uint32_t), f); } free(entry); d_util_endian_convert(header, 12); d_file_write(&header, sizeof(uint32_t)*12, f); d_file_write(ldmz.stringtablez, ldmz.header.stringtable_zsize, f); d_file_write(ldmz.refsz, ldmz.header.refs_zsize, f); d_file_write(ldmz.layer_headerz, ldmz.header.layer_headers_zsize, f); for(i=0; i<ldmz.header.layers; i++) d_file_write(ldmz.layer[i].dataz, ldmz.layer[i].zsize, f); d_file_write(map->tilesheet, map->tilesheet_size, f); map_save_error: d_file_close(f); free(ldmz.stringtablez); free(ldmz.refsz); free(ldmz.layer_headerz); for(i=0; i<ldmz.header.layers; i++) free(ldmz.layer[i].dataz); free(ldmz.layer); while(*st_temp) { stringtable=(*st_temp)->next; free(*st_temp); *st_temp=stringtable; } }
static window_event_result browser_handler(UI_DIALOG *const dlg, const d_event &event, ui_file_browser *const b) { window_event_result rval = window_event_result::ignored; if (event.type == EVENT_UI_DIALOG_DRAW) { ui_dputs_at( dlg, 10, 5, b->message ); ui_dprintf_at( dlg, 20, 32,"N&ame" ); ui_dprintf_at( dlg, 20, 86,"&Files" ); ui_dprintf_at( dlg, 210, 86,"&Dirs" ); ui_dputs_at(dlg, 20, 60, b->spaces.data()); ui_dputs_at( dlg, 20, 60, b->view_dir ); return window_event_result::handled; } if (GADGET_PRESSED(b->button2.get())) { b->filename_list.reset(); b->directory_list.reset(); return window_event_result::close; } if (GADGET_PRESSED(b->help_button.get())) { ui_messagebox( -1, -1, 1, "Sorry, no help is available!", "Ok" ); rval = window_event_result::handled; } if (event.type == EVENT_UI_LISTBOX_MOVED) { if ((ui_event_get_gadget(event) == b->listbox1.get()) && (b->listbox1->current_item >= 0) && b->filename_list[b->listbox1->current_item]) ui_inputbox_set_text(b->user_file.get(), b->filename_list[b->listbox1->current_item]); if ((ui_event_get_gadget(event) == b->listbox2.get()) && (b->listbox2->current_item >= 0) && b->directory_list[b->listbox2->current_item]) ui_inputbox_set_text(b->user_file.get(), b->directory_list[b->listbox2->current_item]); rval = window_event_result::handled; } if (GADGET_PRESSED(b->button1.get()) || GADGET_PRESSED(b->user_file.get()) || event.type == EVENT_UI_LISTBOX_SELECTED) { char *p; if (ui_event_get_gadget(event) == b->listbox2.get()) strcpy(b->user_file->text.get(), b->directory_list[b->listbox2->current_item]); strncpy(b->filename, b->view_dir, PATH_MAX); p = b->user_file->text.get(); while (!strncmp(p, "..", 2)) // shorten the path manually { char *sep = strrchr(b->filename, '/'); if (sep) *sep = 0; else *b->filename = 0; // look directly in search paths p += 2; if (*p == '/') p++; } if (*b->filename && *p) strncat(b->filename, "/", PATH_MAX - strlen(b->filename)); strncat(b->filename, p, PATH_MAX - strlen(b->filename)); if (!PHYSFS_isDirectory(b->filename)) { if (RAIIPHYSFS_File{PHYSFS_openRead(b->filename)}) { // Looks like a valid filename that already exists! return window_event_result::close; } // File doesn't exist, but can we create it? if (RAIIPHYSFS_File TempFile{PHYSFS_openWrite(b->filename)}) { TempFile.reset(); // Looks like a valid filename! PHYSFS_delete(b->filename); return window_event_result::close; } } else { if (b->filename[strlen(b->filename) - 1] == '/') // user typed a separator on the end b->filename[strlen(b->filename) - 1] = 0; strcpy(b->view_dir, b->filename); b->filename_list = file_getfilelist(b->filespec, b->view_dir); if (!b->filename_list) { b->directory_list.reset(); return window_event_result::close; } ui_inputbox_set_text(b->user_file.get(), b->filespec); b->directory_list = file_getdirlist(b->view_dir); if (!b->directory_list) { b->filename_list.reset(); return window_event_result::close; } ui_listbox_change(dlg, b->listbox1.get(), b->filename_list.get_count(), b->filename_list.get()); ui_listbox_change(dlg, b->listbox2.get(), b->directory_list.get_count(), b->directory_list.get()); //i = TICKER; //while ( TICKER < i+2 ); } rval = window_event_result::handled; } return rval; }