diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-04 13:23:47 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2009-10-04 13:23:47 +0200 |
commit | 7b6ddb687ceb1faf1b100929c501ab403e3e63de (patch) | |
tree | 82ea5890bb700799540bdb39f1ae066a6431f3b6 | |
parent | 69217e82e8631bbb2183a1322d0985a495c52f5e (diff) | |
download | mana-7b6ddb687ceb1faf1b100929c501ab403e3e63de.tar.gz mana-7b6ddb687ceb1faf1b100929c501ab403e3e63de.tar.bz2 mana-7b6ddb687ceb1faf1b100929c501ab403e3e63de.tar.xz mana-7b6ddb687ceb1faf1b100929c501ab403e3e63de.zip |
Made sure the server information updates when dragging the server list
It was only updating on click events, due to using ActionListener
instead of SelectionListener.
-rw-r--r-- | src/gui/charcreatedialog.h | 2 | ||||
-rw-r--r-- | src/gui/charselectdialog.cpp | 2 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 35 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 12 | ||||
-rw-r--r-- | src/net/serverinfo.h | 8 |
5 files changed, 35 insertions, 24 deletions
diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 50089a8d..0d8b9856 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -73,7 +73,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener */ void success(); - CharSelectDialog *getSelectDialog() + CharSelectDialog *getSelectDialog() const { return mCharSelectDialog; } private: diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index fef319d9..2fe83849 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -74,6 +74,7 @@ class CharDeleteConfirm : public ConfirmDialog master(m) { } + void action(const gcn::ActionEvent &event) { //ConfirmDialog::action(event); @@ -83,6 +84,7 @@ class CharDeleteConfirm : public ConfirmDialog } ConfirmDialog::action(event); } + private: CharSelectDialog *master; }; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index bbc2d3f9..d126c312 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -82,7 +82,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo): mMostUsedServersListModel = new ServersListModel; ServerInfo currentServer; std::string currentConfig = ""; - for (int i=0; i<=MAX_SERVERLIST; i++) + for (int i = 0; i <= MAX_SERVERLIST; i++) { currentServer.clear(); @@ -90,15 +90,15 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo): currentServer.hostname = config.getValue(currentConfig, ""); currentConfig = "MostUsedServerPort" + toString(i); - currentServer.port = (short)atoi(config.getValue(currentConfig, "").c_str()); - if (!currentServer.hostname.empty() || currentServer.port != 0) + currentServer.port = (short) config.getValue(currentConfig, 0); + if (!currentServer.hostname.empty() && currentServer.port != 0) { mMostUsedServersListModel->addElement(currentServer); } } - mMostUsedServersDropDown = new ListBox(mMostUsedServersListModel); - ScrollArea *usedScroll = new ScrollArea(mMostUsedServersDropDown); + mMostUsedServersList = new ListBox(mMostUsedServersListModel); + ScrollArea *usedScroll = new ScrollArea(mMostUsedServersList); usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mQuitButton = new Button(_("Quit"), "quit", this); @@ -106,13 +106,12 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo): mServerNameField->setActionEventId("connect"); mPortField->setActionEventId("connect"); - mMostUsedServersDropDown->setActionEventId("changeSelection"); mServerNameField->addActionListener(this); mPortField->addActionListener(this); - mMostUsedServersDropDown->addActionListener(this); + mMostUsedServersList->addSelectionListener(this); - mMostUsedServersDropDown->setSelected(0); + mMostUsedServersList->setSelected(0); place(0, 0, serverLabel); place(0, 1, portLabel); @@ -146,22 +145,13 @@ ServerDialog::~ServerDialog() delete mMostUsedServersListModel; } -void -ServerDialog::action(const gcn::ActionEvent &event) +void ServerDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { // Give focus back to the server dialog. mServerNameField->requestFocus(); } - else if (event.getId() == "changeSelection") - { - // Change the textField Values according to new selection - ServerInfo myServer = mMostUsedServersListModel->getServer - (mMostUsedServersDropDown->getSelected()); - mServerNameField->setText(myServer.hostname); - mPortField->setText(toString(myServer.port)); - } else if (event.getId() == "connect") { // Check login @@ -213,3 +203,12 @@ ServerDialog::action(const gcn::ActionEvent &event) state = STATE_FORCE_QUIT; } } + +void ServerDialog::valueChanged(const gcn::SelectionEvent &event) +{ + // Update the server and post fields according to the new selection + const ServerInfo myServer = mMostUsedServersListModel->getServer + (mMostUsedServersList->getSelected()); + mServerNameField->setText(myServer.hostname); + mPortField->setText(toString(myServer.port)); +} diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index 6922f7a9..432d3a99 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -30,6 +30,7 @@ #include <guichan/actionlistener.hpp> #include <guichan/listmodel.hpp> +#include <guichan/selectionlistener.hpp> #include <string> #include <vector> @@ -77,7 +78,9 @@ class ServersListModel : public gcn::ListModel * * \ingroup Interface */ -class ServerDialog : public Window, public gcn::ActionListener +class ServerDialog : public Window, + public gcn::ActionListener, + public gcn::SelectionListener { public: /** @@ -97,13 +100,18 @@ class ServerDialog : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); + /** + * Called when the selected value changed in the servers list box. + */ + void valueChanged(const gcn::SelectionEvent &event); + private: gcn::TextField *mServerNameField; gcn::TextField *mPortField; gcn::Button *mQuitButton; gcn::Button *mConnectButton; - ListBox *mMostUsedServersDropDown; + ListBox *mMostUsedServersList; ServersListModel *mMostUsedServersListModel; ServerInfo *mServerInfo; diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h index ac2e803d..ebc67722 100644 --- a/src/net/serverinfo.h +++ b/src/net/serverinfo.h @@ -24,7 +24,9 @@ #include <string> -typedef struct SERVER_INFO { +class ServerInfo +{ +public: std::string hostname; unsigned short port; @@ -34,10 +36,10 @@ typedef struct SERVER_INFO { port = 0; } - bool operator==(struct SERVER_INFO other) + bool operator==(const ServerInfo &other) { return (hostname == other.hostname && port == other.port); } -} ServerInfo; +}; #endif // SERVERINFO_H |