Free Hero Mesh

Check-in [5c59b19d96]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement divisions of levels in the list of levels menu in the game (only for puzzle sets that have any divisions).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5c59b19d96979670eba295f2eceee02d22393347
User & Date: user on 2022-01-07 05:46:52
Other Links: manifest | tags
Context
2022-01-08
06:06
Flush output in SQL command line mode. check-in: 70ae21443d user: user tags: trunk
2022-01-07
05:46
Implement divisions of levels in the list of levels menu in the game (only for puzzle sets that have any divisions). check-in: 5c59b19d96 user: user tags: trunk
2022-01-05
03:59
Set the correct name of the DIVISION.IDX lump when creating it. check-in: 1d52f98ea2 user: user tags: trunk
Changes

Modified TODO from [e85d57e738] to [c921c09e17].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
12
13
14
15
16
17
18


19
20
21
22
23
24
25







-
-







  * "Goto message" instruction (?)
  * Returning a class from COLLIDE/COLLIDEBY to transform
  * Coordinate input (may be suitable for some kind of games)
  * Possibility to define auto-generation levels mode
* Editor
  * Mouse dragging
  * Level index editor
* Table of contents for levels (partially implemented)
  * Can be divisions by sections
* Deal better with allowing to skip past corrupted levels
* Picture editor/loading
  * Allowing more altimages
  * Batch insert multiple dependent image lumps
* Puzzle set catalog format (using with internet; a separate program)
* Inventory/replay hybrid view
* Bookmarks

Modified config.doc from [834613bb18] to [c3ec9417be].

65
66
67
68
69
70
71
72


73
74
75
76
77
78
79
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80







-
+
+







.listColumns
  Number of columns in the wide mode of the list of levels. If zero or not
  specified, determines automatically by the screen width.

.listMode
  Mode for list of levels, in hexadecimal, where bit0 is set for tall mode
  or clear for wide mode, and bit1 is set for listing the ID numbers or
  clear for listing the order numbers.
  clear for listing the order numbers, and bit2 is set to display the list
  of divisions initially, instead of the list of levels.

.margin
  The X coordinate of the left margin. To the left is the status area, and
  to the right of the margin is the playfield. This should be at least 64,
  or the picture size, whichever is greater.

.maxTrigger

Modified game.c from [2c724763e6] to [e517a0c994].

779
780
781
782
783
784
785

786
787
788
789
790
791
792
793
794


795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812




813


814
815









816
817
818
819
820

821
822
823
824
825
826
827
828



829

830
831















































832
833
834
835
836
837
838
839

840
841
842

843
844
845
846
847
848
849
850

851
852
853
854
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
890
891

892
893
894
895
896
897
898
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794

795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844

845
846
847
848
849


850
851
852
853
854
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
890
891
892
893
894
895
896
897
898
899
900
901
902
903

904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937


938
939
940
941
942
943
944

945
946
947
948
949
950
951
952
953
954
955
956
957
958
959

960
961
962
963
964
965
966
967







+








-
+
+


















+
+
+
+
-
+
+


+
+
+
+
+
+
+
+
+





+







-
+
+
+

+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+



+








+




















-
-
+
+





-
+



+







+


-
+







  draw_text(a*8+x,y,buf,bg,co);
}

