110 struct newgrf_add_d { |
113 struct newgrf_add_d { |
111 GRFConfig **list; |
114 GRFConfig **list; |
112 const GRFConfig *sel; |
115 const GRFConfig *sel; |
113 }; |
116 }; |
114 |
117 |
|
118 /* Names of the add a newgrf window widgets */ |
|
119 enum AddNewGRFWindowWidgets { |
|
120 ANGRFW_CLOSEBOX = 0, |
|
121 ANGRFW_CAPTION, |
|
122 ANGRFW_BACKGROUND, |
|
123 ANGRFW_GRF_LIST, |
|
124 ANGRFW_SCROLLBAR, |
|
125 ANGRFW_GRF_INFO, |
|
126 ANGRFW_ADD, |
|
127 ANGRFW_RESCAN, |
|
128 ANGRFW_RESIZE, |
|
129 }; |
115 |
130 |
116 static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) |
131 static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) |
117 { |
132 { |
118 switch (e->event) { |
133 switch (e->event) { |
119 case WE_PAINT: { |
134 case WE_PAINT: { |
120 const GRFConfig *c; |
135 const GRFConfig *c; |
121 int y; |
136 const Widget *wl = &w->widget[ANGRFW_GRF_LIST]; |
122 int n = 0; |
137 int n = 0; |
123 |
138 |
124 /* Count the number of GRFs */ |
139 /* Count the number of GRFs */ |
125 for (c = _all_grfs; c != NULL; c = c->next) n++; |
140 for (c = _all_grfs; c != NULL; c = c->next) n++; |
126 |
141 |
127 w->vscroll.cap = (w->widget[3].bottom - w->widget[3].top) / 10; |
142 w->vscroll.cap = (wl->bottom - wl->top) / 10; |
128 SetVScrollCount(w, n); |
143 SetVScrollCount(w, n); |
129 |
144 |
130 w->SetWidgetDisabledState(6, WP(w, newgrf_add_d).sel == NULL || WP(w, newgrf_add_d).sel->IsOpenTTDBaseGRF()); |
145 w->SetWidgetDisabledState(ANGRFW_ADD, WP(w, newgrf_add_d).sel == NULL || WP(w, newgrf_add_d).sel->IsOpenTTDBaseGRF()); |
131 DrawWindowWidgets(w); |
146 DrawWindowWidgets(w); |
132 |
147 |
133 GfxFillRect(w->widget[3].left + 1, w->widget[3].top + 1, w->widget[3].right, w->widget[3].bottom, 0xD7); |
148 GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7); |
134 |
149 |
135 n = 0; |
150 uint y = wl->top + 1; |
136 y = w->widget[3].top + 1; |
151 for (c = _all_grfs, n = 0; c != NULL && n < (w->vscroll.pos + w->vscroll.cap); c = c->next, n++) { |
137 |
152 if (n >= w->vscroll.pos) { |
138 for (c = _all_grfs; c != NULL; c = c->next) { |
|
139 if (n >= w->vscroll.pos && n < w->vscroll.pos + w->vscroll.cap) { |
|
140 bool h = c == WP(w, newgrf_add_d).sel; |
153 bool h = c == WP(w, newgrf_add_d).sel; |
141 const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; |
154 const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; |
142 |
155 |
143 /* Draw selection background */ |
156 /* Draw selection background */ |
144 if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156); |
157 if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156); |
145 DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, w->width - 18); |
158 DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, w->width - 18); |
146 y += 10; |
159 y += 10; |
147 } |
160 } |
148 n++; |
|
149 } |
161 } |
150 |
162 |
151 if (WP(w, newgrf_add_d).sel != NULL) { |
163 if (WP(w, newgrf_add_d).sel != NULL) { |
152 const Widget *wi = &w->widget[5]; |
164 const Widget *wi = &w->widget[ANGRFW_GRF_INFO]; |
153 ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false); |
165 ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false); |
154 } |
166 } |
155 break; |
167 break; |
156 } |
168 } |
157 |
169 |
158 case WE_DOUBLE_CLICK: |
170 case WE_DOUBLE_CLICK: |
159 if (e->we.click.widget != 3) break; |
171 if (e->we.click.widget != ANGRFW_GRF_LIST) break; |
160 e->we.click.widget = 6; |
172 e->we.click.widget = ANGRFW_ADD; |
161 /* Fall through */ |
173 /* Fall through */ |
162 |
174 |
163 case WE_CLICK: |
175 case WE_CLICK: |
164 switch (e->we.click.widget) { |
176 switch (e->we.click.widget) { |
165 case 3: { |
177 case ANGRFW_GRF_LIST: { |
166 /* Get row... */ |
178 /* Get row... */ |
167 const GRFConfig *c; |
179 const GRFConfig *c; |
168 uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos; |
180 uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos; |
169 |
181 |
170 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); |
182 for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); |
171 WP(w, newgrf_add_d).sel = c; |
183 WP(w, newgrf_add_d).sel = c; |
172 SetWindowDirty(w); |
184 SetWindowDirty(w); |
173 break; |
185 break; |
174 } |
186 } |
175 |
187 |
176 case 6: // Add selection to list |
188 case ANGRFW_ADD: // Add selection to list |
177 if (WP(w, newgrf_add_d).sel != NULL) { |
189 if (WP(w, newgrf_add_d).sel != NULL) { |
178 const GRFConfig *src = WP(w, newgrf_add_d).sel; |
190 const GRFConfig *src = WP(w, newgrf_add_d).sel; |
179 GRFConfig **list; |
191 GRFConfig **list; |
180 |
192 |
181 /* Find last entry in the list, checking for duplicate grfid on the way */ |
193 /* Find last entry in the list, checking for duplicate grfid on the way */ |
200 DeleteWindowByClass(WC_SAVELOAD); |
212 DeleteWindowByClass(WC_SAVELOAD); |
201 InvalidateWindowData(WC_GAME_OPTIONS, 0); |
213 InvalidateWindowData(WC_GAME_OPTIONS, 0); |
202 } |
214 } |
203 break; |
215 break; |
204 |
216 |
205 case 7: // Rescan list |
217 case ANGRFW_RESCAN: // Rescan list |
206 WP(w, newgrf_add_d).sel = NULL; |
218 WP(w, newgrf_add_d).sel = NULL; |
207 ScanNewGRFFiles(); |
219 ScanNewGRFFiles(); |
208 SetWindowDirty(w); |
220 SetWindowDirty(w); |
209 break; |
221 break; |
210 } |
222 } |
211 break; |
223 break; |
212 } |
224 } |
213 } |
225 } |
214 |
226 |
215 |
227 /* Widget definition for the add a newgrf window */ |
216 static const Widget _newgrf_add_dlg_widgets[] = { |
228 static const Widget _newgrf_add_dlg_widgets[] = { |
217 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, |
229 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // ANGRFW_CLOSEBOX |
218 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, |
230 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION |
219 |
231 { WWT_PANEL, RESIZE_RB, 14, 0, 294, 14, 121, 0x0, STR_NULL }, // ANGRFW_BACKGROUND |
220 /* List of files */ |
232 { WWT_INSET, RESIZE_RB, 14, 2, 292, 16, 119, 0x0, STR_NULL }, // ANGRFW_GRF_LIST |
221 { WWT_PANEL, RESIZE_RB, 14, 0, 294, 14, 121, 0x0, STR_NULL }, |
233 { WWT_SCROLLBAR, RESIZE_LRB, 14, 295, 306, 14, 121, 0x0, STR_NULL }, // ANGRFW_SCROLLBAR |
222 { WWT_INSET, RESIZE_RB, 14, 2, 292, 16, 119, 0x0, STR_NULL }, |
234 { WWT_PANEL, RESIZE_RTB, 14, 0, 306, 122, 224, 0x0, STR_NULL }, // ANGRFW_GRF_INFO |
223 { WWT_SCROLLBAR, RESIZE_LRB, 14, 295, 306, 14, 121, 0x0, STR_NULL }, |
235 { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, // ANGRFW_ADD |
224 |
236 { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // ANGRFW_RESCAN |
225 /* NewGRF file info */ |
237 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0, STR_RESIZE_BUTTON }, // ANGRFW_RESIZE |
226 { WWT_PANEL, RESIZE_RTB, 14, 0, 306, 122, 224, 0x0, STR_NULL }, |
|
227 |
|
228 { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, |
|
229 { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, |
|
230 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0, STR_RESIZE_BUTTON }, |
|
231 { WIDGETS_END }, |
238 { WIDGETS_END }, |
232 }; |
239 }; |
233 |
240 |
234 |
241 /* Window definition for the add a newgrf window */ |
235 static const WindowDesc _newgrf_add_dlg_desc = { |
242 static const WindowDesc _newgrf_add_dlg_desc = { |
236 WDP_CENTER, WDP_CENTER, 307, 237, 307, 337, |
243 WDP_CENTER, WDP_CENTER, 307, 237, 307, 337, |
237 WC_SAVELOAD, WC_NONE, |
244 WC_SAVELOAD, WC_NONE, |
238 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
245 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
239 _newgrf_add_dlg_widgets, |
246 _newgrf_add_dlg_widgets, |
523 SetupNewGRFWindow(w); |
535 SetupNewGRFWindow(w); |
524 break; |
536 break; |
525 } |
537 } |
526 } |
538 } |
527 |
539 |
528 |
540 /* Widget definition of the manage newgrfs window */ |
529 static const Widget _newgrf_widgets[] = { |
541 static const Widget _newgrf_widgets[] = { |
530 { WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, |
542 { WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // SNGRFS_CLOSEBOX |
531 { WWT_CAPTION, RESIZE_RIGHT, 10, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, |
543 { WWT_CAPTION, RESIZE_RIGHT, 10, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION |
532 |
544 { WWT_PANEL, RESIZE_RIGHT, 10, 0, 299, 14, 29, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND |
533 /* NewGRF file Add, Remove, Move up, Move down */ |
545 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 79, 16, 27, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD |
534 { WWT_PANEL, RESIZE_RIGHT, 10, 0, 299, 14, 29, STR_NULL, STR_NULL }, |
546 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 80, 149, 16, 27, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE |
535 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 79, 16, 27, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, |
547 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 150, 219, 16, 27, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP |
536 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 80, 149, 16, 27, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, |
548 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 220, 289, 16, 27, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN |
537 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 150, 219, 16, 27, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, |
549 { WWT_MATRIX, RESIZE_RB, 10, 0, 287, 30, 99, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST |
538 { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 220, 289, 16, 27, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, |
550 { WWT_SCROLLBAR, RESIZE_LRB, 10, 288, 299, 30, 99, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR |
539 |
551 { WWT_PANEL, RESIZE_RTB, 10, 0, 299, 100, 212, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO |
540 /* NewGRF file list */ |
552 { WWT_PUSHTXTBTN, RESIZE_TB, 10, 0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS |
541 { WWT_MATRIX, RESIZE_RB, 10, 0, 287, 30, 99, 0x501, STR_NEWGRF_FILE_TIP }, |
553 { WWT_PUSHTXTBTN, RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES |
542 { WWT_SCROLLBAR, RESIZE_LRB, 10, 288, 299, 30, 99, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, |
554 { WWT_RESIZEBOX, RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0, STR_RESIZE_BUTTON }, // SNGRFS_RESIZE |
543 |
|
544 /* NewGRF file info */ |
|
545 { WWT_PANEL, RESIZE_RTB, 10, 0, 299, 100, 212, STR_NULL, STR_NULL }, |
|
546 |
|
547 /* Edit parameter and apply changes button... */ |
|
548 { WWT_PUSHTXTBTN, RESIZE_TB, 10, 0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, |
|
549 { WWT_PUSHTXTBTN, RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, |
|
550 |
|
551 { WWT_RESIZEBOX, RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0, STR_RESIZE_BUTTON }, |
|
552 |
|
553 { WIDGETS_END }, |
555 { WIDGETS_END }, |
554 }; |
556 }; |
555 |
557 |
556 |
558 /* Window definition of the manage newgrfs window */ |
557 static const WindowDesc _newgrf_desc = { |
559 static const WindowDesc _newgrf_desc = { |
558 WDP_CENTER, WDP_CENTER, 300, 225, 300, 225, |
560 WDP_CENTER, WDP_CENTER, 300, 225, 300, 225, |
559 WC_GAME_OPTIONS, WC_NONE, |
561 WC_GAME_OPTIONS, WC_NONE, |
560 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
562 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, |
561 _newgrf_widgets, |
563 _newgrf_widgets, |