summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/serverdialog.cpp54
-rw-r--r--src/gui/serverdialog.h5
-rw-r--r--src/gui/setup_video.cpp38
-rw-r--r--src/gui/setup_video.h6
4 files changed, 103 insertions, 0 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index ca8da9b4..b3311f55 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -52,6 +52,7 @@
#include <cstdlib>
#include <iostream>
#include <string>
+#include <algorithm>
static const int MAX_SERVERLIST = 6;
@@ -591,6 +592,59 @@ void ServerDialog::loadServers()
if (!found)
mServers.push_back(server);
}
+
+ reorderList(config.getIntValue("serverListOrder"));
+}
+
+/**
+ * Returns true if serv1 must appear before serv2
+ */
+bool ServerDialog::sortByLastUsage(const ServerInfo& serv1, const ServerInfo& serv2)
+{
+ int rank1 = -1;
+ int rank2 = -1;
+
+ for (int i = 0; i < MAX_SERVERLIST; ++i)
+ {
+ const std::string index = toString(i);
+ const std::string nameKey = "MostUsedServerName" + index;
+ std::string serv = config.getValue(nameKey, "");
+ if (serv == serv1.hostname)
+ rank1 = i;
+ else if (serv == serv2.hostname)
+ rank2 = i;
+ }
+
+ if (rank1 > rank2)
+ return true;
+
+ if (rank2 > rank1)
+ return false;
+
+ if (rank1 == rank2)
+ return ServerDialog::sortByName(serv1, serv2);
+}
+
+/**
+ * Returns true if serv1 must appear before serv2
+ */
+bool ServerDialog::sortByName(const ServerInfo& serv1, const ServerInfo& serv2)
+{
+ return compareStrI(serv1.name, serv2.name) < 0;
+}
+
+/**
+ * Reorders the server list
+ * @param orderBy
+ * - 0 : Order by last change (default)
+ * - 1 : Order by name
+ */
+void ServerDialog::reorderList(int orderBy)
+{
+ if (orderBy == 0)
+ std::sort(mServers.begin(), mServers.end(), ServerDialog::sortByLastUsage);
+ else
+ std::sort(mServers.begin(), mServers.end(), ServerDialog::sortByName);
}
void ServerDialog::loadCustomServers()
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index f1d9c9b8..a222912d 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -158,6 +158,11 @@ class ServerDialog : public Window,
void setFieldsReadOnly(bool readOnly);
+ static bool sortByLastUsage(const ServerInfo& serv1, const ServerInfo& serv2);
+ static bool sortByName(const ServerInfo& serv1, const ServerInfo& serv2);
+
+ void reorderList(int orderBy);
+
TextField *mServerNameField;
TextField *mPortField;
Label *mDescription;
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index c8af218f..2ef7ce6c 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -156,6 +156,31 @@ public:
}
};
+const char *SERVLIST_ORDER_BY[2] =
+{
+ N_("Last usage"),
+ N_("Name")
+};
+
+class ServerListOrderListModel : public gcn::ListModel
+{
+public:
+ virtual ~ServerListOrderListModel() { }
+
+ virtual int getNumberOfElements()
+ {
+ return 2;
+ }
+
+ virtual std::string getElementAt(int i)
+ {
+ if (i >= getNumberOfElements())
+ return _("???");
+
+ return SERVLIST_ORDER_BY[i];
+ }
+};
+
static const char *speechModeToString(Being::Speech mode)
{
switch (mode)
@@ -243,6 +268,7 @@ Setup_Video::Setup_Video():
mParticleDetailSlider(new Slider(0, 3)),
mParticleDetailField(new Label),
mFontSize(config.getIntValue("fontSize")),
+ mServerListOrder(config.getIntValue("serverListOrder")),
mDisableSDLTransparencyCheckBox(
new CheckBox(_("Disable transparency (Low CPU mode)"),
mSDLTransparencyDisabled))
@@ -260,10 +286,14 @@ Setup_Video::Setup_Video():
overlayDetailLabel = new Label(_("Ambient FX"));
particleDetailLabel = new Label(_("Particle detail"));
fontSizeLabel = new Label(_("Font size"));
+ serverListOrderLabel = new Label(_("Order servers by"));
mFontSizeListModel = new FontSizeChoiceListModel;
mFontSizeDropDown = new DropDown(mFontSizeListModel);
+ mServerListOrderListModel = new ServerListOrderListModel;
+ mServerListOrderDropDown = new DropDown(mServerListOrderListModel);
+
mModeList->setEnabled(true);
#ifndef USE_OPENGL
@@ -341,6 +371,9 @@ Setup_Video::Setup_Video():
mFontSizeDropDown->setSelected(mFontSize - 10);
mFontSizeDropDown->adjustHeight();
+ mServerListOrderDropDown->setSelected(mServerListOrder);
+ mServerListOrderDropDown->adjustHeight();
+
// Do the layout
LayoutHelper h(this);
ContainerPlacer place = h.getPlacer(0, 0);
@@ -387,6 +420,9 @@ Setup_Video::Setup_Video():
place(0, 12, mDisableSDLTransparencyCheckBox, 4);
+ place(0, 13, serverListOrderLabel, 3);
+ place(1, 13, mServerListOrderDropDown, 2);
+
setDimension(gcn::Rectangle(0, 0, 365, 300));
}
@@ -395,6 +431,7 @@ Setup_Video::~Setup_Video()
delete mModeListModel;
delete mModeList;
delete mFontSizeListModel;
+ delete mServerListOrderListModel;
}
void Setup_Video::apply()
@@ -493,6 +530,7 @@ void Setup_Video::apply()
// FPS change
config.setValue("fpslimit", mFps);
config.setValue("fontSize", mFontSizeDropDown->getSelected() + 10);
+ config.setValue("serverListOrder", mServerListOrderDropDown->getSelected());
// We sync old and new values at apply time
mFullScreenEnabled = config.getBoolValue("screen");
diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h
index d0e2c492..15a0387e 100644
--- a/src/gui/setup_video.h
+++ b/src/gui/setup_video.h
@@ -32,6 +32,7 @@
class ModeListModel;
class FontSizeChoiceListModel;
+class ServerListOrderListModel;
class Setup_Video : public SetupTab, public gcn::ActionListener,
public gcn::KeyListener
@@ -67,6 +68,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
ModeListModel *mModeListModel;
FontSizeChoiceListModel *mFontSizeListModel;
+ ServerListOrderListModel *mServerListOrderListModel;
gcn::Label *speechLabel;
gcn::Label *alphaLabel;
@@ -75,6 +77,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
gcn::Label *overlayDetailLabel;
gcn::Label *particleDetailLabel;
gcn::Label *fontSizeLabel;
+ gcn::Label *serverListOrderLabel;
gcn::ListBox *mModeList;
gcn::CheckBox *mFsCheckBox;
@@ -108,6 +111,9 @@ class Setup_Video : public SetupTab, public gcn::ActionListener,
int mFontSize;
gcn::DropDown *mFontSizeDropDown;
+ int mServerListOrder;
+ gcn::DropDown *mServerListOrderDropDown;
+
gcn::CheckBox *mDisableSDLTransparencyCheckBox;
};