|
|
/* $Id$ */
|
|
|
|
|
|
/*
|
|
|
* 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/>.
|
|
|
*/
|
|
|
|
|
|
/** @file newgrf_gui.cpp GUI to change NewGRF settings. */
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "gui.h"
|
|
|
#include "newgrf.h"
|
|
|
#include "strings_func.h"
|
|
|
#include "window_func.h"
|
|
|
#include "gamelog.h"
|
|
|
#include "settings_func.h"
|
|
|
#include "widgets/dropdown_type.h"
|
|
|
#include "network/network.h"
|
|
|
#include "network/network_content.h"
|
|
|
#include "sortlist_type.h"
|
|
|
#include "querystring_gui.h"
|
|
|
#include "core/geometry_func.hpp"
|
|
|
#include "newgrf_text.h"
|
|
|
|
|
|
#include "table/strings.h"
|
|
|
#include "table/sprites.h"
|
|
|
|
|
|
/**
|
|
|
* 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]);
|
|
|
}
|
|
|
ShowErrorMessage(STR_NEWGRF_ERROR_FATAL_POPUP, INVALID_STRING_ID, WL_CRITICAL);
|
|
|
break;
|
|
@@ -94,48 +95,285 @@ static void ShowNewGRFInfo(const GRFConf
|
|
|
SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
|
|
|
}
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PARAMETER);
|
|
|
|
|
|
/* Draw the palette of the NewGRF */
|
|
|
SetDParamStr(0, (c->palette & GRFP_USE_WINDOWS) ? "Windows" : "DOS");
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_PALETTE);
|
|
|
}
|
|
|
|
|
|
/* Show flags */
|
|
|
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);
|
|
|
|
|
|
/* Draw GRF info if it exists */
|
|
|
if (!StrEmpty(c->GetDescription())) {
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
SetDParamStr(1, c->GetDescription());
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_BLACK_STRING);
|
|
|
} else {
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_NO_INFO);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/** Enum referring to the widgets of the NewGRF parameters window */
|
|
|
enum ShowNewGRFParametersWidgets {
|
|
|
GRFPAR_WIDGET_BACKGROUND, ///< Panel to draw the settings on
|
|
|
GRFPAR_WIDGET_SCROLLBAR, ///< Scrollbar to scroll through all settings
|
|
|
GRFPAR_WIDGET_ACCEPT, ///< Accept button
|
|
|
GRFPAR_WIDGET_DESCRIPTION, ///< Multi-line description of a parameter
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* Window for setting the parameters of a NewGRF.
|
|
|
*/
|
|
|
struct NewGRFParametersWindow : public Window {
|
|
|
static GRFParameterInfo dummy_parameter_info; ///< Dummy info in case a newgrf didn't provide info about some parameter.
|
|
|
GRFConfig *grf_config; ///< Set the parameters of this GRFConfig.
|
|
|
uint clicked_button; ///< The row in which a button was clicked or UINT_MAX.
|
|
|
bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button.
|
|
|
int timeout; ///< How long before we unpress the last-pressed button?
|
|
|
uint clicked_row; ///< The selected parameter
|
|
|
int line_height; ///< Height of a row in the matrix widget.
|
|
|
|
|
|
NewGRFParametersWindow(const WindowDesc *desc, GRFConfig *c) : Window(),
|
|
|
grf_config(c),
|
|
|
clicked_button(UINT_MAX),
|
|
|
timeout(0),
|
|
|
clicked_row(UINT_MAX)
|
|
|
{
|
|
|
this->InitNested(desc); // Initializes 'this->line_height' as side effect.
|
|
|
|
|
|
this->vscroll.SetCount(c->num_valid_params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get a dummy parameter-info object with default information.
|
|
|
* @param nr The param number that should be changed.
|
|
|
* @return GRFParameterInfo with dummy information about the given parameter.
|
|
|
*/
|
|
|
static GRFParameterInfo *GetDummyParameterInfo(uint nr)
|
|
|
{
|
|
|
dummy_parameter_info.param_nr = nr;
|
|
|
return &dummy_parameter_info;
|
|
|
}
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case GRFPAR_WIDGET_BACKGROUND:
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
|
|
|
|
|
|
resize->width = 1;
|
|
|
resize->height = this->line_height;
|
|
|
size->height = GB(this->GetWidget<NWidgetCore>(widget)->widget_data, MAT_ROW_START, MAT_ROW_BITS) * this->line_height;
|
|
|
break;
|
|
|
|
|
|
case GRFPAR_WIDGET_DESCRIPTION:
|
|
|
size->height = max<uint>(size->height, FONT_HEIGHT_NORMAL * 4 + WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
}
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
{
|
|
|
if (widget == GRFPAR_WIDGET_DESCRIPTION) {
|
|
|
const GRFParameterInfo *par_info = (this->clicked_row < this->grf_config->param_info.Length()) ? this->grf_config->param_info[this->clicked_row] : NULL;
|
|
|
if (par_info == NULL) return;
|
|
|
const char *desc = GetGRFStringFromGRFText(par_info->desc);
|
|
|
if (desc == NULL) return;
|
|
|
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_TEXTPANEL_TOP, r.bottom - WD_TEXTPANEL_BOTTOM, desc, TC_BLACK);
|
|
|
return;
|
|
|
} else if (widget != GRFPAR_WIDGET_BACKGROUND) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
uint buttons_left = rtl ? r.right - 23 : r.left + 4;
|
|
|
uint value_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
|
|
|
uint value_right = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
|
|
|
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 54);
|
|
|
uint text_right = r.right - (rtl ? 54 : WD_FRAMERECT_RIGHT);
|
|
|
|
|
|
int y = r.top;
|
|
|
for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->grf_config->num_valid_params; i++) {
|
|
|
GRFParameterInfo *par_info = (i < this->grf_config->param_info.Length()) ? this->grf_config->param_info[i] : NULL;
|
|
|
if (par_info == NULL) par_info = GetDummyParameterInfo(i);
|
|
|
uint32 current_value = par_info->GetValue(this->grf_config);
|
|
|
bool selected = (i == this->clicked_row);
|
|
|
|
|
|
uint x = rtl ? r.right : r.left;
|
|
|
if (par_info->type == PTYPE_BOOL) {
|
|
|
DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
|
|
|
} else if (par_info->type == PTYPE_UINT_ENUM) {
|
|
|
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
|
|
|
bool draw_numeric = true;
|
|
|
if (par_info->value_names.Find(current_value) != par_info->value_names.End()) {
|
|
|
const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second);
|
|
|
if (label != NULL) {
|
|
|
x = DrawString(value_left, value_right, y + WD_MATRIX_TOP, label, TC_ORANGE);
|
|
|
draw_numeric = false;
|
|
|
}
|
|
|
}
|
|
|
if (draw_numeric) {
|
|
|
SetDParam(0, current_value);
|
|
|
x = DrawString(value_left, value_right, y + WD_MATRIX_TOP, STR_JUST_INT, TC_ORANGE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const char *name = GetGRFStringFromGRFText(par_info->name);
|
|
|
if (name != NULL) {
|
|
|
DrawString(max(rtl ? 0U : x + 3, text_left), min(rtl ? x - 3 : r.right, text_right), y + WD_MATRIX_TOP, name, selected ? TC_WHITE : TC_LIGHT_BLUE);
|
|
|
} else {
|
|
|
SetDParam(0, i + 1);
|
|
|
DrawString(max(rtl ? 0U : x + 3, text_left), min(rtl ? x - 3 : r.right, text_right), y + WD_MATRIX_TOP, STR_NEWGRF_PARAMETERS_DEFAULT_NAME, selected ? TC_WHITE : TC_LIGHT_BLUE);
|
|
|
}
|
|
|
y += this->line_height;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case GRFPAR_WIDGET_BACKGROUND: {
|
|
|
uint num = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRFPAR_WIDGET_BACKGROUND);
|
|
|
if (num >= this->grf_config->num_valid_params) break;
|
|
|
if (this->clicked_row != num) {
|
|
|
DeleteChildWindows(WC_QUERY_STRING);
|
|
|
this->clicked_row = num;
|
|
|
}
|
|
|
|
|
|
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(GRFPAR_WIDGET_BACKGROUND);
|
|
|
int x = pt.x - wid->pos_x;
|
|
|
if (_dynlang.text_dir == TD_RTL) x = wid->current_x - x;
|
|
|
x -= 4;
|
|
|
|
|
|
GRFParameterInfo *par_info = (num < this->grf_config->param_info.Length()) ? this->grf_config->param_info[num] : NULL;
|
|
|
if (par_info == NULL) par_info = GetDummyParameterInfo(num);
|
|
|
|
|
|
/* One of the arrows is clicked */
|
|
|
if (IsInsideMM(x, 0, 21)) {
|
|
|
uint32 val = par_info->GetValue(this->grf_config);
|
|
|
if (par_info->type == PTYPE_BOOL) {
|
|
|
val = !val;
|
|
|
} else {
|
|
|
if (x >= 10) {
|
|
|
/* Increase button clicked */
|
|
|
if (val < par_info->max_value) val++;
|
|
|
this->clicked_increase = true;
|
|
|
} else {
|
|
|
/* Decrease button clicked */
|
|
|
if (val > par_info->min_value) val--;
|
|
|
this->clicked_increase = false;
|
|
|
}
|
|
|
}
|
|
|
par_info->SetValue(this->grf_config, val);
|
|
|
|
|
|
this->clicked_button = num;
|
|
|
this->timeout = 5;
|
|
|
} else if (par_info->type == PTYPE_UINT_ENUM && click_count >= 2) {
|
|
|
/* Display a query box so users can enter a custom value. */
|
|
|
SetDParam(0, this->grf_config->param[num]);
|
|
|
ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, 100, this, CS_NUMERAL, QSF_NONE);
|
|
|
}
|
|
|
|
|
|
this->SetDirty();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case GRFPAR_WIDGET_ACCEPT:
|
|
|
delete this;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
{
|
|
|
if (StrEmpty(str)) return;
|
|
|
int32 value = atoi(str);
|
|
|
GRFParameterInfo *par_info = ((uint)this->clicked_row < this->grf_config->param_info.Length()) ? this->grf_config->param_info[this->clicked_row] : NULL;
|
|
|
if (par_info == NULL) par_info = GetDummyParameterInfo(this->clicked_row);
|
|
|
uint32 val = Clamp<uint32>(value, par_info->min_value, par_info->max_value);
|
|
|
par_info->SetValue(this->grf_config, val);
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
|
|
|
virtual void OnResize()
|
|
|
{
|
|
|
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRFPAR_WIDGET_BACKGROUND);
|
|
|
this->vscroll.SetCapacity(nwi->current_y / this->line_height);
|
|
|
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
|
|
}
|
|
|
|
|
|
virtual void OnTick()
|
|
|
{
|
|
|
if (--this->timeout == 0) {
|
|
|
this->clicked_button = UINT_MAX;
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0);
|
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_newgrf_parameter_widgets[] = {
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
|
|
|
NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_NEWGRF_PARAMETERS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
EndContainer(),
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
NWidget(WWT_MATRIX, COLOUR_MAUVE, GRFPAR_WIDGET_BACKGROUND), SetMinimalSize(188, 182), SetResize(1, 1), SetFill(1, 0), SetDataTip(0x501, STR_NULL),
|
|
|
NWidget(WWT_SCROLLBAR, COLOUR_MAUVE, GRFPAR_WIDGET_SCROLLBAR),
|
|
|
EndContainer(),
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE, GRFPAR_WIDGET_DESCRIPTION), SetResize(1, 0), SetFill(1, 0),
|
|
|
EndContainer(),
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, GRFPAR_WIDGET_ACCEPT), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_NEWGRF_PARAMETERS_CLOSE, STR_NULL),
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
|
|
EndContainer(),
|
|
|
};
|
|
|
|
|
|
/* Window definition for the change grf parameters window */
|
|
|
static const WindowDesc _newgrf_parameters_desc(
|
|
|
WDP_CENTER, 500, 208,
|
|
|
WC_GRF_PARAMETERS, WC_NONE,
|
|
|
WDF_UNCLICK_BUTTONS,
|
|
|
_nested_newgrf_parameter_widgets, lengthof(_nested_newgrf_parameter_widgets)
|
|
|
);
|
|
|
|
|
|
void OpenGRFParameterWindow(GRFConfig *c)
|
|
|
{
|
|
|
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
new NewGRFParametersWindow(&_newgrf_parameters_desc, c);
|
|
|
}
|
|
|
|
|
|
static GRFPresetList _grf_preset_list;
|
|
|
|
|
|
class DropDownListPresetItem : public DropDownListItem {
|
|
|
public:
|
|
|
DropDownListPresetItem(int result) : DropDownListItem(result, false) {}
|
|
|
|
|
|
virtual ~DropDownListPresetItem() {}
|
|
|
|
|
|
bool Selectable() const
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
|
|
|
{
|
|
|
DrawString(left + 2, right + 2, top, _grf_preset_list[this->result], sel ? TC_WHITE : TC_BLACK);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
static void NewGRFConfirmationCallback(Window *w, bool confirmed);
|
|
|
|
|
|
/** Names of the manage newgrfs window widgets. */
|
|
|
enum ShowNewGRFStateWidgets {
|
|
|
SNGRFS_PRESET_LIST,
|
|
@@ -163,81 +401,82 @@ enum ShowNewGRFStateWidgets {
|
|
|
* Window for showing NewGRF files
|
|
|
*/
|
|
|
struct NewGRFWindow : public QueryStringBaseWindow {
|
|
|
typedef GUIList<const GRFConfig *> GUIGRFConfigList;
|
|
|
|
|
|
static const uint EDITBOX_MAX_SIZE = 50;
|
|
|
static const uint EDITBOX_MAX_LENGTH = 300;
|
|
|
|
|
|
static Listing last_sorting; ///< Default sorting of #GUIGRFConfigList.
|
|
|
static Filtering last_filtering; ///< Default filtering of #GUIGRFConfigList.
|
|
|
static GUIGRFConfigList::SortFunction * const sorter_funcs[]; ///< Sort functions of the #GUIGRFConfigList.
|
|
|
static GUIGRFConfigList::FilterFunction * const filter_funcs[]; ///< Filter functions of the #GUIGRFConfigList.
|
|
|
|
|
|
GUIGRFConfigList avails; ///< Available (non-active) grfs.
|
|
|
const GRFConfig *avail_sel; ///< Currently selected available grf. \c NULL is none is selected.
|
|
|
int avail_pos; ///< Index of #avail_sel if existing, else \c -1.
|
|
|
|
|
|
GRFConfig *actives; ///< Temporary active grf list to which changes are made.
|
|
|
GRFConfig *active_sel; ///< Selected active grf item.
|
|
|
|
|
|
GRFConfig **orig_list; ///< List active grfs in the game. Used as initial value, may be updated by the window.
|
|
|
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.
|
|
|
int query_widget; ///< Widget that opened the last query.
|
|
|
int preset; ///< Selected preset.
|
|
|
|
|
|
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
|
|
|
{
|
|
|
this->avail_sel = NULL;
|
|
|
this->avail_pos = -1;
|
|
|
this->active_sel = NULL;
|
|
|
this->actives = NULL;
|
|
|
this->orig_list = orig_list;
|
|
|
this->editable = editable;
|
|
|
this->execute = execute;
|
|
|
this->show_params = show_params;
|
|
|
this->preset = -1;
|
|
|
|
|
|
CopyGRFConfigList(&this->actives, *orig_list, false);
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
|
|
|
|
|
this->InitNested(desc);
|
|
|
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
|
|
|
this->SetFocusedWidget(SNGRFS_FILTER);
|
|
|
|
|
|
this->avails.SetListing(this->last_sorting);
|
|
|
this->avails.SetFiltering(this->last_filtering);
|
|
|
this->avails.SetSortFuncs(this->sorter_funcs);
|
|
|
this->avails.SetFilterFuncs(this->filter_funcs);
|
|
|
this->avails.ForceRebuild();
|
|
|
|
|
|
this->OnInvalidateData(2);
|
|
|
}
|
|
|
|
|
|
~NewGRFWindow()
|
|
|
{
|
|
|
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
|
|
|
if (this->editable && !this->execute) {
|
|
|
CopyGRFConfigList(this->orig_list, this->actives, true);
|
|
|
ResetGRFConfig(false);
|
|
|
ReloadNewGRFData();
|
|
|
}
|
|
|
|
|
|
/* Remove the temporary copy of grf-list used in window */
|
|
|
ClearGRFConfigList(&this->actives);
|
|
|
_grf_preset_list.Clear();
|
|
|
}
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case SNGRFS_FILE_LIST:
|
|
|
resize->height = max(12, FONT_HEIGHT_NORMAL + 2);
|
|
|
size->height = max(size->height, WD_FRAMERECT_TOP + 6 * resize->height + WD_FRAMERECT_BOTTOM);
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_AVAIL_LIST:
|
|
|
resize->height = max(12, FONT_HEIGHT_NORMAL + 2);
|
|
|
size->height = max(size->height, WD_FRAMERECT_TOP + 8 * resize->height + WD_FRAMERECT_BOTTOM);
|
|
|
break;
|
|
|
|
|
@@ -408,49 +647,48 @@ struct NewGRFWindow : public QueryString
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
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));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
ShowDropDownList(this, list, this->preset, SNGRFS_PRESET_LIST);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_PRESET_SAVE:
|
|
|
this->query_widget = widget;
|
|
|
ShowQueryString(STR_EMPTY, STR_NEWGRF_SETTINGS_PRESET_SAVE_QUERY, 32, 100, this, CS_ALPHANUMERAL, QSF_NONE);
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_PRESET_DELETE:
|
|
|
if (this->preset == -1) return;
|
|
|
|
|
|
DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]);
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
|
|
this->preset = -1;
|
|
|
this->InvalidateData();
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_MOVE_UP: { // Move GRF up
|
|
|
if (this->active_sel == NULL || !this->editable) break;
|
|
|
|
|
|
int pos = 0;
|
|
|
for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next, pos++) {
|
|
|
GRFConfig *c = *pc;
|
|
|
if (c->next == this->active_sel) {
|
|
|
c->next = this->active_sel->next;
|
|
|
this->active_sel->next = c;
|
|
|
*pc = this->active_sel;
|
|
|
break;
|
|
@@ -466,94 +704,94 @@ struct NewGRFWindow : public QueryString
|
|
|
if (this->active_sel == NULL || !this->editable) break;
|
|
|
|
|
|
int pos = 1; // Start at 1 as we swap the selected newgrf with the next one
|
|
|
for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next, pos++) {
|
|
|
GRFConfig *c = *pc;
|
|
|
if (c == this->active_sel) {
|
|
|
*pc = c->next;
|
|
|
c->next = c->next->next;
|
|
|
(*pc)->next = c;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
this->vscroll.ScrollTowards(pos);
|
|
|
this->preset = -1;
|
|
|
this->InvalidateData();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_FILE_LIST: { // Select an active GRF.
|
|
|
uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
|
|
|
|
|
|
GRFConfig *c;
|
|
|
for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
|
|
|
|
|
|
if (this->active_sel != c) this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
if (this->active_sel != c) DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
this->active_sel = c;
|
|
|
this->avail_sel = NULL;
|
|
|
this->avail_pos = -1;
|
|
|
|
|
|
this->InvalidateData();
|
|
|
if (click_count == 1) break;
|
|
|
}
|
|
|
/* FALL THROUGH, with double click. */
|
|
|
case SNGRFS_REMOVE: { // Remove GRF
|
|
|
if (this->active_sel == NULL || !this->editable) break;
|
|
|
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
|
|
|
/* Choose the next GRF file to be the selected file. */
|
|
|
GRFConfig *newsel = this->active_sel->next;
|
|
|
for (GRFConfig **pc = &this->actives; *pc != NULL; pc = &(*pc)->next) {
|
|
|
GRFConfig *c = *pc;
|
|
|
/* 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->active_sel) newsel = c;
|
|
|
|
|
|
if (c == this->active_sel) {
|
|
|
*pc = c->next;
|
|
|
delete c;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this->active_sel = newsel;
|
|
|
this->preset = -1;
|
|
|
this->avail_pos = -1;
|
|
|
this->avail_sel = NULL;
|
|
|
this->avails.ForceRebuild();
|
|
|
this->InvalidateData(2);
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_AVAIL_LIST: { // Select a non-active GRF.
|
|
|
uint i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
|
|
|
this->active_sel = NULL;
|
|
|
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
if (i < this->avails.Length()) {
|
|
|
this->avail_sel = this->avails[i];
|
|
|
this->avail_pos = i;
|
|
|
}
|
|
|
this->InvalidateData();
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
if (click_count == 1) break;
|
|
|
}
|
|
|
/* FALL THROUGH, with double click. */
|
|
|
case SNGRFS_ADD: {
|
|
|
if (this->avail_sel == NULL || !this->editable) break;
|
|
|
|
|
|
GRFConfig **list;
|
|
|
/* Find last entry in the list, checking for duplicate grfid on the way */
|
|
|
for (list = &this->actives; *list != NULL; list = &(*list)->next) {
|
|
|
if ((*list)->ident.grfid == this->avail_sel->ident.grfid) {
|
|
|
ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GRFConfig *c = new GRFConfig(*this->avail_sel); // Copy GRF details from scanned list.
|
|
|
*list = c; // Append GRF config to configuration list.
|
|
|
|
|
|
/* Select next (or previous, if last one) item in the list. */
|
|
|
int new_pos = this->avail_pos + 1;
|
|
|
if (new_pos >= (int)this->avails.Length()) new_pos = this->avail_pos - 1;
|
|
|
this->avail_pos = new_pos;
|
|
|
if (new_pos >= 0) this->avail_sel = this->avails[new_pos];
|
|
|
|
|
@@ -561,53 +799,49 @@ struct NewGRFWindow : public QueryString
|
|
|
this->InvalidateData(2);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
|
|
|
if (!this->editable) break;
|
|
|
if (this->execute) {
|
|
|
ShowQuery(
|
|
|
STR_NEWGRF_POPUP_CAUTION_CAPTION,
|
|
|
STR_NEWGRF_CONFIRMATION_TEXT,
|
|
|
this,
|
|
|
NewGRFConfirmationCallback
|
|
|
);
|
|
|
} else {
|
|
|
CopyGRFConfigList(this->orig_list, this->actives, true);
|
|
|
ResetGRFConfig(false);
|
|
|
ReloadNewGRFData();
|
|
|
}
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_SET_PARAMETERS: { // Edit parameters
|
|
|
if (this->active_sel == NULL || !this->editable || !this->show_params) break;
|
|
|
|
|
|
this->query_widget = widget;
|
|
|
static char buff[512];
|
|
|
GRFBuildParamList(buff, this->active_sel, lastof(buff));
|
|
|
SetDParamStr(0, buff);
|
|
|
ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_SETTINGS_PARAMETER_QUERY, 63, 250, this, CS_NUMERAL_SPACE, QSF_NONE);
|
|
|
OpenGRFParameterWindow(this->active_sel);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_TOGGLE_PALETTE:
|
|
|
if (this->active_sel != NULL || !this->editable) {
|
|
|
this->active_sel->palette ^= GRFP_USE_MASK;
|
|
|
this->SetDirty();
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_CONTENT_DOWNLOAD:
|
|
|
if (!_network_available) {
|
|
|
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
|
|
} else {
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
|
|
|
/* Only show the things in the current list, or everything when nothing's selected */
|
|
|
ContentVector cv;
|
|
|
for (const GRFConfig *c = this->actives; c != NULL; c = c->next) {
|
|
|
if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
|
|
|
|
|
|
ContentInfo *ci = new ContentInfo();
|
|
|
ci->type = CONTENT_TYPE_NEWGRF;
|
|
@@ -631,83 +865,61 @@ struct NewGRFWindow : public QueryString
|
|
|
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
|
|
|
InvalidateWindowClassesData(WC_SAVELOAD);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
{
|
|
|
if (!this->editable) return;
|
|
|
if (index == -1) {
|
|
|
ClearGRFConfigList(&this->actives);
|
|
|
this->preset = -1;
|
|
|
} else {
|
|
|
GRFConfig *c = LoadGRFPresetFromConfig(_grf_preset_list[index]);
|
|
|
|
|
|
if (c != NULL) {
|
|
|
this->active_sel = NULL;
|
|
|
ClearGRFConfigList(&this->actives);
|
|
|
this->actives = c;
|
|
|
this->preset = index;
|
|
|
this->avails.ForceRebuild();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
|
|
this->active_sel = NULL;
|
|
|
this->InvalidateData(3);
|
|
|
}
|
|
|
|
|
|
virtual void OnQueryTextFinished(char *str)
|
|
|
{
|
|
|
if (str == NULL) return;
|
|
|
|
|
|
switch (this->query_widget) {
|
|
|
default: NOT_REACHED();
|
|
|
|
|
|
case SNGRFS_PRESET_SAVE:
|
|
|
SaveGRFPresetToConfig(str, this->actives);
|
|
|
GetGRFPresetList(&_grf_preset_list);
|
|
|
|
|
|
/* Switch to this preset */
|
|
|
for (uint i = 0; i < _grf_preset_list.Length(); i++) {
|
|
|
if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
|
|
|
this->preset = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case SNGRFS_SET_PARAMETERS: {
|
|
|
if (this->active_sel == NULL || !this->editable || !this->show_params) return;
|
|
|
|
|
|
/* Parse our new "int list" */
|
|
|
GRFConfig *c = this->active_sel;
|
|
|
c->num_params = ParseIntList(str, (int*)c->param, lengthof(c->param));
|
|
|
|
|
|
/* ParseIntList() returns -1 on error */
|
|
|
if (c->num_params == (byte)-1) c->num_params = 0;
|
|
|
|
|
|
this->preset = -1;
|
|
|
/* Switch to this preset */
|
|
|
for (uint i = 0; i < _grf_preset_list.Length(); i++) {
|
|
|
if (_grf_preset_list[i] != NULL && strcmp(_grf_preset_list[i], str) == 0) {
|
|
|
this->preset = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this->InvalidateData();
|
|
|
}
|
|
|
|
|
|
/** Calback to update internal data.
|
|
|
* - 0: (optionally) build availables, update button status.
|
|
|
* - 1: build availables, Add newly found grfs, update button status.
|
|
|
* - 2: (optionally) build availables, Reset preset, + 3
|
|
|
* - 3: (optionally) build availables, Update active scrollbar, update button status.
|
|
|
* - 4: Force a rebuild of the availables, + 2
|
|
|
*/
|
|
|
virtual void OnInvalidateData(int data = 0)
|
|
|
{
|
|
|
switch (data) {
|
|
|
default: NOT_REACHED();
|
|
|
case 0:
|
|
|
/* Nothing important to do */
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
/* Search the list for items that are now found and mark them as such. */
|