Skip to content

Commit

Permalink
UI|Client: Added a rudimentary manual "Connect to Server" dialog
Browse files Browse the repository at this point in the history
This dialog is basically a GUI for the 'connect' console command.
It is only available when a game is loaded, as 'connect' cannot
change the current game.

A more full-featured dialog would first query the given address and
then display some indication of what has been found, if any.

A drop-down list of known server addresses might also be handy
(cf. Shell).
  • Loading branch information
skyjake committed Feb 22, 2014
1 parent 460d13a commit 66651e8
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -379,6 +379,7 @@ DENG_HEADERS += \
include/ui/dialogs/gamesdialog.h \
include/ui/dialogs/inputsettingsdialog.h \
include/ui/dialogs/logsettingsdialog.h \
include/ui/dialogs/manualconnectiondialog.h \
include/ui/dialogs/networksettingsdialog.h \
include/ui/dialogs/renderersettingsdialog.h \
include/ui/dialogs/videosettingsdialog.h \
Expand Down Expand Up @@ -705,6 +706,7 @@ SOURCES += \
src/ui/dialogs/gamesdialog.cpp \
src/ui/dialogs/inputsettingsdialog.cpp \
src/ui/dialogs/logsettingsdialog.cpp \
src/ui/dialogs/manualconnectiondialog.cpp \
src/ui/dialogs/networksettingsdialog.cpp \
src/ui/dialogs/videosettingsdialog.cpp \
src/ui/dialogs/vrsettingsdialog.cpp \
Expand Down
52 changes: 52 additions & 0 deletions doomsday/client/include/ui/dialogs/manualconnectiondialog.h
@@ -0,0 +1,52 @@
/** @file manualconnectiondialog.h Dialog for connecting to a server.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program 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 (at your
* option) any later version. This program 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 this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_MANUALCONNECTIONDIALOG_H
#define DENG_CLIENT_MANUALCONNECTIONDIALOG_H

#include <de/InputDialog>
#include <de/IPersistent>

/**
* Dialog for connecting to a multiplayer server manually using an IP address or domain
* name. The TCP port number can also be optionally provided.
*
* The dialog stores the previously used address persistently.
*/
class ManualConnectionDialog : public de::InputDialog, public de::IPersistent
{
Q_OBJECT

public:
ManualConnectionDialog(de::String const &name = "manualconnection");

// Implements IPersistent.
void operator >> (de::PersistentState &toState) const;
void operator << (de::PersistentState const &fromState);

public slots:
void validate();

protected:
void finish(int result);

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_MANUALCONNECTIONDIALOG_H
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -64,6 +64,7 @@ public slots:
void showAbout();
void showUpdaterSettings();
void showGames();
void connectToServerManually();

protected slots:
void updateCommandLineLayout();
Expand Down
79 changes: 79 additions & 0 deletions doomsday/client/src/ui/dialogs/manualconnectiondialog.cpp
@@ -0,0 +1,79 @@
/** @file manualconnectiondialog.cpp Dialog for connecting to a server.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program 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 (at your
* option) any later version. This program 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 this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "ui/dialogs/manualconnectiondialog.h"
#include <de/PersistentState>

using namespace de;

DENG2_PIMPL_NOREF(ManualConnectionDialog)
{
String usedAddress;
};

ManualConnectionDialog::ManualConnectionDialog(String const &name)
: InputDialog(name), d(new Instance)
{
title().setText(tr("Connect to Server"));
message().setText(tr("Enter the address of the multiplayer server you want to connect to. "
"The address can be a domain name or an IP address. "
"Optionally, you may include a TCP port number, for example "
_E(b) "10.0.1.1:13209" _E(.) "."));

defaultActionItem()->setLabel(tr("Connect"));
buttonWidget(tr("Connect")).disable();

connect(&editor(), SIGNAL(editorContentChanged()), this, SLOT(validate()));
}

void ManualConnectionDialog::operator >> (PersistentState &toState) const
{
toState.names().set(name() + ".address", d->usedAddress);
}

void ManualConnectionDialog::operator << (PersistentState const &fromState)
{
d->usedAddress = fromState.names()[name() + ".address"];
editor().setText(d->usedAddress);
validate();
}

void ManualConnectionDialog::validate()
{
bool valid = true;

if(editor().text().isEmpty() || editor().text().contains(';') ||
editor().text().endsWith(":") || editor().text().startsWith(":"))
{
valid = false;
}

buttonWidget(tr("Connect")).enable(valid);
}

void ManualConnectionDialog::finish(int result)
{
if(result)
{
// The dialog was accepted.
d->usedAddress = editor().text();
}

InputDialog::finish(result);
}

26 changes: 23 additions & 3 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -25,6 +25,7 @@
#include "ui/dialogs/inputsettingsdialog.h"
#include "ui/dialogs/networksettingsdialog.h"
#include "ui/dialogs/renderersettingsdialog.h"
#include "ui/dialogs/manualconnectiondialog.h"
#include "ui/dialogs/vrsettingsdialog.h"
#include "ui/dialogs/gamesdialog.h"
#include "updater/updatersettingsdialog.h"
Expand Down Expand Up @@ -62,6 +63,8 @@ enum MenuItemPositions
POS_GAMES = 0,
POS_UNLOAD = 1,
POS_GAMES_SEPARATOR = 2,
POS_CONNECT = 3,
POS_CONNECT_SEPARATOR = 4,

// Config menu:
POS_RENDERER_SETTINGS = 0,
Expand Down Expand Up @@ -259,9 +262,11 @@ DENG_GUI_PIMPL(TaskBarWidget)
{
updateStatus();

itemWidget(mainMenu, POS_GAMES) .show(!newGame.isNull());
itemWidget(mainMenu, POS_UNLOAD) .show(!newGame.isNull());
itemWidget(mainMenu, POS_GAMES_SEPARATOR).show(!newGame.isNull());
itemWidget(mainMenu, POS_GAMES) .show(!newGame.isNull());
itemWidget(mainMenu, POS_UNLOAD) .show(!newGame.isNull());
itemWidget(mainMenu, POS_GAMES_SEPARATOR) .show(!newGame.isNull());
itemWidget(mainMenu, POS_CONNECT) .show(!newGame.isNull());
itemWidget(mainMenu, POS_CONNECT_SEPARATOR).show(!newGame.isNull());

itemWidget(configMenu, POS_RENDERER_SETTINGS).show(!newGame.isNull());
itemWidget(configMenu, POS_VR_SETTINGS) .show(!newGame.isNull());
Expand Down Expand Up @@ -410,6 +415,8 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
<< new ui::ActionItem(tr("Games..."), new SignalAction(this, SLOT(showGames())))
<< unloadMenu // hidden with null-game
<< new ui::Item(ui::Item::Separator)
<< new ui::ActionItem(tr("Connect to Server..."), new SignalAction(this, SLOT(connectToServerManually())))
<< new ui::Item(ui::Item::Separator)
<< new ui::ActionItem(tr("Check for Updates..."), new CommandAction("updateandnotify"))
<< new ui::ActionItem(tr("About Doomsday"), new SignalAction(this, SLOT(showAbout())))
<< new ui::Item(ui::Item::Separator)
Expand All @@ -418,6 +425,8 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
d->itemWidget(d->mainMenu, POS_GAMES).hide();
d->itemWidget(d->mainMenu, POS_UNLOAD).hide();
d->itemWidget(d->mainMenu, POS_GAMES_SEPARATOR).hide();
d->itemWidget(d->mainMenu, POS_CONNECT).hide();
d->itemWidget(d->mainMenu, POS_CONNECT_SEPARATOR).hide();

d->itemWidget(d->configMenu, POS_RENDERER_SETTINGS).hide();
d->itemWidget(d->configMenu, POS_VR_SETTINGS).hide();
Expand Down Expand Up @@ -707,6 +716,17 @@ void TaskBarWidget::showGames()
games->exec(root());
}

void TaskBarWidget::connectToServerManually()
{
ManualConnectionDialog *dlg = new ManualConnectionDialog;
dlg->setDeleteAfterDismissed(true);
if(dlg->exec(root()))
{
// Connect to the provided address.
Con_Executef(CMDS_DDAY, false, "connect %s", dlg->editor().text().toLatin1().constData());
}
}

void TaskBarWidget::updateCommandLineLayout()
{
SequentialLayout layout(rule().right(), rule().top(), ui::Left);
Expand Down

0 comments on commit 66651e8

Please sign in to comment.