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

Add Overlay Binding Notification on Game Start #986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
63 changes: 62 additions & 1 deletion src/overlay/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void Overlay::PostInitialize()
}

m_initialized = true;

m_startTime = std::chrono::steady_clock::now();
}
}

Expand Down Expand Up @@ -195,12 +197,40 @@ void Overlay::Update()
}
}

// Display binding in bottom right corner for 5 seconds
if (!Bindings::IsFirstTimeSetup() && !m_bindHintShown)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rather do something like in feature/notifications branch instead of this, and consider expanding it to sol_ImGui for mods to use.

Maybe even add some setting for the type of spdlog loglevel to notify about and automatically notify when someone logs something. Could be very useful for mods and also internal errors.

The branch needs tweaking, is just a starting point basically reimplementing this PR. It has issues with close button looking weird (probably collision with our style vs. default ImGui style the ImGuiNotify expects...) and is missing license in ThirdParty_LICENSE file.

{
const auto currentTime = std::chrono::steady_clock::now();
if ((currentTime - m_startTime) < std::chrono::seconds(5))
{
if (m_notificationString.empty())
{
auto overlayBindCode = CET::Get().GetBindings().GetBindCodeForModBind(Bindings::GetOverlayToggleModBind());

m_notificationString = "CET Overlay Bind: ";
m_notificationString += VKBindings::GetBindString(overlayBindCode);
}

m_drawNotification = true;
}
else
{
m_bindHintShown = true;
m_drawNotification = false;
m_notificationString.clear();
}
}

if (m_drawNotification)
DrawNotification();

if (!m_enabled)
return;

const auto [width, height] = CET::Get().GetD3D12().GetResolution();
const auto heightLimit = 2 * ImGui::GetFrameHeight() + 2 * ImGui::GetStyle().WindowPadding.y;
ImGui::SetNextWindowPos({width * 0.25f, height * 0.05f}, ImGuiCond_FirstUseEver);
ImGui::SetNextWindowBgAlpha(1.0);
ImGui::SetNextWindowPos({width * 0.25f, height * 0.05f});
ImGui::SetNextWindowSizeConstraints({width * 0.5f, heightLimit}, {FLT_MAX, heightLimit});
if (ImGui::Begin("Cyber Engine Tweaks"))
DrawToolbar();
Expand Down Expand Up @@ -346,3 +376,34 @@ void Overlay::DrawToolbar()
if (ImGui::Button("Reload all mods", ImVec2(itemWidth, 0)))
m_vm.ReloadAllMods();
}

// TODO: Multiple notifications?
void Overlay::DrawNotification()
{
// ID must be unique for different messages, so why not use the FNV1a hash?
const auto imGuiID = RED4ext::FNV1a32(m_notificationString.c_str());
const auto [width, height] = CET::Get().GetD3D12().GetResolution();

const auto notificationWidth = ImGui::CalcTextSize(m_notificationString.c_str()).x + 2 * ImGui::GetStyle().WindowPadding.x;
const auto notificationHeight = ImGui::CalcTextSize(m_notificationString.c_str()).y + 2 * ImGui::GetStyle().WindowPadding.y;

ImGui::SetNextWindowBgAlpha(0.5);
ImGui::SetNextWindowPos({ImGui::GetStyle().WindowPadding.x, height - (notificationHeight + ImGui::GetStyle().WindowPadding.y)});
ImGui::SetNextWindowSize({notificationWidth, notificationHeight});
if (ImGui::Begin(std::format("##{}", imGuiID).c_str(), nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoSavedSettings))
{
ImGui::TextUnformatted(m_notificationString.c_str());
}
ImGui::End();
}

void Overlay::ShowNotification(const std::string& notification)
{
m_notificationString = notification;
m_drawNotification = true;
}

void Overlay::HideNotification()
{
m_drawNotification = false;
}
9 changes: 9 additions & 0 deletions src/overlay/Overlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ struct Overlay

void Update();

void ShowNotification(const std::string& notification);
void HideNotification();

protected:
void Hook();

static BOOL ClipToCenter(RED4ext::CGameEngine::UnkD0* apThis);

private:
void DrawToolbar();
void DrawNotification();

Console m_console;
Bindings m_bindings;
Expand All @@ -47,8 +51,13 @@ struct Overlay
std::atomic_bool m_enabled{false};
std::atomic_bool m_toggled{false};
bool m_initialized{false};
std::atomic_bool m_drawNotification{false};
std::chrono::time_point<std::chrono::steady_clock> m_startTime;
bool m_bindHintShown{false};

Options& m_options;
PersistentState& m_persistentState;
LuaVM& m_vm;

std::string m_notificationString;
};