SaveTool: optimise code readability.
...mostly for Clang/CLion. :D
This commit is contained in:
parent
de2ba9ce7f
commit
572585e648
2 changed files with 114 additions and 68 deletions
|
@ -105,6 +105,9 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
|
|||
auto drawRenamePopup(Containers::ArrayView<char> name_view) -> bool;
|
||||
void drawGeneralInfo();
|
||||
void drawResearchInventory();
|
||||
template<typename Getter, typename Setter>
|
||||
void drawMaterialRow(const char* name, Int tier, Getter getter, Setter setter);
|
||||
void drawUnavailableMaterialRow(const char* name, Int tier);
|
||||
void drawMassManager();
|
||||
auto drawDeleteMassPopup(int mass_index) -> ImGuiID;
|
||||
auto drawDeleteStagedMassPopup(const std::string& filename) -> ImGuiID;
|
||||
|
|
|
@ -287,44 +287,6 @@ void SaveTool::drawResearchInventory() {
|
|||
return;
|
||||
}
|
||||
|
||||
#define unavRow(name, tier) \
|
||||
ImGui::TableNextRow(); \
|
||||
ImGui::TableSetColumnIndex(0); \
|
||||
ImGui::TextUnformatted("T" #tier); \
|
||||
ImGui::TableSetColumnIndex(1); \
|
||||
ImGui::TextUnformatted(name); \
|
||||
ImGui::TableSetColumnIndex(2); \
|
||||
ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION);
|
||||
|
||||
#define matRow(name, tier, var, getter, setter) \
|
||||
ImGui::TableNextRow(); \
|
||||
ImGui::TableSetColumnIndex(0); \
|
||||
ImGui::TextUnformatted("T" #tier); \
|
||||
ImGui::TableSetColumnIndex(1); \
|
||||
ImGui::TextUnformatted(name); \
|
||||
ImGui::TableSetColumnIndex(2); \
|
||||
if(_currentProfile->getter() != -1) { \
|
||||
ImGui::Text("%i", _currentProfile->getter()); \
|
||||
if(_cheatMode) { \
|
||||
ImGui::TableSetColumnIndex(3); \
|
||||
ImGui::PushID(#setter); \
|
||||
static Int var = _currentProfile->getter(); \
|
||||
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) { \
|
||||
(var) = _currentProfile->getter(); \
|
||||
ImGui::OpenPopup("int_edit"); \
|
||||
} \
|
||||
if(drawIntEditPopup(&(var), 9999)) { \
|
||||
if(!_currentProfile->set##setter((var))) { \
|
||||
_queue.addToast(Toast::Type::Error, _currentProfile->lastError()); \
|
||||
} \
|
||||
} \
|
||||
ImGui::PopID(); \
|
||||
} \
|
||||
} \
|
||||
else { \
|
||||
ImGui::TextDisabled("Not found in the save file"); \
|
||||
}
|
||||
|
||||
if(ImGui::BeginTable("##ResearchInventoryTable", 4,
|
||||
ImGuiTableFlags_BordersOuter|ImGuiTableFlags_ScrollY|ImGuiTableFlags_BordersInnerH))
|
||||
{
|
||||
|
@ -337,55 +299,136 @@ void SaveTool::drawResearchInventory() {
|
|||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("Engine materials");
|
||||
|
||||
matRow("Verse steel", 1, verse_steel, verseSteel, VerseSteel)
|
||||
matRow("Undinium", 2, undinium, undinium, Undinium)
|
||||
matRow("Necrium alloy", 3, necrium_alloy, necriumAlloy, NecriumAlloy)
|
||||
matRow("Lunarite", 4, lunarite, lunarite, Lunarite)
|
||||
matRow("Asterite", 5, asterite, asterite, Asterite)
|
||||
unavRow("Hallite fragma", 6)
|
||||
unavRow("Unnoctinium", 7)
|
||||
drawMaterialRow("Verse steel", 1,
|
||||
[this]{ return _currentProfile->verseSteel(); },
|
||||
[this](Int amount){ return _currentProfile->setVerseSteel(amount); });
|
||||
drawMaterialRow("Undinium", 2,
|
||||
[this]{ return _currentProfile->undinium(); },
|
||||
[this](Int amount){ return _currentProfile->setUndinium(amount); });
|
||||
drawMaterialRow("Necrium alloy", 3,
|
||||
[this]{ return _currentProfile->necriumAlloy(); },
|
||||
[this](Int amount){ return _currentProfile->setNecriumAlloy(amount); });
|
||||
drawMaterialRow("Lunarite", 4,
|
||||
[this]{ return _currentProfile->lunarite(); },
|
||||
[this](Int amount){ return _currentProfile->setLunarite(amount); });
|
||||
drawMaterialRow("Asterite", 5,
|
||||
[this]{ return _currentProfile->asterite(); },
|
||||
[this](Int amount){ return _currentProfile->setAsterite(amount); });
|
||||
drawUnavailableMaterialRow("Hallite fragma", 6);
|
||||
drawUnavailableMaterialRow("Unnoctinium", 7);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("OS materials");
|
||||
|
||||
matRow("Ednil", 1, ednil, ednil, Ednil)
|
||||
matRow("Nuflalt", 2, nuflalt, nuflalt, Nuflalt)
|
||||
matRow("Aurelene", 3, aurelene, aurelene, Aurelene)
|
||||
matRow("Soldus", 4, soldus, soldus, Soldus)
|
||||
matRow("Synthesized N", 5, synthesised_n, synthesisedN, SynthesisedN)
|
||||
unavRow("Nanoc", 6)
|
||||
unavRow("Abyssillite", 7)
|
||||
drawMaterialRow("Ednil", 1,
|
||||
[this]{ return _currentProfile->ednil(); },
|
||||
[this](Int amount){ return _currentProfile->setEdnil(amount); });
|
||||
drawMaterialRow("Nuflalt", 2,
|
||||
[this]{ return _currentProfile->nuflalt(); },
|
||||
[this](Int amount){ return _currentProfile->setNuflalt(amount); });
|
||||
drawMaterialRow("Aurelene", 3,
|
||||
[this]{ return _currentProfile->aurelene(); },
|
||||
[this](Int amount){ return _currentProfile->setAurelene(amount); });
|
||||
drawMaterialRow("Soldus", 4,
|
||||
[this]{ return _currentProfile->soldus(); },
|
||||
[this](Int amount){ return _currentProfile->setSoldus(amount); });
|
||||
drawMaterialRow("Synthesized N", 5,
|
||||
[this]{ return _currentProfile->synthesisedN(); },
|
||||
[this](Int amount){ return _currentProfile->setSynthesisedN(amount); });
|
||||
drawUnavailableMaterialRow("Nanoc", 6);
|
||||
drawUnavailableMaterialRow("Abyssillite", 7);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("Architect materials");
|
||||
|
||||
matRow("Alcarbonite", 1, alcarbonite, alcarbonite, Alcarbonite)
|
||||
matRow("Keriphene", 2, keriphene, keriphene, Keriphene)
|
||||
matRow("Nitinol-CM", 3, nitinol_cm, nitinolCM, NitinolCM)
|
||||
matRow("Quarkium", 4, quarkium, quarkium, Quarkium)
|
||||
matRow("Alterene", 5, alterene, alterene, Alterene)
|
||||
unavRow("Cosmium", 6)
|
||||
unavRow("Purified quarkium", 7)
|
||||
drawMaterialRow("Alcarbonite", 1,
|
||||
[this]{ return _currentProfile->alcarbonite(); },
|
||||
[this](Int amount){ return _currentProfile->setAlcarbonite(amount); });
|
||||
drawMaterialRow("Keripehene", 2,
|
||||
[this]{ return _currentProfile->keriphene(); },
|
||||
[this](Int amount){ return _currentProfile->setKeriphene(amount); });
|
||||
drawMaterialRow("Nitinol-CM", 3,
|
||||
[this]{ return _currentProfile->nitinolCM(); },
|
||||
[this](Int amount){ return _currentProfile->setNitinolCM(amount); });
|
||||
drawMaterialRow("Quarkium", 4,
|
||||
[this]{ return _currentProfile->quarkium(); },
|
||||
[this](Int amount){ return _currentProfile->setQuarkium(amount); });
|
||||
drawMaterialRow("Alterene", 5,
|
||||
[this]{ return _currentProfile->alterene(); },
|
||||
[this](Int amount){ return _currentProfile->setAlterene(amount); });
|
||||
drawUnavailableMaterialRow("Cosmium", 6);
|
||||
drawUnavailableMaterialRow("Purified quarkium", 7);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::Text("Quark data");
|
||||
|
||||
matRow("Mixed composition", 1, mixed_composition, mixedComposition, MixedComposition)
|
||||
matRow("Void residue", 2, void_residue, voidResidue, VoidResidue)
|
||||
matRow("Muscular construction", 3, muscular_construction, muscularConstruction, MuscularConstruction)
|
||||
matRow("Mineral exoskeletology", 4, mineral_exoskeletology, mineralExoskeletology, MineralExoskeletology)
|
||||
matRow("Carbonized skin", 5, carbonised_skin, carbonisedSkin, CarbonisedSkin)
|
||||
unavRow("Isolated void particle", 6)
|
||||
unavRow("Weaponised physiology", 7)
|
||||
drawMaterialRow("Mixed composition", 1,
|
||||
[this]{ return _currentProfile->mixedComposition(); },
|
||||
[this](Int amount){ return _currentProfile->setMixedComposition(amount); });
|
||||
drawMaterialRow("Void residue", 2,
|
||||
[this]{ return _currentProfile->voidResidue(); },
|
||||
[this](Int amount){ return _currentProfile->setVoidResidue(amount); });
|
||||
drawMaterialRow("Muscular construction", 3,
|
||||
[this]{ return _currentProfile->muscularConstruction(); },
|
||||
[this](Int amount){ return _currentProfile->setMuscularConstruction(amount); });
|
||||
drawMaterialRow("Mineral exoskeletology", 4,
|
||||
[this]{ return _currentProfile->mineralExoskeletology(); },
|
||||
[this](Int amount){ return _currentProfile->setMineralExoskeletology(amount); });
|
||||
drawMaterialRow("Carbonized skin", 5,
|
||||
[this]{ return _currentProfile->carbonisedSkin(); },
|
||||
[this](Int amount){ return _currentProfile->setCarbonisedSkin(amount); });
|
||||
drawUnavailableMaterialRow("Isolated void particle", 6);
|
||||
drawUnavailableMaterialRow("Weaponised physiology", 7);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
|
||||
#undef unavRow
|
||||
#undef matRow
|
||||
template<typename Getter, typename Setter>
|
||||
void SaveTool::drawMaterialRow(const char* name, Int tier, Getter getter, Setter setter) {
|
||||
static_assert(std::is_same<decltype(getter()), Int>::value, "getter doesn't return an Int, and/or doesn't take zero arguments.");
|
||||
static_assert(std::is_same<decltype(setter(0)), bool>::value, "setter doesn't return a bool, and/or doesn't take a single Int as an argument.");
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("T%i", tier);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::TextUnformatted(name);
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
if(getter() != -1) {
|
||||
ImGui::Text("%i", getter());
|
||||
if(_cheatMode) {
|
||||
ImGui::TableSetColumnIndex(3);
|
||||
ImGui::PushID(name);
|
||||
static Int var = 0;
|
||||
if(drawUnsafeWidget(ImGui::SmallButton, ICON_FA_EDIT)) {
|
||||
(var) = getter();
|
||||
ImGui::OpenPopup("int_edit");
|
||||
}
|
||||
if(drawIntEditPopup(&(var), 9999)) {
|
||||
if(!setter(var)) {
|
||||
_queue.addToast(Toast::Type::Error, _currentProfile->lastError());
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ImGui::TextDisabled("Not found in the save file");
|
||||
}
|
||||
}
|
||||
|
||||
void SaveTool::drawUnavailableMaterialRow(const char* name, Int tier) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
ImGui::Text("T%i", tier);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
ImGui::TextUnformatted(name);
|
||||
ImGui::TableSetColumnIndex(2);
|
||||
ImGui::TextDisabled("Unavailable as of game version " SUPPORTED_GAME_VERSION);
|
||||
}
|
||||
|
||||
void SaveTool::drawMassManager() {
|
||||
|
|
Loading…
Reference in a new issue