CommonLibSSE (powerof3)
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 
95  template <
96  class T,
97  std::enable_if_t<
98  std::conjunction_v<
101  int> = 0>
103  {
104  return GPtr<T>(static_cast<T*>(GetMenu(T::MENU_NAME).get()));
105  }
106 
107  template <
108  class T,
109  std::enable_if_t<
110  UIImpl::is_menu_ptr_v<T*>,
111  int> = 0>
112  GPtr<T> GetMenu(const std::string_view& a_menuName)
113  {
114  return GPtr<T>(static_cast<T*>(GetMenu(a_menuName).get()));
115  }
116 
117  // members
121  std::uint32_t numPausesGame; // 160 (= 0) += 1 if (imenu->flags & 0x00001)
122  std::uint32_t numItemMenus; // 164 (= 0) += 1 if (imenu->flags & 0x02000)
123  std::uint32_t numDisablePauseMenu; // 168 (= 0) += 1 if (imenu->flags & 0x00080)
124  std::uint32_t numAllowSaving; // 16C (= 0) += 1 if (imenu->flags & 0x00800)
125  std::uint32_t numDontHideCursorWhenTopmost; // 170 (= 0) += 1 if (imenu->flags & 0x04000)
126  std::uint32_t numCustomRendering; // 174 (= 0) += 1 if (imenu->flags & 0x08000)
127  std::uint32_t numApplicationMenus; // 178 (= 0) += 1 if (imenu->flags & 0x20000)
128  bool modal; // 17C (= 0) = 1 if (imenu->flags & 0x00010)
129  std::uint8_t pad17D; // 17D
130  std::uint16_t pad17E; // 17E
131  BSTimer uiTimer; // 180
132  bool menuSystemVisible; // 1C0
133  bool closingAllMenus; // 1C1
134  std::uint16_t pad1C2; // 1C2
135  std::uint32_t pad1C4; // 1C4
136  };
137  static_assert(sizeof(UI) == 0x1C8);
138 
139  template <class T>
141  {
142  GetEventSource<T>()->AddEventSink(a_sink);
143  }
144 
145  template <class T>
147  {
148  return static_cast<BSTEventSource<T>*>(this);
149  }
150 
151  template <class T>
153  {
154  GetEventSource<T>()->RemoveEventSink(a_sink);
155  }
156 }
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:55
Definition: UI.h:58
std::uint32_t numPausesGame
Definition: UI.h:121
bool IsCursorHiddenWhenTopmost() const
std::uint16_t pad17E
Definition: UI.h:130
std::uint32_t pad1C4
Definition: UI.h:135
bool IsApplicationMenuOpen() const
bool IsMenuOpen(const std::string_view &a_menuName)
bool IsSavingAllowed() const
std::uint32_t numApplicationMenus
Definition: UI.h:127
BSTArray< GPtr< IMenu > > menuStack
Definition: UI.h:118
IMenu *() Create_t
Definition: UI.h:60
bool IsModalMenuOpen() const
bool closingAllMenus
Definition: UI.h:133
void RemoveEventSink(BSTEventSink< T > *a_sink)
Definition: UI.h:152
bool modal
Definition: UI.h:128
BSTHashMap< BSFixedString, UIMenuEntry > menuMap
Definition: UI.h:119
GPtr< T > GetMenu(const std::string_view &a_menuName)
Definition: UI.h:112
bool IsShowingMenus() const
std::uint32_t numCustomRendering
Definition: UI.h:126
std::uint32_t numAllowSaving
Definition: UI.h:124
std::uint32_t numDontHideCursorWhenTopmost
Definition: UI.h:125
bool IsPauseMenuDisabled() const
bool IsItemMenuOpen() const
bool menuSystemVisible
Definition: UI.h:132
static UI * GetSingleton()
BSTimer uiTimer
Definition: UI.h:131
void Register(const std::string_view &a_menuName, Create_t *a_creator)
GPtr< T > GetMenu()
Definition: UI.h:102
std::uint32_t numItemMenus
Definition: UI.h:122
std::uint16_t pad1C2
Definition: UI.h:134
GPtr< IMenu > GetMenu(const std::string_view &a_menuName)
std::uint32_t numDisablePauseMenu
Definition: UI.h:123
bool IsUsingCustomRendering() const
BSTEventSource< T > * GetEventSource()
Definition: UI.h:146
void ShowMenus(bool a_show)
GPtr< GFxMovieView > GetMovieView(const std::string_view &a_menuName)
bool GameIsPaused()
std::uint8_t pad17D
Definition: UI.h:129
BSSpinLock processMessagesLock
Definition: UI.h:120
void AddEventSink(BSTEventSink< T > *a_sink)
Definition: UI.h:140
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