Skip to content

Commit

Permalink
UI|Client: Close Games dialog when a game session has been selected
Browse files Browse the repository at this point in the history
A signal is emitted from GameSelectionWidget after a selection
has been made.
  • Loading branch information
skyjake committed Feb 3, 2014
1 parent 22a1816 commit c6ee129
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 47 deletions.
4 changes: 3 additions & 1 deletion doomsday/client/include/ui/commandaction.h
Expand Up @@ -33,8 +33,10 @@ class CommandAction : public de::Action
public:
CommandAction(de::String const &cmd, int commandSource = CMDS_DDAY);

de::String command() const { return _command; }

void trigger();
CommandAction *duplicate() const;
Action *duplicate() const;

private:
de::String _command;
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/include/ui/widgets/gameselectionwidget.h
Expand Up @@ -26,6 +26,8 @@
*/
class GameSelectionWidget : public de::ScrollAreaWidget
{
Q_OBJECT

public:
GameSelectionWidget(de::String const &name = "gameselection");

Expand All @@ -34,6 +36,9 @@ class GameSelectionWidget : public de::ScrollAreaWidget
// Events.
void update();

signals:
void gameSessionSelected();

private:
DENG2_PRIVATE(d)
};
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/include/ui/widgets/mpselectionwidget.h
Expand Up @@ -28,11 +28,16 @@
*/
class MPSelectionWidget : public de::MenuWidget
{
Q_OBJECT

public:
MPSelectionWidget();

void setColumns(int numberOfColumns);

signals:
void gameSelected();

private:
DENG2_PRIVATE(d)
};
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/ui/commandaction.cpp
Expand Up @@ -33,7 +33,7 @@ void CommandAction::trigger()
Con_Execute(_source, _command.toUtf8(), false /*silent*/, false /*net*/);
}

CommandAction *CommandAction::duplicate() const
Action *CommandAction::duplicate() const
{
return new CommandAction(_command, _source);
}
2 changes: 2 additions & 0 deletions doomsday/client/src/ui/dialogs/gamesdialog.cpp
Expand Up @@ -43,6 +43,8 @@ DENG_GUI_PIMPL(GamesDialog)
GamesDialog::GamesDialog(String const &name)
: DialogWidget(name/*, WithHeading*/), d(new Instance(this))
{
connect(d->gameSel, SIGNAL(gameSessionSelected()), this, SLOT(accept()));

//heading().setText(tr("Games"));

//LabelWidget *lab = LabelWidget::newWithText(tr("Games from Master Server and local network:"), &area());
Expand Down
37 changes: 34 additions & 3 deletions doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -93,6 +93,7 @@ DENG_GUI_PIMPL(GameSelectionWidget)

case MultiplayerGames:
menu = new MPSelectionWidget;
QObject::connect(menu, SIGNAL(gameSelected()), owner->thisPublic, SIGNAL(gameSessionSelected()));
break;
}

Expand Down Expand Up @@ -188,6 +189,8 @@ DENG_GUI_PIMPL(GameSelectionWidget)

void addPendingGames()
{
if(pendingGames.isEmpty()) return;

while(Game *game = pendingGames.take())
{
if(game->allStartupFilesFound())
Expand All @@ -201,13 +204,36 @@ DENG_GUI_PIMPL(GameSelectionWidget)
incomplete->items().append(makeItemForGame(*game));
}
}

sortGames();
}

struct LoadGameAction : public CommandAction
{
GameSelectionWidget &owner;

LoadGameAction(String const &cmd, GameSelectionWidget &gameSel)
: CommandAction(cmd)
, owner(gameSel)
{}

void trigger()
{
emit owner.gameSessionSelected();
CommandAction::trigger();
}

Action *duplicate() const
{
return new LoadGameAction(command(), owner);
}
};

ui::Item *makeItemForGame(Game &game)
{
String const idKey = game.identityKey();

CommandAction *loadAction = new CommandAction(String("load ") + idKey);
LoadGameAction *loadAction = new LoadGameAction(String("load ") + idKey, self);
String label = String(_E(b) "%1" _E(.) /*_E(s)_E(C) " %2\n" _E(.)_E(.)*/ "\n"
_E(l)_E(D) "%2")
.arg(game.title())
Expand Down Expand Up @@ -260,6 +286,12 @@ DENG_GUI_PIMPL(GameSelectionWidget)
updateGameAvailability();
}

