Skip to content

Commit

Permalink
UI|Home: Improved click-to-focus behavior in the game/save lists
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 7, 2016
1 parent ec0d004 commit 344a000
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/ui/home/drawerbuttonwidget.h
Expand Up @@ -44,7 +44,7 @@ class DrawerButtonWidget : public de::GuiWidget

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

signals:
void mouseActivity();
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/include/ui/home/savelistwidget.h
Expand Up @@ -21,12 +21,12 @@

#include <de/MenuWidget>

class SavedSessionListData;
class GameDrawerButton;

class SaveListWidget : public de::MenuWidget
{
public:
SaveListWidget();
SaveListWidget(GameDrawerButton &owner);

private:
DENG2_PRIVATE(d)
Expand Down
34 changes: 31 additions & 3 deletions doomsday/apps/client/src/ui/home/drawerbuttonwidget.cpp
Expand Up @@ -26,6 +26,28 @@ using namespace de;

DENG_GUI_PIMPL(DrawerButtonWidget)
{
struct ClickHandler : public GuiWidget::IEventHandler
{
DrawerButtonWidget &owner;

ClickHandler(DrawerButtonWidget &owner)
: owner(owner) {}

bool handleEvent(GuiWidget &, Event const &event)
{
if(event.type() == Event::MouseButton)
{
MouseEvent const &mouse = event.as<MouseEvent>();
if(owner.hitTest(event) && mouse.state() == MouseEvent::Pressed)
{
owner.root().setFocus(owner.d->background);
emit owner.mouseActivity();
}
}
return false;
}
};

LabelWidget *background;
LabelWidget *icon;
LabelWidget *label;
Expand All @@ -50,8 +72,11 @@ DENG_GUI_PIMPL(DrawerButtonWidget)

icon->set(Background(style().colors().colorf("text")));

drawer->set(Background(Vector4f(0, 0, 0, .3f)));
drawer->set(Background(Vector4f(0, 0, 0, .15f)));
//drawer->margins().setZero();

background->setBehavior(Focusable);
background->addEventHandler(new ClickHandler(self));
}

~Instance()
Expand Down Expand Up @@ -139,11 +164,13 @@ void DrawerButtonWidget::setSelected(bool selected)
d->selected = selected;
if(selected)
{
d->drawer->set(Background(Vector4f(0, 0, 0, .4f)));
d->background->set(Background(style().colors().colorf("background")));
d->showButtons(true);
}
else
{
d->drawer->set(Background(Vector4f(0, 0, 0, .15f)));
d->background->set(Background());
d->showButtons(false);
}
Expand Down Expand Up @@ -182,14 +209,14 @@ void DrawerButtonWidget::addButton(ButtonWidget *button)
}
return false;
}*/

/*
bool DrawerButtonWidget::dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event const &))
{
// Observe mouse clicks occurring in the column.
if(isEnabled() && event.isMouse() && event.type() == Event::MouseButton)
{
MouseEvent const &mouse = event.as<MouseEvent>();
if(mouse.state() == MouseEvent::Pressed &&
if(mouse.state() == MouseEvent::Released &&
contentRect().contains(mouse.pos()))
{
root().setFocus(d->background);
Expand All @@ -199,3 +226,4 @@ bool DrawerButtonWidget::dispatchEvent(Event const &event, bool (Widget::*member
return GuiWidget::dispatchEvent(event, memberFunc);
}
*/
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/home/gamedrawerbutton.cpp
Expand Up @@ -52,7 +52,7 @@ DENG_GUI_PIMPL(GameDrawerButton)
self.addButton(playButton);

// List of saved games.
saves = new SaveListWidget;
saves = new SaveListWidget(self);
saves->rule().setInput(Rule::Width, self.rule().width()); // - self.margins().width());
saves->organizer().setFilter(*this);
saves->setItems(savedItems);
Expand Down
30 changes: 26 additions & 4 deletions doomsday/apps/client/src/ui/home/savelistwidget.cpp
Expand Up @@ -17,14 +17,21 @@
*/

#include "ui/home/savelistwidget.h"
#include "ui/home/gamedrawerbutton.h"
#include "ui/savedsessionlistdata.h"

#include <doomsday/game.h>

#include <de/CallbackAction>

using namespace de;

DENG_GUI_PIMPL(SaveListWidget)
, DENG2_OBSERVES(ChildWidgetOrganizer, WidgetUpdate)
{
Instance(Public *i) : Base(i)
GameDrawerButton &owner;

Instance(Public *i, GameDrawerButton &owner) : Base(i), owner(owner)
{
self.organizer().audienceForWidgetUpdate() += this;
}
Expand All @@ -40,13 +47,28 @@ DENG_GUI_PIMPL(SaveListWidget)
button.margins().set("dialog.gap");
button.set(Background(Vector4f()));

button.setAction(new CallbackAction([this, &button] ()
{
if(button.isUsingInfoStyle())
{
button.useNormalStyle();
button.set(Background());
}
else
{
button.useInfoStyle();
button.set(Background(style().colors().colorf("inverted.background")));
}
emit owner.mouseActivity();
}));

auto const &saveItem = item.as<SavedSessionListData::SaveItem>();
button.setImage(style().images().image("logo.game.libdoom")); //saveItem.image());
button.setImage(style().images().image(Game::logoImageForId(saveItem.gameId())));
}
};

SaveListWidget::SaveListWidget()
: d(new Instance(this))
SaveListWidget::SaveListWidget(GameDrawerButton &owner)
: d(new Instance(this, owner))
{
setGridSize(1, ui::Filled, 0, ui::Expand);
enableScrolling(false);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/game.h
Expand Up @@ -271,6 +271,8 @@ class LIBDOOMSDAY_PUBLIC Game : public de::IObject
/// Register the console commands, variables, etc..., of this module.
static void consoleRegister();

static de::String logoImageForId(de::String const &id);

private:
DENG2_PRIVATE(d)
};
Expand Down
9 changes: 6 additions & 3 deletions doomsday/apps/libdoomsday/src/game.cpp
Expand Up @@ -231,15 +231,18 @@ void Game::setPluginId(pluginid_t newId)

String Game::logoImageId() const
{
String idKey = id();
return logoImageForId(id());
}

String Game::logoImageForId(String const &id)
{
/// @todo The name of the plugin should be accessible via the plugin loader.
String plugName;
if(idKey.contains("heretic"))
if(id.contains("heretic"))
{
plugName = "libheretic";
}
else if(idKey.contains("hexen"))
else if(id.contains("hexen"))
{
plugName = "libhexen";
}
Expand Down

0 comments on commit 344a000

Please sign in to comment.