Skip to content

Commit 81adb60

Browse files
authored
Merge pull request #1465 from OutpostUniverse/Fix/Product-Update-Factory-Report
Fix/product update factory report
2 parents e93ba74 + a80c146 commit 81adb60

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

OPHD/Common.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ std::string difficultyString(Difficulty difficulty)
3838
}
3939

4040

41+
bool productTypeInRange(ProductType productType)
42+
{
43+
return ProductType::PRODUCT_NONE < productType && productType < ProductType::PRODUCT_COUNT;
44+
}
45+
46+
4147
const std::map<StructureState, Color> STRUCTURE_COLOR_TABLE
4248
{
4349
{StructureState::UnderConstruction, Color{150, 150, 150, 100}},

OPHD/Common.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ enum class IdleReason
105105

106106
/**
107107
* Connector Direction.
108-
*
109-
* \note CONNECTOR_INTERSECTION is explicitely set to '1' to prevent
108+
*
109+
* \note CONNECTOR_INTERSECTION is intentionally set to '1' to prevent
110110
* breaking changes with save files.
111111
*/
112112
enum ConnectorDir
@@ -120,7 +120,7 @@ enum ConnectorDir
120120

121121
/**
122122
* Unique identifier code for each structure.
123-
*
123+
*
124124
* \note Each individual structure is identified using a SID_ code as opposed
125125
* the structure Class code which is used to group like structures into
126126
* lists for structure updates.
@@ -174,17 +174,17 @@ enum StructureID
174174

175175
/**
176176
* Factory Product enumeration
177-
*
177+
*
178178
* \note Products are arranged to match the order in which they appear
179179
* in the icon atlas (data/ui/factory.png). In order to allow
180180
* for easy future additions, the icons are grouped into two
181181
* sets of 32 icons. The first 32 are for above ground products,
182182
* the second set for underground products.
183-
*
183+
*
184184
* To easily map to icons in the atlas, padding entries with a
185185
* 'reserved' naming convention have been added. These can be
186186
* replaced as additional products are added.
187-
*
187+
*
188188
* \remark ASSUMPTION: Factories will never have more than 32 individual
189189
* products that they can produce.
190190
*/
@@ -277,6 +277,9 @@ enum ProductType
277277
};
278278

279279

280+
bool productTypeInRange(ProductType productType);
281+
282+
280283
enum class Morale
281284
{
282285
Terrible,

OPHD/UI/Reports/FactoryReport.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ FactoryReport::FactoryReport() :
118118

119119
add(lstProducts, {cboFilterByProduct.rect().position.x + cboFilterByProduct.rect().size.x + 20, mRect.position.y + 230});
120120

121-
txtProductDescription.height(128);
122-
txtProductDescription.textColor(constants::PrimaryTextColor);
121+
mTxtProductDescription.height(128);
122+
mTxtProductDescription.textColor(constants::PrimaryTextColor);
123123

124124
fillLists();
125125
}
@@ -140,7 +140,7 @@ void FactoryReport::clearSelected()
140140
{
141141
lstFactoryList.clearSelected();
142142
selectedFactory = nullptr;
143-
txtProductDescription.text("");
143+
mTxtProductDescription.text("");
144144
}
145145

146146

@@ -270,8 +270,8 @@ void FactoryReport::onResize()
270270
lstProducts.size({detailPanelRect.size.x / 3, detailPanelRect.size.y - 219});
271271
lstProducts.selectionChanged().connect({this, &FactoryReport::onProductSelectionChange});
272272

273-
txtProductDescription.position(lstProducts.rect().crossXPoint() + NAS2D::Vector{158, 0});
274-
txtProductDescription.width(mRect.size.x - txtProductDescription.positionX() - 30);
273+
mTxtProductDescription.position(lstProducts.rect().crossXPoint() + NAS2D::Vector{158, 0});
274+
mTxtProductDescription.width(mRect.size.x - mTxtProductDescription.positionX() - 30);
275275
}
276276

277277

@@ -289,7 +289,7 @@ void FactoryReport::onVisibilityChange(bool visible)
289289

290290
if (selectedProductType != ProductType::PRODUCT_NONE)
291291
{
292-
txtProductDescription.text(ProductCatalogue::get(selectedProductType).Description);
292+
mTxtProductDescription.text(ProductCatalogue::get(selectedProductType).Description);
293293
}
294294
}
295295

@@ -414,6 +414,15 @@ void FactoryReport::onListSelectionChange()
414414
lstProducts.selectIf([productType = selectedFactory->productType()](const auto& item){ return item.tag == productType; });
415415
selectedProductType = selectedFactory->productType();
416416

417+
if (productTypeInRange(selectedProductType))
418+
{
419+
mTxtProductDescription.text(ProductCatalogue::get(selectedProductType).Description);
420+
}
421+
else
422+
{
423+
mTxtProductDescription.text("");
424+
}
425+
417426
StructureState state = selectedFactory->state();
418427
btnApply.visible(state == StructureState::Operational || state == StructureState::Idle);
419428
}
@@ -422,7 +431,7 @@ void FactoryReport::onListSelectionChange()
422431
void FactoryReport::onProductSelectionChange()
423432
{
424433
selectedProductType = static_cast<ProductType>(lstProducts.isItemSelected() ? lstProducts.selected().tag : 0);
425-
txtProductDescription.text(ProductCatalogue::get(selectedProductType).Description);
434+
mTxtProductDescription.text(ProductCatalogue::get(selectedProductType).Description);
426435
}
427436

428437

@@ -485,7 +494,7 @@ void FactoryReport::drawProductPane(Renderer& renderer)
485494
{
486495
renderer.drawText(fontBigBold, ProductCatalogue::get(selectedProductType).Name, NAS2D::Point{position_x, detailPanelRect.position.y + 180}, constants::PrimaryTextColor);
487496
renderer.drawImage(productImage(selectedProductType), NAS2D::Point{position_x, lstProducts.positionY()});
488-
txtProductDescription.update();
497+
mTxtProductDescription.update();
489498
}
490499

491500
if (selectedFactory->productType() == ProductType::PRODUCT_NONE) { return; }

OPHD/UI/Reports/FactoryReport.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class FactoryReport : public ReportInterface
9797

9898
ListBox<> lstProducts;
9999

100-
TextArea txtProductDescription;
100+
TextArea mTxtProductDescription;
101101

102102
Factory* selectedFactory = nullptr;
103103
ProductType selectedProductType = ProductType::PRODUCT_NONE;

0 commit comments

Comments
 (0)