From 4c8baa1cfba22037a41778f02287e657d9b6531f Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 15:48:18 -0700 Subject: [PATCH 01/14] Use `protected` for `StructureInspector` methods --- appOPHD/UI/StructureInspector.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index 24de48983..5b0529f0e 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -21,7 +21,7 @@ class StructureInspector : public Window void update() override; -private: +protected: void onClose(); std::string getDisabledReason() const; void drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer); @@ -29,6 +29,7 @@ class StructureInspector : public Window StringTable buildStringTable() const; +private: Button btnClose; const NAS2D::Image& mIcons; Structure* mStructure = nullptr; From e776ce2760cf85906c2ac0f0a8301a54beb96e00 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 15:55:24 -0700 Subject: [PATCH 02/14] Convert `StructureInspector::formatAge()` to unnamed namespace function --- appOPHD/UI/StructureInspector.cpp | 20 ++++++++++---------- appOPHD/UI/StructureInspector.h | 1 - 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 1934bc674..e4cf3f6ab 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -54,6 +54,15 @@ namespace { return idleReadonTable.at(idleReason); } + + + std::string formatAge(const Structure& structure) + { + if (structure.ages()) { + return std::to_string(structure.age()) + " of " + std::to_string(structure.maxAge()); + } + return "N/A"; + } } @@ -108,7 +117,7 @@ StringTable StructureInspector::buildStringTable() const else { stringTable[{2, 0}].text = "Age:"; - stringTable[{3, 0}].text = formatAge(); + stringTable[{3, 0}].text = formatAge(*mStructure); } stringTable[{0, 1}].text = "Power Required:"; @@ -194,12 +203,3 @@ std::string StructureInspector::getDisabledReason() const return ""; } - -std::string StructureInspector::formatAge() const -{ - if (mStructure->ages()) { - return std::to_string(mStructure->age()) + " of " + std::to_string(mStructure->maxAge()); - } - - return "N/A"; -} diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index 5b0529f0e..ea7786419 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -25,7 +25,6 @@ class StructureInspector : public Window void onClose(); std::string getDisabledReason() const; void drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer); - std::string formatAge() const; StringTable buildStringTable() const; From 7a2299f602ca4f46bb4d2d505039a33c0b653c8d Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 15:56:17 -0700 Subject: [PATCH 03/14] Simplify `formatAge` with ternary operator --- appOPHD/UI/StructureInspector.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index e4cf3f6ab..575dd681d 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -58,10 +58,7 @@ namespace std::string formatAge(const Structure& structure) { - if (structure.ages()) { - return std::to_string(structure.age()) + " of " + std::to_string(structure.maxAge()); - } - return "N/A"; + return structure.ages() ? std::to_string(structure.age()) + " of " + std::to_string(structure.maxAge()) : "N/A"; } } From 143e9ab48b8604f0bce64a0b9fafcacbb2aee8ee Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 15:58:26 -0700 Subject: [PATCH 04/14] Convert `StructureInspector::getDisabledReason()` to unnamed namespace function --- appOPHD/UI/StructureInspector.cpp | 31 ++++++++++++++++--------------- appOPHD/UI/StructureInspector.h | 1 - 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 575dd681d..824a49574 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -56,6 +56,21 @@ namespace } + std::string getDisabledReason(const Structure& structure) + { + if (structure.disabled()) + { + return disabledReasonToString(structure.disabledReason()); + } + else if (structure.isIdle()) + { + return idleReasonToString(structure.idleReason()); + } + + return ""; + } + + std::string formatAge(const Structure& structure) { return structure.ages() ? std::to_string(structure.age()) + " of " + std::to_string(structure.maxAge()) : "N/A"; @@ -123,7 +138,7 @@ StringTable StructureInspector::buildStringTable() const stringTable[{2, 1}].text = "State:"; stringTable[{3, 1}].text = mStructure->stateDescription(mStructure->state()); - stringTable[{3, 2}].text = getDisabledReason(); + stringTable[{3, 2}].text = getDisabledReason(*mStructure); if (!mStructure->underConstruction() && !mStructure->destroyed()) { @@ -186,17 +201,3 @@ void StructureInspector::drawStructureSpecificTable(NAS2D::Point position, stringTable.position(position); stringTable.draw(renderer); } - -std::string StructureInspector::getDisabledReason() const -{ - if (mStructure->disabled()) - { - return disabledReasonToString(mStructure->disabledReason()); - } - else if (mStructure->isIdle()) - { - return idleReasonToString(mStructure->idleReason()); - } - - return ""; -} diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index ea7786419..7d4813506 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -23,7 +23,6 @@ class StructureInspector : public Window protected: void onClose(); - std::string getDisabledReason() const; void drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer); StringTable buildStringTable() const; From 3748115d5764aabde922e8a4deb764c5f82416f7 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:02:29 -0700 Subject: [PATCH 05/14] Use distinct names for structure attribute `StringTable` instances --- appOPHD/UI/StructureInspector.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 824a49574..5468e9c77 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -188,16 +188,16 @@ void StructureInspector::update() } title(mStructure->name()); - auto stringTable = buildStringTable(); - stringTable.draw(renderer); + auto genericStructureAttributes = buildStringTable(); + genericStructureAttributes.draw(renderer); - drawStructureSpecificTable({stringTable.position().x, stringTable.screenRect().endPoint().y + 25}, renderer); + drawStructureSpecificTable({genericStructureAttributes.position().x, genericStructureAttributes.screenRect().endPoint().y + 25}, renderer); } void StructureInspector::drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer) { - StringTable stringTable = mStructure->createInspectorViewTable(); - stringTable.computeRelativeCellPositions(); - stringTable.position(position); - stringTable.draw(renderer); + StringTable specificStructureAttributes = mStructure->createInspectorViewTable(); + specificStructureAttributes.computeRelativeCellPositions(); + specificStructureAttributes.position(position); + specificStructureAttributes.draw(renderer); } From 95cb2a7d760cb620266076fe19b2b566e26ff3d1 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:05:39 -0700 Subject: [PATCH 06/14] Extract variable for `specificAttributeTablePosition` --- appOPHD/UI/StructureInspector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 5468e9c77..ead3317c9 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -191,7 +191,8 @@ void StructureInspector::update() auto genericStructureAttributes = buildStringTable(); genericStructureAttributes.draw(renderer); - drawStructureSpecificTable({genericStructureAttributes.position().x, genericStructureAttributes.screenRect().endPoint().y + 25}, renderer); + const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; + drawStructureSpecificTable(specificAttributeTablePosition, renderer); } void StructureInspector::drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer) From 0481ab57be57505ab84638d5dc25d399b3690422 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:09:10 -0700 Subject: [PATCH 07/14] Merge `drawStructureSpecificTable` into `update` --- appOPHD/UI/StructureInspector.cpp | 7 +------ appOPHD/UI/StructureInspector.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index ead3317c9..66be75b98 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -192,13 +192,8 @@ void StructureInspector::update() genericStructureAttributes.draw(renderer); const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; - drawStructureSpecificTable(specificAttributeTablePosition, renderer); -} - -void StructureInspector::drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer) -{ StringTable specificStructureAttributes = mStructure->createInspectorViewTable(); specificStructureAttributes.computeRelativeCellPositions(); - specificStructureAttributes.position(position); + specificStructureAttributes.position(specificAttributeTablePosition); specificStructureAttributes.draw(renderer); } diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index 7d4813506..ef8ab6432 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -23,7 +23,6 @@ class StructureInspector : public Window protected: void onClose(); - void drawStructureSpecificTable(NAS2D::Point position, NAS2D::Renderer& renderer); StringTable buildStringTable() const; From c2d194f18cdeb9df4c23b98dced15c402a2a86d4 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:25:02 -0700 Subject: [PATCH 08/14] Add `const` overload of `Structure::populationAvailable()` --- appOPHD/MapObjects/Structure.h | 1 + 1 file changed, 1 insertion(+) diff --git a/appOPHD/MapObjects/Structure.h b/appOPHD/MapObjects/Structure.h index b50b5f4c5..daf6188ae 100644 --- a/appOPHD/MapObjects/Structure.h +++ b/appOPHD/MapObjects/Structure.h @@ -120,6 +120,7 @@ class Structure : public MapObject const StorableResources& production() const { return mProductionPool; } const PopulationRequirements& populationRequirements() const; + const PopulationRequirements& populationAvailable() const { return mPopulationAvailable; } PopulationRequirements& populationAvailable() { return mPopulationAvailable; } // ATTRIBUTES From f238363efffae17be873bc1c53ed16cf650aa262 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:26:15 -0700 Subject: [PATCH 09/14] Split generic structure attribute extractions to unnamed namespace function --- appOPHD/UI/StructureInspector.cpp | 114 ++++++++++++++++-------------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 66be75b98..07d80af1c 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -75,6 +75,65 @@ namespace { return structure.ages() ? std::to_string(structure.age()) + " of " + std::to_string(structure.maxAge()) : "N/A"; } + + + StringTable buildGenericStructureAttributesStringTable(const Structure& structure) + { + StringTable stringTable{4, 6}; + + stringTable[{0, 0}].text = "Type:"; + stringTable[{1, 0}].text = structure.classDescription(); + + if (structure.underConstruction()) + { + stringTable[{2, 0}].text = "Turns Remaining:"; + stringTable[{3, 0}].text = std::to_string(structure.turnsToBuild() - structure.age()); + } + else + { + stringTable[{2, 0}].text = "Age:"; + stringTable[{3, 0}].text = formatAge(structure); + } + + stringTable[{0, 1}].text = "Power Required:"; + stringTable[{1, 1}].text = std::to_string(structure.energyRequirement()); + + stringTable[{2, 1}].text = "State:"; + stringTable[{3, 1}].text = structure.stateDescription(structure.state()); + + stringTable[{3, 2}].text = getDisabledReason(structure); + + if (!structure.underConstruction() && !structure.destroyed()) + { + stringTable[{0, 2}].text = "Integrity:"; + stringTable[{1, 2}].text = std::to_string(structure.integrity()); + } + + const auto& populationAvailable = structure.populationAvailable(); + const auto& populationRequirements = structure.populationRequirements(); + + if (populationRequirements.workers > 0) + { + stringTable[{0, 3}].text = "Workers:"; + stringTable[{1, 3}].text = std::to_string(populationAvailable.workers) + " / " + std::to_string(populationRequirements.workers); + stringTable[{1, 3}].textColor = populationAvailable.workers >= populationRequirements.workers ? Color::White : Color::Red; + } + + if (populationRequirements.scientists > 0) + { + stringTable[{0, 4}].text = "Scientists:"; + stringTable[{1, 4}].text = std::to_string(populationAvailable.scientists) + " / " + std::to_string(populationRequirements.scientists); + stringTable[{1, 4}].textColor = populationAvailable.scientists >= populationRequirements.scientists ? Color::White : Color::Red; + } + + if (structure.hasCrime()) + { + stringTable[{0, 5}].text = "Crime Rate:"; + stringTable[{1, 5}].text = std::to_string(structure.crimeRate()) + "%"; + } + + return stringTable; + } } @@ -113,64 +172,11 @@ void StructureInspector::onClose() StringTable StructureInspector::buildStringTable() const { - StringTable stringTable(4, 6); + auto stringTable = buildGenericStructureAttributesStringTable(*mStructure); stringTable.position(mRect.position + NAS2D::Vector{5, 25}); stringTable.setVerticalPadding(5); stringTable.setColumnFont(2, stringTable.GetDefaultTitleFont()); - - stringTable[{0, 0}].text = "Type:"; - stringTable[{1, 0}].text = mStructure->classDescription(); - - if (mStructure->underConstruction()) - { - stringTable[{2, 0}].text = "Turns Remaining:"; - stringTable[{3, 0}].text = std::to_string(mStructure->turnsToBuild() - mStructure->age()); - } - else - { - stringTable[{2, 0}].text = "Age:"; - stringTable[{3, 0}].text = formatAge(*mStructure); - } - - stringTable[{0, 1}].text = "Power Required:"; - stringTable[{1, 1}].text = std::to_string(mStructure->energyRequirement()); - - stringTable[{2, 1}].text = "State:"; - stringTable[{3, 1}].text = mStructure->stateDescription(mStructure->state()); - - stringTable[{3, 2}].text = getDisabledReason(*mStructure); - - if (!mStructure->underConstruction() && !mStructure->destroyed()) - { - stringTable[{0, 2}].text = "Integrity:"; - stringTable[{1, 2}].text = std::to_string(mStructure->integrity()); - } - - const auto& populationAvailable = mStructure->populationAvailable(); - const auto& populationRequirements = mStructure->populationRequirements(); - - if (populationRequirements.workers > 0) - { - stringTable[{0, 3}].text = "Workers:"; - stringTable[{1, 3}].text = std::to_string(populationAvailable.workers) + " / " + std::to_string(populationRequirements.workers); - stringTable[{1, 3}].textColor = populationAvailable.workers >= populationRequirements.workers ? Color::White : Color::Red; - } - - if (populationRequirements.scientists > 0) - { - stringTable[{0, 4}].text = "Scientists:"; - stringTable[{1, 4}].text = std::to_string(populationAvailable.scientists) + " / " + std::to_string(populationRequirements.scientists); - stringTable[{1, 4}].textColor = populationAvailable.scientists >= populationRequirements.scientists ? Color::White : Color::Red; - } - - if (mStructure->hasCrime()) - { - stringTable[{0, 5}].text = "Crime Rate:"; - stringTable[{1, 5}].text = std::to_string(mStructure->crimeRate()) + "%"; - } - stringTable.computeRelativeCellPositions(); - return stringTable; } From 7442c2b6a7717d3f6d5a7197a76f0ffcbcfee437 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:27:51 -0700 Subject: [PATCH 10/14] Mark local variable as `const` --- appOPHD/UI/StructureInspector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 07d80af1c..6b8408ed8 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -194,7 +194,7 @@ void StructureInspector::update() } title(mStructure->name()); - auto genericStructureAttributes = buildStringTable(); + const auto genericStructureAttributes = buildStringTable(); genericStructureAttributes.draw(renderer); const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; From a701fb3b4ed62db1b367681595481d629f60d2d4 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:29:20 -0700 Subject: [PATCH 11/14] Re-order code to move drawing together --- appOPHD/UI/StructureInspector.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 6b8408ed8..151aabcdf 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -186,8 +186,6 @@ void StructureInspector::update() if (!visible()) { return; } Window::update(); - auto& renderer = Utility::get(); - if (mStructure == nullptr) { throw std::runtime_error("Null pointer to structure within StructureInspector"); @@ -195,11 +193,12 @@ void StructureInspector::update() title(mStructure->name()); const auto genericStructureAttributes = buildStringTable(); - genericStructureAttributes.draw(renderer); - const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; StringTable specificStructureAttributes = mStructure->createInspectorViewTable(); specificStructureAttributes.computeRelativeCellPositions(); specificStructureAttributes.position(specificAttributeTablePosition); + + auto& renderer = Utility::get(); + genericStructureAttributes.draw(renderer); specificStructureAttributes.draw(renderer); } From a86821b8f526e172268aaa21960cd401504509a7 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:35:14 -0700 Subject: [PATCH 12/14] Rename method to `buildGenericStringTable` --- appOPHD/UI/StructureInspector.cpp | 6 +++--- appOPHD/UI/StructureInspector.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 151aabcdf..2e0d3462b 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -155,7 +155,7 @@ void StructureInspector::structure(Structure* structure) if (!mStructure) { return; } - auto stringTable = buildStringTable(); + auto stringTable = buildGenericStringTable(); auto windowWidth = stringTable.screenRect().size.x + 10; size({windowWidth < 350 ? 350 : windowWidth, rect().size.y}); @@ -170,7 +170,7 @@ void StructureInspector::onClose() } -StringTable StructureInspector::buildStringTable() const +StringTable StructureInspector::buildGenericStringTable() const { auto stringTable = buildGenericStructureAttributesStringTable(*mStructure); stringTable.position(mRect.position + NAS2D::Vector{5, 25}); @@ -192,7 +192,7 @@ void StructureInspector::update() } title(mStructure->name()); - const auto genericStructureAttributes = buildStringTable(); + const auto genericStructureAttributes = buildGenericStringTable(); const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; StringTable specificStructureAttributes = mStructure->createInspectorViewTable(); specificStructureAttributes.computeRelativeCellPositions(); diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index ef8ab6432..199807fb8 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -24,7 +24,7 @@ class StructureInspector : public Window protected: void onClose(); - StringTable buildStringTable() const; + StringTable buildGenericStringTable() const; private: Button btnClose; From 5a60a691336412a22a44db21b32d9f33d8cb70c0 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:52:08 -0700 Subject: [PATCH 13/14] Add `protected` method `buildSpecificStringTable` It's a bit strange having to pass in the `position`, though it does mean the result can be stored in a `const` variable. It also means we don't need to store extra data in the class instance to handle this. Long term we should probably make both tables fields of the class, rather than rebuild them every frame. Though doing so would mean moving the `#include` for `StringTable.h` to the `StructureInspector` header file. That has transitive include implications, which I'd like to avoid for the time being. --- appOPHD/UI/StructureInspector.cpp | 13 ++++++++++--- appOPHD/UI/StructureInspector.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 2e0d3462b..2bbcfe594 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -181,6 +181,15 @@ StringTable StructureInspector::buildGenericStringTable() const } +StringTable StructureInspector::buildSpecificStringTable(NAS2D::Point position) const +{ + auto stringTable = mStructure->createInspectorViewTable(); + stringTable.computeRelativeCellPositions(); + stringTable.position(position); + return stringTable; +} + + void StructureInspector::update() { if (!visible()) { return; } @@ -194,9 +203,7 @@ void StructureInspector::update() const auto genericStructureAttributes = buildGenericStringTable(); const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25}; - StringTable specificStructureAttributes = mStructure->createInspectorViewTable(); - specificStructureAttributes.computeRelativeCellPositions(); - specificStructureAttributes.position(specificAttributeTablePosition); + const auto specificStructureAttributes = buildSpecificStringTable(specificAttributeTablePosition); auto& renderer = Utility::get(); genericStructureAttributes.draw(renderer); diff --git a/appOPHD/UI/StructureInspector.h b/appOPHD/UI/StructureInspector.h index 199807fb8..417a49199 100644 --- a/appOPHD/UI/StructureInspector.h +++ b/appOPHD/UI/StructureInspector.h @@ -25,6 +25,7 @@ class StructureInspector : public Window void onClose(); StringTable buildGenericStringTable() const; + StringTable buildSpecificStringTable(NAS2D::Point position) const; private: Button btnClose; From 4f7f4f7099eb732a8282e4cf998427c906f47b04 Mon Sep 17 00:00:00 2001 From: Daniel Stevens Date: Fri, 21 Feb 2025 16:56:24 -0700 Subject: [PATCH 14/14] Set `title` once when the `structure` is set There's really no need to update the `title` every frame. --- appOPHD/UI/StructureInspector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appOPHD/UI/StructureInspector.cpp b/appOPHD/UI/StructureInspector.cpp index 2bbcfe594..70cf9866a 100644 --- a/appOPHD/UI/StructureInspector.cpp +++ b/appOPHD/UI/StructureInspector.cpp @@ -155,6 +155,8 @@ void StructureInspector::structure(Structure* structure) if (!mStructure) { return; } + title(mStructure->name()); + auto stringTable = buildGenericStringTable(); auto windowWidth = stringTable.screenRect().size.x + 10; @@ -199,7 +201,6 @@ void StructureInspector::update() { throw std::runtime_error("Null pointer to structure within StructureInspector"); } - title(mStructure->name()); const auto genericStructureAttributes = buildGenericStringTable(); const auto specificAttributeTablePosition = genericStructureAttributes.screenRect().crossYPoint() + NAS2D::Vector{0, 25};