-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract item_process_music_help into its own file
- Loading branch information
James De Ricco
committed
Jul 19, 2024
1 parent
212d0a9
commit abecc37
Showing
3 changed files
with
57 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "gui/menu_filesystem_item_processor_music_help.hpp" | ||
|
||
#include "fmt/format.h" | ||
#include "util/file_system.hpp" | ||
#include "util/gettext.hpp" | ||
|
||
void item_processor_music_help(MenuItem& menu_item, const std::string& file_path, bool in_basedir) { | ||
std::unique_ptr<SoundFile> sound_file; | ||
try { | ||
sound_file = load_sound_file(file_path); | ||
} catch (...) { | ||
menu_item.set_help(""); | ||
return; | ||
} | ||
|
||
const std::vector<std::string>& authors = sound_file->m_authors; | ||
const std::string& license = sound_file->m_license; | ||
const std::string& title = sound_file->m_title; | ||
|
||
if (title.empty() && authors.empty() && license.empty()) { | ||
menu_item.set_help(""); | ||
return; | ||
} | ||
|
||
const std::string filename = FileSystem::basename(file_path); | ||
const std::string title_or_filename_line = title.empty() ? filename : "\"" + title + "\""; // assumes path is just a filename | ||
|
||
std::string author_lines = ""; | ||
|
||
for (const std::string& author : authors) { | ||
author_lines.append("\n" + fmt::format(fmt::runtime(_("Author") +": {}"), author)); | ||
} | ||
|
||
const std::string license_line = fmt::format(fmt::runtime(_("License") + ": {}"), license); | ||
|
||
const std::string help_text = | ||
title_or_filename_line | ||
+ author_lines | ||
+ (license.empty() ? "" : "\n" + license_line); | ||
|
||
menu_item.set_help(help_text); | ||
} | ||
|
||
/* EOF */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef HEADER_SUPERTUX_GUI_MENU_FILESYSTEM_ITEM_PROCESSOR_MUSIC_HELP_HPP | ||
#define HEADER_SUPERTUX_GUI_MENU_FILESYSTEM_ITEM_PROCESSOR_MUSIC_HELP_HPP | ||
|
||
#include "audio/sound_file.hpp" | ||
#include "gui/menu_item.hpp" | ||
|
||
void item_processor_music_help(MenuItem& menu_item, const std::string& file_path, bool in_basedir); | ||
|
||
#endif | ||
|
||
/* EOF */ |