Skip to content

Commit

Permalink
UI|Home: New transition animation for switching into/away from a game
Browse files Browse the repository at this point in the history
Dismiss and bring back Home with a vertical scrolling animation.
  • Loading branch information
skyjake committed Jul 16, 2016
1 parent 66b5591 commit 7d4fe14
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
2 changes: 2 additions & 0 deletions doomsday/apps/client/include/ui/home/homewidget.h
Expand Up @@ -40,6 +40,8 @@ class HomeWidget : public de::GuiWidget, public de::IPersistent
bool dispatchEvent(de::Event const &event,
bool (de::Widget::*memberFunc)(de::Event const &)) override;

// Events.
void update() override;

// Implements IPersistent.
void operator >> (de::PersistentState &toState) const;
Expand Down
14 changes: 9 additions & 5 deletions doomsday/apps/client/src/ui/clientwindow.cpp
Expand Up @@ -180,16 +180,20 @@ DENG2_PIMPL(ClientWindow)
gameUI->disable();
container().add(gameUI);

home = new HomeWidget;
home->rule().setRect(root.viewRule());
container().add(home);

// Busy widget shows progress indicator and frozen game content.
busy = new BusyWidget;
busy->hide(); // normally hidden
busy->rule().setRect(root.viewRule());
root.add(busy);

home = new HomeWidget;
home->rule().setRect(root.viewRule());
container().add(home);

// Busy progress should be visible over the Home.
busy->progress().orphan();
container().add(&busy->progress());

// Common notification area.
notifications = new NotificationAreaWidget;
notifications->useDefaultPlacement(game->rule());
Expand Down Expand Up @@ -1040,7 +1044,7 @@ void ClientWindow::drawGameContent()

GLState::current().target().clear(GLTarget::ColorDepthStencil);

d->root.drawUntil(*d->notifications);
d->root.drawUntil(*d->home);
}

void ClientWindow::fadeInTaskBarBlur(TimeDelta span)
Expand Down
68 changes: 58 additions & 10 deletions doomsday/apps/client/src/ui/home/homewidget.cpp
Expand Up @@ -44,6 +44,7 @@
using namespace de;

static TimeDelta const SCROLL_SPAN = .5;
static TimeDelta const DISMISS_SPAN = 2.0;

DENG_GUI_PIMPL(HomeWidget)
, DENG2_OBSERVES(Games, Readiness)
Expand All @@ -70,10 +71,12 @@ DENG_GUI_PIMPL(HomeWidget)
SafeWidgetPtr<FadeToBlackWidget> blanker;
int currentOffsetTab = 0;
AnimationRule *scrollOffset;
AnimationRule *dismissOffset;
ButtonWidget *moveLeft;
ButtonWidget *moveRight;
QTimer moveShowTimer;
ButtonWidget *taskBarHintButton;
bool dismissing = false;

int restoredOffsetTab = -1;
int restoredActiveTab = -1;
Expand All @@ -87,6 +90,8 @@ DENG_GUI_PIMPL(HomeWidget)
columnWidth = new IndirectRule;
scrollOffset = new AnimationRule(0);
scrollOffset->setStyle(Animation::EaseOut);
dismissOffset = new AnimationRule(0);
dismissOffset->setStyle(Animation::EaseBoth);

tabs = new TabWidget;

Expand Down Expand Up @@ -114,7 +119,7 @@ DENG_GUI_PIMPL(HomeWidget)
taskBarHintButton->setOpacity(.66f);
taskBarHintButton->rule()
.setInput(Rule::Right, self.rule().right() - rule("dialog.gap"))
.setInput(Rule::Bottom, self.rule().bottom() - rule("dialog.gap"));
.setInput(Rule::Bottom, self.rule().bottom() - rule("dialog.gap") + *dismissOffset);
taskBarHintButton->setActionFn([this] () {
ClientWindow::main().taskBar().open();
});
Expand Down Expand Up @@ -149,6 +154,7 @@ DENG_GUI_PIMPL(HomeWidget)
{
releaseRef(columnWidth);
releaseRef(scrollOffset);
releaseRef(dismissOffset);
}

void configureEdgeNavigationButton(ButtonWidget &button)
Expand Down Expand Up @@ -231,21 +237,29 @@ DENG_GUI_PIMPL(HomeWidget)

void currentGameChanged(Game const &newGame)
{
if (newGame.isNull())
if (!newGame.isNull())
{
self.show();
//self.show();
//moveOnscreen();
ClientWindow::main().fadeContentFromBlack(1.0);
}
else
/*else
{
self.hide();
}
//self.hide();
moveOffscreen();
}*/
}

void aboutToUnloadGame(Game const &gameBeingUnloaded)
{
if (gameBeingUnloaded.isNull())
{
self.hide();
//self.hide();
moveOffscreen();
}
else
{
moveOnscreen();
}
}

Expand All @@ -256,6 +270,33 @@ DENG_GUI_PIMPL(HomeWidget)
updateLayout();
}

void moveOffscreen()
{
if (fequal(dismissOffset->animation().target(), 0.f))
{
dismissOffset->set(-root().viewHeight(), DISMISS_SPAN);
dismissing = true;
}
}

void moveOnscreen()
{
if (!fequal(dismissOffset->animation().target(), 0.f))
{
self.show();
dismissOffset->set(0, DISMISS_SPAN);
}
}

void checkDismissHiding()
{
if (dismissing && dismissOffset->animation().done())
{
self.hide();
dismissing = false;
}
}

void addColumn(ColumnWidget *col)
{
QObject::connect(col, SIGNAL(mouseActivity(QObject const *)),
Expand Down Expand Up @@ -289,7 +330,8 @@ DENG_GUI_PIMPL(HomeWidget)

// Lay out the columns from left to right.
SequentialLayout layout(self.rule().left() - *scrollOffset,
self.rule().top(), ui::Right);
self.rule().top() + *dismissOffset,
ui::Right);
for (Widget *widget : self.childWidgets())
{
if (!widget->behavior().testFlag(Widget::Hidden))
Expand Down Expand Up @@ -456,12 +498,12 @@ HomeWidget::HomeWidget()
Rule const &gap = rule("gap");
d->tabsBackground->rule()
.setInput(Rule::Left, rule().left())
.setInput(Rule::Top, rule().top())
.setInput(Rule::Top, rule().top() + *d->dismissOffset)
.setInput(Rule::Width, rule().width())
.setInput(Rule::Height, d->tabs->rule().height() + gap*2);
d->tabs->rule()
.setInput(Rule::Width, rule().width())
.setInput(Rule::Top, rule().top() + gap)
.setInput(Rule::Top, rule().top() + gap + *d->dismissOffset)
.setInput(Rule::Left, rule().left());

d->updateLayout();
Expand Down Expand Up @@ -506,6 +548,12 @@ bool HomeWidget::handleEvent(Event const &event)
return false;
}

void HomeWidget::update()
{
GuiWidget::update();
d->checkDismissHiding();
}

PopupWidget *HomeWidget::makeSettingsPopup()
{
PopupMenuWidget *menu = new PopupMenuWidget;
Expand Down

0 comments on commit 7d4fe14

Please sign in to comment.