Elaztek Developer Hub
Blamite Game Engine - blam!  00406.12.10.23.1457.blamite
The core library for the Blamite Game Engine.
debug_menu.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
7 
19 {
20 private:
21  BlamDebugMenu* menu = nullptr;
22 public:
27  {
29  }
30 
39  {
40  switch (item->item_type)
41  {
43  {
44  if (ImGui::TreeNode(item->title.c_str()))
45  {
46  for (int i = 0; i < item->items.size(); i++)
47  {
48  GenerateItemControl(&item->items.at(i));
49  }
50 
52  }
53 
54  return;
55  }
57  {
59  {
60  item->HandleKeyEnter();
61  }
62 
63  return;
64  }
66  {
68 
69  if (global)
70  {
71  switch (global->type)
72  {
74  {
75  ImGui::Checkbox(item->title.c_str(), &global->boolean_value);
76  return;
77  }
79  {
80  if (item->use_bounds)
81  {
82  ImGui::SliderInt(item->title.c_str(), &global->int_value, item->min, item->max);
83  }
84  else
85  {
86  ImGui::InputInt(item->title.c_str(), &global->int_value, 1, item->inc);
87  }
88 
89  return;
90  }
92  {
93  if (item->use_bounds)
94  {
95  ImGui::SliderInt(item->title.c_str(), (int*)&global->long_value, item->min, item->max);
96  }
97  else
98  {
99  ImGui::InputInt(item->title.c_str(), (int*)&global->long_value, 1, item->inc);
100  }
101 
102  return;
103  }
105  {
106  if (item->use_bounds)
107  {
108  ImGui::SliderInt(item->title.c_str(), (int*)&global->short_value, item->min, item->max);
109  }
110  else
111  {
112  ImGui::InputInt(item->title.c_str(), (int*)&global->short_value, 1, item->inc);
113  }
114 
115  return;
116  }
118  {
119  if (item->use_bounds)
120  {
121  ImGui::SliderFloat(item->title.c_str(), &global->float_value, item->min, item->max);
122  }
123  else
124  {
125  ImGui::InputFloat(item->title.c_str(), &global->float_value, 1, item->inc);
126  }
127 
128  return;
129  }
130  default:
131  {
132  std::string text = "UNSUPPORTED: " + item->title + " (" + global->name + ")";
133  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
134 
135  return;
136  }
137  }
138  }
139  else
140  {
141  std::string text = "UNDEFINED: " + item->title + " (" + item->global_id + ")";
142  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
143  }
144 
145  return;
146  }
148  {
150  {
151  item->HandleKeyEnter();
152  }
153 
154  return;
155  }
157  {
159 
161  {
162  item->HandleKeyEnter();
163  }
164 
166 
167  return;
168  }
169  default:
170  {
171  return;
172  }
173  }
174  }
175 
179  void Draw()
180  {
181  if (!show)
182  {
183  return;
184  }
185 
186  if (menu)
187  {
188  if (ImGui::Begin(menu->title.c_str(), &show))
189  {
190  ImGui::TextColored(ImVec4(1, 0, 0, 1), "this debug menu is not supported, please use PgUp and use the primary debug menu");
191  ImGui::TextColored(ImVec4(1, 0, 0, 1), "only use this if you seriously can't stand that one");
192 
193  for (int i = 0; i < menu->items.size(); i++)
194  {
195  if (menu->items.at(i).item_type == BlamDebugMenuItemType::Submenu)
196  {
197  if (ImGui::CollapsingHeader(menu->items.at(i).title.c_str()))
198  {
199  for (int x = 0; x < menu->items.at(i).items.size(); x++)
200  {
201  GenerateItemControl(&menu->items.at(i).items.at(x));
202  }
203  }
204  }
205  else
206  {
207  GenerateItemControl(&menu->items.at(i));
208  }
209  }
210  }
211  }
212  else
213  {
214  if (ImGui::Begin("Main", &show))
215  {
216  ImGui::TextColored(ImVec4(1, 0, 0, 1), "debug menu does not appear to be loaded (menu was nullptr)");
217  }
218  }
219 
220  ImGui::End();
221  }
222 };
BlamDebugMenuItem::title
std::string title
The title of the debug menu item as shown in the menu.
Definition: debug_menu.h:41
ImGui::TreeNode
IMGUI_API bool TreeNode(const char *label)
Definition: imgui_widgets.cpp:5071
Short
@ Short
!< Represents a float.
Definition: globals.h:36
BlamDebugMenuItem::inc
double inc
How much to add or remove from the value at a time upon activation.
Definition: debug_menu.h:56
BlamDebugMenuItemType::Submenu
@ Submenu
Enters into a submenu/subscreen upon activation.
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
Blam::Resources::DebugMenu::GetDebugMenu
BLAM BlamDebugMenu * GetDebugMenu()
Retrieves the debug menu data.
Definition: debug_menu.cpp:411
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
ImGui::PopStyleColor
IMGUI_API void PopStyleColor(int count=1)
Definition: imgui.cpp:6341
ImVec4
Definition: imgui.h:192
Real
@ Real
Definition: globals.h:35
BlamEngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:57
BlamImGuiWindow_DebugMenu::Draw
void Draw()
Draws the debug menu window.
Definition: debug_menu.hpp:179
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
BlamEngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:66
BlamDebugMenuItem::items
std::vector< BlamDebugMenuItem > items
The contents of the submenu to show upon activation.
Definition: debug_menu.h:61
ImGui::GetWindowContentRegionWidth
IMGUI_API float GetWindowContentRegionWidth()
Definition: imgui.cpp:6831
console.h
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
ImGui::GetTextLineHeightWithSpacing
IMGUI_API float GetTextLineHeightWithSpacing()
Definition: imgui.cpp:6843
ImVec2
Definition: imgui.h:179
Int
@ Int
Represents an int.
Definition: globals.h:40
BlamEngineGlobal::type
BlamGlobalType type
The type of the global.
Definition: globals.h:56
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
debug_menu.h
BlamDebugMenuItemType::CommandSequence
@ CommandSequence
Runs a sequence of console commands upon activation.
BlamImGuiWindow_DebugMenu
Class for the ImGUI-based debug menu implementation.
Definition: debug_menu.hpp:18
BlamEngineGlobal
Structure containing data for a game engine global.
Definition: globals.h:54
BlamDebugMenuItemType::Global
@ Global
Modifies an engine global upon activation.
BlamDebugMenuItem::item_type
BlamDebugMenuItemType item_type
The type of menu item. See BlamDebugMenuItemType for details.
Definition: debug_menu.h:40
BlamImGuiWindow_DebugMenu::BlamImGuiWindow_DebugMenu
BlamImGuiWindow_DebugMenu()
Retrieves the debug menu data.
Definition: debug_menu.hpp:26
BlamDebugMenuItemType::Unknown
@ Unknown
Fallback in the event that debug_menu_init contained an invalid option.
BlamEngineGlobal::short_value
short short_value
The short value of the global.
Definition: globals.h:67
BlamDebugMenuItem
Class used to store data and functions relating to an item within the engine's debug menu.
Definition: debug_menu.h:37
BlamImGuiWindow_DebugMenu::GenerateItemControl
void GenerateItemControl(BlamDebugMenuItem *item)
Creates the appropriate control for the debug menu item.
Definition: debug_menu.hpp:38
Blam::Globals::GetGlobal
BLAM BlamEngineGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: globals.cpp:189
BlamDebugMenu::items
std::vector< BlamDebugMenuItem > items
The list of items within the debug menu.
Definition: debug_menu.h:90
ImGui::TreePop
IMGUI_API void TreePop()
Definition: imgui_widgets.cpp:5380
BlamDebugMenuItemType::Command
@ Command
Runs a console command upon activation.
Long
@ Long
Represents a long.
Definition: globals.h:37
BlamDebugMenuItem::global_id
std::string global_id
The ID of the engine global to modify upon activation.
Definition: debug_menu.h:54
Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:34
BlamDebugMenuItem::HandleKeyEnter
void HandleKeyEnter()
Called when the menu item is active and the enter key is pressed.
Definition: BlamDebugMenuItem.cpp:11
BlamDebugMenuItem::max
double max
The maximum value specified in debug_menu_init.
Definition: debug_menu.h:58
BlamDebugMenuItem::use_bounds
bool use_bounds
Whether or not arbitrary bounds are specified in debug_menu_init.
Definition: debug_menu.h:55
x
config GlyphExtraSpacing x
Definition: README.txt:30
BlamDebugMenu::title
std::string title
The title of the main page of the debug menu. Defaults to Main.
Definition: debug_menu.h:89
ImGuiCol_Text
@ ImGuiCol_Text
Definition: imgui.h:1027
BlamEngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:69
ImGui::SliderFloat
IMGUI_API bool SliderFloat(const char *label, float *v, float v_min, float v_max, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2619
imgui.h
BlamDebugMenu
Structure containing data for the root of the debug menu.
Definition: debug_menu.h:87
ImGui::SliderInt
IMGUI_API bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *format="%d")
Definition: imgui_widgets.cpp:2649
BlamEngineGlobal::float_value
float float_value
The float value of the global.
Definition: globals.h:70
ImGui::TextColored
IMGUI_API void TextColored(const ImVec4 &col, const char *fmt,...) IM_FMTARGS(2)
Definition: imgui_widgets.cpp:257
ImGui::InputFloat
IMGUI_API bool InputFloat(const char *label, float *v, float step=0.0f, float step_fast=0.0f, const char *format="%.3f", ImGuiInputTextFlags flags=0)
Definition: imgui_widgets.cpp:2975
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
ImGui::InputInt
IMGUI_API bool InputInt(const char *label, int *v, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
Definition: imgui_widgets.cpp:3031
BlamDebugMenuItem::min
double min
The minimum value specified in debug_menu_init.
Definition: debug_menu.h:57
BlamEngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:68
ImGui::PushStyleColor
IMGUI_API void PushStyleColor(ImGuiCol idx, ImU32 col)
Definition: imgui.cpp:6321