* add new button to the overlay "toggle user info" to show/hide user info + make it hidden by default

* make all popups toggleable, clicking the button another time will show or hide the popup depending on its last state
* reorder the placement of buttons
This commit is contained in:
otavepto 2024-06-06 19:24:58 +03:00
parent e57daf02d0
commit 7201ac40b1
3 changed files with 157 additions and 39 deletions

View File

@ -132,9 +132,9 @@ class Steam_Overlay
std::vector<Overlay_Achievement> achievements{}; std::vector<Overlay_Achievement> achievements{};
bool show_overlay = false; bool show_overlay = false;
bool show_user_info = false;
bool show_achievements = false; bool show_achievements = false;
bool show_settings = false; bool show_settings = false;
bool show_test_ach = false;
// warn when using local save // warn when using local save
bool warn_local_save = false; bool warn_local_save = false;
@ -238,6 +238,7 @@ class Steam_Overlay
void add_invite_notification(std::pair<const Friend, friend_window_state> &wnd_state); void add_invite_notification(std::pair<const Friend, friend_window_state> &wnd_state);
void post_achievement_notification(Overlay_Achievement &ach); void post_achievement_notification(Overlay_Achievement &ach);
void add_chat_message_notification(std::string const& message); void add_chat_message_notification(std::string const& message);
void show_test_achievement();
bool open_overlay_hook(bool toggle); bool open_overlay_hook(bool toggle);

View File

