Skip to content

Commit

Permalink
UI|Resources|Home: PackagesDialog can be used for selecting optionals
Browse files Browse the repository at this point in the history
The [...] buttons in PackagesDialog now show a "Select Packages" item
if the package has optional content.
  • Loading branch information
skyjake committed Jul 5, 2016
1 parent 2c7d91b commit 92d2c58
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
Expand Up @@ -28,7 +28,7 @@ class PackageContentOptionsWidget : public de::GuiWidget
{
public:
PackageContentOptionsWidget(de::String const &packageId,
de::Rule const &maxHeight,
de::Rule const &maxHeight,
de::String const &name = de::String());

private:
Expand Down
23 changes: 21 additions & 2 deletions doomsday/apps/client/src/ui/dialogs/packagesdialog.cpp
Expand Up @@ -216,7 +216,26 @@ DENG_GUI_PIMPL(PackagesDialog)
// Action for showing information about the package.
actions << new ui::SubwidgetItem(tr("..."), ui::Up, [this] () -> PopupWidget *
{
return new PackagePopupWidget(browser->actionPackage());
String const id = browser->actionPackage();
if (Package::hasOptionalContent(id))
{
auto *menu = new PopupMenuWidget;
menu->setColorTheme(Inverted);
menu->items()
<< new ui::SubwidgetItem(tr("Info"), ui::Up,
[this] () -> PopupWidget * {
return new PackagePopupWidget(browser->actionPackage());
})
<< new ui::ActionItem(style().images().image("gear"), tr("Select Packages"),
new CallbackAction([this] () {
browser->openContentOptions(*browser->actionItem());
}));
return menu;
}
else
{
return new PackagePopupWidget(id);
}
});

// Action for (de)selecting the package.
Expand Down Expand Up @@ -283,7 +302,7 @@ DENG_GUI_PIMPL(PackagesDialog)
{
// Only list here the game data files; Doomsday's PK3s are always
// there so listing them is not very helpful.
if (Package::tags(*file).contains(QStringLiteral("gamedata")))
if (Package::matchTags(*file, QStringLiteral("\\bgamedata\\b")))
{
// Resolve indirection (symbolic links and interpretations) to
// describe the actual source file of the package.
Expand Down
5 changes: 3 additions & 2 deletions doomsday/apps/client/src/ui/home/packagescolumnwidget.cpp
Expand Up @@ -21,11 +21,12 @@
#include "ui/widgets/packagepopupwidget.h"
#include "ui/widgets/homeitemwidget.h"

#include <de/PopupMenuWidget>
#include <de/CallbackAction>
#include <de/Config>
#include <de/DirectoryListDialog>
#include <de/Loop>
#include <de/Package>
#include <de/PopupMenuWidget>
#include <de/ui/ActionItem>
#include <de/ui/SubwidgetItem>

Expand Down Expand Up @@ -74,7 +75,7 @@ DENG_GUI_PIMPL(PackagesColumnWidget)
return new PackagePopupWidget(packageId);
});

if (DataBundle::packageBundleFormat(packageId) == DataBundle::Collection)
if (Package::hasOptionalContent(packageId))
{
auto openOpts = [this] () {
packages->openContentOptions(*packages->actionItem());
Expand Down
Expand Up @@ -328,7 +328,7 @@ DENG_GUI_PIMPL(PackageContentOptionsWidget)
};

PackageContentOptionsWidget::PackageContentOptionsWidget(String const &packageId,
Rule const &maxHeight,
Rule const &maxHeight,
String const &name)
: GuiWidget(name)
, d(new Impl(this, packageId, maxHeight))
Expand Down
39 changes: 5 additions & 34 deletions doomsday/apps/client/src/ui/widgets/packageswidget.cpp
Expand Up @@ -323,51 +323,22 @@ DENG_GUI_PIMPL(PackagesWidget)

void openContentOptions()
{
DENG2_ASSERT(_item->file->target().maybeAs<DataBundle>());
DENG2_ASSERT(_item->file->target().maybeAs<DataBundle>()->format() == DataBundle::Collection);
DENG2_ASSERT(Package::hasOptionalContent(*_item->file));

if (!_optionsPopup)
{
_optionsPopup.reset(new PopupWidget);
_optionsPopup->setDeleteAfterDismissed(true);
_optionsPopup->setAnchorAndOpeningDirection(rule(), ui::Left);

//_panelScroll = new ScrollAreaWidget;
//_panelScroll->enableIndicatorDraw(true);

auto *opts = new PackageContentOptionsWidget(packageId(), root().viewHeight());

// Add a close button.
auto *close = new ButtonWidget;
close->setSizePolicy(ui::Expand, ui::Expand);
close->margins().set("dialog.gap");
close->setStyleImage("close.ringless", "small");
//close->setImageColor(style().colors().colorf("altaccent"));
close->setActionFn([this] ()
_optionsPopup->closeButton().setActionFn([this] ()
{
root().setFocus(this);
_optionsPopup->close();
});
close->setBackgroundColor("transparent");
close->rule()
.setInput(Rule::Right, opts->rule().right() - opts->margins().right())
.setInput(Rule::Top, opts->rule().top() + opts->margins().top());

// Embed the options inside a scroll area so longer contents can be
// scrolled.
//_panelScroll->add(opts);
opts->add(close);
//_panelScroll->setContentSize(opts->rule().width(), opts->rule().height());

auto *opts = new PackageContentOptionsWidget(packageId(), root().viewHeight());
opts->rule().setInput(Rule::Width, rule().width());
//.setInput(Rule::Top, opts->contentRule().top())
//.setInput(Rule::Left, opts->contentRule().left());
/*_panelScroll->rule()
.setInput(Rule::Width, rule().width())
.setInput(Rule::Height,
OperatorRule::minimum(root().viewHeight(),
opts->rule().height()));*/

_optionsPopup->setContent(opts);//Scroll);
_optionsPopup->setContent(opts);
add(_optionsPopup);
_optionsPopup->open();
}
Expand Down
4 changes: 4 additions & 0 deletions doomsday/sdk/libcore/include/de/filesys/package.h
Expand Up @@ -181,6 +181,10 @@ class DENG2_PUBLIC Package : public IObject

static void addRequiredPackage(File &packageFile, String const &id);

static bool hasOptionalContent(String const &packageId);

static bool hasOptionalContent(File const &packageFile);

/**
* Splits a string containing a package identifier and version. The
* expected format of the string is `{packageId}_{version}`.
Expand Down
17 changes: 17 additions & 0 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -38,6 +38,8 @@ String const Package::VAR_TITLE ("title");
static String const PACKAGE_ORDER ("package.__order__");
static String const PACKAGE_IMPORT_PATH("package.importPath");
static String const PACKAGE_REQUIRES ("package.requires");
static String const PACKAGE_RECOMMENDS ("package.recommends");
static String const PACKAGE_EXTRAS ("package.extras");
static String const PACKAGE_TAGS ("package.tags");

static String const VAR_ID ("ID");
Expand Down Expand Up @@ -370,6 +372,21 @@ void Package::addRequiredPackage(File &packageFile, String const &id)
packageFile.objectNamespace().appendToArray(PACKAGE_REQUIRES, new TextValue(id));
}

bool Package::hasOptionalContent(String const &packageId)
{
if (File const *file = PackageLoader::get().select(packageId))
{
return hasOptionalContent(*file);
}
return false;
}

bool Package::hasOptionalContent(File const &packageFile)
{
Record const &meta = packageFile.objectNamespace();
return meta.has(PACKAGE_RECOMMENDS) || meta.has(PACKAGE_EXTRAS);
}

static String stripAfterFirstUnderscore(String str)
{
int pos = str.indexOf('_');
Expand Down

0 comments on commit 92d2c58

Please sign in to comment.