|
|
/* $Id$ */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "openttd.h"
|
|
|
#include "functions.h"
|
|
|
#include "variables.h"
|
|
|
#include "gfx.h"
|
|
|
#include "gui.h"
|
|
|
#include "window.h"
|
|
|
#include "table/strings.h"
|
|
|
#include "table/sprites.h"
|
|
|
#include "newgrf.h"
|
|
|
#include "newgrf_config.h"
|
|
|
#include "helpers.hpp"
|
|
|
|
|
|
|
|
|
/** 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;
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w);
|
|
|
}
|
|
|
|
|
|
/* Show flags */
|
|
|
if (HASBIT(c->flags, GCF_NOT_FOUND)) y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w);
|
|
|
if (HASBIT(c->flags, GCF_DISABLED)) y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w);
|
|
|
if (HASBIT(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w);
|
|
|
|
|
|
/* Draw GRF info if it exists */
|
|
|
if (c->info != NULL && !StrEmpty(c->info)) {
|
|
|
SetDParamStr(0, c->info);
|
|
|
y += DrawStringMultiLine(x, y, STR_02BD, w);
|
|
|
} else {
|
|
|
y += DrawStringMultiLine(x, y, STR_NEWGRF_NO_INFO, w);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/* Dialogue for adding NewGRF files to the selection */
|
|
|
typedef struct newgrf_add_d {
|
|
|
GRFConfig **list;
|
|
|
const GRFConfig *sel;
|
|
|
} newgrf_add_d;
|
|
|
|
|
@@ -283,97 +288,98 @@ static void NewGRFConfirmationCallback(W
|
|
|
int i = 0;
|
|
|
|
|
|
CopyGRFConfigList(nd->orig_list, *nd->list);
|
|
|
ReloadNewGRFData();
|
|
|
|
|
|
/* Show new, updated list */
|
|
|
for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++);
|
|
|
CopyGRFConfigList(nd->list, *nd->orig_list);
|
|
|
for (c = *nd->list; c != NULL && i > 0; c = c->next, i--);
|
|
|
nd->sel = c;
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
static void NewGRFWndProc(Window *w, WindowEvent *e)
|
|
|
{
|
|
|
switch (e->event) {
|
|
|
case WE_PAINT: {
|
|
|
const GRFConfig *c;
|
|
|
int i, y;
|
|
|
|
|
|
SetupNewGRFState(w);
|
|
|
|
|
|
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);
|
|
|
w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
|
|
|
w->resize.step_height = 10;
|
|
|
|
|
|
WP(w, newgrf_add_d).list = list;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_REMOVE: { /* Remove GRF */
|
|
|
GRFConfig **pc, *c, *newsel;
|
|
|
|
|
|
/* Choose the next GRF file to be the selected file */
|
|
|
newsel = WP(w, newgrf_d).sel->next;
|
|
|
|
|
|
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) {
|
|
|
/* 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;
|
|
|
|
|
|
if (c == WP(w, newgrf_d).sel) {
|
|
|
*pc = c->next;
|
|
|
free(c);
|
|
|
break;
|
|
|
}
|
|
|
}
|