695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
int i=sqlite3_column_bytes(st,1);
if(i&~0xFFFF) return;
if(replay_size<i) replay_list=realloc(replay_list,replay_size=i);
if(!replay_list) fatal("Allocation failed");
replay_count=i;
if(i) memcpy(replay_list,sqlite3_column_blob(st,1),i);
}
static int list_levels(void) {
static Sint8 mo=-1;
static Uint8 columns=0;
static int scroll=0;
sqlite3_stmt*st;
SDL_Event ev;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
|
int i=sqlite3_column_bytes(st,1);
if(i&~0xFFFF) return;
if(replay_size<i) replay_list=realloc(replay_list,replay_size=i);
if(!replay_list) fatal("Allocation failed");
replay_count=i;
if(i) memcpy(replay_list,sqlite3_column_blob(st,1),i);
}
static void copy_text_to_plain(unsigned char*out,int maxlen,const unsigned char*in) {
int at=0;
if(!in) {
*out=0;
return;
}
while(*in && at<maxlen) switch(*in) {
case 10: if(at && out[at-1]!=32) out[at++]=32; in++; break;
case 14: case 30: in=strchrnul(in,'\\'); if(*in) in++; break;
case 31: in++; if(*in) out[at++]=*in++; break;
case 32 ... 255: out[at++]=*in++; break;
default: in++;
}
out[at]=0;
}
static int list_levels(void) {
static Sint8 mo=-1;
static Uint8 columns=0;
static int scroll=0;
sqlite3_stmt*st;
SDL_Event ev;
|
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
SDL_FillRect(screen,&r,0xF7);
SDL_LockSurface(screen);
draw_text(0,0,"<LMB/\x18\x19\x1A\x1B> Select <MMB/SP> Title <RMB/RET> Play <0-9> Find <ESC> Cancel",0xF7,0xF0);
draw_text(0,8,"<F1> Wide/Tall <F2> ID/Ord",0xF7,0xF0);
sqlite3_reset(st);
if(mo&1) {
scrmax=level_nindex;
draw_text(16,16,mo&2?"\xB3 ID \xB3":"\xB3 ORD \xB3",0xF7,0xF1);
if(rescroll) {
if(sel<scroll) scroll=sel;
if(sel>=scroll+screen->h/8-3) scroll=sel+4-screen->h/8;
rescroll=0;
}
sqlite3_bind_int(st,1,scroll+1);
for(y=24;y<screen->h-7;y+=8) {
if(sqlite3_step(st)!=SQLITE_ROW) break;
i=sqlite3_column_int(st,1);
if(i-1==sel) {
r.x=16; r.y=y;
r.w=screen->w-16; r.h=8;
SDL_FillRect(screen,&r,0xF8);
draw_text(2*8,y,"\x10",b=0xF8,0xFE);
} else {
draw_text(2*8,y,"\xB3",b=0x02,0xF8);
}
snprintf(buf,6,"%5u",mo&2?sqlite3_column_int(st,0):i);
draw_text(3*8,y,buf,b,sqlite3_column_int(st,6)?0xFA:0xFC);
draw_text(8*8,y,"\xB3",b,b^0xFA);
}
} else {
scrmax=(level_nindex+columns-1)/columns;
draw_text(0,16,mo&2?"(ID)":"(Ord)",0xF7,0xF1);
if(rescroll) {
if(sel<scroll*columns) scroll=sel/columns;
if(sel>(scroll+screen->h/8-3)*columns) scroll=(sel+3-screen->h/8)/columns;
|
|
>
>
>
>
>
>
>
|
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
|
SDL_FillRect(screen,&r,0xF7);
SDL_LockSurface(screen);
draw_text(0,0,"<LMB/\x18\x19\x1A\x1B> Select <MMB/SP> Title <RMB/RET> Play <0-9> Find <ESC> Cancel",0xF7,0xF0);
draw_text(0,8,"<F1> Wide/Tall <F2> ID/Ord",0xF7,0xF0);
sqlite3_reset(st);
if(mo&1) {
scrmax=level_nindex;
draw_text(16,16,"\xB3 ORD \xB3W \xB3H \xB3 TITLE",0xF7,0xF1);
if(mo&2) draw_text(24,16," ID ",0xF7,0xF1);
if(rescroll) {
if(sel<scroll) scroll=sel;
if(sel>=scroll+screen->h/8-3) scroll=sel+4-screen->h/8;
rescroll=0;
}
sqlite3_bind_int(st,1,scroll+1);
for(y=24;y<screen->h-7;y+=8) {
if(sqlite3_step(st)!=SQLITE_ROW) break;
i=sqlite3_column_int(st,1);
if(i-1==sel) {
r.x=16; r.y=y;
r.w=screen->w-16; r.h=8;
SDL_FillRect(screen,&r,0xF8);
draw_text(2*8,y,"\x10",b=0xF8,0xFE);
} else {
draw_text(2*8,y,"\xB3",b=0x02,0xF8);
}
snprintf(buf,6,"%5u",mo&2?sqlite3_column_int(st,0):i);
draw_text(3*8,y,buf,b,sqlite3_column_int(st,6)?0xFA:0xFC);
draw_text(8*8,y,"\xB3",b,b^0xFA);
snprintf(buf,6,"%2u %2u",sqlite3_column_int(st,3),sqlite3_column_int(st,4));
draw_text(9*8,y,buf,b,0xFF);
draw_text(11*8,y,"\xB3",b,b^0xFA);
draw_text(14*8,y,"\xB3",b,b^0xFA);
copy_text_to_plain(buf,255,sqlite3_column_text(st,5));
draw_text(15*8,y,buf,b,0xFF);
}
} else {
scrmax=(level_nindex+columns-1)/columns;
draw_text(0,16,mo&2?"(ID)":"(Ord)",0xF7,0xF1);
if(rescroll) {
if(sel<scroll*columns) scroll=sel/columns;
if(sel>(scroll+screen->h/8-3)*columns) scroll=(sel+3-screen->h/8)/columns;
|
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
|
sel+=(screen->h/8-3)*(mo&1?:columns);
scroll+=(screen->h/8-3)*(mo&1?:columns);
rescroll=1; goto redraw;
case SDLK_HOME: case SDLK_KP7: sel=scroll=0; rescroll=1; goto redraw;
case SDLK_END:
sel=level_nindex-1;
rescroll=1; goto redraw;
case SDLK_RETURN: case SDLK_KP_ENTER: play:
sqlite3_finalize(st);
begin_level(~sel);
return 1;
}
break;
case SDL_MOUSEBUTTONDOWN:
if(ev.button.x>=16 && ev.button.y>=24) {
if(mo&1) i=scroll+ev.button.y/8-3;
else i=(scroll+ev.button.y/8-3)*columns+(ev.button.x-16)/070;
if(i>=0 && i<level_nindex) sel=i;
if(ev.button.button==2) goto title;
if(ev.button.button==3) goto play;
goto redraw;
}
break;
case SDL_VIDEOEXPOSE: goto redraw;
case SDL_QUIT: exit(0); break;
}
}
sqlite3_finalize(st); return -1;
}
static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
switch(cmd) {
case '\' ': // Play a move
if(replay_time) {
replay_time=0;
|
|
<
<
<
>
>
|
>
>
|
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
|
sel+=(screen->h/8-3)*(mo&1?:columns);
scroll+=(screen->h/8-3)*(mo&1?:columns);
rescroll=1; goto redraw;
case SDLK_HOME: case SDLK_KP7: sel=scroll=0; rescroll=1; goto redraw;
case SDLK_END:
sel=level_nindex-1;
rescroll=1; goto redraw;
case SDLK_RETURN: case SDLK_KP_ENTER: play: i=1; goto final;
}
break;
case SDL_MOUSEBUTTONDOWN:
if(ev.button.x>=16 && ev.button.y>=24) {
if(mo&1) i=scroll+ev.button.y/8-3;
else i=(scroll+ev.button.y/8-3)*columns+(ev.button.x-16)/070;
if(i>=0 && i<level_nindex) sel=i;
if(ev.button.button==2) goto title;
if(ev.button.button==3) goto play;
goto redraw;
}
break;
case SDL_VIDEOEXPOSE: goto redraw;
case SDL_QUIT: exit(0); break;
}
}
i=-1;
final:
sqlite3_finalize(st);
if(i==1) begin_level(~sel);
return i;
}
static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
switch(cmd) {
case '\' ': // Play a move
if(replay_time) {
replay_time=0;
|