Mario Kart 64
Loading...
Searching...
No Matches
MenuTypes.h
Go to the documentation of this file.
1#ifndef MENUTYPES_H
2#define MENUTYPES_H
3
4#include <libultraship/libultraship.h>
5#include "UIWidgets.h"
6
24
25struct WidgetInfo;
26struct disabledInfo;
27using VoidFunc = void (*)();
28using DisableInfoFunc = bool (*)(disabledInfo&);
29using DisableVec = std::vector<DisableOption>;
30using WidgetFunc = void (*)(WidgetInfo&);
31
53
59
65
75
76// holds the widget values for a widget, contains all CVar types available from LUS. int32_t is used for boolean
77// evaluation
78using CVarVariant = std::variant<int32_t, const char*, float, Color_RGBA8, Color_RGB8>;
82
83// All the info needed for display and search of all widgets in the menu.
84// `name` is the label displayed,
85// `cVar` is the string representation of the CVar used to store the widget value
86// `tooltip` is what is displayed when hovering (except when disabled, more on that later)
87// `type` is the WidgetType for the widget, which is what determines how the information is used in the draw func
88// `options` is a variant that holds the UIWidgetsOptions struct for the widget type
89// blank objects need to be initialized with specific typing matching the expected Options struct for the widget
90// `callback` is a lambda used for running code on widget change. may need `BenGui::GetMenu()` for specific menu actions
91// `preFunc` is a lambda called before drawing code starts. It can be used to determine a widget's status,
92// whether disabled or hidden, as well as update pointers for non-CVar widget types.
93// `postFunc` is a lambda called after all drawing code is finished, for reacting to states other than
94// widgets having been changed, like holding buttons.
95// All three lambdas accept a `widgetInfo` reference in case it needs information on the widget for these operations
96// `activeDisables` is a vector of DisableOptions for specifying what reasons a widget is disabled, which are displayed
97// in the disabledTooltip for the widget. Can display multiple reasons. Handling the reasons is done in `preFunc`.
98// It is recommended to utilize `disabledInfo`/`DisableReason` to list out all reasons for disabling and isHidden so
99// the info can be shown.
100// `windowName` is what is displayed and searched for `windowButton` type and window interactions
101// `isHidden` just prevents the widget from being drawn under whatever circumstances you specify in the `preFunc`
102// `sameLine` allows for specifying that the widget should be on the same line as the previous widget
104 std::string name; // Used by all widgets
105 const char* cVar; // Used by all widgets except
107 std::shared_ptr<UIWidgets::WidgetOptions> options;
108 std::variant<bool*, int32_t*, float*> valuePointer;
114 const char* windowName = "";
115 bool isHidden = false;
116 bool sameLine = false;
117
118 WidgetInfo& CVar(const char* cVar_) {
119 cVar = cVar_;
120 return *this;
121 }
123 switch (type) {
126 case WIDGET_COMBOBOX:
128 options = std::make_shared<UIWidgets::ComboboxOptions>(std::get<UIWidgets::ComboboxOptions>(options_));
129 break;
130 case WIDGET_CHECKBOX:
132 options = std::make_shared<UIWidgets::CheckboxOptions>(std::get<UIWidgets::CheckboxOptions>(options_));
133 break;
136 options =
137 std::make_shared<UIWidgets::FloatSliderOptions>(std::get<UIWidgets::FloatSliderOptions>(options_));
138 break;
141 options =
142 std::make_shared<UIWidgets::IntSliderOptions>(std::get<UIWidgets::IntSliderOptions>(options_));
143 break;
144 case WIDGET_BUTTON:
146 options = std::make_shared<UIWidgets::ButtonOptions>(std::get<UIWidgets::ButtonOptions>(options_));
147 break;
148 case WIDGET_CUSTOM:
149 case WIDGET_TEXT:
151 case WIDGET_SEPARATOR:
152 default:
153 options = std::make_shared<UIWidgets::WidgetOptions>(std::get<UIWidgets::WidgetOptions>(options_));
154 }
155 return *this;
156 }
158 isHidden = false;
159 options->disabled = false;
160 options->disabledTooltip = "";
161 activeDisables.clear();
162 }
163 WidgetInfo& Options(std::shared_ptr<UIWidgets::WidgetOptions> options_) {
164 options = options_;
165 return *this;
166 }
168 callback = callback_;
169 return *this;
170 }
172 preFunc = preFunc_;
173 return *this;
174 }
176 postFunc = postFunc_;
177 return *this;
178 }
179 WidgetInfo& WindowName(const char* windowName_) {
180 windowName = windowName_;
181 return *this;
182 }
183 WidgetInfo& ValuePointer(std::variant<bool*, int32_t*, float*> valuePointer_) {
184 valuePointer = valuePointer_;
185 return *this;
186 }
187 WidgetInfo& SameLine(bool sameLine_) {
188 sameLine = sameLine_;
189 return *this;
190 }
192 customFunction = customFunction_;
193 return *this;
194 }
195};
196
198 std::string sectionName;
199 std::string sidebarName;
201};
202
203// `disabledInfo` holds information on reasons for hiding or disabling a widget, as well as an evaluation lambda that
204// is run once per frame to update its status (this is done to prevent dozens of redundant CVarGets in each frame loop)
205// `evaluation` returns a bool which can be determined by whatever code you want that changes its status
206// `reason` is the text displayed in the disabledTooltip when a widget is disabled by a particular DisableReason
207// `active` is what's referenced when determining disabled status for a widget that uses this This can also be used to
208// hold reasons to hide widgets so that their evaluations are also only run once per frame
211 const char* reason;
212 bool active = false;
213 int32_t value = 0;
214};
215
216// struct Sidebar {
217// //std::unordered_map<std::string, SidebarEntry> entries;
218// uint32_t columnCount;
219// std::vector<std::vector<WidgetInfo>> columnWidgets;
220//
221// void Insert(std::string entryName, WidgetInfo& entry, int32_t index = -1) {
222// if (index == -1 || index >= entryOrder.size()) {
223// entryOrder.push_back(entryName);
224// } else {
225// entryOrder.insert(entryOrder.begin() + index, entryName);
226// }
227// columnWidgets[entryName].push_back({entry});
228// }
229//
230// void Erase(std::string entryName) {
231// if (columnWidgets.contains(entryName)) {
232// columnWidgets.erase(entryName);
233// }
234// std::erase_if(entryOrder, [entryName](std::string name) { return name == entryName; });
235// }
236// };
237
238// Contains the name displayed in the sidebar (label), the number of columns to use in drawing (columnCount; for visual
239// separation, 1-3), and nested vectors of the widgets, grouped by column (columnWidgets). The number of widget vectors
240// added to the column groups does not need to match the specified columnCount, e.g. you can have one vector added to
241// the sidebar, but still separate the window into 3 columns and display only in the first column
243 uint32_t columnCount;
244 std::vector<std::vector<WidgetInfo>> columnWidgets;
245};
246
247// Contains entries for what's listed in the header at the top, including the name displayed on the top bar (label),
248// a vector of the SidebarEntries for that header entry, and the name of the cvar used to track what sidebar entry is
249// the last viewed for that header.
251 std::string label;
252 const char* sidebarCvar;
253 std::unordered_map<std::string, SidebarEntry> sidebars = {};
254 std::vector<std::string> sidebarOrder = {};
255};
256
257static const std::unordered_map<Ship::AudioBackend, const char*> audioBackendsMap = {
258 { Ship::AudioBackend::WASAPI, "Windows Audio Session API" },
259 { Ship::AudioBackend::SDL, "SDL" },
260};
261
262static const std::unordered_map<Ship::WindowBackend, const char*> windowBackendsMap = {
263 { Ship::WindowBackend::FAST3D_DXGI_DX11, "DirectX" },
264 { Ship::WindowBackend::FAST3D_SDL_OPENGL, "OpenGL" },
265 { Ship::WindowBackend::FAST3D_SDL_METAL, "Metal" },
266};
267
268struct MenuInit {
269 static std::vector<std::function<void()>>& GetInitFuncs() {
270 static std::vector<std::function<void()>> menuInitFuncs;
271 return menuInitFuncs;
272 }
273
274 static std::unordered_map<std::string, std::unordered_map<std::string, std::vector<std::function<void()>>>>&
276 static std::unordered_map<std::string, std::unordered_map<std::string, std::vector<std::function<void()>>>>
277 menuUpdateFuncs;
278 return menuUpdateFuncs;
279 }
280
281 static void InitAll() {
282 auto& menuInitFuncs = MenuInit::GetInitFuncs();
283 for (const auto& initFunc : menuInitFuncs) {
284 initFunc();
285 }
286 }
287};
288
290 RegisterMenuInitFunc(std::function<void()> initFunc) {
291 auto& menuInitFuncs = MenuInit::GetInitFuncs();
292
293 menuInitFuncs.push_back(initFunc);
294 }
295};
296
298 RegisterMenuUpdateFunc(std::function<void()> updateFunc, std::string sectionName, std::string sidebarName) {
299 auto& menuUpdateFuncs = MenuInit::GetUpdateFuncs();
300
301 menuUpdateFuncs[sectionName][sidebarName].push_back(updateFunc);
302 }
303};
304
305#endif // MENUTYPES_H
std::variant< int32_t, const char *, float, Color_RGBA8, Color_RGB8 > CVarVariant
Definition MenuTypes.h:78
MotionBlurOption
Definition MenuTypes.h:60
@ MOTION_BLUR_DYNAMIC
Definition MenuTypes.h:61
@ MOTION_BLUR_ALWAYS_ON
Definition MenuTypes.h:63
@ MOTION_BLUR_ALWAYS_OFF
Definition MenuTypes.h:62
static const std::unordered_map< Ship::AudioBackend, const char * > audioBackendsMap
Definition MenuTypes.h:257
void(*)() VoidFunc
Definition MenuTypes.h:27
DisableOption
Definition MenuTypes.h:7
@ DISABLE_FOR_FREE_CAM_OFF
Definition MenuTypes.h:9
@ DISABLE_FOR_DEBUG_MODE_OFF
Definition MenuTypes.h:12
@ DISABLE_FOR_VERTICAL_RES_TOGGLE_ON
Definition MenuTypes.h:20
@ DISABLE_FOR_EDITOR_ON
Definition MenuTypes.h:10
@ DISABLE_FOR_MATCH_REFRESH_RATE_ON
Definition MenuTypes.h:18
@ DISABLE_FOR_LOW_RES_MODE_ON
Definition MenuTypes.h:21
@ DISABLE_FOR_NO_MULTI_VIEWPORT
Definition MenuTypes.h:15
@ DISABLE_FOR_NO_WINDOWED_FULLSCREEN
Definition MenuTypes.h:14
@ DISABLE_FOR_NO_VSYNC
Definition MenuTypes.h:13
@ DISABLE_FOR_EDITOR_OFF
Definition MenuTypes.h:11
@ DISABLE_FOR_FREE_CAM_ON
Definition MenuTypes.h:8
@ DISABLE_FOR_ADVANCED_RESOLUTION_ON
Definition MenuTypes.h:19
@ DISABLE_FOR_NOT_DIRECTX
Definition MenuTypes.h:16
@ DISABLE_FOR_DIRECTX
Definition MenuTypes.h:17
WidgetType
Definition MenuTypes.h:32
@ WIDGET_TEXT
Definition MenuTypes.h:47
@ WIDGET_COMBOBOX
Definition MenuTypes.h:34
@ WIDGET_AUDIO_BACKEND
Definition MenuTypes.h:49
@ WIDGET_CVAR_CHECKBOX
Definition MenuTypes.h:37
@ WIDGET_SEPARATOR
Definition MenuTypes.h:45
@ WIDGET_CVAR_COMBOBOX
Definition MenuTypes.h:38
@ WIDGET_BUTTON
Definition MenuTypes.h:41
@ WIDGET_WINDOW_BUTTON
Definition MenuTypes.h:48
@ WIDGET_CVAR_SLIDER_FLOAT
Definition MenuTypes.h:40
@ WIDGET_COLOR_32
Definition MenuTypes.h:43
@ WIDGET_SEARCH
Definition MenuTypes.h:44
@ WIDGET_CHECKBOX
Definition MenuTypes.h:33
@ WIDGET_CUSTOM
Definition MenuTypes.h:51
@ WIDGET_SEPARATOR_TEXT
Definition MenuTypes.h:46
@ WIDGET_CVAR_SLIDER_INT
Definition MenuTypes.h:39
@ WIDGET_COLOR_24
Definition MenuTypes.h:42
@ WIDGET_SLIDER_INT
Definition MenuTypes.h:35
@ WIDGET_SLIDER_FLOAT
Definition MenuTypes.h:36
@ WIDGET_VIDEO_BACKEND
Definition MenuTypes.h:50
bool(*)(disabledInfo &) DisableInfoFunc
Definition MenuTypes.h:28
std::variant< UIWidgets::ButtonOptions, UIWidgets::CheckboxOptions, UIWidgets::ComboboxOptions, UIWidgets::FloatSliderOptions, UIWidgets::IntSliderOptions, UIWidgets::WidgetOptions > OptionsVariant
Definition MenuTypes.h:79
DebugLogOption
Definition MenuTypes.h:66
@ DEBUG_LOG_WARN
Definition MenuTypes.h:70
@ DEBUG_LOG_INFO
Definition MenuTypes.h:69
@ DEBUG_LOG_ERROR
Definition MenuTypes.h:71
@ DEBUG_LOG_OFF
Definition MenuTypes.h:73
@ DEBUG_LOG_TRACE
Definition MenuTypes.h:67
@ DEBUG_LOG_DEBUG
Definition MenuTypes.h:68
@ DEBUG_LOG_CRITICAL
Definition MenuTypes.h:72
void(*)(WidgetInfo &) WidgetFunc
Definition MenuTypes.h:30
static const std::unordered_map< Ship::WindowBackend, const char * > windowBackendsMap
Definition MenuTypes.h:262
SectionColumns
Definition MenuTypes.h:54
@ SECTION_COLUMN_2
Definition MenuTypes.h:56
@ SECTION_COLUMN_3
Definition MenuTypes.h:57
@ SECTION_COLUMN_1
Definition MenuTypes.h:55
std::vector< DisableOption > DisableVec
Definition MenuTypes.h:29
Definition MenuTypes.h:250
std::string label
Definition MenuTypes.h:251
std::vector< std::string > sidebarOrder
Definition MenuTypes.h:254
std::unordered_map< std::string, SidebarEntry > sidebars
Definition MenuTypes.h:253
const char * sidebarCvar
Definition MenuTypes.h:252
Definition MenuTypes.h:268
static std::unordered_map< std::string, std::unordered_map< std::string, std::vector< std::function< void()> > > > & GetUpdateFuncs()
Definition MenuTypes.h:275
static std::vector< std::function< void()> > & GetInitFuncs()
Definition MenuTypes.h:269
static void InitAll()
Definition MenuTypes.h:281
RegisterMenuInitFunc(std::function< void()> initFunc)
Definition MenuTypes.h:290
RegisterMenuUpdateFunc(std::function< void()> updateFunc, std::string sectionName, std::string sidebarName)
Definition MenuTypes.h:298
Definition MenuTypes.h:242
uint32_t columnCount
Definition MenuTypes.h:243
std::vector< std::vector< WidgetInfo > > columnWidgets
Definition MenuTypes.h:244
Definition UIWidgets.h:127
Definition UIWidgets.h:145
Definition UIWidgets.h:173
Definition UIWidgets.h:261
Definition UIWidgets.h:207
Definition UIWidgets.h:107
Definition MenuTypes.h:103
std::shared_ptr< UIWidgets::WidgetOptions > options
Definition MenuTypes.h:107
WidgetFunc preFunc
Definition MenuTypes.h:110
void ResetDisables()
Definition MenuTypes.h:157
const char * windowName
Definition MenuTypes.h:114
std::variant< bool *, int32_t *, float * > valuePointer
Definition MenuTypes.h:108
WidgetInfo & SameLine(bool sameLine_)
Definition MenuTypes.h:187
WidgetInfo & Callback(WidgetFunc callback_)
Definition MenuTypes.h:167
WidgetInfo & Options(OptionsVariant options_)
Definition MenuTypes.h:122
bool sameLine
Definition MenuTypes.h:116
WidgetInfo & CVar(const char *cVar_)
Definition MenuTypes.h:118
WidgetType type
Definition MenuTypes.h:106
WidgetInfo & ValuePointer(std::variant< bool *, int32_t *, float * > valuePointer_)
Definition MenuTypes.h:183
WidgetFunc customFunction
Definition MenuTypes.h:112
bool isHidden
Definition MenuTypes.h:115
WidgetInfo & PreFunc(WidgetFunc preFunc_)
Definition MenuTypes.h:171
DisableVec activeDisables
Definition MenuTypes.h:113
WidgetInfo & Options(std::shared_ptr< UIWidgets::WidgetOptions > options_)
Definition MenuTypes.h:163
const char * cVar
Definition MenuTypes.h:105
WidgetInfo & PostFunc(WidgetFunc postFunc_)
Definition MenuTypes.h:175
std::string name
Definition MenuTypes.h:104
WidgetFunc callback
Definition MenuTypes.h:109
WidgetFunc postFunc
Definition MenuTypes.h:111
WidgetInfo & CustomFunction(WidgetFunc customFunction_)
Definition MenuTypes.h:191
WidgetInfo & WindowName(const char *windowName_)
Definition MenuTypes.h:179
Definition MenuTypes.h:197
std::string sidebarName
Definition MenuTypes.h:199
std::string sectionName
Definition MenuTypes.h:198
SectionColumns column
Definition MenuTypes.h:200
Definition MenuTypes.h:209
const char * reason
Definition MenuTypes.h:211
DisableInfoFunc evaluation
Definition MenuTypes.h:210
int32_t value
Definition MenuTypes.h:213
bool active
Definition MenuTypes.h:212