imgui window overlay with lighting customization
This commit is contained in:
parent
3d6fef94d0
commit
5acaab54fb
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
|
#include "renderer.hpp"
|
||||||
|
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
@ -66,6 +67,68 @@ namespace gui
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gui_style()
|
||||||
|
{
|
||||||
|
auto* style = &ImGui::GetStyle();
|
||||||
|
auto colors = style->Colors;
|
||||||
|
|
||||||
|
style->WindowRounding = 5.3f;
|
||||||
|
style->FrameRounding = 2.3f;
|
||||||
|
style->ScrollbarRounding = 0;
|
||||||
|
|
||||||
|
//const auto color = ImColor(0, 0, 0, 240);
|
||||||
|
auto alpha = 0.92f;
|
||||||
|
|
||||||
|
colors[ImGuiCol_Text] = ImVec4(1.000f, 1.000f, 1.000f, alpha);
|
||||||
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.500f, 0.500f, 0.500f, alpha);
|
||||||
|
colors[ImGuiCol_WindowBg] = ImVec4(0.180f, 0.180f, 0.180f, alpha);
|
||||||
|
colors[ImGuiCol_ChildBg] = ImVec4(0.280f, 0.280f, 0.280f, 0.000f);
|
||||||
|
colors[ImGuiCol_PopupBg] = ImVec4(0.313f, 0.313f, 0.313f, alpha);
|
||||||
|
colors[ImGuiCol_Border] = ImVec4(0.266f, 0.266f, 0.266f, alpha);
|
||||||
|
colors[ImGuiCol_BorderShadow] = ImVec4(0.000f, 0.000f, 0.000f, 0.000f);
|
||||||
|
colors[ImGuiCol_FrameBg] = ImVec4(0.160f, 0.160f, 0.160f, alpha);
|
||||||
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.200f, 0.200f, 0.200f, alpha);
|
||||||
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.280f, 0.280f, 0.280f, alpha);
|
||||||
|
colors[ImGuiCol_TitleBg] = ImVec4(0.148f, 0.148f, 0.148f, alpha);
|
||||||
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.148f, 0.148f, 0.148f, alpha);
|
||||||
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.148f, 0.148f, 0.148f, alpha);
|
||||||
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.195f, 0.195f, 0.195f, alpha);
|
||||||
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.160f, 0.160f, 0.160f, alpha);
|
||||||
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.277f, 0.277f, 0.277f, alpha);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.300f, 0.300f, 0.300f, alpha);
|
||||||
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_CheckMark] = ImVec4(1.000f, 1.000f, 1.000f, alpha);
|
||||||
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.391f, 0.391f, 0.391f, alpha);
|
||||||
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_Button] = ImVec4(1.000f, 1.000f, 1.000f, 0.000f);
|
||||||
|
colors[ImGuiCol_ButtonHovered] = ImVec4(1.000f, 1.000f, 1.000f, 0.156f);
|
||||||
|
colors[ImGuiCol_ButtonActive] = ImVec4(1.000f, 1.000f, 1.000f, 0.391f);
|
||||||
|
colors[ImGuiCol_Header] = ImVec4(0.313f, 0.313f, 0.313f, alpha);
|
||||||
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.469f, 0.469f, 0.469f, alpha);
|
||||||
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.469f, 0.469f, 0.469f, alpha);
|
||||||
|
colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];
|
||||||
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.391f, 0.391f, 0.391f, alpha);
|
||||||
|
colors[ImGuiCol_SeparatorActive] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_ResizeGrip] = ImVec4(1.000f, 1.000f, 1.000f, 0.250f);
|
||||||
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.000f, 1.000f, 1.000f, 0.670f);
|
||||||
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_Tab] = ImVec4(0.098f, 0.098f, 0.098f, alpha);
|
||||||
|
colors[ImGuiCol_TabHovered] = ImVec4(0.352f, 0.352f, 0.352f, alpha);
|
||||||
|
colors[ImGuiCol_TabActive] = ImVec4(0.195f, 0.195f, 0.195f, alpha);
|
||||||
|
colors[ImGuiCol_TabUnfocused] = ImVec4(0.098f, 0.098f, 0.098f, alpha);
|
||||||
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.195f, 0.195f, 0.195f, alpha);
|
||||||
|
colors[ImGuiCol_PlotLines] = ImVec4(0.469f, 0.469f, 0.469f, alpha);
|
||||||
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_PlotHistogram] = ImVec4(0.586f, 0.586f, 0.586f, alpha);
|
||||||
|
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_TextSelectedBg] = ImVec4(1.000f, 1.000f, 1.000f, 0.156f);
|
||||||
|
colors[ImGuiCol_DragDropTarget] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_NavHighlight] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.000f, 0.391f, 0.000f, alpha);
|
||||||
|
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.000f, 0.000f, 0.000f, 0.586f);
|
||||||
|
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.000f, 0.000f, 0.000f, 0.586f);
|
||||||
|
}
|
||||||
|
|
||||||
void new_gui_frame()
|
void new_gui_frame()
|
||||||
{
|
{
|
||||||
ImGui::GetIO().MouseDrawCursor = toggled;
|
ImGui::GetIO().MouseDrawCursor = toggled;
|
||||||
@ -83,6 +146,7 @@ namespace gui
|
|||||||
run_event_queue();
|
run_event_queue();
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
gui_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_gui_frame()
|
void end_gui_frame()
|
||||||
@ -97,44 +161,6 @@ namespace gui
|
|||||||
enabled_menus[name] = !enabled_menus[name];
|
enabled_menus[name] = !enabled_menus[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_notifications()
|
|
||||||
{
|
|
||||||
static const auto window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
|
|
||||||
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav |
|
|
||||||
ImGuiWindowFlags_NoMove;
|
|
||||||
|
|
||||||
notifications.access([](std::deque<notification_t>& notifications_)
|
|
||||||
{
|
|
||||||
auto index = 0;
|
|
||||||
for (auto i = notifications_.begin(); i != notifications_.end();)
|
|
||||||
{
|
|
||||||
const auto now = std::chrono::high_resolution_clock::now();
|
|
||||||
if (now - i->creation_time >= i->duration)
|
|
||||||
{
|
|
||||||
i = notifications_.erase(i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto title = utils::string::truncate(i->title, 34, "...");
|
|
||||||
const auto text = utils::string::truncate(i->text, 34, "...");
|
|
||||||
|
|
||||||
ImGui::SetNextWindowSizeConstraints(ImVec2(250, 50), ImVec2(250, 50));
|
|
||||||
ImGui::SetNextWindowBgAlpha(0.6f);
|
|
||||||
ImGui::Begin(utils::string::va("Notification #%i", index), nullptr, window_flags);
|
|
||||||
|
|
||||||
ImGui::SetWindowPos(ImVec2(10, 30.f + static_cast<float>(index) * 60.f));
|
|
||||||
ImGui::SetWindowSize(ImVec2(250, 0));
|
|
||||||
ImGui::Text(title.data());
|
|
||||||
ImGui::Text(text.data());
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
++i;
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void menu_checkbox(const std::string& name, const std::string& menu)
|
void menu_checkbox(const std::string& name, const std::string& menu)
|
||||||
{
|
{
|
||||||
ImGui::Checkbox(name.data(), &enabled_menus[menu]);
|
ImGui::Checkbox(name.data(), &enabled_menus[menu]);
|
||||||
@ -154,21 +180,21 @@ namespace gui
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_main_menu_bar()
|
void draw_window()
|
||||||
{
|
{
|
||||||
if (ImGui::BeginMainMenuBar())
|
ImGui::Begin("hello world!", nullptr);
|
||||||
{
|
|
||||||
if (ImGui::BeginMenu("Windows"))
|
|
||||||
{
|
|
||||||
menu_checkbox("Console", "console");
|
|
||||||
menu_checkbox("Script console", "script_console");
|
|
||||||
menu_checkbox("Debug", "debug");
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
static int value = 0;
|
||||||
|
const auto technique = ImGui::SliderInt("lighting technique", &value, 0, 25);
|
||||||
|
|
||||||
|
const auto should_apply = ImGui::Button("apply", ImVec2(125, 125));
|
||||||
|
if (should_apply)
|
||||||
|
{
|
||||||
|
printf("new technique! value is %d\n", value);
|
||||||
|
renderer::update_tech(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::End();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_on_frame()
|
void gui_on_frame()
|
||||||
@ -311,12 +337,11 @@ namespace gui
|
|||||||
{
|
{
|
||||||
utils::hook::jump(0x6CB176_b, utils::hook::assemble(dxgi_swap_chain_present_stub), true);
|
utils::hook::jump(0x6CB176_b, utils::hook::assemble(dxgi_swap_chain_present_stub), true);
|
||||||
|
|
||||||
wnd_proc_hook.create(0x5162D0_b, wnd_proc_stub);
|
wnd_proc_hook.create(0x5BFF60_b, wnd_proc_stub);
|
||||||
|
|
||||||
on_frame([]()
|
on_frame([]()
|
||||||
{
|
{
|
||||||
show_notifications();
|
draw_window();
|
||||||
draw_main_menu_bar();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,50 +10,38 @@
|
|||||||
|
|
||||||
namespace renderer
|
namespace renderer
|
||||||
{
|
{
|
||||||
|
static int tech = 0;
|
||||||
|
|
||||||
|
void custom_gfx_draw_method()
|
||||||
|
{
|
||||||
|
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
|
||||||
|
game::gfxDrawMethod->baseTechType = tech;
|
||||||
|
game::gfxDrawMethod->emissiveTechType = tech;
|
||||||
|
game::gfxDrawMethod->forceTechType = tech;
|
||||||
|
}
|
||||||
|
|
||||||
|
void default_gfx_draw_method()
|
||||||
|
{
|
||||||
|
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
|
||||||
|
game::gfxDrawMethod->baseTechType = game::TECHNIQUE_LIT;
|
||||||
|
game::gfxDrawMethod->emissiveTechType = game::TECHNIQUE_EMISSIVE;
|
||||||
|
game::gfxDrawMethod->forceTechType = 242;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_tech(int new_tech)
|
||||||
|
{
|
||||||
|
tech = new_tech;
|
||||||
|
custom_gfx_draw_method();
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
utils::hook::detour r_init_draw_method_hook;
|
utils::hook::detour r_init_draw_method_hook;
|
||||||
utils::hook::detour r_update_front_end_dvar_options_hook;
|
utils::hook::detour r_update_front_end_dvar_options_hook;
|
||||||
|
|
||||||
int get_fullbright_technique()
|
|
||||||
{
|
|
||||||
switch (dvars::r_fullbright->current.integer)
|
|
||||||
{
|
|
||||||
case 4:
|
|
||||||
return 3;
|
|
||||||
case 3:
|
|
||||||
return 13;
|
|
||||||
case 2:
|
|
||||||
return 25;
|
|
||||||
default:
|
|
||||||
return game::TECHNIQUE_UNLIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gfxdrawmethod()
|
|
||||||
{
|
|
||||||
game::gfxDrawMethod->drawScene = game::GFX_DRAW_SCENE_STANDARD;
|
|
||||||
game::gfxDrawMethod->baseTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_LIT;
|
|
||||||
game::gfxDrawMethod->emissiveTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : game::TECHNIQUE_EMISSIVE;
|
|
||||||
game::gfxDrawMethod->forceTechType = dvars::r_fullbright->current.enabled ? get_fullbright_technique() : 242;
|
|
||||||
}
|
|
||||||
|
|
||||||
void r_init_draw_method_stub()
|
void r_init_draw_method_stub()
|
||||||
{
|
{
|
||||||
gfxdrawmethod();
|
default_gfx_draw_method();
|
||||||
}
|
|
||||||
|
|
||||||
bool r_update_front_end_dvar_options_stub()
|
|
||||||
{
|
|
||||||
if (dvars::r_fullbright->modified)
|
|
||||||
{
|
|
||||||
game::Dvar_ClearModified(dvars::r_fullbright);
|
|
||||||
game::R_SyncRenderThread();
|
|
||||||
|
|
||||||
gfxdrawmethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
return r_update_front_end_dvar_options_hook.invoke<bool>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +55,7 @@ namespace renderer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dvars::r_fullbright = dvars::register_int("r_fullbright", 0, 0, 4, game::DVAR_FLAG_SAVED, "Toggles rendering without lighting");
|
|
||||||
|
|
||||||
r_init_draw_method_hook.create(SELECT_VALUE(0x5467E0_b, 0x669580_b), &r_init_draw_method_stub);
|
r_init_draw_method_hook.create(SELECT_VALUE(0x5467E0_b, 0x669580_b), &r_init_draw_method_stub);
|
||||||
r_update_front_end_dvar_options_hook.create(SELECT_VALUE(0x583560_b, 0x6A78C0_b), &r_update_front_end_dvar_options_stub);
|
|
||||||
|
|
||||||
// use "saved" flags
|
// use "saved" flags
|
||||||
dvars::override::register_enum("r_normalMap", game::DVAR_FLAG_SAVED);
|
dvars::override::register_enum("r_normalMap", game::DVAR_FLAG_SAVED);
|
||||||
|
6
src/client/component/renderer.hpp
Normal file
6
src/client/component/renderer.hpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace renderer
|
||||||
|
{
|
||||||
|
void update_tech(int tech);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user