diff --git a/src/SaveTool/SaveTool.h b/src/SaveTool/SaveTool.h index c8e0f83..3530558 100644 --- a/src/SaveTool/SaveTool.h +++ b/src/SaveTool/SaveTool.h @@ -168,6 +168,12 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener } } + template + void drawAlignedText(const char* text, Args... args) { + ImGui::AlignTextToFramePadding(); + ImGui::Text(text, std::forward(args)...); + } + void openUri(const std::string& uri); void checkGameState(); diff --git a/src/SaveTool/SaveTool_MainManager.cpp b/src/SaveTool/SaveTool_MainManager.cpp index 4534c32..b834640 100644 --- a/src/SaveTool/SaveTool_MainManager.cpp +++ b/src/SaveTool/SaveTool_MainManager.cpp @@ -42,10 +42,9 @@ void SaveTool::drawManager() { return; } - ImGui::AlignTextToFramePadding(); - ImGui::Text("Current profile: %s (%s)", - _currentProfile->companyName().c_str(), - _currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); + drawAlignedText("Current profile: %s (%s)", + _currentProfile->companyName().c_str(), + _currentProfile->type() == ProfileType::Demo ? "demo" : "full game"); ImGui::SameLine(); if(ImGui::Button(ICON_FA_ARROW_LEFT " Back to profile manager")) { _currentProfile = nullptr; diff --git a/src/SaveTool/SaveTool_MassViewer.cpp b/src/SaveTool/SaveTool_MassViewer.cpp index b19ba9b..fa4675f 100644 --- a/src/SaveTool/SaveTool_MassViewer.cpp +++ b/src/SaveTool/SaveTool_MassViewer.cpp @@ -218,8 +218,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Neck"); + drawAlignedText("Neck"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##NeckSlider", &_currentMass->jointSliders().neck, 0.0f, 1.0f)) { @@ -228,8 +227,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Body"); + drawAlignedText("Body"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##BodySlider", &_currentMass->jointSliders().body, 0.0f, 1.0f)) { @@ -238,8 +236,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Shoulders"); + drawAlignedText("Shoulders"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##ShouldersSlider", &_currentMass->jointSliders().shoulders, 0.0f, 1.0f)) { @@ -248,8 +245,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Hips"); + drawAlignedText("Hips"); ImGui::TableSetColumnIndex(1); ImGui::SetNextItemWidth(-1.0f); if(ImGui::SliderFloat("##HipsSlider", &_currentMass->jointSliders().hips, 0.0f, 1.0f)) { @@ -258,8 +254,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Arms"); + drawAlignedText("Arms"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{2.0f, 1.0f}); if(ImGui::BeginTable("##UpperLowerArmsLayoutTable", 2)) { @@ -283,8 +278,7 @@ void SaveTool::drawJointSliders() { ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Legs"); + drawAlignedText("Legs"); ImGui::TableSetColumnIndex(1); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{2.0f, 1.0f}); if(ImGui::BeginTable("##UpperLowerLegsLayoutTable", 2)) { @@ -337,8 +331,7 @@ void SaveTool::drawFrameStyles() { } for(Int i = 0; i < 4; i++) { - ImGui::AlignTextToFramePadding(); - ImGui::Text("Slot %d:", i + 1); + drawAlignedText("Slot %d:", i + 1); ImGui::SameLine(); @@ -520,8 +513,7 @@ void SaveTool::drawArmour() { ImGui::TextUnformatted("Styles:"); for(Int j = 0; j < 4; j++) { - ImGui::AlignTextToFramePadding(); - ImGui::Text("Slot %d:", j + 1); + drawAlignedText("Slot %d:", j + 1); ImGui::SameLine(); @@ -547,8 +539,7 @@ void SaveTool::drawArmour() { ImGui::PushID("Decal"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Showing/editing decal"); + drawAlignedText("Showing/editing decal"); for(UnsignedLong j = 0; j < part.decals.size(); j++) { ImGui::SameLine(); ImGui::RadioButton(std::to_string(j + 1).c_str(), &_selectedArmourDecals[i], j); @@ -563,8 +554,7 @@ void SaveTool::drawArmour() { ImGui::PushID("Accessory"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Showing/editing accessory"); + drawAlignedText("Showing/editing accessory"); for(UnsignedInt j = 0; j < part.accessories.size(); j++) { ImGui::SameLine(); ImGui::RadioButton(std::string{char(65 + j)}.c_str(), &_selectedArmourAccessories[i], j); @@ -901,13 +891,13 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { return; } - ImGui::AlignTextToFramePadding(); static const char* labels[] { #define c(enumerator, strenum, name) name, #include "../Maps/WeaponTypes.hpp" #undef c }; - ImGui::Text("%s: %s", labels[UnsignedInt(weapon.type)], weapon.name.c_str()); + + drawAlignedText("%s: %s", labels[UnsignedInt(weapon.type)], weapon.name.c_str()); ImGui::SameLine(); @@ -924,23 +914,18 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { } ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Equipped:"); + drawAlignedText("Equipped:"); if(weapon.type != WeaponType::Shield) { - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Damage type:"); + drawAlignedText("Damage type:"); } if(weapon.type == WeaponType::Melee) { - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Dual-wield:"); + drawAlignedText("Dual-wield:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Custom effect mode:"); + drawAlignedText("Custom effect mode:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Custom effect colour:"); + drawAlignedText("Custom effect colour:"); } ImGui::EndGroup(); @@ -1006,8 +991,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::Separator(); if(ImGui::CollapsingHeader("Weapon parts")) { - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Viewing/editing part:"); + drawAlignedText("Viewing/editing part:"); for(Int i = 0; UnsignedLong(i) < weapon.parts.size(); i++) { if(UnsignedLong(_selectedWeaponPart) >= weapon.parts.size()) { _selectedWeaponPart = 0; @@ -1024,8 +1008,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::TextUnformatted("Styles:"); for(Int i = 0; i < 4; i++) { - ImGui::AlignTextToFramePadding(); - ImGui::Text("Slot %d:", i + 1); + drawAlignedText("Slot %d:", i + 1); ImGui::SameLine(); @@ -1049,8 +1032,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::PushID("Decal"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Showing/editing decal"); + drawAlignedText("Showing/editing decal"); for(UnsignedLong i = 0; i < part.decals.size(); i++) { ImGui::SameLine(); ImGui::RadioButton(std::to_string(i + 1).c_str(), &_selectedWeaponDecal, i); @@ -1065,8 +1047,7 @@ void SaveTool::drawWeaponEditor(Weapon& weapon) { ImGui::PushID("Accessory"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Showing/editing accessory"); + drawAlignedText("Showing/editing accessory"); for(UnsignedLong i = 0; i < part.accessories.size(); i++) { ImGui::SameLine(); ImGui::RadioButton(std::string{char(65 + i)}.c_str(), &_selectedWeaponAccessory, i); @@ -1255,14 +1236,10 @@ auto SaveTool::drawCustomStyle(CustomStyle& style) -> DCSResult { ImGui::TableNextColumn(); ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Colour:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Metallic:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Gloss:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Glow:"); + drawAlignedText("Colour:"); + drawAlignedText("Metallic:"); + drawAlignedText("Gloss:"); + drawAlignedText("Glow:"); ImGui::EndGroup(); ImGui::SameLine(); @@ -1284,25 +1261,18 @@ auto SaveTool::drawCustomStyle(CustomStyle& style) -> DCSResult { ImGui::TableNextColumn(); ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Pattern:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Opacity:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("X offset:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Y offset:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Rotation:"); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Scale:"); + drawAlignedText("Pattern:"); + drawAlignedText("Opacity:"); + drawAlignedText("X offset:"); + drawAlignedText("Y offset:"); + drawAlignedText("Rotation:"); + drawAlignedText("Scale:"); ImGui::EndGroup(); ImGui::SameLine(); ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::Text("%i", style.patternId); + drawAlignedText("%i", style.patternId); ImGui::PushItemWidth(-FLT_MIN); ImGui::SliderFloat("##SliderOpacity", &style.opacity, 0.0f, 1.0f); ImGui::SliderFloat("##SliderOffsetX", &style.offset.x(), 0.0f, 1.0f); @@ -1340,23 +1310,12 @@ void SaveTool::drawDecalEditor(Decal& decal) { ImGui::TableNextColumn(); ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Colour:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Offset:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Rotation:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Scale:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Flip X:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Surface wrap:"); + drawAlignedText("Colour:"); + drawAlignedText("Offset:"); + drawAlignedText("Rotation:"); + drawAlignedText("Scale:"); + drawAlignedText("Flip X:"); + drawAlignedText("Surface wrap:"); ImGui::EndGroup(); ImGui::SameLine(); @@ -1396,14 +1355,9 @@ void SaveTool::drawDecalEditor(Decal& decal) { ImGui::TextUnformatted("Advanced settings. Touch these at your own risk."); ImGui::BeginGroup(); - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("Position:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("U axis:"); - - ImGui::AlignTextToFramePadding(); - ImGui::TextUnformatted("V axis:"); + drawAlignedText("Position:"); + drawAlignedText("U axis:"); + drawAlignedText("V axis:"); ImGui::EndGroup(); ImGui::SameLine(); @@ -1462,18 +1416,12 @@ void SaveTool::drawAccessoryEditor(Accessory& accessory, Containers::ArrayView(_framelimit); @@ -118,8 +117,7 @@ void SaveTool::drawMainMenu() { } if(_updateAvailable) { - ImGui::AlignTextToFramePadding(); - ImGui::Text("Version %s is available.", _latestVersion.c_str()); + drawAlignedText("Version %s is available.", _latestVersion.c_str()); if(ImGui::Button(ICON_FA_FILE_SIGNATURE " Release notes")) { openUri(_releaseLink); }