@ -1168,6 +1168,102 @@ const char translationRenderer[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFF
}; };
const char translationToggleUserInfo[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = {
// 0 - English
u8"Toggle User Info",
// 1 - Arabic
u8"Toggle User Info",
// 2 - Bulgarian
u8"Toggle User Info",
// 3 - Simplified Chinese
u8"Toggle User Info",
// 4 - Traditional Chinese
u8"Toggle User Info",
// 5 - Czech
u8"Toggle User Info",
// 6 - Danish
u8"Toggle User Info",
// 7 - Dutch
u8"Toggle User Info",
// 8 - Finnish
u8"Toggle User Info",
// 9 - French
u8"Toggle User Info",
// 10 - German
u8"Toggle User Info",
// 11 - Greek
u8"Toggle User Info",
// 12 - Hungarian
u8"Toggle User Info",
// 13 - Italian
u8"Toggle User Info",
// 14 - Japanese
u8"Toggle User Info",
// 15 - Korean
u8"Toggle User Info",
// 16 - Norwegian
u8"Toggle User Info",
// 17 - Polish
u8"Toggle User Info",
// 18 - Portuguese
u8"Toggle User Info",
// 19 - Brazilian Portuguese
u8"Toggle User Info",
// 20 - Romanian
u8"Toggle User Info",
// 21 - Russian
u8"Toggle User Info",
// 22 - Spanish
u8"Toggle User Info",
// 23 - Latin American
u8"Toggle User Info",
// 24 - Swedish
u8"Toggle User Info",
// 25 - Thai
u8"Toggle User Info",
// 26 - Turkish
u8"Toggle User Info",
// 27 - Ukrainian
u8"Toggle User Info",
// 28 - Vietnamese
u8"Toggle User Info",
// 29 - Croatian
u8"Toggle User Info",
// 30 - Indonesian
u8"Toggle User Info",
};
const char translationShowAchievements[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = { const char translationShowAchievements[TRANSLATION_NUMBER_OF_LANGUAGES][TRANSLATION_BUFFER_SIZE] = {
// 0 - English // 0 - English
u8"Show Achievements", u8"Show Achievements",

View File

@ -12,7 +12,6 @@
#include <sstream> #include <sstream>
#include <cctype> #include <cctype>
#include <utility> #include <utility>
#include <random>
#include "InGameOverlay/RendererDetector.h" #include "InGameOverlay/RendererDetector.h"
@ -648,6 +647,34 @@ void Steam_Overlay::add_chat_message_notification(std::string const &message)
submit_notification(notification_type::message, message); submit_notification(notification_type::message, message);
} }
void Steam_Overlay::show_test_achievement()
{
PRINT_DEBUG_ENTRY();
Overlay_Achievement ach{};
ach.title = translationTestAchievement[current_language];
ach.description = "~~~ " + ach.title + " ~~~";
ach.achieved = true;
if (achievements.size()) {
size_t rand_idx = common_helpers::rand_number(achievements.size() - 1);
ach.icon = achievements[rand_idx].icon;
}
bool for_progress = false;
// randomly add progress
if (common_helpers::rand_number(1000) % 2) {
for_progress = true;
float progress = common_helpers::rand_number(500) / 10.0f + 50; // [50.0, 100.0]
ach.max_progress = 100;
ach.progress = progress;
ach.achieved = false;
}
post_achievement_notification(ach, for_progress);
// here we always play the sound for testing
notify_sound_user_achievement();
}
bool Steam_Overlay::is_friend_joinable(std::pair<const Friend, friend_window_state> &f) bool Steam_Overlay::is_friend_joinable(std::pair<const Friend, friend_window_state> &f)
{ {
PRINT_DEBUG("%" PRIu64 "", f.first.id()); PRINT_DEBUG("%" PRIu64 "", f.first.id());
@ -1237,13 +1264,6 @@ void Steam_Overlay::render_main_window()
ImGui::PushFont(font_default); ImGui::PushFont(font_default);
bool show = true; bool show = true;
char tmp[TRANSLATION_BUFFER_SIZE]{};
snprintf(tmp, sizeof(tmp), translationRenderer[current_language], (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str()));
std::string windowTitle{};
// Note: don't translate this, project and author names are nouns, they must be kept intact for proper referral
// think of it as translating "Protobuf - Google"
windowTitle.append("Ingame Overlay project - Nemirtingas (").append(tmp).append(")");
int style_color_stack = 0; int style_color_stack = 0;
if ((settings->overlay_appearance.background_r >= 0) && if ((settings->overlay_appearance.background_r >= 0) &&
(settings->overlay_appearance.background_g >= 0) && (settings->overlay_appearance.background_g >= 0) &&
@ -1311,25 +1331,41 @@ void Steam_Overlay::render_main_window()
style_color_stack += 5; style_color_stack += 5;
} }
char tmp[TRANSLATION_BUFFER_SIZE]{};
snprintf(tmp, sizeof(tmp), translationRenderer[current_language], (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str()));
std::string windowTitle{};
// Note: don't translate this, project and author names are nouns, they must be kept intact for proper referral
// think of it as translating "Protobuf - Google"
windowTitle.append("Ingame Overlay project - Nemirtingas (").append(tmp).append(")");
if (ImGui::Begin(windowTitle.c_str(), &show, if (ImGui::Begin(windowTitle.c_str(), &show,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoBringToFrontOnFocus)) { ImGuiWindowFlags_NoBringToFrontOnFocus)) {
if (show_user_info) {
ImGui::LabelText("##playinglabel", translationUserPlaying[current_language], ImGui::LabelText("##playinglabel", translationUserPlaying[current_language],
settings->get_local_name(), settings->get_local_name(),
settings->get_local_steam_id().ConvertToUint64(), settings->get_local_steam_id().ConvertToUint64(),
settings->get_local_game_id().AppID()); settings->get_local_game_id().AppID());
}
ImGui::Spacing();
ImGui::SameLine(); ImGui::SameLine();
ImGui::Spacing(); // user clicked on "toggle user info"
// user clicked on "show achievements" if (ImGui::Button(translationToggleUserInfo[current_language])) {
if (ImGui::Button(translationShowAchievements[current_language])) { show_user_info = !show_user_info;
show_achievements = true;
} }
ImGui::SameLine(); ImGui::SameLine();
// user clicked on "settings" // user clicked on "show achievements"
if (ImGui::Button(translationSettings[current_language])) { if (ImGui::Button(translationShowAchievements[current_language])) {
show_settings = true; show_achievements = !show_achievements;
}
ImGui::SameLine();
// user clicked on "test achievement"
if (ImGui::Button(translationTestAchievement[current_language])) {
show_test_achievement();
} }
ImGui::SameLine(); ImGui::SameLine();
@ -1340,24 +1376,9 @@ void Steam_Overlay::render_main_window()
} }
ImGui::SameLine(); ImGui::SameLine();
// user clicked on "test achievement" // user clicked on "settings"
if (ImGui::Button(translationTestAchievement[current_language])) { if (ImGui::Button(translationSettings[current_language])) {
Overlay_Achievement ach{}; show_settings = !show_settings;
ach.title = translationTestAchievement[current_language];
ach.description = "~~~ " + ach.title + " ~~~";
if (achievements.size()) {
// https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
std::random_device rd{}; // a seed source for the random number engine
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<> distrib(0, achievements.size() - 1);
size_t rand_idx = distrib(gen);
ach.icon = achievements[rand_idx].icon;
}
post_achievement_notification(ach);
notify_sound_user_achievement();
} }
ImGui::Spacing(); ImGui::Spacing();
@ -1373,7 +1394,7 @@ void Steam_Overlay::render_main_window()
} }
} }
if (ImGuiHelper_BeginListBox("##label", friends.size())) { if (ImGuiHelper_BeginListBox("##label", static_cast<int>(friends.size()))) {
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i) { std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i) {
ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id); ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id);