933 { |
933 { |
934 DeleteWindowById(WC_GAME_OPTIONS, 0); |
934 DeleteWindowById(WC_GAME_OPTIONS, 0); |
935 AllocateWindowDesc(&_patches_selection_desc); |
935 AllocateWindowDesc(&_patches_selection_desc); |
936 } |
936 } |
937 |
937 |
938 |
|
939 |
|
940 struct GRFFile *_sel_grffile; |
938 struct GRFFile *_sel_grffile; |
941 |
939 |
|
940 enum { |
|
941 NEwGRF_WND_PROC_OFFSET_TOP_WIDGET = 14, |
|
942 NEWGRF_WND_PROC_ROWSIZE = 14 |
|
943 }; |
|
944 |
942 static void NewgrfWndProc(Window *w, WindowEvent *e) |
945 static void NewgrfWndProc(Window *w, WindowEvent *e) |
943 { |
946 { |
944 uint i=0; |
947 switch (e->event) { |
945 switch(e->event) { |
|
946 case WE_PAINT: { |
948 case WE_PAINT: { |
947 int x, y = 15; |
949 int x, y = NEwGRF_WND_PROC_OFFSET_TOP_WIDGET; |
948 struct GRFFile *c=_first_grffile; |
950 uint16 i = 0; |
|
951 struct GRFFile *c = _first_grffile; |
949 |
952 |
950 DrawWindowWidgets(w); |
953 DrawWindowWidgets(w); |
951 |
954 |
952 if(_first_grffile==NULL) { // no grf sets installed |
955 if (_first_grffile == NULL) { // no grf sets installed |
953 DrawStringMultiCenter(140, 240, STR_NEWGRF_NO_FILES_INSTALLED, 250); |
956 DrawStringMultiCenter(140, 240, STR_NEWGRF_NO_FILES_INSTALLED, 250); |
954 break; |
957 break; |
955 } |
958 } |
956 |
959 |
957 // draw list of all grf files |
960 // draw list of all grf files |
958 while(c!=NULL) { |
961 while (c != NULL) { |
959 if(i>=w->vscroll.pos) { // draw files according to scrollbar position |
962 if (i >= w->vscroll.pos) { // draw files according to scrollbar position |
960 if(_sel_grffile==c) GfxFillRect(2, y-1, 267, y + 12, 10); // show highlighted item with a different background |
963 DrawSprite(SPRITE_PALETTE(0x2EB | 0x30b8000), 5, y + 3); |
961 DrawSprite(SPRITE_PALETTE(0x2EB | 0x30b8000), 5, y+2); |
964 // give highlighted item other colour |
962 DoDrawString(c->filename, 25, y+2, 0x10); // will be grf name later |
965 // XXX - will be grf name later |
963 y+=15; |
966 DoDrawString(c->filename, 25, y + 2, (_sel_grffile == c) ? 0xC : 0x10); |
|
967 y += NEWGRF_WND_PROC_ROWSIZE; |
964 } |
968 } |
965 |
969 |
966 c=c->next; |
970 c = c->next; |
967 if(++i>=12+w->vscroll.pos) break; // stop after displaying 12 items |
971 if (++i == w->vscroll.cap + w->vscroll.pos) break; // stop after displaying 12 items |
968 } |
972 } |
969 |
973 |
970 // DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name |
974 // DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name |
971 |
975 |
972 if(_sel_grffile==NULL) { // no grf file selected yet |
976 if (_sel_grffile == NULL) { // no grf file selected yet |
973 DrawStringMultiCenter(140, 240, STR_NEWGRF_TIP, 250); |
977 DrawStringMultiCenter(140, 229, STR_NEWGRF_TIP, 250); |
974 } else { |
978 } else { |
975 // draw filename |
979 // draw filename |
976 x = DrawString(5, 210, STR_NEWGRF_FILENAME, 0); |
980 x = DrawString(5, 199, STR_NEWGRF_FILENAME, 0); |
977 DoDrawString(_sel_grffile->filename, x+2, 210, 0x01); |
981 DoDrawString(_sel_grffile->filename, x + 2, 199, 0x01); |
978 |
982 |
979 // draw grf id |
983 // draw grf id |
980 x = DrawString(5, 220, STR_NEWGRF_GRF_ID, 0); |
984 x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0); |
981 SET_DPARAM16(0, _sel_grffile->grfid); |
985 SET_DPARAM16(0, _sel_grffile->grfid); |
982 DrawString(x+2, 220, STR_7024, 0x01); |
986 DrawString(x + 2, 209, STR_7024, 0x01); |
983 } |
987 } |
984 |
988 } break; |
985 } break; |
|
986 |
989 |
987 case WE_CLICK: |
990 case WE_CLICK: |
988 switch(e->click.widget) { |
991 switch(e->click.widget) { |
989 case 2: { // select a grf file |
992 case 2: { // select a grf file |
990 int y; |
993 int y = (e->click.pt.y - NEwGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE; |
991 |
994 |
992 y = e->click.pt.y - 16; |
995 if (y >= w->vscroll.cap) { return;} // click out of bounds |
993 if (y < 0) return; |
996 |
994 |
997 y += w->vscroll.pos; |
995 y = (y/15) + w->vscroll.pos; // calc selected item |
998 |
996 if (y >= _grffile_count) return; |
999 if (y >= _grffile_count) return; |
997 |
1000 |
998 _sel_grffile = _first_grffile; |
1001 _sel_grffile = _first_grffile; |
999 while(y) { |
1002 // get selected grf-file |
1000 _sel_grffile = _sel_grffile->next; |
1003 while (y-- != 0) _sel_grffile = _sel_grffile->next; |
1001 y--; |
1004 |
1002 } |
|
1003 SetWindowDirty(w); |
1005 SetWindowDirty(w); |
1004 } break; |
1006 } break; |
1005 case 9: |
1007 case 9: /* Cancel button */ |
1006 DeleteWindowById(WC_GAME_OPTIONS, 0); |
1008 DeleteWindowById(WC_GAME_OPTIONS, 0); |
1007 break; |
1009 break; |
1008 } break; |
1010 } break; |
1009 |
1011 |
1010 /* Parameter edit box not used yet |
1012 /* Parameter edit box not used yet |
1027 } |
1029 } |
1028 |
1030 |
1029 static const Widget _newgrf_widgets[] = { |
1031 static const Widget _newgrf_widgets[] = { |
1030 { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1032 { WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
1031 { WWT_CAPTION, 14, 11, 279, 0, 13, STR_NEWGRF_SETINGS_CAPTION,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
1033 { WWT_CAPTION, 14, 11, 279, 0, 13, STR_NEWGRF_SETINGS_CAPTION,STR_018C_WINDOW_TITLE_DRAG_THIS}, |
1032 { WWT_MATRIX, 14, 0, 268, 14, 193, 0xC01, STR_NEWGRF_TIP}, |
1034 { WWT_MATRIX, 14, 0, 268, 14, 182, 0xC01,/*small rows*/ STR_NEWGRF_TIP}, |
1033 { WWT_PANEL, 14, 0, 279, 194, 332, 0x0, STR_NULL}, |
1035 { WWT_PANEL, 14, 0, 279, 183, 321, 0x0, STR_NULL}, |
1034 |
1036 |
1035 { WWT_SCROLLBAR, 14, 269, 279, 14, 193, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
1037 { WWT_SCROLLBAR, 14, 269, 279, 14, 182, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
1036 |
1038 |
1037 { WWT_CLOSEBOX, 14, 147, 158, 300, 311, STR_0188, STR_NULL}, |
1039 { WWT_CLOSEBOX, 14, 147, 158, 289, 300, STR_0188, STR_NULL}, |
1038 { WWT_CLOSEBOX, 14, 159, 170, 300, 311, STR_0189, STR_NULL}, |
1040 { WWT_CLOSEBOX, 14, 159, 170, 289, 300, STR_0189, STR_NULL}, |
1039 { WWT_CLOSEBOX, 14, 175, 274, 300, 311, STR_NEWGRF_SET_PARAMETERS, STR_NULL}, |
1041 { WWT_CLOSEBOX, 14, 175, 274, 289, 300, STR_NEWGRF_SET_PARAMETERS, STR_NULL}, |
1040 |
1042 |
1041 { WWT_CLOSEBOX, 3, 5, 138, 317, 328, STR_NEWGRF_APPLY_CHANGES, STR_NULL}, |
1043 { WWT_CLOSEBOX, 3, 5, 138, 306, 317, STR_NEWGRF_APPLY_CHANGES, STR_NULL}, |
1042 { WWT_CLOSEBOX, 3, 142, 274, 317, 328, STR_012E_CANCEL, STR_NULL}, |
1044 { WWT_CLOSEBOX, 3, 142, 274, 306, 317, STR_012E_CANCEL, STR_NULL}, |
1043 { WIDGETS_END}, |
1045 { WIDGETS_END}, |
1044 }; |
1046 }; |
1045 |
1047 |
1046 static const WindowDesc _newgrf_desc = { |
1048 static const WindowDesc _newgrf_desc = { |
1047 WDP_CENTER, WDP_CENTER, 280, 333, |
1049 WDP_CENTER, WDP_CENTER, 280, 322, |
1048 WC_GAME_OPTIONS,0, |
1050 WC_GAME_OPTIONS,0, |
1049 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
1051 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
1050 _newgrf_widgets, |
1052 _newgrf_widgets, |
1051 NewgrfWndProc, |
1053 NewgrfWndProc, |
1052 }; |
1054 }; |