mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
Implemented SDL event listener class and HUD toggle key (#4)
* Implemented SDL event listener class * Add HUD toggle. * frontend_listener: clean-up * window: invoke all listener callbacks at once * window: use raw pointers for listeners * Rename WindowListener to SDLEventListener, reduce virtual functions --------- Co-authored-by: RadiantDerg <jayvier13@gmail.com>
This commit is contained in:
parent
21fc80798e
commit
f157b21d67
6 changed files with 71 additions and 1 deletions
|
|
@ -59,6 +59,7 @@ set(SWA_HID_CXX_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SWA_PATCHES_CXX_SOURCES
|
set(SWA_PATCHES_CXX_SOURCES
|
||||||
|
"patches/ui/frontend_listener.cpp"
|
||||||
"patches/fps_patches.cpp"
|
"patches/fps_patches.cpp"
|
||||||
"patches/misc_patches.cpp"
|
"patches/misc_patches.cpp"
|
||||||
"patches/object_patches.cpp"
|
"patches/object_patches.cpp"
|
||||||
|
|
|
||||||
3
UnleashedRecomp/patches/ui/frontend_listener.cpp
Normal file
3
UnleashedRecomp/patches/ui/frontend_listener.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "frontend_listener.h"
|
||||||
|
|
||||||
|
FrontendListener m_frontendListener;
|
||||||
37
UnleashedRecomp/patches/ui/frontend_listener.h
Normal file
37
UnleashedRecomp/patches/ui/frontend_listener.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kernel/memory.h"
|
||||||
|
#include "ui/sdl_listener.h"
|
||||||
|
|
||||||
|
class FrontendListener : public SDLEventListener
|
||||||
|
{
|
||||||
|
bool m_isF8KeyDown = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void OnSDLEvent(SDL_Event* event) override
|
||||||
|
{
|
||||||
|
switch (event->type)
|
||||||
|
{
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
{
|
||||||
|
if (event->key.keysym.sym != SDLK_F8 || m_isF8KeyDown)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// アプリケーション設定 / 開発用 / デバッグ / HUD / 全 HUD 描画
|
||||||
|
const auto ms_IsRenderHud = (bool*)g_memory.Translate(0x8328BB26);
|
||||||
|
|
||||||
|
*ms_IsRenderHud = !*ms_IsRenderHud;
|
||||||
|
|
||||||
|
printf("[*] HUD %s\n", *ms_IsRenderHud ? "On" : "Off");
|
||||||
|
|
||||||
|
m_isF8KeyDown = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SDL_KEYUP:
|
||||||
|
m_isF8KeyDown = event->key.keysym.sym != SDLK_F8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
21
UnleashedRecomp/ui/sdl_listener.h
Normal file
21
UnleashedRecomp/ui/sdl_listener.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/window.h"
|
||||||
|
|
||||||
|
class ISDLEventListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ISDLEventListener() = default;
|
||||||
|
virtual void OnSDLEvent(SDL_Event* event) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SDLEventListener : public ISDLEventListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SDLEventListener()
|
||||||
|
{
|
||||||
|
Window::s_eventListeners.emplace_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSDLEvent(SDL_Event* event) override {}
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
#include "sdl_listener.h"
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <kernel/function.h>
|
#include <kernel/function.h>
|
||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
|
@ -107,6 +108,9 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto listener : Window::s_eventListeners)
|
||||||
|
listener->OnSDLEvent(event);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@
|
||||||
#define DEFAULT_WIDTH 1280
|
#define DEFAULT_WIDTH 1280
|
||||||
#define DEFAULT_HEIGHT 720
|
#define DEFAULT_HEIGHT 720
|
||||||
|
|
||||||
struct Window
|
class SDLEventListener;
|
||||||
|
|
||||||
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline static SDL_Window* s_pWindow;
|
inline static SDL_Window* s_pWindow;
|
||||||
|
|
@ -20,6 +22,8 @@ public:
|
||||||
|
|
||||||
inline static bool s_isFocused;
|
inline static bool s_isFocused;
|
||||||
|
|
||||||
|
inline static std::vector<SDLEventListener*> s_eventListeners;
|
||||||
|
|
||||||
static SDL_Surface* GetIconSurface(void* pIconBmp = nullptr, size_t iconSize = 0)
|
static SDL_Surface* GetIconSurface(void* pIconBmp = nullptr, size_t iconSize = 0)
|
||||||
{
|
{
|
||||||
auto rw = SDL_RWFromMem(pIconBmp ? pIconBmp : (void*)g_icon, pIconBmp ? iconSize : g_icon_size);
|
auto rw = SDL_RWFromMem(pIconBmp ? pIconBmp : (void*)g_icon, pIconBmp ? iconSize : g_icon_size);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue