Skip to content

Commit

Permalink
UI|Client: Replaced "Multiplayer Games" with a "Games" dialog
Browse files Browse the repository at this point in the history
The Games dialog shows both the available game sessions and the
multiplayer games. It uses the same game selection widget that is
used in the Ring Zero UI.
  • Loading branch information
skyjake committed Feb 3, 2014
1 parent e1e2107 commit 87fa846
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 41 deletions.
4 changes: 2 additions & 2 deletions doomsday/client/client.pro
Expand Up @@ -376,9 +376,9 @@ DENG_HEADERS += \
include/ui/dialogs/alertdialog.h \
include/ui/dialogs/audiosettingsdialog.h \
include/ui/dialogs/coloradjustmentdialog.h \
include/ui/dialogs/gamesdialog.h \
include/ui/dialogs/inputsettingsdialog.h \
include/ui/dialogs/logsettingsdialog.h \
include/ui/dialogs/multiplayerdialog.h \
include/ui/dialogs/networksettingsdialog.h \
include/ui/dialogs/renderersettingsdialog.h \
include/ui/dialogs/videosettingsdialog.h \
Expand Down Expand Up @@ -703,9 +703,9 @@ SOURCES += \
src/ui/dialogs/alertdialog.cpp \
src/ui/dialogs/audiosettingsdialog.cpp \
src/ui/dialogs/coloradjustmentdialog.cpp \
src/ui/dialogs/gamesdialog.cpp \
src/ui/dialogs/inputsettingsdialog.cpp \
src/ui/dialogs/logsettingsdialog.cpp \
src/ui/dialogs/multiplayerdialog.cpp \
src/ui/dialogs/networksettingsdialog.cpp \
src/ui/dialogs/videosettingsdialog.cpp \
src/ui/dialogs/vrsettingsdialog.cpp \
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/data/defaultstyle.pack/rules.dei
Expand Up @@ -63,7 +63,7 @@ group console {

group gameselection {
rule max.width { constant $= UNIT * 215 }
rule max.height { constant $= UNIT * 150 }
rule max.height { constant $= UNIT * 215 }
}

group coloradjustment {
Expand Down
@@ -1,4 +1,4 @@
/** @file multiplayerdialog.h Dialog for listing found servers and joining games.
/** @file gamesdialog.h Dialog for viewing and loading available games.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,28 +16,29 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_MULTIPLAYERDIALOG_H
#define DENG_CLIENT_MULTIPLAYERDIALOG_H
#ifndef DENG_CLIENT_GAMESDIALOG_H
#define DENG_CLIENT_GAMESDIALOG_H

#include <de/DialogWidget>

/**
* Dialog for listing found multiplayer servers and joining games.
*
* Servers can be found via the Master Server, LAN Beacon, and manual IP address.
* Dialog for viewing and loading available games.
*/
class MultiplayerDialog : public de::DialogWidget
class GamesDialog : public de::DialogWidget
{
Q_OBJECT

public:
MultiplayerDialog(de::String const &name = "multiplayer");
GamesDialog(de::String const &name = "games");

public slots:
void showSettings();

protected:
void preparePanelForOpening();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_MULTIPLAYERDIALOG_H
#endif // DENG_CLIENT_GAMESDIALOG_H
3 changes: 2 additions & 1 deletion doomsday/client/include/ui/widgets/gameselectionwidget.h
Expand Up @@ -29,8 +29,9 @@ class GameSelectionWidget : public de::ScrollAreaWidget
public:
GameSelectionWidget(de::String const &name = "gameselection");

void setTitleColor(de::DotPath const &colorId);

// Events.
void viewResized();
void update();

private:
Expand Down
2 changes: 2 additions & 0 deletions doomsday/client/include/ui/widgets/mpselectionwidget.h
Expand Up @@ -31,6 +31,8 @@ class MPSelectionWidget : public de::MenuWidget
public:
MPSelectionWidget();

void setColumns(int numberOfColumns);

private:
DENG2_PRIVATE(d)
};
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/taskbarwidget.h
Expand Up @@ -63,6 +63,7 @@ public slots:
void unloadGame();
void showAbout();
void showUpdaterSettings();
void showGames();

protected slots:
void updateCommandLineLayout();
Expand Down
@@ -1,4 +1,4 @@
/** @file multiplayerdialog.cpp Dialog for listing found servers and joining games.
/** @file gamesdialog.cpp Dialog for viewing and loading available games.
*
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -16,35 +16,44 @@
* http://www.gnu.org/licenses</small>
*/

#include "ui/dialogs/multiplayerdialog.h"
#include "CommandAction"
#include "ui/dialogs/gamesdialog.h"
#include "ui/widgets/gameselectionwidget.h"
#include "ui/dialogs/networksettingsdialog.h"

#include "CommandAction"

#include <de/SignalAction>

using namespace de;

DENG_GUI_PIMPL(MultiplayerDialog)
DENG_GUI_PIMPL(GamesDialog)
{
//MenuWidget *list;
GameSelectionWidget *gameSel; //MenuWidget *list;

Instance(Public *i) : Base(i)
{
self.area().add(gameSel = new GameSelectionWidget("games"));

gameSel->enableScrolling(false);
gameSel->setTitleColor("text");
gameSel->rule().setInput(Rule::Height, gameSel->contentRule().height());
}
};

MultiplayerDialog::MultiplayerDialog(String const &name)
: DialogWidget(name, WithHeading), d(new Instance(this))
GamesDialog::GamesDialog(String const &name)
: DialogWidget(name/*, WithHeading*/), d(new Instance(this))
{
heading().setText(tr("Multiplayer Games"));
//heading().setText(tr("Games"));

//LabelWidget *lab = LabelWidget::newWithText(tr("Games from Master Server and local network:"), &area());

LabelWidget *lab = LabelWidget::newWithText(tr("Games from Master Server and local network:"), &area());
//d->gameSel->rule().setInput(Rule::Height, d->gameSel->contentRule().height()/*style().rules().rule("gameselection.max.height")*/);

GridLayout layout(area().contentRule().left(), area().contentRule().top());
layout.setGridSize(1, 0);
//layout.setColumnAlignment(0, ui::AlignRight);

layout << *lab;// << *d->list;
layout << *d->gameSel;

area().setContentSize(layout.width(), layout.height());

Expand All @@ -55,10 +64,20 @@ MultiplayerDialog::MultiplayerDialog(String const &name)
new SignalAction(this, SLOT(showSettings())));
}

void MultiplayerDialog::showSettings()
void GamesDialog::showSettings()
{
NetworkSettingsDialog *dlg = new NetworkSettingsDialog;
dlg->setAnchorAndOpeningDirection(buttonWidget(Id1)->rule(), ui::Up);
dlg->setDeleteAfterDismissed(true);
dlg->exec(root());
}

void GamesDialog::preparePanelForOpening()
{
DialogWidget::preparePanelForOpening();

d->gameSel->rule()
.setInput(Rule::Width, OperatorRule::minimum(
style().rules().rule("gameselection.max.width"),
root().viewWidth() - margins().width()));
}
58 changes: 44 additions & 14 deletions doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -178,11 +178,28 @@ DENG_GUI_PIMPL(GameSelectionWidget)
pendingGames.put(&game);
}

