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