|
@@ -22,48 +22,53 @@
|
|
|
* @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;
|
|
|
}
|
|
|
|
|
|
|
|
|
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, bool show_params)
|
|
|
{
|
|
|
char buff[256];
|
|
|
|
|
|
if (c->error != NULL) {
|
|
|
SetDParamStr(0, c->error);
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_ERROR_MSG, w);
|
|
|
}
|
|
|
|
|
|
/* Draw filename or not if it is not known (GRF sent over internet) */
|
|
|
if (c->filename != NULL) {
|
|
|
SetDParamStr(0, c->filename);
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w);
|
|
|
}
|
|
|
|
|
|
/* Prepare and draw GRF ID */
|
|
|
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
|
|
|
SetDParamStr(0, buff);
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_GRF_ID, w);
|
|
|
|
|
|
/* Prepare and draw MD5 sum */
|
|
|
md5sumToString(buff, lastof(buff), c->md5sum);
|
|
|
SetDParamStr(0, buff);
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_MD5SUM, w);
|
|
|
|
|
|
/* Show GRF parameter list */
|
|
|
if (show_params) {
|
|
|
if (c->num_params > 0) {
|
|
|
GRFBuildParamList(buff, c, lastof(buff));
|
|
|
SetDParamStr(0, buff);
|
|
|
} else {
|
|
|
SetDParam(0, STR_01A9_NONE);
|
|
|
}
|
|
@@ -307,49 +312,50 @@ static void NewGRFWndProc(Window *w, Win
|
|
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
/* Draw NewGRF list */
|
|
|
y = w->widget[SNGRFS_FILE_LIST].top;
|
|
|
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) {
|
|
|
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
|
|
|
SpriteID pal;
|
|
|
|
|
|
/* Pick a colour */
|
|
|
if (HASBIT(c->flags, GCF_NOT_FOUND) || HASBIT(c->flags, GCF_DISABLED)) {
|
|
|
pal = PALETTE_TO_RED;
|
|
|
} else if (HASBIT(c->flags, GCF_STATIC)) {
|
|
|
pal = PALETTE_TO_GREY;
|
|
|
} else if (HASBIT(c->flags, GCF_COMPATIBLE)) {
|
|
|
pal = PALETTE_TO_ORANGE;
|
|
|
} else if (HASBIT(c->flags, GCF_ACTIVATED)) {
|
|
|
pal = PALETTE_TO_GREEN;
|
|
|
} else {
|
|
|
pal = PALETTE_TO_BLUE;
|
|
|
}
|
|
|
|
|
|
DrawSprite(SPR_SQUARE, pal, 5, y + 2);
|
|
|
DoDrawString(text, 25, y + 3, WP(w, newgrf_d).sel == c ? 0xC : 0x10);
|
|
|
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
|
|
|
DoDrawString(text, c->error != NULL ? 35 : 25, y + 3, WP(w, newgrf_d).sel == c ? 0xC : 0x10);
|
|
|
y += 14;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (WP(w, newgrf_d).sel != NULL) {
|
|
|
/* Draw NewGRF file info */
|
|
|
const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO];
|
|
|
ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, WP(w, newgrf_d).show_params);
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case WE_INVALIDATE_DATA:
|
|
|
SetupNewGRFWindow(w);
|
|
|
break;
|
|
|
|
|
|
case WE_CLICK:
|
|
|
switch (e->we.click.widget) {
|
|
|
case SNGRFS_ADD: { /* Add GRF */
|
|
|
GRFConfig **list = WP(w, newgrf_d).list;
|
|
|
Window *w;
|
|
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|