peter1138@5237: /* $Id$ */ peter1138@5237: peter1138@5237: #include "stdafx.h" peter1138@5237: #include "openttd.h" peter1138@5237: #include "functions.h" peter1138@5237: #include "variables.h" peter1138@5237: #include "gfx.h" peter1138@5237: #include "gui.h" peter1138@5237: #include "window.h" peter1138@5237: #include "table/strings.h" peter1138@5237: #include "table/sprites.h" Darkvater@5352: #include "newgrf.h" peter1138@5237: #include "newgrf_config.h" peter1138@5237: peter1138@5237: peter1138@5237: /** Parse an integerlist string and set each found value peter1138@5237: * @param p the string to be parsed. Each element in the list is seperated by a peter1138@5237: * comma or a space character peter1138@5237: * @param items pointer to the integerlist-array that will be filled with values peter1138@5237: * @param maxitems the maximum number of elements the integerlist-array has peter1138@5237: * @return returns the number of items found, or -1 on an error */ peter1138@5237: static int parse_intlist(const char *p, int *items, int maxitems) peter1138@5237: { peter1138@5237: int n = 0, v; peter1138@5237: char *end; peter1138@5237: peter1138@5237: for (;;) { peter1138@5237: v = strtol(p, &end, 0); peter1138@5237: if (p == end || n == maxitems) return -1; peter1138@5237: p = end; peter1138@5237: items[n++] = v; peter1138@5237: if (*p == '\0') break; peter1138@5237: if (*p != ',' && *p != ' ') return -1; peter1138@5237: p++; peter1138@5237: } peter1138@5237: peter1138@5237: return n; peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, bool show_params) peter1138@5237: { peter1138@5237: char buff[512]; peter1138@5237: char *s; peter1138@5237: uint i; peter1138@5237: rubidium@5339: /* Draw filename or not if it is not known (GRF sent over internet) */ rubidium@5339: if (c->filename != NULL) { rubidium@5339: SetDParamStr(0, c->filename); rubidium@5339: y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w); rubidium@5339: } peter1138@5237: peter1138@5237: /* Prepare and draw GRF ID */ peter1138@5237: snprintf(buff, lengthof(buff), "%08X", (uint32)BSWAP32(c->grfid)); peter1138@5237: SetDParamStr(0, buff); peter1138@5237: y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w); peter1138@5237: peter1138@5237: /* Prepare and draw MD5 sum */ peter1138@5237: s = buff; peter1138@5237: for (i = 0; i < lengthof(c->md5sum); i++) { peter1138@5237: s += snprintf(s, lastof(buff) - s, "%02X", c->md5sum[i]); peter1138@5237: } peter1138@5237: SetDParamStr(0, buff); peter1138@5237: y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w); peter1138@5237: peter1138@5237: /* Show GRF parameter list */ peter1138@5237: if (show_params) { peter1138@5237: if (c->num_params > 0) { peter1138@5308: GRFBuildParamList(buff, c, lastof(buff)); peter1138@5237: SetDParamStr(0, buff); peter1138@5237: } else { peter1138@5237: SetDParam(0, STR_01A9_NONE); peter1138@5237: } peter1138@5237: y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w); peter1138@5237: } peter1138@5237: peter1138@5237: /* Show flags */ peter1138@5237: if (HASBIT(c->flags, GCF_NOT_FOUND)) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w); peter1138@5237: if (HASBIT(c->flags, GCF_DISABLED)) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w); peter1138@5237: peter1138@5237: /* Draw GRF info if it exists */ peter1138@5237: if (c->info != NULL && strlen(c->info) != 0) { peter1138@5237: SetDParamStr(0, c->info); peter1138@5237: y += DrawStringMultiLine(x, y, STR_02BD, w); peter1138@5237: } else { peter1138@5237: y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w); peter1138@5237: } peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: /* Dialogue for adding NewGRF files to the selection */ peter1138@5237: typedef struct newgrf_add_d { peter1138@5237: GRFConfig **list; peter1138@5237: const GRFConfig *sel; peter1138@5237: } newgrf_add_d; peter1138@5237: peter1138@5237: peter1138@5237: static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) peter1138@5237: { peter1138@5237: switch (e->event) { peter1138@5237: case WE_PAINT: { peter1138@5237: const GRFConfig *c; peter1138@5237: int y; peter1138@5237: int n = 0; peter1138@5237: peter1138@5237: /* Count the number of GRFs */ peter1138@5237: for (c = _all_grfs; c != NULL; c = c->next) n++; peter1138@5237: peter1138@5237: w->vscroll.cap = (w->widget[3].bottom - w->widget[3].top) / 10; peter1138@5237: SetVScrollCount(w, n); peter1138@5237: peter1138@5237: SetWindowWidgetDisabledState(w, 6, WP(w, newgrf_add_d).sel == NULL); peter1138@5237: DrawWindowWidgets(w); peter1138@5237: peter1138@5237: GfxFillRect(w->widget[3].left + 1, w->widget[3].top + 1, w->widget[3].right, w->widget[3].bottom, 0xD7); peter1138@5237: peter1138@5237: n = 0; peter1138@5237: y = w->widget[3].top + 1; peter1138@5237: peter1138@5237: for (c = _all_grfs; c != NULL; c = c->next) { peter1138@5237: if (n >= w->vscroll.pos && n < w->vscroll.pos + w->vscroll.cap) { peter1138@5237: bool h = c == WP(w, newgrf_add_d).sel; peter1138@5237: const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename; peter1138@5237: peter1138@5237: /* Draw selection background */ peter1138@5237: if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156); peter1138@5237: DoDrawStringTruncated(text, 4, y, h ? 0xC : 0x6, w->width - 18); peter1138@5237: y += 10; peter1138@5237: } peter1138@5237: n++; peter1138@5237: } peter1138@5237: peter1138@5237: if (WP(w, newgrf_add_d).sel != NULL) { peter1138@5237: const Widget *wi = &w->widget[5]; peter1138@5237: ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, false); peter1138@5237: } peter1138@5237: break; peter1138@5237: } peter1138@5237: peter1138@5237: case WE_CLICK: peter1138@5237: switch (e->we.click.widget) { peter1138@5237: case 3: { peter1138@5237: // Get row... peter1138@5237: const GRFConfig *c; peter1138@5237: uint i = (e->we.click.pt.y - w->widget[3].top) / 10 + w->vscroll.pos; peter1138@5237: peter1138@5237: for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--); peter1138@5237: WP(w, newgrf_add_d).sel = c; peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: peter1138@5237: case 6: /* Add selection to list */ peter1138@5237: if (WP(w, newgrf_add_d).sel != NULL) { peter1138@5237: const GRFConfig *src = WP(w, newgrf_add_d).sel; peter1138@5243: GRFConfig **list, *c; peter1138@5243: peter1138@5243: /* Find last entry in the list, checking for duplicate grfid on the way */ peter1138@5243: for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) { peter1138@5243: if ((*list)->grfid == src->grfid) { peter1138@5243: ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0); peter1138@5243: return; peter1138@5243: } peter1138@5243: } peter1138@5243: peter1138@5243: /* Copy GRF details from scanned list */ peter1138@5243: c = calloc(1, sizeof(*c)); peter1138@5237: *c = *src; peter1138@5237: c->filename = strdup(src->filename); peter1138@5237: if (src->name != NULL) c->name = strdup(src->name); peter1138@5237: if (src->info != NULL) c->info = strdup(src->info); peter1138@5237: c->next = NULL; peter1138@5243: peter1138@5243: /* Append GRF config to configuration list */ peter1138@5243: *list = c; peter1138@5237: peter1138@5237: DeleteWindowByClass(WC_SAVELOAD); peter1138@5237: InvalidateWindowData(WC_GAME_OPTIONS, 0); peter1138@5237: } peter1138@5237: break; peter1138@5237: peter1138@5237: case 7: /* Rescan list */ peter1138@5237: WP(w, newgrf_add_d).sel = NULL; peter1138@5237: ScanNewGRFFiles(); peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: static const Widget _newgrf_add_dlg_widgets[] = { peter1138@5237: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, peter1138@5237: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, peter1138@5237: peter1138@5237: /* List of files */ peter1138@5237: { WWT_PANEL, RESIZE_RB, 14, 0, 294, 14, 221, 0x0, STR_NULL }, peter1138@5237: { WWT_INSET, RESIZE_RB, 14, 2, 292, 16, 219, 0x0, STR_NULL }, peter1138@5237: { WWT_SCROLLBAR, RESIZE_LRB, 14, 295, 306, 14, 221, 0x0, STR_NULL }, peter1138@5237: peter1138@5237: /* NewGRF file info */ rubidium@5552: { WWT_PANEL, RESIZE_RTB, 14, 0, 306, 222, 324, 0x0, STR_NULL }, peter1138@5237: rubidium@5552: { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, 146, 325, 336, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, rubidium@5552: { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 147, 294, 325, 336, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, rubidium@5552: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 295, 306, 325, 336, 0x0, STR_RESIZE_BUTTON }, peter1138@5237: { WIDGETS_END }, peter1138@5237: }; peter1138@5237: peter1138@5237: peter1138@5237: static const WindowDesc _newgrf_add_dlg_desc = { rubidium@5552: WDP_CENTER, WDP_CENTER, 307, 337, peter1138@5237: WC_SAVELOAD, 0, peter1138@5237: WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, peter1138@5237: _newgrf_add_dlg_widgets, peter1138@5237: NewGRFAddDlgWndProc, peter1138@5237: }; peter1138@5237: peter1138@5237: peter1138@5237: /* 'NewGRF Settings' dialogue */ peter1138@5237: typedef struct newgrf_d { Darkvater@5352: GRFConfig **orig_list; ///< grf list the window is shown with Darkvater@5352: GRFConfig **list; ///< temporary grf list to which changes are made Darkvater@5352: GRFConfig *sel; ///< selected grf item Darkvater@5352: bool editable; ///< is the window editable Darkvater@5352: bool show_params; ///< are the grf-parameters shown in the info-panel Darkvater@5352: bool execute; ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated peter1138@5237: } newgrf_d; peter1138@5237: assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d)); peter1138@5237: Darkvater@5352: Darkvater@5345: enum ShowNewGRFStateWidgets { Darkvater@5345: SNGRFS_ADD = 3, Darkvater@5345: SNGRFS_REMOVE, Darkvater@5345: SNGRFS_MOVE_UP, Darkvater@5345: SNGRFS_MOVE_DOWN, Darkvater@5345: SNGRFS_FILE_LIST = 7, Darkvater@5345: SNGRFS_NEWGRF_INFO = 9, Darkvater@5345: SNGRFS_SET_PARAMETERS, Darkvater@5352: SNGRFS_APPLY_CHANGES, Darkvater@5345: }; peter1138@5237: Darkvater@5352: peter1138@5237: static void SetupNewGRFState(Window *w) peter1138@5237: { peter1138@5237: bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable; peter1138@5237: peter1138@5237: SetWindowWidgetDisabledState(w, 3, !WP(w, newgrf_d).editable); Darkvater@5345: SetWindowWidgetsDisabledState(w, disable_all, Darkvater@5345: SNGRFS_REMOVE, Darkvater@5345: SNGRFS_MOVE_UP, Darkvater@5345: SNGRFS_MOVE_DOWN, Darkvater@5345: WIDGET_LIST_END Darkvater@5345: ); Darkvater@5345: SetWindowWidgetDisabledState(w, SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all); peter1138@5237: peter1138@5237: if (!disable_all) { peter1138@5237: /* All widgets are now enabled, so disable widgets we can't use */ Darkvater@5345: if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) DisableWindowWidget(w, SNGRFS_MOVE_UP); Darkvater@5345: if (WP(w, newgrf_d).sel->next == NULL) DisableWindowWidget(w, SNGRFS_MOVE_DOWN); peter1138@5237: } peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: static void SetupNewGRFWindow(Window *w) peter1138@5237: { Darkvater@5345: const GRFConfig *c; peter1138@5237: int i; peter1138@5237: peter1138@5237: for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++); peter1138@5237: Darkvater@5345: w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1; peter1138@5237: SetVScrollCount(w, i); Darkvater@5352: SetWindowWidgetDisabledState(w, SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable); Darkvater@5352: } Darkvater@5352: Darkvater@5352: Darkvater@5352: /** Callback function for the newgrf 'apply changes' confirmation window Darkvater@5352: * @param yes_clicked boolean value, true when yes was clicked, false otherwise */ Darkvater@5352: static void NewGRFConfirmationCallback(bool yes_clicked) Darkvater@5352: { Darkvater@5352: if (yes_clicked) { Darkvater@5352: Window *w = FindWindowById(WC_GAME_OPTIONS, 0); Darkvater@5352: newgrf_d *nd = &WP(w, newgrf_d); Darkvater@5352: Darkvater@5352: CopyGRFConfigList(nd->orig_list, *nd->list); Darkvater@5352: ReloadNewGRFData(); Darkvater@5352: } peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: static void NewGRFWndProc(Window *w, WindowEvent *e) peter1138@5237: { peter1138@5237: switch (e->event) { peter1138@5237: case WE_PAINT: { Darkvater@5345: const GRFConfig *c; peter1138@5237: int i, y; peter1138@5237: peter1138@5237: SetupNewGRFState(w); peter1138@5237: peter1138@5237: DrawWindowWidgets(w); peter1138@5237: peter1138@5237: /* Draw NewGRF list */ Darkvater@5345: y = w->widget[SNGRFS_FILE_LIST].top; peter1138@5237: for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) { peter1138@5237: if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) { peter1138@5237: const char *text = (c->name != NULL && strlen(c->name) != 0) ? c->name : c->filename; peter1138@5237: PalSpriteID pal; peter1138@5237: peter1138@5237: /* Pick a colour */ peter1138@5237: if (HASBIT(c->flags, GCF_NOT_FOUND) || HASBIT(c->flags, GCF_DISABLED)) { peter1138@5237: pal = PALETTE_TO_RED; peter1138@5329: } else if (HASBIT(c->flags, GCF_STATIC)) { peter1138@5329: pal = PALETTE_TO_YELLOW; peter1138@5237: } else if (HASBIT(c->flags, GCF_ACTIVATED)) { peter1138@5237: pal = PALETTE_TO_GREEN; peter1138@5237: } else { peter1138@5237: pal = PALETTE_TO_BLUE; peter1138@5237: } peter1138@5237: peter1138@5237: DrawSprite(SPRITE_PALETTE(SPR_SQUARE | pal), 5, y + 2); peter1138@5237: DoDrawString(text, 25, y + 3, WP(w, newgrf_d).sel == c ? 0xC : 0x10); peter1138@5237: y += 14; peter1138@5237: } peter1138@5237: } peter1138@5237: peter1138@5237: if (WP(w, newgrf_d).sel != NULL) { peter1138@5237: /* Draw NewGRF file info */ Darkvater@5345: const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO]; peter1138@5237: ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params); peter1138@5237: } peter1138@5237: peter1138@5237: break; peter1138@5237: } peter1138@5237: peter1138@5241: case WE_INVALIDATE_DATA: peter1138@5241: SetupNewGRFWindow(w); peter1138@5241: break; peter1138@5241: peter1138@5237: case WE_CLICK: peter1138@5237: switch (e->we.click.widget) { Darkvater@5345: case SNGRFS_ADD: { /* Add GRF */ peter1138@5237: GRFConfig **list = WP(w, newgrf_d).list; peter1138@5237: Window *w; peter1138@5237: peter1138@5237: DeleteWindowByClass(WC_SAVELOAD); peter1138@5237: w = AllocateWindowDesc(&_newgrf_add_dlg_desc); peter1138@5237: w->resize.step_height = 10; peter1138@5237: peter1138@5237: WP(w, newgrf_add_d).list = list; peter1138@5237: break; peter1138@5237: } peter1138@5237: Darkvater@5345: case SNGRFS_REMOVE: { /* Remove GRF */ peter1138@5248: GRFConfig **pc, *c, *newsel; peter1138@5248: peter1138@5248: /* Choose the next GRF file to be the selected file */ peter1138@5248: newsel = WP(w, newgrf_d).sel->next; peter1138@5248: peter1138@5237: for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { peter1138@5248: /* If the new selection is empty (i.e. we're deleting the last item peter1138@5248: * in the list, pick the file just before the selected file */ peter1138@5248: if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c; peter1138@5248: peter1138@5237: if (c == WP(w, newgrf_d).sel) { peter1138@5237: *pc = c->next; peter1138@5237: free(c); peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5248: peter1138@5248: WP(w, newgrf_d).sel = newsel; peter1138@5237: SetupNewGRFWindow(w); peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: Darkvater@5345: case SNGRFS_MOVE_UP: { /* Move GRF up */ peter1138@5237: GRFConfig **pc, *c; peter1138@5237: if (WP(w, newgrf_d).sel == NULL) break; peter1138@5237: peter1138@5237: for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { peter1138@5237: if (c->next == WP(w, newgrf_d).sel) { peter1138@5237: c->next = WP(w, newgrf_d).sel->next; peter1138@5237: WP(w, newgrf_d).sel->next = c; peter1138@5237: *pc = WP(w, newgrf_d).sel; peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: Darkvater@5345: case SNGRFS_MOVE_DOWN: { /* Move GRF down */ peter1138@5237: GRFConfig **pc, *c; peter1138@5237: if (WP(w, newgrf_d).sel == NULL) break; peter1138@5237: peter1138@5237: for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { peter1138@5237: if (c == WP(w, newgrf_d).sel) { peter1138@5237: *pc = c->next; peter1138@5237: c->next = c->next->next; peter1138@5237: (*pc)->next = c; peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: Darkvater@5345: case SNGRFS_FILE_LIST: { /* Select a GRF */ peter1138@5237: GRFConfig *c; Darkvater@5345: uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; peter1138@5237: peter1138@5237: for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--); peter1138@5237: WP(w, newgrf_d).sel = c; peter1138@5237: peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: } peter1138@5237: Darkvater@5352: case SNGRFS_APPLY_CHANGES: /* Apply changes made to GRF list */ Darkvater@5352: if (WP(w, newgrf_d).execute) { Darkvater@5352: ShowQuery( Darkvater@5352: STR_POPUP_CAUTION_CAPTION, Darkvater@5352: STR_NEWGRF_CONFIRMATION_TEXT, Darkvater@5352: NewGRFConfirmationCallback, Darkvater@5352: w->window_class, Darkvater@5352: w->window_number Darkvater@5352: ); Darkvater@5352: } else { Darkvater@5352: CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list); Darkvater@5352: } Darkvater@5352: break; Darkvater@5352: Darkvater@5345: case SNGRFS_SET_PARAMETERS: { /* Edit parameters */ peter1138@5237: char buff[512]; peter1138@5237: if (WP(w, newgrf_d).sel == NULL) break; peter1138@5237: peter1138@5308: GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff)); peter1138@5237: ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w->window_class, w->window_number, CS_ALPHANUMERAL); peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5237: break; peter1138@5237: peter1138@5237: case WE_ON_EDIT_TEXT: peter1138@5237: if (e->we.edittext.str != NULL) { peter1138@5237: /* Parse our new "int list" */ peter1138@5237: GRFConfig *c = WP(w, newgrf_d).sel; peter1138@5237: c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param)); peter1138@5237: peter1138@5237: /* parse_intlist returns -1 on error */ peter1138@5237: if (c->num_params == (byte)-1) c->num_params = 0; peter1138@5237: } peter1138@5237: SetWindowDirty(w); peter1138@5237: break; peter1138@5237: Darkvater@5352: case WE_DESTROY: Darkvater@5352: /* Remove the temporary copy of grf-list used in window */ Darkvater@5352: ClearGRFConfigList(WP(w, newgrf_d).list); Darkvater@5352: break; Darkvater@5352: peter1138@5237: case WE_RESIZE: peter1138@5237: w->vscroll.cap += e->we.sizing.diff.y / 14; Darkvater@5345: w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1; peter1138@5237: break; peter1138@5237: } peter1138@5237: } peter1138@5237: peter1138@5237: peter1138@5237: static const Widget _newgrf_widgets[] = { peter1138@5237: { WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, peter1138@5237: { WWT_CAPTION, RESIZE_RIGHT, 10, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, peter1138@5237: peter1138@5237: /* NewGRF file Add, Remove, Move up, Move down */ Darkvater@5345: { WWT_PANEL, RESIZE_RIGHT, 10, 0, 299, 14, 29, STR_NULL, STR_NULL }, peter1138@5237: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 79, 16, 27, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, peter1138@5237: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 80, 149, 16, 27, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, peter1138@5237: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 150, 219, 16, 27, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, peter1138@5237: { WWT_PUSHTXTBTN, RESIZE_NONE, 3, 220, 289, 16, 27, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, peter1138@5237: peter1138@5237: /* NewGRF file list */ peter1138@5237: { WWT_MATRIX, RESIZE_RB, 10, 0, 287, 30, 99, 0x501, STR_NEWGRF_FILE_TIP }, peter1138@5237: { WWT_SCROLLBAR, RESIZE_LRB, 10, 288, 299, 30, 99, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, peter1138@5237: peter1138@5237: /* NewGRF file info */ rubidium@5552: { WWT_PANEL, RESIZE_RTB, 10, 0, 299, 100, 212, STR_NULL, STR_NULL }, peter1138@5237: Darkvater@5352: /* Edit parameter and apply changes button... */ rubidium@5552: { WWT_PUSHTXTBTN, RESIZE_TB, 10, 0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, rubidium@5552: { WWT_PUSHTXTBTN, RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, Darkvater@5352: rubidium@5552: { WWT_RESIZEBOX, RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0, STR_RESIZE_BUTTON }, peter1138@5237: peter1138@5237: { WIDGETS_END }, peter1138@5237: }; peter1138@5237: peter1138@5237: peter1138@5237: static const WindowDesc _newgrf_desc = { rubidium@5552: WDP_CENTER, WDP_CENTER, 300, 225, peter1138@5237: WC_GAME_OPTIONS, 0, peter1138@5237: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, peter1138@5237: _newgrf_widgets, peter1138@5237: NewGRFWndProc, peter1138@5237: }; peter1138@5237: peter1138@5237: Darkvater@5352: /** Setup the NewGRF gui Darkvater@5352: * @param editable allow the user to make changes to the grfconfig in the window Darkvater@5352: * @param show_params show information about what parameters are set for the grf files Darkvater@5352: * @param exec_changes if changes are made to the list (editable is true), apply these Darkvater@5352: * changes immediately or only update the list Darkvater@5352: * @param config pointer to a linked-list of grfconfig's that will be shown */ Darkvater@5352: void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config) peter1138@5237: { Darkvater@5352: static GRFConfig *local = NULL; peter1138@5237: Window *w; peter1138@5237: peter1138@5237: DeleteWindowByClass(WC_GAME_OPTIONS); peter1138@5237: w = AllocateWindowDesc(&_newgrf_desc); peter1138@5237: if (w == NULL) return; peter1138@5237: peter1138@5237: w->resize.step_height = 14; Darkvater@5352: CopyGRFConfigList(&local, *config); peter1138@5237: peter1138@5237: /* Clear selections */ peter1138@5237: WP(w, newgrf_d).sel = NULL; Darkvater@5352: WP(w, newgrf_d).list = &local; Darkvater@5352: WP(w, newgrf_d).orig_list = config; peter1138@5237: WP(w, newgrf_d).editable = editable; Darkvater@5352: WP(w, newgrf_d).execute = exec_changes; peter1138@5237: WP(w, newgrf_d).show_params = show_params; peter1138@5237: peter1138@5237: SetupNewGRFWindow(w); peter1138@5237: }