2006-12-04 14:27:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
/** @file newgrf_gui.cpp */
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "functions.h"
|
|
|
|
#include "variables.h"
|
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2006-12-04 14:27:54 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2006-12-21 10:29:16 +00:00
|
|
|
#include "newgrf.h"
|
2006-12-04 14:27:54 +00:00
|
|
|
#include "newgrf_config.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/** Parse an integerlist string and set each found value
|
|
|
|
* @param p the string to be parsed. Each element in the list is seperated by a
|
|
|
|
* comma or a space character
|
|
|
|
* @param items pointer to the integerlist-array that will be filled with values
|
|
|
|
* @param maxitems the maximum number of elements the integerlist-array has
|
|
|
|
* @return returns the number of items found, or -1 on an error */
|
|
|
|
static int parse_intlist(const char *p, int *items, int maxitems)
|
|
|
|
{
|
|
|
|
int n = 0, v;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
v = strtol(p, &end, 0);
|
|
|
|
if (p == end || n == maxitems) return -1;
|
|
|
|
p = end;
|
|
|
|
items[n++] = v;
|
|
|
|
if (*p == '\0') break;
|
|
|
|
if (*p != ',' && *p != ' ') return -1;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-25 16:09:36 +00:00
|
|
|
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params)
|
2006-12-04 14:27:54 +00:00
|
|
|
{
|
2007-01-13 13:47:57 +00:00
|
|
|
char buff[256];
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2007-02-21 23:18:08 +00:00
|
|
|
if (c->error != NULL) {
|
2007-02-24 16:34:37 +00:00
|
|
|
SetDParamStr(0, c->filename);
|
2007-06-12 13:22:14 +00:00
|
|
|
SetDParamStr(1, c->error->data);
|
2007-02-24 16:34:37 +00:00
|
|
|
for (uint i = 0; i < c->error->num_params; i++) {
|
|
|
|
uint32 param = 0;
|
|
|
|
byte param_number = c->error->param_number[i];
|
|
|
|
|
|
|
|
if (param_number < c->num_params) param = c->param[param_number];
|
|
|
|
|
|
|
|
SetDParam(2 + i, param);
|
|
|
|
}
|
|
|
|
|
|
|
|
char message[512];
|
2007-06-12 13:22:14 +00:00
|
|
|
GetString(message, c->error->custom_message != NULL ? BindCString(c->error->custom_message) : c->error->message, lastof(message));
|
2007-02-24 16:34:37 +00:00
|
|
|
|
|
|
|
SetDParamStr(0, message);
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, c->error->severity, w, bottom - y);
|
2007-02-21 23:18:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-18 12:26:55 +00:00
|
|
|
/* Draw filename or not if it is not known (GRF sent over internet) */
|
|
|
|
if (c->filename != NULL) {
|
|
|
|
SetDParamStr(0, c->filename);
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y);
|
2006-12-18 12:26:55 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Prepare and draw GRF ID */
|
2007-01-13 15:55:22 +00:00
|
|
|
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, buff);
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Prepare and draw MD5 sum */
|
2007-01-13 13:47:57 +00:00
|
|
|
md5sumToString(buff, lastof(buff), c->md5sum);
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, buff);
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Show GRF parameter list */
|
|
|
|
if (show_params) {
|
|
|
|
if (c->num_params > 0) {
|
2006-12-10 11:29:14 +00:00
|
|
|
GRFBuildParamList(buff, c, lastof(buff));
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, buff);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_01A9_NONE);
|
|
|
|
}
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show flags */
|
2007-03-25 16:09:36 +00:00
|
|
|
if (c->status == GCS_NOT_FOUND) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
|
|
|
|
if (c->status == GCS_DISABLED) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Draw GRF info if it exists */
|
2007-01-13 15:00:16 +00:00
|
|
|
if (c->info != NULL && !StrEmpty(c->info)) {
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, c->info);
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_02BD, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
} else {
|
2007-03-25 16:09:36 +00:00
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w, bottom - y);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Dialogue for adding NewGRF files to the selection */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct newgrf_add_d {
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **list;
|
|
|
|
const GRFConfig *sel;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Names of the add a newgrf window widgets */
|
|
|
|
enum AddNewGRFWindowWidgets {
|
|
|
|
ANGRFW_CLOSEBOX = 0,
|
|
|
|
ANGRFW_CAPTION,
|
|
|
|
ANGRFW_BACKGROUND,
|
|
|
|
ANGRFW_GRF_LIST,
|
|
|
|
ANGRFW_SCROLLBAR,
|
|
|
|
ANGRFW_GRF_INFO,
|
|
|
|
ANGRFW_ADD,
|
|
|
|
ANGRFW_RESCAN,
|
|
|
|
ANGRFW_RESIZE,
|
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
|
|
|
const GRFConfig *c;
|
2007-12-07 12:22:34 +00:00
|
|
|
const Widget *wl = &w->widget[ANGRFW_GRF_LIST];
|
2007-12-14 00:25:00 +00:00
|
|
|
int n = 0;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Count the number of GRFs */
|
|
|
|
for (c = _all_grfs; c != NULL; c = c->next) n++;
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
w->vscroll.cap = (wl->bottom - wl->top) / 10;
|
2006-12-04 14:27:54 +00:00
|
|
|
SetVScrollCount(w, n);
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
w->SetWidgetDisabledState(ANGRFW_ADD, WP(w, newgrf_add_d).sel == NULL || WP(w, newgrf_add_d).sel->IsOpenTTDBaseGRF());
|
2006-12-04 14:27:54 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
uint y = wl->top + 1;
|
|
|
|
for (c = _all_grfs, n = 0; c != NULL && n < (w->vscroll.pos + w->vscroll.cap); c = c->next, n++) {
|
|
|
|
if (n >= w->vscroll.pos) {
|
2006-12-04 14:27:54 +00:00
|
|
|
bool h = c == WP(w, newgrf_add_d).sel;
|
2007-01-13 15:00:16 +00:00
|
|
|
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Draw selection background */
|
|
|
|
if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156);
|
2007-11-04 00:08:57 +00:00
|
|
|
DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, w->width - 18);
|
2006-12-04 14:27:54 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WP(w, newgrf_add_d).sel != NULL) {
|
2007-12-07 12:22:34 +00:00
|
|
|
const Widget *wi = &w->widget[ANGRFW_GRF_INFO];
|
2007-03-25 16:09:36 +00:00
|
|
|
ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-06-22 13:10:56 +00:00
|
|
|
case WE_DOUBLE_CLICK:
|
2007-12-07 12:22:34 +00:00
|
|
|
if (e->we.click.widget != ANGRFW_GRF_LIST) break;
|
|
|
|
e->we.click.widget = ANGRFW_ADD;
|
2007-06-22 13:10:56 +00:00
|
|
|
/* Fall through */
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2007-12-07 12:22:34 +00:00
|
|
|
case ANGRFW_GRF_LIST: {
|
2007-03-21 03:06:21 +00:00
|
|
|
/* Get row... */
|
2006-12-04 14:27:54 +00:00
|
|
|
const GRFConfig *c;
|
2007-12-07 12:22:34 +00:00
|
|
|
uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--);
|
|
|
|
WP(w, newgrf_add_d).sel = c;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
case ANGRFW_ADD: // Add selection to list
|
2006-12-04 14:27:54 +00:00
|
|
|
if (WP(w, newgrf_add_d).sel != NULL) {
|
|
|
|
const GRFConfig *src = WP(w, newgrf_add_d).sel;
|
2007-01-11 17:29:39 +00:00
|
|
|
GRFConfig **list;
|
2006-12-05 11:13:22 +00:00
|
|
|
|
|
|
|
/* Find last entry in the list, checking for duplicate grfid on the way */
|
|
|
|
for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) {
|
|
|
|
if ((*list)->grfid == src->grfid) {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy GRF details from scanned list */
|
2007-01-11 17:29:39 +00:00
|
|
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
2006-12-04 14:27:54 +00:00
|
|
|
*c = *src;
|
|
|
|
c->filename = strdup(src->filename);
|
2007-06-02 09:26:03 +00:00
|
|
|
if (src->name != NULL) c->name = strdup(src->name);
|
|
|
|
if (src->info != NULL) c->info = strdup(src->info);
|
2006-12-04 14:27:54 +00:00
|
|
|
c->next = NULL;
|
2006-12-05 11:13:22 +00:00
|
|
|
|
|
|
|
/* Append GRF config to configuration list */
|
|
|
|
*list = c;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
|
|
|
InvalidateWindowData(WC_GAME_OPTIONS, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
case ANGRFW_RESCAN: // Rescan list
|
2006-12-04 14:27:54 +00:00
|
|
|
WP(w, newgrf_add_d).sel = NULL;
|
|
|
|
ScanNewGRFFiles();
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Widget definition for the add a newgrf window */
|
2006-12-04 14:27:54 +00:00
|
|
|
static const Widget _newgrf_add_dlg_widgets[] = {
|
2007-12-07 12:22:34 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // ANGRFW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 294, 14, 121, 0x0, STR_NULL }, // ANGRFW_BACKGROUND
|
|
|
|
{ WWT_INSET, RESIZE_RB, 14, 2, 292, 16, 119, 0x0, STR_NULL }, // ANGRFW_GRF_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 295, 306, 14, 121, 0x0, STR_NULL }, // ANGRFW_SCROLLBAR
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 306, 122, 224, 0x0, STR_NULL }, // ANGRFW_GRF_INFO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, // ANGRFW_ADD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // ANGRFW_RESCAN
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0, STR_RESIZE_BUTTON }, // ANGRFW_RESIZE
|
2006-12-04 14:27:54 +00:00
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Window definition for the add a newgrf window */
|
2006-12-04 14:27:54 +00:00
|
|
|
static const WindowDesc _newgrf_add_dlg_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SAVELOAD, WC_NONE,
|
2007-12-06 15:58:39 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2006-12-04 14:27:54 +00:00
|
|
|
_newgrf_add_dlg_widgets,
|
|
|
|
NewGRFAddDlgWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* 'NewGRF Settings' dialogue */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct newgrf_d {
|
2006-12-21 10:29:16 +00:00
|
|
|
GRFConfig **orig_list; ///< grf list the window is shown with
|
|
|
|
GRFConfig **list; ///< temporary grf list to which changes are made
|
|
|
|
GRFConfig *sel; ///< selected grf item
|
|
|
|
bool editable; ///< is the window editable
|
|
|
|
bool show_params; ///< are the grf-parameters shown in the info-panel
|
|
|
|
bool execute; ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
|
|
|
|
|
2006-12-21 10:29:16 +00:00
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Names of the manage newgrfs window widgets */
|
2006-12-20 19:16:44 +00:00
|
|
|
enum ShowNewGRFStateWidgets {
|
2007-12-07 12:22:34 +00:00
|
|
|
SNGRFS_CLOSEBOX = 0,
|
|
|
|
SNGRFS_CAPTION,
|
|
|
|
SNGRFS_BACKGROUND,
|
|
|
|
SNGRFS_ADD,
|
2006-12-20 19:16:44 +00:00
|
|
|
SNGRFS_REMOVE,
|
|
|
|
SNGRFS_MOVE_UP,
|
|
|
|
SNGRFS_MOVE_DOWN,
|
2007-12-07 12:22:34 +00:00
|
|
|
SNGRFS_FILE_LIST,
|
|
|
|
SNGRFS_SCROLLBAR,
|
|
|
|
SNGRFS_NEWGRF_INFO,
|
2006-12-20 19:16:44 +00:00
|
|
|
SNGRFS_SET_PARAMETERS,
|
2006-12-21 10:29:16 +00:00
|
|
|
SNGRFS_APPLY_CHANGES,
|
2007-12-07 12:22:34 +00:00
|
|
|
SNGRFS_RESIZE,
|
2006-12-20 19:16:44 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
static void SetupNewGRFState(Window *w)
|
|
|
|
{
|
|
|
|
bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
|
|
|
|
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(3, !WP(w, newgrf_d).editable);
|
|
|
|
w->SetWidgetsDisabledState(disable_all,
|
2006-12-20 19:16:44 +00:00
|
|
|
SNGRFS_REMOVE,
|
|
|
|
SNGRFS_MOVE_UP,
|
|
|
|
SNGRFS_MOVE_DOWN,
|
|
|
|
WIDGET_LIST_END
|
|
|
|
);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
if (!disable_all) {
|
|
|
|
/* All widgets are now enabled, so disable widgets we can't use */
|
2007-12-02 14:29:48 +00:00
|
|
|
if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) w->DisableWidget(SNGRFS_MOVE_UP);
|
|
|
|
if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN);
|
|
|
|
if (WP(w, newgrf_d).sel->IsOpenTTDBaseGRF()) w->DisableWidget(SNGRFS_REMOVE);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void SetupNewGRFWindow(Window *w)
|
|
|
|
{
|
2006-12-20 19:16:44 +00:00
|
|
|
const GRFConfig *c;
|
2006-12-04 14:27:54 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
|
|
|
|
|
2006-12-20 19:16:44 +00:00
|
|
|
w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
|
2006-12-04 14:27:54 +00:00
|
|
|
SetVScrollCount(w, i);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable);
|
2006-12-21 10:29:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Callback function for the newgrf 'apply changes' confirmation window
|
2007-04-18 18:00:33 +00:00
|
|
|
* @param w Window which is calling this callback
|
|
|
|
* @param confirmed boolean value, true when yes was clicked, false otherwise
|
|
|
|
*/
|
2006-12-29 17:54:47 +00:00
|
|
|
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
|
2006-12-21 10:29:16 +00:00
|
|
|
{
|
2006-12-29 17:54:47 +00:00
|
|
|
if (confirmed) {
|
2006-12-21 10:29:16 +00:00
|
|
|
newgrf_d *nd = &WP(w, newgrf_d);
|
2007-01-13 14:01:05 +00:00
|
|
|
GRFConfig *c;
|
|
|
|
int i = 0;
|
2006-12-21 10:29:16 +00:00
|
|
|
|
2007-06-18 23:00:55 +00:00
|
|
|
CopyGRFConfigList(nd->orig_list, *nd->list, false);
|
2006-12-21 10:29:16 +00:00
|
|
|
ReloadNewGRFData();
|
2007-01-13 14:01:05 +00:00
|
|
|
|
|
|
|
/* Show new, updated list */
|
|
|
|
for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++);
|
2007-06-18 23:00:55 +00:00
|
|
|
CopyGRFConfigList(nd->list, *nd->orig_list, false);
|
2007-01-13 14:01:05 +00:00
|
|
|
for (c = *nd->list; c != NULL && i > 0; c = c->next, i--);
|
|
|
|
nd->sel = c;
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
2006-12-21 10:29:16 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT: {
|
2006-12-20 19:16:44 +00:00
|
|
|
const GRFConfig *c;
|
2006-12-04 14:27:54 +00:00
|
|
|
int i, y;
|
|
|
|
|
|
|
|
SetupNewGRFState(w);
|
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
/* Draw NewGRF list */
|
2006-12-20 19:16:44 +00:00
|
|
|
y = w->widget[SNGRFS_FILE_LIST].top;
|
2006-12-04 14:27:54 +00:00
|
|
|
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) {
|
|
|
|
if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) {
|
2007-01-13 15:00:16 +00:00
|
|
|
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
|
2007-01-14 19:57:49 +00:00
|
|
|
SpriteID pal;
|
2007-10-16 00:35:59 +00:00
|
|
|
byte txtoffset;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Pick a colour */
|
2007-03-06 19:33:28 +00:00
|
|
|
switch (c->status) {
|
|
|
|
case GCS_NOT_FOUND:
|
|
|
|
case GCS_DISABLED:
|
|
|
|
pal = PALETTE_TO_RED;
|
|
|
|
break;
|
|
|
|
case GCS_ACTIVATED:
|
|
|
|
pal = PALETTE_TO_GREEN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pal = PALETTE_TO_BLUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-21 12:45:43 +00:00
|
|
|
/* Do not show a "not-failure" colour when it actually failed to load */
|
|
|
|
if (pal != PALETTE_TO_RED) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(c->flags, GCF_STATIC)) {
|
2007-10-21 12:45:43 +00:00
|
|
|
pal = PALETTE_TO_GREY;
|
2007-11-19 21:02:30 +00:00
|
|
|
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
2007-10-21 12:45:43 +00:00
|
|
|
pal = PALETTE_TO_ORANGE;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(SPR_SQUARE, pal, 5, y + 2);
|
2007-02-21 23:18:08 +00:00
|
|
|
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
|
2007-10-16 00:35:59 +00:00
|
|
|
txtoffset = c->error != NULL ? 35 : 25;
|
2007-11-04 00:08:57 +00:00
|
|
|
DoDrawStringTruncated(text, txtoffset, y + 3, WP(w, newgrf_d).sel == c ? TC_WHITE : TC_BLACK, w->width - txtoffset - 10);
|
2006-12-04 14:27:54 +00:00
|
|
|
y += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WP(w, newgrf_d).sel != NULL) {
|
|
|
|
/* Draw NewGRF file info */
|
2006-12-20 19:16:44 +00:00
|
|
|
const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
|
2007-03-25 16:09:36 +00:00
|
|
|
ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, WP(w, newgrf_d).show_params);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-12-04 20:27:53 +00:00
|
|
|
case WE_INVALIDATE_DATA:
|
|
|
|
SetupNewGRFWindow(w);
|
|
|
|
break;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_ADD: { // Add GRF
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **list = WP(w, newgrf_d).list;
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
|
|
|
w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
|
|
|
|
w->resize.step_height = 10;
|
|
|
|
|
|
|
|
WP(w, newgrf_add_d).list = list;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_REMOVE: { // Remove GRF
|
2006-12-05 14:18:58 +00:00
|
|
|
GRFConfig **pc, *c, *newsel;
|
|
|
|
|
|
|
|
/* Choose the next GRF file to be the selected file */
|
|
|
|
newsel = WP(w, newgrf_d).sel->next;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
|
2006-12-05 14:18:58 +00:00
|
|
|
/* If the new selection is empty (i.e. we're deleting the last item
|
|
|
|
* in the list, pick the file just before the selected file */
|
|
|
|
if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
if (c == WP(w, newgrf_d).sel) {
|
|
|
|
*pc = c->next;
|
|
|
|
free(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-05 14:18:58 +00:00
|
|
|
|
|
|
|
WP(w, newgrf_d).sel = newsel;
|
2006-12-04 14:27:54 +00:00
|
|
|
SetupNewGRFWindow(w);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_MOVE_UP: { // Move GRF up
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **pc, *c;
|
|
|
|
if (WP(w, newgrf_d).sel == NULL) break;
|
|
|
|
|
|
|
|
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
|
|
|
|
if (c->next == WP(w, newgrf_d).sel) {
|
|
|
|
c->next = WP(w, newgrf_d).sel->next;
|
|
|
|
WP(w, newgrf_d).sel->next = c;
|
|
|
|
*pc = WP(w, newgrf_d).sel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_MOVE_DOWN: { // Move GRF down
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **pc, *c;
|
|
|
|
if (WP(w, newgrf_d).sel == NULL) break;
|
|
|
|
|
|
|
|
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
|
|
|
|
if (c == WP(w, newgrf_d).sel) {
|
|
|
|
*pc = c->next;
|
|
|
|
c->next = c->next->next;
|
|
|
|
(*pc)->next = c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_FILE_LIST: { // Select a GRF
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig *c;
|
2006-12-20 19:16:44 +00:00
|
|
|
uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--);
|
|
|
|
WP(w, newgrf_d).sel = c;
|
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
|
2006-12-21 10:29:16 +00:00
|
|
|
if (WP(w, newgrf_d).execute) {
|
|
|
|
ShowQuery(
|
|
|
|
STR_POPUP_CAUTION_CAPTION,
|
|
|
|
STR_NEWGRF_CONFIRMATION_TEXT,
|
2006-12-29 17:54:47 +00:00
|
|
|
w,
|
|
|
|
NewGRFConfirmationCallback
|
2006-12-21 10:29:16 +00:00
|
|
|
);
|
|
|
|
} else {
|
2007-06-18 23:00:55 +00:00
|
|
|
CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
|
|
|
|
ResetGRFConfig(false);
|
|
|
|
ReloadNewGRFData();
|
2006-12-21 10:29:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-21 03:06:21 +00:00
|
|
|
case SNGRFS_SET_PARAMETERS: { // Edit parameters
|
2006-12-04 14:27:54 +00:00
|
|
|
char buff[512];
|
|
|
|
if (WP(w, newgrf_d).sel == NULL) break;
|
|
|
|
|
2006-12-10 11:29:14 +00:00
|
|
|
GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff));
|
2006-12-30 01:17:53 +00:00
|
|
|
ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL);
|
2006-12-04 14:27:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT:
|
|
|
|
if (e->we.edittext.str != NULL) {
|
|
|
|
/* Parse our new "int list" */
|
|
|
|
GRFConfig *c = WP(w, newgrf_d).sel;
|
|
|
|
c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param));
|
|
|
|
|
|
|
|
/* parse_intlist returns -1 on error */
|
|
|
|
if (c->num_params == (byte)-1) c->num_params = 0;
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2006-12-21 10:29:16 +00:00
|
|
|
case WE_DESTROY:
|
2007-02-27 16:07:04 +00:00
|
|
|
if (!WP(w, newgrf_d).execute) {
|
2007-06-18 23:00:55 +00:00
|
|
|
CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
|
|
|
|
ResetGRFConfig(false);
|
|
|
|
ReloadNewGRFData();
|
2007-02-27 16:07:04 +00:00
|
|
|
}
|
2006-12-21 10:29:16 +00:00
|
|
|
/* Remove the temporary copy of grf-list used in window */
|
|
|
|
ClearGRFConfigList(WP(w, newgrf_d).list);
|
|
|
|
break;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 14;
|
2006-12-20 19:16:44 +00:00
|
|
|
w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1;
|
2007-10-05 21:31:59 +00:00
|
|
|
SetupNewGRFWindow(w);
|
2006-12-04 14:27:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Widget definition of the manage newgrfs window */
|
2006-12-04 14:27:54 +00:00
|
|
|
static const Widget _newgrf_widgets[] = {
|
2007-12-07 12:22:34 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // SNGRFS_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 10, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 10, 0, 299, 14, 29, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 10, 79, 16, 27, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 80, 149, 16, 27, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 150, 219, 16, 27, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 3, 220, 289, 16, 27, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, 10, 0, 287, 30, 99, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 10, 288, 299, 30, 99, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 10, 0, 299, 100, 212, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 10, 0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0, STR_RESIZE_BUTTON }, // SNGRFS_RESIZE
|
2006-12-04 14:27:54 +00:00
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Window definition of the manage newgrfs window */
|
2006-12-04 14:27:54 +00:00
|
|
|
static const WindowDesc _newgrf_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2006-12-04 14:27:54 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
|
|
|
_newgrf_widgets,
|
|
|
|
NewGRFWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-12-21 10:29:16 +00:00
|
|
|
/** Setup the NewGRF gui
|
|
|
|
* @param editable allow the user to make changes to the grfconfig in the window
|
|
|
|
* @param show_params show information about what parameters are set for the grf files
|
|
|
|
* @param exec_changes if changes are made to the list (editable is true), apply these
|
|
|
|
* changes immediately or only update the list
|
|
|
|
* @param config pointer to a linked-list of grfconfig's that will be shown */
|
|
|
|
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
|
2006-12-04 14:27:54 +00:00
|
|
|
{
|
2006-12-21 10:29:16 +00:00
|
|
|
static GRFConfig *local = NULL;
|
2006-12-04 14:27:54 +00:00
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowByClass(WC_GAME_OPTIONS);
|
|
|
|
w = AllocateWindowDesc(&_newgrf_desc);
|
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
w->resize.step_height = 14;
|
2007-06-18 23:00:55 +00:00
|
|
|
CopyGRFConfigList(&local, *config, false);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Clear selections */
|
|
|
|
WP(w, newgrf_d).sel = NULL;
|
2006-12-21 10:29:16 +00:00
|
|
|
WP(w, newgrf_d).list = &local;
|
|
|
|
WP(w, newgrf_d).orig_list = config;
|
2006-12-04 14:27:54 +00:00
|
|
|
WP(w, newgrf_d).editable = editable;
|
2006-12-21 10:29:16 +00:00
|
|
|
WP(w, newgrf_d).execute = exec_changes;
|
2006-12-04 14:27:54 +00:00
|
|
|
WP(w, newgrf_d).show_params = show_params;
|
|
|
|
|
|
|
|
SetupNewGRFWindow(w);
|
|
|
|
}
|