SaveTool: add a convenience wrapper over ImGui stuff.

This commit is contained in:
Guillaume Jacquemin 2022-02-23 21:59:00 +01:00
parent 883d5d3f41
commit 350ad59f8e
5 changed files with 69 additions and 129 deletions

View File

@ -168,6 +168,12 @@ class SaveTool: public Platform::Sdl2Application, public efsw::FileWatchListener
}
}
template<typename... Args>
void drawAlignedText(const char* text, Args... args) {
ImGui::AlignTextToFramePadding();
ImGui::Text(text, std::forward<Args>(args)...);
}
void openUri(const std::string& uri);
void checkGameState();

View File

@ -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;

View File

@ -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<C
#endif
ImGui::BeginGroup();
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Styles:");
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Base position:");
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Position offset:");
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Base rotation:");
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Rotation offset:");
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Scale:");
drawAlignedText("Styles:");
drawAlignedText("Base position:");
drawAlignedText("Position offset:");
drawAlignedText("Base rotation:");
drawAlignedText("Rotation offset:");
drawAlignedText("Scale:");
ImGui::EndGroup();
ImGui::SameLine();

View File

@ -57,9 +57,8 @@ void SaveTool::drawAbout() {
ImGui::TextWrapped("This application, made for the M.A.S.S. Builder community by Guillaume Jacquemin (aka William JCM), "
"is a rewrite of the wxWidgets-powered M.A.S.S. Builder Save Tool (formerly known as wxMASSManager).");
ImGui::AlignTextToFramePadding();
const char* repo = "https://williamjcm.ovh/git/williamjcm/MassBuilderSaveTool";
ImGui::Text(ICON_FA_GIT_ALT " %s", repo);
drawAlignedText(ICON_FA_GIT_ALT " %s", repo);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(repo);
@ -90,9 +89,8 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Corrade", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", CORRADE_VERSION_STRING);
ImGui::AlignTextToFramePadding();
const char* corrade_website = "https://magnum.graphics/corrade";
ImGui::Text(ICON_FA_GLOBE " %s", corrade_website);
drawAlignedText(ICON_FA_GLOBE " %s", corrade_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(corrade_website);
@ -119,9 +117,8 @@ void SaveTool::drawAbout() {
ImGui::TextUnformatted("Versions used:");
ImGui::BulletText("Magnum: %s", MAGNUM_VERSION_STRING);
ImGui::BulletText("Integration: %s", MAGNUMINTEGRATION_VERSION_STRING);
ImGui::AlignTextToFramePadding();
const char* magnum_website = "https://magnum.graphics";
ImGui::Text(ICON_FA_GLOBE " %s", magnum_website);
drawAlignedText(ICON_FA_GLOBE " %s", magnum_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(magnum_website);
@ -146,9 +143,8 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Dear ImGui", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", IMGUI_VERSION);
ImGui::AlignTextToFramePadding();
const char* imgui_repo = "https://github.com/ocornut/imgui";
ImGui::Text(ICON_FA_GITHUB " %s", imgui_repo);
drawAlignedText(ICON_FA_GITHUB " %s", imgui_repo);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(imgui_repo);
@ -173,9 +169,8 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Simple DirectMedia Layer (SDL) 2", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %i.%i.%i", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
ImGui::AlignTextToFramePadding();
const char* sdl_website = "https://www.libsdl.org/";
ImGui::Text(ICON_FA_GLOBE " %s", sdl_website);
drawAlignedText(ICON_FA_GLOBE " %s", sdl_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(sdl_website);
@ -200,9 +195,8 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("libzip", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::Text("Version used: %s", LIBZIP_VERSION);
ImGui::AlignTextToFramePadding();
const char* libzip_website = "https://libzip.org/";
ImGui::Text(ICON_FA_GLOBE " %s", libzip_website);
drawAlignedText(ICON_FA_GLOBE " %s", libzip_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(libzip_website);
@ -226,9 +220,8 @@ void SaveTool::drawAbout() {
}
if(ImGui::TreeNodeEx("Entropia File System Watcher (efsw)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* efsw_repo = "https://github.com/SpartanJ/efsw";
ImGui::Text(ICON_FA_GITHUB " %s", efsw_repo);
drawAlignedText(ICON_FA_GITHUB " %s", efsw_repo);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(efsw_repo);
@ -252,9 +245,8 @@ void SaveTool::drawAbout() {
}
if(ImGui::TreeNodeEx("C++ Requests (cpr)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* cpr_website = "https://whoshuu.github.io/cpr/";
ImGui::Text(ICON_FA_GLOBE " %s", cpr_website);
drawAlignedText(ICON_FA_GLOBE " %s", cpr_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(cpr_website);
@ -278,9 +270,8 @@ void SaveTool::drawAbout() {
}
if(ImGui::TreeNodeEx("JSON for Modern C++ (aka json.hpp)", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* json_website = "https://json.nlohmann.me/";
ImGui::Text(ICON_FA_GLOBE " %s", json_website);
drawAlignedText(ICON_FA_GLOBE " %s", json_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(json_website);
@ -305,9 +296,8 @@ void SaveTool::drawAbout() {
if(ImGui::TreeNodeEx("Font Awesome", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::TextUnformatted("Version used: 5.15.3");
ImGui::AlignTextToFramePadding();
const char* fa_website = "https://fontawesome.com/";
ImGui::Text(ICON_FA_GLOBE " %s", fa_website);
drawAlignedText(ICON_FA_GLOBE " %s", fa_website);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(fa_website);
@ -323,9 +313,8 @@ void SaveTool::drawAbout() {
}
if(ImGui::TreeNodeEx("IconFontCppHeaders", ImGuiTreeNodeFlags_SpanAvailWidth)) {
ImGui::AlignTextToFramePadding();
const char* icon_repo = "https://github.com/juliettef/IconFontCppHeaders";
ImGui::Text(ICON_FA_GITHUB " %s", icon_repo);
drawAlignedText(ICON_FA_GITHUB " %s", icon_repo);
ImGui::SameLine();
if(ImGui::Button("Copy to clipboard")) {
ImGui::SetClipboardText(icon_repo);

View File

@ -55,8 +55,7 @@ void SaveTool::drawMainMenu() {
ImGui::Separator();
if(ImGui::BeginMenu(ICON_FA_COG " Settings")) {
ImGui::AlignTextToFramePadding();
ImGui::TextUnformatted("Frame limiter:");
drawAlignedText("Frame limiter:");
ImGui::SameLine();
static UnsignedByte selection = static_cast<UnsignedByte>(_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);
}