void sortGames()
{
available->items().sort();
incomplete->items().sort();
}

void updateGameAvailability()
{
// Available games.
Expand Down Expand Up @@ -292,8 +324,7 @@ DENG_GUI_PIMPL(GameSelectionWidget)
}
}

available->items().sort();
incomplete->items().sort();
sortGames();
}

void updateLayoutForWidth(int width)
Expand Down
50 changes: 8 additions & 42 deletions doomsday/client/src/ui/widgets/mpselectionwidget.cpp
Expand Up @@ -35,6 +35,7 @@ using namespace de;

DENG_GUI_PIMPL(MPSelectionWidget)
, DENG2_OBSERVES(ServerLink, DiscoveryUpdate)
, DENG2_OBSERVES(ButtonWidget, Press)
, public ChildWidgetOrganizer::IWidgetFactory
{
static ServerLink &link() { return ClientApp::serverLink(); }
Expand Down Expand Up @@ -74,12 +75,6 @@ DENG_GUI_PIMPL(MPSelectionWidget)
*/
struct ServerWidget : public GameSessionWidget
{
//LabelWidget *title;
//ButtonWidget *extra;
//ButtonWidget *join;
//QScopedPointer<SequentialLayout> layout;
//DocumentPopupWidget *info;

struct JoinAction : public Action
{
public:
Expand Down Expand Up @@ -122,43 +117,8 @@ DENG_GUI_PIMPL(MPSelectionWidget)

ServerWidget()
{
//setBehavior(ContentClipping);

//add(title = new LabelWidget);
//add(extra = new ButtonWidget);
//add(join = new ButtonWidget);

//extra->setText(tr("..."));
//join->setText(tr("Join"));

//title->setSizePolicy(ui::Expand, ui::Expand);
//title->setAppearanceAnimation(LabelWidget::AppearGrowVertically, 0.5);
/*title->setAlignment(ui::AlignTop);
title->setTextAlignment(ui::AlignRight);
title->setTextLineAlignment(ui::AlignLeft);
title->setImageAlignment(ui::AlignCenter);
title->setMaximumTextWidth(style().rules().rule("dialog.multiplayer.width").valuei());*/

//extra->setSizePolicy(ui::Expand, ui::Expand);
//join->setSizePolicy(ui::Expand, ui::Expand);

//join->disable();
loadButton().disable();

loadButton().setHeightPolicy(ui::Expand);

/*
layout.reset(new SequentialLayout(rule().left(), rule().top(), ui::Right));
*layout << *title << *extra << *join;
rule().setSize(layout->width(), title->rule().height());
// Extra info popup.
info = new DocumentPopupWidget;
info->document().setMaximumLineWidth(style().rules().rule("dialog.multiplayer.width").valuei());
info->setAnchorAndOpeningDirection(extra->rule(), ui::Up);
add(info);
extra->setAction(new SignalAction(info, SLOT(open())));*/
}

void updateFromItem(ServerListItem const &item)
Expand Down Expand Up @@ -213,7 +173,7 @@ DENG_GUI_PIMPL(MPSelectionWidget)
GuiWidget *makeItemWidget(ui::Item const &item, GuiWidget const *)
{
ServerWidget *w = new ServerWidget;

w->loadButton().audienceForPress += this;
w->rule().setInput(Rule::Height, w->loadButton().rule().height());

// Automatically close the info popup if the dialog is closed.
Expand All @@ -227,6 +187,12 @@ DENG_GUI_PIMPL(MPSelectionWidget)
widget.as<ServerWidget>().updateFromItem(item.as<ServerListItem>());
}

void buttonPressed(ButtonWidget &)
{
// A load button has been pressed.
emit self.gameSelected();
}

void linkDiscoveryUpdate(ServerLink const &link)
{
// Remove obsolete entries.
Expand Down

0 comments on commit c6ee129

Please sign in to comment.