void addExistingGames()
{
for(int i = 0; i < App_Games().count(); ++i)
{
gameAdded(App_Games().byIndex(i));
}
}

void addPendingGames()
{
while(Game *game = pendingGames.take())
{
incomplete->items().append(makeItemForGame(*game));
if(game->allStartupFilesFound())
{
ui::Item *item = makeItemForGame(*game);
available->items().append(item);
available->gameWidget(*item).loadButton().enable();
}
else
{
incomplete->items().append(makeItemForGame(*game));
}
}
}

Expand Down Expand Up @@ -278,6 +295,18 @@ DENG_GUI_PIMPL(GameSelectionWidget)
available->items().sort();
incomplete->items().sort();
}

void updateLayoutForWidth(int width)
{
// If the view is too small, we'll want to reduce the number of items in the menu.
int const maxWidth = style().rules().rule("gameselection.max.width").valuei();

int suitable = clamp(1, 3 * width / maxWidth, 3);

available->setColumns(suitable);
incomplete->setColumns(suitable);
multi->setColumns(suitable);
}
};

GameSelectionWidget::GameSelectionWidget(String const &name)
Expand All @@ -290,27 +319,28 @@ GameSelectionWidget::GameSelectionWidget(String const &name)
// We want the full menu to be visible even when it doesn't fit the
// designated area.
unsetBehavior(ChildVisibilityClipping);

