summaryrefslogtreecommitdiff
path: root/src/newgrf_gui.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-07-31 14:40:50 +0000
committerrubidium <rubidium@openttd.org>2010-07-31 14:40:50 +0000
commitac280af8bc75f89223238a77f871b1a610014219 (patch)
treef11e8dde3c5e08a29824a11429eb573a3373302a /src/newgrf_gui.cpp
parent5a2862814ac310e5e4629e0242def8ebf3a6da1c (diff)
downloadopenttd-ac280af8bc75f89223238a77f871b1a610014219.tar.xz
(svn r20259) -Add: allow NewGRFs to specify their version and use that to hide old NewGRFs / to choose the newest when loading compatible NewGRFs
Diffstat (limited to 'src/newgrf_gui.cpp')
-rw-r--r--src/newgrf_gui.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index bc6e32f7d..53f9f1650 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -15,6 +15,7 @@
#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"
@@ -80,6 +81,11 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
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);
@@ -617,8 +623,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
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();
@@ -1072,7 +1077,13 @@ 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 */
@@ -1093,7 +1104,23 @@ private:
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);