summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/connection.cpp15
-rw-r--r--src/gui/connection.h2
-rw-r--r--src/gui/serverdialog.cpp251
-rw-r--r--src/gui/serverdialog.h145
-rw-r--r--src/main.cpp81
-rw-r--r--src/main.h16
8 files changed, 494 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index c60794b4..b497869e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-30 Yohann Ferreira <bertram@cegetel.net>
+
+ * src/main.cpp, src/main.h, src/Makefile.am, src/gui/connection.h,
+ src/gui/connection.cpp, src/gui/serverdialog.cpp,
+ src/gui/serverdialog.h: Added a first version of the server dialog
+ with an unskinned dropdown. Upgraded also the connection window a bit
+ to handle Cancelling more gracefully.
+
2006-08-27 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/engine.cpp, src/gui/gui.cpp: Fixed merge issues: printfs and
diff --git a/src/Makefile.am b/src/Makefile.am
index 1e8a1424..01f8a3b2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,6 +79,8 @@ tmw_SOURCES = graphic/imagerect.h \
gui/scrollarea.h \
gui/sell.cpp \
gui/sell.h \
+ gui/serverdialog.cpp \
+ gui/serverdialog.h \
gui/setup_audio.cpp \
gui/setup_audio.h \
gui/setup.cpp \
diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp
index a29008c3..1e0034fb 100644
--- a/src/gui/connection.cpp
+++ b/src/gui/connection.cpp
@@ -35,18 +35,25 @@
namespace {
struct ConnectionActionListener : public gcn::ActionListener
{
+ ConnectionActionListener(unsigned char previousState):
+ mPreviousState(previousState) {};
+
void action(const std::string &eventId, gcn::Widget *widget) {
- state = STATE_EXIT;
+ state = mPreviousState;
}
- } listener;
+
+ unsigned char mPreviousState;
+ };
}
-ConnectionDialog::ConnectionDialog():
+ConnectionDialog::ConnectionDialog(unsigned char previousState):
Window("Info"), mProgress(0)
{
setContentSize(200, 100);
- Button *cancelButton = new Button("Cancel", "cancelButton", &listener);
+ ConnectionActionListener *connectionListener = new ConnectionActionListener(previousState);
+
+ Button *cancelButton = new Button("Cancel", "cancelButton", connectionListener);
mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128);
gcn::Label *label = new gcn::Label("Connecting...");
diff --git a/src/gui/connection.h b/src/gui/connection.h
index 7a072d2e..4b3187f6 100644
--- a/src/gui/connection.h
+++ b/src/gui/connection.h
@@ -41,7 +41,7 @@ class ConnectionDialog : public Window
*
* @see Window::Window
*/
- ConnectionDialog();
+ ConnectionDialog(unsigned char previousState);
void logic();
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
new file mode 100644
index 00000000..50464bcf
--- /dev/null
+++ b/src/gui/serverdialog.cpp
@@ -0,0 +1,251 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: login.cpp 2550 2006-08-20 00:56:23Z b_lindeijer $
+ */
+
+#include "serverdialog.h"
+
+#include <string>
+#include <iostream>
+#include "../utils/tostring.h"
+
+#include <guichan/widgets/label.hpp>
+
+#include "../main.h"
+#include "../logindata.h"
+
+#include "log.h"
+#include "configuration.h"
+
+#include "button.h"
+#include "ok_dialog.h"
+#include "textfield.h"
+
+// TODO : Replace the dropdown by our own skinned one.
+#include <guichan/widgets/dropdown.hpp>
+#include "listbox.h"
+#include "scrollarea.h"
+
+const short MAX_SERVERLIST = 5;
+
+void
+DropDownListener::action(const std::string &eventId, gcn::Widget *widget)
+{
+ if (eventId == "ok")
+ {
+ // Reset the text fields and give back the server dialog.
+ mServerNameField->setText("");
+ mServerNameField->setCaretPosition(0);
+ mServerPortField->setText("");
+ mServerPortField->setCaretPosition(0);
+
+ mServerNameField->requestFocus();
+ }
+ else if (eventId == "changeSelection")
+ {
+ // Change the textField Values according to new selection
+ if (currentSelectedIndex != mServersListBox->getSelected())
+ {
+ Server myServer;
+ myServer = mServersListModel->getServer(mServersListBox->getSelected());
+ mServerNameField->setText(myServer.serverName);
+ mServerPortField->setText(toString(myServer.port));
+ currentSelectedIndex = mServersListBox->getSelected();
+ }
+ }
+}
+
+int ServersListModel::getNumberOfElements()
+{
+ return servers.size();
+}
+
+std::string ServersListModel::getElementAt(int elementIndex)
+{
+ std::string myServer = "";
+ myServer = servers.at(elementIndex).serverName;
+ myServer += ":";
+ myServer += toString(servers.at(elementIndex).port);
+ return myServer;
+}
+
+void ServersListModel::addFirstElement(Server server)
+{
+ // Equivalent to push_front
+ std::vector<Server>::iterator MyIterator = servers.begin();
+ servers.insert(MyIterator, 1, server);
+}
+
+void ServersListModel::addElement(Server server)
+{
+ servers.push_back(server);
+}
+
+ServerDialog::ServerDialog(LoginData *loginData):
+ Window("Choose your Mana World Server"), mLoginData(loginData)
+{
+ gcn::Label *serverLabel = new gcn::Label("Server:");
+ gcn::Label *portLabel = new gcn::Label("Port:");
+ mServerNameField = new TextField(mLoginData->hostname);
+ mPortField = new TextField(toString(mLoginData->port));
+
+ // Add the most used servers from config
+ mMostUsedServersListModel = new ServersListModel();
+ Server currentServer;
+ std::string currentConfig = "";
+ for (int i=0; i<=MAX_SERVERLIST; i++)
+ {
+ currentServer.serverName = "";
+ currentServer.port = 0;
+
+ currentConfig = "MostUsedServerName" + toString(i);
+ currentServer.serverName = config.getValue(currentConfig, "");
+
+ currentConfig = "MostUsedServerPort" + toString(i);
+ currentServer.port = (short)atoi(config.getValue(currentConfig, "").c_str());
+ if (!currentServer.serverName.empty() || currentServer.port != 0)
+ {
+ mMostUsedServersListModel->addElement(currentServer);
+ }
+ }
+
+ mMostUsedServersListBox = new ListBox(mMostUsedServersListModel);
+ mMostUsedServersScrollArea = new ScrollArea();
+ mMostUsedServersDropDown = new gcn::DropDown(mMostUsedServersListModel,
+ mMostUsedServersScrollArea, mMostUsedServersListBox);
+
+ mDropDownListener = new DropDownListener(mServerNameField, mPortField,
+ mMostUsedServersListModel, mMostUsedServersListBox);
+
+ mOkButton = new Button("OK", "ok", this);
+ mCancelButton = new Button("Cancel", "cancel", this);
+
+ setContentSize(200, 100);
+
+ serverLabel->setPosition(10, 5);
+ portLabel->setPosition(10, 14 + serverLabel->getHeight());
+
+ mServerNameField->setPosition(60, 5);
+ mPortField->setPosition(60, 14 + serverLabel->getHeight());
+ mServerNameField->setWidth(130);
+ mPortField->setWidth(130);
+
+ mMostUsedServersDropDown->setPosition(10, 10 +
+ portLabel->getY() + portLabel->getHeight());
+ mMostUsedServersDropDown->setWidth(180);
+
+ mCancelButton->setPosition(
+ 200 - mCancelButton->getWidth() - 5,
+ 100 - mCancelButton->getHeight() - 5);
+ mOkButton->setPosition(
+ mCancelButton->getX() - mOkButton->getWidth() - 5,
+ 100 - mOkButton->getHeight() - 5);
+
+ mServerNameField->setEventId("ok");
+ mPortField->setEventId("ok");
+ mMostUsedServersDropDown->setEventId("changeSelection");
+
+ mServerNameField->addActionListener(this);
+ mPortField->addActionListener(this);
+ mMostUsedServersDropDown->addActionListener(mDropDownListener);
+
+ add(serverLabel);
+ add(portLabel);
+ add(mServerNameField);
+ add(mPortField);
+ add(mMostUsedServersDropDown);
+ add(mOkButton);
+ add(mCancelButton);
+
+ setLocationRelativeTo(getParent());
+
+ if (mServerNameField->getText().empty()) {
+ mServerNameField->requestFocus();
+ } else {
+ if (mPortField->getText().empty()) {
+ mPortField->requestFocus();
+ } else {
+ mOkButton->requestFocus();
+ }
+ }
+}
+
+ServerDialog::~ServerDialog()
+{
+ delete mDropDownListener;
+}
+
+void
+ServerDialog::action(const std::string &eventId, gcn::Widget *widget)
+{
+ if (eventId == "ok")
+ {
+ // Check login
+ if (mServerNameField->getText().empty() || mPortField->getText().empty())
+ {
+ OkDialog *dlg = new OkDialog("Error", "Enter the chosen server.");
+ dlg->addActionListener(mDropDownListener);
+ }
+ else
+ {
+ mLoginData->hostname = mServerNameField->getText();
+ mLoginData->port = (short) atoi(mPortField->getText().c_str());
+ mOkButton->setEnabled(false);
+ mCancelButton->setEnabled(false);
+
+ // First, look if the entry is a new one.
+ Server currentServer;
+ bool newEntry = true;
+ for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++)
+ {
+ currentServer = mMostUsedServersListModel->getServer(i);
+ if (currentServer.serverName == mLoginData->hostname &&
+ currentServer.port == mLoginData->port)
+ newEntry = false;
+ }
+ // Then, add it to config if it's really new
+ currentServer.serverName = mLoginData->hostname;
+ currentServer.port = mLoginData->port;
+ if (newEntry)
+ mMostUsedServersListModel->addFirstElement(currentServer);
+ // Write the entry in config
+ std::string currentConfig = "";
+ for (int i = 0; i < mMostUsedServersListModel->getNumberOfElements(); i++)
+ {
+ currentServer = mMostUsedServersListModel->getServer(i);
+
+ currentConfig = "MostUsedServerName" + toString(i);
+ config.setValue(currentConfig, currentServer.serverName);
+
+ currentConfig = "MostUsedServerPort" + toString(i);
+ config.setValue(currentConfig, toString(currentServer.port));
+ }
+ logger->log("Trying to connect to account server...");
+ Network::connect(Network::ACCOUNT,
+ mLoginData->hostname, mLoginData->port);
+ state = STATE_CONNECT_ACCOUNT;
+ }
+ }
+ else if (eventId == "cancel")
+ {
+ state = STATE_EXIT;
+ }
+}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
new file mode 100644
index 00000000..a638e877
--- /dev/null
+++ b/src/gui/serverdialog.h
@@ -0,0 +1,145 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World 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 The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id: login.h 2486 2006-07-30 14:33:28Z b_lindeijer $
+ */
+
+#ifndef _TMW_SERVERDIALOG_H
+#define _TMW_SERVERDIALOG_H
+
+#include <iosfwd>
+#include <guichan/actionlistener.hpp>
+
+#include "window.h"
+#include "../guichanfwd.h"
+
+#include "login.h"
+#include "net/network.h"
+
+class LoginData;
+
+/**
+ * A server structure to keep pairs of servers and ports.
+ */
+struct Server {
+ Server():
+ serverName(""),
+ port(0) {};
+
+ std::string serverName;
+ short port;
+};
+
+/**
+ * Server and Port List Model
+ */
+class ServersListModel : public gcn::ListModel {
+ public:
+ /**
+ * Used to get number of line in the list
+ */
+ int getNumberOfElements();
+ /**
+ * Used to get an element from the list
+ */
+ std::string getElementAt(int elementIndex);
+ /**
+ * Used to get the corresponding Server struct
+ */
+ Server getServer(int elementIndex) { return servers[elementIndex]; };
+ /**
+ * Add an Element at the end of the server list
+ */
+ void addElement(Server server);
+ /**
+ * Add an Element at the beginning of the server list
+ */
+ void addFirstElement(Server server);
+ private:
+ std::vector<Server> servers;
+};
+
+/**
+ * Listener used for handling the DropDown in the server Dialog.
+ */
+class DropDownListener : public gcn::ActionListener {
+ public:
+ DropDownListener(gcn::TextField *serverNameField,
+ gcn::TextField *serverPortField,
+ ServersListModel *serversListModel,
+ gcn::ListBox *serversListBox):
+ currentSelectedIndex(0),
+ mServerNameField(serverNameField),
+ mServerPortField(serverPortField),
+ mServersListModel(serversListModel),
+ mServersListBox(serversListBox) {};
+ void action(const std::string& eventId,
+ gcn::Widget* widget);
+ private:
+ short currentSelectedIndex;
+ gcn::TextField *mServerNameField;
+ gcn::TextField *mServerPortField;
+ ServersListModel *mServersListModel;
+ gcn::ListBox *mServersListBox;
+};
+
+
+/**
+ * The server choice dialog.
+ *
+ * \ingroup Interface
+ */
+class ServerDialog : public Window, public gcn::ActionListener {
+ public:
+ /**
+ * Constructor
+ *
+ * @see Window::Window
+ */
+ ServerDialog(LoginData *loginData);
+
+ /**
+ * Destructor
+ */
+ ~ServerDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const std::string& eventId, gcn::Widget* widget);
+
+ private:
+ gcn::TextField *mServerNameField;
+ gcn::TextField *mPortField;
+ gcn::Button *mOkButton;
+ gcn::Button *mCancelButton;
+
+ // TODO : child the Dropdown List to skin it.
+ gcn::DropDown *mMostUsedServersDropDown;
+ gcn::ListBox *mMostUsedServersListBox;
+ gcn::ScrollArea *mMostUsedServersScrollArea;
+ ServersListModel *mMostUsedServersListModel;
+
+ DropDownListener *mDropDownListener;
+
+ LoginData *mLoginData;
+};
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
index f540dacd..469a2c47 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -58,6 +58,7 @@
#include "gui/char_select.h"
#include "gui/connection.h"
#include "gui/gui.h"
+#include "gui/serverdialog.h"
#include "gui/login.h"
#include "gui/ok_dialog.h"
#include "gui/register.h"
@@ -231,8 +232,8 @@ void init_engine()
graphics = new Graphics();
#endif
- int width = (int)config.getValue("screenwidth", 800);
- int height = (int)config.getValue("screenheight", 600);
+ int width = (int)config.getValue("screenwidth", defaultScreenWidth);
+ int height = (int)config.getValue("screenheight", defaultScreenHeight);
int bpp = 0;
bool fullscreen = ((int)config.getValue("screen", 0) == 1);
bool hwaccel = ((int)config.getValue("hwaccel", 0) == 1);
@@ -277,8 +278,8 @@ void init_engine()
if (config.getValue("sound", 0) == 1) {
sound.init();
}
- sound.setSfxVolume((int)config.getValue("sfxVolume", 100));
- sound.setMusicVolume((int)config.getValue("musicVolume", 60));
+ sound.setSfxVolume((int)config.getValue("sfxVolume", defaultSfxVolume));
+ sound.setMusicVolume((int)config.getValue("musicVolume", defaultMusicVolume));
}
catch (const char *err) {
state = STATE_ERROR;
@@ -322,15 +323,19 @@ struct Options
Options():
printHelp(false),
skipUpdate(false),
- chooseDefault(false)
+ chooseDefault(false),
+ serverPort(0)
{};
bool printHelp;
bool skipUpdate;
bool chooseDefault;
- std::string username;
- std::string password;
std::string playername;
+ std::string password;
+
+ std::string serverName;
+ short serverPort;
+
};
void printHelp()
@@ -343,13 +348,14 @@ void printHelp()
<< " -U --username : Login with this username" << std::endl
<< " -P --password : Login with this password" << std::endl
<< " -D --default : Bypass the login process with default settings" << std::endl
- << " -p --playername : Login with this player"
- << std::endl;
+ << " -s --server : Login Server name or IP" << std::endl
+ << " -o --port : Login Server Port" << std::endl
+ << " -p --playername : Login with this player" << std::endl;
}
void parseOptions(int argc, char *argv[], Options &options)
{
- const char *optstring = "huU:P:Dp:";
+ const char *optstring = "huU:P:Dp:so";
const struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
@@ -357,6 +363,8 @@ void parseOptions(int argc, char *argv[], Options &options)
{ "username", required_argument, 0, 'U' },
{ "password", required_argument, 0, 'P' },
{ "default", no_argument, 0, 'D' },
+ { "server", required_argument, 0, 's' },
+ { "port", required_argument, 0, 'o' },
{ "playername", required_argument, 0, 'p' },
{ 0 }
};
@@ -377,7 +385,7 @@ void parseOptions(int argc, char *argv[], Options &options)
options.skipUpdate = true;
break;
case 'U':
- options.username = optarg;
+ options.playername = optarg;
break;
case 'P':
options.password = optarg;
@@ -385,6 +393,12 @@ void parseOptions(int argc, char *argv[], Options &options)
case 'D':
options.chooseDefault = true;
break;
+ case 's':
+ options.serverName = optarg;
+ break;
+ case 'o':
+ options.serverPort = (short)atoi(optarg);
+ break;
case 'p':
options.playername = optarg;
break;
@@ -502,6 +516,11 @@ int main(int argc, char *argv[])
logger->setLogFile(homeDir + std::string("/tmw.log"));
logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
+ // Log the tmw version
+#ifdef PACKAGE_VERSION
+ logger->log("The Mana World v%s", PACKAGE_VERSION);
+#endif
+
// Initialize libxml2 and check for potential ABI mismatches between
// compiled version and the shared library actually used.
logger->log("Initializing libxml2...");
@@ -522,7 +541,22 @@ int main(int argc, char *argv[])
sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg");
- loginData.username = options.username;
+ // Server choice
+ if (options.serverName.empty()) {
+ loginData.hostname = config.getValue("MostUsedServerName0",
+ defaultAccountServerName.c_str());
+ }
+ else {
+ loginData.hostname = options.serverName;
+ }
+ if (options.serverPort == 0) {
+ loginData.port = (short)config.getValue("MostUsedServerPort0",
+ defaultAccountServerPort);
+ } else {
+ loginData.port = options.serverPort;
+ }
+
+ loginData.username = options.playername;
if (loginData.username.empty()) {
if (config.getValue("remember", 0)) {
loginData.username = config.getValue("username", "");
@@ -531,8 +565,7 @@ int main(int argc, char *argv[])
if (!options.password.empty()) {
loginData.password = options.password;
}
- loginData.hostname = config.getValue("host", "animesites.de");
- loginData.port = (short)config.getValue("port", 0);
+
loginData.remember = config.getValue("remember", 0);
if (enet_initialize() != 0)
@@ -631,15 +664,23 @@ int main(int argc, char *argv[])
switch (state) {
case STATE_CHOOSE_SERVER:
logger->log("State: CHOOSE_SERVER");
- // TODO: Allow changing this using a server choice dialog
- logger->log("Trying to connect to account server...");
- Network::connect(Network::ACCOUNT,
- loginData.hostname, loginData.port);
- state = STATE_CONNECT_ACCOUNT;
+
+ // Allow changing this using a server choice dialog
+ // We show the dialog box only if the command-line options weren't set.
+ if (options.serverName.empty() && options.serverPort == 0) {
+ currentDialog = new ServerDialog(&loginData);
+ } else {
+ logger->log("Trying to connect to account server...");
+ Network::connect(Network::ACCOUNT,
+ loginData.hostname, loginData.port);
+ state = STATE_CONNECT_ACCOUNT;
+ }
break;
+
case STATE_CONNECT_ACCOUNT:
logger->log("State: CONNECT_ACCOUNT");
+ currentDialog = new ConnectionDialog(STATE_CHOOSE_SERVER);
break;
case STATE_UPDATE:
@@ -705,7 +746,7 @@ int main(int argc, char *argv[])
case STATE_CONNECT_GAME:
logger->log("State: CONNECT_GAME");
- currentDialog = new ConnectionDialog();
+ currentDialog = new ConnectionDialog(STATE_CHAR_SELECT);
break;
case STATE_GAME:
diff --git a/src/main.h b/src/main.h
index fbd7f4a4..2973f1ad 100644
--- a/src/main.h
+++ b/src/main.h
@@ -37,7 +37,9 @@
#define TMW_DATADIR ""
#endif
-
+/*
+ * Client different States
+ */
enum {
STATE_CHOOSE_SERVER,
STATE_CONNECT_ACCOUNT,
@@ -64,6 +66,18 @@ enum {
LEN_MIN_PASSWORD = 4
};
+// Default game values
+// -------------------
+// Screen
+const short defaultScreenWidth = 800;
+const short defaultScreenHeight = 600;
+// Sound
+const short defaultSfxVolume = 100;
+const short defaultMusicVolume = 60;
+// Account Server Name and port
+const std::string defaultAccountServerName = "animesites.de";
+const short defaultAccountServerPort = 9601;
+
extern char n_character;
extern std::string token;
extern unsigned char state;