settings_gui.c
changeset 5237 c14c97d7030a
parent 5211 651c9272ad22
child 5466 85b7662d0342
child 5623 ef2a8a524a95
equal deleted inserted replaced
5236:e959e132a78e 5237:c14c97d7030a
   914 {
   914 {
   915 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   915 	DeleteWindowById(WC_GAME_OPTIONS, 0);
   916 	AllocateWindowDesc(&_patches_selection_desc);
   916 	AllocateWindowDesc(&_patches_selection_desc);
   917 }
   917 }
   918 
   918 
   919 enum {
       
   920 	NEWGRF_WND_PROC_OFFSET_TOP_WIDGET = 14,
       
   921 	NEWGRF_WND_PROC_ROWSIZE = 14
       
   922 };
       
   923 
       
   924 static void NewgrfWndProc(Window *w, WindowEvent *e)
       
   925 {
       
   926 	static GRFFile *_sel_grffile;
       
   927 	switch (e->event) {
       
   928 	case WE_PAINT: {
       
   929 		int x, y = NEWGRF_WND_PROC_OFFSET_TOP_WIDGET;
       
   930 		uint16 i = 0;
       
   931 		GRFFile *c = _first_grffile;
       
   932 
       
   933 		DrawWindowWidgets(w);
       
   934 
       
   935 		if (_first_grffile == NULL) { // no grf sets installed
       
   936 			DrawStringMultiCenter(140, 210, STR_NEWGRF_NO_FILES_INSTALLED, 250);
       
   937 			break;
       
   938 		}
       
   939 
       
   940 		// draw list of all grf files
       
   941 		while (c != NULL) {
       
   942 			if (i >= w->vscroll.pos) { // draw files according to scrollbar position
       
   943 				bool h = (_sel_grffile == c);
       
   944 				// show highlighted item with a different background and highlighted text
       
   945 				if (h) GfxFillRect(1, y + 1, 267, y + 12, 156);
       
   946 				// XXX - will be grf name later
       
   947 				DoDrawString(c->filename, 25, y + 2, h ? 0xC : 0x10);
       
   948 				DrawSprite(SPRITE_PALETTE(SPR_SQUARE | PALETTE_TO_RED), 5, y + 2);
       
   949 				y += NEWGRF_WND_PROC_ROWSIZE;
       
   950 			}
       
   951 
       
   952 			c = c->next;
       
   953 			if (++i == w->vscroll.cap + w->vscroll.pos) break; // stop after displaying 12 items
       
   954 		}
       
   955 
       
   956 // 		DoDrawString(_sel_grffile->setname, 120, 200, 0x01); // draw grf name
       
   957 
       
   958 		if (_sel_grffile == NULL) { // no grf file selected yet
       
   959 			DrawStringMultiCenter(140, 210, STR_NEWGRF_TIP, 250);
       
   960 		} else {
       
   961 			// draw filename
       
   962 			x = DrawString(5, 199, STR_NEWGRF_FILENAME, 0);
       
   963 			DoDrawString(_sel_grffile->filename, x + 2, 199, 0x01);
       
   964 
       
   965 			// draw grf id
       
   966 			x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0);
       
   967 			snprintf(_userstring, lengthof(_userstring), "%08X", (uint32)BSWAP32(_sel_grffile->grfid));
       
   968 			DrawString(x + 2, 209, STR_SPEC_USERSTRING, 0x01);
       
   969 		}
       
   970 	} break;
       
   971 
       
   972 	case WE_CLICK:
       
   973 		switch (e->we.click.widget) {
       
   974 		case 3: { // select a grf file
       
   975 			int y = (e->we.click.pt.y - NEWGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE;
       
   976 
       
   977 			if (y >= w->vscroll.cap) return; // click out of bounds
       
   978 
       
   979 			y += w->vscroll.pos;
       
   980 
       
   981 			if (y >= w->vscroll.count) return;
       
   982 
       
   983 			_sel_grffile = _first_grffile;
       
   984 			// get selected grf-file
       
   985 			while (y-- != 0) _sel_grffile = _sel_grffile->next;
       
   986 
       
   987 			SetWindowDirty(w);
       
   988 		} break;
       
   989 		case 9: /* Cancel button */
       
   990 			DeleteWindowById(WC_GAME_OPTIONS, 0);
       
   991 			break;
       
   992 		} break;
       
   993 
       
   994 #if 0 /* Parameter edit box not used yet */
       
   995 	case WE_TIMEOUT:
       
   996 		WP(w,def_d).data_2 = 0;
       
   997 		SetWindowDirty(w);
       
   998 		break;
       
   999 
       
  1000 	case WE_ON_EDIT_TEXT: {
       
  1001 		if (*e->edittext.str) {
       
  1002 			SetWindowDirty(w);
       
  1003 		}
       
  1004 		break;
       
  1005 	}
       
  1006 #endif
       
  1007 
       
  1008 	case WE_DESTROY:
       
  1009 		_sel_grffile = NULL;
       
  1010 		DeleteWindowById(WC_QUERY_STRING, 0);
       
  1011 		break;
       
  1012 	}
       
  1013 }
       
  1014 
       
  1015 static const Widget _newgrf_widgets[] = {
       
  1016 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                    STR_018B_CLOSE_WINDOW},
       
  1017 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   279,     0,    13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
       
  1018 {      WWT_PANEL,   RESIZE_NONE,    14,     0,   279,   183,   276, 0x0,                         STR_NULL},
       
  1019 
       
  1020 {     WWT_MATRIX,   RESIZE_NONE,    14,     0,   267,    14,   182, 0xC01, /*small rows*/        STR_NEWGRF_TIP},
       
  1021 {  WWT_SCROLLBAR,   RESIZE_NONE,    14,   268,   279,    14,   182, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST},
       
  1022 
       
  1023 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   147,   158,   244,   255, STR_0188,                    STR_NULL},
       
  1024 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   159,   170,   244,   255, STR_0189,                    STR_NULL},
       
  1025 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   175,   274,   244,   255, STR_NEWGRF_SET_PARAMETERS,   STR_NULL},
       
  1026 
       
  1027 { WWT_PUSHTXTBTN,   RESIZE_NONE,     3,     5,   138,   261,   272, STR_NEWGRF_APPLY_CHANGES,    STR_NULL},
       
  1028 { WWT_PUSHTXTBTN,   RESIZE_NONE,     3,   142,   274,   261,   272, STR_012E_CANCEL,             STR_NULL},
       
  1029 {   WIDGETS_END},
       
  1030 };
       
  1031 
       
  1032 static const WindowDesc _newgrf_desc = {
       
  1033 	WDP_CENTER, WDP_CENTER, 280, 277,
       
  1034 	WC_GAME_OPTIONS,0,
       
  1035 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
       
  1036 	_newgrf_widgets,
       
  1037 	NewgrfWndProc,
       
  1038 };
       
  1039 
       
  1040 void ShowNewgrf(void)
       
  1041 {
       
  1042 	const GRFFile* c;
       
  1043 	Window *w;
       
  1044 	uint count;
       
  1045 
       
  1046 	DeleteWindowById(WC_GAME_OPTIONS, 0);
       
  1047 	w = AllocateWindowDesc(&_newgrf_desc);
       
  1048 
       
  1049 	count = 0;
       
  1050 	for (c = _first_grffile; c != NULL; c = c->next) count++;
       
  1051 
       
  1052 	w->vscroll.cap = 12;
       
  1053 	w->vscroll.count = count;
       
  1054 	w->vscroll.pos = 0;
       
  1055 	DisableWindowWidget(w, 5);  // Small up arrow
       
  1056 	DisableWindowWidget(w, 6);  // Small sown arrow
       
  1057 	DisableWindowWidget(w, 7);  // Set parameter button
       
  1058 }
       
  1059 
   919 
  1060 /**
   920 /**
  1061  * Draw [<][>] boxes.
   921  * Draw [<][>] boxes.
  1062  * @param x the x position to draw
   922  * @param x the x position to draw
  1063  * @param y the y position to draw
   923  * @param y the y position to draw