mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
Rename WindowListener to SDLEventListener, reduce virtual functions
This commit is contained in:
parent
62312f2a03
commit
31f24e02eb
5 changed files with 46 additions and 55 deletions
|
|
@ -1,31 +1,37 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "kernel/memory.h"
|
#include "kernel/memory.h"
|
||||||
#include "ui/window_listener.h"
|
#include "ui/sdl_listener.h"
|
||||||
|
|
||||||
class FrontendListener : public WindowListener
|
class FrontendListener : public SDLEventListener
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
bool m_isF8KeyDown = false;
|
bool m_isF8KeyDown = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void OnKeyDown(SDL_Keycode key) override
|
void OnSDLEvent(SDL_Event* event) override
|
||||||
{
|
{
|
||||||
if (key == SDLK_F8 && !m_isF8KeyDown)
|
switch (event->type)
|
||||||
{
|
{
|
||||||
|
case SDL_KEYDOWN:
|
||||||
|
{
|
||||||
|
if (event->key.keysym.sym != SDLK_F8 || m_isF8KeyDown)
|
||||||
|
break;
|
||||||
|
|
||||||
// アプリケーション設定 / 開発用 / デバッグ / HUD / 全 HUD 描画
|
// アプリケーション設定 / 開発用 / デバッグ / HUD / 全 HUD 描画
|
||||||
const auto ms_IsRenderHud = (bool*)g_memory.Translate(0x8328BB26);
|
const auto ms_IsRenderHud = (bool*)g_memory.Translate(0x8328BB26);
|
||||||
|
|
||||||
*ms_IsRenderHud = !*ms_IsRenderHud; // Toggle the entire HUD
|
*ms_IsRenderHud = !*ms_IsRenderHud;
|
||||||
|
|
||||||
printf("[*] HUD %s\n", *ms_IsRenderHud ? "On" : "Off");
|
printf("[*] HUD %s\n", *ms_IsRenderHud ? "On" : "Off");
|
||||||
|
|
||||||
m_isF8KeyDown = true;
|
m_isF8KeyDown = true;
|
||||||
}
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnKeyUp(SDL_Keycode key) override
|
case SDL_KEYUP:
|
||||||
{
|
m_isF8KeyDown = event->key.keysym.sym != SDLK_F8;
|
||||||
m_isF8KeyDown = key != 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,5 +1,5 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "window_listener.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>
|
||||||
|
|
@ -108,20 +108,9 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto listener : Window::s_listeners)
|
for (auto listener : Window::s_eventListeners)
|
||||||
{
|
|
||||||
listener->OnSDLEvent(event);
|
listener->OnSDLEvent(event);
|
||||||
|
|
||||||
if (event->type == SDL_KEYDOWN)
|
|
||||||
{
|
|
||||||
listener->OnKeyDown(event->key.keysym.sym);
|
|
||||||
}
|
|
||||||
else if (event->type == SDL_KEYUP)
|
|
||||||
{
|
|
||||||
listener->OnKeyUp(event->key.keysym.sym);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#define DEFAULT_WIDTH 1280
|
#define DEFAULT_WIDTH 1280
|
||||||
#define DEFAULT_HEIGHT 720
|
#define DEFAULT_HEIGHT 720
|
||||||
|
|
||||||
class WindowListener;
|
class SDLEventListener;
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
inline static bool s_isFocused;
|
inline static bool s_isFocused;
|
||||||
|
|
||||||
inline static std::vector<WindowListener*> s_listeners;
|
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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ui/window.h"
|
|
||||||
|
|
||||||
class IWindowListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~IWindowListener() = default;
|
|
||||||
virtual void OnSDLEvent(SDL_Event* event) = 0;
|
|
||||||
virtual void OnKeyDown(SDL_Keycode key) = 0;
|
|
||||||
virtual void OnKeyUp(SDL_Keycode key) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WindowListener : public IWindowListener
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
WindowListener()
|
|
||||||
{
|
|
||||||
Window::s_listeners.emplace_back(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnSDLEvent(SDL_Event* event) override {}
|
|
||||||
void OnKeyDown(SDL_Keycode key) override {}
|
|
||||||
void OnKeyUp(SDL_Keycode key) override {}
|
|
||||||
};
|
|
||||||
Loading…
Add table
Reference in a new issue