2022-03-21 21:52:44 -04:00
# include "SohImGuiImpl.h"
# include <iostream>
2022-04-03 15:47:24 -04:00
# include <map>
2022-03-21 21:52:44 -04:00
# include <utility>
2022-04-26 19:50:24 -04:00
# include <string>
# include <algorithm>
# include <vector>
2022-03-21 21:52:44 -04:00
# include "Archive.h"
# include "Environment.h"
# include "GameSettings.h"
# include "SohConsole.h"
# include "SohHooks.h"
# include "Lib/ImGui/imgui_internal.h"
# include "GlobalCtx2.h"
# include "ResourceMgr.h"
# include "TextureMod.h"
# include "Window.h"
# include "Cvar.h"
2022-05-11 13:35:03 -04:00
# include "GameOverlay.h"
2022-04-03 15:47:24 -04:00
# include "Texture.h"
2022-03-21 21:52:44 -04:00
# include "../Fast3D/gfx_pc.h"
# include "Lib/stb/stb_image.h"
# include "Lib/Fast3D/gfx_rendering_api.h"
2022-04-03 15:47:24 -04:00
# include "Lib/spdlog/include/spdlog/common.h"
2022-03-21 21:52:44 -04:00
# include "Utils/StringHelper.h"
# ifdef ENABLE_OPENGL
# include "Lib/ImGui/backends/imgui_impl_opengl3.h"
# include "Lib/ImGui/backends/imgui_impl_sdl.h"
# endif
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
# include "Lib/ImGui/backends/imgui_impl_dx11.h"
# include "Lib/ImGui/backends/imgui_impl_win32.h"
# include <Windows.h>
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler ( HWND hWnd , UINT msg , WPARAM wParam , LPARAM lParam ) ;
# endif
using namespace Ship ;
bool oldCursorState = true ;
2022-05-11 10:59:56 -04:00
# define EXPERIMENTAL() \
ImGui : : PushStyleColor ( ImGuiCol_Text , IM_COL32 ( 255 , 50 , 50 , 255 ) ) ; \
ImGui : : Text ( " Experimental " ) ; \
ImGui : : PopStyleColor ( ) ; \
ImGui : : Separator ( ) ;
2022-03-21 21:52:44 -04:00
# define TOGGLE_BTN ImGuiKey_F1
# define HOOK(b) if(b) needs_save = true;
OSContPad * pads ;
std : : map < std : : string , GameAsset * > DefaultAssets ;
namespace SohImGui {
WindowImpl impl ;
ImGuiIO * io ;
Console * console = new Console ;
2022-05-11 13:35:03 -04:00
GameOverlay * overlay = new GameOverlay ;
2022-03-21 21:52:44 -04:00
bool p_open = false ;
bool needs_save = false ;
2022-05-11 13:35:03 -04:00
std : : vector < const char * > CustomTexts ;
2022-05-02 18:24:12 -04:00
int SelectedLanguage = CVar_GetS32 ( " gLanguages " , 0 ) ; //Default Language to 0=English 1=German 2=French
2022-04-26 18:33:18 -04:00
float kokiri_col [ 3 ] = { 0.118f , 0.41f , 0.106f } ;
float goron_col [ 3 ] = { 0.392f , 0.078f , 0.0f } ;
float zora_col [ 3 ] = { 0.0f , 0.235f , 0.392f } ;
float navi_idle_i_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_idle_o_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_npc_i_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_npc_o_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_enemy_i_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_enemy_o_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_prop_i_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
float navi_prop_o_col [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
2022-03-21 21:52:44 -04:00
2022-05-11 10:59:56 -04:00
const char * filters [ 3 ] = {
" Three-Point " ,
" Linear " ,
" None "
} ;
2022-04-03 15:47:24 -04:00
std : : map < std : : string , std : : vector < std : : string > > windowCategories ;
std : : map < std : : string , CustomWindow > customWindows ;
2022-03-21 21:52:44 -04:00
void ImGuiWMInit ( ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplSDL2_InitForOpenGL ( static_cast < SDL_Window * > ( impl . sdl . window ) , impl . sdl . context ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplWin32_Init ( impl . dx11 . window ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
2022-05-11 10:59:56 -04:00
2022-04-29 11:49:28 -04:00
// OTRTODO: This gameplay specific stuff should not be in libultraship. This needs to be moved to soh and use sTunicColors
kokiri_col [ 0 ] = 30 / 255.0f ;
kokiri_col [ 1 ] = 105 / 255.0f ;
kokiri_col [ 2 ] = 27 / 255.0f ;
goron_col [ 0 ] = 100 / 255.0f ;
goron_col [ 1 ] = 20 / 255.0f ;
goron_col [ 2 ] = 0 ;
2022-05-11 10:59:56 -04:00
2022-04-29 11:49:28 -04:00
zora_col [ 0 ] = 0 ;
zora_col [ 1 ] = 60 / 255.0f ;
zora_col [ 2 ] = 100 / 255.0f ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_idle_i_col [ 0 ] = 0 ;
navi_idle_i_col [ 1 ] = 0 ;
navi_idle_i_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_idle_o_col [ 0 ] = 0 ;
navi_idle_o_col [ 1 ] = 0 ;
navi_idle_o_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_npc_i_col [ 0 ] = 0 ;
navi_npc_i_col [ 1 ] = 0 ;
navi_npc_i_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_npc_o_col [ 0 ] = 0 ;
navi_npc_o_col [ 1 ] = 0 ;
navi_npc_o_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_enemy_i_col [ 0 ] = 0 ;
navi_enemy_i_col [ 1 ] = 0 ;
navi_enemy_i_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_enemy_o_col [ 0 ] = 0 ;
navi_enemy_o_col [ 1 ] = 0 ;
navi_enemy_o_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_prop_i_col [ 0 ] = 0 ;
navi_prop_i_col [ 1 ] = 0 ;
navi_prop_i_col [ 2 ] = 0 ;
2022-04-26 18:33:18 -04:00
2022-04-29 11:49:28 -04:00
navi_prop_o_col [ 0 ] = 0 ;
navi_prop_o_col [ 1 ] = 0 ;
navi_prop_o_col [ 2 ] = 0 ;
2022-03-21 21:52:44 -04:00
}
void ImGuiBackendInit ( ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplOpenGL3_Init ( " #version 120 " ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplDX11_Init ( static_cast < ID3D11Device * > ( impl . dx11 . device ) , static_cast < ID3D11DeviceContext * > ( impl . dx11 . device_context ) ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
}
void ImGuiProcessEvent ( EventImpl event ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplSDL2_ProcessEvent ( static_cast < const SDL_Event * > ( event . sdl . event ) ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplWin32_WndProcHandler ( static_cast < HWND > ( event . win32 . handle ) , event . win32 . msg , event . win32 . wparam , event . win32 . lparam ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
}
void ImGuiWMNewFrame ( ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplSDL2_NewFrame ( static_cast < SDL_Window * > ( impl . sdl . window ) ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplWin32_NewFrame ( ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
}
void ImGuiBackendNewFrame ( ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplOpenGL3_NewFrame ( ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplDX11_NewFrame ( ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
}
void ImGuiRenderDrawData ( ImDrawData * data ) {
switch ( impl . backend ) {
case Backend : : SDL :
ImGui_ImplOpenGL3_RenderDrawData ( data ) ;
break ;
2022-05-11 13:18:24 -04:00
# if defined(ENABLE_DX11) || defined(ENABLE_DX12)
2022-03-21 21:52:44 -04:00
case Backend : : DX11 :
ImGui_ImplDX11_RenderDrawData ( data ) ;
break ;
2022-05-11 13:18:24 -04:00
# endif
default :
break ;
2022-03-21 21:52:44 -04:00
}
}
bool UseViewports ( ) {
switch ( impl . backend ) {
case Backend : : DX11 :
return true ;
2022-05-11 13:18:24 -04:00
default :
return false ;
2022-03-21 21:52:44 -04:00
}
}
2022-05-11 13:18:24 -04:00
void ShowCursor ( bool hide , Dialogues d ) {
2022-03-21 21:52:44 -04:00
if ( d = = Dialogues : : dLoadSettings ) {
GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) - > ShowCursor ( hide ) ;
return ;
}
2022-05-11 10:59:56 -04:00
if ( d = = Dialogues : : dConsole & & CVar_GetS32 ( " gOpenMenuBar " , 0 ) ) {
2022-03-21 21:52:44 -04:00
return ;
}
if ( ! GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) - > IsFullscreen ( ) ) {
oldCursorState = false ;
return ;
}
if ( oldCursorState ! = hide ) {
oldCursorState = hide ;
GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) - > ShowCursor ( hide ) ;
}
}
2022-04-03 15:47:24 -04:00
void LoadTexture ( const std : : string & name , const std : : string & path ) {
2022-03-21 21:52:44 -04:00
GfxRenderingAPI * api = gfx_get_current_rendering_api ( ) ;
2022-05-12 10:26:32 -04:00
const auto res = GlobalCtx2 : : GetInstance ( ) - > GetResourceManager ( ) - > LoadFile ( path ) ;
2022-03-21 21:52:44 -04:00
const auto asset = new GameAsset { api - > new_texture ( ) } ;
uint8_t * img_data = stbi_load_from_memory ( reinterpret_cast < const stbi_uc * > ( res - > buffer . get ( ) ) , res - > dwBufferSize , & asset - > width , & asset - > height , nullptr , 4 ) ;
if ( img_data = = nullptr ) {
std : : cout < < " Found error: " < < stbi_failure_reason ( ) < < std : : endl ;
return ;
}
api - > select_texture ( 0 , asset - > textureId ) ;
api - > set_sampler_parameters ( 0 , false , 0 , 0 ) ;
api - > upload_texture ( img_data , asset - > width , asset - > height ) ;
DefaultAssets [ name ] = asset ;
stbi_image_free ( img_data ) ;
}
2022-04-17 11:24:43 -04:00
void LoadResource ( const std : : string & name , const std : : string & path , const ImVec4 & tint ) {
2022-04-03 15:47:24 -04:00
GfxRenderingAPI * api = gfx_get_current_rendering_api ( ) ;
2022-05-12 10:28:25 -04:00
const auto res = static_cast < Ship : : Texture * > ( GlobalCtx2 : : GetInstance ( ) - > GetResourceManager ( ) - > LoadResource ( path ) . get ( ) ) ;
2022-04-03 15:47:24 -04:00
2022-04-17 11:24:43 -04:00
std : : vector < uint8_t > texBuffer ;
texBuffer . reserve ( res - > width * res - > height * 4 ) ;
switch ( res - > texType ) {
case Ship : : TextureType : : RGBA32bpp :
texBuffer . assign ( res - > imageData , res - > imageData + ( res - > width * res - > height * 4 ) ) ;
break ;
case Ship : : TextureType : : GrayscaleAlpha8bpp :
for ( int32_t i = 0 ; i < res - > width * res - > height ; i + + ) {
uint8_t ia = res - > imageData [ i ] ;
uint8_t color = ( ( ia > > 4 ) & 0xF ) * 255 / 15 ;
uint8_t alpha = ( ia & 0xF ) * 255 / 15 ;
texBuffer . push_back ( color ) ;
texBuffer . push_back ( color ) ;
texBuffer . push_back ( color ) ;
texBuffer . push_back ( alpha ) ;
}
break ;
default :
2022-04-03 15:47:24 -04:00
// TODO convert other image types
SPDLOG_WARN ( " SohImGui::LoadResource: Attempting to load unsupporting image type %s " , path . c_str ( ) ) ;
return ;
}
2022-04-17 11:24:43 -04:00
for ( size_t pixel = 0 ; pixel < texBuffer . size ( ) / 4 ; pixel + + ) {
texBuffer [ pixel * 4 + 0 ] * = tint . x ;
texBuffer [ pixel * 4 + 1 ] * = tint . y ;
texBuffer [ pixel * 4 + 2 ] * = tint . z ;
texBuffer [ pixel * 4 + 3 ] * = tint . w ;
}
2022-04-03 15:47:24 -04:00
const auto asset = new GameAsset { api - > new_texture ( ) } ;
api - > select_texture ( 0 , asset - > textureId ) ;
api - > set_sampler_parameters ( 0 , false , 0 , 0 ) ;
2022-04-17 11:24:43 -04:00
api - > upload_texture ( texBuffer . data ( ) , res - > width , res - > height ) ;
2022-04-03 15:47:24 -04:00
DefaultAssets [ name ] = asset ;
}
2022-03-21 21:52:44 -04:00
void Init ( WindowImpl window_impl ) {
Game : : LoadSettings ( ) ;
2022-05-11 10:59:56 -04:00
impl = window_impl ;
2022-03-21 21:52:44 -04:00
ImGuiContext * ctx = ImGui : : CreateContext ( ) ;
ImGui : : SetCurrentContext ( ctx ) ;
io = & ImGui : : GetIO ( ) ;
io - > ConfigFlags | = ImGuiConfigFlags_DockingEnable ;
2022-05-11 13:35:03 -04:00
io - > Fonts - > AddFontDefault ( ) ;
2022-03-21 21:52:44 -04:00
if ( UseViewports ( ) ) {
io - > ConfigFlags | = ImGuiConfigFlags_ViewportsEnable ;
}
console - > Init ( ) ;
2022-05-11 13:35:03 -04:00
overlay - > Init ( ) ;
2022-03-21 21:52:44 -04:00
ImGuiWMInit ( ) ;
ImGuiBackendInit ( ) ;
ModInternal : : registerHookListener ( { GFX_INIT , [ ] ( const HookEvent ev ) {
if ( GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) - > IsFullscreen ( ) )
2022-05-11 10:59:56 -04:00
ShowCursor ( CVar_GetS32 ( " gOpenMenuBar " , 0 ) , Dialogues : : dLoadSettings ) ;
2022-03-21 21:52:44 -04:00
LoadTexture ( " Game_Icon " , " assets/ship_of_harkinian/icons/gSohIcon.png " ) ;
LoadTexture ( " A-Btn " , " assets/ship_of_harkinian/buttons/ABtn.png " ) ;
LoadTexture ( " B-Btn " , " assets/ship_of_harkinian/buttons/BBtn.png " ) ;
LoadTexture ( " L-Btn " , " assets/ship_of_harkinian/buttons/LBtn.png " ) ;
LoadTexture ( " R-Btn " , " assets/ship_of_harkinian/buttons/RBtn.png " ) ;
LoadTexture ( " Z-Btn " , " assets/ship_of_harkinian/buttons/ZBtn.png " ) ;
LoadTexture ( " Start-Btn " , " assets/ship_of_harkinian/buttons/StartBtn.png " ) ;
LoadTexture ( " C-Left " , " assets/ship_of_harkinian/buttons/CLeft.png " ) ;
LoadTexture ( " C-Right " , " assets/ship_of_harkinian/buttons/CRight.png " ) ;
LoadTexture ( " C-Up " , " assets/ship_of_harkinian/buttons/CUp.png " ) ;
LoadTexture ( " C-Down " , " assets/ship_of_harkinian/buttons/CDown.png " ) ;
} } ) ;
2022-05-01 13:23:40 -04:00
for ( const auto & [ i , controllers ] : Ship : : Window : : Controllers )
{
CVar_SetFloat ( StringHelper : : Sprintf ( " gCont%i_GyroDriftX " , i ) . c_str ( ) , 0 ) ;
CVar_SetFloat ( StringHelper : : Sprintf ( " gCont%i_GyroDriftY " , i ) . c_str ( ) , 0 ) ;
needs_save = true ;
}
2022-03-21 21:52:44 -04:00
ModInternal : : registerHookListener ( { CONTROLLER_READ , [ ] ( const HookEvent ev ) {
pads = static_cast < OSContPad * > ( ev - > baseArgs [ " cont_pad " ] ) ;
2022-05-15 15:51:58 -04:00
} } ) ;
2022-03-21 21:52:44 -04:00
Game : : InitSettings ( ) ;
}
void Update ( EventImpl event ) {
if ( needs_save ) {
Game : : SaveSettings ( ) ;
needs_save = false ;
}
ImGuiProcessEvent ( event ) ;
}
2022-04-03 15:47:24 -04:00
# define BindButton(btn, status) ImGui::Image(GetTextureByID(DefaultAssets[btn]->textureId), ImVec2(16.0f * scale, 16.0f * scale), ImVec2(0, 0), ImVec2(1.0f, 1.0f), ImVec4(255, 255, 255, (status) ? 255 : 0));
2022-03-21 21:52:44 -04:00
2022-05-11 10:59:56 -04:00
void BindAudioSlider ( const char * name , const char * key , float defaultValue , SeqPlayers playerId )
2022-04-25 02:27:24 -04:00
{
float value = CVar_GetFloat ( key , defaultValue ) ;
ImGui : : Text ( name , static_cast < int > ( 100 * value ) ) ;
if ( ImGui : : SliderFloat ( ( std : : string ( " ## " ) + key ) . c_str ( ) , & value , 0.0f , 1.0f , " " ) ) {
const float volume = floorf ( value * 100 ) / 100 ;
2022-04-06 20:42:23 -04:00
CVar_SetFloat ( key , volume ) ;
2022-03-21 21:52:44 -04:00
needs_save = true ;
Game : : SetSeqPlayerVolume ( playerId , volume ) ;
}
}
2022-05-19 14:00:36 -04:00
void EnhancementCombobox ( const char * name , const char * ComboArray [ ] , s16 FirstTimeValue = - 1 ) {
2022-05-19 13:48:49 -04:00
if ( FirstTimeValue < 0 ) {
FirstTimeValue = 0 ;
}
2022-05-19 14:00:36 -04:00
s16 selected = CVar_GetS32 ( name , FirstTimeValue ) ;
2022-05-19 13:48:49 -04:00
s16 DefaultValue = selected ;
2022-05-19 14:00:36 -04:00
if ( ImGui : : BeginCombo ( " ##name " , ComboArray [ DefaultValue ] ) ) {
2022-05-19 20:42:53 -04:00
s16 ComboxSize = sizeof ( & ComboArray ) ;
2022-05-19 14:00:36 -04:00
for ( uint8_t i = 0 ; i < = ComboxSize ; i + + ) {
2022-05-19 20:42:53 -04:00
if ( strlen ( ComboArray [ i ] ) > 1 ) {
if ( ImGui : : Selectable ( ComboArray [ i ] , i = = selected ) ) {
2022-05-19 14:00:36 -04:00
CVar_SetS32 ( name , i ) ;
2022-05-19 13:48:49 -04:00
selected = i ;
needs_save = true ;
2022-05-19 20:42:53 -04:00
}
2022-05-19 13:48:49 -04:00
}
}
ImGui : : EndCombo ( ) ;
}
}
2022-05-02 18:24:12 -04:00
void EnhancementRadioButton ( std : : string text , std : : string cvarName , int id ) {
/*Usage :
EnhancementRadioButton ( " My Visible Name " , " gMyCVarName " , MyID ) ;
First arg is the visible name of the Radio button
Second is the cvar name where MyID will be saved .
Note : the CVar name should be the same to each Buddies .
Example :
EnhancementRadioButton ( " English " , " gLanguages " , 0 ) ;
EnhancementRadioButton ( " German " , " gLanguages " , 1 ) ;
EnhancementRadioButton ( " French " , " gLanguages " , 2 ) ;
*/
int val = CVar_GetS32 ( cvarName . c_str ( ) , 0 ) ;
2022-05-15 15:51:58 -04:00
if ( ImGui : : RadioButton ( text . c_str ( ) , id = = val ) ) {
2022-05-02 18:24:12 -04:00
CVar_SetS32 ( cvarName . c_str ( ) , ( int ) id ) ;
needs_save = true ;
}
}
2022-04-25 02:27:24 -04:00
void EnhancementCheckbox ( std : : string text , std : : string cvarName )
{
bool val = ( bool ) CVar_GetS32 ( cvarName . c_str ( ) , 0 ) ;
if ( ImGui : : Checkbox ( text . c_str ( ) , & val ) ) {
CVar_SetS32 ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
}
2022-05-12 09:05:54 -04:00
void EnhancementButton ( std : : string text , std : : string cvarName )
{
bool val = ( bool ) CVar_GetS32 ( cvarName . c_str ( ) , 0 ) ;
if ( ImGui : : Button ( text . c_str ( ) ) ) {
CVar_SetS32 ( cvarName . c_str ( ) , ! val ) ;
needs_save = true ;
}
}
2022-04-25 02:27:24 -04:00
void EnhancementSliderInt ( std : : string text , std : : string id , std : : string cvarName , int min , int max , std : : string format )
{
int val = CVar_GetS32 ( cvarName . c_str ( ) , 0 ) ;
ImGui : : Text ( text . c_str ( ) , val ) ;
2022-05-11 10:59:56 -04:00
if ( ImGui : : SliderInt ( id . c_str ( ) , & val , min , max , format . c_str ( ) ) )
2022-04-25 02:27:24 -04:00
{
CVar_SetS32 ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
if ( val < min )
{
val = min ;
CVar_SetS32 ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
if ( val > max )
{
val = max ;
CVar_SetS32 ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
}
2022-04-29 11:49:28 -04:00
void EnhancementSliderFloat ( std : : string text , std : : string id , std : : string cvarName , float min , float max , std : : string format , float defaultValue , bool isPercentage )
2022-04-25 02:27:24 -04:00
{
float val = CVar_GetFloat ( cvarName . c_str ( ) , defaultValue ) ;
2022-04-29 11:49:28 -04:00
if ( ! isPercentage )
ImGui : : Text ( text . c_str ( ) , val ) ;
else
ImGui : : Text ( text . c_str ( ) , static_cast < int > ( 100 * val ) ) ;
2022-04-25 02:27:24 -04:00
if ( ImGui : : SliderFloat ( id . c_str ( ) , & val , min , max , format . c_str ( ) ) )
{
CVar_SetFloat ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
if ( val < min )
{
val = min ;
CVar_SetFloat ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
if ( val > max )
{
val = max ;
CVar_SetFloat ( cvarName . c_str ( ) , val ) ;
needs_save = true ;
}
}
2022-04-29 11:49:28 -04:00
void EnhancementColor3 ( std : : string text , std : : string cvarName , float defaultColors [ 3 ] )
{
int r = CVar_GetS32 ( ( cvarName + " _Red " ) . c_str ( ) , ( defaultColors [ 0 ] * 255.0f ) ) ;
int g = CVar_GetS32 ( ( cvarName + " _Green " ) . c_str ( ) , ( defaultColors [ 1 ] * 255.0f ) ) ;
int b = CVar_GetS32 ( ( cvarName + " _Blue " ) . c_str ( ) , ( defaultColors [ 2 ] * 255.0f ) ) ;
float colors [ 3 ] ;
colors [ 0 ] = r / 255.0f ;
colors [ 1 ] = g / 255.0f ;
colors [ 2 ] = b / 255.0f ;
{
2022-05-11 10:59:56 -04:00
if ( ImGui : : ColorEdit3 ( text . c_str ( ) , colors ) )
2022-04-29 11:49:28 -04:00
{
CVar_SetS32 ( ( cvarName + " _Red " ) . c_str ( ) , ( int ) ( colors [ 0 ] * 255 ) ) ;
CVar_SetS32 ( ( cvarName + " _Green " ) . c_str ( ) , ( int ) ( colors [ 1 ] * 255 ) ) ;
CVar_SetS32 ( ( cvarName + " _Blue " ) . c_str ( ) , ( int ) ( colors [ 2 ] * 255 ) ) ;
needs_save = true ;
}
}
}
2022-05-15 15:51:58 -04:00
void Tooltip ( std : : string text ) {
2022-05-14 15:08:17 -04:00
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " %s " , text . c_str ( ) ) ;
}
2022-05-15 15:51:58 -04:00
void DrawMainMenuAndCalculateGameSize ( ) {
2022-03-21 21:52:44 -04:00
console - > Update ( ) ;
ImGuiBackendNewFrame ( ) ;
ImGuiWMNewFrame ( ) ;
ImGui : : NewFrame ( ) ;
const std : : shared_ptr < Window > wnd = GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) ;
2022-04-18 05:37:47 -04:00
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoBackground |
2022-03-21 21:52:44 -04:00
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoResize ;
2022-05-11 10:59:56 -04:00
if ( CVar_GetS32 ( " gOpenMenuBar " , 0 ) ) window_flags | = ImGuiWindowFlags_MenuBar ;
2022-03-21 21:52:44 -04:00
const ImGuiViewport * viewport = ImGui : : GetMainViewport ( ) ;
ImGui : : SetNextWindowPos ( viewport - > WorkPos ) ;
ImGui : : SetNextWindowSize ( ImVec2 ( wnd - > GetCurrentWidth ( ) , wnd - > GetCurrentHeight ( ) ) ) ;
ImGui : : SetNextWindowViewport ( viewport - > ID ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowPadding , ImVec2 ( 0.0f , 0.0f ) ) ;
2022-04-18 05:37:47 -04:00
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowBorderSize , 0.0f ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildBorderSize , 0.0f ) ;
2022-03-21 21:52:44 -04:00
ImGui : : Begin ( " Main - Deck " , nullptr , window_flags ) ;
2022-04-18 05:37:47 -04:00
ImGui : : PopStyleVar ( 3 ) ;
ImVec2 top_left_pos = ImGui : : GetWindowPos ( ) ;
2022-03-21 21:52:44 -04:00
const ImGuiID dockId = ImGui : : GetID ( " main_dock " ) ;
if ( ! ImGui : : DockBuilderGetNode ( dockId ) ) {
ImGui : : DockBuilderRemoveNode ( dockId ) ;
ImGui : : DockBuilderAddNode ( dockId , ImGuiDockNodeFlags_NoTabBar ) ;
ImGui : : DockBuilderDockWindow ( " OoT Master Quest " , dockId ) ;
ImGui : : DockBuilderFinish ( dockId ) ;
}
ImGui : : DockSpace ( dockId , ImVec2 ( 0.0f , 0.0f ) , ImGuiDockNodeFlags_None ) ;
if ( ImGui : : IsKeyPressed ( TOGGLE_BTN ) ) {
2022-05-11 10:59:56 -04:00
bool menu_bar = CVar_GetS32 ( " gOpenMenuBar " , 0 ) ;
CVar_SetS32 ( " gOpenMenuBar " , ! menu_bar ) ;
2022-03-21 21:52:44 -04:00
needs_save = true ;
2022-05-11 10:59:56 -04:00
GlobalCtx2 : : GetInstance ( ) - > GetWindow ( ) - > dwMenubar = menu_bar ;
ShowCursor ( menu_bar , Dialogues : : dMenubar ) ;
2022-03-21 21:52:44 -04:00
}
if ( ImGui : : BeginMenuBar ( ) ) {
if ( DefaultAssets . contains ( " Game_Icon " ) ) {
ImGui : : SetCursorPos ( ImVec2 ( 5 , 2.5f ) ) ;
2022-04-03 15:47:24 -04:00
ImGui : : Image ( GetTextureByID ( DefaultAssets [ " Game_Icon " ] - > textureId ) , ImVec2 ( 16.0f , 16.0f ) ) ;
2022-03-21 21:52:44 -04:00
ImGui : : SameLine ( ) ;
ImGui : : SetCursorPos ( ImVec2 ( 25 , 0 ) ) ;
}
ImGui : : Text ( " Shipwright " ) ;
ImGui : : Separator ( ) ;
if ( ImGui : : BeginMenu ( " Audio " ) ) {
2022-04-29 11:49:28 -04:00
EnhancementSliderFloat ( " Master Volume: %d %% " , " ##Master_Vol " , " gGameMasterVolume " , 0.0f , 1.0f , " " , 1.0f , true ) ;
2022-03-21 21:52:44 -04:00
2022-04-25 02:27:24 -04:00
BindAudioSlider ( " Main Music Volume: %d %% " , " gMainMusicVolume " , 1.0f , SEQ_BGM_MAIN ) ;
BindAudioSlider ( " Sub Music Volume: %d %% " , " gSubMusicVolume " , 1.0f , SEQ_BGM_SUB ) ;
BindAudioSlider ( " Sound Effects Volume: %d %% " , " gSFXMusicVolume " , 1.0f , SEQ_SFX ) ;
BindAudioSlider ( " Fanfare Volume: %d %% " , " gFanfareVolume " , 1.0f , SEQ_FANFARE ) ;
2022-03-21 21:52:44 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-29 11:49:28 -04:00
if ( ImGui : : BeginMenu ( " Controller " ) )
2022-04-25 02:27:24 -04:00
{
2022-04-29 11:49:28 -04:00
for ( const auto & [ i , controllers ] : Ship : : Window : : Controllers )
{
bool hasPad = std : : find_if ( controllers . begin ( ) , controllers . end ( ) , [ ] ( const auto & c ) {
return c - > HasPadConf ( ) & & c - > Connected ( ) ;
} ) ! = controllers . end ( ) ;
2022-03-29 22:23:02 -04:00
2022-04-29 11:49:28 -04:00
if ( ! hasPad ) continue ;
2022-03-29 22:23:02 -04:00
2022-04-29 11:49:28 -04:00
auto menuLabel = " Controller " + std : : to_string ( i + 1 ) ;
if ( ImGui : : BeginMenu ( menuLabel . c_str ( ) ) )
{
EnhancementSliderFloat ( " Gyro Sensitivity: %d %% " , " ##GYROSCOPE " , StringHelper : : Sprintf ( " gCont%i_GyroSensitivity " , i ) , 0.0f , 1.0f , " " , 1.0f , true ) ;
if ( ImGui : : Button ( " Recalibrate Gyro " ) )
{
2022-05-01 13:23:40 -04:00
CVar_SetFloat ( StringHelper : : Sprintf ( " gCont%i_GyroDriftX " , i ) . c_str ( ) , 0 ) ;
CVar_SetFloat ( StringHelper : : Sprintf ( " gCont%i_GyroDriftY " , i ) . c_str ( ) , 0 ) ;
2022-04-29 11:49:28 -04:00
needs_save = true ;
}
ImGui : : Separator ( ) ;
EnhancementSliderFloat ( " Rumble Strength: %d %% " , " ##RUMBLE " , StringHelper : : Sprintf ( " gCont%i_RumbleStrength " , i ) , 0.0f , 1.0f , " " , 1.0f , true ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : Separator ( ) ;
2022-03-21 21:52:44 -04:00
}
2022-04-29 11:49:28 -04:00
EnhancementCheckbox ( " Show Inputs " , " gInputEnabled " ) ;
2022-05-14 15:08:17 -04:00
Tooltip ( " Shows currently pressed inputs on the bottom right of the screen " ) ;
2022-04-29 11:49:28 -04:00
EnhancementCheckbox ( " Rumble Enabled " , " gRumbleEnabled " ) ;
EnhancementSliderFloat ( " Input Scale: %.1f " , " ##Input " , " gInputScale " , 1.0f , 3.0f , " " , 1.0f , false ) ;
2022-05-14 15:08:17 -04:00
Tooltip ( " Sets the on screen size of the displayed inputs from Show Inputs " ) ;
2022-03-21 21:52:44 -04:00
2022-04-10 18:19:26 -04:00
ImGui : : Separator ( ) ;
2022-05-14 15:08:17 -04:00
EnhancementCheckbox ( " D-pad Support on Pause and File Select " , " gDpadPauseName " ) ;
EnhancementCheckbox ( " D-pad Support in Ocarina and Text Choice " , " gDpadOcarinaText " ) ;
EnhancementCheckbox ( " D-pad Support for Browsing Shop Items " , " gDpadShop " ) ;
2022-04-12 21:38:08 -04:00
2022-03-21 21:52:44 -04:00
ImGui : : EndMenu ( ) ;
}
2022-05-11 10:59:56 -04:00
if ( ImGui : : BeginMenu ( " Graphics " ) )
2022-04-29 11:49:28 -04:00
{
2022-05-11 10:59:56 -04:00
EnhancementSliderInt ( " Internal Resolution: %dx " , " ##IMul " , " gInternalResolution " , 1 , 8 , " " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Increases the render resolution of the game, up to 8x your output resolution, \n as a more intensive but effective form of anti-aliasing " ) ;
2022-05-11 10:59:56 -04:00
gfx_current_dimensions . internal_mul = CVar_GetS32 ( " gInternalResolution " , 1 ) ;
EnhancementSliderInt ( " MSAA: %d " , " ##IMSAA " , " gMSAAValue " , 1 , 8 , " " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Activates anti-aliasing when above 1, up to 8x for 8 samples for every pixel " ) ;
2022-05-11 10:59:56 -04:00
gfx_msaa_level = CVar_GetS32 ( " gMSAAValue " , 1 ) ;
EXPERIMENTAL ( ) ;
ImGui : : Text ( " Texture Filter (Needs reload) " ) ;
2022-05-19 13:48:49 -04:00
EnhancementCombobox ( " gTextureFilter " , filters ) ;
2022-05-11 10:59:56 -04:00
GfxRenderingAPI * gapi = gfx_get_current_rendering_api ( ) ;
2022-05-19 13:48:49 -04:00
gapi - > set_texture_filter ( ( FilteringMode ) CVar_GetS32 ( " gTextureFilter " , 0 ) ) ;
2022-05-11 13:35:03 -04:00
overlay - > DrawSettings ( ) ;
2022-05-11 10:59:56 -04:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Languages " ) ) {
EnhancementRadioButton ( " English " , " gLanguages " , 0 ) ;
EnhancementRadioButton ( " German " , " gLanguages " , 1 ) ;
EnhancementRadioButton ( " French " , " gLanguages " , 2 ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Enhancements " ) )
{
2022-05-15 15:51:58 -04:00
if ( ImGui : : BeginMenu ( " Gameplay " ) )
{
EnhancementSliderInt ( " Text Speed: %dx " , " ##TEXTSPEED " , " gTextSpeed " , 1 , 5 , " " ) ;
EnhancementSliderInt ( " King Zora Speed: %dx " , " ##WEEPSPEED " , " gMweepSpeed " , 1 , 5 , " " ) ;
EnhancementCheckbox ( " Skip Text " , " gSkipText " ) ;
Tooltip ( " Holding down B skips text " ) ;
EnhancementCheckbox ( " Mute Low HP Alarm " , " gLowHpAlarm " ) ;
Tooltip ( " Disable the low HP beeping sound " ) ;
EnhancementCheckbox ( " Minimal UI " , " gMinimalUI " ) ;
Tooltip ( " Hides most of the UI when not needed " ) ;
EnhancementCheckbox ( " Visual Stone of Agony " , " gVisualAgony " ) ;
Tooltip ( " Displays an icon and plays a sound when Stone of Agony should be activated, for those without rumble " ) ;
EnhancementCheckbox ( " Faster Block Push " , " gFasterBlockPush " ) ;
EnhancementCheckbox ( " Assignable Tunics and Boots " , " gAssignableTunicsAndBoots " ) ;
Tooltip ( " Allows equiping the tunic and boots to c-buttons " ) ;
EnhancementCheckbox ( " MM Bunny Hood " , " gMMBunnyHood " ) ;
Tooltip ( " Wearing the Bunny Hood grants a speed increase like in Majora's Mask " ) ;
2022-03-21 21:52:44 -04:00
2022-05-15 15:51:58 -04:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Graphics " ) )
{
EnhancementCheckbox ( " N64 Mode " , " gN64Mode " ) ;
Tooltip ( " Sets aspect ratio to 4:3 and lowers resolution to 240p, the N64's native resolution " ) ;
EnhancementCheckbox ( " Animated Link in Pause Menu " , " gPauseLiveLink " ) ;
EnhancementCheckbox ( " Enable 3D Dropped items " , " gNewDrops " ) ;
EnhancementCheckbox ( " Dynamic Wallet Icon " , " gDynamicWalletIcon " ) ;
Tooltip ( " Changes the rupee in the wallet icon to match the wallet size you currently have " ) ;
EnhancementCheckbox ( " Always show dungeon entrances " , " gAlwaysShowDungeonMinimapIcon " ) ;
Tooltip ( " Always shows dungeon entrance icons on the minimap " ) ;
2022-03-21 21:52:44 -04:00
2022-05-15 15:51:58 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-24 10:50:41 -04:00
2022-05-15 15:51:58 -04:00
if ( ImGui : : BeginMenu ( " Fixes " ) )
{
EnhancementCheckbox ( " Fix L&R Pause menu " , " gUniformLR " ) ;
Tooltip ( " Makes the L and R buttons in the pause menu the same color " ) ;
EnhancementCheckbox ( " Fix Dungeon entrances " , " gFixDungeonMinimapIcon " ) ;
Tooltip ( " Show dungeon entrances icon only when it should be " ) ;
EnhancementCheckbox ( " Fix Two Handed idle animations " , " gTwoHandedIdle " ) ;
Tooltip ( " Makes two handed idle animation play, a seemingly finished animation that was disabled on accident in the original game " ) ;
2022-03-21 21:52:44 -04:00
2022-05-15 15:51:58 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-18 05:37:47 -04:00
2022-05-11 10:59:56 -04:00
EXPERIMENTAL ( ) ;
2022-05-15 15:51:58 -04:00
EnhancementCheckbox ( " 60FPS Interpolation " , " g60FPS " ) ;
2022-05-11 10:59:56 -04:00
EnhancementCheckbox ( " Disable LOD " , " gDisableLOD " ) ;
2022-05-14 15:08:17 -04:00
Tooltip ( " Turns off the level of detail setting, making models always use their higher poly variants " ) ;
2022-03-21 21:52:44 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-18 05:37:47 -04:00
2022-05-11 10:59:56 -04:00
if ( ImGui : : BeginMenu ( " Cosmetics " ) )
2022-04-29 11:49:28 -04:00
{
2022-05-11 10:59:56 -04:00
ImGui : : Text ( " Tunics " ) ;
ImGui : : Separator ( ) ;
EnhancementColor3 ( " Kokiri Tunic " , " gTunic_Kokiri " , kokiri_col ) ;
EnhancementColor3 ( " Goron Tunic " , " gTunic_Goron " , goron_col ) ;
EnhancementColor3 ( " Zora Tunic " , " gTunic_Zora " , zora_col ) ;
ImGui : : Text ( " Navi " ) ;
ImGui : : Separator ( ) ;
EnhancementColor3 ( " Navi Idle Inner " , " gNavi_Idle_Inner " , navi_idle_i_col ) ;
EnhancementColor3 ( " Navi Idle Outer " , " gNavi_Idle_Outer " , navi_idle_o_col ) ;
EnhancementColor3 ( " Navi NPC Inner " , " gNavi_NPC_Inner " , navi_npc_i_col ) ;
EnhancementColor3 ( " Navi NPC Outer " , " gNavi_NPC_Outer " , navi_npc_o_col ) ;
EnhancementColor3 ( " Navi Enemy Inner " , " gNavi_Enemy_Inner " , navi_enemy_i_col ) ;
EnhancementColor3 ( " Navi Enemy Outer " , " gNavi_Enemy_Outer " , navi_enemy_o_col ) ;
EnhancementColor3 ( " Navi Prop Inner " , " gNavi_Prop_Inner " , navi_prop_i_col ) ;
EnhancementColor3 ( " Navi Prop Outer " , " gNavi_Prop_Outer " , navi_prop_o_col ) ;
2022-04-18 05:37:47 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-29 11:49:28 -04:00
if ( ImGui : : BeginMenu ( " Cheats " ) )
{
2022-04-21 18:39:39 -04:00
if ( ImGui : : BeginMenu ( " Infinite... " ) ) {
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Money " , " gInfiniteMoney " ) ;
EnhancementCheckbox ( " Health " , " gInfiniteHealth " ) ;
EnhancementCheckbox ( " Ammo " , " gInfiniteAmmo " ) ;
EnhancementCheckbox ( " Magic " , " gInfiniteMagic " ) ;
EnhancementCheckbox ( " Nayru's Love " , " gInfiniteNayru " ) ;
2022-04-21 18:39:39 -04:00
2022-04-26 19:04:47 -04:00
ImGui : : EndMenu ( ) ;
2022-03-27 21:18:05 -04:00
}
2022-04-18 05:37:47 -04:00
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " No Clip " , " gNoClip " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Allows you to walk through walls " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Climb Everything " , " gClimbEverything " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Makes every surface in the game climbable " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Moon Jump on L " , " gMoonJumpOnL " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Holding L makes you float into the air " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Super Tunic " , " gSuperTunic " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Makes every tunic have the effects of every other tunic " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Easy ISG " , " gEzISG " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Automatically activates the Infinite Sword glitch, making you constantly swing your sword " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Unrestricted Items " , " gNoRestrictItems " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Allows you to use any item at any location " ) ;
2022-04-25 02:27:24 -04:00
EnhancementCheckbox ( " Freeze Time " , " gFreezeTime " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Freezes the time of day " ) ;
2022-04-18 05:37:47 -04:00
2022-04-27 21:16:26 -04:00
ImGui : : EndMenu ( ) ;
2022-04-26 19:04:47 -04:00
}
2022-04-26 18:33:18 -04:00
2022-05-11 10:59:56 -04:00
if ( ImGui : : BeginMenu ( " Developer Tools " ) )
2022-04-29 11:49:28 -04:00
{
2022-05-12 09:05:54 -04:00
EnhancementCheckbox ( " OoT Debug Mode " , " gDebugEnabled " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Enables Debug Mode, allowing you to select maps with L + R + Z, noclip with L + D-pad Right, \n and open the debug menu with L on the pause screen " ) ;
2022-05-12 09:05:54 -04:00
ImGui : : Separator ( ) ;
2022-05-11 10:59:56 -04:00
EnhancementCheckbox ( " Stats " , " gStatsEnabled " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Shows the stats window, with your FPS and frametimes, and the OS you're playing on " ) ;
2022-05-11 10:59:56 -04:00
EnhancementCheckbox ( " Console " , " gConsoleEnabled " ) ;
2022-05-15 15:51:58 -04:00
Tooltip ( " Enables the console window, allowing you to input commands, type help for some examples " ) ;
2022-05-11 10:59:56 -04:00
console - > opened = CVar_GetS32 ( " gConsoleEnabled " , 0 ) ;
2022-03-21 21:52:44 -04:00
2022-05-02 18:24:12 -04:00
ImGui : : EndMenu ( ) ;
}
2022-04-03 15:47:24 -04:00
for ( const auto & category : windowCategories ) {
if ( ImGui : : BeginMenu ( category . first . c_str ( ) ) ) {
for ( const std : : string & name : category . second ) {
2022-05-11 10:59:56 -04:00
std : : string varName ( name ) ;
2022-05-15 15:51:58 -04:00
varName . erase ( std : : ranges : : remove_if ( varName , isspace ) . begin ( ) , varName . end ( ) ) ;
2022-05-11 10:59:56 -04:00
std : : string toggleName = " g " + varName + " Enabled " ;
EnhancementCheckbox ( name , toggleName ) ;
customWindows [ name ] . enabled = CVar_GetS32 ( toggleName . c_str ( ) , 0 ) ;
2022-04-03 15:47:24 -04:00
}
ImGui : : EndMenu ( ) ;
}
2022-05-12 09:05:54 -04:00
2022-04-03 15:47:24 -04:00
}
2022-03-21 21:52:44 -04:00
ImGui : : EndMenuBar ( ) ;
}
ImGui : : End ( ) ;
2022-04-18 05:37:47 -04:00
2022-05-11 10:59:56 -04:00
if ( CVar_GetS32 ( " gStatsEnabled " , 0 ) ) {
2022-04-18 05:37:47 -04:00
const float framerate = ImGui : : GetIO ( ) . Framerate ;
ImGui : : PushStyleColor ( ImGuiCol_Border , ImVec4 ( 0 , 0 , 0 , 0 ) ) ;
2022-05-12 09:05:54 -04:00
ImGui : : Begin ( " Debug Stats " , nullptr , ImGuiWindowFlags_NoFocusOnAppearing ) ;
2022-04-18 05:37:47 -04:00
2022-05-11 13:18:24 -04:00
# ifdef _WIN32
2022-04-18 05:37:47 -04:00
ImGui : : Text ( " Platform: Windows " ) ;
2022-05-11 13:18:24 -04:00
# else
ImGui : : Text ( " Platform: Linux " ) ;
# endif
2022-04-18 05:37:47 -04:00
ImGui : : Text ( " Status: %.3f ms/frame (%.1f FPS) " , 1000.0f / framerate , framerate ) ;
ImGui : : End ( ) ;
ImGui : : PopStyleColor ( ) ;
}
console - > Draw ( ) ;
for ( auto & windowIter : customWindows ) {
CustomWindow & window = windowIter . second ;
if ( window . drawFunc ! = nullptr ) {
window . drawFunc ( window . enabled ) ;
}
}
2022-03-21 21:52:44 -04:00
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowPadding , ImVec2 ( 0 , 0 ) ) ;
2022-04-18 05:37:47 -04:00
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowBorderSize , 0.0f ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildBorderSize , 0.0f ) ;
2022-03-21 21:52:44 -04:00
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , ImVec4 ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
2022-04-18 05:37:47 -04:00
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground ;
2022-03-21 21:52:44 -04:00
ImGui : : Begin ( " OoT Master Quest " , nullptr , flags ) ;
2022-04-18 05:37:47 -04:00
ImGui : : PopStyleVar ( 3 ) ;
2022-03-21 21:52:44 -04:00
ImGui : : PopStyleColor ( ) ;
ImVec2 main_pos = ImGui : : GetWindowPos ( ) ;
2022-04-18 05:37:47 -04:00
main_pos . x - = top_left_pos . x ;
main_pos . y - = top_left_pos . y ;
2022-03-21 21:52:44 -04:00
ImVec2 size = ImGui : : GetContentRegionAvail ( ) ;
ImVec2 pos = ImVec2 ( 0 , 0 ) ;
gfx_current_dimensions . width = size . x * gfx_current_dimensions . internal_mul ;
gfx_current_dimensions . height = size . y * gfx_current_dimensions . internal_mul ;
2022-04-18 05:37:47 -04:00
gfx_current_game_window_viewport . x = main_pos . x ;
gfx_current_game_window_viewport . y = main_pos . y ;
gfx_current_game_window_viewport . width = size . x ;
gfx_current_game_window_viewport . height = size . y ;
2022-04-25 02:27:24 -04:00
if ( CVar_GetS32 ( " gN64Mode " , 0 ) )
{
2022-04-18 05:37:47 -04:00
gfx_current_dimensions . width = 320 ;
gfx_current_dimensions . height = 240 ;
const int sw = size . y * 320 / 240 ;
gfx_current_game_window_viewport . x + = ( size . x - sw ) / 2 ;
gfx_current_game_window_viewport . width = sw ;
pos = ImVec2 ( size . x / 2 - sw / 2 , 0 ) ;
size = ImVec2 ( sw , size . y ) ;
2022-03-21 21:52:44 -04:00
}
2022-05-11 13:35:03 -04:00
overlay - > Draw ( ) ;
2022-04-18 05:37:47 -04:00
}
2022-03-21 21:52:44 -04:00
2022-04-18 05:37:47 -04:00
void DrawFramebufferAndGameInput ( ) {
ImVec2 main_pos = ImGui : : GetWindowPos ( ) ;
ImVec2 size = ImGui : : GetContentRegionAvail ( ) ;
ImVec2 pos = ImVec2 ( 0 , 0 ) ;
2022-04-25 02:27:24 -04:00
if ( CVar_GetS32 ( " gN64Mode " , 0 ) ) {
2022-04-18 05:37:47 -04:00
const int sw = size . y * 320 / 240 ;
pos = ImVec2 ( size . x / 2 - sw / 2 , 0 ) ;
size = ImVec2 ( sw , size . y ) ;
2022-03-21 21:52:44 -04:00
}
2022-04-18 05:37:47 -04:00
std : : string fb_str = SohUtils : : getEnvironmentVar ( " framebuffer " ) ;
if ( ! fb_str . empty ( ) ) {
uintptr_t fbuf = ( uintptr_t ) std : : stoull ( fb_str ) ;
//ImGui::ImageSimple(reinterpret_cast<ImTextureID>(fbuf), pos, size);
ImGui : : SetCursorPos ( pos ) ;
ImGui : : Image ( reinterpret_cast < ImTextureID > ( fbuf ) , size ) ;
2022-03-21 21:52:44 -04:00
}
2022-04-18 05:37:47 -04:00
ImGui : : End ( ) ;
2022-04-25 02:27:24 -04:00
const float scale = CVar_GetFloat ( " gInputScale " , 1.0f ) ;
2022-03-21 21:52:44 -04:00
ImVec2 BtnPos = ImVec2 ( 160 * scale , 85 * scale ) ;
2022-04-25 02:27:24 -04:00
if ( CVar_GetS32 ( " gInputEnabled " , 0 ) ) {
2022-03-21 22:25:30 -04:00
ImGui : : SetNextWindowSize ( BtnPos ) ;
ImGui : : SetNextWindowPos ( ImVec2 ( main_pos . x + size . x - BtnPos . x - 20 , main_pos . y + size . y - BtnPos . y - 20 ) ) ;
if ( pads ! = nullptr & & ImGui : : Begin ( " Game Buttons " , nullptr , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground ) ) {
ImGui : : SetCursorPosY ( 32 * scale ) ;
ImGui : : BeginGroup ( ) ;
const ImVec2 cPos = ImGui : : GetCursorPos ( ) ;
ImGui : : SetCursorPos ( ImVec2 ( cPos . x + 10 * scale , cPos . y - 20 * scale ) ) ;
BindButton ( " L-Btn " , pads [ 0 ] . button & BTN_L ) ;
ImGui : : SetCursorPos ( ImVec2 ( cPos . x + 16 * scale , cPos . y ) ) ;
BindButton ( " C-Up " , pads [ 0 ] . button & BTN_CUP ) ;
ImGui : : SetCursorPos ( ImVec2 ( cPos . x , cPos . y + 16 * scale ) ) ;
BindButton ( " C-Left " , pads [ 0 ] . button & BTN_CLEFT ) ;
ImGui : : SetCursorPos ( ImVec2 ( cPos . x + 32 * scale , cPos . y + 16 * scale ) ) ;
BindButton ( " C-Right " , pads [ 0 ] . button & BTN_CRIGHT ) ;
ImGui : : SetCursorPos ( ImVec2 ( cPos . x + 16 * scale , cPos . y + 32 * scale ) ) ;
BindButton ( " C-Down " , pads [ 0 ] . button & BTN_CDOWN ) ;
ImGui : : EndGroup ( ) ;
2022-03-21 21:52:44 -04:00
2022-03-21 22:25:30 -04:00
ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
const ImVec2 sPos = ImGui : : GetCursorPos ( ) ;
ImGui : : SetCursorPos ( ImVec2 ( sPos . x + 21 , sPos . y - 20 * scale ) ) ;
BindButton ( " Z-Btn " , pads [ 0 ] . button & BTN_Z ) ;
ImGui : : SetCursorPos ( ImVec2 ( sPos . x + 22 , sPos . y + 16 * scale ) ) ;
BindButton ( " Start-Btn " , pads [ 0 ] . button & BTN_START ) ;
ImGui : : EndGroup ( ) ;
ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
const ImVec2 bPos = ImGui : : GetCursorPos ( ) ;
ImGui : : SetCursorPos ( ImVec2 ( bPos . x + 20 * scale , bPos . y - 20 * scale ) ) ;
BindButton ( " R-Btn " , pads [ 0 ] . button & BTN_R ) ;
ImGui : : SetCursorPos ( ImVec2 ( bPos . x + 12 * scale , bPos . y + 8 * scale ) ) ;
BindButton ( " B-Btn " , pads [ 0 ] . button & BTN_B ) ;
ImGui : : SetCursorPos ( ImVec2 ( bPos . x + 28 * scale , bPos . y + 24 * scale ) ) ;
BindButton ( " A-Btn " , pads [ 0 ] . button & BTN_A ) ;
ImGui : : EndGroup ( ) ;
ImGui : : End ( ) ;
}
2022-03-21 21:52:44 -04:00
}
2022-04-18 05:37:47 -04:00
}
2022-03-21 21:52:44 -04:00
2022-04-18 05:37:47 -04:00
void Render ( ) {
2022-03-21 21:52:44 -04:00
ImGui : : Render ( ) ;
ImGuiRenderDrawData ( ImGui : : GetDrawData ( ) ) ;
if ( UseViewports ( ) ) {
ImGui : : UpdatePlatformWindows ( ) ;
ImGui : : RenderPlatformWindowsDefault ( ) ;
}
}
2022-04-18 05:37:47 -04:00
void CancelFrame ( ) {
ImGui : : EndFrame ( ) ;
if ( UseViewports ( ) ) {
ImGui : : UpdatePlatformWindows ( ) ;
}
}
2022-03-21 21:52:44 -04:00
void BindCmd ( const std : : string & cmd , CommandEntry entry ) {
console - > Commands [ cmd ] = std : : move ( entry ) ;
}
2022-04-03 15:47:24 -04:00
void AddWindow ( const std : : string & category , const std : : string & name , WindowDrawFunc drawFunc ) {
if ( customWindows . contains ( name ) ) {
SPDLOG_ERROR ( " SohImGui::AddWindow: Attempting to add duplicate window name %s " , name . c_str ( ) ) ;
return ;
}
customWindows [ name ] = {
. enabled = false ,
. drawFunc = drawFunc
} ;
windowCategories [ category ] . emplace_back ( name ) ;
}
ImTextureID GetTextureByName ( const std : : string & name ) {
return GetTextureByID ( DefaultAssets [ name ] - > textureId ) ;
}
2022-05-11 13:18:24 -04:00
ImTextureID GetTextureByID ( int id ) {
# ifdef ENABLE_DX11
2022-05-12 09:06:39 -04:00
if ( impl . backend = = Backend : : DX11 )
{
ImTextureID gfx_d3d11_get_texture_by_id ( int id ) ;
return gfx_d3d11_get_texture_by_id ( id ) ;
}
2022-05-11 13:18:24 -04:00
# endif
2022-05-12 09:06:39 -04:00
return reinterpret_cast < ImTextureID > ( id ) ;
2022-05-11 13:18:24 -04:00
}
2022-04-17 11:26:49 -04:00
}