Index: edit.c ================================================================== --- edit.c +++ edit.c @@ -563,10 +563,12 @@ exit(0); break; } } } + +static int string_list(void); static Value ask_value(const char*s) { int i; s=screen_prompt(s); if(!s || !*s) return UVALUE(0,4); @@ -649,19 +651,24 @@ } } draw_text(0,64,"Str:",0xF0,0xF7); snprintf(buf,255,"%d",nlevelstrings); draw_text(64,64,buf,0xF0,0xF7); + draw_text(0,80,"<1-3> Misc <4-6> Misc=String Dir",0xF0,0xF3); + draw_text(0,88," Help EditorHelp Exit",0xF0,0xF3); SDL_UnlockSurface(screen); SDL_Flip(screen); while(SDL_WaitEvent(&ev)) switch(ev.type) { case SDL_KEYDOWN: switch(ev.key.keysym.sym) { case SDLK_RETURN: case SDLK_KP_ENTER: case SDLK_ESCAPE: return; case SDLK_1: v=ask_value("Misc1:"); if(v.t<4) m->misc1=v; break; case SDLK_2: v=ask_value("Misc2:"); if(v.t<4) m->misc2=v; break; case SDLK_3: v=ask_value("Misc3:"); if(v.t<4) m->misc3=v; break; + case SDLK_4: case SDLK_q: j=string_list(); if(j!=-1) m->misc1=UVALUE(j,TY_LEVELSTRING); break; + case SDLK_5: case SDLK_w: j=string_list(); if(j!=-1) m->misc2=UVALUE(j,TY_LEVELSTRING); break; + case SDLK_6: case SDLK_e: j=string_list(); if(j!=-1) m->misc3=UVALUE(j,TY_LEVELSTRING); break; case SDLK_KP1: m->dir=5; break; case SDLK_KP2: m->dir=6; break; case SDLK_KP3: m->dir=7; break; case SDLK_KP4: m->dir=4; break; case SDLK_KP6: m->dir=0; break; @@ -1261,10 +1268,32 @@ *cp=31; cp[1]=i; c++; goto redraw; } + +static inline void replace_level_string_uses(int x) { + Uint32 n; + Object*o; + for(n=0;nmisc1.t==TY_LEVELSTRING && o->misc1.u>=x) --o->misc1.u; + if(o->misc2.t==TY_LEVELSTRING && o->misc2.u>=x) --o->misc2.u; + if(o->misc3.t==TY_LEVELSTRING && o->misc3.u>=x) --o->misc3.u; + } +} + +static inline int count_level_string_uses(int x) { + int c=0; + Uint32 n; + Object*o; + for(n=0;nmisc1.t==TY_LEVELSTRING && o->misc1.u==x) c++; + if(o->misc2.t==TY_LEVELSTRING && o->misc2.u==x) c++; + if(o->misc3.t==TY_LEVELSTRING && o->misc3.u==x) c++; + } + return c; +} static int string_list(void) { char buf[18]; SDL_Event ev; SDL_Rect r; @@ -1280,11 +1309,11 @@ SDL_FillRect(screen,&r,0xF1); r.y=8; r.h=screen->h-8; scrollbar(&scroll,screen->h/8-1,nlevelstrings,0,&r); SDL_LockSurface(screen); - draw_text(0,0,"Level Strings: Add Delete Edit Pick Preview Cancel",0xF1,0xFF); + draw_text(0,0,"Level Strings: Add Delete Edit Pick Preview Uses Cancel",0xF1,0xFF); for(i=0;ih/8-1;i++) { j=i+scroll; if(j>=nlevelstrings) break; snprintf(buf,8,"%c%5d%c",n==j?'<':' ',j,n==j?'>':' '); draw_text(16,(i+1)<<3,buf,0xF0,0xFB); @@ -1326,14 +1355,23 @@ case SDLK_DELETE: if(n>=nlevelstrings) break; if(n==nlevelstrings-1) { free(levelstrings[--nlevelstrings]); } else { - //TODO + replace_level_string_uses(n+1); + free(levelstrings[n]); + --nlevelstrings; + for(i=n;i=nlevelstrings) n=nlevelstrings-1; goto redraw;