Skip to content

Commit

Permalink
UI|Client: Added a filter widget for the game selection menu
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 18, 2014
1 parent c4ba7a6 commit 43e3ea8
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -392,6 +392,7 @@ DENG_HEADERS += \
include/ui/widgets/cvarlineeditwidget.h \
include/ui/widgets/cvarsliderwidget.h \
include/ui/widgets/cvartogglewidget.h \
include/ui/widgets/gamefilterwidget.h \
include/ui/widgets/gameselectionwidget.h \
include/ui/widgets/gamesessionwidget.h \
include/ui/widgets/gameuiwidget.h \
Expand Down Expand Up @@ -728,6 +729,7 @@ SOURCES += \
src/ui/widgets/cvarlineeditwidget.cpp \
src/ui/widgets/cvarsliderwidget.cpp \
src/ui/widgets/cvartogglewidget.cpp \
src/ui/widgets/gamefilterwidget.cpp \
src/ui/widgets/gameselectionwidget.cpp \
src/ui/widgets/gamesessionwidget.cpp \
src/ui/widgets/gamewidget.cpp \
Expand Down
51 changes: 51 additions & 0 deletions doomsday/client/include/ui/widgets/gamefilterwidget.h
@@ -0,0 +1,51 @@
/** @file gamefilterwidget.h
*
* @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_GAMEFILTERWIDGET_H
#define DENG_CLIENT_GAMEFILTERWIDGET_H

#include <de/GuiWidget>

/**
* Filtering and sorting parameters for a game selection widget. Allows picking the type
* of games to show (singleplayer or multiplayer) and how the games are sorted.
*
* The widget defines its own height, but width must be set manually.
*/
class GameFilterWidget : public de::GuiWidget
{
Q_OBJECT

public:
enum SortOrder
{
SortByTitle,
SortByIdentityKey
};

public:
GameFilterWidget(de::String const &name = "gamefilter");

signals:
void filterChanged();

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_GAMEFILTERWIDGET_H
3 changes: 3 additions & 0 deletions doomsday/client/include/ui/widgets/gamesessionwidget.h
Expand Up @@ -36,6 +36,9 @@ class GameSessionWidget : public de::GuiWidget
de::ButtonWidget &infoButton();
de::DocumentWidget &document();

/**
* Called immediately before the Info button is pressed.
*/
virtual void updateInfoContent();

private:
Expand Down
71 changes: 71 additions & 0 deletions doomsday/client/src/ui/widgets/gamefilterwidget.cpp
@@ -0,0 +1,71 @@
/** @file gamefilterwidget.cpp
*
* @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/widgets/gamefilterwidget.h"

#include <de/ButtonWidget>
#include <de/ChoiceWidget>
#include <de/SequentialLayout>
#include <de/DialogContentStylist>

using namespace de;

DENG2_PIMPL(GameFilterWidget)
{
ButtonWidget *sp;
ButtonWidget *mp;
ButtonWidget *all;
LabelWidget *sortLabel;
ChoiceWidget *sortBy;
DialogContentStylist stylist;

Instance(Public *i) : Base(i)
{
stylist.setContainer(self);

// Create widgets.
self.add(sp = new ButtonWidget);
self.add(mp = new ButtonWidget);
self.add(all = new ButtonWidget);
sortLabel = LabelWidget::newWithText(tr("Sort By:"), &self);
self.add(sortBy = new ChoiceWidget);

sp->setText(tr("Singleplayer"));
mp->setText(tr("Multiplayer"));
all->setText(tr("All"));
sortLabel->setTextColor("inverted.text");
sortBy->items()
<< new ChoiceItem(tr("Title"), SortByTitle)
<< new ChoiceItem(tr("Identity key"), SortByIdentityKey);

SequentialLayout layout(self.rule().right(), self.rule().top(), ui::Left);
layout << *sortBy << *sortLabel;

AutoRef<Rule> sum(sp->rule().width() + mp->rule().width() + all->rule().width());
SequentialLayout blay(self.rule().left() + self.rule().width() / 2 - sum / 2,
self.rule().top(), ui::Right);
blay << *sp << *mp << *all;
}
};

GameFilterWidget::GameFilterWidget(String const &name)
: GuiWidget(name), d(new Instance(this))
{
rule().setInput(Rule::Height, d->sp->rule().height());
}

10 changes: 7 additions & 3 deletions doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -19,6 +19,7 @@
#include "ui/widgets/gameselectionwidget.h"
#include "ui/widgets/gamesessionwidget.h"
#include "ui/widgets/mpselectionwidget.h"
#include "ui/widgets/gamefilterwidget.h"
#include "CommandAction"
#include "clientapp.h"
#include "games.h"
Expand Down Expand Up @@ -161,6 +162,7 @@ DENG_GUI_PIMPL(GameSelectionWidget)
FIFO<Game> pendingGames;
SequentialLayout superLayout;

GameFilterWidget *filter;
SubsetWidget *available;
SubsetWidget *incomplete;
SubsetWidget *multi;
Expand All @@ -169,6 +171,8 @@ DENG_GUI_PIMPL(GameSelectionWidget)
: Base(i)
, superLayout(i->contentRule().left(), i->contentRule().top(), ui::Down)
{
self.add(filter = new GameFilterWidget);

// Menu of available games.
self.add(available = new SubsetWidget(SubsetWidget::NormalGames,
App_GameLoaded()? tr("Switch Game") : tr("Available Games"), this));
Expand Down Expand Up @@ -203,6 +207,8 @@ DENG_GUI_PIMPL(GameSelectionWidget)
{
superLayout.clear();

superLayout << *filter;

QList<SubsetWidget *> order;
if(!App_GameLoaded())
{
Expand Down Expand Up @@ -295,10 +301,8 @@ DENG_GUI_PIMPL(GameSelectionWidget)
{
String const idKey = game.identityKey();

String label = String(_E(b) "%1" _E(.) /*_E(s)_E(C) " %2\n" _E(.)_E(.)*/ "\n"
_E(l)_E(D) "%2")
String label = String(_E(b) "%1" _E(.) "\n" _E(l)_E(D) "%2")
.arg(game.title())
//.arg(game.author())
.arg(idKey);

GameItem *item = new GameItem(game, label, new LoadGameAction(String("load ") + idKey, self));
Expand Down

0 comments on commit 43e3ea8

Please sign in to comment.