Elaztek Developer Hub
Blamite Game Engine - blam!  00423.10.27.24.0533.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->GetType())
41  {
43  {
45 
46  if (ImGui::TreeNode(item->title.c_str()))
47  {
48  for (int i = 0; i < submenu_item->items.size(); i++)
49  {
50  GenerateItemControl(submenu_item->items.at(i));
51  }
52 
54  }
55 
56  return;
57  }
59  {
61  {
62  item->Activate();
63  }
64 
65  return;
66  }
68  {
70  BlamEngineGlobal* global = Blam::Globals::GetGlobal(global_item->global_id);
71 
72  if (global)
73  {
74  switch (global->type)
75  {
77  {
78  ImGui::Checkbox(item->title.c_str(), &global->boolean_value);
79  return;
80  }
82  {
83  if (global_item->use_bounds)
84  {
85  ImGui::SliderInt(item->title.c_str(), &global->int_value, global_item->min, global_item->max);
86  }
87  else
88  {
89  ImGui::InputInt(item->title.c_str(), &global->int_value, 1, global_item->inc);
90  }
91 
92  return;
93  }
95  {
96  if (global_item->use_bounds)
97  {
98  ImGui::SliderInt(item->title.c_str(), (int*)&global->long_value, global_item->min, global_item->max);
99  }
100  else
101  {
102  ImGui::InputInt(item->title.c_str(), (int*)&global->long_value, 1, global_item->inc);
103  }
104 
105  return;
106  }
108  {
109  if (global_item->use_bounds)
110  {
111  ImGui::SliderInt(item->title.c_str(), (int*)&global->short_value, global_item->min, global_item->max);
112  }
113  else
114  {
115  ImGui::InputInt(item->title.c_str(), (int*)&global->short_value, 1, global_item->inc);
116  }
117 
118  return;
119  }
121  {
122  if (global_item->use_bounds)
123  {
124  ImGui::SliderFloat(item->title.c_str(), &global->float_value, global_item->min, global_item->max);
125  }
126  else
127  {
128  ImGui::InputFloat(item->title.c_str(), &global->float_value, 1, global_item->inc);
129  }
130 
131  return;
132  }
133  default:
134  {
135  std::string text = "UNSUPPORTED: " + item->title + " (" + global->name + ")";
136  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
137 
138  return;
139  }
140  }
141  }
142  else
143  {
144  std::string text = "UNDEFINED: " + item->title + " (" + global_item->global_id + ")";
145  ImGui::TextColored(ImVec4(1, 0, 0, 1), text.c_str());
146  }
147 
148  return;
149  }
151  {
153  {
154  item->Activate();
155  }
156 
157  return;
158  }
160  {
162 
164  {
165  item->Activate();
166  }
167 
169 
170  return;
171  }
172  default:
173  {
174  return;
175  }
176  }
177  }
178 
182  void Draw()
183  {
184  if (!show)
185  {
186  return;
187  }
188 
189  if (menu)
190  {
191  if (ImGui::Begin(menu->title.c_str(), &show))
192  {
193  ImGui::TextColored(ImVec4(1, 0, 0, 1), "this debug menu is not supported, please use PgUp and use the primary debug menu");
194  ImGui::TextColored(ImVec4(1, 0, 0, 1), "only use this if you seriously can't stand that one");
195 
196  for (int i = 0; i < menu->items.size(); i++)
197  {
198  if (menu->items.at(i)->GetType() == BlamDebugMenuItemType::Submenu)
199  {
200  BlamDebugMenuItem_Submenu* submenu_item = (BlamDebugMenuItem_Submenu*)menu->items.at(i);
201 
202  if (ImGui::CollapsingHeader(submenu_item->title.c_str()))
203  {
204  for (int x = 0; x < submenu_item->items.size(); x++)
205  {
206  GenerateItemControl(submenu_item->items.at(x));
207  }
208  }
209  }
210  else
211  {
212  GenerateItemControl(menu->items.at(i));
213  }
214  }
215  }
216  }
217  else
218  {
219  if (ImGui::Begin("Main", &show))
220  {
221  ImGui::TextColored(ImVec4(1, 0, 0, 1), "debug menu does not appear to be loaded (menu was nullptr)");
222  }
223  }
224 
225  ImGui::End();
226  }
227 };
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
BlamDebugMenuItem_Global::inc
double inc
The amount to increase or decrease the global value by when incrementing or decrementing.
Definition: debug_menu.h:127
BlamDebugMenuItem_Global::use_bounds
bool use_bounds
Whether or not the min/max bounds should be used.
Definition: debug_menu.h:126
BlamDebugMenuItem_Submenu
Class representing a submenu debug menu item.
Definition: debug_menu.h:161
Real
@ Real
Definition: globals.h:25
BlamDebugMenuItem_Global::global_id
std::string global_id
The ID of the engine global to update.
Definition: debug_menu.h:125
BlamDebugMenuItemType::Submenu
@ Submenu
Enters into a submenu/subscreen upon activation.
Long
@ Long
Represents a long.
Definition: globals.h:27
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:517
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
BlamDebugMenuItem_Global::min
double min
The minimum value of the global.
Definition: debug_menu.h:128
ImGui::PopStyleColor
IMGUI_API void PopStyleColor(int count=1)
Definition: imgui.cpp:6341
ImVec4
Definition: imgui.h:192
Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: globals.h:24
BlamEngineGlobal::name
std::string name
The name of the global.
Definition: globals.h:47
BlamImGuiWindow_DebugMenu::Draw
void Draw()
Draws the debug menu window.
Definition: debug_menu.hpp:182
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
console.h
BlamEngineGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: globals.h:56
Int
@ Int
Represents an int.
Definition: globals.h:30
ImGui::GetWindowContentRegionWidth
IMGUI_API float GetWindowContentRegionWidth()
Definition: imgui.cpp:6831
BlamDebugMenuItem_Global::max
double max
The maximum value of the global.
Definition: debug_menu.h:129
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
BlamEngineGlobal::type
BlamGlobalType type
The type of the global.
Definition: globals.h:46
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
BlamDebugMenuItem::Activate
virtual void Activate()
Called when the menu item is active and the enter key is pressed.
Definition: debug_menu.h:60
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:44
BlamDebugMenuItemType::Global
@ Global
Modifies an engine global upon activation.
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:57
BlamDebugMenuItem
Class representing a debug menu item.
Definition: debug_menu.h:35
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
ImGui::TreePop
IMGUI_API void TreePop()
Definition: imgui_widgets.cpp:5380
BlamDebugMenuItemType::Command
@ Command
Runs a console command upon activation.
Short
@ Short
!< Represents a float.
Definition: globals.h:26
BlamDebugMenuItem::GetType
BlamDebugMenuItemType GetType()
Retrieves the type of the debug menu item.
Definition: BlamDebugMenuItem.cpp:8
BlamDebugMenu::items
std::vector< BlamDebugMenuItem * > items
The list of items within the debug menu.
Definition: debug_menu.h:176
BlamDebugMenu::title
std::string title
The title of the main page of the debug menu. Defaults to Main.
Definition: debug_menu.h:175
ImGuiCol_Text
@ ImGuiCol_Text
Definition: imgui.h:1027
BlamEngineGlobal::int_value
int int_value
The int value of the global.
Definition: globals.h:59
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:173
x
config GlyphExtraSpacing x
Definition: README.txt:30
BlamDebugMenuItem_Global
Class representing a global debug menu item.
Definition: debug_menu.h:122
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:60
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
BlamDebugMenuItem_Submenu::items
std::vector< BlamDebugMenuItem * > items
The contents of the submenu to show upon activation.
Definition: debug_menu.h:164
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
BlamEngineGlobal::long_value
long long_value
The long value of the global.
Definition: globals.h:58
ImGui::PushStyleColor
IMGUI_API void PushStyleColor(ImGuiCol idx, ImU32 col)
Definition: imgui.cpp:6321