diff --git a/src/common/font_file.cpp b/src/common/font_file.cpp index 0b234d02..bd7fd583 100644 --- a/src/common/font_file.cpp +++ b/src/common/font_file.cpp @@ -44,11 +44,6 @@ CFontConfigFile::CFontConfigFile() CFontConfigFile::~CFontConfigFile() { - if (m_needsSave) - { - GetLogger()->Warn("Font config file was not properly saved! Saving now...\n"); - Save(); - } } bool CFontConfigFile::Init() @@ -59,13 +54,13 @@ bool CFontConfigFile::Init() bool good; if (m_useCurrentDirectory) { - auto inputStream = MakeUnique("./fonts.ini"); + auto inputStream = MakeUnique("/fonts/fonts.ini"); good = inputStream->good(); stream = std::move(inputStream); } else { - auto inputStream = MakeUnique("fonts.ini"); + auto inputStream = MakeUnique("/fonts/fonts.ini"); good = inputStream->is_open(); stream = std::move(inputStream); } @@ -73,6 +68,7 @@ bool CFontConfigFile::Init() if (good) { bp::ini_parser::read_ini(*stream, m_propertyTree); + GetLogger()->Debug("Fonts config file loaded correctly. \n"); m_loaded = true; } else @@ -88,198 +84,92 @@ bool CFontConfigFile::Init() return true; } -bool CFontConfigFile::Save() -{ - if (m_needsSave) - { - try - { - std::unique_ptr stream; - bool good; - if (m_useCurrentDirectory) - { - auto outputStream = MakeUnique("./fonts.ini"); - good = outputStream->good(); - stream = std::move(outputStream); - } - else - { - auto outputStream = MakeUnique("fonts.ini"); - good = outputStream->is_open(); - stream = std::move(outputStream); - } - - if (good) - { - bp::ini_parser::write_ini(*stream, m_propertyTree); - m_needsSave = false; - } - else - { - GetLogger()->Error("Error on storing fonts config file: failed to open file\n"); - return false; - } - } - catch (std::exception & e) - { - GetLogger()->Error("Error on storing fonts config file: %s\n", e.what()); - return false; - } - } - return true; -} - std::string CFontConfigFile::GetCommonFont() { try { - std::string path = std::string("/fonts/") + m_propertyTree.get("FONT_COMMON"); + std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommon"); return path; } catch (std::exception & e) { GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); - SetCommonFont("dvu_sans.ttf"); return "/fonts/dvu_sans.ttf"; } return ""; } -bool CFontConfigFile::SetCommonFont(std::string filename) -{ - try - { - m_propertyTree.put("FONT_COMMON", filename); - m_needsSave = true; - } - catch (std::exception & e) - { - GetLogger()->Error("Error on editing config file: %s\n", e.what()); - return false; - } - return true; -} - std::string CFontConfigFile::GetCommonBoldFont() { try { - std::string path = std::string("/fonts/") + m_propertyTree.get("FONT_COMMON_BOLD"); + std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommonBold"); return path; } catch (std::exception & e) { GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); - SetCommonBoldFont("dvu_sans_bold.ttf"); return "/fonts/dvu_sans_bold.ttf"; } return ""; } -bool CFontConfigFile::SetCommonBoldFont(std::string filename) -{ - try - { - m_propertyTree.put("FONT_COMMON_BOLD", filename); - m_needsSave = true; - } - catch (std::exception & e) - { - GetLogger()->Error("Error on editing config file: %s\n", e.what()); - return false; - } - return true; -} - std::string CFontConfigFile::GetCommonItalicFont() { try { - std::string path = std::string("/fonts/") + m_propertyTree.get("FONT_COMMON_ITALIC"); + std::string path = std::string("/fonts/") + m_propertyTree.get("FontCommonItalic"); return path; } catch (std::exception & e) { GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); - SetCommonItalicFont("dvu_sans_italic.ttf"); return "/fonts/dvu_sans_italic.ttf"; } return ""; } -bool CFontConfigFile::SetCommonItalicFont(std::string filename) -{ - try - { - m_propertyTree.put("FONT_COMMON_ITALIC", filename); - m_needsSave = true; - } - catch (std::exception & e) - { - GetLogger()->Error("Error on editing config file: %s\n", e.what()); - return false; - } - return true; -} - std::string CFontConfigFile::GetStudioFont() { try { - std::string path = std::string("/fonts/") + m_propertyTree.get("FONT_STUDIO"); + std::string path = std::string("/fonts/") + m_propertyTree.get("FontStudio"); return path; } catch (std::exception & e) { GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); - SetStudioFont("dvu_sans_mono.ttf"); return "/fonts/dvu_sans_mono.ttf"; } return ""; } -bool CFontConfigFile::SetStudioFont(std::string filename) -{ - try - { - m_propertyTree.put("FONT_STUDIO", filename); - m_needsSave = true; - } - catch (std::exception & e) - { - GetLogger()->Error("Error on editing config file: %s\n", e.what()); - return false; - } - return true; -} - std::string CFontConfigFile::GetStudioBoldFont() { try { - std::string path = std::string("/fonts/") + m_propertyTree.get("FONT_STUDIO_BOLD"); + std::string path = std::string("/fonts/") + m_propertyTree.get("FontStudioBold"); return path; } catch (std::exception & e) { GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); - SetStudioBoldFont("dvu_sans_mono_bold.ttf"); return "/fonts/dvu_sans_mono_bold.ttf"; } return ""; } -bool CFontConfigFile::SetStudioBoldFont(std::string filename) +std::string CFontConfigFile::GetSatComFont() { try { - m_propertyTree.put("FONT_STUDIO_BOLD", filename); - m_needsSave = true; + std::string path = std::string("/fonts/") + m_propertyTree.get("FontSatCom"); + return path; } catch (std::exception & e) { - GetLogger()->Error("Error on editing config file: %s\n", e.what()); - return false; + GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %s. Default font will be used instead.\n", e.what()); + return "/fonts/dvu_sans.ttf"; } - return true; + return ""; } diff --git a/src/common/font_file.h b/src/common/font_file.h index c5d2869d..d6a320a3 100644 --- a/src/common/font_file.h +++ b/src/common/font_file.h @@ -47,99 +47,44 @@ public: * \return return true on success */ bool Init(); - - /** Saves fonts.ini - * \return return true on success - */ - bool Save(); - + /** Reads common font from file * \return return path to font file */ - std::string GetCommonFont(); - - /** Writes common font to file - * \return return true on success - */ - - bool SetCommonFont(std::string filename); - + /** Reads common bold font from file * \return return path to font file */ - std::string GetCommonBoldFont(); - - /** Writes common bold font to file - * \return return true on success - */ - - bool SetCommonBoldFont(std::string filename); - + /** Reads common italic font from file * \return return path to font file */ - std::string GetCommonItalicFont(); - - /** Writes common italic font to file - * \return return true on success - */ - - bool SetCommonItalicFont(std::string filename); - + /** Reads studio font from file * \return return path to font file */ - std::string GetStudioFont(); - /** Writes studio font to file - * \return return true on success - */ - - bool SetStudioFont(std::string filename); - /** Reads studio bold font from file * \return returns path to font file */ - std::string GetStudioBoldFont(); - /** Writes studio bold font to file - * \return return true on success + /** Reads satcom font from file + * \return returns path to font file */ - - bool SetStudioBoldFont(std::string filename); + std::string GetSatComFont(); private: boost::property_tree::ptree m_propertyTree; bool m_needsSave; bool m_useCurrentDirectory; bool m_loaded; - - /*std::string m_colobotFont; - std::string m_colobotFontb; - std::string m_colobotFonti; - - std::string m_courierFont; - std::string m_courierFontb;*/ }; -/** - * \enum Fonts - * \brief enum of types of fonts used in game - *//* -enum Fonts -{ - FONT_COLOBOT = 0, - FONT_COLOBOT_BOLD = 1, - FONT_COLOBOT_ITALIC = 2, - FONT_COURIER = 3, - FONT_COURIER_BOLD = 4 -};*/ - //! Global function to get config file instance inline CFontConfigFile & GetFontConfigFile() { diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index aa7008d1..6443a6f1 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -131,6 +131,8 @@ bool CText::Create() m_fonts[FONT_COLOBOT] = MakeUnique(GetFontConfigFile().GetCommonFont()); m_fonts[FONT_COLOBOT_BOLD] = MakeUnique(GetFontConfigFile().GetCommonBoldFont()); m_fonts[FONT_COLOBOT_ITALIC] = MakeUnique(GetFontConfigFile().GetCommonItalicFont()); + + m_fonts[FONT_SATCOM] = MakeUnique(GetFontConfigFile().GetSatComFont()); m_fonts[FONT_COURIER] = MakeUnique(GetFontConfigFile().GetStudioFont()); m_fonts[FONT_COURIER_BOLD] = MakeUnique(GetFontConfigFile().GetStudioBoldFont()); diff --git a/src/graphics/engine/text.h b/src/graphics/engine/text.h index f6414c00..275885e9 100644 --- a/src/graphics/engine/text.h +++ b/src/graphics/engine/text.h @@ -88,7 +88,9 @@ enum FontType //! Alias for bold courier font FONT_COURIER_BOLD = FONT_COURIER | FONT_BOLD, - // 0x02 left for possible another font + //! SatCom font used for interface + + FONT_SATCOM = 0x02, //! Pseudo-font loaded from textures for buttons, icons, etc. FONT_BUTTON = 0x03, diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp index 76aee701..8ae66ad5 100644 --- a/src/ui/displayinfo.cpp +++ b/src/ui/displayinfo.cpp @@ -383,7 +383,7 @@ void CDisplayInfo::StartDisplayInfo(std::string filename, int index, bool bSoluc edit->SetState(STATE_SHADOW); edit->SetMultiFont(true); edit->SetMaxChar(10000); - edit->SetFontType(Gfx::FONT_COLOBOT); + edit->SetFontType(Gfx::FONT_SATCOM); edit->SetSoluceMode(bSoluce); edit->ReadText(filename.c_str()); edit->HyperHome(filename.c_str());