|
@@ -12,12 +12,13 @@
|
|
|
#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"
|
|
@@ -77,12 +78,17 @@ static void ShowNewGRFInfo(const GRFConf
|
|
|
/* 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 */
|
|
@@ -614,14 +620,13 @@ struct NewGRFWindow : public QueryString
|
|
|
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);
|
|
@@ -1069,13 +1074,19 @@ struct NewGRFWindow : public QueryString
|
|
|
}
|
|
|
|
|
|
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;
|
|
@@ -1090,13 +1101,29 @@ private:
|
|
|
|
|
|
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();
|