summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-03-29 13:14:21 -0600
committerJared Adams <jaxad0127@gmail.com>2010-03-29 19:09:18 -0600
commit43abf72c78b492fa1cd383dac3990ee331c217ef (patch)
tree8d353aefa21fe02cdba7ac015223b31ed33be956 /src
parent588148553eb41672147fb98d0e7ad558a8c2884c (diff)
downloadmana-client-43abf72c78b492fa1cd383dac3990ee331c217ef.tar.gz
mana-client-43abf72c78b492fa1cd383dac3990ee331c217ef.tar.bz2
mana-client-43abf72c78b492fa1cd383dac3990ee331c217ef.tar.xz
mana-client-43abf72c78b492fa1cd383dac3990ee331c217ef.zip
Add minimum version information to the server list
Use it to hilight entries that we don't meet. Also make the entries in that list higher, put server name and location on different lines, and use the description below the list. The dialog is also resizable now. Reviewed-by: Freeyorp
Diffstat (limited to 'src')
-rw-r--r--src/gui/serverdialog.cpp170
-rw-r--r--src/gui/serverdialog.h12
-rw-r--r--src/gui/theme.cpp3
-rw-r--r--src/gui/theme.h1
-rw-r--r--src/net/serverinfo.h9
5 files changed, 165 insertions, 30 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 6a6c7a91..6cd364cc 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -23,10 +23,12 @@
#include "client.h"
#include "configuration.h"
+#include "gui.h"
#include "log.h"
#include "gui/okdialog.h"
#include "gui/sdlinput.h"
+#include "gui/theme.h"
#include "gui/widgets/button.h"
#include "gui/widgets/dropdown.h"
@@ -43,6 +45,8 @@
#include "utils/xml.h"
#include "widgets/dropdown.h"
+#include <guichan/font.hpp>
+
#include <cstdlib>
#include <iostream>
#include <string>
@@ -76,6 +80,7 @@ static unsigned short defaultPortForServerType(ServerInfo::Type type)
ServersListModel::ServersListModel(ServerInfos *servers, ServerDialog *parent):
mServers(servers),
+ mVersionStrings(servers->size(), VersionString(0, "")),
mParent(parent)
{
}
@@ -91,22 +96,35 @@ std::string ServersListModel::getElementAt(int elementIndex)
MutexLocker lock = mParent->lock();
const ServerInfo &server = mServers->at(elementIndex);
std::string myServer;
- if (server.name.empty())
+ myServer += server.hostname;
+ myServer += ":";
+ myServer += toString(server.port);
+ return myServer;
+}
+
+void ServersListModel::setVersionString(int index, const std::string &version)
+{
+ if (version.empty())
+ mVersionStrings[index] = VersionString(0, "");
+ else
{
- myServer += server.hostname;
- myServer += ":";
- myServer += toString(server.port);
+ int width = gui->getFont()->getWidth(version);
+ mVersionStrings[index] = VersionString(width, version);
}
+}
+
+void ServersListModel::addServer(const ServerInfo &info,
+ const std::string &version)
+{
+ mServers->push_back(info);
+
+ if (version.empty())
+ mVersionStrings.push_back(VersionString(0, ""));
else
{
- myServer += server.name;
- myServer += " (";
- myServer += server.hostname;
- myServer += ":";
- myServer += toString(server.port);
- myServer += ")";
+ int width = gui->getFont()->getWidth(version);
+ mVersionStrings.push_back(VersionString(width, version));
}
- return myServer;
}
std::string TypeListModel::getElementAt(int elementIndex)
@@ -119,6 +137,74 @@ std::string TypeListModel::getElementAt(int elementIndex)
return "Unknown";
}
+class ServersListBox : public ListBox
+{
+public:
+ ServersListBox(ServersListModel *model):
+ ListBox(model)
+ {
+ }
+
+ void draw(gcn::Graphics *graphics)
+ {
+ if (!mListModel)
+ return;
+
+ ServersListModel *model = static_cast<ServersListModel*>(mListModel);
+
+ updateAlpha();
+
+ graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT,
+ (int) (mAlpha * 255.0f)));
+ graphics->setFont(getFont());
+
+ const int height = getRowHeight();
+ const gcn::Color unsupported =
+ Theme::getThemeColor(Theme::SERVER_VERSION_NOT_SUPPORTED,
+ (int) (mAlpha * 255.0f));
+
+ // Draw filled rectangle around the selected list element
+ if (mSelected >= 0)
+ graphics->fillRectangle(gcn::Rectangle(0, height * mSelected,
+ getWidth(), height));
+
+ // Draw the list elements
+ for (int i = 0, y = 0; i < model->getNumberOfElements();
+ ++i, y += height)
+ {
+ ServerInfo info = model->getServer(i);
+
+ graphics->setColor(Theme::getThemeColor(Theme::TEXT));
+
+ if (!info.name.empty())
+ {
+ graphics->setFont(boldFont);
+ graphics->drawText(info.name, 2, y);
+ }
+
+ graphics->setFont(getFont());
+
+ int top = y + height / 2;
+
+ graphics->drawText(model->getElementAt(i), 2, top);
+
+ const ServersListModel::VersionString versionInfo = model->getVersionString(i);
+ if (versionInfo.first > 0)
+ {
+ graphics->setColor(unsupported);
+
+ graphics->drawText(versionInfo.second,
+ getWidth() - versionInfo.first - 2, top);
+ }
+ }
+ }
+
+ unsigned int getRowHeight() const
+ {
+ return 2 * getFont()->getHeight();
+ }
+};
+
ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
Window(_("Choose Your Server")),
@@ -128,6 +214,8 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
mServers(ServerInfos()),
mServerInfo(serverInfo)
{
+ setWindowName("ServerDialog");
+
Label *serverLabel = new Label(_("Server:"));
Label *portLabel = new Label(_("Port:"));
Label *typeLabel = new Label(_("Server type:"));
@@ -138,7 +226,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
mServersListModel = new ServersListModel(&mServers, this);
- mServersList = new ListBox(mServersListModel);
+ mServersList = new ServersListBox(mServersListModel);
mServersList->addMouseListener(this);
ScrollArea *usedScroll = new ScrollArea(mServersList);
@@ -183,17 +271,23 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
// minimum width.
int width = 0, height = 0;
getLayout().reflow(width, height);
- if (width < 300)
+ if (width < 400)
{
- width = 300;
+ width = 400;
getLayout().reflow(width, height);
}
setContentSize(width, height);
+ setMinWidth(getWidth());
+ setMinHeight(getHeight());
+ setDefaultSize(getWidth(), getHeight(), ImageRect::CENTER);
+
+ setResizable(true);
addKeyListener(this);
- center();
+ loadWindowState();
+
setFieldsReadOnly(true);
mServersList->setSelected(0); // Do this after for the Delete button
setVisible(true);
@@ -314,7 +408,7 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &)
// Update the server and post fields according to the new selection
const ServerInfo &myServer = mServersListModel->getServer(index);
- mDescription->setCaption(myServer.name);
+ mDescription->setCaption(myServer.description);
mServerNameField->setText(myServer.hostname);
mPortField->setText(toString(myServer.port));
switch (myServer.type)
@@ -441,6 +535,18 @@ void ServerDialog::loadServers()
server.type = ServerInfo::parseType(type);
server.name = XML::getProperty(serverNode, "name", std::string());
+ std::string version = XML::getProperty(serverNode, "minimumVersion",
+ std::string());
+
+ server.meetsMinimumVersion = (compareStrI(version, PACKAGE_VERSION)
+ <= 0);
+
+ // For display in the list
+ if (server.meetsMinimumVersion)
+ version.clear();
+ else
+ version = strprintf(_("requires v%s"), version.c_str());
+
if (server.type == ServerInfo::UNKNOWN)
{
logger->log("Unknown server type: %s", type.c_str());
@@ -449,36 +555,41 @@ void ServerDialog::loadServers()
for_each_xml_child_node(subNode, serverNode)
{
- if (!xmlStrEqual(subNode->name, BAD_CAST "connection"))
- continue;
-
- server.hostname = XML::getProperty(subNode, "hostname", "");
- server.port = XML::getProperty(subNode, "port", 0);
- if (server.port == 0)
+ if (xmlStrEqual(subNode->name, BAD_CAST "connection"))
+ {
+ server.hostname = XML::getProperty(subNode, "hostname", "");
+ server.port = XML::getProperty(subNode, "port", 0);
+ if (server.port == 0)
+ {
+ // If no port is given, use the default for the given type
+ server.port = defaultPortForServerType(server.type);
+ }
+ }
+ else if (xmlStrEqual(subNode->name, BAD_CAST "description"))
{
- // If no port is given, use the default for the given type
- server.port = defaultPortForServerType(server.type);
+ server.description = (const char*) subNode->xmlChildrenNode->content;
}
}
MutexLocker lock(&mMutex);
// Add the server to the local list if it's not already present
- ServerInfos::iterator it;
bool found = false;
- for (it = mServers.begin(); it != mServers.end(); it++)
+ for (unsigned int i = 0; i < mServers.size(); i++)
{
- if ((*it) == server)
+ if (mServers[i] == server)
{
// Use the name listed in the server list
- (*it).name = server.name;
+ mServers[i].name = server.name;
+ mServers[i].meetsMinimumVersion = server.meetsMinimumVersion;
+ mServersListModel->setVersionString(i, version);
found = true;
break;
}
}
if (!found)
- mServers.push_back(server);
+ mServersListModel->addServer(server, version);
}
}
@@ -503,6 +614,7 @@ void ServerDialog::loadCustomServers()
break;
server.save = true;
+ server.meetsMinimumVersion = true;
mServers.push_back(server);
}
}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 673ee97c..5b9d53fd 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -51,6 +51,8 @@ class DropDown;
class ServersListModel : public gcn::ListModel
{
public:
+ typedef std::pair<int, std::string> VersionString;
+
ServersListModel(ServerInfos *servers, ServerDialog *parent);
/**
@@ -69,8 +71,18 @@ class ServersListModel : public gcn::ListModel
const ServerInfo &getServer(int elementIndex) const
{ return mServers->at(elementIndex); }
+ const VersionString &getVersionString(int index) const
+ { return mVersionStrings[index]; }
+
+ void setVersionString(int index, const std::string &version);
+
+ void addServer(const ServerInfo &info, const std::string &version);
+
private:
+ typedef std::vector<VersionString> VersionStrings;
+
ServerInfos *mServers;
+ VersionStrings mVersionStrings;
ServerDialog *mParent;
};
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index f42b0fc2..33e9f301 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -408,7 +408,8 @@ static int readColorType(const std::string &type)
"RING",
"NECKLACE",
"ARMS",
- "AMMO"
+ "AMMO",
+ "SERVER_VERSION_NOT_SUPPORTED"
};
if (type.empty())
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 4dd63660..6798bed5 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -156,6 +156,7 @@ class Theme : public Palette, public ConfigListener
NECKLACE,
ARMS,
AMMO,
+ SERVER_VERSION_NOT_SUPPORTED,
THEME_COLORS_END
};
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index 803bcc71..adfdee7e 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -41,13 +41,17 @@ public:
std::string hostname;
unsigned short port;
+ std::string description;
+
bool save;
+ bool meetsMinimumVersion;
ServerInfo()
{
type = UNKNOWN;
port = 0;
save = false;
+ meetsMinimumVersion = true;
}
ServerInfo(const ServerInfo &info)
@@ -56,7 +60,9 @@ public:
name = info.name;
hostname = info.hostname;
port = info.port;
+ description = info.description;
save = info.save;
+ meetsMinimumVersion = info.meetsMinimumVersion;
}
bool isValid() const
@@ -70,6 +76,9 @@ public:
name.clear();
hostname.clear();
port = 0;
+ description.clear();
+ save = false;
+ meetsMinimumVersion = true;
}
bool operator==(const ServerInfo &other) const