From e8e05403c9babcfc6232bc9416210ebcada03572 Mon Sep 17 00:00:00 2001 From: stormy <120167078+stowmyy@users.noreply.github.com> Date: Thu, 26 Oct 2023 02:52:17 -0500 Subject: [PATCH] quality: add indicator when restart is needed --- .../assets/images/background-diagonal.png | Bin 8216 -> 5991 bytes dropship/src/DashboardManager.cpp | 130 +++++++++++++++--- dropship/src/DashboardManager.h | 3 + dropship/src/_WindowsFirewallUtil.h | 2 + dropship/src/images.cpp | 8 ++ dropship/src/images.h | 10 +- dropship/src/theme.cpp | 4 + 7 files changed, 133 insertions(+), 24 deletions(-) diff --git a/dropship/assets/images/background-diagonal.png b/dropship/assets/images/background-diagonal.png index 204ee8b988b0b09fe7654e9e41f77ef08c53917b..fc77d634fc6698ac8ad69bdea09011064a7bba38 100644 GIT binary patch literal 5991 zcmeHLYfuwc6kZ;JkRm=t8DBvW2dAm7LTlbi-bTDAR#nBg2^s)rZfH3$&YOAetY)Z zz31Nh-S3?2Pqu`*xh`-80KhFgEO;vb*zYv9>!&*zukUj>w~T*wDO*D~0^Em-x{NoD zi9r!T08o@m(8ocO>M>K%KQ>^k4=eg~>q7IE(Jyr#%2jDkl>UXm1{l#m7*4ShUT)mK8|MR-~n zy0Gei6j-HmI@(6g5FmCj8aLUHgzd?dG0{NOa6d5fr4+41v-f7g3pIyDrE$`4MjPTo zQ2H)U?X4j@?o=@05QdXVWwO!+(ecVfNWH&gEZ!3VTlCc9*|}sYnnx)jl?~C1vsIJ? z&AEFu4^h@}Iv)d~r0f%I(X+?i`Z@vfZju`7(IO0_PN8kFf&BLXSX3;6u z721S^U8u9@)YAXhrzUDbs{Lap`F^vj^(El!7rmxInL*1@i!Q=>t8-0*!uhv_0<$VU z`a;M(t!w1^=UXj1k!hW+T#~vk5`9<28CDf=s#5Au(p}TSG+T_VS>av-{fyckVXD%S zg|bGU=FkMl&YFjclK?jCP=;s~CrI_JDTBMa$M{H{bTu0Gy*bV_CSJJIEdWWp;%v7Ksj5qHw#`GT4knIEe$^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3oL-98KY+nKSMwO2qT!gC=JR^y~^&RNxk-cx!$0ZFMS@8=MXD-H7PCYQ7sA zdl9~`<>aFXLB=Cc-lhJ2S=1LU%yb6XR~^z~P#e0g2{I9C^M)j-o8Ub#jeTu4Ue`8? z5}rc<1q(Kq2%r#X7^+4b6cAPPY6iYIhpIG(6Bd`kPi=(C=fuHt2*IqR8iLa!fdJff z<+(UuDBrM*U?E$U&Yf8Bkz=I`MWts=tM`9UChQvl?5XW=49XaWi=wblmyt^?+bxX1 z@r-@|VF?rl3&F*XbqJ>{3v1z~q0~W6{yhmvXskS+(mc^pcJo%cE-nPAe77+p0OlBIwlcmKVSg3#&nh_|;AS!CwAK1+LjwN4B9TZ-#6B-O0wtxOr1x6w$m%Ivu zoO+rQyd_(sj+`t8Yt*Bhv8snChoFUEOoyC1`{zYXrO@HboB9}u3lZtM=G6}S&Bpai z6X4>8=2n}z<=f-Do+5XIpx2jMesEPsOcJ>~OFgu0#vH*O<~u#Lr;8AKov1OQqD01|D8e1Bpj)@$j5Rn}t|iJ)A<*J-7x z?LSXAs)h~n;u4dR3-qW8FcLw2(!sSBvvd}0oXwjvam~&$)KA_qb>yUB4M(YT%zXUV z?rtY%nWi#OYNKJ@62pJkILns}DXH$}imlVKwxvyi;aG%(y_E2Y_RTY=5o(hGHpCFT zIq<1%gjS5H@f9@?n8JfS=|=#Cr&1q5*eeP?(@q41hQTAy%#-P&gEGAGuTyCv!kuyo z`VQmHh&UP!Tm|g}?qS4%i_3)ek-5ze`1daAElGP|pXl0GMp2+Ac0 z0H%fR0};KU5nFBjy6=jlLi?l5Gugp@8=Yx>7pjua%MAaO}stUY_z_Wi#nhe$yJk%9y}TY1|~{eL2INI^oL vkdOx~ua8;({2YlCB>z}J!ZJB*>PhBgame_restart_required = false; } if (!__previous__application_open && appStore.application_open) { - appStore.dashboard.heading = "Blocking new servers won't take effect until Overwatch is relaunched."; + appStore.dashboard.heading = "Blocking new servers won't take effect until Overwatch is restarted."; } if (this->processes[process_name].icon.texture == nullptr) @@ -517,7 +519,86 @@ void DashboardManager::RenderInline() } } - for (auto const& [_p, process] : this->processes) + { + + static const auto color = ImGui::ColorConvertFloat4ToU32({ .4f, .4f, .4f, 1.0f }); + // static const auto color_2 = ImGui::ColorConvertFloat4ToU32({ 0, 0, 0, 0.6f }); + static const std::string text = "GAME RESTART REQUIRED"; + + static const auto font = font_subtitle; + static const auto font_size = font->CalcTextSizeA(font_subtitle->FontSize, FLT_MAX, 0.0f, text.c_str()); + + + if (this->game_restart_required) + { + ImGui::Dummy({ ImGui::GetContentRegionAvail().x, font_size.y + 16 }); + + list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color, 5.0f); + static const auto pos = ImGui::GetItemRectMin() + ImVec2((ImGui::GetItemRectSize().x - font_size.x) / 2, 8 - 2); + + list->AddText(font_subtitle, font_subtitle->FontSize, pos, white, text.c_str()); + } + + /*else + { + list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_2, 5.0f, 0); + + static const std::string tips[3] = { + "TIP: Don't queue with other people", + "tip 2", + }; + + list->PushClipRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + list->AddText(font_subtitle, font_subtitle->FontSize, ImGui::GetItemRectMin() + ImVec2(style.FramePadding.x, 8 - 1), white, tips[((int) (ImGui::GetTime() / 9)) % 2].c_str()); + list->PopClipRect(); + }*/ + + else + { + /*static const auto n_buttons = 3; + static const auto button_width = (ImGui::GetContentRegionAvail().x / n_buttons); + static const auto button_height = 36; + + ImGui::PushFont(font_subtitle); + ImGui::PushStyleColor(ImGuiCol_Text, white); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { style.FramePadding.x, style.FramePadding.y - 4 }); + { + ImGui::Button("ALL ON", { button_width, button_height }); + ImGui::SameLine(); + ImGui::Button("RESET APP", { button_width, button_height }); + ImGui::SameLine(); + ImGui::Button("TEST", { button_width, button_height }); + } + ImGui::PopStyleVar(); + ImGui::PopStyleColor(); + ImGui::PopFont();*/ + + // static const auto color_2 = ImGui::ColorConvertFloat4ToU32({ 0, 0, 0, 0.9f }); + + /*{ + ImGui::PushID(1); + ImGui::PushStyleColor(ImGuiCol_Header, button); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, button_hovered); + ImGui::PushStyleColor(ImGuiCol_HeaderActive, button_active); + ImGui::PushStyleColor(ImGuiCol_NavHighlight, NULL); + bool action = (ImGui::Selectable("##end", &(this->all_selected), ImGuiSelectableFlags_SelectOnClick, { button_width, button_height })); + ImGui::PopStyleColor(4); + ImGui::PopID(); + + if (!this->all_selected) list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_2, 5.0f); + + static const std::string text = "ALL ON"; + list->AddText(font_subtitle, font_subtitle->FontSize, ImGui::GetItemRectMin() + ImVec2(style.FramePadding.x, 8 - 1), white, text.c_str()); + + if (action) + { + } + }*/ + } + + } + + /*for (auto const& [_p, process] : this->processes) { // TODO current window if (appStore._window_overlaying == "Overwatch") @@ -558,7 +639,7 @@ void DashboardManager::RenderInline() if(!process.on) ImGui::EndDisabled(); } - ImGui::EndGroup(); + ImGui::EndGroup();*/ /*{ static const auto width = 140; @@ -581,7 +662,7 @@ void DashboardManager::RenderInline() list->AddText(pos + style.FramePadding + ImVec2(24, -8), white, "KILLSWITCH"); }*/ - + /* if (ImGui::IsItemClicked() && process.window) { @@ -591,7 +672,7 @@ void DashboardManager::RenderInline() // maximize window PostMessage(process.window, WM_SYSCOMMAND, SC_RESTORE, 0); } - } + }*/ ImGui::Spacing(); @@ -607,7 +688,7 @@ void DashboardManager::RenderInline() auto const unsynced = (endpoint.active != endpoint.active_desired_state); // 0.4f looks quite good - static const ImU32 color_disabled = ImGui::ColorConvertFloat4ToU32({ .8f, .8f, .8f, 8.0f }); + static const ImU32 color_disabled = ImGui::ColorConvertFloat4ToU32({ .8f, .8f, .8f, 1.0f }); static const ImU32 color_disabled_secondary = ImGui::ColorConvertFloat4ToU32({ .88f, .88f, .88f, 1.0f }); static const ImU32 color_disabled_secondary_faded = ImGui::ColorConvertFloat4ToU32({ .95f, .95f, .95f, 1.0f }); @@ -623,14 +704,12 @@ void DashboardManager::RenderInline() // ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 16, 73 }); ImGui::PushID(i); - ImGui::PushStyleColor(ImGuiCol_HeaderHovered, endpoint.active_desired_state ? color_secondary : color_secondary_faded); - ImGui::PushStyleColor(ImGuiCol_Header, endpoint.active_desired_state ? color_secondary : color_secondary_faded); - ImGui::PushStyleColor(ImGuiCol_HeaderActive, endpoint.active_desired_state ? color_secondary : color_secondary_faded); + ImGui::PushStyleColor(ImGuiCol_HeaderHovered, endpoint.active ? color_secondary : color_secondary_faded); + ImGui::PushStyleColor(ImGuiCol_Header, endpoint.active ? color_secondary : color_secondary_faded); + ImGui::PushStyleColor(ImGuiCol_HeaderActive, endpoint.active ? color_secondary : color_secondary_faded); ImGui::PushStyleColor(ImGuiCol_NavHighlight, NULL); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 16.0f); bool action = (ImGui::Selectable("##end", &(endpoint.active_desired_state), ImGuiSelectableFlags_SelectOnClick, { ImGui::GetContentRegionAvail().x - 16, 74 - 9 })); ImGui::PopStyleColor(4); - ImGui::PopStyleVar(); ImGui::PopID(); ImGui::Spacing(); @@ -639,10 +718,10 @@ void DashboardManager::RenderInline() // background if (hovered) - if (endpoint.active_desired_state) + if (endpoint.active) w_list->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, 0, 8); - else if (endpoint.active_desired_state) + if (!hovered && endpoint.active) w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color, 5, NULL); // unsynced background @@ -653,24 +732,26 @@ void DashboardManager::RenderInline() const auto offset_vec = ImVec2((float) offset, (float) offset); const auto pos = ImGui::GetItemRectMin() - ImVec2(40, 40) + offset_vec; + static const auto image = _get_image("background_diagonal"); + w_list->PushClipRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), true); - w_list->AddImage(_get_texture("background_diagonal"), pos, pos + ImVec2(400, 400), ImVec2(0, 0), ImVec2(1, 1), color); + w_list->AddImage(image.texture, pos, pos + ImVec2(image.width, image.height), ImVec2(0, 0), ImVec2(1, 1), color); w_list->PopClipRect(); } // icon const auto icon_frame = ImVec2({ ImGui::GetItemRectSize().y, ImGui::GetItemRectSize().y }); static auto padding = ImVec2(21, 21); - const auto icon = !unsynced ? (endpoint.active_desired_state ? _get_texture("icon_allow") : _get_texture("icon_block")) : _get_texture("icon_wall_fire"); - w_list->AddImage(icon, ImGui::GetItemRectMin() + padding, ImGui::GetItemRectMin() + icon_frame - padding, ImVec2(0, 0), ImVec2(1, 1), endpoint.active_desired_state ? color_text_secondary : color /*color_secondary_faded*/); + const auto icon = !unsynced ? (endpoint.active ? _get_texture("icon_allow") : _get_texture("icon_block")) : _get_texture("icon_wall_fire"); + w_list->AddImage(icon, ImGui::GetItemRectMin() + padding, ImGui::GetItemRectMin() + icon_frame - padding, ImVec2(0, 0), ImVec2(1, 1), endpoint.active ? color_text_secondary : color /*color_secondary_faded*/); // display 1 auto pos = ImGui::GetItemRectMin() + ImVec2(icon_frame.x, 4) + ImVec2(-2, 0); - w_list->AddText(font_title, 35, pos, endpoint.active_desired_state ? white : color, endpoint.title.c_str()); + w_list->AddText(font_title, 35, pos, endpoint.active ? white : color, endpoint.title.c_str()); // display 2 pos += ImVec2(1, ImGui::GetItemRectSize().y - 24 - 16); - w_list->AddText(font_subtitle, 24, pos, endpoint.active_desired_state ? color_text_secondary : color_secondary, endpoint.heading.c_str()); + w_list->AddText(font_subtitle, 24, pos, endpoint.active ? color_text_secondary : color_secondary, endpoint.heading.c_str()); // popup /*{ @@ -699,6 +780,13 @@ void DashboardManager::RenderInline() { // std::thread([&]() { firewallManager.sync(&(this->endpoints), appStore.application_open); + + bool pending_actions = false; + for (auto& e : this->endpoints) + if (e.active != e.active_desired_state) + pending_actions = true; + + this->game_restart_required = pending_actions; // }).detach(); // fill missing frame @@ -723,7 +811,7 @@ void DashboardManager::RenderInline() } auto pos = ImGui::GetItemRectMax() - ImVec2(frame.x, ImGui::GetItemRectSize().y) + (style.FramePadding * ImVec2(-1, 1)) + ImVec2(-8, 1); - w_list->AddImage(icon, pos, pos + frame, ImVec2(0, 0), ImVec2(1, 1), endpoint.active_desired_state ? white : color); + w_list->AddImage(icon, pos, pos + frame, ImVec2(0, 0), ImVec2(1, 1), endpoint.active ? white : color); } @@ -734,9 +822,11 @@ void DashboardManager::RenderInline() auto text_size = font_subtitle->CalcTextSizeA(24, FLT_MAX, 0.0f, text.c_str()); auto pos = ImGui::GetItemRectMax() - style.FramePadding - text_size + ImVec2(-8, -4); - w_list->AddText(font_subtitle, 24, pos, endpoint.active_desired_state ? color_text_secondary : color_secondary, text.c_str()); + w_list->AddText(font_subtitle, 24, pos, endpoint.active ? color_text_secondary : color_secondary, text.c_str()); } + // ImGui::Text("active: %d, desired: %d", endpoint.active, endpoint.active_desired_state); + i += 1; } } diff --git a/dropship/src/DashboardManager.h b/dropship/src/DashboardManager.h index 71b8c35..62908d6 100644 --- a/dropship/src/DashboardManager.h +++ b/dropship/src/DashboardManager.h @@ -44,6 +44,9 @@ class DashboardManager : public manager double __date_new_selection = 0; bool show_all = { false }; bool pinging; + bool game_restart_required = false; + + bool all_selected = { false }; const std::unordered_map ips; std::vector endpoints; diff --git a/dropship/src/_WindowsFirewallUtil.h b/dropship/src/_WindowsFirewallUtil.h index dcf0825..e484b62 100644 --- a/dropship/src/_WindowsFirewallUtil.h +++ b/dropship/src/_WindowsFirewallUtil.h @@ -1330,6 +1330,8 @@ class _WindowsFirewallUtil : public failable if (!e.active_desired_state != ruleEnabled && (!only_unblocks || (only_unblocks && (!e.active && e.active_desired_state)))) { + printf("\n\nhere\n\n"); + // if endpointDominant, set firewall to mirror endpoint state if (endpointDominant) { diff --git a/dropship/src/images.cpp b/dropship/src/images.cpp index 2a3f335..1b0d9e4 100644 --- a/dropship/src/images.cpp +++ b/dropship/src/images.cpp @@ -137,6 +137,14 @@ bool _add_texture(std::string title, std::string type) return loaded; } +ImageTexture _get_image (std::string title) +{ + if (APP_TEXTURES.contains(title)) + return APP_TEXTURES.at(title); + + else return { nullptr, 0, 0 }; +} + ID3D11ShaderResourceView* _get_texture(std::string title) { diff --git a/dropship/src/images.h b/dropship/src/images.h index 4592736..4a17bbf 100644 --- a/dropship/src/images.h +++ b/dropship/src/images.h @@ -19,10 +19,6 @@ bool loadPicture(std::string title, std::string type, ID3D11ShaderResourceView** bool _add_texture(std::string title, std::string type); -ID3D11ShaderResourceView* _get_texture(std::string title); - -// static std::unordered_map APP_TEXTURES = { }; - struct ImageTexture { ID3D11ShaderResourceView* texture; @@ -30,3 +26,9 @@ struct ImageTexture int height; }; +ImageTexture _get_image(std::string title); + +ID3D11ShaderResourceView* _get_texture(std::string title); + +// static std::unordered_map APP_TEXTURES = { }; + diff --git a/dropship/src/theme.cpp b/dropship/src/theme.cpp index ae2f1f0..e994c2e 100644 --- a/dropship/src/theme.cpp +++ b/dropship/src/theme.cpp @@ -62,6 +62,10 @@ void setTheme(THEME theme) style.DisabledAlpha = 0.4; + style.Colors[ImGuiCol_Button] = { 0, 0, 0, 0.8f }; + style.Colors[ImGuiCol_ButtonHovered] = { 0, 0, 0, 0.7f }; + style.Colors[ImGuiCol_ButtonActive] = { 0, 0, 0, 0.6f }; + if (theme == dark) { style.Colors[ImGuiCol_ModalWindowDimBg] = { 0.0f, 0.0f, 0.0f, 0.90f };