static int list_levels(void) {
  static Sint8 mo=-1;
  static Uint8 columns=0;
  static int scroll=0;
  static Uint16 divmin,divmax; // 1 less than level order number
  sqlite3_stmt*st;
  SDL_Event ev;
  SDL_Rect r;
  const char*v;
  int scrmax=0;
  int sel=level_ord-1;
  int b,i,j,x,y;
  char buf[256];
  char rescroll=1;
  char rescroll=2;
  Uint16 ndiv;
  if(mo<0) {
    optionquery[1]=Q_listMode;
    v=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"";
    mo=strtol(v,0,16);
    if(mo<0) mo=0;
  }
  if(!columns) {
    optionquery[1]=Q_listColumns;
    v=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"";
    i=strtol(v,0,10);
    j=(screen->w-16)/070;
    if(i<1) i=j;
    if(i>j) i=j;
    if(i>255) i=255;
    columns=i;
  }
  if(!ll_head) ll_head="\xB3W \xB3H \xB3 TITLE";
  // ID, ORD, CODE, WIDTH, HEIGHT, TITLE, SOLVED, SOLVABLE, ...
  prepare:
  if(sqlite3_prepare_v2(userdb,mo&4
   ?"WITH D(F,L,H,R) AS (SELECT `FIRST`, LEAD(`FIRST`,1,MAX_LEVEL()+1) OVER (ORDER BY `FIRST`,_ROWID_), `HEADING`, _ROWID_ FROM `DIVISIONS`)"
    " SELECT F, L, H, PRINTF('(%d/%d)',(SELECT COUNT() FROM `LEVELS` WHERE `ORD` >= F AND `ORD` < L AND `SOLVED`),L-F) FROM D WHERE F <> L ORDER BY F, R;"
  if(sqlite3_prepare_v2(userdb,"SELECT * FROM `LEVELS` WHERE `ORD` NOT NULL AND `ORD` >= ?1 ORDER BY `ORD`;",-1,&st,0)) {
   :"SELECT * FROM `LEVELS` WHERE `ORD` NOT NULL AND `ORD` >= ?1 AND `ORD` < ?2 ORDER BY `ORD`;"
   ,-1,&st,0)) {
    screen_message(sqlite3_errmsg(userdb));
    return 0;
  }
  if(mo&4) {
    ndiv=0;
    while(sqlite3_step(st)==SQLITE_ROW) ndiv++;
    if(!ndiv) {
      mo&=3;
      sqlite3_finalize(st);
      goto prepare;
    }
  }
  set_cursor(XC_arrow);
  redraw:
  if(sel<0) sel=0;
  if(sel>=level_nindex) sel=level_nindex-1;
  if((mo&8) && sel>=divmax-divmin) sel=divmax-divmin-1;
  SDL_FillRect(screen,0,0x02);
  r.x=r.y=0;
  r.w=screen->w;
  r.h=24;
  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);
  draw_text(0,8,"<F1> Wide/Tall  <F2> ID/Ord  <F3> Divisions  <F4> All",0xF7,0xF0);
  if(mo&8) draw_text(0,16,"\x15",0xF7,0xF0);
  reset:
  sqlite3_reset(st);
  sqlite3_bind_int(st,2,mo&8?divmax:level_nindex+1);
  if(mo&1) {
    scrmax=level_nindex;
  if(mo&4) {
    scrmax=ndiv;
    for(i=0;i<scroll;i++) if(sqlite3_step(st)!=SQLITE_ROW) sqlite3_reset(st),scroll=i-1;
    for(j=0,y=24;y<screen->h-7;y+=8,j++) {
      i=sqlite3_step(st);
      if(i!=SQLITE_ROW) break;
      if(rescroll==2 && sel>=sqlite3_column_int(st,0) && sel<sqlite3_column_int(st,1)) {
        found:
        sel=j;
        rescroll=1;
        goto reset;
      }
      if(j==sel) {
        divmin=sqlite3_column_int(st,0);
        divmax=sqlite3_column_int(st,1);
        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);
        snprintf(buf,100,"#%d  (%d - %d)",sel+1,divmin,divmax-1);
        draw_text(80,16,buf,0xF7,0xFE);
      } else {
        draw_text(2*8,y,"\xB3",b=0x02,0xF8);
      }
      if(v=sqlite3_column_text(st,2)) {
        x=sqlite3_column_bytes(st,2);
        draw_text(4*8,y,v,b,0xFF);
        if(v=sqlite3_column_text(st,3)) draw_text((x+5)*8,y,v,b,0xFB);
      }
    }
    if(rescroll) {
      if(rescroll==2 && i==SQLITE_ROW) {
        while((i=sqlite3_step(st))==SQLITE_ROW) {
          j++;
          if(sel>=sqlite3_column_int(st,0) && sel<sqlite3_column_int(st,1)) goto found;
        }
      }
      if(sel<scroll) scroll=sel;
      if(sel>=scroll+screen->h/8-3) scroll=sel+4-screen->h/8;
      rescroll=0;
    }
    if(y<screen->h-7 && sel>=j) {
      sel=j-1;
      goto reset;
    }
  } else if(mo&1) {
    scrmax=mo&8?(divmax-divmin):level_nindex;
    draw_text(16+060,16,ll_head,0xF7,0xF1);
    draw_text(16,16,mo&2?"\xB3 ID  ":"\xB3 ORD ",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);
    sqlite3_bind_int(st,1,scroll+(mo&8?divmin:1));
    for(y=24;y<screen->h-7;y+=8) {
      if(sqlite3_step(st)!=SQLITE_ROW) break;
      i=sqlite3_column_int(st,1);
      if(mo&8) i-=divmin-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);
      }
      if(mo&8) i+=divmin-1;
      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);
      if(ll_ndisp) {
        x=9*8;
        for(i=0;i<ll_ndisp && x<screen->w;i++) {
          levels_column(x,y,i,b,st,buf);
          x+=ll_disp[i].width*8+8;
          if(x<screen->w && !(ll_disp[i].flag&1)) draw_text(x-8,y,"\xB3",b,b^0xFA);
        }
      } else {
        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);
    scrmax=((mo&8?divmax-divmin:level_nindex)+columns-1)/columns;
    draw_text(8,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;
      rescroll=0;
    }
    sqlite3_bind_int(st,1,scroll*columns+1);
    sqlite3_bind_int(st,1,scroll*columns+(mo&8?divmin:1));
    for(y=24;y<screen->h-7;y+=8) for(x=0;x<columns;x++) {
      if(sqlite3_step(st)!=SQLITE_ROW) goto done;
      i=sqlite3_column_int(st,1);
      if(mo&8) i-=divmin-1;
      if(i-1==sel) {
        draw_text(x*070+16,y,"\x10",b=0xF8,0xFE);
        snprintf(buf,128,"[ ID=%u Ord=%u Code=%u Size=%ux%u ]",sqlite3_column_int(st,0),i,sqlite3_column_int(st,2),sqlite3_column_int(st,3),sqlite3_column_int(st,4));
        draw_text(80,16,buf,0xF7,0xFE);
      } else {
        draw_text(x*070+16,y," ",b=0x02,0x02);
      }
      if(mo&8) i+=divmin-1;
      snprintf(buf,7,"%5u ",mo&2?sqlite3_column_int(st,0):i);
      draw_text(x*070+24,y,buf,b,sqlite3_column_int(st,6)?0xFA:0xFC);
      if(!sqlite3_column_int(st,7)) draw_text(x*070+64,y,"\a",b,i-1==sel?0xF1:0xF9);
      if(!sqlite3_column_int(st,7)) draw_text(x*070+64,y,"\a",b,b==0xF8?0xF1:0xF9);
    }
  }
  done:
  SDL_UnlockSurface(screen);
  r.x=r.w=0; r.y=24; r.h=screen->h-24;
  scrollbar(&scroll,screen->h/8-3,scrmax,0,&r);
  SDL_Flip(screen);
