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