CommonLibVR
UI.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSAtomic.h"
4 #include "RE/B/BSFixedString.h"
5 #include "RE/B/BSTArray.h"
6 #include "RE/B/BSTEvent.h"
7 #include "RE/B/BSTHashMap.h"
8 #include "RE/B/BSTSingleton.h"
9 #include "RE/B/BSTimer.h"
10 #include "RE/G/GPtr.h"
11 
12 namespace RE
13 {
14  class GFxMovieView;
15  class IMenu;
16  class MenuModeChangeEvent;
17  class MenuOpenCloseEvent;
18 
19  namespace UIImpl
20  {
21  template <class, class = void>
22  struct _has_menu_name :
23  std::false_type
24  {};
25 
26  template <class T>
28  T,
29  std::void_t<decltype(T::MENU_NAME)>> :
30  std::true_type
31  {};
32 
33  template <class T>
34  struct has_menu_name :
36  std::remove_cv_t<T>>
37  {};
38 
39  template <class T>
40  inline constexpr bool has_menu_name_v = has_menu_name<T>::value;
41 
42  template <class T>
43  struct is_menu_ptr :
44  std::is_convertible<
45  std::remove_cv_t<T>,
46  IMenu*>
47  {};
48 
49  template <class T>
50  inline constexpr bool is_menu_ptr_v = is_menu_ptr<T>::value;
51  }
52 
53  class UI :
54  public BSTSingletonSDM<UI>, // 000
55  public BSTEventSource<MenuOpenCloseEvent>, // 008
56  public BSTEventSource<MenuModeChangeEvent>, // 060
57  public BSTEventSource<void*> // 0B8 MenuModeCounterChangedEvent/TutorialEvent
58  {
59  public:
60  using Create_t = IMenu*();
61 
62  struct UIMenuEntry
63  {
64  public:
65  // members
67  Create_t* create; // 08
68  };
69  static_assert(sizeof(UIMenuEntry) == 0x10);
70 
71  static UI* GetSingleton();
72 
73  template <class T>
74  void AddEventSink(BSTEventSink<T>* a_sink);
75  bool GameIsPaused();
76  template <class T>
78  GPtr<IMenu> GetMenu(const std::string_view& a_menuName);
79  GPtr<GFxMovieView> GetMovieView(const std::string_view& a_menuName);
80  bool IsApplicationMenuOpen() const;
82  bool IsItemMenuOpen() const;
83  bool IsMenuOpen(const std::string_view& a_menuName);
84  bool IsModalMenuOpen() const;
85  bool IsPauseMenuDisabled() const;
86  bool IsSavingAllowed() const;
87  bool IsShowingMenus() const;
88  bool IsUsingCustomRendering() const;
89  void Register(const std::string_view& a_menuName, Create_t* a_creator);
90 
91  template <class T>
92  void RemoveEventSink(BSTEventSink<T>* a_sink);
93  void ShowMenus(bool a_show);
94  void GetTopMostMenu(RE::IMenu** a_result, std::uint32_t a_depthLimit);
95 
96  template <
97  class T,
98  std::enable_if_t<
99  std::conjunction_v<
102  int> = 0>
104  {
105  return GPtr<T>(static_cast<T*>(GetMenu(T::MENU_NAME).get()));
106  }
107 
108  template <
109  class T,
110  std::enable_if_t<
111  UIImpl::is_menu_ptr_v<T*>,
112  int> = 0>
113  GPtr<T> GetMenu(const std::string_view& a_menuName)
114  {
115  return GPtr<T>(static_cast<T*>(GetMenu(a_menuName).get()));
116  }
117 
118  // members
122  std::uint32_t numPausesGame; // 160 (= 0) += 1 if (imenu->flags & 0x00001)
123  std::uint32_t numItemMenus; // 164 (= 0) += 1 if (imenu->flags & 0x02000)
124  std::uint32_t numDisablePauseMenu; // 168 (= 0) += 1 if (imenu->flags & 0x00080)
125  std::uint32_t numAllowSaving; // 16C (= 0) += 1 if (imenu->flags & 0x00800)
126  std::uint32_t numDontHideCursorWhenTopmost; // 170 (= 0) += 1 if (imenu->flags & 0x04000)
127  std::uint32_t numCustomRendering; // 174 (= 0) += 1 if (imenu->flags & 0x08000)
128  std::uint32_t numApplicationMenus; // 178 (= 0) += 1 if (imenu->flags & 0x20000)
129  bool modal; // 17C (= 0) = 1 if (imenu->flags & 0x00010)
130  std::uint8_t pad17D; // 17D
131  std::uint16_t pad17E; // 17E
132  BSTimer uiTimer; // 180
133  bool menuSystemVisible; // 1C0
134  bool closingAllMenus; // 1C1
135  std::uint16_t pad1C2; // 1C2
136  std::uint32_t pad1C4; // 1C4
137 #ifdef SKYRIMVR
138  std::uint32_t unk1C8; // 1C8
139  std::uint32_t unk1CA; // 1CA
140 #endif
141  private:
142  KEEP_FOR_RE()
143  };
144 #ifndef SKYRIMVR
145  static_assert(sizeof(UI) == 0x1C8);
146 #else
147  static_assert(sizeof(UI) == 0x1D0);
148 #endif
149 
150  template <class T>
152  {
153  GetEventSource<T>()->AddEventSink(a_sink);
154  }
155 
156  template <class T>
158  {
159  return static_cast<BSTEventSource<T>*>(this);
160  }
161 
162  template <class T>
164  {
165  GetEventSource<T>()->RemoveEventSink(a_sink);
166  }
167 }
#define KEEP_FOR_RE()
Definition: PCH.h:713
Definition: BSAtomic.h:92
Definition: BSTArray.h:378
Definition: BSTEvent.h:143
Definition: BSTEvent.h:19
Definition: BSTHashMap.h:21
Definition: BSTimer.h:6
Definition: GPtr.h:7
Definition: IMenu.h:64
Definition: UI.h:58
std::uint32_t numPausesGame
Definition: UI.h:122
bool IsCursorHiddenWhenTopmost() const
std::uint16_t pad17E
Definition: UI.h:131
std::uint32_t pad1C4
Definition: UI.h:136
bool IsApplicationMenuOpen() const
bool IsMenuOpen(const std::string_view &a_menuName)
bool IsSavingAllowed() const
std::uint32_t numApplicationMenus
Definition: UI.h:128
BSTArray< GPtr< IMenu > > menuStack
Definition: UI.h:119
IMenu *() Create_t
Definition: UI.h:60
bool IsModalMenuOpen() const
bool closingAllMenus
Definition: UI.h:134
void RemoveEventSink(BSTEventSink< T > *a_sink)
Definition: UI.h:163
bool modal
Definition: UI.h:129
BSTHashMap< BSFixedString, UIMenuEntry > menuMap
Definition: UI.h:120
GPtr< T > GetMenu(const std::string_view &a_menuName)
Definition: UI.h:113
bool IsShowingMenus() const
std::uint32_t numCustomRendering
Definition: UI.h:127
std::uint32_t numAllowSaving
Definition: UI.h:125
std::uint32_t numDontHideCursorWhenTopmost
Definition: UI.h:126
bool IsPauseMenuDisabled() const
bool IsItemMenuOpen() const
bool menuSystemVisible
Definition: UI.h:133
static UI * GetSingleton()
BSTimer uiTimer
Definition: UI.h:132
void Register(const std::string_view &a_menuName, Create_t *a_creator)
GPtr< T > GetMenu()
Definition: UI.h:103
std::uint32_t numItemMenus
Definition: UI.h:123
std::uint16_t pad1C2
Definition: UI.h:135
GPtr< IMenu > GetMenu(const std::string_view &a_menuName)
std::uint32_t numDisablePauseMenu
Definition: UI.h:124
void GetTopMostMenu(RE::IMenu **a_result, std::uint32_t a_depthLimit)
bool IsUsingCustomRendering() const
BSTEventSource< T > * GetEventSource()
Definition: UI.h:157
void ShowMenus(bool a_show)
GPtr< GFxMovieView > GetMovieView(const std::string_view &a_menuName)
bool GameIsPaused()
std::uint8_t pad17D
Definition: UI.h:130
BSSpinLock processMessagesLock
Definition: UI.h:121
void AddEventSink(BSTEventSink< T > *a_sink)
Definition: UI.h:151
constexpr bool has_menu_name_v
Definition: UI.h:40
constexpr bool is_menu_ptr_v
Definition: UI.h:50
Definition: AbsorbEffect.h:6
Definition: EffectArchetypes.h:65
Definition: BSTSingleton.h:50
Definition: UI.h:24
Definition: UI.h:37
Definition: UI.h:47
Definition: UI.h:63
GPtr< IMenu > menu
Definition: UI.h:66
Create_t * create
Definition: UI.h:67