Skip to content

Commit

Permalink
UI|Home: Basic column behavior
Browse files Browse the repository at this point in the history
Activating the column being interacted with. Header with information
text and a button. Hiding and showing columns based on game
availability.
  • Loading branch information
skyjake committed Jan 29, 2016
1 parent 0e7b1c3 commit 0e62ea3
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 30 deletions.
14 changes: 12 additions & 2 deletions doomsday/apps/client/include/ui/home/columnwidget.h
Expand Up @@ -19,7 +19,7 @@
#ifndef DENG_CLIENT_UI_COLUMNWIDGET_H
#define DENG_CLIENT_UI_COLUMNWIDGET_H

#include <de/GuiWidget>
#include <de/ScrollAreaWidget>

/**
* Home column.
Expand All @@ -29,12 +29,22 @@
*/
class ColumnWidget : public de::GuiWidget
{
Q_OBJECT

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

de::ScrollAreaWidget &scrollArea();
de::Rule const &maximumContentWidth() const;

void setHighlighted(bool highlighted);
virtual void setHighlighted(bool highlighted);

// Events.
bool dispatchEvent(de::Event const &event,
bool (de::Widget::*memberFunc)(de::Event const &)) override;

signals:
void mouseActivity(QObject const *columnWidget);

private:
DENG2_PRIVATE(d)
Expand Down
38 changes: 38 additions & 0 deletions doomsday/apps/client/include/ui/home/gamecolumnwidget.h
@@ -0,0 +1,38 @@
/** @file gamecolumnwidget.h
*
* @authors Copyright (c) 2016 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_UI_HOME_GAMECOLUMNWIDGET_H
#define DENG_CLIENT_UI_HOME_GAMECOLUMNWIDGET_H

#include "columnwidget.h"

class GameColumnWidget : public ColumnWidget
{
public:
GameColumnWidget(de::String const &name,
de::String const &author,
de::String const &gameTitle,
de::DotPath const &logoId);

void setHighlighted(bool highlighted) override;

private:
DENG2_PRIVATE(d)
};

#endif // DENG_CLIENT_UI_HOME_GAMECOLUMNWIDGET_H
8 changes: 7 additions & 1 deletion doomsday/apps/client/include/ui/home/headerwidget.h
Expand Up @@ -19,7 +19,7 @@
#ifndef DENG_CLIENT_UI_HEADERWIDGET_H
#define DENG_CLIENT_UI_HEADERWIDGET_H

#include <de/GuiWidget>
#include <de/LabelWidget>

/**
* Home column header.
Expand All @@ -29,6 +29,12 @@ class HeaderWidget : public de::GuiWidget
public:
HeaderWidget();

de::LabelWidget &logo();
de::LabelWidget &title();
de::LabelWidget &info();

void setLogoImage(de::DotPath const &imageId);

private:
DENG2_PRIVATE(d)
};
Expand Down
1 change: 1 addition & 0 deletions doomsday/apps/client/include/ui/home/homewidget.h
Expand Up @@ -39,6 +39,7 @@ class HomeWidget : public de::GuiWidget

public slots:
void tabChanged();
void mouseActivityInColumn(QObject const *);

private:
DENG2_PRIVATE(d)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -24,6 +24,10 @@ logo {
image libdoom { path = "graphics/game-libdoom.png" }
image libheretic { path = "graphics/game-libheretic.png" }
image libhexen { path = "graphics/game-libhexen.png" }

image doom { path = "graphics/logo-doom.png" }
image heretic { path = "graphics/logo-heretic.png" }
image hexen { path = "graphics/logo-hexen.png" }
}
}

Expand Down
33 changes: 32 additions & 1 deletion doomsday/apps/client/src/ui/home/columnwidget.cpp
Expand Up @@ -30,12 +30,14 @@ DENG_GUI_PIMPL(ColumnWidget)
{
bool highlighted;
LabelWidget *back;
ScrollAreaWidget *scrollArea;
Vector4f bgColor;
Rule const *maxContentWidth = nullptr;

Instance(Public *i) : Base(i)
{
back = new LabelWidget;
scrollArea = new ScrollAreaWidget;

QColor bg;
bg.setHsvF(de::frand(), .9, .5);
Expand All @@ -54,8 +56,21 @@ ColumnWidget::ColumnWidget(String const &name)
{
changeRef(d->maxContentWidth, rule().width() - style().rules().rule("gap") * 2);

AutoRef<Rule> contentMargin = (rule().width() - *d->maxContentWidth) / 2;
d->scrollArea->margins()
.setLeft(contentMargin)
.setRight(contentMargin);

d->scrollArea->rule().setRect(rule());
d->back->rule().setRect(rule());

add(d->back);
add(d->scrollArea);
}

ScrollAreaWidget &ColumnWidget::scrollArea()
{
return *d->scrollArea;
}

Rule const &ColumnWidget::maximumContentWidth() const
Expand All @@ -68,5 +83,21 @@ void ColumnWidget::setHighlighted(bool highlighted)
d->highlighted = highlighted;

d->back->set(Background(highlighted? d->bgColor :
(d->bgColor * Vector4f(.5f, .5f, .5f, 1.f))));
(d->bgColor * Vector4f(.5f, .5f, .5f, 1.f))));
}

bool ColumnWidget::dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event const &))
{
// Observe mouse clicks occurring in the column.
if(event.isMouse() && event.type() == Event::MouseButton)
{
MouseEvent const &mouse = event.as<MouseEvent>();
if(mouse.state() == MouseEvent::Pressed &&
d->scrollArea->contentRect().contains(mouse.pos()))
{
emit mouseActivity(this);
}
}

return GuiWidget::dispatchEvent(event, memberFunc);
}
82 changes: 82 additions & 0 deletions doomsday/apps/client/src/ui/home/gamecolumnwidget.cpp
@@ -0,0 +1,82 @@
/** @file gamecolumnwidget.cpp
*
* @authors Copyright (c) 2016 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/home/gamecolumnwidget.h"
#include "ui/home/headerwidget.h"

using namespace de;

DENG2_PIMPL(GameColumnWidget)
{
HeaderWidget *header;

Instance(Public *i) : Base(i)
{
ScrollAreaWidget &area = self.scrollArea();

area.add(header = new HeaderWidget);
header->rule()
.setInput(Rule::Left, area.contentRule().left())
.setInput(Rule::Top, area.contentRule().top())
.setInput(Rule::Width, area.contentRule().width());
}
};

GameColumnWidget::GameColumnWidget(String const &name,
String const &author,
String const &gameTitle,
DotPath const &logoId)
: ColumnWidget(name)
, d(new Instance(this))
{
scrollArea().setContentSize(maximumContentWidth(),
d->header->rule().height());

d->header->title().setText(String(_E(s) "%1\n" _E(.)_E(w) "%2")
.arg(author)
.arg(gameTitle));
if(!logoId.isEmpty())
{
d->header->setLogoImage(logoId);
}

/// @todo Get these from the games def.
if(name == "doom-column")
{
d->header->info().setText("id Software released DOOM for MS-DOS in 1993. It soon became a massive hit and is regarded as the game that popularized the first-person shooter genre. Since then the franchise has been continued in several sequels, starting with DOOM II: Hell on Earth in 1994. DOOM and many of its follow-ups have been ported to numerous other platforms, and to this day remains a favorite among gamers.");
}
else if(name == "heretic-column")
{
d->header->info().setText("Raven Software released Heretic in 1994. It used a modified version of id Software's DOOM engine. The game featured such enhancements as inventory management and the ability to look up and down. Ambient sound effects were used to improve the atmosphere of the game world.");
}
else if(name == "hexen-column")
{
d->header->info().setText("Raven Software released Hexen in 1996. The company had continued making heavy modifications to the DOOM engine, and Hexen introduced such sophisticated features as a scripting language for game events. The maps were well-designed and interconnected with each other, resulting in a more intriguing game world and more complex puzzles to solve.");
}
else
{
d->header->info().setText("Thanks to its excellent modding support, DOOM was used as a basis for many games and community projects.");
}
}

void GameColumnWidget::setHighlighted(bool highlighted)
{
ColumnWidget::setHighlighted(highlighted);

d->header->setOpacity(highlighted? 1 : .7, .5);
}
103 changes: 101 additions & 2 deletions doomsday/apps/client/src/ui/home/headerwidget.cpp
Expand Up @@ -18,14 +18,113 @@

#include "ui/home/headerwidget.h"

#include <de/LabelWidget>
#include <de/ButtonWidget>
#include <de/PanelWidget>
#include <de/CallbackAction>

using namespace de;

DENG_GUI_PIMPL(HeaderWidget)
{
LabelWidget *logo;
LabelWidget *title;
PanelWidget *infoPanel;
LabelWidget *info;
ButtonWidget *menuButton;

Instance(Public *i) : Base(i)
{}
{
self.add(logo = new LabelWidget);
self.add(title = new LabelWidget);
self.add(infoPanel = new PanelWidget);
info = new LabelWidget;
infoPanel->setContent(info);
self.add(menuButton = new ButtonWidget);
}
};

HeaderWidget::HeaderWidget()
: d(new Instance(this))
{}
{
AutoRef<Rule> logoHeight(new ConstantRule(2 * 120));

margins().setTop("gap");

d->title->setAlignment(ui::AlignLeft);
d->title->setTextLineAlignment(ui::AlignLeft);
d->title->setFont("title");
d->title->setSizePolicy(ui::Fixed, ui::Fixed);
d->title->margins().setLeft("");

d->logo->setSizePolicy(ui::Filled, ui::Filled);
d->logo->setImageFit(ui::FitToSize | ui::OriginalAspectRatio);
d->logo->set(Background(Vector4f(0, 0, 0, 1)));

d->info->setFont("small");
d->info->setAlignment(ui::AlignLeft);
d->info->setTextLineAlignment(ui::AlignLeft);
d->info->setMaximumTextWidth(rule().width());
d->info->setSizePolicy(ui::Fixed, ui::Expand);
d->info->margins().setLeft("").setRight("");

d->menuButton->setSizePolicy(ui::Expand, ui::Expand);
d->menuButton->setFont("small");
d->menuButton->setText("...");
d->menuButton->margins().setTopBottom("unit");
d->menuButton->setAction(new CallbackAction([this] ()
{
if(d->infoPanel->isOpen())
{
d->infoPanel->close(0);
}
else
{
d->infoPanel->open();
}
}));

d->logo->rule()
.setInput(Rule::Height, logoHeight)
.setInput(Rule::Width, Const(0))
.setInput(Rule::Top, rule().top() + margins().top())
.setInput(Rule::Left, rule().left());
d->title->rule()
.setInput(Rule::Height, logoHeight)
.setInput(Rule::Right, rule().right())
.setInput(Rule::Top, d->logo->rule().top())
.setInput(Rule::Left, d->logo->rule().right());
d->menuButton->rule()
.setInput(Rule::Bottom, d->title->rule().bottom())
.setInput(Rule::Left, d->title->rule().left() +
d->title->margins().left());
d->infoPanel->rule()
.setInput(Rule::Top, d->title->rule().bottom())
.setInput(Rule::Left, rule().left());
d->info->rule()
.setInput(Rule::Width, rule().width());

rule().setInput(Rule::Height, logoHeight + d->infoPanel->rule().height());
}

LabelWidget &HeaderWidget::logo()
{
return *d->logo;
}

LabelWidget &HeaderWidget::title()
{
return *d->title;
}

LabelWidget &HeaderWidget::info()
{
return *d->info;
}

void HeaderWidget::setLogoImage(const DotPath &imageId)
{
d->logo->setImage(style().images().image(imageId));
d->logo->rule().setInput(Rule::Width, Const(2 * 160));
d->title->margins().setLeft("gap");
}

0 comments on commit 0e62ea3

Please sign in to comment.