906
907
908
909
910
911
912




















913

914
915
916
917
918
919
920
921

922
923
924
925
926
927
928
929
930
931
932
933
934
935

936
937
938

939
940
941
942
943
944
945
946
947
948


949
950
951
952


953
954
955
956

957
958








959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978

979
980
981
982
983
984
985
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028

1029
1030
1031
1032
1033
1034
1035
1036
1037


1038
1039
1040
1041


1042
1043
1044
1045
1046

1047
1048

1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075

1076
1077
1078
1079
1080
1081
1082
1083







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+








+













-
+


-
+








-
-
+
+


-
-
+
+



-
+

-
+
+
+
+
+
+
+
+



















-
+







      case SDL_KEYDOWN:
        if((ev.key.keysym.mod&KMOD_NUM) && ev.key.keysym.sym>=SDLK_KP0 && ev.key.keysym.sym<=SDLK_KP9) goto digit;
        switch(ev.key.keysym.sym) {
          case SDLK_ESCAPE: i=0; goto final;
          //TODO: Change the scroll to approximately the middle, instead of zero
          case SDLK_F1: scroll=0; mo^=1; rescroll=1; goto redraw;
          case SDLK_F2: mo^=2; goto redraw;
          case SDLK_F3:
            mo&=~8;
            if(mo&4) break;
            mo|=4;
            rescroll=2;
            sqlite3_finalize(st);
            goto prepare;
          case SDLK_F4:
            if(mo&8) {
              sel+=divmin-1;
              divmin=0;
            }
            if(mo&4) {
              sqlite3_finalize(st);
              mo&=3;
              sel=level_ord-1;
              goto prepare;
            }
            mo&=3;
            goto redraw;
          case SDLK_SPACE: title:
            if(mo&4) break;
            sqlite3_reset(st);
            sqlite3_bind_int(st,1,sel+1);
            if(sqlite3_step(st)==SQLITE_ROW) {
              v=sqlite3_column_text(st,5); // not Unicode, but add the null terminator
              if(v) modal_draw_popup(v);
            }
            goto redraw;
          case SDLK_0 ... SDLK_9: digit:
            if(mo&4) break;
            SDL_PushEvent(&ev);
            if(v=screen_prompt("Find?")) {
              if(!*v) goto redraw;
              i=strtol(v,0,10);
              if(mo&2) {
                for(j=0;j<level_nindex;j++) if(level_index[j]==i) sel=j;
              } else {
                if(i>0 && i<=level_nindex) sel=i-1;
              }
              rescroll=1;
            }
            goto redraw;
          case SDLK_DOWN: case SDLK_KP2: case SDLK_j:
            sel+=mo&1?:columns;
            sel+=mo&5?1:columns;
            rescroll=1; goto redraw;
          case SDLK_UP: case SDLK_KP8: case SDLK_k:
            sel-=mo&1?:columns;
            sel-=mo&5?1:columns;
            rescroll=1; goto redraw;
          case SDLK_LEFT: case SDLK_KP4: case SDLK_h:
            sel--;
            rescroll=1; goto redraw;
          case SDLK_RIGHT: case SDLK_KP6: case SDLK_l:
            sel++;
            rescroll=1; goto redraw;
          case SDLK_PAGEUP: case SDLK_KP9:
            sel-=(screen->h/8-3)*(mo&1?:columns);
            scroll-=(screen->h/8-3)*(mo&1?:columns);
            sel-=(screen->h/8-3)*(mo&5?1:columns);
            scroll-=(screen->h/8-3)*(mo&5?1:columns);
            rescroll=1; goto redraw;
          case SDLK_PAGEDOWN: case SDLK_KP3:
            sel+=(screen->h/8-3)*(mo&1?:columns);
            scroll+=(screen->h/8-3)*(mo&1?:columns);
            sel+=(screen->h/8-3)*(mo&5?1:columns);
            scroll+=(screen->h/8-3)*(mo&5?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;
            sel=mo&8?divmax-divmin-1:level_nindex-1;
            rescroll=1; goto redraw;
          case SDLK_RETURN: case SDLK_KP_ENTER: play: i=1; goto final;
          case SDLK_RETURN: case SDLK_KP_ENTER: play:
            if(mo&4) {
              mo=(mo|8)&~4;
              sel=0;
              sqlite3_finalize(st);
              goto prepare;
            }
            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);
  if(i==1) begin_level(mo&8?-sel-divmin:~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) {

Modified game.doc from [772a7e8517] to [7328cb695b].

112
113
114
115
116
117
118






119
120
121
122
123
124
125
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131







+
+
+
+
+
+







can also push the following:

* F1 = Toggle tall/wide mode. The tall mode lists one level per row, and
shows the columns of the details. The wide mode only displays the level
numbers but more will fit on the screen at once.

* F2 = Toggle displaying order numbers or ID numbers.

* F3 = Display list of divisions of levels. This function is not available
in all puzzle sets. When this function is activated, you can push return
or right mouse button to list only the subset of levels in that division.

* F4 = Cancel the division display, and list all levels.

* Space or middle mouse button = Display title.

* Return or right mouse button = Go to selected level.


=== Summary of default key/mouse bindings ===