mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-30 15:50:05 -06:00
* Implemented guest-to-host function pointers (WIP) Co-Authored-By: Skyth (Asilkan) <19259897+blueskythlikesclouds@users.noreply.github.com> * function: support more types for function pointers * Initial options menu implementation. * Improve options menu visuals. * Draw fade on borders, center tabs better. * Adjust line sizes, fix tab text centering. * Adjust padding & text sizes. * Fix bar dark gradient effect. * api: ported BlueBlur headers and misc. research * Fix config name padding not getting scaled at different resolutions. * config: use string_view, added method to get value pointer * config: use std::map for reverse enum template * Draw config options manually instead of looping through them. * config: implemented name and enum localisation * config_detail: move implementation to cpp, relocate sources * Implemented accessing options menu via pause and title screen * config: replace MSAA with AntiAliasing enum * options_menu: implemented info panel and text marquee (see TODOs) * Draw selection triangles. * Supersample fonts to 2K. * Implement options menu navigation. * Fix duplicate triangles when selecting options. * Draw scroll bar. * Adjust scroll bar padding. * Further scroll bar padding adjustments. * Draw outer container as an outline. * Improve marquee text scrolling. * CTitleMenu: fix options menu re-entering on A press whilst visible * Make procedural grid pattern more accurate. * Add enum & bool editing. * Update English localisation * Fix input state mapping. * options_menu: hide menu on Y hold * CHudPause: fix crash when opening options menu from village/lab * Implement float slider. * options_menu: round res scale description resolution * options_menu: use config callbacks after setting items * api: fix GameObject layout * camera_patches: implemented camera X/Y invert * options_menu: fix buffered A press selecting first option upon entry * config_locale: update description for Battle Music * config: added Allow Background Input option * options_menu: move ATOC option below Anti-Aliasing * options_menu: only draw header/footer fade in stages * Handle real-time modifications of some video config values. * Converge increments only when holding the left/right button. * Add sound effects to options menu. * Change some sounds used in options menu. * Give the final decide sound to bool toggling. * Add option select animation. * options_menu: only play slider sound between min/max range * Apply category select animation. * config: rename Controls category to Input * Implement intro transition animation for options menu. * audio_patches: implemented music volume * Implement FPS slider. * Prevent ImGui from displaying OS cursor. * Fade container brackets during intro transition. * player_patches: added penalty to Unleash Cancel * config_locale: update English localisation * player_patches: ensure Unleash gauge penalty doesn't dip into negatives * options_menu: fix being unable to press A at least once after opening the menu * CTitleMenu: added open/close sounds to the options menu * audio_patches: implemented Music and SE volume * api: update research * Implemented music volume attenuation for Windows 10+ * api: fix score offset * Add an interval between consecutive playbacks of the slider sound effect in fastIncrement mode * config: implemented enum descriptions * options_menu: fit thumbnail rect to grid, remove menu hide input * options_menu: fix description wrap width * camera_patches: fix FOV at narrow aspect ratios mobile gaming is back on the menu * options_menu: implemented greyed out options and localisation * options_menu: allow providing reasons for greyed out options * audio_patches: check if Windows version is supported * Update PowerRecomp submodule * api: more research * options_menu: forget selected item upon opening * options_menu: restrict XButtonHoming to title and world map * window: always hide mouse cursor The options menu doesn't accept mouse input, so there's not really any point to showing the cursor at all. * Animate category tab background from the center. * Fix clip rect in info panel not getting popped at all times. * Expose texture loader in "video.h". * config: use final names and descriptions, label options to be moved to exports * options_menu: implemented Voice Language (and some misc. clean-up) * Move Voice Language patch to resident_patches * config: added Aspect Ratio option (to be implemented) * options_menu: implemented Subtitles * Remove triple buffering from options menu, turn it to an enum. * window: hide mouse cursor on controller input for windowed mode * window: show window dimensions on title bar when resizing window * api: update research * Accept functions directly in GuestToHostFunction & add memory range asserts. * Add guest_stack_var, improve shared_ptr implementation. * Handle float/double arguments properly in GuestToHostFunction. * CHudPause_patches: allocate options strings on stack * api: update research * guest_stack_var: allow creation without constructing underlying type * memory: make assertions lenient towards nullptr * api: include guest_stack_var in SWA.inl * audio_patches: don't worry about it * Implemented achievement overlay (WIP) * Implemented achievements menu (WIP) * Clean-up, improved animation and layouts * options_menu: fix naming convention * achievements_overlay: implemented queue and hermite interpolation * achievements_menu: implemented animations and improved navigation * achievements_menu: improve animation accuracy * achievements_menu: added timestamps * achievement_data: added checksum and format verification * achievement_menu: improved outro animation * achievement_menu: added total unlocked achievements * achievement_menu: update sprite animation * Update resources submodule * Add installer wizard. * Skip drawing scanlines when height is 0. * Tweak install screen to better match the original * Added arrow circle to installer's header * Move icon header generation to resources submodule * Added missing animations and tweaked other ones for installer * Improve detection for DLC only mode. Add template for message prompts. * Add language picker. * window: update icon resources * Added file_to_c * Fixes to conversion. * Implemented message window * achievement_menu: use selection cursor texture * Update embedded resources * Implemented message window * Merge branch 'bin2c' into options-menu * Update embedded resources * Framework for max width for buttons. * Update embedded resources * Use textures for pause menu containers * audio_patches: check if Windows major version is >=10 Just in case. * installer_wizard: use integer outline for button text * Added arrow circle spinning animation during installation screen * achievement_menu: fix timestamp and scroll bar padding * achievement_overlay: fix achievement name padding * installer_wizard: fix arrow circle spinning animation misaligning * Add Scale and Origin to ImGui shaders. Change text to be squashed. * message_window: implemented mouse input * installer_wizard: implemented message windows * achievement_menu: start marquee before timestamp margin * Fix message box flow. * message_window: use pause container texture * Add extra condition for starting the installer. * message_window: only accept mouse click if option is selected * Implemented safer way to check if the game is loaded * Add queued update when using files pickers. * installer_wizard: implement localisation * installer_wizard: use enum for localisation * message_window: fix visibility persisting after window closes * Fix arrow circle animation and added pulse animation * Come back check space. * Implement ZSTD compression in file_to_c. * Add fade-in/out to installation icons and sleep after hitting 100% * Implement ImGui font atlas caching. * Controller navigation. * Implemented button guide * CTitleStateMenu: fix start button opening old options menu * Update resources submodule * imgui_snapshot: check if game is loaded before accessing XDBF * message_window: added button guide * options_menu: increase button guide side margins * video: disable imgui.ini creation * Use IM_DELETE for deleting the existing font atlas. * Remove redundant FlushViewport call. * Fix ImGui callbacks leaking memory. * Replace unique_ptr reference arguments with raw pointers. * Specialize description for resolution scale by reference. --------- Co-authored-by: Hyper <34012267+hyperbx@users.noreply.github.com> Co-authored-by: PTKay <jp_moura99@outlook.com> Co-authored-by: Dario <dariosamo@gmail.com>
306 lines
9.2 KiB
C++
306 lines
9.2 KiB
C++
#include "button_guide.h"
|
|
#include "imgui_utils.h"
|
|
#include <gpu/imgui_snapshot.h>
|
|
#include <gpu/video.h>
|
|
#include <decompressor.h>
|
|
#include <res/images/common/left_mouse_button.dds.h>
|
|
#include <res/images/common/mat_comon_x360_001.dds.h>
|
|
#include <res/images/common/start_back.dds.h>
|
|
|
|
constexpr float DEFAULT_SIDE_MARGINS = 379;
|
|
|
|
ImFont* g_fntNewRodin;
|
|
ImFont* g_fntNewRodinLQ;
|
|
|
|
std::unique_ptr<GuestTexture> g_upIcons;
|
|
std::unique_ptr<GuestTexture> g_upLMBIcon;
|
|
std::unique_ptr<GuestTexture> g_upStartBackIcons;
|
|
|
|
float g_sideMargins = DEFAULT_SIDE_MARGINS;
|
|
|
|
std::vector<Button> g_buttons;
|
|
|
|
std::unordered_map<EButtonIcon, float> g_iconWidths =
|
|
{
|
|
{ EButtonIcon::A, 40 },
|
|
{ EButtonIcon::B, 40 },
|
|
{ EButtonIcon::X, 40 },
|
|
{ EButtonIcon::Y, 40 },
|
|
{ EButtonIcon::LB, 70 },
|
|
{ EButtonIcon::RB, 70 },
|
|
{ EButtonIcon::LBRB, 70 },
|
|
{ EButtonIcon::LT, 42 },
|
|
{ EButtonIcon::RT, 42 },
|
|
{ EButtonIcon::LTRT, 42 },
|
|
{ EButtonIcon::Start, 40 },
|
|
{ EButtonIcon::Back, 40 },
|
|
{ EButtonIcon::LMB, 40 }
|
|
};
|
|
|
|
std::unordered_map<EButtonIcon, float> g_iconHeights =
|
|
{
|
|
{ EButtonIcon::A, 40 },
|
|
{ EButtonIcon::B, 40 },
|
|
{ EButtonIcon::X, 40 },
|
|
{ EButtonIcon::Y, 40 },
|
|
{ EButtonIcon::LB, 40 },
|
|
{ EButtonIcon::RB, 40 },
|
|
{ EButtonIcon::LBRB, 40 },
|
|
{ EButtonIcon::LT, 42 },
|
|
{ EButtonIcon::RT, 42 },
|
|
{ EButtonIcon::LTRT, 42 },
|
|
{ EButtonIcon::Start, 40 },
|
|
{ EButtonIcon::Back, 40 },
|
|
{ EButtonIcon::LMB, 40 }
|
|
};
|
|
|
|
std::tuple<std::tuple<ImVec2, ImVec2>, GuestTexture*> GetButtonIcon(EButtonIcon icon)
|
|
{
|
|
std::tuple<ImVec2, ImVec2> btn;
|
|
GuestTexture* texture;
|
|
|
|
switch (icon)
|
|
{
|
|
case EButtonIcon::A:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 0, 0, 40, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::B:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 40, 0, 40, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::X:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 80, 0, 40, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::Y:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 120, 0, 40, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::LB:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 166, 0, 70, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::RB:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 246, 0, 70, 40);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::LT:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 319, 0, 42, 42);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::RT:
|
|
btn = PIXELS_TO_UV_COORDS(512, 512, 359, 0, 42, 42);
|
|
texture = g_upIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::Start:
|
|
btn = PIXELS_TO_UV_COORDS(256, 256, 0, 0, 128, 128);
|
|
texture = g_upStartBackIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::Back:
|
|
btn = PIXELS_TO_UV_COORDS(256, 256, 0, 128, 128, 128);
|
|
texture = g_upStartBackIcons.get();
|
|
break;
|
|
|
|
case EButtonIcon::LMB:
|
|
btn = PIXELS_TO_UV_COORDS(128, 128, 0, 0, 128, 128);
|
|
texture = g_upLMBIcon.get();
|
|
break;
|
|
}
|
|
|
|
return std::make_tuple(btn, texture);
|
|
}
|
|
|
|
ImFont* GetFont(EFontQuality fontQuality)
|
|
{
|
|
return fontQuality == EFontQuality::Low
|
|
? g_fntNewRodinLQ
|
|
: g_fntNewRodin;
|
|
}
|
|
|
|
static void DrawGuide(float* offset, ImVec2 regionMin, ImVec2 regionMax, EButtonIcon icon,
|
|
EButtonAlignment alignment, ImVec2 iconMin, ImVec2 iconMax, EFontQuality fontQuality,
|
|
ImVec2 textSize, float fontSize, const char* text)
|
|
{
|
|
auto drawList = ImGui::GetForegroundDrawList();
|
|
auto _icon = icon;
|
|
auto iconWidth = Scale(g_iconWidths[icon]);
|
|
auto dualIconMarginX = Scale(25);
|
|
|
|
if (icon == EButtonIcon::LBRB)
|
|
{
|
|
_icon = EButtonIcon::LB;
|
|
}
|
|
else if (icon == EButtonIcon::LTRT)
|
|
{
|
|
_icon = EButtonIcon::LT;
|
|
}
|
|
else
|
|
{
|
|
dualIconMarginX = 0;
|
|
}
|
|
|
|
if (icon == EButtonIcon::LBRB || icon == EButtonIcon::LTRT)
|
|
{
|
|
iconMin = alignment == EButtonAlignment::Left
|
|
? ImVec2(/* X */ regionMin.x + *offset - dualIconMarginX * 3, /* Y */ iconMin.y)
|
|
: ImVec2(/* X */ regionMax.x - *offset - textSize.x - iconWidth, /* Y */ iconMin.y);
|
|
|
|
iconMax = alignment == EButtonAlignment::Left
|
|
? ImVec2(iconMin.x + iconWidth, iconMax.y)
|
|
: ImVec2(iconMin.x, iconMax.y);
|
|
}
|
|
|
|
auto btnIcon = GetButtonIcon(_icon);
|
|
drawList->AddImage(std::get<1>(btnIcon), iconMin, iconMax, GET_UV_COORDS(std::get<0>(btnIcon)));
|
|
|
|
auto textMarginX = alignment == EButtonAlignment::Left
|
|
? regionMin.x + *offset + dualIconMarginX
|
|
: regionMax.x - *offset - dualIconMarginX * 2;
|
|
|
|
DrawTextWithOutline<int>
|
|
(
|
|
GetFont(fontQuality),
|
|
fontSize,
|
|
{ /* X */ textMarginX, /* Y */ regionMin.y + Scale(8) },
|
|
IM_COL32(255, 255, 255, 255),
|
|
text,
|
|
2,
|
|
IM_COL32(0, 0, 0, 255)
|
|
);
|
|
|
|
if (icon == EButtonIcon::LBRB || icon == EButtonIcon::LTRT)
|
|
{
|
|
auto btnIcon = GetButtonIcon(icon == EButtonIcon::LBRB ? EButtonIcon::RB : EButtonIcon::RT);
|
|
|
|
auto dualIconMin = alignment == EButtonAlignment::Left
|
|
? ImVec2(/* X */ regionMin.x + *offset + textSize.x + dualIconMarginX * 2, /* Y */ iconMin.y)
|
|
: ImVec2(/* X */ regionMax.x - *offset + textSize.x - dualIconMarginX, /* Y */ iconMin.y);
|
|
|
|
auto dualIconMax = ImVec2(dualIconMin.x + iconWidth, iconMax.y);
|
|
|
|
drawList->AddImage(std::get<1>(btnIcon), dualIconMin, dualIconMax, GET_UV_COORDS(std::get<0>(btnIcon)));
|
|
|
|
*offset += dualIconMarginX + iconWidth;
|
|
}
|
|
}
|
|
|
|
void ButtonGuide::Init()
|
|
{
|
|
auto& io = ImGui::GetIO();
|
|
|
|
constexpr float FONT_SCALE = 2.0f;
|
|
|
|
g_fntNewRodin = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-M.otf", 24.0f * FONT_SCALE);
|
|
g_fntNewRodinLQ = ImFontAtlasSnapshot::GetFont("FOT-NewRodinPro-M.otf", 19.0f);
|
|
|
|
g_upIcons = LoadTexture(
|
|
decompressZstd(g_mat_comon_x360_001, g_mat_comon_x360_001_uncompressed_size).get(),
|
|
g_mat_comon_x360_001_uncompressed_size);
|
|
|
|
g_upLMBIcon = LoadTexture(
|
|
decompressZstd(g_left_mouse_button, g_left_mouse_button_uncompressed_size).get(),
|
|
g_left_mouse_button_uncompressed_size);
|
|
|
|
g_upStartBackIcons = LoadTexture(
|
|
decompressZstd(g_start_back, g_start_back_uncompressed_size).get(),
|
|
g_start_back_uncompressed_size);
|
|
}
|
|
|
|
void ButtonGuide::Draw()
|
|
{
|
|
if (!s_isVisible)
|
|
return;
|
|
|
|
auto drawList = ImGui::GetForegroundDrawList();
|
|
auto& res = ImGui::GetIO().DisplaySize;
|
|
|
|
auto regionMarginX = Scale(g_sideMargins);
|
|
auto regionHeight = Scale(102);
|
|
|
|
ImVec2 regionMin = { regionMarginX, res.y - regionHeight };
|
|
ImVec2 regionMax = { res.x - regionMarginX, res.y };
|
|
|
|
auto textMarginX = Scale(57);
|
|
auto textMarginY = Scale(8);
|
|
auto iconMarginX = Scale(4);
|
|
auto fontSize = Scale(22.5f);
|
|
|
|
auto offsetLeft = 0.0f;
|
|
auto offsetRight = 0.0f;
|
|
|
|
// Draw left aligned icons.
|
|
for (int i = 0; i < g_buttons.size(); i++)
|
|
{
|
|
auto& btn = g_buttons[i];
|
|
|
|
if (btn.Alignment != EButtonAlignment::Left)
|
|
continue;
|
|
|
|
if (btn.Visibility && !*btn.Visibility)
|
|
continue;
|
|
|
|
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
|
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
|
auto textSize = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, btn.Name.c_str());
|
|
|
|
if (i > 0)
|
|
offsetLeft += textSize.x + iconWidth + textMarginX;
|
|
|
|
ImVec2 iconMin = { regionMin.x + offsetLeft - iconWidth - iconMarginX, regionMin.y };
|
|
ImVec2 iconMax = { regionMin.x + offsetLeft - iconMarginX, regionMin.y + iconHeight };
|
|
|
|
DrawGuide(&offsetLeft, regionMin, regionMax, btn.Icon, btn.Alignment, iconMin, iconMax, btn.FontQuality, textSize, fontSize, btn.Name.c_str());
|
|
}
|
|
|
|
// Draw right aligned icons.
|
|
for (int i = g_buttons.size() - 1; i >= 0; i--)
|
|
{
|
|
auto& btn = g_buttons[i];
|
|
|
|
if (btn.Alignment != EButtonAlignment::Right)
|
|
continue;
|
|
|
|
if (btn.Visibility && !*btn.Visibility)
|
|
continue;
|
|
|
|
auto iconWidth = Scale(g_iconWidths[btn.Icon]);
|
|
auto iconHeight = Scale(g_iconHeights[btn.Icon]);
|
|
auto textSize = g_fntNewRodin->CalcTextSizeA(fontSize, FLT_MAX, 0, btn.Name.c_str());
|
|
|
|
if (i < g_buttons.size() - 1)
|
|
offsetRight += textSize.x + iconWidth + textMarginX;
|
|
|
|
ImVec2 iconMin = { regionMax.x - offsetRight - iconWidth - iconMarginX, regionMin.y };
|
|
ImVec2 iconMax = { regionMax.x - offsetRight - iconMarginX, regionMin.y + iconHeight };
|
|
|
|
DrawGuide(&offsetRight, regionMin, regionMax, btn.Icon, btn.Alignment, iconMin, iconMax, btn.FontQuality, textSize, fontSize, btn.Name.c_str());
|
|
}
|
|
}
|
|
|
|
void ButtonGuide::Open(const std::vector<Button> buttons)
|
|
{
|
|
s_isVisible = true;
|
|
g_sideMargins = DEFAULT_SIDE_MARGINS;
|
|
g_buttons = buttons;
|
|
}
|
|
|
|
void ButtonGuide::SetSideMargins(float width = DEFAULT_SIDE_MARGINS)
|
|
{
|
|
g_sideMargins = width;
|
|
}
|
|
|
|
void ButtonGuide::Close()
|
|
{
|
|
s_isVisible = false;
|
|
}
|