|
@@ -6,24 +6,25 @@
|
|
|
* 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_type.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"
|
|
|
|
|
@@ -71,24 +72,29 @@ static void ShowNewGRFInfo(const GRFConf
|
|
|
/* Draw filename or not if it is not known (GRF sent over internet) */
|
|
|
if (c->filename != NULL) {
|
|
|
SetDParamStr(0, c->filename);
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_FILENAME);
|
|
|
}
|
|
|
|
|
|
/* Prepare and draw GRF ID */
|
|
|
char buff[256];
|
|
|
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
|
|
|
SetDParamStr(0, buff);
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
|
|
|
|
|
|
if (c->version != 0) {
|
|
|
SetDParam(0, c->version);
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_VERSION);
|
|
|
}
|
|
|
|
|
|
/* Prepare and draw MD5 sum */
|
|
|
md5sumToString(buff, lastof(buff), c->ident.md5sum);
|
|
|
SetDParamStr(0, buff);
|
|
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
|
|
|
|
|
|
/* Show GRF parameter list */
|
|
|
if (show_params) {
|
|
|
if (c->num_params > 0) {
|
|
|
GRFBuildParamList(buff, c, lastof(buff));
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
SetDParamStr(1, buff);
|
|
|
} else {
|
|
@@ -608,26 +614,25 @@ struct NewGRFWindow : public QueryString
|
|
|
}
|
|
|
} break;
|
|
|
|
|
|
case SNGRFS_AVAIL_LIST: {
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, 0xD7);
|
|
|
|
|
|
uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_AVAIL_LIST)->resize_y;
|
|
|
int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
|
|
|
uint y = r.top + WD_FRAMERECT_TOP;
|
|
|
uint min_index = this->vscroll2.GetPosition();
|
|
|
uint max_index = min(min_index + this->vscroll2.GetCapacity(), this->avails.Length());
|
|
|
|
|
|
for (uint i = min_index; i < max_index; i++)
|
|
|
{
|
|
|
for (uint i = min_index; i < max_index; i++) {
|
|
|
const GRFConfig *c = this->avails[i];
|
|
|
bool h = (c == this->avail_sel);
|
|
|
const char *text = c->GetName();
|
|
|
|
|
|
if (h) GfxFillRect(r.left + 1, y, r.right - 1, y + step_height - 1, 156);
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y + offset_y, text, h ? TC_WHITE : TC_SILVER);
|
|
|
y += step_height;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SNGRFS_NEWGRF_INFO_TITLE:
|
|
@@ -1063,46 +1068,68 @@ struct NewGRFWindow : public QueryString
|
|
|
|
|
|
virtual void OnOSKInput(int wid)
|
|
|
{
|
|
|
this->avails.SetFilterState(!StrEmpty(this->edit_str_buf));
|
|
|
this->avails.ForceRebuild();
|
|
|
this->InvalidateData(0);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
/** Sort grfs by name. */
|
|
|
static int CDECL NameSorter(const GRFConfig * const *a, const GRFConfig * const *b)
|
|
|
{
|
|
|
return strcasecmp((*a)->GetName(), (*b)->GetName());
|
|
|
int i = strcasecmp((*a)->GetName(), (*b)->GetName());
|
|
|
if (i != 0) return i;
|
|
|
|
|
|
i = (*a)->version - (*b)->version;
|
|
|
if (i != 0) return i;
|
|
|
|
|
|
return memcmp((*a)->ident.md5sum, (*b)->ident.md5sum, lengthof((*b)->ident.md5sum));
|
|
|
}
|
|
|
|
|
|
/** Filter grfs by tags/name */
|
|
|
static bool CDECL TagNameFilter(const GRFConfig * const *a, const char *filter_string)
|
|
|
{
|
|
|
if (strcasestr((*a)->GetName(), filter_string) != NULL) return true;
|
|
|
if ((*a)->filename != NULL && strcasestr((*a)->filename, filter_string) != NULL) return true;
|
|
|
if ((*a)->GetDescription() != NULL && strcasestr((*a)->GetDescription(), filter_string) != NULL) return true;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void BuildAvailables()
|
|
|
{
|
|
|
if (!this->avails.NeedRebuild()) return;
|
|
|
|
|
|
this->avails.Clear();
|
|
|
|
|
|
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
|
|
bool found = false;
|
|
|
for (const GRFConfig *grf = this->actives; grf != NULL && !found; grf = grf->next) found = grf->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum);
|
|
|
if (!found) *this->avails.Append() = c;
|
|
|
if (found) continue;
|
|
|
|
|
|
if (_settings_client.gui.newgrf_show_old_versions) {
|
|
|
*this->avails.Append() = c;
|
|
|
} else {
|
|
|
const GRFConfig *best = FindGRFConfig(c->ident.grfid, NULL);
|
|
|
/*
|
|
|
* If the best version is 0, then all NewGRF with this GRF ID
|
|
|
* have version 0, so for backward compatability reasons we
|
|
|
* want to show them all.
|
|
|
* If we are the best version, then we definitely want to
|
|
|
* show that NewGRF!.
|
|
|
*/
|
|
|
if (best->version == 0 || best->ident.HasGrfIdentifier(c->ident.grfid, c->ident.md5sum)) {
|
|
|
*this->avails.Append() = c;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
this->avails.Filter(this->edit_str_buf);
|
|
|
this->avails.Compact();
|
|
|
this->avails.RebuildDone();
|
|
|
this->avails.Sort();
|
|
|
|
|
|
if (this->avail_sel != NULL) {
|
|
|
this->avail_pos = this->avails.FindIndex(this->avail_sel);
|
|
|
if (this->avail_pos < 0) this->avail_sel = NULL;
|
|
|
}
|
|
|
|