equal
deleted
inserted
replaced
112 /* Dialogue for adding NewGRF files to the selection */ |
112 /* Dialogue for adding NewGRF files to the selection */ |
113 struct newgrf_add_d { |
113 struct newgrf_add_d { |
114 GRFConfig **list; |
114 GRFConfig **list; |
115 const GRFConfig *sel; |
115 const GRFConfig *sel; |
116 }; |
116 }; |
|
117 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_add_d)); |
117 |
118 |
118 /* Names of the add a newgrf window widgets */ |
119 /* Names of the add a newgrf window widgets */ |
119 enum AddNewGRFWindowWidgets { |
120 enum AddNewGRFWindowWidgets { |
120 ANGRFW_CLOSEBOX = 0, |
121 ANGRFW_CLOSEBOX = 0, |
121 ANGRFW_CAPTION, |
122 ANGRFW_CAPTION, |
177 case ANGRFW_GRF_LIST: { |
178 case ANGRFW_GRF_LIST: { |
178 /* Get row... */ |
179 /* Get row... */ |
179 const GRFConfig *c; |
180 const GRFConfig *c; |
180 uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos; |
181 uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos; |
181 |
182 |
182 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); |
183 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {} |
183 WP(w, newgrf_add_d).sel = c; |
184 WP(w, newgrf_add_d).sel = c; |
184 SetWindowDirty(w); |
185 SetWindowDirty(w); |
185 break; |
186 break; |
186 } |
187 } |
187 |
188 |
302 static void SetupNewGRFWindow(Window *w) |
303 static void SetupNewGRFWindow(Window *w) |
303 { |
304 { |
304 const GRFConfig *c; |
305 const GRFConfig *c; |
305 int i; |
306 int i; |
306 |
307 |
307 for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++); |
308 for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {} |
308 |
309 |
309 w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1; |
310 w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1; |
310 SetVScrollCount(w, i); |
311 SetVScrollCount(w, i); |
311 w->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable); |
312 w->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable); |
312 } |
313 } |
325 |
326 |
326 CopyGRFConfigList(nd->orig_list, *nd->list, false); |
327 CopyGRFConfigList(nd->orig_list, *nd->list, false); |
327 ReloadNewGRFData(); |
328 ReloadNewGRFData(); |
328 |
329 |
329 /* Show new, updated list */ |
330 /* Show new, updated list */ |
330 for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++); |
331 for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++) {} |
331 CopyGRFConfigList(nd->list, *nd->orig_list, false); |
332 CopyGRFConfigList(nd->list, *nd->orig_list, false); |
332 for (c = *nd->list; c != NULL && i > 0; c = c->next, i--); |
333 for (c = *nd->list; c != NULL && i > 0; c = c->next, i--) {} |
333 nd->sel = c; |
334 nd->sel = c; |
334 |
335 |
335 SetWindowDirty(w); |
336 SetWindowDirty(w); |
336 } |
337 } |
337 } |
338 } |
472 |
473 |
473 case SNGRFS_FILE_LIST: { // Select a GRF |
474 case SNGRFS_FILE_LIST: { // Select a GRF |
474 GRFConfig *c; |
475 GRFConfig *c; |
475 uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; |
476 uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; |
476 |
477 |
477 for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--); |
478 for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--) {} |
478 WP(w, newgrf_d).sel = c; |
479 WP(w, newgrf_d).sel = c; |
479 |
480 |
480 SetWindowDirty(w); |
481 SetWindowDirty(w); |
481 break; |
482 break; |
482 } |
483 } |