equal
deleted
inserted
replaced
1 /* $Id$ */ |
1 /* $Id$ */ |
|
2 |
|
3 /** @file newgrf_gui.cpp */ |
2 |
4 |
3 #include "stdafx.h" |
5 #include "stdafx.h" |
4 #include "openttd.h" |
6 #include "openttd.h" |
5 #include "functions.h" |
7 #include "functions.h" |
6 #include "variables.h" |
8 #include "variables.h" |
155 } |
157 } |
156 |
158 |
157 case WE_CLICK: |
159 case WE_CLICK: |
158 switch (e->we.click.widget) { |
160 switch (e->we.click.widget) { |
159 case 3: { |
161 case 3: { |
160 // Get row... |
162 /* Get row... */ |
161 const GRFConfig *c; |
163 const GRFConfig *c; |
162 uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos; |
164 uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos; |
163 |
165 |
164 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); |
166 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); |
165 WP(w, newgrf_add_d).sel = c; |
167 WP(w, newgrf_add_d).sel = c; |
166 SetWindowDirty(w); |
168 SetWindowDirty(w); |
167 break; |
169 break; |
168 } |
170 } |
169 |
171 |
170 case 6: /* Add selection to list */ |
172 case 6: // Add selection to list |
171 if (WP(w, newgrf_add_d).sel != NULL) { |
173 if (WP(w, newgrf_add_d).sel != NULL) { |
172 const GRFConfig *src = WP(w, newgrf_add_d).sel; |
174 const GRFConfig *src = WP(w, newgrf_add_d).sel; |
173 GRFConfig **list; |
175 GRFConfig **list; |
174 |
176 |
175 /* Find last entry in the list, checking for duplicate grfid on the way */ |
177 /* Find last entry in the list, checking for duplicate grfid on the way */ |
194 DeleteWindowByClass(WC_SAVELOAD); |
196 DeleteWindowByClass(WC_SAVELOAD); |
195 InvalidateWindowData(WC_GAME_OPTIONS, 0); |
197 InvalidateWindowData(WC_GAME_OPTIONS, 0); |
196 } |
198 } |
197 break; |
199 break; |
198 |
200 |
199 case 7: /* Rescan list */ |
201 case 7: // Rescan list |
200 WP(w, newgrf_add_d).sel = NULL; |
202 WP(w, newgrf_add_d).sel = NULL; |
201 ScanNewGRFFiles(); |
203 ScanNewGRFFiles(); |
202 SetWindowDirty(w); |
204 SetWindowDirty(w); |
203 break; |
205 break; |
204 } |
206 } |
374 SetupNewGRFWindow(w); |
376 SetupNewGRFWindow(w); |
375 break; |
377 break; |
376 |
378 |
377 case WE_CLICK: |
379 case WE_CLICK: |
378 switch (e->we.click.widget) { |
380 switch (e->we.click.widget) { |
379 case SNGRFS_ADD: { /* Add GRF */ |
381 case SNGRFS_ADD: { // Add GRF |
380 GRFConfig **list = WP(w, newgrf_d).list; |
382 GRFConfig **list = WP(w, newgrf_d).list; |
381 Window *w; |
383 Window *w; |
382 |
384 |
383 DeleteWindowByClass(WC_SAVELOAD); |
385 DeleteWindowByClass(WC_SAVELOAD); |
384 w = AllocateWindowDesc(&_newgrf_add_dlg_desc); |
386 w = AllocateWindowDesc(&_newgrf_add_dlg_desc); |
386 |
388 |
387 WP(w, newgrf_add_d).list = list; |
389 WP(w, newgrf_add_d).list = list; |
388 break; |
390 break; |
389 } |
391 } |
390 |
392 |
391 case SNGRFS_REMOVE: { /* Remove GRF */ |
393 case SNGRFS_REMOVE: { // Remove GRF |
392 GRFConfig **pc, *c, *newsel; |
394 GRFConfig **pc, *c, *newsel; |
393 |
395 |
394 /* Choose the next GRF file to be the selected file */ |
396 /* Choose the next GRF file to be the selected file */ |
395 newsel = WP(w, newgrf_d).sel->next; |
397 newsel = WP(w, newgrf_d).sel->next; |
396 |
398 |
410 SetupNewGRFWindow(w); |
412 SetupNewGRFWindow(w); |
411 SetWindowDirty(w); |
413 SetWindowDirty(w); |
412 break; |
414 break; |
413 } |
415 } |
414 |
416 |
415 case SNGRFS_MOVE_UP: { /* Move GRF up */ |
417 case SNGRFS_MOVE_UP: { // Move GRF up |
416 GRFConfig **pc, *c; |
418 GRFConfig **pc, *c; |
417 if (WP(w, newgrf_d).sel == NULL) break; |
419 if (WP(w, newgrf_d).sel == NULL) break; |
418 |
420 |
419 for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { |
421 for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { |
420 if (c->next == WP(w, newgrf_d).sel) { |
422 if (c->next == WP(w, newgrf_d).sel) { |
426 } |
428 } |
427 SetWindowDirty(w); |
429 SetWindowDirty(w); |
428 break; |
430 break; |
429 } |
431 } |
430 |
432 |
431 case SNGRFS_MOVE_DOWN: { /* Move GRF down */ |
433 case SNGRFS_MOVE_DOWN: { // Move GRF down |
432 GRFConfig **pc, *c; |
434 GRFConfig **pc, *c; |
433 if (WP(w, newgrf_d).sel == NULL) break; |
435 if (WP(w, newgrf_d).sel == NULL) break; |
434 |
436 |
435 for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { |
437 for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { |
436 if (c == WP(w, newgrf_d).sel) { |
438 if (c == WP(w, newgrf_d).sel) { |
442 } |
444 } |
443 SetWindowDirty(w); |
445 SetWindowDirty(w); |
444 break; |
446 break; |
445 } |
447 } |
446 |
448 |
447 case SNGRFS_FILE_LIST: { /* Select a GRF */ |
449 case SNGRFS_FILE_LIST: { // Select a GRF |
448 GRFConfig *c; |
450 GRFConfig *c; |
449 uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; |
451 uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; |
450 |
452 |
451 for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--); |
453 for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--); |
452 WP(w, newgrf_d).sel = c; |
454 WP(w, newgrf_d).sel = c; |
453 |
455 |
454 SetWindowDirty(w); |
456 SetWindowDirty(w); |
455 break; |
457 break; |
456 } |
458 } |
457 |
459 |
458 case SNGRFS_APPLY_CHANGES: /* Apply changes made to GRF list */ |
460 case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list |
459 if (WP(w, newgrf_d).execute) { |
461 if (WP(w, newgrf_d).execute) { |
460 ShowQuery( |
462 ShowQuery( |
461 STR_POPUP_CAUTION_CAPTION, |
463 STR_POPUP_CAUTION_CAPTION, |
462 STR_NEWGRF_CONFIRMATION_TEXT, |
464 STR_NEWGRF_CONFIRMATION_TEXT, |
463 w, |
465 w, |
466 } else { |
468 } else { |
467 CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list); |
469 CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list); |
468 } |
470 } |
469 break; |
471 break; |
470 |
472 |
471 case SNGRFS_SET_PARAMETERS: { /* Edit parameters */ |
473 case SNGRFS_SET_PARAMETERS: { // Edit parameters |
472 char buff[512]; |
474 char buff[512]; |
473 if (WP(w, newgrf_d).sel == NULL) break; |
475 if (WP(w, newgrf_d).sel == NULL) break; |
474 |
476 |
475 GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff)); |
477 GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff)); |
476 ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL); |
478 ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL); |