// Maybe there are games loaded already.
d->addExistingGames();
}

void GameSelectionWidget::viewResized()
void GameSelectionWidget::setTitleColor(DotPath const &colorId)
{
ScrollAreaWidget::viewResized();

// If the view is too small, we'll want to reduce the number of items in the menu.
int const maxWidth = style().rules().rule("gameselection.max.width").valuei();
//int const maxHeight = style().rules().rule("gameselection.max.height").valuei();

int suitable = clamp(1, 3 * rule().width().valuei() / maxWidth, 3);
//clamp(1, 8 * rule().height().valuei() / maxHeight, 6));

d->available->setColumns(suitable);
d->incomplete->setColumns(suitable);
d->multi->setColumns(suitable);
d->available->title().setTextColor(colorId);
d->multi->title().setTextColor(colorId);
d->incomplete->title().setTextColor(colorId);
}

void GameSelectionWidget::update()
{
d->addPendingGames();

ScrollAreaWidget::update();

// Adapt grid layout for the widget width.
Rectanglei rect;
if(hasChangedPlace(rect))
{
d->updateLayoutForWidth(rect.width());
}
}
35 changes: 34 additions & 1 deletion doomsday/client/src/ui/widgets/mpselectionwidget.cpp
Expand Up @@ -258,8 +258,41 @@ DENG_GUI_PIMPL(MPSelectionWidget)
}
}
}

/*
void updateLayoutForWidth(int width)
{
// If the view is too small, we'll want to reduce the number of items in the menu.
int const maxWidth = style().rules().rule("mpselection.max.width").valuei();
qDebug() << maxWidth << width;
int suitable = clamp(1, 3 * width / maxWidth, 3);
}*/
};

MPSelectionWidget::MPSelectionWidget()
: MenuWidget("mp-selection"), d(new Instance(this))
{}
{
setGridSize(3, ui::Filled, 0, ui::Expand);
}

void MPSelectionWidget::setColumns(int numberOfColumns)
{
if(layout().maxGridSize().x != numberOfColumns)
{
setGridSize(numberOfColumns, ui::Filled, 0, ui::Expand);
}
}
/*
void MPSelectionWidget::update()
{
MenuWidget::update();
Rectanglei rect;
if(hasChangedPlace(rect))
{
d->updateLayoutForWidth(rect.width());
}
}
*/
11 changes: 9 additions & 2 deletions doomsday/client/src/ui/widgets/taskbarwidget.cpp
Expand Up @@ -26,7 +26,7 @@
#include "ui/dialogs/networksettingsdialog.h"
#include "ui/dialogs/renderersettingsdialog.h"
#include "ui/dialogs/vrsettingsdialog.h"
#include "ui/dialogs/multiplayerdialog.h"
#include "ui/dialogs/gamesdialog.h"
#include "updater/updatersettingsdialog.h"
#include "ui/clientwindow.h"
#include "ui/clientrootwidget.h"
Expand Down Expand Up @@ -403,7 +403,7 @@ TaskBarWidget::TaskBarWidget() : GuiWidget("taskbar"), d(new Instance(this))
<< new ui::SubwidgetItem(style().images().image("updater"), tr("Updater"), ui::Left, makeUpdaterSettings);

d->mainMenu->items()
<< new ui::SubwidgetItem(tr("Multiplayer Games"), ui::Left, makePopup<MultiplayerDialog>)
<< new ui::ActionItem(tr("Games..."), new SignalAction(this, SLOT(showGames())))
<< 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())))
Expand Down Expand Up @@ -695,6 +695,13 @@ void TaskBarWidget::showUpdaterSettings()
dlg->open();
}

void TaskBarWidget::showGames()
{
GamesDialog *games = new GamesDialog;
games->setDeleteAfterDismissed(true);
games->exec(root());
}

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

0 comments on commit 87fa846

Please sign in to comment.