2006-12-04 14:27:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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"
|
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-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"
|
2009-09-14 20:59:46 +00:00
|
|
|
#include "sortlist_type.h"
|
|
|
|
#include "querystring_gui.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
2009-12-15 00:00:51 +00:00
|
|
|
/**
|
|
|
|
* Show the first NewGRF error we can find.
|
|
|
|
*/
|
|
|
|
void ShowNewGRFError()
|
|
|
|
{
|
|
|
|
for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
|
|
|
/* We only want to show fatal errors */
|
|
|
|
if (c->error == NULL || c->error->severity != STR_NEWGRF_ERROR_MSG_FATAL) continue;
|
|
|
|
|
|
|
|
SetDParam (0, c->error->custom_message == NULL ? c->error->message : STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, c->error->custom_message);
|
|
|
|
SetDParam (2, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(3, c->filename);
|
|
|
|
SetDParam (4, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(5, c->error->data);
|
|
|
|
for (uint i = 0; i < c->error->num_params; i++) {
|
|
|
|
SetDParam(6 + i, c->error->param_value[i]);
|
|
|
|
}
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
|
2009-12-15 00:00:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-12 17:17:07 +00:00
|
|
|
static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, 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++) {
|
2009-05-04 11:23:21 +00:00
|
|
|
SetDParam(5 + i, c->error->param_value[i]);
|
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-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, 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-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
|
2006-12-18 12:26:55 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Prepare and draw GRF ID */
|
2010-02-25 20:05:31 +00:00
|
|
|
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, buff);
|
2009-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Prepare and draw MD5 sum */
|
2010-02-25 20:05:31 +00:00
|
|
|
md5sumToString(buff, lastof(buff), c->ident.md5sum);
|
2006-12-04 14:27:54 +00:00
|
|
|
SetDParamStr(0, buff);
|
2009-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_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-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_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-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_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-09-12 17:17:07 +00:00
|
|
|
if (c->status == GCS_NOT_FOUND) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NOT_FOUND);
|
|
|
|
if (c->status == GCS_DISABLED) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_DISABLED);
|
|
|
|
if (HasBit(c->flags, GCF_COMPATIBLE)) y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_COMPATIBLE_LOADED);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
|
|
|
/* Draw GRF info if it exists */
|
2010-02-28 20:28:08 +00:00
|
|
|
if (!StrEmpty(c->GetDescription())) {
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
2010-02-28 20:28:08 +00:00
|
|
|
SetDParamStr(1, c->GetDescription());
|
2009-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_STRING);
|
2006-12-04 14:27:54 +00:00
|
|
|
} else {
|
2009-09-12 17:17:07 +00:00
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_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 {
|
2009-09-14 20:59:46 +00:00
|
|
|
ANGRFW_FILTER,
|
2009-04-29 20:29:19 +00:00
|
|
|
ANGRFW_GRF_LIST,
|
|
|
|
ANGRFW_SCROLLBAR,
|
|
|
|
ANGRFW_GRF_INFO,
|
|
|
|
ANGRFW_ADD,
|
|
|
|
ANGRFW_RESCAN,
|
|
|
|
};
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/**
|
|
|
|
* Window for adding NewGRF files
|
|
|
|
*/
|
2009-09-14 20:59:46 +00:00
|
|
|
struct NewGRFAddWindow : public QueryStringBaseWindow {
|
|
|
|
private:
|
|
|
|
typedef GUIList<const GRFConfig *> GUIGRFConfigList;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
GRFConfig **list;
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
/** Runtime saved values */
|
|
|
|
static Listing last_sorting;
|
|
|
|
static Filtering last_filtering;
|
|
|
|
|
|
|
|
static GUIGRFConfigList::SortFunction * const sorter_funcs[];
|
|
|
|
static GUIGRFConfigList::FilterFunction * const filter_funcs[];
|
|
|
|
GUIGRFConfigList grfs;
|
|
|
|
|
2006-12-04 14:27:54 +00:00
|
|
|
const GRFConfig *sel;
|
2009-09-14 20:59:46 +00:00
|
|
|
int sel_pos;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
EDITBOX_MAX_SIZE = 50,
|
|
|
|
EDITBOX_MAX_LENGTH = 300,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (Re)build the grf as its amount has changed because
|
|
|
|
* an item has been added or deleted for example
|
|
|
|
*/
|
|
|
|
void BuildGrfList()
|
|
|
|
{
|
|
|
|
if (!this->grfs.NeedRebuild()) return;
|
|
|
|
|
|
|
|
/* Create temporary array of grfs to use for listing */
|
|
|
|
this->grfs.Clear();
|
|
|
|
|
|
|
|
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
|
|
|
*this->grfs.Append() = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->FilterGrfList();
|
|
|
|
this->grfs.Compact();
|
|
|
|
this->grfs.RebuildDone();
|
|
|
|
this->SortGrfList();
|
|
|
|
|
|
|
|
this->vscroll.SetCount(this->grfs.Length()); // Update the scrollbar
|
|
|
|
this->ScrollToSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort grfs by name. */
|
|
|
|
static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
|
|
|
|
{
|
2010-02-28 20:28:08 +00:00
|
|
|
return strcasecmp((*a)->GetName(), (*b)->GetName());
|
2009-09-14 20:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sort the grf list */
|
|
|
|
void SortGrfList()
|
|
|
|
{
|
|
|
|
if (!this->grfs.Sort()) return;
|
2010-01-03 15:25:51 +00:00
|
|
|
this->UpdateListPosition();
|
|
|
|
}
|
2009-09-14 20:59:46 +00:00
|
|
|
|
2010-01-03 15:25:51 +00:00
|
|
|
/** Update selection position. */
|
|
|
|
void UpdateListPosition()
|
|
|
|
{
|
2009-09-14 20:59:46 +00:00
|
|
|
/* update list position */
|
|
|
|
if (this->sel != NULL) {
|
|
|
|
this->sel_pos = this->grfs.FindIndex(this->sel);
|
|
|
|
if (this->sel_pos < 0) {
|
|
|
|
this->sel = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Filter grfs by tags/name */
|
|
|
|
static bool CDECL TagNameFilter(const GRFConfig * const *a, const char *filter_string)
|
|
|
|
{
|
2010-02-28 20:28:08 +00:00
|
|
|
if (strcasestr((*a)->GetName(), filter_string) != NULL) return true;
|
2009-09-14 20:59:46 +00:00
|
|
|
if ((*a)->filename != NULL && strcasestr((*a)->filename, filter_string) != NULL) return true;
|
2010-02-28 20:28:08 +00:00
|
|
|
if ((*a)->GetDescription() != NULL && strcasestr((*a)->GetDescription(), filter_string) != NULL) return true;
|
2009-09-14 20:59:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-14 20:59:46 +00:00
|
|
|
/** Filter the grf list */
|
|
|
|
void FilterGrfList()
|
|
|
|
{
|
|
|
|
if (!this->grfs.Filter(this->edit_str_buf)) return;
|
2010-01-03 15:25:51 +00:00
|
|
|
this->UpdateListPosition();
|
2009-09-14 20:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Make sure that the currently selected grf is within the visible part of the list */
|
|
|
|
void ScrollToSelected()
|
|
|
|
{
|
|
|
|
if (this->sel_pos >= 0) {
|
|
|
|
this->vscroll.ScrollTowards(this->sel_pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2009-09-17 12:34:00 +00:00
|
|
|
NewGRFAddWindow(const WindowDesc *desc, Window *parent, GRFConfig **list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
2009-09-17 12:34:00 +00:00
|
|
|
this->parent = parent;
|
2009-09-12 18:40:02 +00:00
|
|
|
this->InitNested(desc, 0);
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
|
|
|
|
this->SetFocusedWidget(ANGRFW_FILTER);
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
this->list = list;
|
2009-09-14 20:59:46 +00:00
|
|
|
this->grfs.SetListing(this->last_sorting);
|
|
|
|
this->grfs.SetFiltering(this->last_filtering);
|
|
|
|
this->grfs.SetSortFuncs(this->sorter_funcs);
|
|
|
|
this->grfs.SetFilterFuncs(this->filter_funcs);
|
|
|
|
|
2009-09-12 18:40:02 +00:00
|
|
|
this->OnInvalidateData(0);
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-12 18:40:02 +00:00
|
|
|
virtual void OnInvalidateData(int data)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
2009-09-14 20:59:46 +00:00
|
|
|
/* data == 0: NewGRFS were rescanned. All pointers to GrfConfigs are invalid.
|
|
|
|
* data == 1: User interaction with this window: Filter or selection change. */
|
|
|
|
if (data == 0) {
|
|
|
|
this->sel = NULL;
|
|
|
|
this->sel_pos = -1;
|
|
|
|
this->grfs.ForceRebuild();
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-14 20:59:46 +00:00
|
|
|
this->BuildGrfList();
|
2008-05-13 20:26:48 +00:00
|
|
|
this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF());
|
2009-09-12 18:40:02 +00:00
|
|
|
}
|
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2009-09-12 18:40:02 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case ANGRFW_GRF_LIST:
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL;
|
|
|
|
size->height = max(size->height, WD_FRAMERECT_TOP + 10 * resize->height + WD_FRAMERECT_BOTTOM + padding.height + 2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANGRFW_GRF_INFO:
|
|
|
|
size->height = max(size->height, WD_FRAMERECT_TOP + 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + padding.height + 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-09-12 18:40:02 +00:00
|
|
|
{
|
2009-12-20 20:08:39 +00:00
|
|
|
this->vscroll.SetCapacityFromWidget(this, ANGRFW_GRF_LIST);
|
2009-09-12 18:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2008-05-17 12:48:06 +00:00
|
|
|
this->DrawWidgets();
|
2009-09-14 20:59:46 +00:00
|
|
|
this->DrawEditBox(ANGRFW_FILTER);
|
2009-09-12 18:40:02 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-12 18:40:02 +00:00
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case ANGRFW_GRF_LIST: {
|
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-12 18:40:02 +00:00
|
|
|
uint y = r.top + WD_FRAMERECT_TOP;
|
2009-09-19 16:22:49 +00:00
|
|
|
uint min_index = this->vscroll.GetPosition();
|
|
|
|
uint max_index = min(min_index + this->vscroll.GetCapacity(), this->grfs.Length());
|
2009-09-14 20:59:46 +00:00
|
|
|
|
2009-09-19 16:22:49 +00:00
|
|
|
for (uint i = min_index; i < max_index; i++)
|
2009-09-14 20:59:46 +00:00
|
|
|
{
|
|
|
|
const GRFConfig *c = this->grfs[i];
|
|
|
|
bool h = c == this->sel;
|
2010-02-28 20:28:08 +00:00
|
|
|
const char *text = c->GetName();
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
/* Draw selection background */
|
|
|
|
if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + this->resize.step_height - 1, 156);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, text, h ? TC_WHITE : TC_ORANGE);
|
|
|
|
y += this->resize.step_height;
|
2009-09-12 18:40:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 18:40:02 +00:00
|
|
|
case ANGRFW_GRF_INFO:
|
|
|
|
if (this->sel != NULL) {
|
|
|
|
ShowNewGRFInfo(this->sel, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, r.bottom - WD_FRAMERECT_BOTTOM, false);
|
|
|
|
}
|
|
|
|
break;
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case ANGRFW_GRF_LIST: {
|
|
|
|
/* Get row... */
|
2009-09-19 11:31:12 +00:00
|
|
|
uint i = (pt.y - this->GetWidget<NWidgetBase>(ANGRFW_GRF_LIST)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height + this->vscroll.GetPosition();
|
2008-05-13 20:26:48 +00:00
|
|
|
|
2009-09-14 20:59:46 +00:00
|
|
|
if (i < this->grfs.Length()) {
|
|
|
|
this->sel = this->grfs[i];
|
|
|
|
this->sel_pos = i;
|
|
|
|
} else {
|
|
|
|
this->sel = NULL;
|
|
|
|
this->sel_pos = -1;
|
|
|
|
}
|
2009-09-30 21:00:35 +00:00
|
|
|
this->InvalidateData(1);
|
2010-01-30 18:34:48 +00:00
|
|
|
if (click_count == 1) break;
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2010-01-30 18:34:48 +00:00
|
|
|
/* FALL THROUGH */
|
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) {
|
2010-02-25 20:05:31 +00:00
|
|
|
if ((*list)->ident.grfid == src->ident.grfid) {
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
|
2008-05-13 20:26:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
/* Copy GRF details from scanned list */
|
2010-01-15 18:28:30 +00:00
|
|
|
GRFConfig *c = DuplicateGRFConfig(src);
|
2010-01-15 20:20:24 +00:00
|
|
|
c->next = NULL;
|
2008-05-13 20:26:48 +00:00
|
|
|
|
|
|
|
/* Append GRF config to configuration list */
|
|
|
|
*list = c;
|
|
|
|
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
2009-09-30 21:11:29 +00:00
|
|
|
InvalidateWindowData(WC_GAME_OPTIONS, 0, 2);
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ANGRFW_RESCAN: // Rescan list
|
|
|
|
ScanNewGRFFiles();
|
2009-09-30 21:00:35 +00:00
|
|
|
this->InvalidateData();
|
2009-09-14 20:59:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnMouseLoop()
|
|
|
|
{
|
|
|
|
this->HandleEditBox(ANGRFW_FILTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual EventState OnKeyPress(uint16 key, uint16 keycode)
|
|
|
|
{
|
|
|
|
switch (keycode) {
|
|
|
|
case WKC_UP:
|
|
|
|
/* scroll up by one */
|
|
|
|
if (this->sel_pos > 0) this->sel_pos--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_DOWN:
|
|
|
|
/* scroll down by one */
|
|
|
|
if (this->sel_pos < (int)this->grfs.Length() - 1) this->sel_pos++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_PAGEUP:
|
|
|
|
/* scroll up a page */
|
|
|
|
this->sel_pos = (this->sel_pos < this->vscroll.GetCapacity()) ? 0 : this->sel_pos - this->vscroll.GetCapacity();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_PAGEDOWN:
|
|
|
|
/* scroll down a page */
|
|
|
|
this->sel_pos = min(this->sel_pos + this->vscroll.GetCapacity(), (int)this->grfs.Length() - 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_HOME:
|
|
|
|
/* jump to beginning */
|
|
|
|
this->sel_pos = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WKC_END:
|
|
|
|
/* jump to end */
|
|
|
|
this->sel_pos = this->grfs.Length() - 1;
|
2008-05-13 20:26:48 +00:00
|
|
|
break;
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
default: {
|
|
|
|
/* Handle editbox input */
|
|
|
|
EventState state = ES_NOT_HANDLED;
|
|
|
|
if (this->HandleEditBoxKey(ANGRFW_FILTER, key, keycode, state) == HEBR_EDITING) {
|
|
|
|
this->OnOSKInput(ANGRFW_FILTER);
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->grfs.Length() == 0) this->sel_pos = -1;
|
|
|
|
if (this->sel_pos >= 0) {
|
|
|
|
this->sel = this->grfs[this->sel_pos];
|
|
|
|
|
|
|
|
this->ScrollToSelected();
|
2009-09-30 21:00:35 +00:00
|
|
|
this->InvalidateData(1);
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
return ES_HANDLED;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2009-09-14 20:59:46 +00:00
|
|
|
|
|
|
|
virtual void OnOSKInput(int wid)
|
|
|
|
{
|
|
|
|
this->grfs.SetFilterState(!StrEmpty(this->edit_str_buf));
|
|
|
|
this->grfs.ForceRebuild();
|
2009-09-30 21:00:35 +00:00
|
|
|
this->InvalidateData(1);
|
2009-09-14 20:59:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Listing NewGRFAddWindow::last_sorting = {false, 0};
|
|
|
|
Filtering NewGRFAddWindow::last_filtering = {false, 0};
|
|
|
|
|
|
|
|
NewGRFAddWindow::GUIGRFConfigList::SortFunction * const NewGRFAddWindow::sorter_funcs[] = {
|
|
|
|
&NameSorter,
|
|
|
|
};
|
|
|
|
|
|
|
|
NewGRFAddWindow::GUIGRFConfigList::FilterFunction * const NewGRFAddWindow::filter_funcs[] = {
|
|
|
|
&TagNameFilter,
|
2008-05-13 20:26:48 +00:00
|
|
|
};
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-04-29 20:32:11 +00:00
|
|
|
static const NWidgetPart _nested_newgrf_add_dlg_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NEWGRF_ADD_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0),
|
2009-09-14 20:59:46 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0), SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_LIST_FILTER_TITLE, STR_NULL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_EDITBOX, COLOUR_GREY, ANGRFW_FILTER), SetFill(1, 0), SetMinimalSize(100, 12), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
|
2009-09-14 20:59:46 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-04-29 20:32:11 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2009-09-12 18:40:02 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_GREY, ANGRFW_GRF_LIST), SetMinimalSize(290, 1), SetResize(1, 1), SetPadding(2, 2, 2, 2), EndContainer(),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_GREY, ANGRFW_SCROLLBAR),
|
|
|
|
EndContainer(),
|
2009-09-12 18:40:02 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, ANGRFW_GRF_INFO), SetMinimalSize(306, 1), SetResize(1, 0), EndContainer(),
|
2009-04-29 20:32:11 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-09-12 18:40:02 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ANGRFW_ADD), SetMinimalSize(147, 12), SetResize(1, 0), SetDataTip(STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ANGRFW_RESCAN), SetMinimalSize(147, 12), SetResize(1, 0), SetDataTip(STR_NEWGRF_ADD_RESCAN_FILES, STR_NEWGRF_ADD_RESCAN_FILES_TOOLTIP),
|
|
|
|
EndContainer(),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2009-04-29 20:32:11 +00:00
|
|
|
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(
|
2009-11-28 14:42:35 +00:00
|
|
|
WDP_CENTER, 306, 347,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_SAVELOAD, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_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_PRESET_LIST,
|
|
|
|
SNGRFS_PRESET_SAVE,
|
|
|
|
SNGRFS_PRESET_DELETE,
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2009-09-30 21:49:24 +00:00
|
|
|
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window()
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2009-09-30 21:49:24 +00:00
|
|
|
this->InitNested(desc);
|
2009-09-30 21:11:29 +00:00
|
|
|
this->OnInvalidateData(2);
|
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
|
|
|
|
2009-11-22 18:28:14 +00:00
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
2009-09-30 21:49:24 +00:00
|
|
|
switch (widget) {
|
|
|
|
case SNGRFS_FILE_LIST:
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
size->height = max(size->height, 7 * resize->height);
|
|
|
|
break;
|
2007-03-06 19:33:28 +00:00
|
|
|
|
2009-09-30 21:49:24 +00:00
|
|
|
case SNGRFS_NEWGRF_INFO:
|
|
|
|
size->height = max(size->height, WD_FRAMERECT_TOP + 10 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM + padding.height + 2);
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-30 21:49:24 +00:00
|
|
|
case SNGRFS_PRESET_LIST: {
|
|
|
|
Dimension d = GetStringBoundingBox(STR_NUM_CUSTOM);
|
|
|
|
for (uint i = 0; i < _grf_preset_list.Length(); i++) {
|
|
|
|
if (_grf_preset_list[i] != NULL) {
|
|
|
|
SetDParamStr(0, _grf_preset_list[i]);
|
|
|
|
d = maxdim(d, GetStringBoundingBox(STR_JUST_RAW_STRING));
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
2009-09-30 21:49:24 +00:00
|
|
|
d.width += padding.width;
|
|
|
|
*size = maxdim(d, *size);
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-30 21:49:24 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-10-24 14:53:55 +00:00
|
|
|
virtual void OnResize()
|
2009-09-30 21:49:24 +00:00
|
|
|
{
|
2009-12-20 20:08:39 +00:00
|
|
|
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-09-30 21:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case SNGRFS_PRESET_LIST:
|
|
|
|
if (this->preset == -1) {
|
|
|
|
SetDParam(0, STR_NUM_CUSTOM);
|
|
|
|
} else {
|
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, _grf_preset_list[this->preset]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case SNGRFS_FILE_LIST: {
|
|
|
|
uint y = r.top + WD_MATRIX_TOP;
|
2009-11-22 14:15:50 +00:00
|
|
|
int sprite_offset_y = (FONT_HEIGHT_NORMAL - 10) / 2 - 1;
|
2009-09-30 21:49:24 +00:00
|
|
|
|
2009-11-19 15:45:08 +00:00
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
|
uint text_left = rtl ? r.left + WD_FRAMERECT_LEFT : r.left + 25;
|
|
|
|
uint text_right = rtl ? r.right - 25 : r.right - WD_FRAMERECT_RIGHT;
|
|
|
|
uint square_left = rtl ? r.right - 15 : r.left + 5;
|
|
|
|
uint warning_left = rtl ? r.right - 30 : r.left + 20;
|
|
|
|
|
2009-09-30 21:49:24 +00:00
|
|
|
int i = 0;
|
|
|
|
for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
|
|
|
|
if (this->vscroll.IsVisible(i)) {
|
2010-02-28 20:28:08 +00:00
|
|
|
const char *text = c->GetName();
|
2010-01-21 01:38:13 +00:00
|
|
|
PaletteID pal;
|
2009-09-30 21:49:24 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 14:15:50 +00:00
|
|
|
DrawSprite(SPR_SQUARE, pal, square_left, y + sprite_offset_y);
|
|
|
|
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, warning_left, y + sprite_offset_y);
|
2009-11-19 15:45:08 +00:00
|
|
|
uint txtoffset = c->error == NULL ? 0 : 10;
|
|
|
|
DrawString(text_left + (rtl ? 0 : txtoffset), text_right - (rtl ? txtoffset : 0), y, text, this->sel == c ? TC_WHITE : TC_BLACK);
|
2009-09-30 21:49:24 +00:00
|
|
|
y += this->resize.step_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case SNGRFS_NEWGRF_INFO:
|
|
|
|
if (this->sel != NULL) {
|
2009-11-22 14:58:27 +00:00
|
|
|
ShowNewGRFInfo(this->sel, r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, r.right - WD_FRAMERECT_RIGHT, r.bottom - WD_FRAMERECT_BOTTOM, this->show_params);
|
2009-09-30 21:49:24 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2010-01-30 18:34:48 +00:00
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
|
|
|
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;
|
2009-08-05 17:59:21 +00:00
|
|
|
ShowQueryString(STR_EMPTY, STR_NEWGRF_SETTINGS_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;
|
2009-09-30 21:11:29 +00:00
|
|
|
this->InvalidateData();
|
2008-07-22 14:17:29 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-13 20:26:48 +00:00
|
|
|
case SNGRFS_ADD: // Add GRF
|
|
|
|
DeleteWindowByClass(WC_SAVELOAD);
|
2009-09-17 12:34:00 +00:00
|
|
|
new NewGRFAddWindow(&_newgrf_add_dlg_desc, this, &this->list);
|
2008-05-13 20:26:48 +00:00
|
|
|
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;
|
2010-01-29 15:50:56 +00:00
|
|
|
this->InvalidateData(3);
|
2009-10-31 14:53:19 +00:00
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
2008-05-13 20:26:48 +00:00
|
|
|
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
|
|
|
|
2010-01-29 15:45:53 +00:00
|
|
|
int pos = 0;
|
|
|
|
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) {
|
2008-05-13 20:26:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2010-01-29 15:45:53 +00:00
|
|
|
this->vscroll.ScrollTowards(pos);
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2009-09-30 21:11:29 +00:00
|
|
|
this->InvalidateData();
|
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_MOVE_DOWN: { // Move GRF down
|
|
|
|
GRFConfig **pc, *c;
|
|
|
|
if (this->sel == NULL) break;
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2010-01-29 15:45:53 +00:00
|
|
|
int pos = 1; // Start at 1 as we swap the selected newgrf with the next one
|
|
|
|
for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) {
|
2008-05-13 20:26:48 +00:00
|
|
|
if (c == this->sel) {
|
|
|
|
*pc = c->next;
|
|
|
|
c->next = c->next->next;
|
|
|
|
(*pc)->next = c;
|
|
|
|
break;
|
2006-12-04 14:27:54 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-29 15:45:53 +00:00
|
|
|
this->vscroll.ScrollTowards(pos);
|
2008-07-22 14:17:29 +00:00
|
|
|
this->preset = -1;
|
2009-09-30 21:11:29 +00:00
|
|
|
this->InvalidateData();
|
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_FILE_LIST: { // Select a GRF
|
|
|
|
GRFConfig *c;
|
2009-09-30 21:49:24 +00:00
|
|
|
uint i = (pt.y - this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition();
|
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--) {}
|
2009-10-31 14:53:19 +00:00
|
|
|
|
|
|
|
if (this->sel != c) this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
2008-05-13 20:26:48 +00:00
|
|
|
this->sel = c;
|
|
|
|
|
2009-09-30 21:11:29 +00:00
|
|
|
this->InvalidateData();
|
2010-01-30 18:34:48 +00:00
|
|
|
if (click_count > 1) this->OnClick(pt, SNGRFS_SET_PARAMETERS, 1);
|
2008-05-13 20:26:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
|
|
|
|
if (this->execute) {
|
|
|
|
ShowQuery(
|
2009-08-05 17:59:21 +00:00
|
|
|
STR_NEWGRF_POPUP_CAUTION_CAPTION,
|
2008-05-13 20:26:48 +00:00
|
|
|
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);
|
2009-10-31 14:06:16 +00:00
|
|
|
ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_SETTINGS_PARAMETER_QUERY, 63, 250, this, CS_NUMERAL_SPACE, 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) {
|
2010-02-24 14:46:15 +00:00
|
|
|
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
2009-01-17 16:53:32 +00:00
|
|
|
} 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;
|
2010-02-28 20:28:08 +00:00
|
|
|
ttd_strlcpy(ci->name, c->GetName(), lengthof(ci->name));
|
2010-02-25 20:05:31 +00:00
|
|
|
ci->unique_id = BSWAP32(c->ident.grfid);
|
|
|
|
memcpy(ci->md5sum, c->ident.md5sum, sizeof(ci->md5sum));
|
|
|
|
if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->ident.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;
|
2009-09-30 21:11:29 +00:00
|
|
|
this->InvalidateData(3);
|
2008-07-22 14:17:29 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2009-09-30 21:11:29 +00:00
|
|
|
default: NOT_REACHED();
|
|
|
|
|
2008-07-22 14:17:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2010-04-07 20:28:02 +00:00
|
|
|
c->num_params = ParseIntList(str, (int*)c->param, lengthof(c->param));
|
2008-07-22 14:17:29 +00:00
|
|
|
|
2010-04-07 20:28:02 +00:00
|
|
|
/* ParseIntList() returns -1 on error */
|
2008-07-22 14:17:29 +00:00
|
|
|
if (c->num_params == (byte)-1) c->num_params = 0;
|
|
|
|
|
|
|
|
this->preset = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-30 21:11:29 +00:00
|
|
|
|
|
|
|
this->InvalidateData();
|
2008-05-13 20:26:48 +00:00
|
|
|
}
|
2006-12-04 14:27:54 +00:00
|
|
|
|
2009-09-30 21:11:29 +00:00
|
|
|
virtual void OnInvalidateData(int data = 0)
|
2008-05-13 20:26:48 +00:00
|
|
|
{
|
2009-01-17 16:53:32 +00:00
|
|
|
switch (data) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case 0:
|
2009-09-30 21:11:29 +00:00
|
|
|
/* Nothing important to do */
|
2009-01-17 16:53:32 +00:00
|
|
|
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;
|
|
|
|
|
2010-02-25 20:05:31 +00:00
|
|
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
2009-01-17 16:53:32 +00:00
|
|
|
if (f == NULL) continue;
|
|
|
|
|
|
|
|
free(c->filename);
|
|
|
|
free(c->name);
|
|
|
|
free(c->info);
|
|
|
|
|
|
|
|
c->filename = f->filename == NULL ? NULL : strdup(f->filename);
|
2010-02-14 16:31:35 +00:00
|
|
|
c->name = f->name == NULL ? NULL : strdup(f->name);
|
|
|
|
c->info = f->info == NULL ? NULL : strdup(f->info);
|
2009-01-17 16:53:32 +00:00
|
|
|
c->status = GCS_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
2009-09-30 21:11:29 +00:00
|
|
|
|
|
|
|
case 2:
|
|
|
|
this->preset = -1;
|
|
|
|
/* Fall through */
|
|
|
|
case 3:
|
|
|
|
const GRFConfig *c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
|
|
|
|
|
2009-12-20 20:08:39 +00:00
|
|
|
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
2009-09-30 21:49:24 +00:00
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
2009-09-30 21:11:29 +00:00
|
|
|
this->vscroll.SetCount(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->SetWidgetsDisabledState(!this->editable,
|
|
|
|
SNGRFS_PRESET_LIST,
|
|
|
|
SNGRFS_ADD,
|
|
|
|
SNGRFS_APPLY_CHANGES,
|
|
|
|
SNGRFS_TOGGLE_PALETTE,
|
|
|
|
WIDGET_LIST_END
|
|
|
|
);
|
|
|
|
|
|
|
|
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);
|
|
|
|
this->SetWidgetDisabledState(SNGRFS_TOGGLE_PALETTE, disable_all);
|
|
|
|
|
|
|
|
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);
|
2009-01-17 16:53:32 +00:00
|
|
|
}
|
2009-09-30 21:11:29 +00:00
|
|
|
|
|
|
|
this->SetWidgetDisabledState(SNGRFS_PRESET_DELETE, this->preset == -1);
|
|
|
|
|
|
|
|
bool has_missing = false;
|
|
|
|
bool has_compatible = false;
|
|
|
|
for (const GRFConfig *c = this->list; !has_missing && c != NULL; c = c->next) {
|
|
|
|
has_missing |= c->status == GCS_NOT_FOUND;
|
|
|
|
has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
|
|
|
|
}
|
|
|
|
if (has_missing || has_compatible) {
|
2009-09-30 21:49:24 +00:00
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_CONTENT_DOWNLOAD)->widget_data = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON;
|
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_CONTENT_DOWNLOAD)->tool_tip = STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP;
|
2009-09-30 21:11:29 +00:00
|
|
|
} else {
|
2009-09-30 21:49:24 +00:00
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_CONTENT_DOWNLOAD)->widget_data = STR_INTRO_ONLINE_CONTENT;
|
|
|
|
this->GetWidget<NWidgetCore>(SNGRFS_CONTENT_DOWNLOAD)->tool_tip = STR_INTRO_TOOLTIP_ONLINE_CONTENT;
|
2009-09-30 21:11:29 +00:00
|
|
|
}
|
|
|
|
this->SetWidgetDisabledState(SNGRFS_PRESET_SAVE, has_missing);
|
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 */
|
2009-04-29 20:32:11 +00:00
|
|
|
static const NWidgetPart _nested_newgrf_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_SETTINGS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE),
|
2009-04-29 20:32:11 +00:00
|
|
|
NWidget(NWID_HORIZONTAL), SetPadding(2, 10, 2, 10),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_YELLOW, SNGRFS_PRESET_LIST), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_JUST_STRING, STR_NEWGRF_SETTINGS_PRESET_LIST_TOOLTIP),
|
2009-09-30 21:49:24 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_PRESET_SAVE), SetFill(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_PRESET_SAVE, STR_NEWGRF_SETTINGS_PRESET_SAVE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_PRESET_DELETE), SetFill(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_PRESET_DELETE, STR_NEWGRF_SETTINGS_PRESET_DELETE_TOOLTIP),
|
2009-09-30 21:49:24 +00:00
|
|
|
EndContainer(),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
2009-11-24 21:13:36 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE),
|
2009-09-30 21:49:24 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(2, 10, 2, 10),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_ADD), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_ADD, STR_NEWGRF_SETTINGS_ADD_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_REMOVE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_REMOVE, STR_NEWGRF_SETTINGS_REMOVE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_MOVE_UP), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_MOVEUP, STR_NEWGRF_SETTINGS_MOVEUP_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, SNGRFS_MOVE_DOWN), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_MOVEDOWN, STR_NEWGRF_SETTINGS_MOVEDOWN_TOOLTIP),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, SNGRFS_FILE_LIST), SetFill(1, 0), SetDataTip(0x501, STR_NEWGRF_SETTINGS_FILE_TOOLTIP), SetResize(1, 0),
|
2009-04-29 20:32:11 +00:00
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_MAUVE, SNGRFS_SCROLLBAR),
|
|
|
|
EndContainer(),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, SNGRFS_NEWGRF_INFO), SetFill(1, 0), SetResize(1, 0), EndContainer(),
|
2009-09-30 21:49:24 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_SET_PARAMETERS), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_TOGGLE_PALETTE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_TOGGLE_PALETTE, STR_NEWGRF_SETTINGS_TOGGLE_PALETTE_TOOLTIP),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_APPLY_CHANGES), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_APPLY_CHANGES, STR_NULL),
|
2009-04-29 20:32:11 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2009-11-22 18:26:01 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, SNGRFS_CONTENT_DOWNLOAD), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
|
2009-11-24 18:05:55 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
2009-04-29 20:32:11 +00:00
|
|
|
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-11-28 14:42:35 +00:00
|
|
|
WDP_CENTER, 300, 263,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_GAME_OPTIONS, WC_NONE,
|
2009-11-24 17:28:29 +00:00
|
|
|
WDF_UNCLICK_BUTTONS,
|
2009-11-15 10:26:01 +00:00
|
|
|
_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
|
|
|
}
|