Skip to content

Commit

Permalink
Fixed shooting to walls, reworked About section, updated Font, change…
Browse files Browse the repository at this point in the history
…d formatting tags, ImGui log, updated translations
  • Loading branch information
deathkiller committed Jun 26, 2024
1 parent dd3383c commit 07326bf
Show file tree
Hide file tree
Showing 52 changed files with 2,951 additions and 1,309 deletions.
Binary file modified Content/Animations/UI/font_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Content/Animations/UI/font_small.png.font
Binary file not shown.
Binary file modified Content/Translations/cs.mo
Binary file not shown.
244 changes: 122 additions & 122 deletions Content/Translations/cs.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/fr.mo
Binary file not shown.
230 changes: 115 additions & 115 deletions Content/Translations/fr.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/it.mo
Binary file not shown.
264 changes: 132 additions & 132 deletions Content/Translations/it.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/pl.mo
Binary file not shown.
259 changes: 130 additions & 129 deletions Content/Translations/pl.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/pt.mo
Binary file not shown.
201 changes: 102 additions & 99 deletions Content/Translations/pt.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/pt_BR.mo
Binary file not shown.
234 changes: 117 additions & 117 deletions Content/Translations/pt_BR.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/ro.mo
Binary file not shown.
263 changes: 131 additions & 132 deletions Content/Translations/ro.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/ru.mo
Binary file not shown.
229 changes: 115 additions & 114 deletions Content/Translations/ru.po

Large diffs are not rendered by default.

