Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pack devs to specify font and font size for messages #379

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class HexagonGame
std::optional<SwapParticleSpawnInfo> swapParticlesSpawnInfo;
float nextPBParticleSpawn{0.f};
float pbTextGrowth{0.f};
float messageTextCharacterSize{32.f};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely needs to be reset between levels or even between resets of the same level. Maybe make it part of HGStatus? That should get reset automatically.


sf::Sprite keyIconLeft;
sf::Sprite keyIconRight;
Expand Down
2 changes: 2 additions & 0 deletions include/SSVOpenHexagon/Global/Assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class HGAssets
const std::string& mPackId, const ssvufs::Path& mPath);
void loadPackAssets_loadCustomSounds(
const std::string& mPackId, const ssvufs::Path& mPath);
void loadPackAssets_loadCustomFonts(
const std::string& mPackId, const ssvufs::Path& mPath);

[[nodiscard]] std::string getCurrentLocalProfileFilePath();

Expand Down
2 changes: 1 addition & 1 deletion src/SSVOpenHexagon/Core/HGGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void HexagonGame::updateText(ssvu::FT mFT)
fpsText.setCharacterSize(getScaledCharacterSize(20.f));
}

messageText.setCharacterSize(getScaledCharacterSize(32.f));
messageText.setCharacterSize(getScaledCharacterSize(messageTextCharacterSize));
messageText.setOrigin({ssvs::getGlobalWidth(messageText) / 2.f, 0.f});

const float growth = std::sin(pbTextGrowth);
Expand Down
15 changes: 15 additions & 0 deletions src/SSVOpenHexagon/Core/HGScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ void HexagonGame::initLua_Utils()
.doc(
"Force-swaps (180 degrees) the player when invoked. If `$0` is "
"`true`, the swap sound will be played.");

addLuaFn(lua, "u_setMessageFont", //
[this](std::string mFontId) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[this](std::string mFontId) {
[this](const std::string& mFontId) {

messageText.setFont(
assets.getFontOrNullFont(getPackId() + "_" + mFontId));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can use the concat utility here to create the final string.

})
.arg("fontId")
.doc(
"Sets the font messages will use to `$0` which is the filename of "
"a file inside the `Fonts` folder in your pack.");

addLuaFn(lua, "u_setMessageFontSize", //
[this](float mSize) { messageTextCharacterSize = mSize; })
.arg("size")
.doc("Sets the font size messages will use to `$0`.");
}

void HexagonGame::initLua_AudioControl()
Expand Down
3 changes: 3 additions & 0 deletions src/SSVOpenHexagon/Core/HexagonGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,9 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId,

debugPause = false;

// Font cleanup
messageText.setFont(font);

// Events cleanup
messageText.setString("");
pbText.setString("");
Expand Down
42 changes: 42 additions & 0 deletions src/SSVOpenHexagon/Global/Assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ HGAssets::~HGAssets()
{
loadPackAssets_loadCustomSounds(packId, packPath);
}

if(!levelsOnly && ssvufs::Path{packPath + "Fonts/"}.isFolder())
{
loadPackAssets_loadCustomFonts(packId, packPath);
}
}

if(ssvufs::Path{packPath + "Music/"}.isFolder() && !levelsOnly)
Expand Down Expand Up @@ -734,6 +739,22 @@ void HGAssets::loadPackAssets_loadCustomSounds(
}
}

void HGAssets::loadPackAssets_loadCustomFonts(
const std::string& mPackId, const ssvufs::Path& mPath)
{
for(const auto& p : scanSingleByExt(mPath + "Fonts/", ".ttf"))
{
if(!assetStorage->loadFont(
concatIntoBuf(mPackId, '_', p.getFileName()), p))
{
ssvu::lo("hg::loadPackAssets_loadCustomFonts")
<< "Failed to load font '" << p << "'\n";
}

++loadInfo.assets;
}
}

void HGAssets::loadPackAssets_loadMusic(
const std::string& mPackId, const ssvufs::Path& mPath)
{
Expand Down Expand Up @@ -1074,6 +1095,27 @@ void HGAssets::reloadAllShaders()
output += "Custom sound files successfully reloaded\n";
}

// Custom fonts
temp = mPath + "Fonts/";
if(!ssvufs::Path{temp}.isFolder())
{
output += "invalid custom font path\n";
}
else
{
for(const auto& p : scanSingleByExt(mPath + "Fonts/", ".ttf"))
{
temp = mPackId + "_" + p.getFileName();
if(!assetStorage->loadFont(temp, p))
{
output += "Failed to load font '";
output += p;
output += "'\n";
}
}
output += "Custom font files successfully reloaded\n";
}

return output;
}

Expand Down