Modified a bit overlay and added comments

This commit is contained in:
Nemirtingas 2019-08-14 14:56:57 +02:00
parent 2c74abd6ab
commit 3eeca9b50e

View file

@ -339,10 +339,30 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
} }
} }
ImGui::PushItemWidth(-1.0f); ImGui::PushItemWidth(-1.0f); // Make the chat history widget fill the window
ImGui::ColoredInputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, 0 }, ImGuiInputTextFlags_ReadOnly); ImGui::ColoredInputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, 0 }, ImGuiInputTextFlags_ReadOnly);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
// TODO: Fix the layout of the chat line + send button.
// It should be like this: chat input should fill the window size minus send button size (button size is fixed)
// |------------------------------|
// | /--------------------------\ |
// | | | |
// | | chat history | |
// | | | |
// | \--------------------------/ |
// | [____chat line______] [send] |
// |------------------------------|
//
// And it is like this
// |------------------------------|
// | /--------------------------\ |
// | | | |
// | | chat history | |
// | | | |
// | \--------------------------/ |
// | [__chat line__] [send] |
// |------------------------------|
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue)) if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
{ {
send_chat_msg = true; send_chat_msg = true;
@ -371,13 +391,13 @@ void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& st
ImGui::End(); ImGui::End();
} }
// Try to make this function as short as possible or it might affect game's fps.
void Steam_Overlay::OverlayProc( int width, int height ) void Steam_Overlay::OverlayProc( int width, int height )
{ {
if (!show_overlay)
return;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (show_overlay)
{
int friend_size = friends.size(); int friend_size = friends.size();
// Set the overlay windows to the size of the game window // Set the overlay windows to the size of the game window
@ -387,7 +407,7 @@ void Steam_Overlay::OverlayProc( int width, int height )
ImGui::SetNextWindowBgAlpha(0.50); ImGui::SetNextWindowBgAlpha(0.50);
ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0.0; style.WindowRounding = 0.0; // Disable round window
if (ImGui::Begin("SteamOverlay", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus)) if (ImGui::Begin("SteamOverlay", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
{ {
@ -400,7 +420,7 @@ void Steam_Overlay::OverlayProc( int width, int height )
ImGui::LabelText("##label", "Friends"); ImGui::LabelText("##label", "Friends");
ImGui::ListBoxHeader("##label", friend_size); ImGui::ListBoxHeader("##label", friend_size);
std::for_each(friends.begin(), friends.end(), [this]( auto& i) std::for_each(friends.begin(), friends.end(), [this](auto& i)
{ {
ImGui::PushID(i.first.id()); ImGui::PushID(i.first.id());
@ -416,16 +436,10 @@ void Steam_Overlay::OverlayProc( int width, int height )
BuildFriendWindow(i.first, i.second); BuildFriendWindow(i.first, i.second);
}); });
ImGui::ListBoxFooter(); ImGui::ListBoxFooter();
//RECT rect;
//GetWindowRect(game_hwnd, &rect);
//auto pos = ImGui::GetMousePos();
//ImGui::LabelText("", "Window pos: %dx%d %dx%d", rect.left, rect.top, rect.right, rect.bottom);
//ImGui::LabelText("", "Mouse pos: %dx%d", (int)pos.x, (int)pos.y);
} }
ImGui::End(); ImGui::End();
}// if(show_overlay)
//ImGui::ShowDemoWindow();
} }
void Steam_Overlay::Callback(Common_Message *msg) void Steam_Overlay::Callback(Common_Message *msg)
@ -439,7 +453,7 @@ void Steam_Overlay::Callback(Common_Message *msg)
{ {
Steam_Messages const& steam_message = msg->steam_messages(); Steam_Messages const& steam_message = msg->steam_messages();
// Change color to cyan for friend // Change color to cyan for friend
friend_info->second.chat_history.append("\x1", 1).append("00FFFFFF", 8).append(steam_message.message()).append("\n", 1); friend_info->second.chat_history.append("\x1""00FFFFFF", 9).append(steam_message.message()).append("\n", 1);
} }
} }
} }
@ -485,7 +499,7 @@ void Steam_Overlay::RunCallbacks()
msg.set_dest_id(friend_id); msg.set_dest_id(friend_id);
network->sendTo(&msg, true); network->sendTo(&msg, true);
friend_info->second.chat_history.append("\x1", 1).append("00FF00FF", 8).append(input).append("\n", 1); friend_info->second.chat_history.append("\x1""00FF00FF", 9).append(input).append("\n", 1);
} }
*input = 0; // Reset the input field *input = 0; // Reset the input field
friend_info->second.window_state &= ~window_state_send_message; friend_info->second.window_state &= ~window_state_send_message;