src/newgrf_gui.cpp
branchcpp_gui
changeset 6258 a2f86b8fd99b
parent 6247 67e881450cf3
child 6263 19dab6a68886
equal deleted inserted replaced
6257:2ffe947969ca 6258:a2f86b8fd99b
    90 	GRFConfig **list;
    90 	GRFConfig **list;
    91 	const GRFConfig *sel;
    91 	const GRFConfig *sel;
    92 } newgrf_add_d;
    92 } newgrf_add_d;
    93 
    93 
    94 
    94 
    95 static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
    95 static void NewGRFAddDlgWndProc(BaseWindow *w, WindowEvent *e)
    96 {
    96 {
    97 	switch (e->event) {
    97 	switch (e->event) {
    98 		case WE_PAINT: {
    98 		case WE_PAINT: {
    99 			const GRFConfig *c;
    99 			const GRFConfig *c;
   100 			int y;
   100 			int y;
   126 				}
   126 				}
   127 				n++;
   127 				n++;
   128 			}
   128 			}
   129 
   129 
   130 			if (WP(w, newgrf_add_d).sel != NULL) {
   130 			if (WP(w, newgrf_add_d).sel != NULL) {
   131 				const Widget *wi = &w->widget[5];
   131 				const OldWidget *wi = &w->widget[5];
   132 				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, false);
   132 				ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, false);
   133 			}
   133 			}
   134 			break;
   134 			break;
   135 		}
   135 		}
   136 
   136 
   185 			break;
   185 			break;
   186 	}
   186 	}
   187 }
   187 }
   188 
   188 
   189 
   189 
   190 static const Widget _newgrf_add_dlg_widgets[] = {
   190 static const OldWidget _newgrf_add_dlg_widgets[] = {
   191 {   WWT_CLOSEBOX,    RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },
   191 {   WWT_CLOSEBOX,    RESIZE_NONE, 14,   0,  10,   0,  13, STR_00C5,                STR_018B_CLOSE_WINDOW },
   192 {    WWT_CAPTION,   RESIZE_RIGHT, 14,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS },
   192 {    WWT_CAPTION,   RESIZE_RIGHT, 14,  11, 306,   0,  13, STR_NEWGRF_ADD_CAPTION,  STR_018C_WINDOW_TITLE_DRAG_THIS },
   193 
   193 
   194 /* List of files */
   194 /* List of files */
   195 {      WWT_PANEL,      RESIZE_RB, 14,   0, 294,  14, 221, 0x0,                     STR_NULL },
   195 {      WWT_PANEL,      RESIZE_RB, 14,   0, 294,  14, 221, 0x0,                     STR_NULL },
   237 	SNGRFS_SET_PARAMETERS,
   237 	SNGRFS_SET_PARAMETERS,
   238 	SNGRFS_APPLY_CHANGES,
   238 	SNGRFS_APPLY_CHANGES,
   239 };
   239 };
   240 
   240 
   241 
   241 
   242 static void SetupNewGRFState(Window *w)
   242 static void SetupNewGRFState(BaseWindow *w)
   243 {
   243 {
   244 	bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
   244 	bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
   245 
   245 
   246 	w->SetWidgetDisabledState(3, !WP(w, newgrf_d).editable);
   246 	w->SetWidgetDisabledState(3, !WP(w, newgrf_d).editable);
   247 	w->SetWidgetsDisabledState(disable_all,
   247 	w->SetWidgetsDisabledState(disable_all,
   258 		if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN);
   258 		if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN);
   259 	}
   259 	}
   260 }
   260 }
   261 
   261 
   262 
   262 
   263 static void SetupNewGRFWindow(Window *w)
   263 static void SetupNewGRFWindow(BaseWindow *w)
   264 {
   264 {
   265 	const GRFConfig *c;
   265 	const GRFConfig *c;
   266 	int i;
   266 	int i;
   267 
   267 
   268 	for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
   268 	for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
   273 }
   273 }
   274 
   274 
   275 
   275 
   276 /** Callback function for the newgrf 'apply changes' confirmation window
   276 /** Callback function for the newgrf 'apply changes' confirmation window
   277  * @param yes_clicked boolean value, true when yes was clicked, false otherwise */
   277  * @param yes_clicked boolean value, true when yes was clicked, false otherwise */
   278 static void NewGRFConfirmationCallback(Window *w, bool confirmed)
   278 static void NewGRFConfirmationCallback(BaseWindow *w, bool confirmed)
   279 {
   279 {
   280 	if (confirmed) {
   280 	if (confirmed) {
   281 		newgrf_d *nd = &WP(w, newgrf_d);
   281 		newgrf_d *nd = &WP(w, newgrf_d);
   282 		GRFConfig *c;
   282 		GRFConfig *c;
   283 		int i = 0;
   283 		int i = 0;
   294 		w->SetDirty();
   294 		w->SetDirty();
   295 	}
   295 	}
   296 }
   296 }
   297 
   297 
   298 
   298 
   299 static void NewGRFWndProc(Window *w, WindowEvent *e)
   299 static void NewGRFWndProc(BaseWindow *w, WindowEvent *e)
   300 {
   300 {
   301 	switch (e->event) {
   301 	switch (e->event) {
   302 		case WE_PAINT: {
   302 		case WE_PAINT: {
   303 			const GRFConfig *c;
   303 			const GRFConfig *c;
   304 			int i, y;
   304 			int i, y;
   333 				}
   333 				}
   334 			}
   334 			}
   335 
   335 
   336 			if (WP(w, newgrf_d).sel != NULL) {
   336 			if (WP(w, newgrf_d).sel != NULL) {
   337 				/* Draw NewGRF file info */
   337 				/* Draw NewGRF file info */
   338 				const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
   338 				const OldWidget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
   339 				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
   339 				ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
   340 			}
   340 			}
   341 
   341 
   342 			break;
   342 			break;
   343 		}
   343 		}
   348 
   348 
   349 		case WE_CLICK:
   349 		case WE_CLICK:
   350 			switch (e->we.click.widget) {
   350 			switch (e->we.click.widget) {
   351 				case SNGRFS_ADD: { /* Add GRF */
   351 				case SNGRFS_ADD: { /* Add GRF */
   352 					GRFConfig **list = WP(w, newgrf_d).list;
   352 					GRFConfig **list = WP(w, newgrf_d).list;
   353 					Window *w;
   353 					BaseWindow *w;
   354 
   354 
   355 					DeleteWindowByClass(WC_SAVELOAD);
   355 					DeleteWindowByClass(WC_SAVELOAD);
   356 					w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
   356 					w = BaseWindow::Allocate(&_newgrf_add_dlg_desc);
   357 					w->resize.step_height = 10;
   357 					w->resize.step_height = 10;
   358 
   358 
   359 					WP(w, newgrf_add_d).list = list;
   359 					WP(w, newgrf_add_d).list = list;
   360 					break;
   360 					break;
   361 				}
   361 				}
   474 			break;
   474 			break;
   475 	}
   475 	}
   476 }
   476 }
   477 
   477 
   478 
   478 
   479 static const Widget _newgrf_widgets[] = {
   479 static const OldWidget _newgrf_widgets[] = {
   480 {   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },
   480 {   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },
   481 {    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },
   481 {    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },
   482 
   482 
   483 /* NewGRF file Add, Remove, Move up, Move down */
   483 /* NewGRF file Add, Remove, Move up, Move down */
   484 {      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },
   484 {      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },
   520  *        changes immediately or only update the list
   520  *        changes immediately or only update the list
   521  * @param config pointer to a linked-list of grfconfig's that will be shown */
   521  * @param config pointer to a linked-list of grfconfig's that will be shown */
   522 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
   522 void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
   523 {
   523 {
   524 	static GRFConfig *local = NULL;
   524 	static GRFConfig *local = NULL;
   525 	Window *w;
   525 	BaseWindow *w;
   526 
   526 
   527 	DeleteWindowByClass(WC_GAME_OPTIONS);
   527 	DeleteWindowByClass(WC_GAME_OPTIONS);
   528 	w = AllocateWindowDesc(&_newgrf_desc);
   528 	w = BaseWindow::Allocate(&_newgrf_desc);
   529 	if (w == NULL) return;
   529 	if (w == NULL) return;
   530 
   530 
   531 	w->resize.step_height = 14;
   531 	w->resize.step_height = 14;
   532 	CopyGRFConfigList(&local, *config);
   532 	CopyGRFConfigList(&local, *config);
   533 
   533