Binary file modified Content/Translations/tr.mo
Binary file not shown.
260 changes: 129 additions & 131 deletions Content/Translations/tr.po

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Sources/Jazz2.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@
<ClInclude Include="Jazz2\UI\ControlScheme.h" />
<ClInclude Include="Jazz2\UI\DiscordRpcClient.h" />
<ClInclude Include="Jazz2\UI\Font.h" />
<ClInclude Include="Jazz2\UI\FormattedTextBlock.h" />
<ClInclude Include="Jazz2\UI\HUD.h" />
<ClInclude Include="Jazz2\UI\LoadingHandler.h" />
<ClInclude Include="Jazz2\UI\Menu\AboutSection.h" />
Expand Down Expand Up @@ -696,6 +697,7 @@
<ClInclude Include="$(ExtensionLibraryPath)\Containers\StringStl.h" />
<ClInclude Include="$(ExtensionLibraryPath)\IO\FileAccess.h" />
<ClInclude Include="$(ExtensionLibraryPath)\Base\IDisposable.h" />
<ClInclude Include="$(ExtensionLibraryPath)\Base\StackAlloc.h" />
<ClInclude Include="simdjson\simdjson.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -841,6 +843,7 @@
<ClCompile Include="Jazz2\UI\ControlScheme.cpp" />
<ClCompile Include="Jazz2\UI\DiscordRpcClient.cpp" />
<ClCompile Include="Jazz2\UI\Font.cpp" />
<ClCompile Include="Jazz2\UI\FormattedTextBlock.cpp" />
<ClCompile Include="Jazz2\UI\HUD.cpp" />
<ClCompile Include="Jazz2\UI\LoadingHandler.cpp" />
<ClCompile Include="Jazz2\UI\Menu\AboutSection.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions Sources/Jazz2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,12 @@
<ClInclude Include="$(ExtensionLibraryPath)\Base\IDisposable.h">
<Filter>Header Files\Shared\Base</Filter>
</ClInclude>
<ClInclude Include="Jazz2\UI\FormattedTextBlock.h">
<Filter>Header Files\Jazz2\UI</Filter>
</ClInclude>
<ClInclude Include="$(ExtensionLibraryPath)\Base\StackAlloc.h">
<Filter>Header Files\Shared\Base</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down Expand Up @@ -2453,6 +2459,9 @@
<ClCompile Include="$(ExtensionLibraryPath)\IO\PakFile.cpp">
<Filter>Source Files\Shared\IO</Filter>
</ClCompile>
<ClCompile Include="Jazz2\UI\FormattedTextBlock.cpp">
<Filter>Source Files\Jazz2\UI</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources.rc">
Expand Down
7 changes: 5 additions & 2 deletions Sources/Jazz2/Actors/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ namespace Jazz2::Actors
// Fire
bool weaponInUse = false;
if (_weaponAllowed && areaWeaponAllowed && _levelHandler->PlayerActionPressed(_playerIndex, PlayerActions::Fire)) {
if (!_isLifting && _suspendType != SuspendType::SwingingVine && (_currentAnimation->State & AnimState::Push) != AnimState::Push && _pushFramesLeft <= 0.0f) {
if (!_isLifting && _suspendType != SuspendType::SwingingVine) {
if (_playerType == PlayerType::Frog) {
if (_currentTransition == nullptr && std::abs(_speed.X) < 0.1f && std::abs(_speed.Y) < 0.1f && std::abs(_externalForce.X) < 0.1f && std::abs(_externalForce.Y) < 0.1f) {
PlayPlayerSfx("Tongue"_s, 0.8f);
Expand All @@ -985,6 +985,9 @@ namespace Jazz2::Actors
} else if (_weaponAmmo[(int)_currentWeapon] != 0) {
_wasFirePressed = true;

// Shooting has higher priority than pushing
_pushFramesLeft = 0.0f;

bool weaponCooledDown = (_weaponCooldown <= 0.0f);
weaponInUse = FireCurrentWeapon(_currentWeapon);
if (weaponInUse) {
Expand Down Expand Up @@ -1727,7 +1730,7 @@ namespace Jazz2::Actors
newState = AnimState::Swing;
} else if (_isLifting) {
newState = AnimState::Lift;
} else if (GetState(ActorState::CanJump) && _isActivelyPushing && _pushFramesLeft > 0.0f && _keepRunningTime <= 0.0f) {
} else if (GetState(ActorState::CanJump) && _isActivelyPushing && _pushFramesLeft > 0.0f && _keepRunningTime <= 0.0f && _fireFramesLeft <= 0.0f) {
newState = AnimState::Push;

if (_inIdleTransition) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Weapons/BouncerShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Jazz2::Actors::Weapons

_fired++;
if (_fired == 2) {
MoveInstantly(_gunspotPos, MoveType::Absolute | MoveType::Force);
MoveInstantly(_gunspotPos, MoveType::Absolute);
_renderer.setDrawEnabled(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Jazz2/Actors/Weapons/ToasterShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Jazz2::Actors::Weapons

_fired++;
if (_fired == 2) {
MoveInstantly(_gunspotPos, MoveType::Absolute | MoveType::Force);
MoveInstantly(_gunspotPos, (_upgrades & 0x1) != 0 ? MoveType::Absolute : (MoveType::Absolute | MoveType::Force));
_renderer.setDrawEnabled(true);
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Jazz2/Compatibility/JJ2Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ namespace Jazz2::Compatibility

if (text[i] == '/') {
buffer[j++] = '[';
buffer[j++] = '/';
buffer[j++] = 'w';
buffer[j++] = ']';
} else {
Expand Down Expand Up @@ -259,10 +260,11 @@ namespace Jazz2::Compatibility
int colorIndex2 = colorIndex % (arraySize<int>(DefaultFontColors) + 1);
if (colorIndex2 == 0) {
buffer[j++] = '[';
buffer[j++] = '/';
buffer[j++] = 'c';
buffer[j++] = ']';
} else {
j += formatString(&buffer[j], 16, "[c:0x%08x]", DefaultFontColors[colorIndex2 - 1]);
j += formatString(&buffer[j], 16, "[c:#%08x]", DefaultFontColors[colorIndex2 - 1]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Jazz2/UI/Alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace Jazz2::UI
{
enum class Alignment {
enum class Alignment
{
Center = 0x00,

Left = 0x01,
Expand Down
165 changes: 115 additions & 50 deletions Sources/Jazz2/UI/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Jazz2::UI

int32_t unicodeCharCount = asciiCount + s->ReadValue<int32_t>();
for (; i < unicodeCharCount; i++) {
char c[4] = { };
char c[4] {};
s->Read(c, 1);

int32_t remainingBytes =
Expand Down Expand Up @@ -107,7 +107,35 @@ namespace Jazz2::UI
}
}

Vector2f Font::MeasureString(const StringView text, float scale, float charSpacing, float lineSpacing)
std::int32_t Font::GetSizeInPixels() const
{
// TODO
return _charSize.Y;
}

std::int32_t Font::GetAscentInPixels() const
{
// TODO
return (_charSize.Y * 4 / 5);
}

Vector2f Font::MeasureChar(char32_t c) const
{
Rectf uvRect;
if (c < 128) {
uvRect = _asciiChars[c];
} else {
auto it = _unicodeChars.find(c);
if (it != _unicodeChars.end()) {
uvRect = it->second;
} else {
uvRect = _asciiChars[0];
}
}
return Vector2f(uvRect.W, uvRect.H);
}

Vector2f Font::MeasureString(StringView text, float scale, float charSpacing, float lineSpacing)
{
size_t textLength = text.size();
if (textLength == 0 || _charSize.Y <= 0) {
Expand Down Expand Up @@ -143,20 +171,9 @@ namespace Jazz2::UI
} while (idx < textLength);
}
} else {
Rectf uvRect;
if (cursor.first < 128) {
uvRect = _asciiChars[cursor.first];
} else {
auto it = _unicodeChars.find(cursor.first);
if (it != _unicodeChars.end()) {
uvRect = it->second;
} else {
uvRect = _asciiChars[0];
}
}

if (uvRect.W > 0 && uvRect.H > 0) {
lastWidth += (uvRect.W + _baseSpacing) * charSpacingPre * scalePre;
Vector2f charSize = MeasureChar(cursor.first);
if (charSize.X > 0 && charSize.Y > 0) {
lastWidth += (charSize.X + _baseSpacing) * charSpacingPre * scalePre;
}
}

Expand All @@ -171,7 +188,51 @@ namespace Jazz2::UI
return Vector2f(ceilf(totalWidth), ceilf(totalHeight));
}

void Font::DrawString(Canvas* canvas, const StringView text, int32_t& charOffset, float x, float y, uint16_t z, Alignment align, Colorf color, float scale, float angleOffset, float varianceX, float varianceY, float speed, float charSpacing, float lineSpacing)
Vector2f Font::MeasureStringEx(StringView text, float scale, float charSpacing, float maxWidth, std::int32_t* charFit, float* charFitWidths)
{
if (charFit != nullptr) {
*charFit = 0;
}

std::size_t textLength = text.size();
if (textLength == 0 || _charSize.Y <= 0) {
return Vector2f::Zero;
}

float totalWidth = 0.0f, totalHeight = 0.0f;
std::size_t idx = 0;;
std::size_t lastCharFit = 0;

do {
auto [c, next] = Utf8::NextChar(text, idx);

Vector2f charSize = MeasureChar(c);
if (charSize.X > 0 && charSize.Y > 0) {
float totalWidthNew = totalWidth + (charSize.X + _baseSpacing) * charSpacing * scale;
if (charFitWidths != nullptr) {
do {
charFitWidths[lastCharFit++] = totalWidthNew;
} while (lastCharFit < next);
}
if (totalWidthNew > maxWidth) {
break;
}
totalWidth = totalWidthNew;
}

idx = next;
} while (idx < textLength);

if (charFit != nullptr) {
*charFit = static_cast<std::int32_t>(idx);
}

totalHeight += (_charSize.Y * scale);

return Vector2f(ceilf(totalWidth), ceilf(totalHeight));
}

void Font::DrawString(Canvas* canvas, StringView text, int32_t& charOffset, float x, float y, uint16_t z, Alignment align, Colorf color, float scale, float angleOffset, float varianceX, float varianceY, float speed, float charSpacing, float lineSpacing)
{
size_t textLength = text.size();
if (textLength == 0 || _charSize.Y <= 0) {
Expand Down Expand Up @@ -342,44 +403,34 @@ namespace Jazz2::UI
// Set custom color
idx = cursor.second;
cursor = Utf8::NextChar(text, idx);
if (cursor.first == '0') {
if (cursor.first == '#') {
idx = cursor.second;
cursor = Utf8::NextChar(text, idx);
if (cursor.first == 'x') {
int32_t paramLength = 0;
char param[9];
do {
cursor = Utf8::NextChar(text, idx);
if (cursor.first == ']') {
break;
}
if (paramLength < arraySize<std::int32_t>(param) - 1) {
param[paramLength++] = (char)cursor.first;
}
idx = cursor.second;
int32_t paramLength = 0;
char param[9];
do {
cursor = Utf8::NextChar(text, idx);
if (cursor.first == ']') {
break;
}
if (paramLength < arraySize<std::int32_t>(param) - 1) {
param[paramLength++] = (char)cursor.first;
}
idx = cursor.second;
} while (idx < textLength);

if (paramLength > 0 && !useRandomColor && !isShadow) {
param[paramLength] = '\0';
char* end = &param[paramLength];
unsigned long paramValue = strtoul(param, &end, 16);
if (param != end) {
color = Color(paramValue);
color.SetAlpha(0.5f * alpha);
if (colorizeShader == nullptr) {
colorizeShader = ContentResolver::Get().GetShader(PrecompiledShader::Colorized);
}
} while (idx < textLength);

if (paramLength > 0 && !useRandomColor && !isShadow) {
param[paramLength] = '\0';
char* end = &param[paramLength];
unsigned long paramValue = strtoul(param, &end, 16);
if (param != end) {
color = Color(paramValue);
color.SetAlpha(0.5f * alpha);
if (colorizeShader == nullptr) {
colorizeShader = ContentResolver::Get().GetShader(PrecompiledShader::Colorized);
}
}
}
}
} else if (cursor.first == ']') {
// Reset color
if (!useRandomColor && !isShadow) {
color = Colorf(1.0f, 1.0f, 1.0f, alpha);
colorizeShader = nullptr;
}
}
} else if (cursor.first == 'w') {
idx = cursor.second;
Expand Down Expand Up @@ -407,12 +458,26 @@ namespace Jazz2::UI
charSpacing = paramValue * 0.01f;
}
}
} else if (cursor.first == ']') {
}
} else if (cursor.first == '/') {
idx = cursor.second;
cursor = Utf8::NextChar(text, idx);
if (cursor.first == 'c') {
// Reset color
if (!useRandomColor && !isShadow) {
color = Colorf(1.0f, 1.0f, 1.0f, alpha);
colorizeShader = nullptr;
}
} else if (cursor.first == 'w') {
// Reset char spacing
charSpacing = charSpacingPre;
}
}
}

while (cursor.first != ']') {
cursor = Utf8::NextChar(text, cursor.second);
}
} else {
Rectf uvRect;
if (cursor.first < 128) {
Expand Down
10 changes: 7 additions & 3 deletions Sources/Jazz2/UI/Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ namespace Jazz2::UI

Font(const StringView path, const uint32_t* palette);

Vector2f MeasureString(const StringView text, float scale = 1.0f, float charSpacing = 1.0f, float lineSpacing = 1.0f);
void DrawString(Canvas* canvas, const StringView text, int32_t& charOffset, float x, float y, uint16_t z, Alignment align, Colorf color, float scale = 1.0f, float angleOffset = 0.0f, float varianceX = 4.0f, float varianceY = 4.0f, float speed = 0.4f, float charSpacing = 1.0f, float lineSpacing = 1.0f);
std::int32_t GetSizeInPixels() const;
std::int32_t GetAscentInPixels() const;
Vector2f MeasureChar(char32_t c) const;
Vector2f MeasureString(StringView text, float scale = 1.0f, float charSpacing = 1.0f, float lineSpacing = 1.0f);
Vector2f MeasureStringEx(StringView text, float scale, float charSpacing, float maxWidth, std::int32_t* charFit, float* charFitWidths);
void DrawString(Canvas* canvas, StringView text, int32_t& charOffset, float x, float y, uint16_t z, Alignment align, Colorf color, float scale = 1.0f, float angleOffset = 0.0f, float varianceX = 4.0f, float varianceY = 4.0f, float speed = 0.4f, float charSpacing = 1.0f, float lineSpacing = 1.0f);

private:
static constexpr Colorf RandomColors[] = {
Expand All @@ -38,7 +42,7 @@ namespace Jazz2::UI
Rectf _asciiChars[128];
HashMap<uint32_t, Rectf> _unicodeChars;
Vector2i _charSize;
int32_t _baseSpacing;
std::int32_t _baseSpacing;
std::unique_ptr<Texture> _texture;
};
}
Loading

0 comments on commit 07326bf

Please sign in to comment.