From 13f082e8c8a3e22c7f61dffb49f322b641665a5a Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Wed, 31 Jan 2018 21:05:06 +0100 Subject: [PATCH] Implement Credits.txt export from StartupAboutDlg Pressing Ctrl+S while on the Credits screen will save everything to Credits.txt in the current working directory. This is only meant for developers modifying the credits; the shortcut isn't mentioned anywhere. --- Credits.txt | 18 +++--- src/gui/C4StartupAboutDlg.cpp | 115 +++++++++++++++++++++++++++------- src/gui/C4StartupAboutDlg.h | 3 + 3 files changed, 105 insertions(+), 31 deletions(-) diff --git a/Credits.txt b/Credits.txt index e20333645..b2fdf0f04 100644 --- a/Credits.txt +++ b/Credits.txt @@ -1,15 +1,16 @@ Sven Eberhardt (Sven2) -Armin Burgmeier (Clonk-Karl) Günther Brammer (Günther) Nicolas Hake (Isilkor) -Martin Plicht (Mortimer) +Armin Burgmeier (Clonk-Karl) +Lukas Werling (Luchs) +Julius Michaelis (JCaesar) Peter Wortmann (PeterW) -Julius Michaelis (Caesar) Maikel de Vries (Maikel) David Dormagen (Zapper) +Mark Haßelbusch (Marky) Felix Wagner (Clonkonaut) Bernhard Bonigl (Boni) @@ -26,11 +27,8 @@ Martin Strohmeier (K-Pone) Tobias Zwick (Newton) - -Benedict Etzel (B_E), Philipp Kern (pkern), Kevin Zheng and more - -Martin Adam (Win), Florian Graier (Nachtfalter), Mark Haßelbusch (Marky), Merten Ehmig (pluto), Benjamin Herr (Loriel), Armin Schäfer, Pyrit, Philip Holzmann (Batman), Alexander Semeniuk (AlteredARMOR), Andriel, Peewee, Oliver Schneider (ker), Fabian Pietsch, Manuel Rieke (MrBeast), Felix Riese (Fungiform), Carl-Philip Hänsch (Carli), Sebastian Rühl, Gurkenglas and many more: -Luchs, Asmageddon, mizipzor, Tim Blume, Apfelclonk, Sven-Hendrik Haase, Lauri Niskanen (Ape), Daniel Theuke (ST-DDT), Russell, Stan, TomyLobo, Clonkine, Koronis, Johannes Nixdorf (mixi), grgecko, Dominik Bayerl, Misty de Meo, Lorenz Schwittmann, hasufell, Jan Heberer, dylanstrategie, Checkmaty, Faby - -Also, big thanks to Matthes Bender and all those who contributed to previous Clonk titles for the passion they put into the game and for agreeing to make Clonk open source. +Contributors for OpenClonk 8.0: George Tokmaji (Fulgen), Martin Adam (Win), Merten Ehmig (pluto), Florian Graier (Nachtfalter), Philip Holzmann (Foaly), Dominik Bayerl (Kanibal), Linus Heckemann (sphalerite), Pyrit, Armin Schäfer, Tushar Maheshwari, jok, Tarte, Philip Kern (pkern), Arne Schauf (NativeException), Matthias Mailänder, marsmoon +Previous contributors: Tim Blume, Sven-Hendrik Haase, Carl-Philip Hänsch (Carli), Jan Heberer, Benjamin Herr (Loriel), Lauri Niskanen (Ape), Johannes Nixdorf (mixi), Misty de Meo, Fabian Pietsch, Manuel Rieke (MrBeast), Felix Riese (Fungiform), Sebastian Rühl, Oliver Schneider (ker), Lorenz Schwittmann, Alexander Semeniuk (AlteredARMOR), Daniel Theuke (ST-DDT), Andriel, Apfelclonk, Asmageddon, Checkmaty, Clonkine, dylanstrategie, Faby, grgecko, Gurkenglas, hasufell, Koronis, mizipzor, Peewee, Russell, Stan, TomyLobo +Also thanks to our Linux package maintainers Benedict Etzel (B_E), Linus Heckemann (sphalerite), Philip Kern (pkern), Matthias Mailänder, Julian Ospald (hasufell), Kevin Zeng, and more +Finally, a big thanks to Matthes Bender and all those who contributed to previous Clonk titles for the passion they put into the game and for agreeing to make Clonk open source. diff --git a/src/gui/C4StartupAboutDlg.cpp b/src/gui/C4StartupAboutDlg.cpp index c7af2973e..cde79ae9a 100644 --- a/src/gui/C4StartupAboutDlg.cpp +++ b/src/gui/C4StartupAboutDlg.cpp @@ -22,6 +22,8 @@ #include "graphics/C4GraphicsResource.h" #include "gui/C4UpdateDlg.h" +#include + struct PersonList { struct Entry @@ -29,6 +31,7 @@ struct PersonList const char *name, *nick; }; virtual void WriteTo(C4GUI::TextWindow *textbox, CStdFont &font) = 0; + virtual std::string ToString() = 0; virtual ~PersonList() { } }; @@ -45,6 +48,16 @@ static struct DeveloperList : public PersonList textbox->AddTextLine(FormatString("%s (%s)", p.name, p.nick).getData(), &font, C4GUI_MessageFontClr, false, true); } } + + std::string ToString() + { + std::stringstream out; + for (auto& p : developers) + { + out << p.name << " (" << p.nick << ")\n"; + } + return out.str(); + } } // the following lists are all sorted by all-time commit count: git shortlog -s | sort -rn engineAndTools = @@ -86,38 +99,65 @@ static struct ContributorList : public PersonList { static const std::vector contributorsThisRelease, contributors, packageMaintainers; - StdStrBuf ConcatNames(const std::vector& names) + std::string ConcatNames(const std::vector& names, bool with_color) { - StdStrBuf result; + const char *opening_tag = with_color ? "" : ""; + const char *closing_tag = with_color ? "" : ""; + std::stringstream result; + bool first = true; for (auto& p : names) { - if (result.getLength()) result.Append(", "); + if (!first) result << ", "; + first = false; if (p.nick) - result.AppendFormat("%s (%s)", p.name, p.nick); + result << p.name << " " << opening_tag << "(" << p.nick << ")" << closing_tag; else - result.Append(p.name); + result << p.name; } - return result; + return result.str(); + } + + template + std::string WriteLines(Func f, bool with_color) + { + const char *opening_tag = with_color ? "" : ""; + const char *closing_tag = with_color ? "" : ""; + std::stringstream text; + + text << opening_tag << "Contributors for OpenClonk 8.0:" << closing_tag << " "; + text << ConcatNames(contributorsThisRelease, with_color); + f(text); + + text << opening_tag << "Previous contributors:" << closing_tag << " "; + text << ConcatNames(contributors, with_color); + f(text); + + text << opening_tag << "Also thanks to our Linux package maintainers" << closing_tag << " "; + text << ConcatNames(packageMaintainers, with_color); + text << ", and more"; + f(text); + + text << "Finally, a big thanks to Matthes Bender and all those who contributed to previous Clonk titles for the passion they put into the game and for agreeing to make Clonk open source."; + f(text); + + return text.str(); } void WriteTo(C4GUI::TextWindow *textbox, CStdFont &font) { - StdStrBuf text; - text = "Contributors for OpenClonk 8.0: "; - text.Append(ConcatNames(contributorsThisRelease)); - textbox->AddTextLine(text.getData(), &font, C4GUI_MessageFontClr, false, true); + WriteLines([&](std::stringstream& text) + { + textbox->AddTextLine(text.str().c_str(), &font, C4GUI_MessageFontClr, false, true); + text.str(""); + }, true); + } - text = "Previous contributors: "; - text.Append(ConcatNames(contributors)); - textbox->AddTextLine(text.getData(), &font, C4GUI_MessageFontClr, false, true); - - text = "Also thanks to our Linux package maintainers "; - text.Append(ConcatNames(packageMaintainers)); - text.Append(", and more"); - textbox->AddTextLine(text.getData(), &font, C4GUI_MessageFontClr, false, true); - - text = "Finally, a big thanks to Matthes Bender and all those who contributed to previous Clonk titles for the passion they put into the game and for agreeing to make Clonk open source."; - textbox->AddTextLine(text.getData(), &font, C4GUI_MessageFontClr, false, true); + std::string ToString() + { + return WriteLines([&](std::stringstream& text) + { + text << "\n"; + }, false); } } contributors; @@ -226,6 +266,8 @@ C4StartupAboutDlg::C4StartupAboutDlg() : C4StartupDlg(LoadResStr("IDS_DLG_ABOUT" DrawPersonList(C4StartupAboutContributors, contributors, caContributors.GetFromTop(caContributors.GetHeight())); + keySaveCredits = std::make_unique(C4KeyCodeEx(K_S, KEYS_Control), "StartupAboutSaveCredits", KEYSCOPE_Gui, + new C4GUI::DlgKeyCB(*this, &C4StartupAboutDlg::SaveCredits), C4CustomKey::PRIO_CtrlOverride); } C4StartupAboutDlg::~C4StartupAboutDlg() = default; @@ -247,6 +289,37 @@ void C4StartupAboutDlg::DrawPersonList(int title, PersonList& persons, C4Rect& r textbox->UpdateHeight(); } +bool C4StartupAboutDlg::SaveCredits() +{ + std::ofstream credits("Credits.txt", std::ios::out | std::ios::trunc); + if (!credits) + { + GetScreen()->ShowMessageModal("Couldn't open Credits.txt", "Credits", C4GUI::MessageDialog::btnOK, C4GUI::Ico_Error, nullptr); + return true; + } + + credits << "\n"; + credits << engineAndTools.ToString(); + + credits << "\n\n"; + credits << scriptingAndContent.ToString(); + + credits << "\n\n"; + credits << artAndContent.ToString(); + + credits << "\n\n"; + credits << musicAndSound.ToString(); + + credits << "\n\n"; + credits << administration.ToString(); + + credits << "\n\n"; + credits << contributors.ToString(); + + GetScreen()->ShowMessageModal("Saved to Credits.txt", "Credits", C4GUI::MessageDialog::btnOK, C4GUI::Ico_Notify, nullptr); + return true; +} + void C4StartupAboutDlg::DoBack() { C4Startup::Get()->SwitchDialog(C4Startup::SDID_Main); diff --git a/src/gui/C4StartupAboutDlg.h b/src/gui/C4StartupAboutDlg.h index f95767b44..26e686423 100644 --- a/src/gui/C4StartupAboutDlg.h +++ b/src/gui/C4StartupAboutDlg.h @@ -39,6 +39,9 @@ protected: private: void DrawPersonList(int title, struct PersonList&, C4Rect& rect); + bool SaveCredits(); + + std::unique_ptr keySaveCredits; public: void DoBack(); // back to main menu