split the selection panel into one card per kind of selection
This commit is contained in:
59
src/ui/selection/RecipeProductionContent.cpp
Normal file
59
src/ui/selection/RecipeProductionContent.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "RecipeProductionContent.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingTarget.h"
|
||||
#include "GameConfig.h"
|
||||
#include "RecipeSelectionControl.h"
|
||||
#include "SelectionNames.h"
|
||||
|
||||
RecipeProductionContent::RecipeProductionContent(const SelectionContext& context,
|
||||
const SelectionRequest& request,
|
||||
QWidget* parent)
|
||||
: BufferedBuildingContent(context, request.buildings.front(), parent)
|
||||
{
|
||||
const BuildingTarget target = resolveBuildingTarget(context, getBuildingId());
|
||||
|
||||
// The control is shown for a construction site too: a site is configured exactly
|
||||
// like the building it will become (REQ-BLD-SITE-CONFIG).
|
||||
m_recipeControl = new RecipeSelectionControl(context, getBuildingId(), target.type,
|
||||
this);
|
||||
getConfigurationLayout()->addWidget(m_recipeControl);
|
||||
}
|
||||
|
||||
void RecipeProductionContent::refreshConfiguration()
|
||||
{
|
||||
const BuildingTarget target = resolveBuildingTarget(getContext(), getBuildingId());
|
||||
if (!target.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
setBuildingIdentity(target.type, getBuildingTypeName(target.type));
|
||||
m_recipeControl->setRecipeId(target.recipeId);
|
||||
}
|
||||
|
||||
BufferedBuildingContent::CycleInfo RecipeProductionContent::getCycleInfo(
|
||||
const Building& building) const
|
||||
{
|
||||
CycleInfo info;
|
||||
const RecipeDef* recipe = building.recipeId.empty()
|
||||
? nullptr
|
||||
: getContext().config->recipes.findRecipeDef(building.recipeId, building.type);
|
||||
if (!recipe)
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
for (const RecipeIngredient& ingredient : recipe->inputs)
|
||||
{
|
||||
info.perCycleInputs[ingredient.item] = ingredient.amount;
|
||||
}
|
||||
for (const RecipeOutput& output : recipe->outputs)
|
||||
{
|
||||
info.perCycleOutputs[output.item] = output.amount;
|
||||
}
|
||||
info.runsProduction = true;
|
||||
info.durationSeconds = recipe->durationSeconds;
|
||||
return info;
|
||||
}
|
||||
Reference in New Issue
Block a user