Skip to content

Commit

Permalink
Improved console
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 12, 2024
1 parent 5ea51a0 commit f5d8824
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 77 deletions.
6 changes: 6 additions & 0 deletions Sources/Jazz2.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,9 @@
<ClInclude Include="$(ExtensionLibraryPath)\IO\Compression\Lz4Stream.h">
<Filter>Header Files\Shared\IO\Compression</Filter>
</ClInclude>
<ClInclude Include="Jazz2\UI\InGameConsole.h">
<Filter>Header Files\Jazz2\UI</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
Expand Down Expand Up @@ -2537,6 +2540,9 @@
<ClCompile Include="$(ExtensionLibraryPath)\IO\Compression\Lz4Stream.cpp">
<Filter>Source Files\Shared\IO\Compression</Filter>
</ClCompile>
<ClCompile Include="Jazz2\UI\InGameConsole.cpp">
<Filter>Source Files\Jazz2\UI</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resources.rc">
Expand Down
39 changes: 25 additions & 14 deletions Sources/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ namespace Jazz2
_rootNode = std::make_unique<SceneNode>();
_rootNode->setVisitOrderState(SceneNode::VisitOrderState::Disabled);

_console = std::make_unique<UI::InGameConsole>(this);

LevelDescriptor descriptor;
if (!resolver.TryLoadLevel("/"_s.joinWithoutEmptyParts({ _episodeName, _levelFileName }), _difficulty, descriptor)) {
LOGE("Cannot load level \"%s/%s\"", _episodeName.data(), _levelFileName.data());
return false;
}

_console->WriteLine(UI::MessageLevel::Debug, _f("Level \"%s\" initialized", descriptor.DisplayName.data()));

AttachComponents(std::move(descriptor));
SpawnPlayers(levelInit);

Expand Down Expand Up @@ -195,12 +199,16 @@ namespace Jazz2
_rootNode = std::make_unique<SceneNode>();
_rootNode->setVisitOrderState(SceneNode::VisitOrderState::Disabled);

_console = std::make_unique<UI::InGameConsole>(this);

LevelDescriptor descriptor;
if (!resolver.TryLoadLevel("/"_s.joinWithoutEmptyParts({ _episodeName, _levelFileName }), _difficulty, descriptor)) {
LOGE("Cannot load level \"%s/%s\"", _episodeName.data(), _levelFileName.data());
return false;
}

_console->WriteLine(UI::MessageLevel::Debug, _f("Level \"%s\" initialized", descriptor.DisplayName.data()));

AttachComponents(std::move(descriptor));

// All components are ready, deserialize the rest of state
Expand Down Expand Up @@ -242,13 +250,14 @@ namespace Jazz2
resolver.PreloadMetadataAsync("Common/Explosions"_s);

_hud = std::make_unique<UI::HUD>(this);
_console = std::make_unique<UI::InGameConsole>(this);

_eventMap->PreloadEventsAsync();

InitializeRumbleEffects();
UpdateRichPresence();

_console->OnInitialized();

#if defined(WITH_ANGELSCRIPT)
if (_scripts != nullptr) {
_scripts->OnLevelLoad();
Expand Down Expand Up @@ -467,15 +476,14 @@ namespace Jazz2
UpdatePressedActions();

if (PlayerActionHit(0, PlayerActions::Menu)) {
if (!_console->parent() && _nextLevelType == ExitType::None) {
if (!_console->IsVisible() && _nextLevelType == ExitType::None) {
PauseGame();
}
} else if (PlayerActionHit(0, PlayerActions::Console)) {
if (_console->parent()) {
_console->setParent(nullptr);
if (_console->IsVisible()) {
_console->Hide();
} else {
_console->setParent(_upscalePass.GetNode());
_console->OnAttached();
_console->Show();
}
}
#if defined(DEATH_DEBUG)
Expand Down Expand Up @@ -639,6 +647,9 @@ namespace Jazz2
if (_hud != nullptr) {
_hud->setParent(_upscalePass.GetNode());
}
if (_console != nullptr) {
_console->setParent(_upscalePass.GetNode());
}
}

_combineWithWaterShader = resolver.GetShader(PreferencesCache::LowWaterQuality
Expand Down Expand Up @@ -689,7 +700,7 @@ namespace Jazz2

if (_pauseMenu != nullptr) {
_pauseMenu->OnKeyReleased(event);
} else if (_console->parent()) {
} else if (_console->IsVisible()) {
_console->OnKeyPressed(event);
}
}
Expand All @@ -705,7 +716,7 @@ namespace Jazz2

void LevelHandler::OnTextInput(const TextInputEvent& event)
{
if (_console->parent()) {
if (_console->IsVisible()) {
_console->OnTextInput(event);
}
}
Expand Down Expand Up @@ -1240,7 +1251,7 @@ namespace Jazz2

bool LevelHandler::PlayerActionPressed(std::int32_t index, PlayerActions action, bool includeGamepads)
{
if (_console->parent() && action != PlayerActions::Menu && action != PlayerActions::Console) {
if (_console->IsVisible() && action != PlayerActions::Menu && action != PlayerActions::Console) {
return false;
}

Expand All @@ -1250,7 +1261,7 @@ namespace Jazz2

bool LevelHandler::PlayerActionPressed(std::int32_t index, PlayerActions action, bool includeGamepads, bool& isGamepad)
{
if (_console->parent() && action != PlayerActions::Menu && action != PlayerActions::Console) {
if (_console->IsVisible() && action != PlayerActions::Menu && action != PlayerActions::Console) {
return false;
}

Expand All @@ -1266,7 +1277,7 @@ namespace Jazz2

bool LevelHandler::PlayerActionHit(std::int32_t index, PlayerActions action, bool includeGamepads)
{
if (_console->parent() && action != PlayerActions::Menu && action != PlayerActions::Console) {
if (_console->IsVisible() && action != PlayerActions::Menu && action != PlayerActions::Console) {
return false;
}

Expand All @@ -1276,7 +1287,7 @@ namespace Jazz2

bool LevelHandler::PlayerActionHit(std::int32_t index, PlayerActions action, bool includeGamepads, bool& isGamepad)
{
if (_console->parent() && action != PlayerActions::Menu && action != PlayerActions::Console) {
if (_console->IsVisible() && action != PlayerActions::Menu && action != PlayerActions::Console) {
return false;
}

Expand All @@ -1292,7 +1303,7 @@ namespace Jazz2

float LevelHandler::PlayerHorizontalMovement(std::int32_t index)
{
if (_console->parent()) {
if (_console->IsVisible()) {
return 0.0f;
}

Expand All @@ -1302,7 +1313,7 @@ namespace Jazz2

float LevelHandler::PlayerVerticalMovement(std::int32_t index)
{
if (_console->parent()) {
if (_console->IsVisible()) {
return 0.0f;
}

Expand Down
Loading

0 comments on commit f5d8824

Please sign in to comment.