Allow to draw produced-item icons in recipe dialog and game world
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QSize>
|
||||
#include <QStringList>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
@@ -11,6 +14,7 @@
|
||||
#include "BuildingType.h"
|
||||
#include "DisplayName.h"
|
||||
#include "GameConfig.h"
|
||||
#include "ItemIconCache.h"
|
||||
#include "RecipesConfig.h"
|
||||
#include "RecipeTooltip.h"
|
||||
#include "ShipsConfig.h"
|
||||
@@ -83,23 +87,38 @@ std::vector<RecipeSelectionOption> buildRecipeSelectionOptions(
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Icon shown on the option button (REQ-UI-RECIPE-ICON): the recipe's
|
||||
// configured icon item, else its first output item.
|
||||
const std::string iconItemId = recipe.icon
|
||||
? *recipe.icon
|
||||
: (recipe.outputs.empty() ? std::string()
|
||||
: recipe.outputs.front().item);
|
||||
options.push_back({recipe.id,
|
||||
QString::fromStdString(toDisplayName(recipe.id)),
|
||||
buildRecipeTooltip(recipe)});
|
||||
buildRecipeTooltip(recipe),
|
||||
iconItemId});
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// On-screen size of a recipe option button's item icon (REQ-UI-RECIPE-ICON).
|
||||
const QSize kOptionIconSize(32, 32);
|
||||
}
|
||||
|
||||
RecipeSelectionDialog::RecipeSelectionDialog(
|
||||
const std::vector<RecipeSelectionOption>& options,
|
||||
const QString& title, QWidget* parent)
|
||||
const QString& title, const QString& itemIconDir, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setWindowTitle(title);
|
||||
setModal(true);
|
||||
|
||||
ItemIconCache iconCache(itemIconDir);
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||
QGridLayout* grid = new QGridLayout();
|
||||
mainLayout->addLayout(grid);
|
||||
@@ -109,7 +128,19 @@ RecipeSelectionDialog::RecipeSelectionDialog(
|
||||
{
|
||||
const RecipeSelectionOption& option = options[static_cast<std::size_t>(i)];
|
||||
|
||||
QPushButton* button = new QPushButton(option.caption, this);
|
||||
QPushButton* button = new QPushButton(this);
|
||||
// Icon-only when the produced item has an icon (REQ-UI-RECIPE-ICON); otherwise
|
||||
// fall back to the caption. The name stays reachable via the tooltip.
|
||||
if (!option.iconItemId.empty() && iconCache.hasIcon(option.iconItemId))
|
||||
{
|
||||
button->setIcon(QIcon(iconCache.getPixmap(
|
||||
option.iconItemId, kOptionIconSize.width())));
|
||||
button->setIconSize(kOptionIconSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
button->setText(option.caption);
|
||||
}
|
||||
if (!option.tooltip.isEmpty())
|
||||
{
|
||||
button->setToolTip(option.tooltip);
|
||||
|
||||
Reference in New Issue
Block a user