Skip to content

Commit

Permalink
Rework UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Deewarz committed Mar 15, 2024
1 parent d875deb commit b17295c
Show file tree
Hide file tree
Showing 36 changed files with 966 additions and 958 deletions.
17 changes: 9 additions & 8 deletions code/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ set(MAFIAMP_CLIENT_FILES
src/core/luavm.cpp
src/core/application.cpp
src/core/dev_features.cpp
src/core/ui/audio_debug.cpp
src/core/ui/console.cpp
src/core/ui/ui_base.cpp
src/core/ui/chat.cpp
src/core/ui/camera_studio.cpp
src/core/ui/entity_browser.cpp
src/core/ui/network_stats.cpp
src/core/ui/player_debug.cpp
src/core/ui/vehicle_debug.cpp
src/core/ui/console.cpp
src/core/ui/devs/camera_studio.cpp
src/core/ui/devs/debug_audio.cpp
src/core/ui/devs/debug_player.cpp
src/core/ui/devs/debug_vehicle.cpp
src/core/ui/devs/debug_world.cpp
src/core/ui/devs/entity_browser.cpp
src/core/ui/devs/network_stats.cpp
src/core/ui/web/manager.cpp
src/core/ui/web/clipboard.cpp
src/core/ui/web/sdk.cpp
src/core/ui/web/view.cpp
src/core/ui/world_debug.cpp
src/core/states/initialize.cpp
src/core/states/main_menu.cpp
src/core/states/session_connected.cpp
Expand Down
72 changes: 49 additions & 23 deletions code/client/src/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ namespace MafiaMP::Core {

_commandProcessor = std::make_shared<Framework::Utils::CommandProcessor>();
_input = std::make_shared<MafiaMP::Game::GameInput>();
_console = std::make_shared<UI::MafiaConsole>(_commandProcessor, _input);
_console = std::make_shared<UI::Console>(_commandProcessor);
_chat = std::make_shared<UI::Chat>();
_webManager = std::make_shared<UI::Web::Manager>();
_webManager = std::make_shared<UI::Web::Manager>();

if (_webManager) {
if (!_webManager->Init()) {
Expand Down Expand Up @@ -142,28 +142,41 @@ namespace MafiaMP::Core {
discordApi->SetPresence("Freeroam", "Screwing around", discord::ActivityType::Playing);
}

#if 1
// Console UI
Core::gApplication->GetImGUI()->PushWidget([&]() {
using namespace Framework::External::ImGUI::Widgets;
const auto networkClient = Core::gApplication->GetNetworkingEngine()->GetNetworkClient();
const auto connState = networkClient->GetConnectionState();
const auto ping = networkClient->GetPing();

_console->Update();
_devFeatures.Update();

if (_input->IsKeyPressed(FW_KEY_F8)) {
_console->Toggle();
}
});

const char *connStateNames[] = {"Connecting", "Online", "Offline"};
#ifdef FW_DEBUG
Core::gApplication->GetImGUI()->PushWidget([&]() {
_devFeatures.Update();

using namespace Framework::External::ImGUI::Widgets; // For DrawCornerText() and Corner enum

// Bypass locked controls
if (AreControlsLocked()) {
DrawCornerText(CORNER_RIGHT_TOP, fmt::format("Press APPS to {} controls locked", AreControlsLockedBypassed() ? "RESTORE" : "BYPASS"));

if (_input->IsKeyPressed(FW_KEY_APPS)) {
ToggleLockControlsBypass();
}
}

// versioning
DrawCornerText(CORNER_RIGHT_BOTTOM, "Mafia: Multiplayer");
DrawCornerText(CORNER_RIGHT_BOTTOM, fmt::format("Framework version: {} ({})", Framework::Utils::Version::rel, Framework::Utils::Version::git));
DrawCornerText(CORNER_RIGHT_BOTTOM, fmt::format("MafiaMP version: {} ({})", MafiaMP::Version::rel, MafiaMP::Version::git));

// connection details
const auto networkClient = Core::gApplication->GetNetworkingEngine()->GetNetworkClient();
const auto connState = networkClient->GetConnectionState();
const auto ping = networkClient->GetPing();
const char *connStateNames[] = {"Connecting", "Online", "Offline"};

DrawCornerText(CORNER_LEFT_BOTTOM, fmt::format("Connection: {}", connStateNames[connState]));
DrawCornerText(CORNER_LEFT_BOTTOM, fmt::format("Ping: {}", ping));
});
Expand Down Expand Up @@ -265,28 +278,41 @@ namespace MafiaMP::Core {
ImGui::GetStyle().WindowTitleAlign = {0.5f, 0.5f};
}

void Application::ProcessLockControls(bool lock) {
Game::Helpers::Controls::Lock(lock);

GetImGUI()->SetProcessEventEnabled(lock);
GetImGUI()->ShowCursor(lock);
}

void Application::LockControls(bool lock) {
if (lock) {
_controlsLocked++;
if (_lockControlsCounter == 0) {
ProcessLockControls(true);
}

_lockControlsCounter++;
}
else {
_controlsLocked = std::max(--_controlsLocked, 0);
}
_lockControlsCounter = std::max(--_lockControlsCounter, 0);

if (_controlsLocked) {
// Lock game controls
Game::Helpers::Controls::Lock(true);
if (_lockControlsCounter == 0) {
ProcessLockControls(false);

// Enable cursor
GetImGUI()->ShowCursor(true);
// Reset bypass
_lockControlsBypassed = false;
}
}
else {
// Unlock game controls
Game::Helpers::Controls::Lock(false);
}

// Disable cursor
GetImGUI()->ShowCursor(false);
void Application::ToggleLockControlsBypass() {
if (!AreControlsLocked()) {
Framework::Logging::GetLogger("Application")->error("[ToggleLockControlsBypass] Controls are not locked.");
return;
}

ProcessLockControls(_lockControlsBypassed);
_lockControlsBypassed = !_lockControlsBypassed;
}

uint64_t Application::GetLocalPlayerID() {
Expand Down
19 changes: 14 additions & 5 deletions code/client/src/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
namespace MafiaMP::Core {
class Application: public Framework::Integrations::Client::Instance {
private:
friend class DevFeatures;
std::shared_ptr<Framework::Utils::States::Machine> _stateMachine;
std::shared_ptr<UI::MafiaConsole> _console;
std::shared_ptr<UI::Console> _console;
std::shared_ptr<UI::Chat> _chat;
std::shared_ptr<UI::Web::Manager> _webManager;
std::shared_ptr<Game::Streaming::EntityFactory> _entityFactory;
Expand All @@ -34,14 +33,19 @@ namespace MafiaMP::Core {
std::shared_ptr<LuaVM> _luaVM;
flecs::entity _localPlayer;
DevFeatures _devFeatures;

float _tickInterval = 0.01667f;
int _controlsLocked = 0;

int _lockControlsCounter = 0;
bool _lockControlsBypassed = false;

int _mainMenuViewId = -1;

private:
Game::Helpers::Districts _lastDistrictID = Game::Helpers::Districts::UNSPECIFIED;

void ProcessLockControls(bool lock);

public:
bool PostInit() override;
bool PreShutdown() override;
Expand All @@ -52,9 +56,14 @@ namespace MafiaMP::Core {
void InitRPCs();

void PimpMyImGUI();

void LockControls(bool lock);
bool AreControlsLocked() const {
return _controlsLocked > 0;
return _lockControlsCounter > 0;
}
void ToggleLockControlsBypass();
bool AreControlsLockedBypassed() const {
return _lockControlsBypassed;
}

std::shared_ptr<Framework::Utils::States::Machine> GetStateMachine() const {
Expand All @@ -77,7 +86,7 @@ namespace MafiaMP::Core {
return _input;
}

std::shared_ptr<UI::MafiaConsole> GetDevConsole() const {
std::shared_ptr<UI::Console> GetConsole() const {
return _console;
}

Expand Down
Loading

0 comments on commit b17295c

Please sign in to comment.