2006-12-04 14:27:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file newgrf_gui.cpp GUI to change NewGRF settings. */
|
2007-03-21 03:06:21 +00:00
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2006-12-21 10:29:16 +00:00
|
|
|
#include "newgrf.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-06-03 18:35:58 +00:00
|
|
|
#include "gamelog.h"
|
2008-07-22 14:17:29 +00:00
|
|
|
#include "settings_func.h"
|
|
|
|
#include "widgets/dropdown_type.h"
|
2009-01-17 16:53:32 +00:00
|
|
|
#include "network/network.h"
|
|
|
|
#include "network/network_content.h"
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.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) {
|
2008-07-17 13:47:04 +00:00
|
|
|
char message[512];
|
2008-08-20 19:31:35 +00:00
|
|
|
SetDParamStr(0, c->error->custom_message); // is skipped by built-in messages
|
|
|
|
SetDParam (1, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(2, c->filename);
|
|
|
|
SetDParam (3, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(4, c->error->data);
|
|
|
|
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(5 + i, param);
|
2008-07-17 13:47:04 +00:00
|
|
|
}
|
2008-08-20 19:31:35 +00:00
|
|
|
GetString(message, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING, lastof(message));
|
2007-02-24 16:34:37 +00:00
|
|
|
|
|
|
|
SetDParamStr(0, message);
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, c->error->severity);
|
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);
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_FILENAME);
|
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);
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_GRF_ID);
|
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);
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_MD5SUM);
|
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));
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, buff);
|
2006-12-04 14:27:54 +00:00
|
|
|
} else {
|
2009-04-21 23:40:56 +00:00
|
|
|
SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_PARAMETER);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-09-13 12:40:31 +00:00
|
|
|
/* Draw the palette of the NewGRF */
|
|
|
|
SetDParamStr(0, c->windows_paletted ? "Windows" : "DOS");
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_PALETTE);
|
2008-09-13 12:40:31 +00:00
|
|
|
}
|
2008-09-03 07:51:07 +00:00
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
/* Show flags */
|
2009-03-21 23:45:34 +00:00
|
|
|
if (c->status == GCS_NOT_FOUND) y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_NOT_FOUND);
|
|
|
|
if (c->status == GCS_DISABLED) y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_DISABLED);
|
|
|
|
if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED);
|
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)) {
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, c->info);
|
2009-04-21 23:40:56 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_BLACK_STRING);
|
2006-12-04 14:27:54 +00:00
|
|
|
} else {
|
2009-03-21 23:45:34 +00:00
|
|
|
y = DrawStringMultiLine(x, x + w, y, bottom, STR_NEWGRF_NO_INFO);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-29 20:29:19 +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,
|
|
|
|
};
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/**
|
|
|
|
* Window for adding NewGRF files
|
|
|
|
*/
|
|
|
|
struct NewGRFAddWindow : public Window {
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **list;
|
|
|
|
const GRFConfig *sel;
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
|
|
|
|
{
|
|
|
|
this->list = list;
|
|
|
|
this->resize.step_height = 10;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
const GRFConfig *c;
|
|
|
|
const Widget *wl = &this->widget[ANGRFW_GRF_LIST];
|
|
|
|
int n = 0;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Count the number of GRFs */
|
|
|
|
for (c = _all_grfs; c != NULL; c = c->next) n++;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->vscroll.cap = (wl->bottom - wl->top) / 10;
|
|
|
|
SetVScrollCount(this, n);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF());
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
uint y = wl->top + 1;
|
|
|
|
for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) {
|
|
|
|
if (n >= this->vscroll.pos) {
|
|
|
|
bool h = c == this->sel;
|
|
|
|
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
|
|
|
|
|
|
|
|
/* Draw selection background */
|
|
|
|
if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156);
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(4, this->width - 22, y, text, h ? TC_WHITE : TC_ORANGE);
|
2008-05-13 20:26:48 +00:00
|
|
|
y += 10;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
if (this->sel != NULL) {
|
|
|
|
const Widget *wi = &this->widget[ANGRFW_GRF_INFO];
|
|
|
|
ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
|
|
|
|
}
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnDoubleClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD);
|
|
|
|
}
|
2006-12-05 11:13:22 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case ANGRFW_GRF_LIST: {
|
|
|
|
/* Get row... */
|
|
|
|
const GRFConfig *c;
|
|
|
|
uint i = (pt.y - this->widget[ANGRFW_GRF_LIST].top) / 10 + this->vscroll.pos;
|
|
|
|
|
|
|
|
for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {}
|
|
|
|
this->sel = c;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2006-12-05 11:13:22 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case ANGRFW_ADD: // Add selection to list
|
|
|
|
if (this->sel != NULL) {
|
|
|
|
const GRFConfig *src = this->sel;
|
|
|
|
GRFConfig **list;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Find last entry in the list, checking for duplicate grfid on the way */
|
|
|
|
for (list = this->list; *list != NULL; list = &(*list)->next) {
|
|
|
|
if ((*list)->grfid == src->grfid) {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Copy GRF details from scanned list */
|
|
|
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
|
|
|
*c = *src;
|
|
|
|
c->filename = strdup(src->filename);
|
|
|
|
if (src->name != NULL) c->name = strdup(src->name);
|
|
|
|
if (src->info != NULL) c->info = strdup(src->info);
|
|
|
|
c->next = NULL;
|
|
|
|
|
|
|
|
/* Append GRF config to configuration list */
|
|
|
|
*list = c;
|
|
|
|
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
|
|
|
InvalidateWindowData(WC_GAME_OPTIONS, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANGRFW_RESCAN: // Rescan list
|
|
|
|
this->sel = NULL;
|
|
|
|
ScanNewGRFFiles();
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2008-05-13 20:26:48 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
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[] = {
|
2009-04-29 20:29:19 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW }, // ANGRFW_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION
|
|
|
|
{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 294, 14, 121, 0x0, STR_NULL }, // ANGRFW_BACKGROUND
|
|
|
|
{ WWT_INSET, RESIZE_RB, COLOUR_GREY, 2, 292, 16, 119, 0x0, STR_NULL }, // ANGRFW_GRF_LIST
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 295, 306, 14, 121, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST }, // ANGRFW_SCROLLBAR
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 0, 306, 122, 224, 0x0, STR_NULL }, // ANGRFW_GRF_INFO
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, // ANGRFW_ADD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // ANGRFW_RESCAN
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 295, 306, 225, 236, 0x0, STR_RESIZE_BUTTON }, // ANGRFW_RESIZE
|
2006-12-04 14:27:54 +00:00
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2009-04-29 20:32:11 +00:00
|
|
|
static const NWidgetPart _nested_newgrf_add_dlg_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY, ANGRFW_CLOSEBOX),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, ANGRFW_CAPTION), SetDataTip(STR_NEWGRF_ADD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, ANGRFW_BACKGROUND),
|
|
|
|
NWidget(WWT_INSET, COLOUR_GREY, ANGRFW_GRF_LIST), SetMinimalSize(291, 104), SetResize(1, 10), SetPadding(2, 2, 2, 2), EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_GREY, ANGRFW_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, ANGRFW_GRF_INFO), SetResize(1, 0), SetMinimalSize(307, 103), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ANGRFW_ADD), SetMinimalSize(147, 12), SetResize(1, 0), SetDataTip(STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ANGRFW_RESCAN), SetMinimalSize(148, 12), SetDataTip(STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY, ANGRFW_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Window definition for the add a newgrf window */
|
2009-03-15 15:12:06 +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,
|
2009-04-29 20:32:11 +00:00
|
|
|
_newgrf_add_dlg_widgets, _nested_newgrf_add_dlg_widgets, lengthof(_nested_newgrf_add_dlg_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
static GRFPresetList _grf_preset_list;
|
|
|
|
|
|
|
|
class DropDownListPresetItem : public DropDownListItem {
|
|
|
|
public:
|
|
|
|
DropDownListPresetItem(int result) : DropDownListItem(result, false) {}
|
|
|
|
|
|
|
|
virtual ~DropDownListPresetItem() {}
|
2008-08-06 20:14:21 +00:00
|
|
|
|
2008-08-06 20:12:42 +00:00
|
|
|
bool Selectable() const
|
2008-07-22 14:17:29 +00:00
|
|
|
{
|
2008-08-06 20:12:42 +00:00
|
|
|
return true;
|
2008-07-22 14:17:29 +00:00
|
|
|
}
|
|
|
|
|
2009-03-21 19:31:47 +00:00
|
|
|
void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
|
2008-07-22 14:17:29 +00:00
|
|
|
{
|
2009-03-21 19:31:47 +00:00
|
|
|
DrawString(left + 2, right + 2, top, _grf_preset_list[this->result], sel ? TC_WHITE : TC_BLACK);
|
2008-07-22 14:17:29 +00:00
|
|
|
}
|
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
static void NewGRFConfirmationCallback(Window *w, bool confirmed);
|
|
|
|
|
2009-04-29 20:29:19 +00:00
|
|
|
/** Names of the manage newgrfs window widgets. */
|
|
|
|
enum ShowNewGRFStateWidgets {
|
|
|
|
SNGRFS_CLOSEBOX = 0,
|
|
|
|
SNGRFS_CAPTION,
|
|
|
|
SNGRFS_BACKGROUND1,
|
|
|
|
SNGRFS_PRESET_LIST,
|
|
|
|
SNGRFS_PRESET_SAVE,
|
|
|
|
SNGRFS_PRESET_DELETE,
|
|
|
|
SNGRFS_BACKGROUND2,
|
|
|
|
SNGRFS_ADD,
|
|
|
|
SNGRFS_REMOVE,
|
|
|
|
SNGRFS_MOVE_UP,
|
|
|
|
SNGRFS_MOVE_DOWN,
|
|
|
|
SNGRFS_FILE_LIST,
|
|
|
|
SNGRFS_SCROLLBAR,
|
|
|
|
SNGRFS_NEWGRF_INFO,
|
|
|
|
SNGRFS_SET_PARAMETERS,
|
|
|
|
SNGRFS_TOGGLE_PALETTE,
|
|
|
|
SNGRFS_APPLY_CHANGES,
|
|
|
|
SNGRFS_CONTENT_DOWNLOAD,
|
|
|
|
SNGRFS_RESIZE,
|
|
|
|
};
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/**
|
|
|
|
* Window for showing NewGRF files
|
|
|
|
*/
|
|
|
|
struct NewGRFWindow : public Window {
|
2006-12-21 10:29:16 +00:00
|
|
|
GRFConfig **orig_list; ///< grf list the window is shown with
|
2008-05-13 20:26:48 +00:00
|
|
|
GRFConfig *list; ///< temporary grf list to which changes are made
|
2006-12-21 10:29:16 +00:00
|
|
|
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
|
2008-07-22 14:17:29 +00:00
|
|
|
int query_widget; ///< widget that opened a query
|
|
|
|
int preset; ///< selected preset
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0)
|
|
|
|
{
|
|
|
|
this->resize.step_height = 14;
|
|
|
|
this->sel = NULL;
|
|
|
|
this->list = NULL;
|
|
|
|
this->orig_list = config;
|
|
|
|
this->editable = editable;
|
|
|
|
this->execute = exec_changes;
|
|
|
|
this->show_params = show_params;
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
CopyGRFConfigList(&this->list, *config, false);
|
2008-07-22 14:17:29 +00:00
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
2008-05-13 20:26:48 +00:00
|
|
|
|
|
|
|
this->FindWindowPlacementAndResize(desc);
|
|
|
|
this->SetupNewGRFWindow();
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
~NewGRFWindow()
|
|
|
|
{
|
2009-01-23 23:37:49 +00:00
|
|
|
if (this->editable && !this->execute) {
|
2008-05-13 20:26:48 +00:00
|
|
|
CopyGRFConfigList(this->orig_list, this->list, true);
|
|
|
|
ResetGRFConfig(false);
|
|
|
|
ReloadNewGRFData();
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Remove the temporary copy of grf-list used in window */
|
|
|
|
ClearGRFConfigList(&this->list);
|
2008-07-22 14:17:29 +00:00
|
|
|
_grf_preset_list.Clear();
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
void SetupNewGRFWindow()
|
|
|
|
{
|
|
|
|
const GRFConfig *c;
|
|
|
|
int i;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
|
2006-12-21 10:29:16 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
|
|
|
|
SetVScrollCount(this, i);
|
2006-12-21 10:29:16 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
this->SetWidgetsDisabledState(!this->editable,
|
|
|
|
SNGRFS_PRESET_LIST,
|
|
|
|
SNGRFS_ADD,
|
|
|
|
SNGRFS_APPLY_CHANGES,
|
2008-09-03 07:51:07 +00:00
|
|
|
SNGRFS_TOGGLE_PALETTE,
|
2008-07-22 14:17:29 +00:00
|
|
|
WIDGET_LIST_END
|
|
|
|
);
|
2006-12-21 10:29:16 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
bool disable_all = this->sel == NULL || !this->editable;
|
|
|
|
|
|
|
|
this->SetWidgetsDisabledState(disable_all,
|
|
|
|
SNGRFS_REMOVE,
|
|
|
|
SNGRFS_MOVE_UP,
|
|
|
|
SNGRFS_MOVE_DOWN,
|
|
|
|
WIDGET_LIST_END
|
|
|
|
);
|
|
|
|
this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all);
|
2008-09-12 17:38:57 +00:00
|
|
|
this->SetWidgetDisabledState(SNGRFS_TOGGLE_PALETTE, disable_all);
|
2008-05-13 20:26:48 +00:00
|
|
|
|
|
|
|
if (!disable_all) {
|
|
|
|
/* All widgets are now enabled, so disable widgets we can't use */
|
|
|
|
if (this->sel == this->list) this->DisableWidget(SNGRFS_MOVE_UP);
|
|
|
|
if (this->sel->next == NULL) this->DisableWidget(SNGRFS_MOVE_DOWN);
|
|
|
|
if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE);
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
if (this->preset == -1) {
|
2009-04-21 23:40:56 +00:00
|
|
|
this->widget[SNGRFS_PRESET_LIST].data = STR_NUM_CUSTOM;
|
2008-07-22 14:17:29 +00:00
|
|
|
} else {
|
|
|
|
SetDParamStr(0, _grf_preset_list[this->preset]);
|
|
|
|
this->widget[SNGRFS_PRESET_LIST].data = STR_JUST_RAW_STRING;
|
|
|
|
}
|
2009-02-23 20:45:34 +00:00
|
|
|
this->SetWidgetDisabledState(SNGRFS_PRESET_DELETE, this->preset == -1);
|
2008-07-22 14:17:29 +00:00
|
|
|
|
2009-01-23 10:20:29 +00:00
|
|
|
bool has_missing = false;
|
2009-02-23 20:45:34 +00:00
|
|
|
bool has_compatible = false;
|
2009-01-23 10:20:29 +00:00
|
|
|
for (const GRFConfig *c = this->list; !has_missing && c != NULL; c = c->next) {
|
2009-02-23 20:45:34 +00:00
|
|
|
has_missing |= c->status == GCS_NOT_FOUND;
|
|
|
|
has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
|
2009-01-23 10:20:29 +00:00
|
|
|
}
|
2009-02-23 20:45:34 +00:00
|
|
|
if (has_missing || has_compatible) {
|
2009-01-23 10:20:29 +00:00
|
|
|
this->widget[SNGRFS_CONTENT_DOWNLOAD].data = STR_CONTENT_INTRO_MISSING_BUTTON;
|
|
|
|
this->widget[SNGRFS_CONTENT_DOWNLOAD].tooltips = STR_CONTENT_INTRO_MISSING_BUTTON_TIP;
|
|
|
|
} else {
|
|
|
|
this->widget[SNGRFS_CONTENT_DOWNLOAD].data = STR_CONTENT_INTRO_BUTTON;
|
|
|
|
this->widget[SNGRFS_CONTENT_DOWNLOAD].tooltips = STR_CONTENT_INTRO_BUTTON_TIP;
|
|
|
|
}
|
2009-02-23 20:45:34 +00:00
|
|
|
this->SetWidgetDisabledState(SNGRFS_PRESET_SAVE, has_missing);
|
2009-01-23 10:20:29 +00:00
|
|
|
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2007-03-06 19:33:28 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Draw NewGRF list */
|
|
|
|
int y = this->widget[SNGRFS_FILE_LIST].top;
|
|
|
|
int i = 0;
|
|
|
|
for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
|
|
|
|
if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) {
|
|
|
|
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
|
|
|
|
SpriteID pal;
|
|
|
|
byte txtoffset;
|
|
|
|
|
|
|
|
/* Pick a colour */
|
|
|
|
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;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Do not show a "not-failure" colour when it actually failed to load */
|
|
|
|
if (pal != PALETTE_TO_RED) {
|
|
|
|
if (HasBit(c->flags, GCF_STATIC)) {
|
|
|
|
pal = PALETTE_TO_GREY;
|
|
|
|
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
|
|
|
pal = PALETTE_TO_ORANGE;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
DrawSprite(SPR_SQUARE, pal, 5, y + 2);
|
|
|
|
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
|
|
|
|
txtoffset = c->error != NULL ? 35 : 25;
|
2009-03-21 20:12:12 +00:00
|
|
|
DrawString(txtoffset, this->widget[SNGRFS_FILE_LIST].right - 2, y + 3, text, this->sel == c ? TC_WHITE : TC_BLACK);
|
2008-05-13 20:26:48 +00:00
|
|
|
y += 14;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
if (this->sel != NULL) {
|
|
|
|
/* Draw NewGRF file info */
|
|
|
|
const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO];
|
|
|
|
ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params);
|
|
|
|
}
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2008-07-22 14:17:29 +00:00
|
|
|
case SNGRFS_PRESET_LIST: {
|
|
|
|
DropDownList *list = new DropDownList();
|
|
|
|
|
|
|
|
/* Add 'None' option for clearing list */
|
|
|
|
list->push_back(new DropDownListStringItem(STR_NONE, -1, false));
|
|
|
|
|
|
|
|
for (uint i = 0; i < _grf_preset_list.Length(); i++) {
|
|
|
|
if (_grf_preset_list[i] != NULL) {
|
|
|
|
list->push_back(new DropDownListPresetItem(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowDropDownList(this, list, this->preset, SNGRFS_PRESET_LIST);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SNGRFS_PRESET_SAVE:
|
|
|
|
this->query_widget = widget;
|
2008-09-15 16:29:40 +00:00
|
|
|
ShowQueryString(STR_EMPTY, STR_NEWGRF_PRESET_SAVE_QUERY, 32, 100, this, CS_ALPHANUMERAL, QSF_NONE);
|
2008-07-22 14:17:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNGRFS_PRESET_DELETE:
|
|
|
|
if (this->preset == -1) return;
|
|
|
|
|
|
|
|
DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
|
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
|
|
|
this->preset = -1;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_ADD: // Add GRF
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
|
|
|
new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNGRFS_REMOVE: { // Remove GRF
|
|
|
|
GRFConfig **pc, *c, *newsel;
|
|
|
|
|
|
|
|
/* Choose the next GRF file to be the selected file */
|
|
|
|
newsel = this->sel->next;
|
|
|
|
|
|
|
|
for (pc = &this->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 == this->sel) newsel = c;
|
|
|
|
|
|
|
|
if (c == this->sel) {
|
|
|
|
*pc = c->next;
|
|
|
|
free(c);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->sel = newsel;
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetupNewGRFWindow();
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2006-12-05 14:18:58 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_MOVE_UP: { // Move GRF up
|
|
|
|
GRFConfig **pc, *c;
|
|
|
|
if (this->sel == NULL) break;
|
2006-12-05 14:18:58 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
|
|
|
|
if (c->next == this->sel) {
|
|
|
|
c->next = this->sel->next;
|
|
|
|
this->sel->next = c;
|
|
|
|
*pc = this->sel;
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_MOVE_DOWN: { // Move GRF down
|
|
|
|
GRFConfig **pc, *c;
|
|
|
|
if (this->sel == NULL) break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
|
|
|
|
if (c == this->sel) {
|
|
|
|
*pc = c->next;
|
|
|
|
c->next = c->next->next;
|
|
|
|
(*pc)->next = c;
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_FILE_LIST: { // Select a GRF
|
|
|
|
GRFConfig *c;
|
|
|
|
uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
|
|
|
|
this->sel = c;
|
|
|
|
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
|
|
|
|
if (this->execute) {
|
|
|
|
ShowQuery(
|
|
|
|
STR_POPUP_CAUTION_CAPTION,
|
|
|
|
STR_NEWGRF_CONFIRMATION_TEXT,
|
|
|
|
this,
|
|
|
|
NewGRFConfirmationCallback
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
CopyGRFConfigList(this->orig_list, this->list, true);
|
|
|
|
ResetGRFConfig(false);
|
|
|
|
ReloadNewGRFData();
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2008-05-13 20:26:48 +00:00
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_SET_PARAMETERS: { // Edit parameters
|
|
|
|
if (this->sel == NULL) break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
this->query_widget = widget;
|
2008-07-17 13:47:04 +00:00
|
|
|
static char buff[512];
|
2008-05-13 20:26:48 +00:00
|
|
|
GRFBuildParamList(buff, this->sel, lastof(buff));
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParamStr(0, buff);
|
2008-09-15 16:29:40 +00:00
|
|
|
ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL, QSF_NONE);
|
2008-05-13 20:26:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-03 07:51:07 +00:00
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
case SNGRFS_TOGGLE_PALETTE:
|
2008-09-03 07:51:07 +00:00
|
|
|
if (this->sel != NULL) {
|
|
|
|
this->sel->windows_paletted ^= true;
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
break;
|
2009-01-17 16:53:32 +00:00
|
|
|
|
|
|
|
case SNGRFS_CONTENT_DOWNLOAD:
|
|
|
|
if (!_network_available) {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
|
|
|
|
} else {
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
/* Only show the things in the current list, or everything when nothing's selected */
|
|
|
|
ContentVector cv;
|
|
|
|
for (const GRFConfig *c = this->list; c != NULL; c = c->next) {
|
2009-01-23 10:20:29 +00:00
|
|
|
if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
|
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
ContentInfo *ci = new ContentInfo();
|
|
|
|
ci->type = CONTENT_TYPE_NEWGRF;
|
|
|
|
ci->state = ContentInfo::DOES_NOT_EXIST;
|
2009-01-18 19:23:41 +00:00
|
|
|
ttd_strlcpy(ci->name, c->name != NULL ? c->name : c->filename, lengthof(ci->name));
|
2009-01-17 16:53:32 +00:00
|
|
|
ci->unique_id = BSWAP32(c->grfid);
|
|
|
|
memcpy(ci->md5sum, c->md5sum, sizeof(ci->md5sum));
|
2009-01-23 15:06:56 +00:00
|
|
|
if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->grfid, ci->md5sum);
|
2009-01-17 16:53:32 +00:00
|
|
|
*cv.Append() = ci;
|
|
|
|
}
|
|
|
|
ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
|
|
|
if (index == -1) {
|
|
|
|
ClearGRFConfigList(&this->list);
|
|
|
|
this->preset = -1;
|
|
|
|
} else {
|
|
|
|
GRFConfig *c = LoadGRFPresetFromConfig(_grf_preset_list[index]);
|
|
|
|
|
|
|
|
if (c != NULL) {
|
|
|
|
this->sel = NULL;
|
|
|
|
ClearGRFConfigList(&this->list);
|
|
|
|
this->list = c;
|
|
|
|
this->preset = index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-24 18:29:01 +00:00
|
|
|
this->sel = NULL;
|
2008-07-22 14:17:29 +00:00
|
|
|
this->SetupNewGRFWindow();
|
|
|
|
this->SetDirty();
|
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
|
{
|
|
|
|
if (str == NULL) return;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
switch (this->query_widget) {
|
|
|
|
case SNGRFS_PRESET_SAVE:
|
|
|
|
SaveGRFPresetToConfig(str, this->list);
|
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
2006-12-21 10:29:16 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
/* Switch to this preset */
|
2008-07-22 20:52:30 +00:00
|
|
|
for (uint i = 0; i < _grf_preset_list.Length(); i++) {
|
2008-07-22 14:17:29 +00:00
|
|
|
if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
|
|
|
|
this->preset = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-07-22 20:52:30 +00:00
|
|
|
|
|
|
|
this->SetDirty();
|
2008-07-22 14:17:29 +00:00
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
case SNGRFS_SET_PARAMETERS: {
|
|
|
|
/* Parse our new "int list" */
|
|
|
|
GRFConfig *c = this->sel;
|
|
|
|
c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param));
|
|
|
|
|
|
|
|
/* parse_intlist returns -1 on error */
|
|
|
|
if (c->num_params == (byte)-1) c->num_params = 0;
|
|
|
|
|
|
|
|
this->preset = -1;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-03-29 09:49:11 +00:00
|
|
|
virtual void OnResize(Point delta)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
|
|
|
if (delta.x != 0) {
|
|
|
|
ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
|
|
|
|
ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->vscroll.cap += delta.y / 14;
|
|
|
|
this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;
|
2008-05-10 08:58:52 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetupNewGRFWindow();
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-01-17 16:53:32 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
2009-01-17 16:53:32 +00:00
|
|
|
switch (data) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case 0:
|
|
|
|
this->preset = -1;
|
|
|
|
this->SetupNewGRFWindow();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* Search the list for items that are now found and mark them as such. */
|
|
|
|
for (GRFConfig *c = this->list; c != NULL; c = c->next) {
|
|
|
|
if (c->status != GCS_NOT_FOUND) continue;
|
|
|
|
|
|
|
|
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
|
|
|
if (f == NULL) continue;
|
|
|
|
|
|
|
|
free(c->filename);
|
|
|
|
free(c->name);
|
|
|
|
free(c->info);
|
|
|
|
|
|
|
|
c->filename = f->filename == NULL ? NULL : strdup(f->filename);
|
|
|
|
c->name = f->name == NULL ? NULL : strdup(f->name);;
|
|
|
|
c->info = f->info == NULL ? NULL : strdup(f->info);;
|
|
|
|
c->status = GCS_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2008-05-13 20:26:48 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
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[] = {
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_MAUVE, 0, 10, 0, 13, STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW }, // SNGRFS_CLOSEBOX
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_MAUVE, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION
|
2009-04-29 20:29:19 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 299, 14, 29, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND1
|
2008-07-31 16:42:11 +00:00
|
|
|
{ WWT_DROPDOWN, RESIZE_RIGHT, COLOUR_YELLOW, 10, 103, 16, 27, STR_EMPTY, STR_NEWGRF_PRESET_LIST_TIP }, // SNGRFS_PRESET_LIST
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 104, 196, 16, 27, STR_NEWGRF_PRESET_SAVE, STR_NEWGRF_PRESET_SAVE_TIP }, // SNGRFS_PRESET_SAVE
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 197, 289, 16, 27, STR_NEWGRF_PRESET_DELETE, STR_NEWGRF_PRESET_DELETE_TIP }, // SNGRFS_PRESET_DELETE
|
2009-04-29 20:29:19 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 299, 30, 45, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND2
|
2008-07-31 16:42:11 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 10, 79, 32, 43, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 80, 149, 32, 43, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 150, 219, 32, 43, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RIGHT, COLOUR_YELLOW, 220, 289, 32, 43, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN
|
|
|
|
{ WWT_MATRIX, RESIZE_RB, COLOUR_MAUVE, 0, 287, 46, 115, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST
|
2009-04-21 23:40:56 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_MAUVE, 288, 299, 46, 115, 0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
|
2008-09-03 07:51:07 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RTB, COLOUR_MAUVE, 0, 299, 116, 238, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO
|
2009-01-17 16:53:32 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_MAUVE, 0, 99, 239, 250, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_MAUVE, 100, 199, 239, 250, STR_NEWGRF_TOGGLE_PALETTE, STR_NEWGRF_TOGGLE_PALETTE_TIP }, // SNGRFS_TOGGLE_PALETTE
|
2009-04-29 20:29:19 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_MAUVE, 200, 299, 239, 250, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_MAUVE, 0, 287, 251, 262, STR_CONTENT_INTRO_BUTTON, STR_CONTENT_INTRO_BUTTON_TIP }, // SNGRFS_CONTENT_DOWNLOAD
|
2009-02-01 22:11:46 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_MAUVE, 288, 299, 251, 262, 0x0, STR_RESIZE_BUTTON }, // SNGRFS_RESIZE
|
2006-12-04 14:27:54 +00:00
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2009-04-29 20:32:11 +00:00
|
|
|
static const NWidgetPart _nested_newgrf_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE, SNGRFS_CLOSEBOX),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE, SNGRFS_CAPTION), SetDataTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, SNGRFS_BACKGROUND1),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(2, 10, 2, 10),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_YELLOW, SNGRFS_PRESET_LIST), SetMinimalSize(94, 12), SetResize(1, 0), SetDataTip(STR_EMPTY, STR_NEWGRF_PRESET_LIST_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_PRESET_SAVE), SetMinimalSize(93, 12), SetDataTip(STR_NEWGRF_PRESET_SAVE, STR_NEWGRF_PRESET_SAVE_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_PRESET_DELETE), SetMinimalSize(93, 12), SetDataTip(STR_NEWGRF_PRESET_DELETE, STR_NEWGRF_PRESET_DELETE_TIP),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, SNGRFS_BACKGROUND2),
|
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(2, 10, 2, 10),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_ADD), SetMinimalSize(70, 12), SetDataTip(STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_REMOVE), SetMinimalSize(70, 12), SetDataTip(STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_MOVE_UP), SetMinimalSize(70, 12), SetDataTip(STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_MOVE_DOWN), SetMinimalSize(70, 12), SetDataTip(STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP), SetResize(1, 0),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, SNGRFS_FILE_LIST), SetMinimalSize(288, 70), SetDataTip(0x501, STR_NEWGRF_FILE_TIP), SetResize(1, 14),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_MAUVE, SNGRFS_SCROLLBAR),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, SNGRFS_NEWGRF_INFO), SetResize(1, 0), SetMinimalSize(300, 123), EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_SET_PARAMETERS), SetMinimalSize(100, 12), SetDataTip(STR_NEWGRF_SET_PARAMETERS, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_TOGGLE_PALETTE), SetMinimalSize(100, 12), SetResize(1, 0),
|
|
|
|
SetDataTip(STR_NEWGRF_TOGGLE_PALETTE, STR_NEWGRF_TOGGLE_PALETTE_TIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_APPLY_CHANGES), SetMinimalSize(100, 12), SetDataTip(STR_NEWGRF_APPLY_CHANGES, STR_NULL),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_CONTENT_DOWNLOAD), SetFill(1, 0), SetMinimalSize(288, 12), SetResize(1, 0),
|
|
|
|
SetDataTip(STR_CONTENT_INTRO_BUTTON, STR_CONTENT_INTRO_BUTTON_TIP),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE, SNGRFS_RESIZE),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2007-12-07 12:22:34 +00:00
|
|
|
/* Window definition of the manage newgrfs window */
|
2009-03-15 15:12:06 +00:00
|
|
|
static const WindowDesc _newgrf_desc(
|
2009-01-24 10:28:41 +00:00
|
|
|
WDP_CENTER, WDP_CENTER, 300, 263, 300, 263,
|
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,
|
2009-04-29 20:32:11 +00:00
|
|
|
_newgrf_widgets, _nested_newgrf_widgets, lengthof(_nested_newgrf_widgets)
|
2009-03-15 15:12:06 +00:00
|
|
|
);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/** Callback function for the newgrf 'apply changes' confirmation window
|
|
|
|
* @param w Window which is calling this callback
|
|
|
|
* @param confirmed boolean value, true when yes was clicked, false otherwise
|
|
|
|
*/
|
|
|
|
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
|
|
|
|
{
|
|
|
|
if (confirmed) {
|
|
|
|
NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
|
|
|
|
GRFConfig *c;
|
|
|
|
int i = 0;
|
|
|
|
|
2008-06-03 18:35:58 +00:00
|
|
|
GamelogStartAction(GLAT_GRF);
|
|
|
|
GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes
|
2008-05-13 20:26:48 +00:00
|
|
|
CopyGRFConfigList(nw->orig_list, nw->list, false);
|
|
|
|
ReloadNewGRFData();
|
2008-06-03 18:35:58 +00:00
|
|
|
GamelogStopAction();
|
2008-05-13 20:26:48 +00:00
|
|
|
|
|
|
|
/* Show new, updated list */
|
|
|
|
for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {}
|
|
|
|
CopyGRFConfigList(&nw->list, *nw->orig_list, false);
|
|
|
|
for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {}
|
|
|
|
nw->sel = c;
|
|
|
|
|
|
|
|
w->SetDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
DeleteWindowByClass(WC_GAME_OPTIONS);
|
2008-05-13 20:26:48 +00:00
|
|
|
new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|